Search in sources :

Example 1 with MolecularFormula

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));
}
Also used : IIsotope(org.openscience.cdk.interfaces.IIsotope) IMolecularFormula(org.openscience.cdk.interfaces.IMolecularFormula) MolecularFormula(org.openscience.cdk.formula.MolecularFormula) IMolecularFormula(org.openscience.cdk.interfaces.IMolecularFormula) Test(org.junit.Test)

Example 2 with MolecularFormula

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));
}
Also used : IIsotope(org.openscience.cdk.interfaces.IIsotope) IElement(org.openscience.cdk.interfaces.IElement) IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) IMolecularFormula(org.openscience.cdk.interfaces.IMolecularFormula) MolecularFormula(org.openscience.cdk.formula.MolecularFormula) IMolecularFormula(org.openscience.cdk.interfaces.IMolecularFormula) IAtom(org.openscience.cdk.interfaces.IAtom) Test(org.junit.Test)

Example 3 with MolecularFormula

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));
}
Also used : IIsotope(org.openscience.cdk.interfaces.IIsotope) IMolecularFormula(org.openscience.cdk.interfaces.IMolecularFormula) MolecularFormula(org.openscience.cdk.formula.MolecularFormula) Test(org.junit.Test)

Example 4 with MolecularFormula

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));
}
Also used : IIsotope(org.openscience.cdk.interfaces.IIsotope) IMolecularFormula(org.openscience.cdk.interfaces.IMolecularFormula) MolecularFormula(org.openscience.cdk.formula.MolecularFormula) IMolecularFormula(org.openscience.cdk.interfaces.IMolecularFormula) Test(org.junit.Test)

Example 5 with MolecularFormula

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")));
}
Also used : IIsotope(org.openscience.cdk.interfaces.IIsotope) IMolecularFormula(org.openscience.cdk.interfaces.IMolecularFormula) MolecularFormula(org.openscience.cdk.formula.MolecularFormula) IMolecularFormula(org.openscience.cdk.interfaces.IMolecularFormula) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)81 MolecularFormula (org.openscience.cdk.formula.MolecularFormula)81 IMolecularFormula (org.openscience.cdk.interfaces.IMolecularFormula)81 IIsotope (org.openscience.cdk.interfaces.IIsotope)72 MolecularFormulaSet (org.openscience.cdk.formula.MolecularFormulaSet)11 IMolecularFormulaSet (org.openscience.cdk.interfaces.IMolecularFormulaSet)11 IAtom (org.openscience.cdk.interfaces.IAtom)9 IAtomContainer (org.openscience.cdk.interfaces.IAtomContainer)8 MolecularFormulaRange (org.openscience.cdk.formula.MolecularFormulaRange)6 Isotope (org.openscience.cdk.Isotope)5 IElement (org.openscience.cdk.interfaces.IElement)5 Atom (org.openscience.cdk.Atom)3 ArrayList (java.util.ArrayList)2 StringWriter (java.io.StringWriter)1 ReactionScheme (org.openscience.cdk.ReactionScheme)1 Isotopes (org.openscience.cdk.config.Isotopes)1 IReaction (org.openscience.cdk.interfaces.IReaction)1 IReactionScheme (org.openscience.cdk.interfaces.IReactionScheme)1 CMLWriter (org.openscience.cdk.io.CMLWriter)1