// method which calculated distance btw an atom and the middle point of a bond // and returns distance and coordinates of middle point private double[] calculateDistanceBetweenAtomAndBond(IAtom proton, IBond theBond) { Point3d middlePoint = theBond.get3DCenter(); Point3d protonPoint = proton.getPoint3d(); double[] values = new double[4]; values[0] = middlePoint.distance(protonPoint); values[1] = middlePoint.x; values[2] = middlePoint.y; values[3] = middlePoint.z; return values; }
@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()); }