Search in sources :

Example 1 with IsotopePatternGenerator

use of org.openscience.cdk.formula.IsotopePatternGenerator in project mzmine2 by mzmine.

the class IsotopePatternCalculator method calculateIsotopePattern.

public static IsotopePattern calculateIsotopePattern(IMolecularFormula cdkFormula, double minAbundance, double mergeWidth, int charge, PolarityType polarity, boolean storeFormula) {
    // TODO: check if the formula is not too big (>100 of a single atom?).
    // if so, just cancel the prediction
    // Set the minimum abundance of isotope
    // TODO: in the CDK minAbundance is now called minIntensity and refers to the relative intensity
    // in the isotope pattern, should change it here, too
    IsotopePatternGenerator generator = new IsotopePatternGenerator(minAbundance);
    generator.setMinResolution(mergeWidth);
    generator.setStoreFormulas(storeFormula);
    org.openscience.cdk.formula.IsotopePattern pattern = generator.getIsotopes(cdkFormula);
    int numOfIsotopes = pattern.getNumberOfIsotopes();
    DataPoint[] dataPoints = new DataPoint[numOfIsotopes];
    String[] isotopeComposition = new String[numOfIsotopes];
    for (int i = 0; i < numOfIsotopes; i++) {
        IsotopeContainer isotope = pattern.getIsotope(i);
        // For each unit of charge, we have to add or remove a mass of a
        // single electron. If the charge is positive, we remove electron
        // mass. If the charge is negative, we add it.
        double mass = isotope.getMass() + (polarity.getSign() * -1 * charge * ELECTRON_MASS);
        if (charge != 0)
            mass /= charge;
        double intensity = isotope.getIntensity();
        dataPoints[i] = new SimpleDataPoint(mass, intensity);
        if (storeFormula)
            isotopeComposition[i] = formatCDKString(isotope.toString());
    }
    String formulaString = MolecularFormulaManipulator.getString(cdkFormula);
    if (storeFormula)
        return new ExtendedIsotopePattern(dataPoints, IsotopePatternStatus.PREDICTED, formulaString, isotopeComposition);
    else
        return new SimpleIsotopePattern(dataPoints, IsotopePatternStatus.PREDICTED, formulaString);
}
Also used : DataPoint(net.sf.mzmine.datamodel.DataPoint) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) IsotopePatternGenerator(org.openscience.cdk.formula.IsotopePatternGenerator) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) DataPoint(net.sf.mzmine.datamodel.DataPoint) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) IsotopeContainer(org.openscience.cdk.formula.IsotopeContainer) SimpleIsotopePattern(net.sf.mzmine.datamodel.impl.SimpleIsotopePattern) ExtendedIsotopePattern(net.sf.mzmine.datamodel.impl.ExtendedIsotopePattern)

Aggregations

DataPoint (net.sf.mzmine.datamodel.DataPoint)1 ExtendedIsotopePattern (net.sf.mzmine.datamodel.impl.ExtendedIsotopePattern)1 SimpleDataPoint (net.sf.mzmine.datamodel.impl.SimpleDataPoint)1 SimpleIsotopePattern (net.sf.mzmine.datamodel.impl.SimpleIsotopePattern)1 IsotopeContainer (org.openscience.cdk.formula.IsotopeContainer)1 IsotopePatternGenerator (org.openscience.cdk.formula.IsotopePatternGenerator)1