Skip to content

Commit

Permalink
Replace BFSShortestPath usage.
Browse files Browse the repository at this point in the history
Signed-off-by: Egon Willighagen <egonw@users.sourceforge.net>
  • Loading branch information
johnmay authored and egonw committed Aug 5, 2014
1 parent 81e8021 commit b741861
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,10 @@
*/
package org.openscience.cdk.qsar.descriptors.atomic;

import org._3pq.jgrapht.Edge;
import org.openscience.cdk.annotations.TestClass;
import org.openscience.cdk.annotations.TestMethod;
import org.openscience.cdk.exception.CDKException;
import static org.openscience.cdk.graph.BFSShortestPath.findPathBetween;
import org.openscience.cdk.graph.MoleculeGraphs;
import org.openscience.cdk.graph.ShortestPaths;
import org.openscience.cdk.interfaces.IAtom;
import org.openscience.cdk.interfaces.IAtomContainer;
import org.openscience.cdk.qsar.AbstractAtomicDescriptor;
Expand Down Expand Up @@ -65,9 +63,6 @@
public class BondsToAtomDescriptor extends AbstractAtomicDescriptor implements IAtomicDescriptor {

private int focusPosition = 0;
java.util.List<Edge> mylist = null;
Object startVertex = null;
Object endVertex = null;

/**
* Constructor for the BondsToAtomDescriptor object
Expand Down Expand Up @@ -135,17 +130,11 @@ public String[] getDescriptorNames() {

@TestMethod(value="testCalculate_IAtomContainer")
public DescriptorValue calculate(IAtom atom, IAtomContainer container) {
org._3pq.jgrapht.Graph mygraph = MoleculeGraphs.getMoleculeGraph(container);
int bondsToAtom;


IAtom focus = container.getAtom(focusPosition);

startVertex = atom;
endVertex = focus;

mylist = findPathBetween(mygraph, startVertex, endVertex);

bondsToAtom = mylist.size();
// could be cached
int bondsToAtom = new ShortestPaths(container, atom).distanceTo(focus);

return new DescriptorValue(getSpecification(), getParameterNames(), getParameters(),
new IntegerResult(bondsToAtom),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,13 @@
import javax.vecmath.Point3d;
import javax.vecmath.Vector3d;

import org._3pq.jgrapht.Edge;
import org.openscience.cdk.CDKConstants;
import org.openscience.cdk.annotations.TestClass;
import org.openscience.cdk.annotations.TestMethod;
import org.openscience.cdk.aromaticity.Aromaticity;
import org.openscience.cdk.charges.GasteigerMarsiliPartialCharges;
import org.openscience.cdk.exception.CDKException;
import org.openscience.cdk.graph.MoleculeGraphs;
import org.openscience.cdk.graph.ShortestPaths;
import org.openscience.cdk.graph.invariant.ConjugatedPiSystemsDetector;
import org.openscience.cdk.interfaces.IAtom;
import org.openscience.cdk.interfaces.IAtomContainer;
Expand Down Expand Up @@ -387,42 +386,29 @@ public DescriptorValue calculate(IAtom atom, IAtomContainer atomContainer, IRing

///////////////////////THE SECOND CALCULATED DESCRIPTOR IS g(H)r TOPOLOGICAL WITH SUM OF BOND LENGTHS

distance = 0;
sum = 0;
smooth = -20;
position = 0;
atom2 = null;
org._3pq.jgrapht.Graph mygraph = MoleculeGraphs.getMoleculeGraph(mol);
smooth = -20;
IAtom startVertex = clonedAtom;
IAtom endVertex;
org._3pq.jgrapht.Edge edg;
List<Edge> mylist;
IAtom atomTarget;
IAtom atomSource;
Integer thisAtom;
partial = 0;
limitInf = 1.4;
limitSup = 4;
step = (limitSup - limitInf)/15;

if(atoms.size() > 0) {
//ArrayList gHr_topol_function = new ArrayList(15);
int counter = 0;
ShortestPaths shortestPaths = new ShortestPaths(mol, startVertex);
for(double ghrt = limitInf; ghrt < limitSup; ghrt = ghrt + step) {
sum = 0;
for( int at = 0; at < atoms.size(); at++ ) {
partial = 0;
distance = 0;
thisAtom = atoms.get(at);
position = thisAtom;
endVertex = mol.getAtom(position);
atom2 = mol.getAtom(position);
mylist = org.openscience.cdk.graph.BFSShortestPath.findPathBetween(mygraph,startVertex,endVertex);
for (int u = 0; u < mylist.size(); u++) {
edg = mylist.get(u);
atomTarget = (IAtom)edg.getTarget();
atomSource = (IAtom)edg.getSource();
distance += calculateDistanceBetweenTwoAtoms(atomTarget, atomSource);
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,13 @@
*/
package org.openscience.cdk.qsar.descriptors.molecular;

import org._3pq.jgrapht.graph.SimpleGraph;
import org.openscience.cdk.CDKConstants;
import org.openscience.cdk.annotations.TestClass;
import org.openscience.cdk.annotations.TestMethod;
import org.openscience.cdk.aromaticity.Aromaticity;
import org.openscience.cdk.exception.CDKException;
import org.openscience.cdk.graph.BFSShortestPath;
import org.openscience.cdk.graph.AllPairsShortestPaths;
import org.openscience.cdk.graph.Cycles;
import org.openscience.cdk.graph.MoleculeGraphs;
import org.openscience.cdk.interfaces.*;
import org.openscience.cdk.interfaces.IAtomType.Hybridization;
import org.openscience.cdk.isomorphism.UniversalIsomorphismTester;
Expand Down Expand Up @@ -825,18 +823,16 @@ else if (getAtomTypeXCount(ac, atomi) == 2) {
}
}
//logger.debug("XLOGP: Before Correction:"+xlogP);
List path=null;
SimpleGraph moleculeGraph=null;
int [][] pairCheck=null;
// //logger.debug("Acceptors:"+hBondAcceptors.size()+" Donors:"+hBondDonors.size());
if (hBondAcceptors.size()>0 && hBondDonors.size()>0){
moleculeGraph=MoleculeGraphs.getMoleculeGraph(ac);
pairCheck=initializeHydrogenPairCheck(new int[atomCount][atomCount]);
}
AllPairsShortestPaths apsp = new AllPairsShortestPaths(ac);
for (int i=0; i<hBondAcceptors.size();i++){
for (int j=0; j<hBondDonors.size();j++){
if (checkRingLink(rs,ac,ac.getAtom(hBondAcceptors.get(i))) || checkRingLink(rs,ac,ac.getAtom(hBondDonors.get(j).intValue()))){
path=BFSShortestPath.findPathBetween(moleculeGraph,ac.getAtom(hBondAcceptors.get(i)), ac.getAtom((Integer) hBondDonors.get(j)));
int dist = apsp.from(ac.getAtom(hBondAcceptors.get(i))).distanceTo(ac.getAtom(hBondDonors.get(j)));
// //logger.debug(" Acc:"+checkRingLink(rs,ac,atoms[((Integer)hBondAcceptors.get(i)).intValue()])
// +" S:"+atoms[((Integer)hBondAcceptors.get(i)).intValue()].getSymbol()
// +" Nr:"+((Integer)hBondAcceptors.get(i)).intValue()
Expand All @@ -845,14 +841,14 @@ else if (getAtomTypeXCount(ac, atomi) == 2) {
// +" Nr:"+((Integer)hBondDonors.get(j)).intValue()
// +" i:"+i+" j:"+j+" path:"+path.size());
if (checkRingLink(rs,ac,ac.getAtom(hBondAcceptors.get(i))) && checkRingLink(rs,ac,ac.getAtom(hBondDonors.get(j).intValue()))){
if (path.size()==3 && pairCheck[hBondAcceptors.get(i)][hBondDonors.get(j)]==0){
if (dist==3 && pairCheck[hBondAcceptors.get(i)][hBondDonors.get(j)]==0){
xlogP += 0.429;
pairCheck[hBondAcceptors.get(i)][hBondDonors.get(j)]=1;
pairCheck[hBondDonors.get(j)][hBondAcceptors.get(i)]=1;
//logger.debug("XLOGP: Internal HBonds 1-4 0.429");
}
}else{
if (path.size()==4 && pairCheck[hBondAcceptors.get(i)][hBondDonors.get(j)]==0){
if (dist==4 && pairCheck[hBondAcceptors.get(i)][hBondDonors.get(j)]==0){
xlogP += 0.429;
pairCheck[hBondAcceptors.get(i)][hBondDonors.get(j)]=1;
pairCheck[hBondDonors.get(j)][hBondAcceptors.get(i)]=1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,9 @@
import java.util.Iterator;
import java.util.List;

import org._3pq.jgrapht.Edge;
import org._3pq.jgrapht.graph.SimpleGraph;
import org.openscience.cdk.annotations.TestClass;
import org.openscience.cdk.annotations.TestMethod;
import org.openscience.cdk.graph.BFSShortestPath;
import org.openscience.cdk.graph.MoleculeGraphs;
import org.openscience.cdk.graph.ShortestPaths;
import org.openscience.cdk.interfaces.IAtom;
import org.openscience.cdk.interfaces.IAtomContainer;
import org.openscience.cdk.interfaces.IAtomContainerSet;
Expand Down Expand Up @@ -108,7 +105,7 @@ public double calculatePositive(IAtomContainer atomContainer, IAtom atom){
double result = electronegativity.calculatePiElectronegativity(resonance, atomP);
result1.add(result);

int dis = calculateBondsToAtom(resonance.getAtom(positionStart),atomP, resonance);
int dis = calculateBondsToAtom(resonance.getAtom(positionStart), atomP, resonance);
distance1.add(dis);
}

Expand Down Expand Up @@ -137,11 +134,7 @@ public double calculatePositive(IAtomContainer atomContainer, IAtom atom){
* @return The distance
*/
private int calculateBondsToAtom(IAtom startAtom, IAtom focusAtom, IAtomContainer container) {
SimpleGraph mygraph = MoleculeGraphs.getMoleculeGraph(container);

List<Edge> mylist = BFSShortestPath.findPathBetween(mygraph,startAtom,focusAtom);

return mylist.size();
return new ShortestPaths(container, startAtom).distanceTo(focusAtom);
}

}
Expand Down

0 comments on commit b741861

Please sign in to comment.