/** * Return true if a bond is matched between query and target * * @param targetBond * @return */ private boolean isBondTypeMatch(IBond targetBond) { if ((queryBond.getFlag(CDKConstants.ISAROMATIC) == targetBond.getFlag(CDKConstants.ISAROMATIC)) && (queryBond.getOrder() == targetBond.getOrder())) { return true; } else if (queryBond.getFlag(CDKConstants.ISAROMATIC) && targetBond.getFlag(CDKConstants.ISAROMATIC)) { return true; } return false; }
/** * 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; }
@Test public void testBondAromatic2() throws Exception { String cmlString = "<molecule id='m1'><atomArray atomID='a1 a2'/><bondArray><bond atomRefs='a1 a2' order='2'><bondType dictRef='cdk:aromaticBond'/></bond></bondArray></molecule>"; IChemFile chemFile = parseCMLString(cmlString); IMolecule mol = checkForSingleMoleculeFile(chemFile); Assert.assertEquals(2, mol.getAtomCount()); Assert.assertEquals(1, mol.getBondCount()); org.openscience.cdk.interfaces.IBond bond = mol.getBond(0); Assert.assertEquals(CDKConstants.BONDORDER_DOUBLE, bond.getOrder()); Assert.assertTrue(bond.getFlag(CDKConstants.ISAROMATIC)); }
@Test(timeout = 1000) public void testPyrrole_Silent() throws Exception { String smiles = "c2ccc3n([H])c1ccccc1c3(c2)"; SmilesParser smilesParser = new SmilesParser(SilentChemObjectBuilder.getInstance()); IAtomContainer molecule = smilesParser.parseSmiles(smiles); molecule = fbot.kekuliseAromaticRings(molecule); Assert.assertNotNull(molecule); molecule = (IAtomContainer) AtomContainerManipulator.removeHydrogens(molecule); int doubleBondCount = 0; for (int i = 0; i < molecule.getBondCount(); i++) { IBond bond = molecule.getBond(i); Assert.assertTrue(bond.getFlag(CDKConstants.ISAROMATIC)); if (bond.getOrder() == Order.DOUBLE) doubleBondCount++; } Assert.assertEquals(6, doubleBondCount); }
/** * Determines if the isolatedRingSystem has attached double bonds, which are not part of the ring * system itself, and not part of any other ring system. Exceptions: a N.sp2.3 nitrogen with a * double ring to an oxygen outwards. */ private static boolean isRingSystemSproutedWithNonRingDoubleBonds( IAtomContainer fullContainer, IAtomContainer isolatedRingSystem) { Iterator<IAtom> atoms = isolatedRingSystem.atoms().iterator(); while (atoms.hasNext()) { IAtom atom = atoms.next(); Iterator<IBond> neighborBonds = fullContainer.getConnectedBondsList(atom).iterator(); while (neighborBonds.hasNext()) { IBond neighborBond = neighborBonds.next(); if (!neighborBond.getFlag(CDKConstants.ISINRING) && neighborBond.getOrder() == CDKConstants.BONDORDER_DOUBLE || neighborBond.getOrder() == CDKConstants.BONDORDER_TRIPLE) { if (!("N.sp2.3".equals(atom.getAtomTypeName()) && "O.sp2".equals(neighborBond.getConnectedAtom(atom).getAtomTypeName()))) return true; } } } return false; }
protected synchronized BitSet getStructureKeyBits(IAtomContainer ac) { // quick workaround for aromatic compounds, to avoid matching non-aromatic keys // TODO remove this when isoTester/keys processing is fixed // isoTester is fixed, but CDK isomorphism tester still needs the workaround, should be fixed in // CDK nightly Mar 2010 for (IBond bond : ac.bonds()) if (bond.getFlag(CDKConstants.ISAROMATIC)) { for (IAtom a : bond.atoms()) a.setFlag(CDKConstants.ISAROMATIC, true); // in e.g. triazole the atoms are not set as aromatics, but bonds are! if (cleanKekuleBonds) bond.setOrder(Order.SINGLE); } // end of the workaround BitSet keys = new BitSet(nKeys); boolean res; for (int i = 0; i < nKeys; i++) { isoTester.setSequence(smartsQueries.get(i), sequences.get(i)); res = isoTester.hasIsomorphism(ac); keys.set(i, res); } return (keys); }
/** * Initiate process. It is needed to call the addExplicitHydrogensToSatisfyValency from the class * tools.HydrogenAdder. * * @exception CDKException Description of the Exception * @param reactants reactants of the reaction. * @param agents agents of the reaction (Must be in this case null). */ @TestMethod("testInitiate_IAtomContainerSet_IAtomContainerSet") public IReactionSet initiate(IAtomContainerSet reactants, IAtomContainerSet agents) throws CDKException { logger.debug("initiate reaction: RearrangementRadicalReaction"); if (reactants.getAtomContainerCount() != 1) { throw new CDKException("RearrangementRadicalReaction only expects one reactant"); } if (agents != null) { throw new CDKException("RearrangementRadicalReaction don't expects agents"); } IReactionSet setOfReactions = DefaultChemObjectBuilder.getInstance().newInstance(IReactionSet.class); IAtomContainer reactant = reactants.getAtomContainer(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<IAtom> atoms = reactants.getAtomContainer(0).atoms().iterator(); while (atoms.hasNext()) { IAtom atomi = atoms.next(); if (atomi.getFlag(CDKConstants.REACTIVE_CENTER) && reactant.getConnectedSingleElectronsCount(atomi) == 1) { Iterator<IBond> bondis = reactant.getConnectedBondsList(atomi).iterator(); while (bondis.hasNext()) { IBond bondi = bondis.next(); if (bondi.getFlag(CDKConstants.REACTIVE_CENTER) && bondi.getOrder() == IBond.Order.SINGLE) { IAtom atomj = bondi.getConnectedAtom(atomi); if (atomi.getFlag(CDKConstants.REACTIVE_CENTER) && (atomj.getFormalCharge() == CDKConstants.UNSET ? 0 : atomj.getFormalCharge()) == 0 && reactant.getConnectedSingleElectronsCount(atomj) == 0) { Iterator<IBond> bondjs = reactant.getConnectedBondsList(atomj).iterator(); while (bondjs.hasNext()) { IBond bondj = bondjs.next(); if (bondj.equals(bondi)) continue; if (bondj.getFlag(CDKConstants.REACTIVE_CENTER) && bondj.getOrder() == IBond.Order.DOUBLE) { IAtom atomk = bondj.getConnectedAtom(atomj); if (atomk.getFlag(CDKConstants.REACTIVE_CENTER) && (atomk.getFormalCharge() == CDKConstants.UNSET ? 0 : atomk.getFormalCharge()) == 0 && reactant.getConnectedSingleElectronsCount(atomk) == 0) { ArrayList<IAtom> atomList = new ArrayList<IAtom>(); atomList.add(atomi); atomList.add(atomj); atomList.add(atomk); ArrayList<IBond> bondList = new ArrayList<IBond>(); bondList.add(bondi); bondList.add(bondj); IAtomContainerSet moleculeSet = reactant.getBuilder().newInstance(IAtomContainerSet.class); moleculeSet.addAtomContainer(reactant); IReaction reaction = mechanism.initiate(moleculeSet, atomList, bondList); if (reaction == null) continue; else setOfReactions.addReaction(reaction); } } } } } } } } return setOfReactions; }
@TestMethod(value = "testCalculate_IAtomContainer") public DescriptorValue calculate( IAtom atom, IAtomContainer atomContainer, IRingSet precalculatedringset) { IAtomContainer varAtomContainer; try { varAtomContainer = (IAtomContainer) atomContainer.clone(); } catch (CloneNotSupportedException e) { return getDummyDescriptorValue(e); } int atomPosition = atomContainer.getAtomNumber(atom); IAtom clonedAtom = varAtomContainer.getAtom(atomPosition); DoubleArrayResult rdfProtonCalculatedValues = new DoubleArrayResult(gsr_desc_length); if (!atom.getSymbol().equals("H")) { return getDummyDescriptorValue(new CDKException("Invalid atom specified")); } ///////////////////////// FIRST SECTION OF MAIN METHOD: DEFINITION OF MAIN VARIABLES ///////////////////////// AND AROMATICITY AND PI-SYSTEM AND RINGS DETECTION Molecule mol = new Molecule(varAtomContainer); if (varAtomContainer != acold) { acold = varAtomContainer; // DETECTION OF pi SYSTEMS varAtomContainerSet = ConjugatedPiSystemsDetector.detect(mol); if (precalculatedringset == null) try { varRingSet = (new AllRingsFinder()).findAllRings(varAtomContainer); } catch (CDKException e) { return getDummyDescriptorValue(e); } else varRingSet = precalculatedringset; try { GasteigerMarsiliPartialCharges peoe = new GasteigerMarsiliPartialCharges(); peoe.assignGasteigerMarsiliSigmaPartialCharges(mol, true); } catch (Exception ex1) { return getDummyDescriptorValue(ex1); } } if (checkAromaticity) { try { AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(varAtomContainer); CDKHueckelAromaticityDetector.detectAromaticity(varAtomContainer); } catch (CDKException e) { return getDummyDescriptorValue(e); } } IRingSet rsAtom; Ring ring; IRingSet ringsWithThisBond; // SET ISINRING FLAGS FOR BONDS Iterator<IBond> bondsInContainer = varAtomContainer.bonds().iterator(); while (bondsInContainer.hasNext()) { IBond bond = bondsInContainer.next(); ringsWithThisBond = varRingSet.getRings(bond); if (ringsWithThisBond.getAtomContainerCount() > 0) { bond.setFlag(CDKConstants.ISINRING, true); } } // SET ISINRING FLAGS FOR ATOMS IRingSet ringsWithThisAtom; for (int w = 0; w < varAtomContainer.getAtomCount(); w++) { ringsWithThisAtom = varRingSet.getRings(varAtomContainer.getAtom(w)); if (ringsWithThisAtom.getAtomContainerCount() > 0) { varAtomContainer.getAtom(w).setFlag(CDKConstants.ISINRING, true); } } IAtomContainer detected = varAtomContainerSet.getAtomContainer(0); // neighboors[0] is the atom joined to the target proton: List<IAtom> neighboors = mol.getConnectedAtomsList(clonedAtom); IAtom neighbour0 = neighboors.get(0); // 2', 3', 4', 5', 6', and 7' atoms up to the target are detected: List<IAtom> atomsInSecondSphere = mol.getConnectedAtomsList(neighbour0); List<IAtom> atomsInThirdSphere; List<IAtom> atomsInFourthSphere; List<IAtom> atomsInFifthSphere; List<IAtom> atomsInSixthSphere; List<IAtom> atomsInSeventhSphere; // SOME LISTS ARE CREATED FOR STORING OF INTERESTING ATOMS AND BONDS DURING DETECTION ArrayList<Integer> singles = new ArrayList<Integer>(); // list of any bond not rotatable ArrayList<Integer> doubles = new ArrayList<Integer>(); // list with only double bonds ArrayList<Integer> atoms = new ArrayList<Integer>(); // list with all the atoms in spheres // atoms.add( Integer.valueOf( mol.getAtomNumber(neighboors[0]) ) ); ArrayList<Integer> bondsInCycloex = new ArrayList<Integer>(); // list for bonds in cycloexane-like rings // 2', 3', 4', 5', 6', and 7' bonds up to the target are detected: IBond secondBond; // (remember that first bond is proton bond) IBond thirdBond; // IBond fourthBond; // IBond fifthBond; // IBond sixthBond; // IBond seventhBond; // // definition of some variables used in the main FOR loop for detection of interesting atoms and // bonds: boolean theBondIsInA6MemberedRing; // this is like a flag for bonds which are in cycloexane-like // rings (rings with more than 4 at.) IBond.Order bondOrder; int bondNumber; int sphere; // THIS MAIN FOR LOOP DETECT RIGID BONDS IN 7 SPHERES: for (IAtom curAtomSecond : atomsInSecondSphere) { secondBond = mol.getBond(neighbour0, curAtomSecond); if (mol.getAtomNumber(curAtomSecond) != atomPosition && getIfBondIsNotRotatable(mol, secondBond, detected)) { sphere = 2; bondOrder = secondBond.getOrder(); bondNumber = mol.getBondNumber(secondBond); theBondIsInA6MemberedRing = false; checkAndStore( bondNumber, bondOrder, singles, doubles, bondsInCycloex, mol.getAtomNumber(curAtomSecond), atoms, sphere, theBondIsInA6MemberedRing); atomsInThirdSphere = mol.getConnectedAtomsList(curAtomSecond); if (atomsInThirdSphere.size() > 0) { for (IAtom curAtomThird : atomsInThirdSphere) { thirdBond = mol.getBond(curAtomThird, curAtomSecond); // IF THE ATOMS IS IN THE THIRD SPHERE AND IN A CYCLOEXANE-LIKE RING, IT IS STORED IN // THE PROPER LIST: if (mol.getAtomNumber(curAtomThird) != atomPosition && getIfBondIsNotRotatable(mol, thirdBond, detected)) { sphere = 3; bondOrder = thirdBond.getOrder(); bondNumber = mol.getBondNumber(thirdBond); theBondIsInA6MemberedRing = false; // if the bond is in a cyclohexane-like ring (a ring with 5 or more atoms, not // aromatic) // the boolean "theBondIsInA6MemberedRing" is set to true if (!thirdBond.getFlag(CDKConstants.ISAROMATIC)) { if (!curAtomThird.equals(neighbour0)) { rsAtom = varRingSet.getRings(thirdBond); for (int f = 0; f < rsAtom.getAtomContainerCount(); f++) { ring = (Ring) rsAtom.getAtomContainer(f); if (ring.getRingSize() > 4 && ring.contains(thirdBond)) { theBondIsInA6MemberedRing = true; } } } } checkAndStore( bondNumber, bondOrder, singles, doubles, bondsInCycloex, mol.getAtomNumber(curAtomThird), atoms, sphere, theBondIsInA6MemberedRing); theBondIsInA6MemberedRing = false; atomsInFourthSphere = mol.getConnectedAtomsList(curAtomThird); if (atomsInFourthSphere.size() > 0) { for (IAtom curAtomFourth : atomsInFourthSphere) { fourthBond = mol.getBond(curAtomThird, curAtomFourth); if (mol.getAtomNumber(curAtomFourth) != atomPosition && getIfBondIsNotRotatable(mol, fourthBond, detected)) { sphere = 4; bondOrder = fourthBond.getOrder(); bondNumber = mol.getBondNumber(fourthBond); theBondIsInA6MemberedRing = false; checkAndStore( bondNumber, bondOrder, singles, doubles, bondsInCycloex, mol.getAtomNumber(curAtomFourth), atoms, sphere, theBondIsInA6MemberedRing); atomsInFifthSphere = mol.getConnectedAtomsList(curAtomFourth); if (atomsInFifthSphere.size() > 0) { for (IAtom curAtomFifth : atomsInFifthSphere) { fifthBond = mol.getBond(curAtomFifth, curAtomFourth); if (mol.getAtomNumber(curAtomFifth) != atomPosition && getIfBondIsNotRotatable(mol, fifthBond, detected)) { sphere = 5; bondOrder = fifthBond.getOrder(); bondNumber = mol.getBondNumber(fifthBond); theBondIsInA6MemberedRing = false; checkAndStore( bondNumber, bondOrder, singles, doubles, bondsInCycloex, mol.getAtomNumber(curAtomFifth), atoms, sphere, theBondIsInA6MemberedRing); atomsInSixthSphere = mol.getConnectedAtomsList(curAtomFifth); if (atomsInSixthSphere.size() > 0) { for (IAtom curAtomSixth : atomsInSixthSphere) { sixthBond = mol.getBond(curAtomFifth, curAtomSixth); if (mol.getAtomNumber(curAtomSixth) != atomPosition && getIfBondIsNotRotatable(mol, sixthBond, detected)) { sphere = 6; bondOrder = sixthBond.getOrder(); bondNumber = mol.getBondNumber(sixthBond); theBondIsInA6MemberedRing = false; checkAndStore( bondNumber, bondOrder, singles, doubles, bondsInCycloex, mol.getAtomNumber(curAtomSixth), atoms, sphere, theBondIsInA6MemberedRing); atomsInSeventhSphere = mol.getConnectedAtomsList(curAtomSixth); if (atomsInSeventhSphere.size() > 0) { for (IAtom curAtomSeventh : atomsInSeventhSphere) { seventhBond = mol.getBond(curAtomSeventh, curAtomSixth); if (mol.getAtomNumber(curAtomSeventh) != atomPosition && getIfBondIsNotRotatable(mol, seventhBond, detected)) { sphere = 7; bondOrder = seventhBond.getOrder(); bondNumber = mol.getBondNumber(seventhBond); theBondIsInA6MemberedRing = false; checkAndStore( bondNumber, bondOrder, singles, doubles, bondsInCycloex, mol.getAtomNumber(curAtomSeventh), atoms, sphere, theBondIsInA6MemberedRing); } } } } } } } } } } } } } } } } } // Variables double[] values; // for storage of results of other methods double distance; double sum; double smooth = -20; double partial; int position; double limitInf; double limitSup; double step; //////////////////////// THE FOUTH DESCRIPTOR IS gS(r), WHICH TAKES INTO ACCOUNT SINGLE BONDS IN // RIGID SYSTEMS Vector3d a_a = new Vector3d(); Vector3d a_b = new Vector3d(); Vector3d b_a = new Vector3d(); Vector3d b_b = new Vector3d(); Point3d middlePoint = new Point3d(); double angle = 0; if (singles.size() > 0) { double dist0; double dist1; IAtom singleBondAtom0; IAtom singleBondAtom1; distance = 0; position = 0; IBond theSingleBond = null; limitInf = 0; limitSup = Math.PI / 2; step = (limitSup - limitInf) / 7; smooth = -1.15; int counter = 0; for (double ghs = 0; ghs < limitSup; ghs = ghs + step) { sum = 0; for (int sing = 0; sing < singles.size(); sing++) { angle = 0; partial = 0; Integer thisSingleBond = singles.get(sing); position = thisSingleBond; theSingleBond = mol.getBond(position); middlePoint = theSingleBond.get3DCenter(); singleBondAtom0 = theSingleBond.getAtom(0); singleBondAtom1 = theSingleBond.getAtom(1); dist0 = calculateDistanceBetweenTwoAtoms(singleBondAtom0, atom); dist1 = calculateDistanceBetweenTwoAtoms(singleBondAtom1, atom); a_a.set(middlePoint.x, middlePoint.y, middlePoint.z); if (dist1 > dist0) a_b.set( singleBondAtom0.getPoint3d().x, singleBondAtom0.getPoint3d().y, singleBondAtom0.getPoint3d().z); else a_b.set( singleBondAtom1.getPoint3d().x, singleBondAtom1.getPoint3d().y, singleBondAtom1.getPoint3d().z); b_a.set(middlePoint.x, middlePoint.y, middlePoint.z); b_b.set(atom.getPoint3d().x, atom.getPoint3d().y, atom.getPoint3d().z); values = calculateDistanceBetweenAtomAndBond(atom, theSingleBond); angle = calculateAngleBetweenTwoLines(a_a, a_b, b_a, b_b); // System.out.println("ANGLe: "+angle+ " "+ mol.getAtomNumber(atomsInSingleBond[0]) +" " // +mol.getAtomNumber(atomsInSingleBond[1])); partial = (1 / (Math.pow(values[0], 2))) * Math.exp(smooth * (Math.pow((ghs - angle), 2))); sum += partial; } // gSr_function.add(new Double(sum)); rdfProtonCalculatedValues.add(sum); logger.debug("RDF gSr prob.: " + sum + " at distance " + ghs); counter++; } } else { return getDummyDescriptorValue(new CDKException("Some error occurred. Please report")); } return new DescriptorValue( getSpecification(), getParameterNames(), getParameters(), rdfProtonCalculatedValues, getDescriptorNames()); }