Search in sources :

Example 1 with GasteigerMarsiliPartialCharges

use of org.openscience.cdk.charges.GasteigerMarsiliPartialCharges in project ambit-mirror by ideaconsult.

the class TestUtils method testPartialCharges.

public static void testPartialCharges(String smi) throws Exception {
    System.out.println("Test partial charges for " + smi);
    DecimalFormat df = new DecimalFormat("0.000", new DecimalFormatSymbols(new Locale("en-US")));
    IAtomContainer mol = SmartsHelper.getMoleculeFromSmiles(smi, true);
    // IChargeCalculator chargeCalc = new GasteigerPEPEPartialCharges(); - not working --> only 0.0 charges
    // IChargeCalculator chargeCalc = new InductivePartialCharges(); - not working --> Exception
    // MMFF94PartialCharges present in CDK 2.3
    // GasteigerPEPEPartialCharges  gastPC = new GasteigerPEPEPartialCharges();
    // gastPC.assignGasteigerPiPartialCharges(mol, true);
    IChargeCalculator chargeCalc = new GasteigerMarsiliPartialCharges();
    chargeCalc.calculateCharges(mol);
    for (int i = 0; i < mol.getAtomCount(); i++) {
        IAtom at = mol.getAtom(i);
        System.out.println("" + (i + 1) + "  " + at.getSymbol() + "  " + df.format(at.getCharge()));
    }
}
Also used : Locale(java.util.Locale) GasteigerMarsiliPartialCharges(org.openscience.cdk.charges.GasteigerMarsiliPartialCharges) IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) IChargeCalculator(org.openscience.cdk.charges.IChargeCalculator) DecimalFormatSymbols(java.text.DecimalFormatSymbols) DecimalFormat(java.text.DecimalFormat) IAtom(org.openscience.cdk.interfaces.IAtom)

Example 2 with GasteigerMarsiliPartialCharges

use of org.openscience.cdk.charges.GasteigerMarsiliPartialCharges in project cdk by cdk.

the class RDFProtonDescriptor_GDR method calculate.

public DescriptorValue calculate(IAtom atom, IAtomContainer atomContainer, IRingSet precalculatedringset) {
    IAtomContainer varAtomContainer;
    try {
        varAtomContainer = atomContainer.clone();
    } catch (CloneNotSupportedException e) {
        return getDummyDescriptorValue(e);
    }
    int atomPosition = atomContainer.indexOf(atom);
    IAtom clonedAtom = varAtomContainer.getAtom(atomPosition);
    DoubleArrayResult rdfProtonCalculatedValues = new DoubleArrayResult(gdr_desc_length);
    if (atom.getAtomicNumber() != IElement.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
    IAtomContainer mol = varAtomContainer.getBuilder().newInstance(IAtomContainer.class, 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);
            Aromaticity.cdkLegacy().apply(varAtomContainer);
        } catch (CDKException e) {
            return getDummyDescriptorValue(e);
        }
    }
    IRingSet rsAtom;
    IRing ring;
    IRingSet ringsWithThisBond;
    for (IBond bond : varAtomContainer.bonds()) {
        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
    // list of any bond not rotatable
    ArrayList<Integer> singles = new ArrayList<>();
    // list with only double bonds
    ArrayList<Integer> doubles = new ArrayList<>();
    // list with all the atoms in spheres
    ArrayList<Integer> atoms = new ArrayList<>();
    // atoms.add( Integer.valueOf( mol.indexOf(neighboors[0]) ) );
    // list for bonds in cycloexane-like rings
    ArrayList<Integer> bondsInCycloex = new ArrayList<>();
    // 2', 3', 4', 5', 6', and 7' bonds up to the target are detected:
    // (remember that first bond is proton bond)
    IBond secondBond;
    // 
    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:
    // this is like a flag for bonds which are in cycloexane-like rings (rings with more than 4 at.)
    boolean theBondIsInA6MemberedRing;
    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.indexOf(curAtomSecond) != atomPosition && getIfBondIsNotRotatable(mol, secondBond, detected)) {
            sphere = 2;
            bondOrder = secondBond.getOrder();
            bondNumber = mol.indexOf(secondBond);
            theBondIsInA6MemberedRing = false;
            checkAndStore(bondNumber, bondOrder, singles, doubles, bondsInCycloex, mol.indexOf(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.indexOf(curAtomThird) != atomPosition && getIfBondIsNotRotatable(mol, thirdBond, detected)) {
                        sphere = 3;
                        bondOrder = thirdBond.getOrder();
                        bondNumber = mol.indexOf(thirdBond);
                        theBondIsInA6MemberedRing = false;
                        // the boolean "theBondIsInA6MemberedRing" is set to true
                        if (!thirdBond.getFlag(CDKConstants.ISAROMATIC)) {
                            if (!curAtomThird.equals(neighbour0)) {
                                rsAtom = varRingSet.getRings(thirdBond);
                                for (Object aRsAtom : rsAtom.atomContainers()) {
                                    ring = (IRing) aRsAtom;
                                    if (ring.getRingSize() > 4 && ring.contains(thirdBond)) {
                                        theBondIsInA6MemberedRing = true;
                                    }
                                }
                            }
                        }
                        checkAndStore(bondNumber, bondOrder, singles, doubles, bondsInCycloex, mol.indexOf(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.indexOf(curAtomFourth) != atomPosition && getIfBondIsNotRotatable(mol, fourthBond, detected)) {
                                    sphere = 4;
                                    bondOrder = fourthBond.getOrder();
                                    bondNumber = mol.indexOf(fourthBond);
                                    theBondIsInA6MemberedRing = false;
                                    checkAndStore(bondNumber, bondOrder, singles, doubles, bondsInCycloex, mol.indexOf(curAtomFourth), atoms, sphere, theBondIsInA6MemberedRing);
                                    atomsInFifthSphere = mol.getConnectedAtomsList(curAtomFourth);
                                    if (atomsInFifthSphere.size() > 0) {
                                        for (IAtom curAtomFifth : atomsInFifthSphere) {
                                            fifthBond = mol.getBond(curAtomFifth, curAtomFourth);
                                            if (mol.indexOf(curAtomFifth) != atomPosition && getIfBondIsNotRotatable(mol, fifthBond, detected)) {
                                                sphere = 5;
                                                bondOrder = fifthBond.getOrder();
                                                bondNumber = mol.indexOf(fifthBond);
                                                theBondIsInA6MemberedRing = false;
                                                checkAndStore(bondNumber, bondOrder, singles, doubles, bondsInCycloex, mol.indexOf(curAtomFifth), atoms, sphere, theBondIsInA6MemberedRing);
                                                atomsInSixthSphere = mol.getConnectedAtomsList(curAtomFifth);
                                                if (atomsInSixthSphere.size() > 0) {
                                                    for (IAtom curAtomSixth : atomsInSixthSphere) {
                                                        sixthBond = mol.getBond(curAtomFifth, curAtomSixth);
                                                        if (mol.indexOf(curAtomSixth) != atomPosition && getIfBondIsNotRotatable(mol, sixthBond, detected)) {
                                                            sphere = 6;
                                                            bondOrder = sixthBond.getOrder();
                                                            bondNumber = mol.indexOf(sixthBond);
                                                            theBondIsInA6MemberedRing = false;
                                                            checkAndStore(bondNumber, bondOrder, singles, doubles, bondsInCycloex, mol.indexOf(curAtomSixth), atoms, sphere, theBondIsInA6MemberedRing);
                                                            atomsInSeventhSphere = mol.getConnectedAtomsList(curAtomSixth);
                                                            if (atomsInSeventhSphere.size() > 0) {
                                                                for (IAtom curAtomSeventh : atomsInSeventhSphere) {
                                                                    seventhBond = mol.getBond(curAtomSeventh, curAtomSixth);
                                                                    if (mol.indexOf(curAtomSeventh) != atomPosition && getIfBondIsNotRotatable(mol, seventhBond, detected)) {
                                                                        sphere = 7;
                                                                        bondOrder = seventhBond.getOrder();
                                                                        bondNumber = mol.indexOf(seventhBond);
                                                                        theBondIsInA6MemberedRing = false;
                                                                        checkAndStore(bondNumber, bondOrder, singles, doubles, bondsInCycloex, mol.indexOf(curAtomSeventh), atoms, sphere, theBondIsInA6MemberedRing);
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    // Variables
    // for storage of results of other methods
    double[] values;
    double sum;
    double smooth;
    double partial;
    int position;
    double limitInf;
    double limitSup;
    double step;
    // //////////////////////THE THIRD DESCRIPTOR IS gD(r) WITH DISTANCE AND RADIAN ANGLE BTW THE PROTON AND THE MIDDLE POINT OF DOUBLE BOND
    Vector3d aA = new Vector3d();
    Vector3d aB = new Vector3d();
    Vector3d bA = new Vector3d();
    Vector3d bB = new Vector3d();
    Point3d middlePoint = new Point3d();
    double angle;
    if (doubles.size() > -0.0001) {
        IAtom goodAtom0;
        IAtom goodAtom1;
        limitInf = 0;
        limitSup = Math.PI / 2;
        position = 0;
        partial = 0;
        IBond theDoubleBond;
        smooth = -1.15;
        int goodPosition;
        IBond goodBond;
        for (int c = 0; c < gdr_desc_length; c++) {
            double ghd = limitInf + (limitSup - limitInf) * ((double) c / gdr_desc_length);
            sum = 0;
            for (Integer aDouble : doubles) {
                partial = 0;
                position = aDouble;
                theDoubleBond = mol.getBond(position);
                goodPosition = getNearestBondtoAGivenAtom(mol, atom, theDoubleBond);
                goodBond = mol.getBond(goodPosition);
                goodAtom0 = goodBond.getBegin();
                goodAtom1 = goodBond.getEnd();
                // System.out.println("GOOD POS IS "+mol.indexOf(goodAtoms[0])+" "+mol.indexOf(goodAtoms[1]));
                middlePoint = theDoubleBond.get3DCenter();
                values = calculateDistanceBetweenAtomAndBond(atom, theDoubleBond);
                if (theDoubleBond.contains(goodAtom0)) {
                    aA.set(goodAtom0.getPoint3d().x, goodAtom0.getPoint3d().y, goodAtom0.getPoint3d().z);
                    aB.set(goodAtom1.getPoint3d().x, goodAtom1.getPoint3d().y, goodAtom1.getPoint3d().z);
                } else {
                    aA.set(goodAtom1.getPoint3d().x, goodAtom1.getPoint3d().y, goodAtom1.getPoint3d().z);
                    aB.set(goodAtom0.getPoint3d().x, goodAtom0.getPoint3d().y, goodAtom0.getPoint3d().z);
                }
                bA.set(middlePoint.x, middlePoint.y, middlePoint.z);
                bB.set(atom.getPoint3d().x, atom.getPoint3d().y, atom.getPoint3d().z);
                angle = calculateAngleBetweenTwoLines(aA, aB, bA, bB);
                partial = ((1 / (Math.pow(values[0], 2))) * Math.exp(smooth * (Math.pow((ghd - angle), 2))));
                sum += partial;
            }
            // gDr_function.add(new Double(sum));
            rdfProtonCalculatedValues.add(sum);
            LOGGER.debug("GDR prob dist.: " + sum + " at distance " + ghd);
        }
    } else {
        return getDummyDescriptorValue(new CDKException("Some error occurred. Please report"));
    }
    return new DescriptorValue(getSpecification(), getParameterNames(), getParameters(), rdfProtonCalculatedValues, getDescriptorNames());
}
Also used : IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) CDKException(org.openscience.cdk.exception.CDKException) IBond(org.openscience.cdk.interfaces.IBond) ArrayList(java.util.ArrayList) AllRingsFinder(org.openscience.cdk.ringsearch.AllRingsFinder) CDKException(org.openscience.cdk.exception.CDKException) DescriptorValue(org.openscience.cdk.qsar.DescriptorValue) GasteigerMarsiliPartialCharges(org.openscience.cdk.charges.GasteigerMarsiliPartialCharges) IRing(org.openscience.cdk.interfaces.IRing) Vector3d(javax.vecmath.Vector3d) IRingSet(org.openscience.cdk.interfaces.IRingSet) Point3d(javax.vecmath.Point3d) DoubleArrayResult(org.openscience.cdk.qsar.result.DoubleArrayResult) IAtom(org.openscience.cdk.interfaces.IAtom)

Example 3 with GasteigerMarsiliPartialCharges

use of org.openscience.cdk.charges.GasteigerMarsiliPartialCharges in project cdk by cdk.

the class RDFProtonDescriptor_GHR method calculate.

public DescriptorValue calculate(IAtom atom, IAtomContainer atomContainer, IRingSet precalculatedringset) {
    IAtomContainer varAtomContainer;
    try {
        varAtomContainer = atomContainer.clone();
    } catch (CloneNotSupportedException e) {
        return getDummyDescriptorValue(e);
    }
    int atomPosition = atomContainer.indexOf(atom);
    IAtom clonedAtom = varAtomContainer.getAtom(atomPosition);
    DoubleArrayResult rdfProtonCalculatedValues = new DoubleArrayResult(ghr_desc_length);
    if (atom.getAtomicNumber() != IElement.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
    IAtomContainer mol = varAtomContainer.getBuilder().newInstance(IAtomContainer.class, 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);
            Aromaticity.cdkLegacy().apply(varAtomContainer);
        } catch (CDKException e) {
            return getDummyDescriptorValue(e);
        }
    }
    IRingSet rsAtom;
    IRing ring;
    IRingSet ringsWithThisBond;
    // SET ISINRING FLAGS FOR BONDS
    for (IBond bond : varAtomContainer.bonds()) {
        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
    // list of any bond not rotatable
    ArrayList<Integer> singles = new ArrayList<>();
    // list with only double bonds
    ArrayList<Integer> doubles = new ArrayList<>();
    // list with all the atoms in spheres
    ArrayList<Integer> atoms = new ArrayList<>();
    // atoms.add( Integer.valueOf( mol.indexOf(neighboors[0]) ) );
    // list for bonds in cycloexane-like rings
    ArrayList<Integer> bondsInCycloex = new ArrayList<>();
    // 2', 3', 4', 5', 6', and 7' bonds up to the target are detected:
    // (remember that first bond is proton bond)
    IBond secondBond;
    // 
    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:
    // this is like a flag for bonds which are in cycloexane-like rings (rings with more than 4 at.)
    boolean theBondIsInA6MemberedRing;
    IBond.Order bondOrder;
    int bondNumber;
    int sphere;
    // THIS MAIN FOR LOOP DETECT RIGID BONDS IN 7 SPHERES:
    for (Object anAtomsInSecondSphere : atomsInSecondSphere) {
        IAtom curAtomSecond = (IAtom) anAtomsInSecondSphere;
        secondBond = mol.getBond(neighbour0, curAtomSecond);
        if (mol.indexOf(curAtomSecond) != atomPosition && getIfBondIsNotRotatable(mol, secondBond, detected)) {
            sphere = 2;
            bondOrder = secondBond.getOrder();
            bondNumber = mol.indexOf(secondBond);
            theBondIsInA6MemberedRing = false;
            checkAndStore(bondNumber, bondOrder, singles, doubles, bondsInCycloex, mol.indexOf(curAtomSecond), atoms, sphere, theBondIsInA6MemberedRing);
            atomsInThirdSphere = mol.getConnectedAtomsList(curAtomSecond);
            if (atomsInThirdSphere.size() > 0) {
                for (Object anAtomsInThirdSphere : atomsInThirdSphere) {
                    IAtom curAtomThird = (IAtom) anAtomsInThirdSphere;
                    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.indexOf(curAtomThird) != atomPosition && getIfBondIsNotRotatable(mol, thirdBond, detected)) {
                        sphere = 3;
                        bondOrder = thirdBond.getOrder();
                        bondNumber = mol.indexOf(thirdBond);
                        theBondIsInA6MemberedRing = false;
                        // 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 = (IRing) rsAtom.getAtomContainer(f);
                                    if (ring.getRingSize() > 4 && ring.contains(thirdBond)) {
                                        theBondIsInA6MemberedRing = true;
                                    }
                                }
                            }
                        }
                        checkAndStore(bondNumber, bondOrder, singles, doubles, bondsInCycloex, mol.indexOf(curAtomThird), atoms, sphere, theBondIsInA6MemberedRing);
                        theBondIsInA6MemberedRing = false;
                        atomsInFourthSphere = mol.getConnectedAtomsList(curAtomThird);
                        if (atomsInFourthSphere.size() > 0) {
                            for (Object anAtomsInFourthSphere : atomsInFourthSphere) {
                                IAtom curAtomFourth = (IAtom) anAtomsInFourthSphere;
                                fourthBond = mol.getBond(curAtomThird, curAtomFourth);
                                if (mol.indexOf(curAtomFourth) != atomPosition && getIfBondIsNotRotatable(mol, fourthBond, detected)) {
                                    sphere = 4;
                                    bondOrder = fourthBond.getOrder();
                                    bondNumber = mol.indexOf(fourthBond);
                                    theBondIsInA6MemberedRing = false;
                                    checkAndStore(bondNumber, bondOrder, singles, doubles, bondsInCycloex, mol.indexOf(curAtomFourth), atoms, sphere, theBondIsInA6MemberedRing);
                                    atomsInFifthSphere = mol.getConnectedAtomsList(curAtomFourth);
                                    if (atomsInFifthSphere.size() > 0) {
                                        for (Object anAtomsInFifthSphere : atomsInFifthSphere) {
                                            IAtom curAtomFifth = (IAtom) anAtomsInFifthSphere;
                                            fifthBond = mol.getBond(curAtomFifth, curAtomFourth);
                                            if (mol.indexOf(curAtomFifth) != atomPosition && getIfBondIsNotRotatable(mol, fifthBond, detected)) {
                                                sphere = 5;
                                                bondOrder = fifthBond.getOrder();
                                                bondNumber = mol.indexOf(fifthBond);
                                                theBondIsInA6MemberedRing = false;
                                                checkAndStore(bondNumber, bondOrder, singles, doubles, bondsInCycloex, mol.indexOf(curAtomFifth), atoms, sphere, theBondIsInA6MemberedRing);
                                                atomsInSixthSphere = mol.getConnectedAtomsList(curAtomFifth);
                                                if (atomsInSixthSphere.size() > 0) {
                                                    for (Object anAtomsInSixthSphere : atomsInSixthSphere) {
                                                        IAtom curAtomSixth = (IAtom) anAtomsInSixthSphere;
                                                        sixthBond = mol.getBond(curAtomFifth, curAtomSixth);
                                                        if (mol.indexOf(curAtomSixth) != atomPosition && getIfBondIsNotRotatable(mol, sixthBond, detected)) {
                                                            sphere = 6;
                                                            bondOrder = sixthBond.getOrder();
                                                            bondNumber = mol.indexOf(sixthBond);
                                                            theBondIsInA6MemberedRing = false;
                                                            checkAndStore(bondNumber, bondOrder, singles, doubles, bondsInCycloex, mol.indexOf(curAtomSixth), atoms, sphere, theBondIsInA6MemberedRing);
                                                            atomsInSeventhSphere = mol.getConnectedAtomsList(curAtomSixth);
                                                            if (atomsInSeventhSphere.size() > 0) {
                                                                for (Object anAtomsInSeventhSphere : atomsInSeventhSphere) {
                                                                    IAtom curAtomSeventh = (IAtom) anAtomsInSeventhSphere;
                                                                    seventhBond = mol.getBond(curAtomSeventh, curAtomSixth);
                                                                    if (mol.indexOf(curAtomSeventh) != atomPosition && getIfBondIsNotRotatable(mol, seventhBond, detected)) {
                                                                        sphere = 7;
                                                                        bondOrder = seventhBond.getOrder();
                                                                        bondNumber = mol.indexOf(seventhBond);
                                                                        theBondIsInA6MemberedRing = false;
                                                                        checkAndStore(bondNumber, bondOrder, singles, doubles, bondsInCycloex, mol.indexOf(curAtomSeventh), atoms, sphere, theBondIsInA6MemberedRing);
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    // Variables
    double distance;
    double sum;
    double smooth = -20;
    double partial;
    int position;
    double limitInf = 1.4;
    double limitSup = 4;
    IAtom atom2;
    // /////////////////////THE FIRST CALCULATED DESCRIPTOR IS g(H)r	 WITH PARTIAL CHARGES:
    if (atoms.size() > 0) {
        for (int c = 0; c < ghr_desc_length; c++) {
            double ghr = limitInf + (limitSup - limitInf) * ((double) c / ghr_desc_length);
            sum = 0;
            for (Object atom1 : atoms) {
                distance = 0;
                partial = 0;
                Integer thisAtom = (Integer) atom1;
                position = thisAtom;
                atom2 = mol.getAtom(position);
                distance = calculateDistanceBetweenTwoAtoms(atom, atom2);
                partial = atom2.getCharge() * Math.exp(smooth * (Math.pow((ghr - distance), 2)));
                sum += partial;
            }
            rdfProtonCalculatedValues.add(sum);
            LOGGER.debug("RDF gr distance prob.: " + sum + " at distance " + ghr);
        }
    } else {
        return getDummyDescriptorValue(new CDKException("Some error occurred. Please report"));
    }
    return new DescriptorValue(getSpecification(), getParameterNames(), getParameters(), rdfProtonCalculatedValues, getDescriptorNames());
}
Also used : IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) CDKException(org.openscience.cdk.exception.CDKException) IBond(org.openscience.cdk.interfaces.IBond) ArrayList(java.util.ArrayList) AllRingsFinder(org.openscience.cdk.ringsearch.AllRingsFinder) CDKException(org.openscience.cdk.exception.CDKException) DescriptorValue(org.openscience.cdk.qsar.DescriptorValue) GasteigerMarsiliPartialCharges(org.openscience.cdk.charges.GasteigerMarsiliPartialCharges) IRing(org.openscience.cdk.interfaces.IRing) IRingSet(org.openscience.cdk.interfaces.IRingSet) DoubleArrayResult(org.openscience.cdk.qsar.result.DoubleArrayResult) IAtom(org.openscience.cdk.interfaces.IAtom)

Example 4 with GasteigerMarsiliPartialCharges

use of org.openscience.cdk.charges.GasteigerMarsiliPartialCharges in project cdk by cdk.

the class RDFProtonDescriptor_GHR_topol method calculate.

public DescriptorValue calculate(IAtom atom, IAtomContainer atomContainer, IRingSet precalculatedringset) {
    IAtomContainer varAtomContainer;
    try {
        varAtomContainer = atomContainer.clone();
    } catch (CloneNotSupportedException e) {
        return getDummyDescriptorValue(e);
    }
    int atomPosition = atomContainer.indexOf(atom);
    IAtom clonedAtom = varAtomContainer.getAtom(atomPosition);
    DoubleArrayResult rdfProtonCalculatedValues = new DoubleArrayResult(ghr_topol_desc_length);
    if (atom.getAtomicNumber() != IElement.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
    IAtomContainer mol = varAtomContainer.getBuilder().newInstance(IAtomContainer.class, 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);
            Aromaticity.cdkLegacy().apply(varAtomContainer);
        } catch (CDKException e) {
            return getDummyDescriptorValue(e);
        }
    }
    IRingSet rsAtom;
    IRing ring;
    IRingSet ringsWithThisBond;
    // SET ISINRING FLAGS FOR BONDS
    for (IBond bond : varAtomContainer.bonds()) {
        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
    // list of any bond not rotatable
    ArrayList<Integer> singles = new ArrayList<>();
    // list with only double bonds
    ArrayList<Integer> doubles = new ArrayList<>();
    // list with all the atoms in spheres
    ArrayList<Integer> atoms = new ArrayList<>();
    // atoms.add( Integer.valueOf( mol.indexOf(neighboors[0]) ) );
    // list for bonds in cycloexane-like rings
    ArrayList<Integer> bondsInCycloex = new ArrayList<>();
    // 2', 3', 4', 5', 6', and 7' bonds up to the target are detected:
    // (remember that first bond is proton bond)
    IBond secondBond;
    // 
    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:
    // this is like a flag for bonds which are in cycloexane-like rings (rings with more than 4 at.)
    boolean theBondIsInA6MemberedRing;
    IBond.Order bondOrder;
    int bondNumber;
    int sphere;
    // THIS MAIN FOR LOOP DETECT RIGID BONDS IN 7 SPHERES:
    for (Object anAtomsInSecondSphere : atomsInSecondSphere) {
        IAtom curAtomSecond = (IAtom) anAtomsInSecondSphere;
        secondBond = mol.getBond(neighbour0, curAtomSecond);
        if (mol.indexOf(curAtomSecond) != atomPosition && getIfBondIsNotRotatable(mol, secondBond, detected)) {
            sphere = 2;
            bondOrder = secondBond.getOrder();
            bondNumber = mol.indexOf(secondBond);
            theBondIsInA6MemberedRing = false;
            checkAndStore(bondNumber, bondOrder, singles, doubles, bondsInCycloex, mol.indexOf(curAtomSecond), atoms, sphere, theBondIsInA6MemberedRing);
            atomsInThirdSphere = mol.getConnectedAtomsList(curAtomSecond);
            if (atomsInThirdSphere.size() > 0) {
                for (Object anAtomsInThirdSphere : atomsInThirdSphere) {
                    IAtom curAtomThird = (IAtom) anAtomsInThirdSphere;
                    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.indexOf(curAtomThird) != atomPosition && getIfBondIsNotRotatable(mol, thirdBond, detected)) {
                        sphere = 3;
                        bondOrder = thirdBond.getOrder();
                        bondNumber = mol.indexOf(thirdBond);
                        theBondIsInA6MemberedRing = false;
                        // the boolean "theBondIsInA6MemberedRing" is set to true
                        if (!thirdBond.getFlag(CDKConstants.ISAROMATIC)) {
                            if (!curAtomThird.equals(neighbour0)) {
                                rsAtom = varRingSet.getRings(thirdBond);
                                for (Object aRsAtom : rsAtom.atomContainers()) {
                                    ring = (IRing) aRsAtom;
                                    if (ring.getRingSize() > 4 && ring.contains(thirdBond)) {
                                        theBondIsInA6MemberedRing = true;
                                    }
                                }
                            }
                        }
                        checkAndStore(bondNumber, bondOrder, singles, doubles, bondsInCycloex, mol.indexOf(curAtomThird), atoms, sphere, theBondIsInA6MemberedRing);
                        theBondIsInA6MemberedRing = false;
                        atomsInFourthSphere = mol.getConnectedAtomsList(curAtomThird);
                        if (atomsInFourthSphere.size() > 0) {
                            for (Object anAtomsInFourthSphere : atomsInFourthSphere) {
                                IAtom curAtomFourth = (IAtom) anAtomsInFourthSphere;
                                fourthBond = mol.getBond(curAtomThird, curAtomFourth);
                                if (mol.indexOf(curAtomFourth) != atomPosition && getIfBondIsNotRotatable(mol, fourthBond, detected)) {
                                    sphere = 4;
                                    bondOrder = fourthBond.getOrder();
                                    bondNumber = mol.indexOf(fourthBond);
                                    theBondIsInA6MemberedRing = false;
                                    checkAndStore(bondNumber, bondOrder, singles, doubles, bondsInCycloex, mol.indexOf(curAtomFourth), atoms, sphere, theBondIsInA6MemberedRing);
                                    atomsInFifthSphere = mol.getConnectedAtomsList(curAtomFourth);
                                    if (atomsInFifthSphere.size() > 0) {
                                        for (Object anAtomsInFifthSphere : atomsInFifthSphere) {
                                            IAtom curAtomFifth = (IAtom) anAtomsInFifthSphere;
                                            fifthBond = mol.getBond(curAtomFifth, curAtomFourth);
                                            if (mol.indexOf(curAtomFifth) != atomPosition && getIfBondIsNotRotatable(mol, fifthBond, detected)) {
                                                sphere = 5;
                                                bondOrder = fifthBond.getOrder();
                                                bondNumber = mol.indexOf(fifthBond);
                                                theBondIsInA6MemberedRing = false;
                                                checkAndStore(bondNumber, bondOrder, singles, doubles, bondsInCycloex, mol.indexOf(curAtomFifth), atoms, sphere, theBondIsInA6MemberedRing);
                                                atomsInSixthSphere = mol.getConnectedAtomsList(curAtomFifth);
                                                if (atomsInSixthSphere.size() > 0) {
                                                    for (Object anAtomsInSixthSphere : atomsInSixthSphere) {
                                                        IAtom curAtomSixth = (IAtom) anAtomsInSixthSphere;
                                                        sixthBond = mol.getBond(curAtomFifth, curAtomSixth);
                                                        if (mol.indexOf(curAtomSixth) != atomPosition && getIfBondIsNotRotatable(mol, sixthBond, detected)) {
                                                            sphere = 6;
                                                            bondOrder = sixthBond.getOrder();
                                                            bondNumber = mol.indexOf(sixthBond);
                                                            theBondIsInA6MemberedRing = false;
                                                            checkAndStore(bondNumber, bondOrder, singles, doubles, bondsInCycloex, mol.indexOf(curAtomSixth), atoms, sphere, theBondIsInA6MemberedRing);
                                                            atomsInSeventhSphere = mol.getConnectedAtomsList(curAtomSixth);
                                                            if (atomsInSeventhSphere.size() > 0) {
                                                                for (Object anAtomsInSeventhSphere : atomsInSeventhSphere) {
                                                                    IAtom curAtomSeventh = (IAtom) anAtomsInSeventhSphere;
                                                                    seventhBond = mol.getBond(curAtomSeventh, curAtomSixth);
                                                                    if (mol.indexOf(curAtomSeventh) != atomPosition && getIfBondIsNotRotatable(mol, seventhBond, detected)) {
                                                                        sphere = 7;
                                                                        bondOrder = seventhBond.getOrder();
                                                                        bondNumber = mol.indexOf(seventhBond);
                                                                        theBondIsInA6MemberedRing = false;
                                                                        checkAndStore(bondNumber, bondOrder, singles, doubles, bondsInCycloex, mol.indexOf(curAtomSeventh), atoms, sphere, theBondIsInA6MemberedRing);
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    // Variables
    double distance;
    double sum;
    double smooth;
    double partial;
    int position;
    double limitInf = 1.4;
    double limitSup = 4;
    double step = (limitSup - limitInf) / 15;
    IAtom atom2;
    // /////////////////////THE SECOND CALCULATED DESCRIPTOR IS g(H)r TOPOLOGICAL WITH SUM OF BOND LENGTHS
    smooth = -20;
    IAtom startVertex = clonedAtom;
    IAtom endVertex;
    Integer thisAtom;
    limitInf = 1.4;
    limitSup = 4;
    if (atoms.size() > 0) {
        // ArrayList gHr_topol_function = new ArrayList(15);
        ShortestPaths shortestPaths = new ShortestPaths(mol, startVertex);
        for (int c = 0; c < ghr_topol_desc_length; c++) {
            double ghrt = limitInf + (limitSup - limitInf) * ((double) c / ghr_topol_desc_length);
            sum = 0;
            for (Integer integer : atoms) {
                distance = 0;
                thisAtom = integer;
                position = thisAtom;
                endVertex = mol.getAtom(position);
                atom2 = mol.getAtom(position);
                int[] path = shortestPaths.pathTo(endVertex);
                for (int i = 1; i < path.length; i++) {
                    distance += calculateDistanceBetweenTwoAtoms(mol.getAtom(path[i - 1]), mol.getAtom(path[i]));
                }
                partial = atom2.getCharge() * Math.exp(smooth * (Math.pow((ghrt - distance), 2)));
                sum += partial;
            }
            // gHr_topol_function.add(new Double(sum));
            rdfProtonCalculatedValues.add(sum);
            LOGGER.debug("RDF gr-topol distance prob.: " + sum + " at distance " + ghrt);
        }
    } else {
        return getDummyDescriptorValue(new CDKException("Some error occurred. Please report"));
    }
    return new DescriptorValue(getSpecification(), getParameterNames(), getParameters(), rdfProtonCalculatedValues, getDescriptorNames());
}
Also used : IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) CDKException(org.openscience.cdk.exception.CDKException) IBond(org.openscience.cdk.interfaces.IBond) ArrayList(java.util.ArrayList) AllRingsFinder(org.openscience.cdk.ringsearch.AllRingsFinder) CDKException(org.openscience.cdk.exception.CDKException) DescriptorValue(org.openscience.cdk.qsar.DescriptorValue) GasteigerMarsiliPartialCharges(org.openscience.cdk.charges.GasteigerMarsiliPartialCharges) IRing(org.openscience.cdk.interfaces.IRing) ShortestPaths(org.openscience.cdk.graph.ShortestPaths) IRingSet(org.openscience.cdk.interfaces.IRingSet) DoubleArrayResult(org.openscience.cdk.qsar.result.DoubleArrayResult) IAtom(org.openscience.cdk.interfaces.IAtom)

Example 5 with GasteigerMarsiliPartialCharges

use of org.openscience.cdk.charges.GasteigerMarsiliPartialCharges in project cdk by cdk.

the class RDFProtonDescriptor_G3R method calculate.

public DescriptorValue calculate(IAtom atom, IAtomContainer atomContainer, IRingSet precalculatedringset) {
    IAtomContainer varAtomContainer;
    try {
        varAtomContainer = atomContainer.clone();
    } catch (CloneNotSupportedException e) {
        return getDummyDescriptorValue(e);
    }
    int atomPosition = atomContainer.indexOf(atom);
    IAtom clonedAtom = varAtomContainer.getAtom(atomPosition);
    DoubleArrayResult rdfProtonCalculatedValues = new DoubleArrayResult(G3R_DESC_LENGTH);
    if (atom.getAtomicNumber() != IElement.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
    IAtomContainer mol = varAtomContainer.getBuilder().newInstance(IAtomContainer.class, 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);
            Aromaticity.cdkLegacy().apply(varAtomContainer);
        } catch (CDKException e) {
            return getDummyDescriptorValue(e);
        }
    }
    IRingSet rsAtom;
    IRing ring;
    IRingSet ringsWithThisBond;
    for (IBond bond : varAtomContainer.bonds()) {
        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
    // list of any bond not
    ArrayList<Integer> singles = new ArrayList<>();
    // rotatable
    // list with only double bonds
    ArrayList<Integer> doubles = new ArrayList<>();
    // list with all the atoms in
    ArrayList<Integer> atoms = new ArrayList<>();
    // spheres
    // atoms.add( Integer.valueOf( mol.indexOf(neighboors[0]) ) );
    // list for bonds in
    ArrayList<Integer> bondsInCycloex = new ArrayList<>();
    // cycloexane-like rings
    // 2', 3', 4', 5', 6', and 7' bonds up to the target are detected:
    // (remember that first bond is proton bond)
    IBond secondBond;
    // 
    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:
    // this is like a flag for bonds
    boolean theBondIsInA6MemberedRing;
    // 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.indexOf(curAtomSecond) != atomPosition && getIfBondIsNotRotatable(mol, secondBond, detected)) {
            sphere = 2;
            bondOrder = secondBond.getOrder();
            bondNumber = mol.indexOf(secondBond);
            theBondIsInA6MemberedRing = false;
            checkAndStore(bondNumber, bondOrder, singles, doubles, bondsInCycloex, mol.indexOf(curAtomSecond), atoms, sphere, theBondIsInA6MemberedRing);
            atomsInThirdSphere = mol.getConnectedAtomsList(curAtomSecond);
            if (atomsInThirdSphere.size() > 0) {
                for (IAtom curAtomThird : atomsInThirdSphere) {
                    thirdBond = mol.getBond(curAtomThird, curAtomSecond);
                    // LIST:
                    if (mol.indexOf(curAtomThird) != atomPosition && getIfBondIsNotRotatable(mol, thirdBond, detected)) {
                        sphere = 3;
                        bondOrder = thirdBond.getOrder();
                        bondNumber = mol.indexOf(thirdBond);
                        theBondIsInA6MemberedRing = false;
                        // true
                        if (!thirdBond.getFlag(CDKConstants.ISAROMATIC)) {
                            if (!curAtomThird.equals(neighbour0)) {
                                rsAtom = varRingSet.getRings(thirdBond);
                                for (IAtomContainer aRsAtom : rsAtom.atomContainers()) {
                                    ring = (IRing) aRsAtom;
                                    if (ring.getRingSize() > 4 && ring.contains(thirdBond)) {
                                        theBondIsInA6MemberedRing = true;
                                    }
                                }
                            }
                        }
                        checkAndStore(bondNumber, bondOrder, singles, doubles, bondsInCycloex, mol.indexOf(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.indexOf(curAtomFourth) != atomPosition && getIfBondIsNotRotatable(mol, fourthBond, detected)) {
                                    sphere = 4;
                                    bondOrder = fourthBond.getOrder();
                                    bondNumber = mol.indexOf(fourthBond);
                                    theBondIsInA6MemberedRing = false;
                                    checkAndStore(bondNumber, bondOrder, singles, doubles, bondsInCycloex, mol.indexOf(curAtomFourth), atoms, sphere, theBondIsInA6MemberedRing);
                                    atomsInFifthSphere = mol.getConnectedAtomsList(curAtomFourth);
                                    if (atomsInFifthSphere.size() > 0) {
                                        for (IAtom curAtomFifth : atomsInFifthSphere) {
                                            fifthBond = mol.getBond(curAtomFifth, curAtomFourth);
                                            if (mol.indexOf(curAtomFifth) != atomPosition && getIfBondIsNotRotatable(mol, fifthBond, detected)) {
                                                sphere = 5;
                                                bondOrder = fifthBond.getOrder();
                                                bondNumber = mol.indexOf(fifthBond);
                                                theBondIsInA6MemberedRing = false;
                                                checkAndStore(bondNumber, bondOrder, singles, doubles, bondsInCycloex, mol.indexOf(curAtomFifth), atoms, sphere, theBondIsInA6MemberedRing);
                                                atomsInSixthSphere = mol.getConnectedAtomsList(curAtomFifth);
                                                if (atomsInSixthSphere.size() > 0) {
                                                    for (IAtom curAtomSixth : atomsInSixthSphere) {
                                                        sixthBond = mol.getBond(curAtomFifth, curAtomSixth);
                                                        if (mol.indexOf(curAtomSixth) != atomPosition && getIfBondIsNotRotatable(mol, sixthBond, detected)) {
                                                            sphere = 6;
                                                            bondOrder = sixthBond.getOrder();
                                                            bondNumber = mol.indexOf(sixthBond);
                                                            theBondIsInA6MemberedRing = false;
                                                            checkAndStore(bondNumber, bondOrder, singles, doubles, bondsInCycloex, mol.indexOf(curAtomSixth), atoms, sphere, theBondIsInA6MemberedRing);
                                                            atomsInSeventhSphere = mol.getConnectedAtomsList(curAtomSixth);
                                                            if (atomsInSeventhSphere.size() > 0) {
                                                                for (IAtom curAtomSeventh : atomsInSeventhSphere) {
                                                                    seventhBond = mol.getBond(curAtomSeventh, curAtomSixth);
                                                                    if (mol.indexOf(curAtomSeventh) != atomPosition && getIfBondIsNotRotatable(mol, seventhBond, detected)) {
                                                                        sphere = 7;
                                                                        bondOrder = seventhBond.getOrder();
                                                                        bondNumber = mol.indexOf(seventhBond);
                                                                        theBondIsInA6MemberedRing = false;
                                                                        checkAndStore(bondNumber, bondOrder, singles, doubles, bondsInCycloex, mol.indexOf(curAtomSeventh), atoms, sphere, theBondIsInA6MemberedRing);
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    // Variables
    double sum;
    double smooth;
    double partial;
    int position;
    double limitInf;
    double limitSup;
    double step;
    // ////////////////////////LAST DESCRIPTOR IS g3(r), FOR PROTONS BONDED
    // TO LIKE-CYCLOEXANE RINGS:
    Vector3d aA = new Vector3d();
    Vector3d aB = new Vector3d();
    Vector3d bA = new Vector3d();
    Vector3d bB = new Vector3d();
    double angle;
    if (bondsInCycloex.size() > 0) {
        IAtom cycloexBondAtom0;
        IAtom cycloexBondAtom1;
        IBond theInCycloexBond;
        limitInf = 0;
        limitSup = Math.PI;
        position = 0;
        smooth = -2.86;
        angle = 0;
        int yaCounter;
        List<IAtom> connAtoms;
        for (int c = 0; c < G3R_DESC_LENGTH; c++) {
            double g3r = limitSup * ((double) c / G3R_DESC_LENGTH);
            sum = 0;
            for (Integer aBondsInCycloex : bondsInCycloex) {
                yaCounter = 0;
                angle = 0;
                partial = 0;
                position = aBondsInCycloex;
                theInCycloexBond = mol.getBond(position);
                cycloexBondAtom0 = theInCycloexBond.getBegin();
                cycloexBondAtom1 = theInCycloexBond.getEnd();
                connAtoms = mol.getConnectedAtomsList(cycloexBondAtom0);
                for (IAtom connAtom : connAtoms) {
                    if (connAtom.equals(neighbour0))
                        yaCounter += 1;
                }
                if (yaCounter > 0) {
                    aA.set(cycloexBondAtom1.getPoint3d().x, cycloexBondAtom1.getPoint3d().y, cycloexBondAtom1.getPoint3d().z);
                    aB.set(cycloexBondAtom0.getPoint3d().x, cycloexBondAtom0.getPoint3d().y, cycloexBondAtom0.getPoint3d().z);
                } else {
                    aA.set(cycloexBondAtom0.getPoint3d().x, cycloexBondAtom0.getPoint3d().y, cycloexBondAtom0.getPoint3d().z);
                    aB.set(cycloexBondAtom1.getPoint3d().x, cycloexBondAtom1.getPoint3d().y, cycloexBondAtom1.getPoint3d().z);
                }
                bA.set(neighbour0.getPoint3d().x, neighbour0.getPoint3d().y, neighbour0.getPoint3d().z);
                bB.set(atom.getPoint3d().x, atom.getPoint3d().y, atom.getPoint3d().z);
                angle = calculateAngleBetweenTwoLines(aA, aB, bA, bB);
                // LOGGER.debug("gcycr ANGLE: " + angle + " "
                // +mol.indexOf(cycloexBondAtom0) + "
                // "+mol.indexOf(cycloexBondAtom1));
                partial = Math.exp(smooth * (Math.pow((g3r - angle), 2)));
                sum += partial;
            }
            // g3r_function.add(new Double(sum));
            rdfProtonCalculatedValues.add(sum);
            LOGGER.debug("RDF g3r prob.: " + sum + " at distance " + g3r);
        }
    } else {
        return getDummyDescriptorValue(new CDKException("Some error occurred. Please report"));
    }
    return new DescriptorValue(getSpecification(), getParameterNames(), getParameters(), rdfProtonCalculatedValues, getDescriptorNames());
}
Also used : IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) CDKException(org.openscience.cdk.exception.CDKException) IBond(org.openscience.cdk.interfaces.IBond) ArrayList(java.util.ArrayList) AllRingsFinder(org.openscience.cdk.ringsearch.AllRingsFinder) CDKException(org.openscience.cdk.exception.CDKException) DescriptorValue(org.openscience.cdk.qsar.DescriptorValue) GasteigerMarsiliPartialCharges(org.openscience.cdk.charges.GasteigerMarsiliPartialCharges) IRing(org.openscience.cdk.interfaces.IRing) Vector3d(javax.vecmath.Vector3d) IRingSet(org.openscience.cdk.interfaces.IRingSet) DoubleArrayResult(org.openscience.cdk.qsar.result.DoubleArrayResult) IAtom(org.openscience.cdk.interfaces.IAtom)

Aggregations

GasteigerMarsiliPartialCharges (org.openscience.cdk.charges.GasteigerMarsiliPartialCharges)14 IAtomContainer (org.openscience.cdk.interfaces.IAtomContainer)12 CDKException (org.openscience.cdk.exception.CDKException)11 DescriptorValue (org.openscience.cdk.qsar.DescriptorValue)10 IAtom (org.openscience.cdk.interfaces.IAtom)9 DoubleArrayResult (org.openscience.cdk.qsar.result.DoubleArrayResult)8 IRingSet (org.openscience.cdk.interfaces.IRingSet)6 ArrayList (java.util.ArrayList)5 IBond (org.openscience.cdk.interfaces.IBond)5 IRing (org.openscience.cdk.interfaces.IRing)5 AllRingsFinder (org.openscience.cdk.ringsearch.AllRingsFinder)5 Vector3d (javax.vecmath.Vector3d)3 Polarizability (org.openscience.cdk.charges.Polarizability)3 Point3d (javax.vecmath.Point3d)2 Electronegativity (org.openscience.cdk.charges.Electronegativity)2 GasteigerPEPEPartialCharges (org.openscience.cdk.charges.GasteigerPEPEPartialCharges)2 PiElectronegativity (org.openscience.cdk.charges.PiElectronegativity)2 StabilizationCharges (org.openscience.cdk.charges.StabilizationCharges)2 DoubleResult (org.openscience.cdk.qsar.result.DoubleResult)2 EigenvalueDecomposition (Jama.EigenvalueDecomposition)1