/** {@inheritDoc} */ @Override public Integer getImplicitHydrogenCount() { logger.debug("Getting hydrogen count: ", super.getImplicitHydrogenCount()); return super.getImplicitHydrogenCount(); }
@Test public void testNewAtomImplicitHydrogenCount() { Assert.assertNull(new Atom("C").getImplicitHydrogenCount()); Assert.assertNull(new Atom("*").getImplicitHydrogenCount()); Assert.assertNull(new Atom("H").getImplicitHydrogenCount()); Assert.assertNull(new Atom("D").getImplicitHydrogenCount()); Assert.assertNull(new Atom("T").getImplicitHydrogenCount()); } }
@Test public void testAmmonia() throws Exception { IAtomContainer mol = new AtomContainer(); Atom nitrogen = new Atom("N"); mol.addAtom(nitrogen); IAtomType type = matcher.findMatchingAtomType(mol, nitrogen); Assert.assertNotNull(type); AtomTypeManipulator.configure(nitrogen, type); adder.addImplicitHydrogens(mol); Assert.assertNotNull(nitrogen.getImplicitHydrogenCount()); Assert.assertEquals(3, nitrogen.getImplicitHydrogenCount().intValue()); }
@Test public void testSulphur() throws Exception { IAtomContainer mol = new AtomContainer(); Atom atom = new Atom("S"); mol.addAtom(atom); IAtomType type = matcher.findMatchingAtomType(mol, atom); Assert.assertNotNull(type); AtomTypeManipulator.configure(atom, type); Assert.assertNotEquals((Integer) 2, atom.getImplicitHydrogenCount()); adder.addImplicitHydrogens(mol); Assert.assertEquals(1, mol.getAtomCount()); Assert.assertNotNull(atom.getImplicitHydrogenCount()); Assert.assertEquals(2, atom.getImplicitHydrogenCount().intValue()); }
@Test public void testWater() throws Exception { IAtomContainer mol = new AtomContainer(); Atom oxygen = new Atom("O"); mol.addAtom(oxygen); IAtomType type = matcher.findMatchingAtomType(mol, oxygen); Assert.assertNotNull(type); AtomTypeManipulator.configure(oxygen, type); adder.addImplicitHydrogens(mol); Assert.assertNotNull(oxygen.getImplicitHydrogenCount()); Assert.assertEquals(2, oxygen.getImplicitHydrogenCount().intValue()); }
@Test public void testHydroxonium() throws Exception { IAtomContainer mol = new AtomContainer(); Atom oxygen = new Atom("O"); oxygen.setFormalCharge(+1); mol.addAtom(oxygen); IAtomType type = matcher.findMatchingAtomType(mol, oxygen); Assert.assertNotNull(type); AtomTypeManipulator.configure(oxygen, type); adder.addImplicitHydrogens(mol); Assert.assertNotNull(oxygen.getImplicitHydrogenCount()); Assert.assertEquals(3, oxygen.getImplicitHydrogenCount().intValue()); }
private void halogenTest(String halogen) throws Exception { IAtomContainer mol = new AtomContainer(); Atom atom = new Atom(halogen); mol.addAtom(atom); IAtomType type = matcher.findMatchingAtomType(mol, atom); Assert.assertNotNull(type); AtomTypeManipulator.configure(atom, type); adder.addImplicitHydrogens(mol); Assert.assertEquals(1, mol.getAtomCount()); Assert.assertNotNull(atom.getImplicitHydrogenCount()); Assert.assertEquals(1, atom.getImplicitHydrogenCount().intValue()); }
@Test public void testAmmonium() throws Exception { IAtomContainer mol = new AtomContainer(); Atom nitrogen = new Atom("N"); nitrogen.setFormalCharge(+1); mol.addAtom(nitrogen); IAtomType type = matcher.findMatchingAtomType(mol, nitrogen); Assert.assertNotNull(type); AtomTypeManipulator.configure(nitrogen, type); adder.addImplicitHydrogens(mol); Assert.assertNotNull(nitrogen.getImplicitHydrogenCount()); Assert.assertEquals(4, nitrogen.getImplicitHydrogenCount().intValue()); }
@Test public void testHydroxyl() throws Exception { IAtomContainer mol = new AtomContainer(); Atom oxygen = new Atom("O"); oxygen.setFormalCharge(-1); mol.addAtom(oxygen); IAtomType type = matcher.findMatchingAtomType(mol, oxygen); Assert.assertNotNull(type); AtomTypeManipulator.configure(oxygen, type); adder.addImplicitHydrogens(mol); Assert.assertNotNull(oxygen.getImplicitHydrogenCount()); Assert.assertEquals(1, oxygen.getImplicitHydrogenCount().intValue()); }
private void negativeHalogenTest(String halogen) throws Exception { IAtomContainer mol = new AtomContainer(); Atom atom = new Atom(halogen); atom.setFormalCharge(-1); mol.addAtom(atom); IAtomType type = matcher.findMatchingAtomType(mol, atom); Assert.assertNotNull(type); AtomTypeManipulator.configure(atom, type); adder.addImplicitHydrogens(mol); Assert.assertEquals(1, mol.getAtomCount()); Assert.assertNotNull(atom.getImplicitHydrogenCount()); Assert.assertEquals(0, atom.getImplicitHydrogenCount().intValue()); }
@Test public void testaddImplicitHydrogensToSatisfyValency_OldValue() throws Exception { IAtomContainer mol = new AtomContainer(); mol.addAtom(new Atom("C")); Atom oxygen = new Atom("O"); mol.addAtom(oxygen); mol.addAtom(new Atom("C")); mol.addBond(0, 1, IBond.Order.SINGLE); mol.addBond(1, 2, IBond.Order.SINGLE); findAndConfigureAtomTypesForAllAtoms(mol); adder.addImplicitHydrogens(mol); Assert.assertNotNull(oxygen.getImplicitHydrogenCount()); Assert.assertEquals(0, oxygen.getImplicitHydrogenCount().intValue()); }
@Test public void testEthyne() throws Exception { IAtomContainer mol = new AtomContainer(); Atom carbon1 = new Atom("C"); Atom carbon2 = new Atom("C"); Bond b = new Bond(carbon1, carbon2, IBond.Order.TRIPLE); mol.addAtom(carbon1); mol.addAtom(carbon2); mol.addBond(b); findAndConfigureAtomTypesForAllAtoms(mol); adder.addImplicitHydrogens(mol); Assert.assertEquals(2, mol.getAtomCount()); Assert.assertEquals(1, mol.getBondCount()); Assert.assertEquals(1, carbon1.getImplicitHydrogenCount().intValue()); Assert.assertEquals(1, carbon2.getImplicitHydrogenCount().intValue()); }
@Test public void testEthane() throws Exception { IAtomContainer mol = new AtomContainer(); Atom carbon1 = new Atom("C"); Atom carbon2 = new Atom("C"); Bond b = new Bond(carbon1, carbon2, IBond.Order.SINGLE); mol.addAtom(carbon1); mol.addAtom(carbon2); mol.addBond(b); findAndConfigureAtomTypesForAllAtoms(mol); adder.addImplicitHydrogens(mol); Assert.assertEquals(2, mol.getAtomCount()); Assert.assertEquals(1, mol.getBondCount()); Assert.assertEquals(3, carbon1.getImplicitHydrogenCount().intValue()); Assert.assertEquals(3, carbon2.getImplicitHydrogenCount().intValue()); }
@Test public void testEthene() throws Exception { IAtomContainer mol = new AtomContainer(); Atom carbon1 = new Atom("C"); Atom carbon2 = new Atom("C"); Bond b = new Bond(carbon1, carbon2, IBond.Order.DOUBLE); mol.addAtom(carbon1); mol.addAtom(carbon2); mol.addBond(b); findAndConfigureAtomTypesForAllAtoms(mol); adder.addImplicitHydrogens(mol); Assert.assertEquals(2, mol.getAtomCount()); Assert.assertEquals(1, mol.getBondCount()); Assert.assertEquals(2, carbon1.getImplicitHydrogenCount().intValue()); Assert.assertEquals(2, carbon2.getImplicitHydrogenCount().intValue()); }
@Test public void testEthaneWithPresetImplicitHCount() throws Exception { IAtomContainer mol = new AtomContainer(); Atom carbon1 = new Atom("C"); Atom carbon2 = new Atom("C"); Bond b = new Bond(carbon1, carbon2, IBond.Order.SINGLE); mol.addAtom(carbon1); mol.addAtom(carbon2); mol.addBond(b); carbon1.setImplicitHydrogenCount(3); carbon2.setImplicitHydrogenCount(3); AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(mol); adder.addImplicitHydrogens(mol); Assert.assertEquals(2, mol.getAtomCount()); Assert.assertEquals(1, mol.getBondCount()); Assert.assertEquals(3, carbon1.getImplicitHydrogenCount().intValue()); Assert.assertEquals(3, carbon2.getImplicitHydrogenCount().intValue()); }
@Test public void testNaCl() throws Exception { IAtomContainer mol = new AtomContainer(); Atom cl = new Atom("Cl"); cl.setFormalCharge(-1); mol.addAtom(cl); Atom na = new Atom("Na"); na.setFormalCharge(+1); mol.addAtom(na); findAndConfigureAtomTypesForAllAtoms(mol); adder.addImplicitHydrogens(mol); Assert.assertEquals(2, mol.getAtomCount()); Assert.assertEquals(0, AtomContainerManipulator.getTotalHydrogenCount(mol)); Assert.assertEquals(0, mol.getConnectedBondsCount(cl)); Assert.assertEquals(0, cl.getImplicitHydrogenCount().intValue()); Assert.assertEquals(0, mol.getConnectedBondsCount(na)); Assert.assertEquals(0, na.getImplicitHydrogenCount().intValue()); }
@Test public void testHydrogen() throws Exception { IAtomContainer mol = new AtomContainer(); Atom proton = new Atom("H"); mol.addAtom(proton); IAtomType type = matcher.findMatchingAtomType(mol, proton); Assert.assertNotNull(type); AtomTypeManipulator.configure(proton, type); adder.addImplicitHydrogens(mol); Assert.assertEquals(1, mol.getAtomCount()); IMolecularFormula formula = MolecularFormulaManipulator.getMolecularFormula(mol); Assert.assertEquals(2, MolecularFormulaManipulator.getElementCount(formula, mol.getBuilder().newInstance(IElement.class, "H"))); Assert.assertEquals(0, mol.getConnectedBondsCount(proton)); Assert.assertNotNull(proton.getImplicitHydrogenCount()); Assert.assertEquals(1, proton.getImplicitHydrogenCount().intValue()); }
@Test public void testProton() throws Exception { IAtomContainer mol = new AtomContainer(); Atom proton = new Atom("H"); proton.setFormalCharge(+1); mol.addAtom(proton); IAtomType type = matcher.findMatchingAtomType(mol, proton); Assert.assertNotNull(type); AtomTypeManipulator.configure(proton, type); adder.addImplicitHydrogens(mol); Assert.assertEquals(1, mol.getAtomCount()); IMolecularFormula formula = MolecularFormulaManipulator.getMolecularFormula(mol); Assert.assertEquals(1, MolecularFormulaManipulator.getElementCount(formula, mol.getBuilder().newInstance(IElement.class, "H"))); Assert.assertEquals(0, mol.getConnectedBondsCount(proton)); Assert.assertNotNull(proton.getImplicitHydrogenCount()); Assert.assertEquals(0, proton.getImplicitHydrogenCount().intValue()); }
/** * @cdk.bug 1713398 */ @Test public void testHydrogenCount() throws Exception { IAtomContainer mol = new AtomContainer(); Atom atom = new Atom("N"); atom.setImplicitHydrogenCount(3); mol.addAtom(atom); IAtomContainer roundTrippedMol = CMLRoundTripTool.roundTripMolecule(convertor, mol); Assert.assertEquals(1, roundTrippedMol.getAtomCount()); IAtom roundTrippedAtom = roundTrippedMol.getAtom(0); Assert.assertEquals(atom.getImplicitHydrogenCount(), roundTrippedAtom.getImplicitHydrogenCount()); }
/** * Test roundtripping of Unset property (Hydrogencount). * @throws Exception */ @Test public void testUnsetHydrogenCount() throws Exception { IAtomContainer mol = new AtomContainer(); Atom atom = new Atom("C"); atom.setImplicitHydrogenCount(null); Assert.assertNull(atom.getImplicitHydrogenCount()); mol.addAtom(atom); IAtomContainer roundTrippedMol = CMLRoundTripTool.roundTripMolecule(convertor, mol); Assert.assertEquals(1, roundTrippedMol.getAtomCount()); IAtom roundTrippedAtom = roundTrippedMol.getAtom(0); Assert.assertNull(roundTrippedAtom.getImplicitHydrogenCount()); }