/** {@inheritDoc} */ @Override public void setImplicitHydrogenCount(Integer hydrogenCount) { logger.debug("Setting hydrogen count: ", hydrogenCount); super.setImplicitHydrogenCount(hydrogenCount); }
/** * Create a new atom with of the specified element, hydrogen count, and formal charge. * * @param elem atomic number * @param hcnt hydrogen count * @param fchg formal charge */ public Atom(int elem, int hcnt, int fchg) { super((String)null); setAtomicNumber(elem); setSymbol(Elements.ofNumber(elem).symbol()); setImplicitHydrogenCount(hcnt); setFormalCharge(fchg); }
/** * Create a new atom with of the specified element, hydrogen count, and formal charge. * * @param elem atomic number * @param hcnt hydrogen count * @param fchg formal charge */ public Atom(int elem, int hcnt, int fchg) { super((String)null); setAtomicNumber(elem); setSymbol(Elements.ofNumber(elem).symbol()); setImplicitHydrogenCount(hcnt); setFormalCharge(fchg); }
@Test public void testPossibleAtomTypes_IAtomContainer_IAtom() throws java.lang.Exception { IAtomContainer mol = new AtomContainer(); Atom atom = new Atom("C"); atom.setImplicitHydrogenCount(3); Atom atom2 = new Atom("N"); atom2.setImplicitHydrogenCount(2); mol.addAtom(atom); mol.addAtom(atom2); mol.addBond(new Bond(atom, atom2, IBond.Order.SINGLE)); StructGenAtomTypeGuesser atm = new StructGenAtomTypeGuesser(); List<IAtomType> matched = atm.possibleAtomTypes(mol, atom); Assert.assertNotNull(matched); Assert.assertTrue(matched.size() > 0); Assert.assertTrue(matched.get(0) instanceof IAtomType); Assert.assertEquals("C", ((IAtomType) matched.get(0)).getSymbol()); }
@Test public void testGetTotalHydrogenCount_ImplicitHydrogens() throws Exception { IAtomContainer mol = new AtomContainer(); Atom carbon = new Atom("C"); carbon.setImplicitHydrogenCount(4); mol.addAtom(carbon); Assert.assertEquals(4, AtomContainerManipulator.getTotalHydrogenCount(mol)); }
/** * A unit test for JUnit */ @Test public void testSaturate() throws Exception { // test ethene Atom c1 = new Atom("C"); c1.setImplicitHydrogenCount(2); Atom c2 = new Atom("C"); c2.setImplicitHydrogenCount(2); Bond b = new Bond(c1, c2, IBond.Order.SINGLE); // force single bond, saturate() must fix that IAtomContainer m = new AtomContainer(); m.addAtom(c1); m.addAtom(c2); m.addBond(b); satcheck.saturate(m); Assert.assertEquals(IBond.Order.DOUBLE, b.getOrder()); }
@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()); }
/** * A unit test for JUnit */ @Test public void testAllSaturated_Methanethiol() throws Exception { // test Methanethiol, CH4S Atom c = new Atom("C"); c.setImplicitHydrogenCount(3); Atom s = new Atom("S"); s.setImplicitHydrogenCount(1); Bond b1 = new Bond(c, s, IBond.Order.SINGLE); IAtomContainer m = new AtomContainer(); m.addAtom(c); m.addAtom(s); m.addBond(b1); for (int i = 0; i < 1; i++) { LonePair lp = new LonePair(s); m.addLonePair(lp); } AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(m); Assert.assertFalse(lpcheck.allSaturated(m)); }
/** * A unit test for JUnit */ @Test public void testNewSaturate_Methyl_alcohol_protonated() throws Exception { // test Methyl alcohol protonated, CH3OH2+ Atom c1 = new Atom("C"); c1.setImplicitHydrogenCount(3); Atom o = new Atom("O"); o.setFormalCharge(+1); o.setImplicitHydrogenCount(2); Bond b1 = new Bond(c1, o, IBond.Order.SINGLE); IAtomContainer m = new AtomContainer(); m.addAtom(c1); m.addAtom(o); m.addBond(b1); AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(m); lpcheck.saturate(m); Assert.assertEquals(1, m.getConnectedLonePairsCount(o)); }
/** * A unit test for JUnit */ @Test public void testNewSaturate_methylamine_radical_cation() throws Exception { // test Ammonia, CH3NH3+ Atom c = new Atom("C"); c.setImplicitHydrogenCount(3); Atom n = new Atom("N"); n.setImplicitHydrogenCount(3); n.setFormalCharge(+1); Bond b1 = new Bond(c, n, IBond.Order.SINGLE); IAtomContainer m = new AtomContainer(); m.addAtom(c); m.addAtom(n); m.addBond(b1); AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(m); lpcheck.saturate(m); Assert.assertEquals(0, m.getConnectedLonePairsCount(n)); }
@Test public void testN3() throws Exception { IAtomContainer mol = new AtomContainer(); Atom atom = new Atom("N"); atom.setImplicitHydrogenCount(3); mol.addAtom(atom); StructGenMatcher atm = new StructGenMatcher(); IAtomType matched = atm.findMatchingAtomType(mol, atom); Assert.assertNotNull(matched); Assert.assertEquals("N", matched.getSymbol()); }
/** * A unit test for JUnit */ @Test public void testNewSaturate_Ammonia() throws Exception { // test Ammonia, H3N Atom n = new Atom("N"); n.setImplicitHydrogenCount(3); IAtomContainer m = new AtomContainer(); m.addAtom(n); AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(m); lpcheck.saturate(m); Assert.assertEquals(1, m.getConnectedLonePairsCount(n)); }
/** * A unit test for JUnit */ @Test public void testNewSaturate_Methyl_alcohol() throws Exception { // test Methyl chloride, CH3OH Atom c1 = new Atom("C"); c1.setImplicitHydrogenCount(3); Atom o = new Atom("O"); o.setImplicitHydrogenCount(1); Bond b1 = new Bond(c1, o, IBond.Order.SINGLE); IAtomContainer m = new AtomContainer(); m.addAtom(c1); m.addAtom(o); m.addBond(b1); AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(m); lpcheck.saturate(m); Assert.assertEquals(2, m.getConnectedLonePairsCount(o)); Assert.assertEquals(0, m.getConnectedLonePairsCount(c1)); }
@Test public void testIsSaturated_MissingHydrogens_Methane() throws Exception { // test methane with explicit hydrogen IAtomContainer mol = new AtomContainer(); CDKValencyChecker checker = CDKValencyChecker.getInstance(mol.getBuilder()); Atom c = new Atom("C"); mol.addAtom(c); c.setImplicitHydrogenCount(3); findAndConfigureAtomTypesForAllAtoms(mol); Assert.assertFalse(checker.isSaturated(mol)); }
/** * A unit test for JUnit */ @Test public void testPartitioning() throws Exception { String smiles = ""; IAtomContainer molecule = new AtomContainer(); SmilesGenerator sg = new SmilesGenerator(); Atom sodium = new Atom("Na"); sodium.setFormalCharge(+1); Atom hydroxyl = new Atom("O"); hydroxyl.setImplicitHydrogenCount(1); hydroxyl.setFormalCharge(-1); molecule.addAtom(sodium); molecule.addAtom(hydroxyl); addImplicitHydrogens(molecule); smiles = sg.create(molecule); Assert.assertTrue(smiles.indexOf(".") != -1); }
/** * @cdk.bug 1713398 */ @Test public void testHydrogenCount_UNSET() throws Exception { IAtomContainer mol = new AtomContainer(); Atom atom = new Atom("N"); atom.setImplicitHydrogenCount((Integer) CDKConstants.UNSET); mol.addAtom(atom); IAtomContainer roundTrippedMol = CMLRoundTripTool.roundTripMolecule(convertor, mol); Assert.assertEquals(1, roundTrippedMol.getAtomCount()); IAtom roundTrippedAtom = roundTrippedMol.getAtom(0); Assert.assertEquals(CDKConstants.UNSET, roundTrippedAtom.getImplicitHydrogenCount()); }
/** * @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()); }
/** * A unit test for JUnit */ @Test public void testNewSaturate_methoxide_anion() throws Exception { // test methoxide anion, CH3O- Atom c1 = new Atom("C"); c1.setImplicitHydrogenCount(3); Atom o = new Atom("O"); o.setFormalCharge(-1); Bond b1 = new Bond(c1, o, IBond.Order.SINGLE); IAtomContainer m = new AtomContainer(); m.addAtom(c1); m.addAtom(o); m.addBond(b1); AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(m); lpcheck.saturate(m); Assert.assertEquals(3, m.getConnectedLonePairsCount(o)); }
/** * A unit test for JUnit */ @Test public void testNewSaturate_Methyl_chloride() throws Exception { // test Methyl chloride, CH3Cl Atom c1 = new Atom("C"); c1.setImplicitHydrogenCount(3); Atom cl = new Atom("Cl"); Bond b1 = new Bond(c1, cl, IBond.Order.SINGLE); IAtomContainer m = new AtomContainer(); m.addAtom(c1); m.addAtom(cl); m.addBond(b1); AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(m); lpcheck.saturate(m); Assert.assertEquals(3, m.getConnectedLonePairsCount(cl)); Assert.assertEquals(0, m.getConnectedLonePairsCount(c1)); }