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);
}
Aggregations