Search in sources :

Example 16 with AtomContainer

use of org.openscience.cdk.AtomContainer in project cdk by cdk.

the class AtomContainerManipulatorTest method testRemoveHydrogensFromMolecularHydrogen.

/**
 * Molecular hydrogen is found in the first batch of PubChem entries, and
 * removal of hydrogen should simply return an empty IAtomContainer, not
 * throw an NullPointerException.
 *
 * - note now molecular hydrogen is preserved to avoid information loss.
 *
 * @cdk.bug 2366528
 */
@Test
public void testRemoveHydrogensFromMolecularHydrogen() {
    // molecular hydrogen
    IAtomContainer mol = new AtomContainer();
    mol.addAtom(new Atom("H"));
    mol.addAtom(new Atom("H"));
    mol.addBond(0, 1, IBond.Order.SINGLE);
    Assert.assertEquals(2, mol.getAtomCount());
    IAtomContainer ac = AtomContainerManipulator.removeHydrogens(mol);
    Assert.assertEquals(2, ac.getAtomCount());
}
Also used : IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) AtomContainer(org.openscience.cdk.AtomContainer) PseudoAtom(org.openscience.cdk.silent.PseudoAtom) IAtom(org.openscience.cdk.interfaces.IAtom) Atom(org.openscience.cdk.Atom) Test(org.junit.Test)

Example 17 with AtomContainer

use of org.openscience.cdk.AtomContainer in project cdk by cdk.

the class AtomContainerManipulatorTest method dontSuppressHydrogensOnPseudoAtoms.

@Test
public void dontSuppressHydrogensOnPseudoAtoms() throws Exception {
    // *[H]
    IAtomContainer mol = new AtomContainer();
    mol.addAtom(new PseudoAtom("*"));
    mol.addAtom(new Atom("H"));
    mol.getAtom(0).setImplicitHydrogenCount(0);
    mol.getAtom(1).setImplicitHydrogenCount(1);
    mol.addBond(0, 1, Order.SINGLE);
    Assert.assertEquals(2, mol.getAtomCount());
    IAtomContainer ac = AtomContainerManipulator.removeHydrogens(mol);
    Assert.assertEquals(2, ac.getAtomCount());
}
Also used : IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) AtomContainer(org.openscience.cdk.AtomContainer) PseudoAtom(org.openscience.cdk.silent.PseudoAtom) PseudoAtom(org.openscience.cdk.silent.PseudoAtom) IAtom(org.openscience.cdk.interfaces.IAtom) Atom(org.openscience.cdk.Atom) Test(org.junit.Test)

Example 18 with AtomContainer

use of org.openscience.cdk.AtomContainer in project cdk by cdk.

the class AtomContainerManipulatorTest method testRemoveHydrogensZeroHydrogenCounts.

@Test
public void testRemoveHydrogensZeroHydrogenCounts() throws IOException, ClassNotFoundException, CDKException {
    // ethene
    IAtomContainer mol = new AtomContainer();
    mol.addAtom(new Atom("C"));
    mol.addAtom(new Atom("C"));
    mol.addAtom(new Atom("Br"));
    mol.addAtom(new Atom("Br"));
    mol.addAtom(new Atom("H"));
    mol.addAtom(new Atom("H"));
    mol.addBond(0, 1, IBond.Order.DOUBLE);
    mol.addBond(0, 2, IBond.Order.SINGLE);
    mol.addBond(0, 3, IBond.Order.SINGLE);
    mol.addBond(1, 4, IBond.Order.SINGLE);
    mol.addBond(1, 5, IBond.Order.SINGLE);
    mol.getAtom(0).setImplicitHydrogenCount(0);
    mol.getAtom(1).setImplicitHydrogenCount(0);
    mol.getAtom(2).setImplicitHydrogenCount(0);
    mol.getAtom(3).setImplicitHydrogenCount(0);
    mol.getAtom(4).setImplicitHydrogenCount(0);
    mol.getAtom(5).setImplicitHydrogenCount(0);
    Assert.assertEquals(6, mol.getAtomCount());
    IAtomContainer ac = AtomContainerManipulator.removeHydrogens(mol);
    Assert.assertEquals(4, ac.getAtomCount());
    Assert.assertNotNull(ac.getAtom(0).getImplicitHydrogenCount());
    Assert.assertNotNull(ac.getAtom(1).getImplicitHydrogenCount());
    Assert.assertNotNull(ac.getAtom(2).getImplicitHydrogenCount());
    Assert.assertNotNull(ac.getAtom(3).getImplicitHydrogenCount());
    Assert.assertEquals(0, ac.getAtom(0).getImplicitHydrogenCount().intValue());
    Assert.assertEquals(2, ac.getAtom(1).getImplicitHydrogenCount().intValue());
    Assert.assertEquals(0, ac.getAtom(2).getImplicitHydrogenCount().intValue());
    Assert.assertEquals(0, ac.getAtom(3).getImplicitHydrogenCount().intValue());
}
Also used : IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) AtomContainer(org.openscience.cdk.AtomContainer) PseudoAtom(org.openscience.cdk.silent.PseudoAtom) IAtom(org.openscience.cdk.interfaces.IAtom) Atom(org.openscience.cdk.Atom) Test(org.junit.Test)

Example 19 with AtomContainer

use of org.openscience.cdk.AtomContainer in project cdk by cdk.

the class AtomContainerManipulatorTest method testGetAtomById_IAtomContainer_String.

@Test
public void testGetAtomById_IAtomContainer_String() throws Exception {
    // ethene
    IAtomContainer mol = new AtomContainer();
    mol.addAtom(new Atom("C"));
    mol.getAtom(0).setID("a1");
    mol.addAtom(new Atom("C"));
    mol.getAtom(1).setID("a2");
    mol.addAtom(new Atom("H"));
    mol.getAtom(2).setID("a3");
    mol.addAtom(new Atom("H"));
    mol.getAtom(3).setID("a4");
    mol.addAtom(new Atom("H"));
    mol.getAtom(4).setID("a5");
    mol.addAtom(new Atom("H"));
    mol.getAtom(5).setID("a6");
    mol.addBond(0, 1, IBond.Order.DOUBLE);
    mol.addBond(0, 2, IBond.Order.SINGLE);
    mol.addBond(0, 3, IBond.Order.SINGLE);
    mol.addBond(1, 4, IBond.Order.DOUBLE);
    mol.addBond(1, 5, IBond.Order.DOUBLE);
    mol.setFlag(CDKConstants.ISAROMATIC, true);
    Assert.assertEquals(mol.getAtom(0), AtomContainerManipulator.getAtomById(mol, "a1"));
    Assert.assertEquals(mol.getAtom(1), AtomContainerManipulator.getAtomById(mol, "a2"));
    Assert.assertEquals(mol.getAtom(2), AtomContainerManipulator.getAtomById(mol, "a3"));
    Assert.assertEquals(mol.getAtom(3), AtomContainerManipulator.getAtomById(mol, "a4"));
    Assert.assertEquals(mol.getAtom(4), AtomContainerManipulator.getAtomById(mol, "a5"));
    Assert.assertEquals(mol.getAtom(5), AtomContainerManipulator.getAtomById(mol, "a6"));
}
Also used : IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) AtomContainer(org.openscience.cdk.AtomContainer) PseudoAtom(org.openscience.cdk.silent.PseudoAtom) IAtom(org.openscience.cdk.interfaces.IAtom) Atom(org.openscience.cdk.Atom) Test(org.junit.Test)

Example 20 with AtomContainer

use of org.openscience.cdk.AtomContainer in project cdk by cdk.

the class AtomContainerSetManipulatorTest method setUp.

@Before
public void setUp() {
    mol1 = new AtomContainer();
    atomInMol1 = new Atom("Cl");
    atomInMol1.setCharge(-1.0);
    atomInMol1.setFormalCharge(-1);
    atomInMol1.setImplicitHydrogenCount(1);
    mol1.addAtom(atomInMol1);
    mol1.addAtom(new Atom("Cl"));
    bondInMol1 = new Bond(atomInMol1, mol1.getAtom(1));
    mol1.addBond(bondInMol1);
    mol2 = new AtomContainer();
    atomInMol2 = new Atom("O");
    atomInMol2.setImplicitHydrogenCount(2);
    mol2.addAtom(atomInMol2);
    som.addAtomContainer(mol1);
    som.addAtomContainer(mol2);
}
Also used : IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) AtomContainer(org.openscience.cdk.AtomContainer) Bond(org.openscience.cdk.Bond) IBond(org.openscience.cdk.interfaces.IBond) Atom(org.openscience.cdk.Atom) IAtom(org.openscience.cdk.interfaces.IAtom) Before(org.junit.Before)

Aggregations

AtomContainer (org.openscience.cdk.AtomContainer)743 IAtomContainer (org.openscience.cdk.interfaces.IAtomContainer)730 Test (org.junit.Test)641 IAtom (org.openscience.cdk.interfaces.IAtom)556 Atom (org.openscience.cdk.Atom)523 PseudoAtom (org.openscience.cdk.PseudoAtom)206 IBond (org.openscience.cdk.interfaces.IBond)136 Bond (org.openscience.cdk.Bond)90 Point2d (javax.vecmath.Point2d)86 InputStream (java.io.InputStream)80 IQueryAtomContainer (org.openscience.cdk.isomorphism.matchers.IQueryAtomContainer)61 QueryAtomContainer (org.openscience.cdk.isomorphism.matchers.QueryAtomContainer)57 MDLV2000Reader (org.openscience.cdk.io.MDLV2000Reader)44 SimpleChemObjectReaderTest (org.openscience.cdk.test.io.SimpleChemObjectReaderTest)43 ByteArrayInputStream (java.io.ByteArrayInputStream)41 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)32 SlowTest (org.openscience.cdk.test.SlowTest)32 Point3d (javax.vecmath.Point3d)30 IPseudoAtom (org.openscience.cdk.interfaces.IPseudoAtom)29 DoubleArrayResult (org.openscience.cdk.qsar.result.DoubleArrayResult)23