use of org.openscience.cdk.graph.ShortestPaths 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());
}
use of org.openscience.cdk.graph.ShortestPaths in project cdk by cdk.
the class BondsToAtomDescriptor method calculate.
/**
* This method calculate the number of bonds on the shortest path between two atoms.
*
*@param atom The IAtom for which the DescriptorValue is requested
*@param container Parameter is the atom container.
*@return The number of bonds on the shortest path between two atoms
*/
@Override
public DescriptorValue calculate(IAtom atom, IAtomContainer container) {
IAtom focus = container.getAtom(focusPosition);
// could be cached
int bondsToAtom = new ShortestPaths(container, atom).distanceTo(focus);
return new DescriptorValue(getSpecification(), getParameterNames(), getParameters(), new IntegerResult(bondsToAtom), getDescriptorNames());
}
use of org.openscience.cdk.graph.ShortestPaths in project cdk by cdk.
the class StabilizationCharges method calculatePositive.
/**
* calculate the stabilization of orbitals when they contain deficiency of charge.
*
* @param atomContainer the molecule to be considered
* @param atom IAtom for which effective atom StabilizationCharges
* factor should be calculated
*
* @return stabilizationValue
*/
public double calculatePositive(IAtomContainer atomContainer, IAtom atom) {
// if(atomContainer.getConnectedSingleElectronsCount(atom) > 0 || atom.getFormalCharge() != 1){
if (atom.getFormalCharge() != 1) {
return 0.0;
}
// only must be generated all structures which stabilize the atom in question.
StructureResonanceGenerator gRI = new StructureResonanceGenerator();
List<IReactionProcess> reactionList = gRI.getReactions();
reactionList.add(new HyperconjugationReaction());
gRI.setReactions(reactionList);
IAtomContainerSet resonanceS = gRI.getStructures(atomContainer);
IAtomContainerSet containerS = gRI.getContainers(atomContainer);
if (// meaning it was not find any resonance structure
resonanceS.getAtomContainerCount() < 2)
return 0.0;
final int positionStart = atomContainer.indexOf(atom);
List<Double> result1 = new ArrayList<>();
List<Integer> distance1 = new ArrayList<>();
// the first is the initial structure
resonanceS.removeAtomContainer(0);
for (final IAtomContainer resonance : resonanceS.atomContainers()) {
if (// resonance with only one atom donnot have resonance
resonance.getAtomCount() < 2)
continue;
final ShortestPaths shortestPaths = new ShortestPaths(resonance, resonance.getAtom(positionStart));
/* search positive charge */
PiElectronegativity electronegativity = new PiElectronegativity();
for (IAtom atomP : resonance.atoms()) {
IAtom atomR = atomContainer.getAtom(resonance.indexOf(atomP));
if (containerS.getAtomContainer(0).contains(atomR)) {
electronegativity.setMaxIterations(6);
double result = electronegativity.calculatePiElectronegativity(resonance, atomP);
result1.add(result);
int dis = shortestPaths.distanceTo(atomP);
distance1.add(dis);
}
}
}
/* logarithm */
double value;
double sum = 0.0;
Iterator<Integer> itDist = distance1.iterator();
for (double suM : result1) {
if (suM < 0)
suM = -1 * suM;
sum += suM * Math.pow(0.67, itDist.next());
}
value = sum;
return value;
}
Aggregations