/** {@inheritDoc} */ @Override public void setFormalCharge(Integer charge) { logger.debug("Setting formal charge: ", charge); super.setFormalCharge(charge); }
/** * 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); }
/** * 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); }
/** * Tests whether the saturation checker gets a proton right. */ @Test public void testIsSaturated_Proton() throws Exception { // test H+ IAtomContainer m = new AtomContainer(); Atom h = new Atom("H"); h.setFormalCharge(+1); m.addAtom(h); Assert.assertTrue(satcheck.isSaturated(h, m)); }
@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()); }
@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()); }
@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()); }
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()); }
/** * Tests if the saturation checker gets a proton right. */ @Test public void testIsSaturated_Proton() throws Exception { // test H+ IAtomContainer mol = new AtomContainer(); CDKValencyChecker checker = CDKValencyChecker.getInstance(mol.getBuilder()); Atom hydrogen = new Atom("H"); hydrogen.setFormalCharge(+1); mol.addAtom(hydrogen); findAndConfigureAtomTypesForAllAtoms(mol); Assert.assertTrue(checker.isSaturated(mol)); }
@Test public void testAtomFormalCharge() throws Exception { IAtomContainer mol = new AtomContainer(); Atom atom = new Atom("N"); int formalCharge = +1; atom.setFormalCharge(formalCharge); mol.addAtom(atom); IAtomContainer roundTrippedMol = CMLRoundTripTool.roundTripMolecule(convertor, mol); Assert.assertEquals(1, roundTrippedMol.getAtomCount()); IAtom roundTrippedAtom = roundTrippedMol.getAtom(0); Assert.assertEquals(atom.getFormalCharge(), roundTrippedAtom.getFormalCharge()); }
/** * 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_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)); }
/** * 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)); }
@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()); }
/** TODO: check who added this test. I think Miguel; it seems to be a * resonance structure. */ @Test public void test1() throws Exception { IAtomContainer mol = new AtomContainer(); Atom f1 = new Atom("F"); Atom c2 = new Atom("C"); Atom c3 = new Atom("C"); f1.setFormalCharge(1); mol.addAtom(f1); mol.addAtom(c2); mol.addAtom(c3); mol.addBond(0, 1, IBond.Order.DOUBLE); mol.addBond(1, 2, IBond.Order.DOUBLE); CDKValencyChecker checker = CDKValencyChecker.getInstance(mol.getBuilder()); findAndConfigureAtomTypesForAllAtoms(mol); mol.getAtom(2).setImplicitHydrogenCount(2); // third atom Assert.assertTrue(checker.isSaturated(mol)); }
/** * A unit test for JUnit with F-[I-]-F. * * @cdk.bug 2323126 */ @Test public void testAtomHybridizationVSEPRDescriptorTest_6() throws ClassNotFoundException, CDKException, java.lang.Exception { AtomHybridizationVSEPRDescriptor descriptor = new AtomHybridizationVSEPRDescriptor(); //IF2- IAtomContainer molecule = new AtomContainer(); Atom I1 = new Atom("I"); I1.setFormalCharge(-1); Atom F2 = new Atom("F"); Atom F3 = new Atom("F"); molecule.addAtom(I1); molecule.addAtom(F2); molecule.addAtom(F3); Bond b1 = new Bond(I1, F2, IBond.Order.SINGLE); Bond b2 = new Bond(I1, F3, IBond.Order.SINGLE); molecule.addBond(b1); molecule.addBond(b2); assertAtomTypesPerceived(molecule); Assert.assertEquals(IAtomType.Hybridization.SP3D1.ordinal(), ((IntegerResult) descriptor.calculate(molecule.getAtom(0), molecule).getValue()).intValue()); }
/** * Tests if the saturation checker considers negative charges. */ @Test public void testIsSaturated_NegativelyChargedOxygen() throws Exception { // test methane with explicit hydrogen IAtomContainer mol = new AtomContainer(); CDKValencyChecker checker = CDKValencyChecker.getInstance(mol.getBuilder()); Atom c = new Atom("C"); Atom h1 = new Atom("H"); Atom h2 = new Atom("H"); Atom h3 = new Atom("H"); Atom o = new Atom("O"); o.setFormalCharge(-1); mol.addAtom(c); mol.addAtom(h1); mol.addAtom(h2); mol.addAtom(h3); mol.addAtom(o); mol.addBond(new Bond(c, h1)); mol.addBond(new Bond(c, h2)); mol.addBond(new Bond(c, h3)); mol.addBond(new Bond(c, o)); findAndConfigureAtomTypesForAllAtoms(mol); Assert.assertTrue(checker.isSaturated(mol)); }
/** * Tests if the saturation checker considers positive * charges. */ @Test public void testIsSaturated_PositivelyChargedNitrogen() throws Exception { // test methane with explicit hydrogen IAtomContainer mol = new AtomContainer(); CDKValencyChecker checker = CDKValencyChecker.getInstance(mol.getBuilder()); Atom n = new Atom("N"); Atom h1 = new Atom("H"); Atom h2 = new Atom("H"); Atom h3 = new Atom("H"); Atom h4 = new Atom("H"); n.setFormalCharge(+1); mol.addAtom(n); mol.addAtom(h1); mol.addAtom(h2); mol.addAtom(h3); mol.addAtom(h4); mol.addBond(new Bond(n, h1)); mol.addBond(new Bond(n, h2)); mol.addBond(new Bond(n, h3)); mol.addBond(new Bond(n, h4)); findAndConfigureAtomTypesForAllAtoms(mol); Assert.assertTrue(checker.isSaturated(mol)); }