@Test public void testMDMoleculeCustomization() { StringWriter writer = new StringWriter(); CMLWriter cmlWriter = new CMLWriter(writer); cmlWriter.registerCustomizer(new MDMoleculeCustomizer()); try { IAtomContainer molecule = makeMDBenzene(); cmlWriter.write(molecule); } catch (Exception exception) { logger.error("Error while creating an CML2 file: ", exception.getMessage()); logger.debug(exception); Assert.fail(exception.getMessage()); } String cmlContent = writer.toString(); logger.debug("****************************** testMDMoleculeCustomization()"); logger.debug(cmlContent); logger.debug("******************************"); // System.out.println("****************************** testMDMoleculeCustomization()"); // System.out.println(cmlContent); // System.out.println("******************************"); Assert.assertTrue(cmlContent.indexOf("xmlns:md") != -1); Assert.assertTrue(cmlContent.indexOf("md:residue\"") != -1); Assert.assertTrue(cmlContent.indexOf("md:resNumber\"") != -1); Assert.assertTrue(cmlContent.indexOf("md:chargeGroup\"") != -1); Assert.assertTrue(cmlContent.indexOf("md:cgNumber\"") != -1); Assert.assertTrue(cmlContent.indexOf("md:switchingAtom\"") != -1); }
/** * Selects an optimum edge for elimination in structures without N2 nodes. * * <p>This might be severely broken! Would have helped if there was an explanation of how this * algorithm worked. * * @param ring * @param molecule */ private IBond checkEdges(IRing ring, IAtomContainer molecule) { IRing r1, r2; IRingSet ringSet = ring.getBuilder().newInstance(IRingSet.class); IBond bond; int minMaxSize = Integer.MAX_VALUE; int minMax = 0; logger.debug("Molecule: " + molecule); Iterator<IBond> bonds = ring.bonds().iterator(); while (bonds.hasNext()) { bond = (IBond) bonds.next(); molecule.removeElectronContainer(bond); r1 = getRing(bond.getAtom(0), molecule); r2 = getRing(bond.getAtom(1), molecule); logger.debug("checkEdges: " + bond); if (r1.getAtomCount() > r2.getAtomCount()) { ringSet.addAtomContainer(r1); } else { ringSet.addAtomContainer(r2); } molecule.addBond(bond); } for (int i = 0; i < ringSet.getAtomContainerCount(); i++) { if (((IRing) ringSet.getAtomContainer(i)).getBondCount() < minMaxSize) { minMaxSize = ((IRing) ringSet.getAtomContainer(i)).getBondCount(); minMax = i; } } return (IBond) ring.getElectronContainer(minMax); }
/** * Starts the reading of the CML file. Whenever a new Molecule is read, a event is thrown to the * ReaderListener. */ public void process() throws CDKException { logger.debug("Started parsing from input..."); try { parser.setFeature("http://xml.org/sax/features/validation", false); logger.info("Deactivated validation"); } catch (SAXException e) { logger.warn("Cannot deactivate validation."); } parser.setContentHandler(new EventCMLHandler(this, builder)); parser.setEntityResolver(new CMLResolver()); parser.setErrorHandler(new CMLErrorHandler()); try { logger.debug("Parsing from Reader"); parser.parse(new InputSource(input)); } catch (IOException e) { String error = "Error while reading file: " + e.getMessage(); logger.error(error); logger.debug(e); throw new CDKException(error, e); } catch (SAXParseException saxe) { SAXParseException spe = (SAXParseException) saxe; String error = "Found well-formedness error in line " + spe.getLineNumber(); logger.error(error); logger.debug(saxe); throw new CDKException(error, saxe); } catch (SAXException saxe) { String error = "Error while parsing XML: " + saxe.getMessage(); logger.error(error); logger.debug(saxe); throw new CDKException(error, saxe); } }
/** * Returns the ring that is formed by the atoms in the given vector. * * @param vec The vector that contains the atoms of the ring * @param mol The molecule this ring is a substructure of * @return The ring formed by the given atoms */ private IRing prepareRing(List vec, IAtomContainer mol) { // add the atoms in vec to the new ring int atomCount = vec.size(); IRing ring = mol.getBuilder().newInstance(IRing.class, atomCount); IAtom[] atoms = new IAtom[atomCount]; vec.toArray(atoms); ring.setAtoms(atoms); // add the bonds in mol to the new ring try { IBond b; for (int i = 0; i < atomCount - 1; i++) { b = mol.getBond(atoms[i], atoms[i + 1]); if (b != null) { ring.addBond(b); } else { logger.error("This should not happen."); } } b = mol.getBond(atoms[0], atoms[atomCount - 1]); if (b != null) { ring.addBond(b); } else { logger.error("This should not happen either."); } } catch (Exception exc) { logger.debug(exc); } logger.debug("found Ring ", ring); return ring; }
@Override public synchronized void setChemFilters( boolean stereoFilter, boolean fragmentFilter, boolean energyFilter) { if (getMappingCount() > 0) { if (energyFilter) { try { sortResultsByEnergies(); this.bondEnergiesList = getSortedEnergy(); } catch (CDKException ex) { Logger.error(Level.SEVERE, null, ex); } } if (fragmentFilter) { sortResultsByFragments(); this.fragmentSizeList = getSortedFragment(); } if (stereoFilter) { try { sortResultsByStereoAndBondMatch(); this.stereoScoreList = getStereoMatches(); } catch (CDKException ex) { Logger.error(Level.SEVERE, null, ex); } } } }
public Point2d getPoint2d() { Point2d point2d = super.getPoint2d(); if (point2d == null) { logger.debug("Getting point2d: null"); } else { logger.debug("Getting point2d: x=" + point2d.x + ", y=" + point2d.y); } return point2d; }
public Point3d getPoint3d() { Point3d point3d = super.getPoint3d(); if (point3d == null) { logger.debug("Getting point3d: null"); } else { logger.debug("Getting point3d: x=" + point3d.x + ", y=" + point3d.y, ", z=" + point3d.z); } return point3d; }
public Object clone() throws CloneNotSupportedException { Object clone = null; try { clone = super.clone(); } catch (Exception exception) { logger.error("Could not clone DebugAtom: " + exception.getMessage(), exception); logger.debug(exception); } return clone; }
private boolean isReady() throws CDKException { try { return input.ready(); } catch (Exception exception) { String error = "Unexpected error while reading file: " + exception.getMessage(); logger.error(error); logger.debug(exception); throw new CDKException(error, exception); } }
/** Returns true if another IMolecule can be read. */ public boolean hasNext() { if (!nextAvailableIsKnown) { hasNext = false; // now try to parse the next Molecule try { if ((currentLine = input.readLine()) != null) { currentFormat = (IChemFormat) MDLFormat.getInstance(); StringBuffer buffer = new StringBuffer(); while (currentLine != null && !currentLine.equals("M END")) { // still in a molecule buffer.append(currentLine); buffer.append(System.getProperty("line.separator")); currentLine = input.readLine(); // do MDL molfile version checking if (currentLine.contains("V2000") || currentLine.contains("v2000")) { currentFormat = (IChemFormat) MDLV2000Format.getInstance(); } else if (currentLine.contains("V3000") || currentLine.contains("v3000")) { currentFormat = (IChemFormat) MDLV3000Format.getInstance(); } } buffer.append(currentLine); buffer.append(System.getProperty("line.separator")); logger.debug("MDL file part read: ", buffer); ISimpleChemObjectReader reader = factory.createReader(currentFormat); reader.setReader(new StringReader(buffer.toString())); if (currentFormat instanceof MDLV2000Format) { reader.addChemObjectIOListener(this); ((MDLV2000Reader) reader).customizeJob(); } nextMolecule = (IMolecule) reader.read(builder.newInstance(IMolecule.class)); // note that a molecule may have 0 atoms, but still // be useful (by having SD tags for example), so just // check for null'ness rather than atom count hasNext = nextMolecule != null; // now read the data part currentLine = input.readLine(); readDataBlockInto(nextMolecule); } else { hasNext = false; } } catch (Exception exception) { logger.error("Error while reading next molecule: " + exception.getMessage()); logger.debug(exception); hasNext = false; } if (!hasNext) nextMolecule = null; nextAvailableIsKnown = true; } return hasNext; }
/** * Place all hydrogens connected to atoms which have already been laid out. * * @param container atom container * @param bondLength bond length to user */ @TestMethod("testBug933572,testH2") public void placeHydrogens2D(final IAtomContainer container, final double bondLength) { logger.debug("placing hydrogens on all atoms"); for (IAtom atom : container.atoms()) { // only place hydrogens for atoms which have coordinates if (atom.getPoint2d() != null) { placeHydrogens2D(container, atom, bondLength); } } logger.debug("hydrogen placement complete"); }
private void init() { boolean success = false; // If JAXP is prefered (comes with Sun JVM 1.4.0 and higher) if (!success) { try { javax.xml.parsers.SAXParserFactory spf = javax.xml.parsers.SAXParserFactory.newInstance(); spf.setNamespaceAware(true); javax.xml.parsers.SAXParser saxParser = spf.newSAXParser(); parser = saxParser.getXMLReader(); logger.info("Using JAXP/SAX XML parser."); success = true; } catch (ParserConfigurationException | SAXException e) { logger.warn("Could not instantiate JAXP/SAX XML reader: ", e.getMessage()); logger.debug(e); } } // Aelfred is first alternative. if (!success) { try { parser = (XMLReader) this.getClass() .getClassLoader() .loadClass("gnu.xml.aelfred2.XmlReader") .newInstance(); logger.info("Using Aelfred2 XML parser."); success = true; } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) { logger.warn("Could not instantiate Aelfred2 XML reader!"); logger.debug(e); } } // Xerces is second alternative if (!success) { try { parser = (XMLReader) this.getClass() .getClassLoader() .loadClass("org.apache.xerces.parsers.SAXParser") .newInstance(); logger.info("Using Xerces XML parser."); success = true; } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) { logger.warn("Could not instantiate Xerces XML reader!"); logger.debug(e); } } if (!success) { logger.error("Could not instantiate any XML parser!"); } }
/** @cdk.bug 891021 */ @Test public void testBug891021() throws Exception { IAtomContainer molecule = null; String filename = "data/mdl/too.many.rings.mol"; InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); MDLV2000Reader reader = new MDLV2000Reader(ins, Mode.STRICT); molecule = (IAtomContainer) reader.read((IChemObject) new AtomContainer()); logger.debug("Testing " + filename); IRingSet ringSet = new SSSRFinder(molecule).findSSSR(); logger.debug("Found ring set of size: " + ringSet.getAtomContainerCount()); Assert.assertEquals(57, ringSet.getAtomContainerCount()); }
private String readLine() throws CDKException { String line = null; try { line = input.readLine(); logger.debug("read line: " + line); } catch (Exception exception) { String error = "Unexpected error while reading file: " + exception.getMessage(); logger.error(error); logger.debug(exception); throw new CDKException(error, exception); } return line; }
/** * 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"); }
/** * Generated coordinates for a given ring, which is connected to a spiro ring. The rings share * exactly one atom. * * @param ring The ring to be placed * @param sharedAtoms The atoms of this ring, also members of another ring, which are already * placed * @param sharedAtomsCenter The geometric center of these atoms * @param ringCenterVector A vector pointing the the center of the new ring * @param bondLength The standard bondlength */ public void placeSpiroRing( IRing ring, IAtomContainer sharedAtoms, Point2d sharedAtomsCenter, Vector2d ringCenterVector, double bondLength) { logger.debug("placeSpiroRing"); double radius = getNativeRingRadius(ring, bondLength); Point2d ringCenter = new Point2d(sharedAtomsCenter); ringCenterVector.normalize(); ringCenterVector.scale(radius); ringCenter.add(ringCenterVector); double addAngle = 2 * Math.PI / ring.getRingSize(); IAtom startAtom = sharedAtoms.getAtom(0); // double centerX = ringCenter.x; // double centerY = ringCenter.y; // int direction = 1; IAtom currentAtom = startAtom; double startAngle = GeometryTools.getAngle( startAtom.getPoint2d().x - ringCenter.x, startAtom.getPoint2d().y - ringCenter.y); /* * Get one bond connected to the spiro bridge atom. * It doesn't matter in which direction we draw. */ java.util.List bonds = ring.getConnectedBondsList(startAtom); IBond currentBond = (IBond) bonds.get(0); Vector atomsToDraw = new Vector(); /* * Store all atoms to draw in consequtive order relative to the * chosen bond. */ for (int i = 0; i < ring.getBondCount(); i++) { currentBond = ring.getNextBond(currentBond, currentAtom); currentAtom = currentBond.getConnectedAtom(currentAtom); atomsToDraw.addElement(currentAtom); } logger.debug("currentAtom " + currentAtom); logger.debug("startAtom " + startAtom); atomPlacer.populatePolygonCorners(atomsToDraw, ringCenter, startAngle, addAngle, radius); }
@Test public void testReading() throws Exception { String filename = "data/asn/pubchem/cid1145.xml"; logger.info("Testing: " + filename); InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); PCCompoundXMLReader reader = new PCCompoundXMLReader(ins); IMolecule molecule = (IMolecule) reader.read(new Molecule()); Assert.assertNotNull(molecule); // check atom stuff Assert.assertEquals(14, molecule.getAtomCount()); Assert.assertEquals("O", molecule.getAtom(0).getSymbol()); Assert.assertEquals(Integer.valueOf(-1), molecule.getAtom(0).getFormalCharge()); Assert.assertEquals("N", molecule.getAtom(1).getSymbol()); Assert.assertEquals(Integer.valueOf(1), molecule.getAtom(1).getFormalCharge()); // check bond stuff Assert.assertEquals(13, molecule.getBondCount()); Assert.assertNotNull(molecule.getBond(3)); // coordinates Assert.assertNull(molecule.getAtom(0).getPoint3d()); Point2d point = molecule.getAtom(0).getPoint2d(); Assert.assertNotNull(point); Assert.assertEquals(3.7320508956909, point.x, 0.00000001); Assert.assertEquals(0.5, point.y, 0.00000001); }
private synchronized double calRelation(IReaction reaction, IMappingAlgorithm theory) { try { Map<Integer, IAtomContainer> educts = synchronizedSortedMap(new TreeMap<Integer, IAtomContainer>()); for (int i = 0; i < reaction.getReactantCount(); i++) { educts.put(i, reaction.getReactants().getAtomContainer(i)); } Map<Integer, IAtomContainer> products = synchronizedSortedMap(new TreeMap<Integer, IAtomContainer>()); for (int i = 0; i < reaction.getProductCount(); i++) { products.put(i, reaction.getProducts().getAtomContainer(i)); } GameTheoryMatrix EDSH = new GameTheoryMatrix(theory, reaction, removeHydrogen); IGameTheory gameTheory = make(theory, reaction, removeHydrogen, educts, products, EDSH); this.reactionBlastMolMapping = gameTheory.getReactionMolMapping(); EDSH.Clear(); return gameTheory.getDelta(); } catch (Exception e) { logger.error(e); return -1; } }
/** * Performs the pharmacophore matching. * * @param atomContainer The target molecule. Must have 3D coordinates * @param initializeTarget If <i>true</i>, the target molecule specified in the first argument * will be analyzed to identify matching pharmacophore groups. If <i>false</i> this is not * performed. The latter case is only useful when dealing with conformers since for a given * molecule, all conformers will have the same pharmacophore groups and only the constraints * will change from one conformer to another. * @return true is the target molecule contains the query pharmacophore * @throws org.openscience.cdk.exception.CDKException if the query pharmacophore was not set or * the query is invalid or if the molecule does not have 3D coordinates */ public boolean matches(IAtomContainer atomContainer, boolean initializeTarget) throws CDKException { if (!GeometryUtil.has3DCoordinates(atomContainer)) throw new CDKException("Molecule must have 3D coordinates"); if (pharmacophoreQuery == null) throw new CDKException("Must set the query pharmacophore before matching"); if (!checkQuery(pharmacophoreQuery)) throw new CDKException( "A problem in the query. Make sure all pharmacophore groups of the same symbol have the same same SMARTS"); String title = (String) atomContainer.getProperty(CDKConstants.TITLE); if (initializeTarget) pharmacophoreMolecule = getPharmacophoreMolecule(atomContainer); else { // even though the atoms comprising the pcore groups are // constant, their coords will differ, so we need to make // sure we get the latest set of effective coordinates for (IAtom iAtom : pharmacophoreMolecule.atoms()) { PharmacophoreAtom patom = (PharmacophoreAtom) iAtom; List<Integer> tmpList = new ArrayList<Integer>(); for (int idx : patom.getMatchingAtoms()) tmpList.add(idx); Point3d coords = getEffectiveCoordinates(atomContainer, tmpList); patom.setPoint3d(coords); } } if (pharmacophoreMolecule.getAtomCount() < pharmacophoreQuery.getAtomCount()) { logger.debug("Target [" + title + "] did not match the query SMARTS. Skipping constraints"); return false; } mappings = Pattern.findSubstructure(pharmacophoreQuery).matchAll(pharmacophoreMolecule); // XXX: doing one search then discarding return mappings.atLeast(1); }
@Test public void testLoopProblem() throws Exception { String filename = "data/mdl/ring_03419.mol"; InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); MDLV2000Reader reader = new MDLV2000Reader(ins, Mode.STRICT); IAtomContainer molecule = (IAtomContainer) reader.read((IChemObject) new AtomContainer()); logger.debug("Testing " + filename); IRingSet ringSet = new SSSRFinder(molecule).findSSSR(); logger.debug("Found ring set of size: " + ringSet.getAtomContainerCount()); Assert.assertEquals(12, ringSet.getAtomContainerCount()); for (int f = 0; f < ringSet.getAtomContainerCount(); f++) { IRing ring = (IRing) ringSet.getAtomContainer(f); logger.debug("ring: " + toString(ring, molecule)); } }
/** * Layout all rings in the given RingSet that are connected to a given Ring * * @param rs The RingSet to be searched for rings connected to Ring * @param ring The Ring for which all connected rings in RingSet are to be layed out. */ void placeConnectedRings(IRingSet rs, IRing ring, int handleType, double bondLength) { IRingSet connectedRings = rs.getConnectedRings(ring); IRing connectedRing; IAtomContainer sharedAtoms; int sac; Point2d oldRingCenter, sharedAtomsCenter, tempPoint; Vector2d tempVector, oldRingCenterVector, newRingCenterVector; // logger.debug(rs.reportRingList(molecule)); for (IAtomContainer container : connectedRings.atomContainers()) { connectedRing = (IRing) container; if (!connectedRing.getFlag(CDKConstants.ISPLACED)) { // logger.debug(ring.toString(molecule)); // logger.debug(connectedRing.toString(molecule)); sharedAtoms = AtomContainerManipulator.getIntersection(ring, connectedRing); sac = sharedAtoms.getAtomCount(); logger.debug("placeConnectedRings-> connectedRing: " + (ring.toString())); if ((sac == 2 && handleType == FUSED) || (sac == 1 && handleType == SPIRO) || (sac > 2 && handleType == BRIDGED)) { sharedAtomsCenter = GeometryTools.get2DCenter(sharedAtoms); oldRingCenter = GeometryTools.get2DCenter(ring); tempVector = (new Vector2d(sharedAtomsCenter)); newRingCenterVector = new Vector2d(tempVector); newRingCenterVector.sub(new Vector2d(oldRingCenter)); oldRingCenterVector = new Vector2d(newRingCenterVector); logger.debug( "placeConnectedRing -> tempVector: " + tempVector + ", tempVector.length: " + tempVector.length()); logger.debug("placeConnectedRing -> bondCenter: " + sharedAtomsCenter); logger.debug( "placeConnectedRing -> oldRingCenterVector.length(): " + oldRingCenterVector.length()); logger.debug( "placeConnectedRing -> newRingCenterVector.length(): " + newRingCenterVector.length()); tempPoint = new Point2d(sharedAtomsCenter); tempPoint.add(newRingCenterVector); placeRing(connectedRing, sharedAtoms, sharedAtomsCenter, newRingCenterVector, bondLength); connectedRing.setFlag(CDKConstants.ISPLACED, true); placeConnectedRings(rs, connectedRing, handleType, bondLength); } } } }
/** * The method returns partial charges assigned to an heavy atom through MMFF94 method. It is * needed to call the addExplicitHydrogensToSatisfyValency method from the class * tools.HydrogenAdder. * * @param atom The IAtom for which the DescriptorValue is requested * @param org AtomContainer * @return partial charge of parameter atom */ @Override public DescriptorValue calculate(IAtom atom, IAtomContainer org) { if (atom.getProperty(CHARGE_CACHE) == null) { IAtomContainer copy; try { copy = org.clone(); } catch (CloneNotSupportedException e) { return new DescriptorValue( getSpecification(), getParameterNames(), getParameters(), new DoubleResult(Double.NaN), NAMES); } for (IAtom a : org.atoms()) { if (a.getImplicitHydrogenCount() == null || a.getImplicitHydrogenCount() != 0) { logger.error("Hydrogens must be explict for MMFF charge calculation"); return new DescriptorValue( getSpecification(), getParameterNames(), getParameters(), new DoubleResult(Double.NaN), NAMES); } } if (!mmff.assignAtomTypes(copy)) logger.warn("One or more atoms could not be assigned an MMFF atom type"); mmff.partialCharges(copy); mmff.clearProps(copy); // cache charges for (int i = 0; i < org.getAtomCount(); i++) { org.getAtom(i).setProperty(CHARGE_CACHE, copy.getAtom(i).getCharge()); } } return new DescriptorValue( getSpecification(), getParameterNames(), getParameters(), new DoubleResult(atom.getProperty(CHARGE_CACHE, Double.class)), NAMES); }
/** * 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"); }
/** * @param removeHydrogen * @param reaction * @param algorithm */ public CalculationProcess( boolean removeHydrogen, IReaction reaction, IMappingAlgorithm algorithm) { /* * This case handles rings cases where 6 membered ring reduces to 5 membered rings Example KEGG reaction R01432 * of Isomerase class */ super(reaction); // System.out.println("I am CalculationProcess"); this.removeHydrogen = removeHydrogen; logger.debug("\n|++++++++++++++++++++++++++++|"); logger.debug("Performing Atom-Atom Mapping ....... " + reaction.getID() + " ......."); logger.debug("\n|++++++++++++++++++++++++++++|"); this.algorithm = algorithm; run(); }
/** * 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"); }
/** * Validate the Tolerance Range of this IMolecularFormula. * * @param formula Parameter is the IMolecularFormula * @return A double value meaning 1.0 True, 0.0 False */ public double validate(IMolecularFormula formula) throws CDKException { logger.info("Start validation of ", formula); double totalExactMass = MolecularFormulaManipulator.getTotalExactMass(formula); if (Math.abs(totalExactMass - mass) > tolerance) return 0.0; else return 1.0; }
private void readDataBlockInto(IMolecule m) throws IOException { String fieldName = null; while (currentLine != null && !(currentLine.trim().equals("$$$$"))) { logger.debug("looking for data header: ", currentLine); String str = new String(currentLine); if (str.startsWith("> ")) { fieldName = extractFieldName(fieldName, str); str = skipOtherFieldHeaderLines(str); String data = extractFieldData(str); if (fieldName != null) { logger.info("fieldName, data: ", fieldName, ", ", data); m.setProperty(fieldName, data); } } currentLine = input.readLine(); } }
private String skipOtherFieldHeaderLines(String str) throws IOException { while (str.startsWith("> ")) { logger.debug("data header line: ", currentLine); currentLine = input.readLine(); str = new String(currentLine); } return str; }
/** * Initiate process. It is needed to call the addExplicitHydrogensToSatisfyValency from the class * tools.HydrogenAdder. * * @param reactants reactants of the reaction * @param agents agents of the reaction (Must be in this case null) * @exception CDKException Description of the Exception */ @TestMethod("testInitiate_IMoleculeSet_IMoleculeSet") public IReactionSet initiate(IMoleculeSet reactants, IMoleculeSet agents) throws CDKException { logger.debug("initiate reaction: HeterolyticCleavagePBReaction"); if (reactants.getMoleculeCount() != 1) { throw new CDKException("HeterolyticCleavagePBReaction only expects one reactant"); } if (agents != null) { throw new CDKException("HeterolyticCleavagePBReaction don't expects agents"); } IReactionSet setOfReactions = DefaultChemObjectBuilder.getInstance().newInstance(IReactionSet.class); IMolecule reactant = reactants.getMolecule(0); /* if the parameter hasActiveCenter is not fixed yet, set the active centers*/ IParameterReact ipr = super.getParameterClass(SetReactionCenter.class); if (ipr != null && !ipr.isSetParameter()) setActiveCenters(reactant); Iterator<IBond> bondis = reactant.bonds().iterator(); while (bondis.hasNext()) { IBond bondi = bondis.next(); IAtom atom1 = bondi.getAtom(0); IAtom atom2 = bondi.getAtom(1); if (bondi.getFlag(CDKConstants.REACTIVE_CENTER) && bondi.getOrder() != IBond.Order.SINGLE && atom1.getFlag(CDKConstants.REACTIVE_CENTER) && atom2.getFlag(CDKConstants.REACTIVE_CENTER) && (atom1.getFormalCharge() == CDKConstants.UNSET ? 0 : atom1.getFormalCharge()) == 0 && (atom2.getFormalCharge() == CDKConstants.UNSET ? 0 : atom2.getFormalCharge()) == 0 && reactant.getConnectedSingleElectronsCount(atom1) == 0 && reactant.getConnectedSingleElectronsCount(atom2) == 0) { /**/ for (int j = 0; j < 2; j++) { ArrayList<IAtom> atomList = new ArrayList<IAtom>(); if (j == 0) { atomList.add(atom1); atomList.add(atom2); } else { atomList.add(atom2); atomList.add(atom1); } ArrayList<IBond> bondList = new ArrayList<IBond>(); bondList.add(bondi); IMoleculeSet moleculeSet = reactant.getBuilder().newInstance(IMoleculeSet.class); moleculeSet.addMolecule(reactant); IReaction reaction = mechanism.initiate(moleculeSet, atomList, bondList); if (reaction == null) continue; else setOfReactions.addReaction(reaction); } } } return setOfReactions; }
public void processIOSettingQuestion(IOSetting setting) { if (setting.getName().equals(forceReadAs3DCoords.getName())) { try { setting.setSetting(forceReadAs3DCoords.getSetting()); } catch (CDKException e) { logger.debug("Could not propagate forceReadAs3DCoords setting"); } } }