use of org.openscience.cdk.formula.MolecularFormula in project cdk by cdk.
the class MolecularFormulaManipulatorTest method test6.
/**
* Test if formula-comparison is simplify-independant
*/
@Test
public void test6() {
String formula = "(CH3)2";
IMolecularFormula formula1 = new MolecularFormula();
formula1.addIsotope(builder.newInstance(IIsotope.class, "C"), 2);
formula1.addIsotope(builder.newInstance(IIsotope.class, "H"), 6);
IMolecularFormula ff = MolecularFormulaManipulator.getMolecularFormula(formula, builder);
Assert.assertTrue(MolecularFormulaManipulator.compare(formula1, MolecularFormulaManipulator.getMolecularFormula(formula, builder)));
Assert.assertEquals("C2H6", MolecularFormulaManipulator.getString(ff));
}
use of org.openscience.cdk.formula.MolecularFormula in project cdk by cdk.
the class MolecularFormulaManipulatorTest method testGetMolecularFormula_IAtomContainerIMolecularFormula_2.
@Test
public void testGetMolecularFormula_IAtomContainerIMolecularFormula_2() {
IAtomContainer ac = builder.newInstance(IAtomContainer.class);
ac.addAtom(builder.newInstance(IAtom.class, "C"));
ac.addAtom(builder.newInstance(IAtom.class, "C"));
ac.addAtom(builder.newInstance(IAtom.class, "H"));
ac.addAtom(builder.newInstance(IAtom.class, "H"));
ac.addAtom(builder.newInstance(IAtom.class, "H"));
ac.addAtom(builder.newInstance(IAtom.class, "H"));
IMolecularFormula mf0 = new MolecularFormula();
mf0.addIsotope(builder.newInstance(IIsotope.class, "C"), 2);
mf0.addIsotope(builder.newInstance(IIsotope.class, "H"), 5);
IMolecularFormula mf1 = MolecularFormulaManipulator.getMolecularFormula(ac, mf0);
IMolecularFormula mf2 = new MolecularFormula();
mf2.addIsotope(builder.newInstance(IIsotope.class, "C"), 4);
mf2.addIsotope(builder.newInstance(IIsotope.class, "H"), 9);
Assert.assertEquals(getAtomCount(mf2), getAtomCount(mf1));
Assert.assertEquals(mf2.getIsotopeCount(), mf1.getIsotopeCount());
IElement elemC = builder.newInstance(IElement.class, "C");
IElement elemH = builder.newInstance(IElement.class, "H");
Assert.assertEquals(mf2.getIsotopeCount(builder.newInstance(IIsotope.class, elemC)), mf1.getIsotopeCount(builder.newInstance(IIsotope.class, elemC)));
Assert.assertEquals(mf2.getIsotopeCount(builder.newInstance(IIsotope.class, elemH)), mf1.getIsotopeCount(builder.newInstance(IIsotope.class, elemH)));
Assert.assertEquals(MolecularFormulaManipulator.getElementCount(mf2, elemC), MolecularFormulaManipulator.getElementCount(mf1, elemC));
Assert.assertEquals(MolecularFormulaManipulator.getElementCount(mf2, elemH), MolecularFormulaManipulator.getElementCount(mf1, elemH));
}
use of org.openscience.cdk.formula.MolecularFormula in project cdk by cdk.
the class MolecularFormulaManipulatorTest method testGetHTML_IMolecularFormula.
@Test
public void testGetHTML_IMolecularFormula() {
MolecularFormula formula = new MolecularFormula();
formula.addIsotope(builder.newInstance(IIsotope.class, "C"), 8);
formula.addIsotope(builder.newInstance(IIsotope.class, "H"), 10);
formula.addIsotope(builder.newInstance(IIsotope.class, "Cl"), 2);
formula.addIsotope(builder.newInstance(IIsotope.class, "O"), 2);
Assert.assertEquals("C<sub>8</sub>H<sub>10</sub>Cl<sub>2</sub>O<sub>2</sub>", MolecularFormulaManipulator.getHTML(formula));
}
use of org.openscience.cdk.formula.MolecularFormula in project cdk by cdk.
the class MolecularFormulaManipulatorTest method testSimplifygetMF.
@Test
public void testSimplifygetMF() {
String formula = "CH4.H2O";
IMolecularFormula formula1 = new MolecularFormula();
formula1.addIsotope(builder.newInstance(IIsotope.class, "C"), 1);
formula1.addIsotope(builder.newInstance(IIsotope.class, "H"), 6);
formula1.addIsotope(builder.newInstance(IIsotope.class, "O"), 1);
IMolecularFormula ff = MolecularFormulaManipulator.getMolecularFormula(formula, builder);
Assert.assertTrue(MolecularFormulaManipulator.compare(formula1, MolecularFormulaManipulator.getMolecularFormula(formula, builder)));
Assert.assertEquals("CH6O", MolecularFormulaManipulator.getString(ff));
}
use of org.openscience.cdk.formula.MolecularFormula in project cdk by cdk.
the class MolecularFormulaManipulatorTest method testContainsElement_IMolecularFormula_IElement.
@Test
public void testContainsElement_IMolecularFormula_IElement() {
IMolecularFormula formula = new MolecularFormula();
IIsotope carb = builder.newInstance(IIsotope.class, "C");
IIsotope flu = builder.newInstance(IIsotope.class, "F");
IIsotope h1 = builder.newInstance(IIsotope.class, "H");
IIsotope h2 = builder.newInstance(IIsotope.class, "H");
h2.setExactMass(2.014101778);
formula.addIsotope(carb, 1);
formula.addIsotope(flu);
formula.addIsotope(h1, 1);
formula.addIsotope(h2, 2);
Assert.assertTrue(MolecularFormulaManipulator.containsElement(formula, builder.newInstance(IElement.class, "C")));
Assert.assertTrue(MolecularFormulaManipulator.containsElement(formula, builder.newInstance(IElement.class, "H")));
Assert.assertTrue(MolecularFormulaManipulator.containsElement(formula, builder.newInstance(IElement.class, "F")));
}
Aggregations