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());
}
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());
}
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());
}
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"));
}
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);
}
Aggregations