Search in sources :

Example 1 with IsotopeFactory

use of org.openscience.cdk.config.IsotopeFactory in project mzmine2 by mzmine.

the class FormulaUtils method replaceAllIsotopesWithoutExactMass.

/**
 * Searches for all isotopes exactmass=null and replaces them with the major isotope
 *
 * @param f
 * @return
 * @throws IOException
 */
public static IMolecularFormula replaceAllIsotopesWithoutExactMass(IMolecularFormula f) throws IOException {
    for (IIsotope iso : f.isotopes()) {
        // find isotope without exact mass
        if (iso.getExactMass() == null || iso.getExactMass() == 0) {
            int isotopeCount = f.getIsotopeCount(iso);
            f.removeIsotope(iso);
            // replace
            IsotopeFactory iFac = Isotopes.getInstance();
            IIsotope major = iFac.getMajorIsotope(iso.getAtomicNumber());
            if (major != null)
                f.addIsotope(major, isotopeCount);
            return replaceAllIsotopesWithoutExactMass(f);
        }
    }
    // no isotope found
    return f;
}
Also used : IIsotope(org.openscience.cdk.interfaces.IIsotope) IsotopeFactory(org.openscience.cdk.config.IsotopeFactory)

Example 2 with IsotopeFactory

use of org.openscience.cdk.config.IsotopeFactory in project mzmine2 by mzmine.

the class ElementsParameter method loadValueFromXML.

@Override
public void loadValueFromXML(Element xmlElement) {
    try {
        MolecularFormulaRange newValue = new MolecularFormulaRange();
        IsotopeFactory iFac = Isotopes.getInstance();
        String s = xmlElement.getTextContent();
        Pattern p = Pattern.compile("([a-zA-Z]+)\\[([0-9]+)-([0-9]+)\\]");
        Matcher m = p.matcher(s);
        while (m.find()) {
            String elementSymbol = m.group(1);
            int minCount = Integer.parseInt(m.group(2));
            int maxCount = Integer.parseInt(m.group(3));
            newValue.addIsotope(iFac.getMajorIsotope(elementSymbol), minCount, maxCount);
        }
        this.value = newValue;
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : IsotopeFactory(org.openscience.cdk.config.IsotopeFactory) Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) MolecularFormulaRange(org.openscience.cdk.formula.MolecularFormulaRange) IOException(java.io.IOException)

Example 3 with IsotopeFactory

use of org.openscience.cdk.config.IsotopeFactory in project mzmine2 by mzmine.

the class PeriodicTableDialog method stateChanged.

public void stateChanged(EventObject event) {
    if (event.getSource() == periodicTable) {
        try {
            String elementSymbol = periodicTable.getSelectedElement();
            IsotopeFactory isoFac = Isotopes.getInstance();
            selectedIsotope = isoFac.getMajorIsotope(elementSymbol);
        } catch (Exception e) {
            e.printStackTrace();
        }
        dispose();
    }
}
Also used : IsotopeFactory(org.openscience.cdk.config.IsotopeFactory)

Example 4 with IsotopeFactory

use of org.openscience.cdk.config.IsotopeFactory in project mzmine2 by mzmine.

the class SiriusParameters method createDefaultElements.

/**
 * Create default table of elements The table is used later to calculate FormulaConstraints
 *
 * @return
 */
private static MolecularFormulaRange createDefaultElements() {
    MolecularFormulaRange range = new MolecularFormulaRange();
    try {
        IsotopeFactory iFac = Isotopes.getInstance();
        range.addIsotope(iFac.getMajorIsotope("C"), ISOTOPE_MIN, ISOTOPE_MAX);
        range.addIsotope(iFac.getMajorIsotope("H"), ISOTOPE_MIN, ISOTOPE_MAX);
        range.addIsotope(iFac.getMajorIsotope("N"), ISOTOPE_MIN, ISOTOPE_MAX);
        range.addIsotope(iFac.getMajorIsotope("O"), ISOTOPE_MIN, ISOTOPE_MAX);
        range.addIsotope(iFac.getMajorIsotope("P"), ISOTOPE_MIN, ISOTOPE_MAX);
        range.addIsotope(iFac.getMajorIsotope("S"), ISOTOPE_MIN, ISOTOPE_MAX);
        range.addIsotope(iFac.getMajorIsotope("F"), ISOTOPE_MIN, ISOTOPE_MIN);
        range.addIsotope(iFac.getMajorIsotope("B"), ISOTOPE_MIN, ISOTOPE_MIN);
        range.addIsotope(iFac.getMajorIsotope("I"), ISOTOPE_MIN, ISOTOPE_MIN);
        range.addIsotope(iFac.getMajorIsotope("Br"), ISOTOPE_MIN, ISOTOPE_MIN);
        range.addIsotope(iFac.getMajorIsotope("Se"), ISOTOPE_MIN, ISOTOPE_MIN);
        range.addIsotope(iFac.getMajorIsotope("Cl"), ISOTOPE_MIN, ISOTOPE_MIN);
    } catch (IOException e) {
        e.printStackTrace();
    }
    return range;
}
Also used : IsotopeFactory(org.openscience.cdk.config.IsotopeFactory) MolecularFormulaRange(org.openscience.cdk.formula.MolecularFormulaRange) IOException(java.io.IOException)

Aggregations

IsotopeFactory (org.openscience.cdk.config.IsotopeFactory)4 IOException (java.io.IOException)2 MolecularFormulaRange (org.openscience.cdk.formula.MolecularFormulaRange)2 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 IIsotope (org.openscience.cdk.interfaces.IIsotope)1