Skip to content

Commit

Permalink
Calculate the weight as we go traverse the path.
Browse files Browse the repository at this point in the history
  • Loading branch information
johnmay authored and egonw committed Feb 6, 2022
1 parent aeef769 commit b3b0696
Showing 1 changed file with 6 additions and 16 deletions.
Expand Up @@ -177,15 +177,7 @@ public Consumer(IAtomContainer mol) {
}
}

private double weight(List<IBond> bonds) {
double val = 1.0;
for (IBond bond : bonds)
val /= bondWeights[bond.getIndex()];
return val;
}

void consume(List<IAtom> apath, List<IBond> bpath) {
double val = weight(bpath);
void consume(List<IAtom> apath, double val) {
if (unique(apath))
uniqWeight += val;
int elem = apath.get(0).getAtomicNumber();
Expand All @@ -202,26 +194,24 @@ else if (elem == IAtom.N)
private void traverseAllPaths(boolean[] visit,
Consumer consumer,
List<IAtom> apath,
List<IBond> bpath,
double weight,
IAtom atom,
IBond prev) {
visit[atom.getIndex()] = true;
apath.add(atom);
if (prev != null) {
bpath.add(prev);
consumer.consume(apath, bpath);
weight /= consumer.bondWeights[prev.getIndex()];
consumer.consume(apath, weight);
}
for (IBond bond : atom.bonds()) {
if (bond == prev)
continue;
IAtom nbor = bond.getOther(atom);
if (!visit[nbor.getIndex()])
traverseAllPaths(visit, consumer, apath, bpath, nbor, bond);
traverseAllPaths(visit, consumer, apath, weight, nbor, bond);
}
visit[atom.getIndex()] = false;
apath.remove(apath.size()-1);
if (prev != null)
bpath.remove(bpath.size()-1);
}

/**
Expand All @@ -239,7 +229,7 @@ public DescriptorValue calculate(IAtomContainer container) {
Consumer consumer = new Consumer(local);
boolean[] visit = new boolean[local.getAtomCount()];
for (IAtom a : local.atoms()) {
traverseAllPaths(visit, consumer, new ArrayList<>(), new ArrayList<>(), a, null);
traverseAllPaths(visit, consumer, new ArrayList<>(), 1.0, a, null);
}

retval.add(consumer.uniqWeight);
Expand Down

0 comments on commit b3b0696

Please sign in to comment.