Recipe 2.1.3. Getting molecular mass
Problem
You want to compute molecular mass given an accuracy.
Solution
The dedicated object MassCalculator makes the computation. It just need a Molecule or a BioPolymer:
// monoisotopic mass calculator MassCalculator monoMassCalc = MassCalculator.getMonoAccuracyInstance(); // average mass calculator MassCalculator avgMassCalc = MassCalculator.getAvgAccuracyInstance(); Molecule methane = ChemicalFacade.getMolecule("CH4"); // compute mass of a molecule Assert.assertEquals(16.0313, monoMassCalc.getMass(methane)); Assert.assertEquals(16.0429, avgMassCalc.getMass(methane)); // compute mass of polymer Peptide peptide = new Peptide.Builder("MQRSTA({133.0})TGCFKL").build(); Assert.assertEquals(1474.6533, monoMassCalc.getMass(peptide));
Discussion
See Also