use of org.openscience.cdk.interfaces.IIsotope 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.interfaces.IIsotope 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;
}
use of org.openscience.cdk.interfaces.IIsotope in project mzmine2 by mzmine.
the class ElementsParameter method saveValueToXML.
@Override
public void saveValueToXML(Element xmlElement) {
if (value == null)
return;
StringBuilder s = new StringBuilder();
for (IIsotope i : value.isotopes()) {
s.append(i.getSymbol());
s.append("[");
s.append(value.getIsotopeCountMin(i));
s.append("-");
s.append(value.getIsotopeCountMax(i));
s.append("]");
}
xmlElement.setTextContent(s.toString());
}
use of org.openscience.cdk.interfaces.IIsotope in project mzmine2 by mzmine.
the class ElementsTableComponent method actionPerformed.
public void actionPerformed(ActionEvent event) {
Object src = event.getSource();
if (src == addElementButton) {
JFrame parent = (JFrame) SwingUtilities.getAncestorOfClass(JFrame.class, this);
PeriodicTableDialog dialog = new PeriodicTableDialog(parent);
dialog.setVisible(true);
IIsotope chosenIsotope = dialog.getSelectedIsotope();
if (chosenIsotope == null)
return;
elementsTableModel.addRow(chosenIsotope, 0, 100);
}
if (src == removeElementButton) {
int selectedRow = elementsTable.getSelectedRow();
if (selectedRow < 0)
return;
elementsTableModel.removeRow(selectedRow);
}
}
use of org.openscience.cdk.interfaces.IIsotope in project mzmine2 by mzmine.
the class ElementsTableComponent method setElements.
public void setElements(MolecularFormulaRange elements) {
if (elements == null)
return;
for (IIsotope isotope : elements.isotopes()) {
int minCount = elements.getIsotopeCountMin(isotope);
int maxCount = elements.getIsotopeCountMax(isotope);
elementsTableModel.addRow(isotope, minCount, maxCount);
}
}
Aggregations