Search in sources :

Example 1 with Isotopes

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;
    }
}
Also used : IIsotope(org.openscience.cdk.interfaces.IIsotope) IOException(java.io.IOException) Isotopes(org.openscience.cdk.config.Isotopes)

Example 2 with Isotopes

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;
}
Also used : IIsotope(org.openscience.cdk.interfaces.IIsotope) IMolecularFormula(org.openscience.cdk.interfaces.IMolecularFormula) IOException(java.io.IOException) Isotopes(org.openscience.cdk.config.Isotopes) IChemObjectBuilder(org.openscience.cdk.interfaces.IChemObjectBuilder)

Aggregations

IOException (java.io.IOException)2 Isotopes (org.openscience.cdk.config.Isotopes)2 IIsotope (org.openscience.cdk.interfaces.IIsotope)2 IChemObjectBuilder (org.openscience.cdk.interfaces.IChemObjectBuilder)1 IMolecularFormula (org.openscience.cdk.interfaces.IMolecularFormula)1