@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()); } }
/** * 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); }
@Test public void testHas2DCoordinates_IBond() { Atom atom1 = new Atom("C"); atom1.setPoint2d(new Point2d(1, 1)); Atom atom2 = new Atom("C"); atom2.setPoint2d(new Point2d(1, 0)); IBond bond = new Bond(atom1, atom2); Assert.assertTrue(GeometryUtil.has2DCoordinates(bond)); atom1 = new Atom("C"); atom1.setPoint3d(new Point3d(1, 1, 1)); atom2 = new Atom("C"); atom2.setPoint3d(new Point3d(1, 0, 5)); bond = new Bond(atom1, atom2); Assert.assertFalse(GeometryUtil.has2DCoordinates(bond)); }
/** * 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); }
public String toString() { StringBuffer stringContent = new StringBuffer(64); stringContent.append("Atom(").append(hashCode()); if (getSymbol() != null) { stringContent.append(", S:").append(getSymbol()); if (getImplicitHydrogenCount() != null) { stringContent.append(", H:").append(getImplicitHydrogenCount()); if (getStereoParity() != null) { stringContent.append(", SP:").append(getStereoParity()); if (getPoint2d() != null) { stringContent.append(", 2D:[").append(getPoint2d()).append(']'); if (getPoint3d() != null) { stringContent.append(", 3D:[").append(getPoint3d()).append(']'); if (getFractionalPoint3d() != null) { stringContent.append(", F3D:[").append(getFractionalPoint3d()); if (getCharge() != null) { stringContent.append(", C:").append(getCharge());
/** * Clones this atom object and its content. * * @return The cloned object */ @Override public IAtom clone() throws CloneNotSupportedException { Object clone = super.clone(); if (point2d != null) { ((Atom) clone).setPoint2d(new Point2d(point2d.x, point2d.y)); } if (point3d != null) { ((Atom) clone).setPoint3d(new Point3d(point3d.x, point3d.y, point3d.z)); } if (fractionalPoint3d != null) { ((Atom) clone).setFractionalPoint3d(new Point3d(fractionalPoint3d.x, fractionalPoint3d.y, fractionalPoint3d.z)); } return (IAtom) clone; }
@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)); }
static IAtom atom(String symbol, int hCount) { IAtom a = new Atom(symbol); a.setImplicitHydrogenCount(hCount); return a; } }
/** * 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()); }
Atom c = new Atom("C"); mol.addAtom(c); c.setPoint3d(c_coord); Atom f = new Atom("F"); mol.addAtom(f); f.setPoint3d(f_coord); Atom h1 = new Atom("H"); mol.addAtom(h1); h1.setPoint3d(h1_coord); Atom h2 = new Atom("H"); mol.addAtom(h2); h2.setPoint3d(h2_coord); Atom h3 = new Atom("H"); mol.addAtom(h3); h3.setPoint3d(h3_coord);
@Test public void testTranslateAllPositive_IAtomContainer_HashMap() { Atom atom1 = new Atom("C"); atom1.setPoint2d(new Point2d(-1, -1)); Atom atom2 = new Atom("C"); atom2.setPoint2d(new Point2d(1, 0)); IAtomContainer ac = DefaultChemObjectBuilder.getInstance().newInstance(IAtomContainer.class); ac.addAtom(atom1); ac.addAtom(atom2); GeometryUtil.translateAllPositive(ac); Assert.assertEquals(atom1.getPoint2d().x, 0.0, 0.01); Assert.assertEquals(atom1.getPoint2d().y, 0.0, 0.01); Assert.assertEquals(atom2.getPoint2d().x, 2.0, 0.01); Assert.assertEquals(atom2.getPoint2d().y, 1.0, 0.01); }
@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 testSFBug956923_nonAromatic() throws Exception { String smiles = ""; IAtomContainer molecule = new AtomContainer(); SmilesGenerator sg = new SmilesGenerator(); Atom sp2CarbonWithOneHydrogen = new Atom("C"); sp2CarbonWithOneHydrogen.setHybridization(IAtomType.Hybridization.SP2); sp2CarbonWithOneHydrogen.setImplicitHydrogenCount(1); molecule.addAtom(sp2CarbonWithOneHydrogen); molecule.addAtom((Atom) sp2CarbonWithOneHydrogen.clone()); molecule.addAtom((Atom) sp2CarbonWithOneHydrogen.clone()); molecule.addAtom((Atom) sp2CarbonWithOneHydrogen.clone()); molecule.addAtom((Atom) sp2CarbonWithOneHydrogen.clone()); molecule.addAtom((Atom) sp2CarbonWithOneHydrogen.clone()); molecule.addBond(0, 1, IBond.Order.SINGLE); molecule.addBond(1, 2, IBond.Order.SINGLE); molecule.addBond(2, 3, IBond.Order.SINGLE); molecule.addBond(3, 4, IBond.Order.SINGLE); molecule.addBond(4, 5, IBond.Order.SINGLE); molecule.addBond(5, 0, IBond.Order.SINGLE); smiles = sg.create(molecule); Assert.assertEquals("[CH]1[CH][CH][CH][CH][CH]1", smiles); }
@Test public void testRotate_IAtom_Point3d_Point3d_double() { Atom atom1 = new Atom("C"); atom1.setPoint3d(new Point3d(1, 1, 0)); GeometryUtil.rotate(atom1, new Point3d(2, 0, 0), new Point3d(2, 2, 0), 90); assertEquals(new Point3d(2.0, 1.0, 1.0), atom1.getPoint3d(), 0.2); }
@Test public void testCalculate_RDFWeightFunction2() { RDFCalculator calculator = new RDFCalculator(0.0, 5.0, 0.1, 0.0, new IRDFWeightFunction() { @Override public double calculate(org.openscience.cdk.interfaces.IAtom atom, org.openscience.cdk.interfaces.IAtom atom2) { return atom.getCharge() * atom2.getCharge(); } }); AtomContainer h2mol = new org.openscience.cdk.AtomContainer(); Atom h1 = new Atom("H"); h1.setPoint3d(new Point3d(-0.5, 0.0, 0.0)); h1.setCharge(+1.0); Atom h2 = new Atom("H"); h2.setPoint3d(new Point3d(0.5, 0.0, 0.0)); h2.setCharge(-1.0); h2mol.addAtom(h1); h2mol.addAtom(h2); double[] rdf1 = calculator.calculate(h2mol, h1); double[] rdf2 = calculator.calculate(h2mol, h2); // test whether the double array length is ok Assert.assertEquals(51, rdf1.length); // test whether the RDFs are identical Assert.assertEquals(rdf1.length, rdf2.length); for (int i = 0; i < rdf1.length; i++) { Assert.assertEquals(rdf1[i], rdf2[i], 0.00001); } }
@Test public void testAtom2DAnd3D() throws Exception { IAtomContainer mol = new AtomContainer(); Atom atom = new Atom("N"); Point2d p2d = new Point2d(1.3, 1.4); atom.setPoint2d(p2d); Point3d p3d = new Point3d(1.3, 1.4, 0.9); atom.setPoint3d(p3d); mol.addAtom(atom); IAtomContainer roundTrippedMol = CMLRoundTripTool.roundTripMolecule(convertor, mol); Assert.assertEquals(1, roundTrippedMol.getAtomCount()); IAtom roundTrippedAtom = roundTrippedMol.getAtom(0); assertEquals(atom.getPoint2d(), roundTrippedAtom.getPoint2d(), 0.00001); assertEquals(atom.getPoint3d(), roundTrippedAtom.getPoint3d(), 0.00001); }
@Test public void testIsSaturated_MissingBondOrders_Ethane() throws Exception { // test ethane with explicit hydrogen IAtomContainer mol = new AtomContainer(); CDKValencyChecker checker = CDKValencyChecker.getInstance(mol.getBuilder()); Atom c1 = new Atom("C"); c1.setImplicitHydrogenCount(2); c1.setHybridization(IAtomType.Hybridization.SP2); Atom c2 = new Atom("C"); c2.setHybridization(IAtomType.Hybridization.SP2); c2.setImplicitHydrogenCount(2); mol.addAtom(c1); mol.addAtom(c2); IBond bond = new Bond(c1, c2, Order.SINGLE); mol.addBond(bond); findAndConfigureAtomTypesForAllAtoms(mol); Assert.assertFalse(checker.isSaturated(mol)); // sanity check bond.setOrder(Order.DOUBLE); 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()); }
/** {@inheritDoc} */ @Override public void setFormalCharge(Integer charge) { logger.debug("Setting formal charge: ", charge); super.setFormalCharge(charge); }