use of org.openscience.cdk.config.Isotopes in project mzmine2 by mzmine.
the class FormulaUtils method getElementMass.
/**
* Returns the exact mass of an element. Mass is obtained from the CDK library.
*/
public static double getElementMass(String element) {
try {
Isotopes isotopeFactory = Isotopes.getInstance();
IIsotope majorIsotope = isotopeFactory.getMajorIsotope(element);
// If the isotope symbol does not exist, return 0
if (majorIsotope == null) {
return 0;
}
double mass = majorIsotope.getExactMass();
return mass;
} catch (IOException e) {
e.printStackTrace();
return 0;
}
}
use of org.openscience.cdk.config.Isotopes in project mzmine2 by mzmine.
the class FormulaUtils method getFormulaSize.
public static long getFormulaSize(String formula) {
long size = 1;
IChemObjectBuilder builder = SilentChemObjectBuilder.getInstance();
IMolecularFormula molFormula;
molFormula = MolecularFormulaManipulator.getMajorIsotopeMolecularFormula(formula, builder);
Isotopes isotopeFactory;
try {
isotopeFactory = Isotopes.getInstance();
for (IIsotope iso : molFormula.isotopes()) {
int naturalIsotopes = 0;
for (IIsotope i : isotopeFactory.getIsotopes(iso.getSymbol())) {
if (i.getNaturalAbundance() > 0.0) {
naturalIsotopes++;
}
}
try {
size = Math.multiplyExact(size, (molFormula.getIsotopeCount(iso) * naturalIsotopes));
} catch (ArithmeticException e) {
e.printStackTrace();
logger.info("Formula size of " + formula + " is too big.");
return -1;
}
}
} catch (IOException e) {
logger.warning("Unable to initialise Isotopes.");
e.printStackTrace();
}
return size;
}
Aggregations