/** * Calculates a score based on the overlap of atoms and intersection of bonds. * The overlap is calculated by summing up the distances between all pairs of * atoms, if they are less than half the standard bondlength apart. * *@param ac The Atomcontainer to work on *@param overlappingAtoms Description of the Parameter *@param overlappingBonds Description of the Parameter *@return The overlapScore value */ public double getOverlapScore(IAtomContainer ac, Vector overlappingAtoms, Vector overlappingBonds) { double overlapScore = 0; overlapScore = getAtomOverlapScore(ac, overlappingAtoms); //overlapScore += getBondOverlapScore(ac, overlappingBonds); return overlapScore; }
/** * Main method to be called to resolve overlap situations. * * @param ac The atomcontainer in which the atom or bond overlap exists * @param sssr A ring set for this atom container if one exists, otherwhise null */ public double resolveOverlap(IAtomContainer ac, IRingSet sssr) { Vector overlappingAtoms = new Vector(); Vector overlappingBonds = new Vector(); logger.debug("Start of resolveOverlap"); double overlapScore = getOverlapScore(ac, overlappingAtoms, overlappingBonds); if (overlapScore > 0) { overlapScore = displace(ac, overlappingAtoms, overlappingBonds); } logger.debug("overlapScore = " + overlapScore); logger.debug("End of resolveOverlap"); return overlapScore; }
/** * A unit test for JUnit * *@exception Exception Description of the Exception */ @Test public void testResolveOverlap1() throws Exception { logger.debug("Test case with atom clash"); String filename = "data/cml/overlaptest.cml"; InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); CMLReader reader = new CMLReader(ins); IChemFile chemFile = (IChemFile) reader.read(new ChemFile()); IAtomContainer atomContainer = (IAtomContainer) ChemFileManipulator.getAllAtomContainers(chemFile).get(0); OverlapResolver or = new OverlapResolver(); double score = new OverlapResolver().getAtomOverlapScore(atomContainer, new Vector()); logger.debug("Overlap Score before treatment: " + score); Assert.assertTrue(score > 0); or.resolveOverlap(atomContainer, null); //MoleculeViewer2D.display(new AtomContainer(atomContainer), false); score = new OverlapResolver().getAtomOverlapScore(atomContainer, new Vector()); logger.debug("Overlap Score after treatment: " + score); Assert.assertEquals(0.0, score, 0.00001); logger.debug("End of test case with atom clash"); }
/** * A unit test for JUnit * *@exception Exception Description of the Exception */ @Test public void testResolveOverlap2() throws Exception { logger.debug("Test case with neither bond nor atom overlap"); String filename = "data/cml/overlaptest2.cml"; InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); CMLReader reader = new CMLReader(ins); IChemFile chemFile = (IChemFile) reader.read(new ChemFile()); IAtomContainer atomContainer = (IAtomContainer) ChemFileManipulator.getAllAtomContainers(chemFile).get(0); //MoleculeViewer2D.display(new AtomContainer(atomContainer), false); double score = new OverlapResolver().getOverlapScore(atomContainer, new Vector(), new Vector()); Assert.assertEquals(0.0, score, 0.0001); logger.debug("End of test case with neither bond nor atom overlap"); }
/** * A unit test for JUnit * *@exception Exception Description of the Exception */ @Test public void testResolveOverlap4() throws Exception { double overlapScore = 0; logger.debug("Test case with atom clash"); String filename = "data/cml/overlaptest.cml"; InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); CMLReader reader = new CMLReader(ins); IChemFile chemFile = (IChemFile) reader.read(new ChemFile()); IAtomContainer atomContainer = (IAtomContainer) ChemFileManipulator.getAllAtomContainers(chemFile).get(0); //MoleculeViewer2D.display(new AtomContainer(atomContainer), false); OverlapResolver or = new OverlapResolver(); overlapScore = or.resolveOverlap(atomContainer, null); //MoleculeViewer2D.display(new AtomContainer(atomContainer), false); Assert.assertEquals(0.0, overlapScore, 0.0001); logger.debug("End of test case with atom clash"); }
logger.debug("Random variable: " + choice + ", displacing second atom"); overlapScore = getOverlapScore(ac, overlappingAtoms, overlappingBonds); steps++; } while (overlapScore > 0 && !(steps > maxSteps));
/** * A unit test for JUnit * *@exception Exception Description of the Exception */ @Test public void testResolveOverlap3() throws Exception { logger.debug("Test case with bond overlap"); String filename = "data/cml/overlaptest3.cml"; InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); CMLReader reader = new CMLReader(ins); IChemFile chemFile = (IChemFile) reader.read(new ChemFile()); IAtomContainer atomContainer = (IAtomContainer) ChemFileManipulator.getAllAtomContainers(chemFile).get(0); //MoleculeViewer2D.display(new AtomContainer(atomContainer), false); double score = new OverlapResolver().getBondOverlapScore(atomContainer, new Vector()); Assert.assertTrue(score > 0); logger.debug("End of test case with bond overlap"); }
/** * Calculates a score based on the intersection of bonds. * *@param ac The Atomcontainer to work on *@param overlappingBonds Description of the Parameter *@return The overlapScore value */ public double getBondOverlapScore(IAtomContainer ac, Vector overlappingBonds) { overlappingBonds.removeAllElements(); double overlapScore = 0; IBond bond1 = null; IBond bond2 = null; double bondLength = GeometryUtil.getBondLengthAverage(ac);; double overlapCutoff = bondLength / 2; for (int f = 0; f < ac.getBondCount(); f++) { bond1 = ac.getBond(f); for (int g = f; g < ac.getBondCount(); g++) { bond2 = ac.getBond(g); /* bonds must not be connected */ if (!bond1.isConnectedTo(bond2)) { if (areIntersected(bond1, bond2)) { overlapScore += overlapCutoff; overlappingBonds.addElement(new OverlapPair(bond1, bond2)); } } } } return overlapScore; }
/** * A unit test for JUnit * *@exception Exception Description of the Exception */ @Test public void testResolveOverlap5() throws Exception { double overlapScore = 0; logger.debug("Test case with atom clash"); IAtomContainer atomContainer = new SmilesParser(DefaultChemObjectBuilder.getInstance()) .parseSmiles("OC4C(N2C1=C(C(=NC(=N1)SC)SC)C3=C2N=CN=C3N)OC(C4O)CO"); StructureDiagramGenerator sdg = new StructureDiagramGenerator(); sdg.setMolecule(new AtomContainer(atomContainer)); sdg.generateCoordinates(); atomContainer = sdg.getMolecule(); OverlapResolver or = new OverlapResolver(); overlapScore = or.resolveOverlap(atomContainer, null); //MoleculeViewer2D.display(new AtomContainer(atomContainer), true); Assert.assertEquals(0.0, overlapScore, 0.0001); logger.debug("End of test case with atom clash"); }
logger.debug("Random variable: " + choice + ", displacing second atom"); overlapScore = getOverlapScore(ac, overlappingAtoms, overlappingBonds); steps++; } while (overlapScore > 0 && !(steps > maxSteps));
/** * Calculates a score based on the intersection of bonds. * *@param ac The Atomcontainer to work on *@param overlappingBonds Description of the Parameter *@return The overlapScore value */ public double getBondOverlapScore(IAtomContainer ac, Vector overlappingBonds) { overlappingBonds.removeAllElements(); double overlapScore = 0; IBond bond1 = null; IBond bond2 = null; double bondLength = GeometryUtil.getBondLengthAverage(ac);; double overlapCutoff = bondLength / 2; for (int f = 0; f < ac.getBondCount(); f++) { bond1 = ac.getBond(f); for (int g = f; g < ac.getBondCount(); g++) { bond2 = ac.getBond(g); /* bonds must not be connected */ if (!bond1.isConnectedTo(bond2)) { if (areIntersected(bond1, bond2)) { overlapScore += overlapCutoff; overlappingBonds.addElement(new OverlapPair(bond1, bond2)); } } } } return overlapScore; }
/** * Main method to be called to resolve overlap situations. * * @param ac The atomcontainer in which the atom or bond overlap exists * @param sssr A ring set for this atom container if one exists, otherwhise null */ public double resolveOverlap(IAtomContainer ac, IRingSet sssr) { Vector overlappingAtoms = new Vector(); Vector overlappingBonds = new Vector(); logger.debug("Start of resolveOverlap"); double overlapScore = getOverlapScore(ac, overlappingAtoms, overlappingBonds); if (overlapScore > 0) { overlapScore = displace(ac, overlappingAtoms, overlappingBonds); } logger.debug("overlapScore = " + overlapScore); logger.debug("End of resolveOverlap"); return overlapScore; }
/** * Calculates a score based on the overlap of atoms and intersection of bonds. * The overlap is calculated by summing up the distances between all pairs of * atoms, if they are less than half the standard bondlength apart. * *@param ac The Atomcontainer to work on *@param overlappingAtoms Description of the Parameter *@param overlappingBonds Description of the Parameter *@return The overlapScore value */ public double getOverlapScore(IAtomContainer ac, Vector overlappingAtoms, Vector overlappingBonds) { double overlapScore = 0; overlapScore = getAtomOverlapScore(ac, overlappingAtoms); //overlapScore += getBondOverlapScore(ac, overlappingBonds); return overlapScore; }