/** * {@inheritDoc} */ @Override public void addAtom(IAtom atom) { logger.debug("Adding atom: ", atom); super.addAtom(atom); }
/** * Adds the atom oAtom to a specified Monomer. * * @param oAtom The atom to add * @param oMonomer The monomer the atom belongs to */ @Override public void addAtom(IAtom oAtom, IMonomer oMonomer) { if (!contains(oAtom)) { super.addAtom(oAtom); if (oMonomer != null) { // Not sure what's better here...throw nullpointer exception? oMonomer.addAtom(oAtom); if (!monomers.containsKey(oMonomer.getMonomerName())) { monomers.put(oMonomer.getMonomerName(), oMonomer); } } } /* * notifyChanged() is called by addAtom in AtomContainer */ }
/** * Adds the atom oAtom to a specified Monomer. * * @param oAtom The atom to add * @param oMonomer The monomer the atom belongs to */ @Override public void addAtom(IAtom oAtom, IMonomer oMonomer) { if (!contains(oAtom)) { super.addAtom(oAtom); if (oMonomer != null) { // Not sure what's better here...throw nullpointer exception? oMonomer.addAtom(oAtom); if (!monomers.containsKey(oMonomer.getMonomerName())) { monomers.put(oMonomer.getMonomerName(), oMonomer); } } } /* * notifyChanged() is called by addAtom in AtomContainer */ }
/** * * Adds the atom oAtom to a specific Monomer. * * @param oAtom The atom to add * @param oMonomer The monomer the atom belongs to * */ @Override public void addAtom(IAtom oAtom, IMonomer oMonomer) { int atomCount = super.getAtomCount(); // Add atom to AtomContainer super.addAtom(oAtom); if (atomCount != super.getAtomCount()) { // ok, super did not yet contain the atom if (oMonomer == null) { oMonomer = getMonomer(""); } oMonomer.addAtom(oAtom); if (!monomers.containsKey(oMonomer.getMonomerName())) { monomers.put(oMonomer.getMonomerName(), oMonomer); } } }
/** * * Adds the atom oAtom to a specific Monomer. * * @param oAtom The atom to add * @param oMonomer The monomer the atom belongs to * */ @Override public void addAtom(IAtom oAtom, IMonomer oMonomer) { int atomCount = super.getAtomCount(); // Add atom to AtomContainer super.addAtom(oAtom); if (atomCount != super.getAtomCount()) { // ok, super did not yet contain the atom if (oMonomer == null) { oMonomer = getMonomer(""); } oMonomer.addAtom(oAtom); if (!monomers.containsKey(oMonomer.getMonomerName())) { monomers.put(oMonomer.getMonomerName(), oMonomer); } } }
@Test public void testConfigureAtoms_IAtomContainer() throws Exception { AtomContainer container = new org.openscience.cdk.AtomContainer(); container.addAtom(new Atom("C")); container.addAtom(new Atom("H")); container.addAtom(new Atom("N")); container.addAtom(new Atom("O")); container.addAtom(new Atom("F")); container.addAtom(new Atom("Cl")); Isotopes isofac = Isotopes.getInstance(); isofac.configureAtoms(container); for (int i = 0; i < container.getAtomCount(); i++) { Assert.assertTrue(0 < container.getAtom(i).getAtomicNumber()); } }
@Test public void testConfigureAtoms_IAtomContainer() throws Exception { AtomContainer container = new org.openscience.cdk.AtomContainer(); container.addAtom(new Atom("C")); container.addAtom(new Atom("H")); container.addAtom(new Atom("N")); container.addAtom(new Atom("O")); container.addAtom(new Atom("F")); container.addAtom(new Atom("Cl")); XMLIsotopeFactory isofac = XMLIsotopeFactory.getInstance(new ChemObject().getBuilder()); isofac.configureAtoms(container); for (int i = 0; i < container.getAtomCount(); i++) { Assert.assertTrue(0 < container.getAtom(i).getAtomicNumber()); } }
@Test public void testCountAtomPermutation() { AtomContainer ac = new AtomContainer(); ac.addAtom(new Atom("C")); ac.addAtom(new Atom("N")); ac.addAtom(new Atom("P")); ac.addAtom(new Atom("O")); ac.addAtom(new Atom("S")); ac.addAtom(new Atom("Br")); ac.addBond(0, 1, IBond.Order.SINGLE); ac.addBond(1, 2, IBond.Order.SINGLE); ac.addBond(2, 3, IBond.Order.SINGLE); ac.addBond(3, 4, IBond.Order.SINGLE); ac.addBond(4, 5, IBond.Order.SINGLE); AtomContainerAtomPermutor acap = new AtomContainerAtomPermutor(ac); int counter = 0; while (acap.hasNext()) { counter++; acap.next(); } Assert.assertEquals(719, counter); }
@Test public void testBondPermutation() { AtomContainer ac = new AtomContainer(); ac.addAtom(new Atom("C")); ac.addAtom(new Atom("N")); ac.addAtom(new Atom("P")); ac.addAtom(new Atom("O")); ac.addAtom(new Atom("S")); ac.addAtom(new Atom("Br")); ac.addBond(0, 1, IBond.Order.SINGLE); ac.addBond(1, 2, IBond.Order.DOUBLE); ac.addBond(2, 3, IBond.Order.TRIPLE); ac.addBond(3, 4, IBond.Order.QUADRUPLE); ac.addBond(4, 5, IBond.Order.SINGLE); // was 5.0 ! AtomContainerBondPermutor acap = new AtomContainerBondPermutor(ac); int counter = 0; while (acap.hasNext()) { counter++; acap.next(); } Assert.assertEquals(119, counter); }
@Test public void testIsIsomorph_IAtomContainer_IAtomContainer() throws Exception { AtomContainer ac1 = new AtomContainer(); ac1.addAtom(new Atom("C")); AtomContainer ac2 = new AtomContainer(); ac2.addAtom(new Atom("C")); Assert.assertTrue(uiTester.isIsomorph(ac1, ac2)); Assert.assertTrue(uiTester.isSubgraph(ac1, ac2)); }
@Test public void testBondPermutation() { AtomContainer ac = new org.openscience.cdk.AtomContainer(); AtomContainer result; String bonds = new String(""); ac.addAtom(new Atom("C")); ac.addAtom(new Atom("N")); ac.addAtom(new Atom("P")); ac.addAtom(new Atom("O")); ac.addAtom(new Atom("S")); ac.addAtom(new Atom("Br")); ac.addBond(0, 1, IBond.Order.SINGLE); ac.addBond(1, 2, IBond.Order.DOUBLE); ac.addBond(2, 3, IBond.Order.TRIPLE); ac.addBond(3, 4, IBond.Order.QUADRUPLE); ac.addBond(4, 5, IBond.Order.SINGLE); // was 5.0 ! AtomContainerBondPermutor acap = new AtomContainerBondPermutor(ac); int counter = 0; while (acap.hasNext()) { counter++; bonds = ""; result = (AtomContainer) acap.next(); for (int f = 0; f < result.getBondCount(); f++) { bonds += result.getBond(f).getOrder(); } //logger.debug(bonds); } Assert.assertEquals(119, counter); }
@Test public void testAtomPermutation() { AtomContainer ac = new org.openscience.cdk.AtomContainer(); AtomContainer result; String atoms = new String(""); ac.addAtom(new Atom("C")); ac.addAtom(new Atom("N")); ac.addAtom(new Atom("P")); ac.addAtom(new Atom("O")); ac.addAtom(new Atom("S")); ac.addAtom(new Atom("Br")); ac.addBond(0, 1, IBond.Order.SINGLE); ac.addBond(1, 2, IBond.Order.SINGLE); ac.addBond(2, 3, IBond.Order.SINGLE); ac.addBond(3, 4, IBond.Order.SINGLE); ac.addBond(4, 5, IBond.Order.SINGLE); AtomContainerAtomPermutor acap = new AtomContainerAtomPermutor(ac); int counter = 0; while (acap.hasNext()) { counter++; atoms = ""; result = (AtomContainer) acap.next(); for (int f = 0; f < result.getAtomCount(); f++) { atoms += result.getAtom(f).getSymbol(); } } Assert.assertEquals(719, counter); }
/** * @cdk.bug 1875946 */ @Test public void testPreservingFormalCharge() throws Exception { AtomContainer mol = new AtomContainer(); mol.addAtom(new Atom(Elements.OXYGEN)); mol.getAtom(0).setFormalCharge(-1); mol.addAtom(new Atom(Elements.CARBON)); mol.addBond(0, 1, IBond.Order.SINGLE); addImplicitHydrogens(mol); SmilesGenerator generator = new SmilesGenerator(); generator.create(new AtomContainer(mol)); Assert.assertEquals(-1, mol.getAtom(0).getFormalCharge().intValue()); // mmm, that does not reproduce the bug findings yet :( }
@Test public void testNoConnections() { HydrogenPlacer hydrogenPlacer = new HydrogenPlacer(); AtomContainer container = new AtomContainer(); Atom atom = new Atom("C", new Point2d(0, 0)); container.addAtom(atom); hydrogenPlacer.placeHydrogens2D(container, atom, 1.5); }
@Test public void testCalculate() { RDFCalculator calculator = new RDFCalculator(0.0, 5.0, 0.1, 0.0); AtomContainer h2mol = new org.openscience.cdk.AtomContainer(); Atom h1 = new Atom("H"); h1.setPoint3d(new Point3d(-0.5, 0.0, 0.0)); Atom h2 = new Atom("H"); h2.setPoint3d(new Point3d(0.5, 0.0, 0.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 testCalculate_RDFWeightFunction() { 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 1.0; } }); AtomContainer h2mol = new org.openscience.cdk.AtomContainer(); Atom h1 = new Atom("H"); h1.setPoint3d(new Point3d(-0.5, 0.0, 0.0)); Atom h2 = new Atom("H"); h2.setPoint3d(new Point3d(0.5, 0.0, 0.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 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 for SF bug #903551 */ @Test public void testPartitionIntoMoleculesKeepsAtomIDs() { AtomContainer atomCon = new org.openscience.cdk.AtomContainer(); Atom atom1 = new Atom("C"); atom1.setID("atom1"); Atom atom2 = new Atom("C"); atom2.setID("atom2"); atomCon.addAtom(atom1); atomCon.addAtom(atom2); IAtomContainerSet moleculeSet = ConnectivityChecker.partitionIntoMolecules(atomCon); Assert.assertNotNull(moleculeSet); Assert.assertEquals(2, moleculeSet.getAtomContainerCount()); org.openscience.cdk.interfaces.IAtom copy1 = moleculeSet.getAtomContainer(0).getAtom(0); org.openscience.cdk.interfaces.IAtom copy2 = moleculeSet.getAtomContainer(1).getAtom(0); Assert.assertEquals(atom1.getID(), copy1.getID()); Assert.assertEquals(atom2.getID(), copy2.getID()); }
/** * Test generation of a reaction SMILES. I know, it's a stupid alchemic * reaction, but it serves its purpose. */ @Test public void testReactionSMILES() throws Exception { Reaction reaction = new Reaction(); AtomContainer methane = new AtomContainer(); methane.addAtom(new Atom("C")); reaction.addReactant(methane); IAtomContainer magic = new AtomContainer(); magic.addAtom(new PseudoAtom("magic")); reaction.addAgent(magic); IAtomContainer gold = new AtomContainer(); gold.addAtom(new Atom("Au")); reaction.addProduct(gold); methane.getAtom(0).setImplicitHydrogenCount(4); gold.getAtom(0).setImplicitHydrogenCount(0); SmilesGenerator sg = new SmilesGenerator(SmiFlavor.Generic); String smiles = sg.create(reaction); //logger.debug("Generated SMILES: " + smiles); Assert.assertEquals("C>*>[Au]", smiles); }