Skip to content

Commit 37d7d97

Browse files
committed
minor performance improvements
1 parent ae24352 commit 37d7d97

File tree

9 files changed

+326
-429
lines changed

9 files changed

+326
-429
lines changed

src/main/java/com/actelion/research/chem/IDCodeParserWithoutCoordinateInvention.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,13 @@
4040
/**
4141
* Typically you should use IDCodeParser instead of this class. You may instantiate this class
4242
* if you need to avoid a dependency to the CoordinateInventor and if you pass encoded coordinates
43-
* together with any idcode for parsing.
43+
* together with any idcode for parsing, or if you don't need 2D-coordinates, e.g. because you
44+
* intend to generate 3D-coordinates afterward.
4445
* We needed to introduce this class to avoid a cyclic dependency between the IDCodeParser and
45-
* the CoordinateInventor: If encoded atom coords are not given, then the IDcodeParser needs
46-
* to invent then in order to assign proper up-/down-bonds. The CoordinateInventor needs the
47-
* IDCodeParser to unpack its default template list.
46+
* the CoordinateInventor: If encoded atom coords are not given and if you later depict the
47+
* molecule in 2D, then IDCodeParser needs to invent 2D-coordinates in order to assign
48+
* proper up-/down-bonds from stereo parities. CoordinateInventor needs IDCodeParser in turn
49+
* to unpack its default template list.
4850
*/
4951
public class IDCodeParserWithoutCoordinateInvention {
5052
private StereoMolecule mMol;
@@ -69,7 +71,7 @@ public void neglectSpaceDelimitedCoordinates() {
6971
/**
7072
* Creates and returns a molecule from the idcode with its atom and bond arrays being
7173
* just as large as needed to hold the molecule. Use this to conserve memory if no
72-
* atoms or bonds are added to the molecule afterwards. This version of the method
74+
* atoms or bonds are added to the molecule afterward. This version of the method
7375
* allows to pass idcode and atom coordinates in one String object.
7476
* @param idcode null or idcode, which may contain coordinates separated by a space character
7577
* @return

src/main/java/com/actelion/research/chem/alignment3d/PheSAAlignmentOptimizer.java

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,42 @@ public class PheSAAlignmentOptimizer {
2525
public static final int PMI_OPTIMIZATIONS = 10;
2626
private static final double EXIT_VECTOR_WEIGHT = 10.0;
2727
private static final int BEST_RESULT_SIZE = 20;
28-
28+
29+
private final PheSASetting mSettings;
30+
private final MolecularVolume mRefVol;
31+
private final Coordinates mOrigCOM;
32+
private final Rotation mInverseRefRotation;
33+
2934
public enum SimilarityMode {REFTVERSKY,TVERSKY, TANIMOTO
3035
}
3136

32-
private PheSAAlignmentOptimizer() {}
33-
37+
public PheSAAlignmentOptimizer(StereoMolecule refMol, double ppWeight) {
38+
mSettings = new PheSASetting();
39+
mSettings.setPpWeight(ppWeight);
40+
mRefVol = new MolecularVolume(refMol);
41+
mOrigCOM = new Coordinates(mRefVol.getCOM());
42+
mInverseRefRotation = mRefVol.preProcess(new Conformer(refMol)).getInvert();
43+
}
44+
45+
public double alignMoleculeInPlace(StereoMolecule fitMol, ThreadMaster tm) {
46+
MolecularVolume fitVol = new MolecularVolume(fitMol);
47+
Conformer fitConf = new Conformer(fitMol);
48+
fitVol.preProcess(fitConf);
49+
50+
AlignmentResult bestSolution = createAlignmentSolutions(Collections.singletonList(mRefVol), Collections.singletonList(fitVol),mSettings, tm).get(0);
51+
52+
for(int a=0;a<fitMol.getAllAtoms();a++) {
53+
fitMol.setAtomX(a, fitConf.getX(a));
54+
fitMol.setAtomY(a, fitConf.getY(a));
55+
fitMol.setAtomZ(a, fitConf.getZ(a));
56+
}
57+
58+
bestSolution.getTransform().apply(fitMol);
59+
mInverseRefRotation.apply(fitMol);
60+
fitMol.translate(mOrigCOM.x, mOrigCOM.y, mOrigCOM.z);
61+
62+
return bestSolution.getSimilarity();
63+
}
3464

3565
public static double alignTwoMolsInPlace(StereoMolecule refMol, StereoMolecule fitMol, ThreadMaster tm) {
3666
return alignTwoMolsInPlace(refMol, fitMol, 0.5, tm);
@@ -39,7 +69,6 @@ public static double alignTwoMolsInPlace(StereoMolecule refMol, StereoMolecule f
3969
public static double alignTwoMolsInPlace(StereoMolecule refMol, StereoMolecule fitMol, double ppWeight, ThreadMaster tm) {
4070
PheSASetting setting = new PheSASetting();
4171
setting.setPpWeight(ppWeight);
42-
double similarity = 0.0;
4372
MolecularVolume refVol = new MolecularVolume(refMol);
4473
MolecularVolume fitVol = new MolecularVolume(fitMol);
4574
Coordinates origCOM = new Coordinates(refVol.getCOM());
@@ -49,7 +78,7 @@ public static double alignTwoMolsInPlace(StereoMolecule refMol, StereoMolecule f
4978
rotation = rotation.getInvert();
5079
fitVol.preProcess(fitConf);
5180
AlignmentResult bestSolution = createAlignmentSolutions(Collections.singletonList(refVol), Collections.singletonList(fitVol),setting, tm).get(0);
52-
similarity = bestSolution.getSimilarity();
81+
double similarity = bestSolution.getSimilarity();
5382

5483
for(int a=0;a<fitMol.getAllAtoms();a++) {
5584
fitMol.setAtomX(a, fitConf.getX(a));
@@ -61,9 +90,6 @@ public static double alignTwoMolsInPlace(StereoMolecule refMol, StereoMolecule f
6190
fitMol.translate(origCOM.x, origCOM.y, origCOM.z);
6291

6392
return similarity;
64-
65-
66-
6793
}
6894

6995
public static List<AlignmentResult> alignToNegRecImg(ShapeVolume ref,

src/main/java/com/actelion/research/chem/conf/BondRotationHelper.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,16 @@ public class BondRotationHelper {
5656
private int[] mRotationCenters;
5757
private int[] mRotationCentersBig;
5858
private String[] mTorsionIDs;
59-
private boolean includeTerminalPolarH;
60-
private int[] terminalPolarHBond;
59+
private final boolean mIncludeTerminalPolarH;
60+
private int[] mTerminalPolarHBond;
6161

6262
public BondRotationHelper(StereoMolecule mol) {
6363
this(mol,false);
6464
}
6565

6666
public BondRotationHelper(StereoMolecule mol, boolean includeTerminalPolarH) {
6767
mMol = mol;
68-
this.includeTerminalPolarH = includeTerminalPolarH;
68+
mIncludeTerminalPolarH = includeTerminalPolarH;
6969
initialize();
7070
}
7171

@@ -77,8 +77,8 @@ public void initialize() {
7777
disconnectedFragmentSize[disconnectedFragmentNo[atom]]++;
7878
mIsRotatableBond = new boolean[mMol.getBonds()];
7979
TorsionDB.findRotatableBonds(mMol,true, mIsRotatableBond);
80-
if(includeTerminalPolarH)
81-
terminalPolarHBond = findTerminalBondsPolarHs(mIsRotatableBond);
80+
if(mIncludeTerminalPolarH)
81+
mTerminalPolarHBond = findTerminalBondsPolarHs(mIsRotatableBond);
8282
List<Integer> rotBonds = new ArrayList<Integer>();
8383
IntStream.range(0, mIsRotatableBond.length).forEach(e -> {
8484
if(mIsRotatableBond[e])
@@ -96,8 +96,8 @@ public void initialize() {
9696
for(int i=0;i<mRotatableBonds.length;i++) {
9797
int bond = mRotatableBonds[i];
9898
boolean isSpecialBond = false;
99-
if(terminalPolarHBond!=null) {
100-
for(int b : terminalPolarHBond) {
99+
if(mTerminalPolarHBond!=null) {
100+
for(int b : mTerminalPolarHBond) {
101101
if(b==bond)
102102
isSpecialBond=true;
103103
}

src/main/java/com/actelion/research/chem/phesa/EvaluableOverlap.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ private double getFGValueOverlap(double[] grad,List<AtomicGaussian> refMolGauss,
275275
double dy = refAt.getCenter().y-fitCenterModCoord.y;
276276
double dz = refAt.getCenter().z-fitCenterModCoord.z;
277277
double Rij2 = dx*dx + dy*dy + dz*dz;
278-
if(Rij2>=Gaussian3D.DIST_CUTOFF)
278+
if(Rij2>=Gaussian3D.SQUARE_DIST_CUTOFF)
279279
continue;
280280
atomOverlap = refAt.getHeight()*fitAt.getHeight()*QuickMathCalculator.getInstance().quickExp(-( refAt.getWidth() * fitAt.getWidth()* Rij2)/alphaSum) *
281281
QuickMathCalculator.getInstance().getPrefactor(refAt.getAtomicNo(),fitAt.getAtomicNo());
@@ -310,7 +310,7 @@ private double getFGValueOverlap(double[] grad,List<AtomicGaussian> refMolGauss,
310310
double dz = refVol.getCenter().z-fitCenterModCoord.z;
311311
double Rij2 = dx*dx + dy*dy + dz*dz;
312312

313-
if(Rij2>=Gaussian3D.DIST_CUTOFF)
313+
if(Rij2>=Gaussian3D.SQUARE_DIST_CUTOFF)
314314
continue;
315315
atomOverlap = refVol.getRole()*refVol.getHeight()*fitAt.getHeight()*QuickMathCalculator.getInstance().quickExp(-( refVol.getWidth() * fitAt.getWidth()* Rij2)/alphaSum) *
316316
QuickMathCalculator.getInstance().getPrefactor(refVol.getAtomicNo(),fitAt.getAtomicNo());
@@ -369,7 +369,7 @@ private double getFGValueOverlapPP(double[] grad, List<PPGaussian> refMolGauss,L
369369
double dz = refAt.getCenter().z-fitCenterModCoord.z;
370370
double Rij2 = dx*dx + dy*dy + dz*dz;
371371

372-
if(Rij2>=Gaussian3D.DIST_CUTOFF) {
372+
if(Rij2>=Gaussian3D.SQUARE_DIST_CUTOFF) {
373373
continue;
374374
}
375375

src/main/java/com/actelion/research/chem/phesa/Gaussian3D.java

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,20 @@
11
package com.actelion.research.chem.phesa;
22

3-
import com.actelion.research.util.EncoderFloatingPointNumbers;
4-
5-
import java.io.IOException;
6-
import java.nio.ByteBuffer;
7-
import java.util.Arrays;
8-
3+
import com.actelion.research.chem.Coordinates;
94
import com.actelion.research.chem.PeriodicTable;
10-
import com.actelion.research.chem.StereoMolecule;
115
import com.actelion.research.chem.alignment3d.transformation.Transformation;
12-
import com.actelion.research.chem.conf.Conformer;
13-
import com.actelion.research.chem.Coordinates;
146

157
/**
168
* @version: 1.0, February 2018
179
* Author: J. Wahl
1810
* basic class to describe Gaussian functions used for the calculation of Molecular Volumes
1911
* Gaussian functions have a center (3D coordinates), a width and a height
2012
* this class provides functionalities for calculating higher order overlaps of Gaussians
21-
2213
*/
2314

2415
public abstract class Gaussian3D {
25-
public static final double DIST_CUTOFF = 10.0;
16+
public static final double DISTANCE_CUTOFF = 3.2;
17+
public static final double SQUARE_DIST_CUTOFF = DISTANCE_CUTOFF * DISTANCE_CUTOFF;
2618
protected int atomId;
2719
protected int atomicNo;
2820
protected Coordinates center;
@@ -53,9 +45,7 @@ public Gaussian3D(Gaussian3D original){
5345
}
5446

5547
public Gaussian3D() {}
56-
5748

58-
5949
public abstract double calculateHeight();
6050

6151
public abstract double calculateWidth();
@@ -77,13 +67,11 @@ public void setHeight(double height) {
7767
public double getWidth() {
7868
return this.alpha;
7969
}
80-
8170

8271
public double getVolume() {
8372
return this.volume;
8473
}
8574

86-
8775
public Coordinates getCenter() {
8876
return this.center;
8977
}
@@ -118,15 +106,11 @@ public double getWeight() {
118106
public void setWeight(double weight) {
119107
this.weight = weight;
120108
}
121-
122-
109+
123110
public void transform(Transformation transform) {
124111
transform.apply(center);
125112
}
126113

127-
128-
129-
130114
public final double getVolumeOverlap(Gaussian3D g2,Coordinates c2, double distCutoff) {
131115
double alphaSum = getWidth() + g2.getWidth();
132116
double Vij = 0.0;
@@ -141,13 +125,12 @@ public final double getVolumeOverlap(Gaussian3D g2,Coordinates c2, double distCu
141125
Kij = getHeight()*g2.getHeight()*QuickMathCalculator.getInstance().quickExp(c);
142126
double factor = QuickMathCalculator.getInstance().getPrefactor(getAtomicNo(),g2.getAtomicNo());
143127
Vij = weight*factor*Kij;
144-
145128
}
146129
return Vij;
147130
}
148131

149132
public final double getVolumeOverlap(Gaussian3D g2) {
150-
return getVolumeOverlap(g2,DIST_CUTOFF);
133+
return getVolumeOverlap(g2, SQUARE_DIST_CUTOFF);
151134
}
152135

153136
public final double getVolumeOverlap(Gaussian3D g2, double distCutoff) {
@@ -157,15 +140,11 @@ public final double getVolumeOverlap(Gaussian3D g2, double distCutoff) {
157140
public void updateCoordinates(Coordinates[] coords) {
158141
center = new Coordinates(coords[atomId]);
159142
}
160-
161-
143+
162144
public void updateAtomIndeces(int[] map) {
163145
atomId = map[atomId];
164146
}
165147

166148
abstract public String encode();
167-
168-
169-
170149
}
171150

0 commit comments

Comments
 (0)