Skip to content

Commit

Permalink
made the creation of morgan numbers N times faster, where N is the nu…
Browse files Browse the repository at this point in the history
…mber of atoms in the AtomContainer

Change-Id: Ia7fd027490939f112ec268f0128a935d2c031f04
Signed-off-by: Egon Willighagen <egonw@users.sourceforge.net>
  • Loading branch information
thorsten-fluegel authored and egonw committed Aug 20, 2011
1 parent 5d268f5 commit 1c5ba83
Showing 1 changed file with 32 additions and 21 deletions.
Expand Up @@ -20,6 +20,10 @@
*/
package org.openscience.cdk.graph.invariant;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.openscience.cdk.annotations.TestClass;
import org.openscience.cdk.annotations.TestMethod;
import org.openscience.cdk.interfaces.IAtom;
Expand All @@ -46,27 +50,34 @@ public class MorganNumbersTools {
*/
@TestMethod("testGetMorganNumbers_IAtomContainer")
public static long[] getMorganNumbers(IAtomContainer atomContainer) {
long[] morganMatrix;
long[] tempMorganMatrix;
int N = atomContainer.getAtomCount();
morganMatrix = new long[N];
tempMorganMatrix = new long[N];
java.util.List<IAtom> atoms;
for (int f = 0; f < N; f++) {
morganMatrix[f] = atomContainer.getConnectedBondsCount(f);
tempMorganMatrix[f] = atomContainer.getConnectedBondsCount(f);
}
for (int e = 0; e < N; e++) {
for (int f = 0; f < N; f++) {
morganMatrix[f] = 0;
atoms = atomContainer.getConnectedAtomsList(atomContainer.getAtom(f));
for (IAtom atom : atoms) {
morganMatrix[f] += tempMorganMatrix[atomContainer.getAtomNumber(atom)];
}
}
System.arraycopy(morganMatrix, 0, tempMorganMatrix, 0, N);
}
return tempMorganMatrix;
long[] morganMatrix;
long[] tempMorganMatrix;
int N = atomContainer.getAtomCount();
morganMatrix = new long[N];
tempMorganMatrix = new long[N];
@SuppressWarnings("unchecked")
java.util.List<IAtom>[] atoms = new List[N];
@SuppressWarnings("unchecked")
Map<IAtom, Integer>[] atomIndices = new HashMap[N];
for (int f = 0; f < N; f++) {
morganMatrix[f] = atomContainer.getConnectedBondsCount(f);
tempMorganMatrix[f] = atomContainer.getConnectedBondsCount(f);
atoms[f] = atomContainer.getConnectedAtomsList(atomContainer.getAtom(f));
atomIndices[f] = new HashMap<IAtom, Integer>();
for (IAtom atom : atoms[f]) {
atomIndices[f].put(atom, atomContainer.getAtomNumber(atom));
}
}
for (int e = 0; e < N; e++) {
for (int f = 0; f < N; f++) {
morganMatrix[f] = 0;
for (IAtom atom : atoms[f]) {
morganMatrix[f] += tempMorganMatrix[atomIndices[f].get(atom)];
}
}
System.arraycopy(morganMatrix, 0, tempMorganMatrix, 0, N);
}
return tempMorganMatrix;
}


Expand Down

0 comments on commit 1c5ba83

Please sign in to comment.