Skip to content

Commit

Permalink
fixed error handling issue
Browse files Browse the repository at this point in the history
  • Loading branch information
thsa committed Oct 11, 2024
1 parent e545288 commit 9d70a31
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,12 @@

package com.actelion.research.chem.forcefield.mmff;

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

import com.actelion.research.chem.StereoMolecule;
import com.actelion.research.chem.forcefield.AbstractForceField;

/**
import java.util.*;

/*
* The MMFF ForceField class is the top level class used to perform
* energy calculations/minimisation on a molecule. It accepts an
* ExtendedMolecule and the string name of the parameter tables to use.
Expand All @@ -68,17 +64,17 @@
* (default: 1.0)
* - "dielectric model": A string for the dielectric model. "distance"
* selects a distance-dependent dielectric model, everything else
* selects the constant dielectric model (default: "constant")
* selects the constant dielectric model (default: "constant")
* - "angle bend": A boolean, default True, for whether to include angle
* bending energy terms.
* - "bond stretch": A boolean, default True, for whether to include bond
* stretching energy terms.
* - "electrostatic": A boolean, default True, for whether to include the
* nonbonded electrostatic energy terms.
* - "out of plane": A boolean, default True, for whether to include out
of plane energy terms.
* of plane energy terms.
* - "stretch bend": A boolean, default True, for whether to include
stretch bending energy terms.
* stretch bending energy terms.
* - "torsion angle": A boolean, default True, for whether to include
* torsional angle energy terms.
* - "van der waals": A boolean, default True, for whether to include the
Expand All @@ -88,20 +84,15 @@
* @author joel
*
*/
/**
* @author joel
*
*/
public final class ForceFieldMMFF94 extends AbstractForceField {
public static final String MMFF94 = "MMFF94";
public static final String MMFF94S = "MMFF94s";
public static final String MMFF94SPLUS = "MMFF94s+";


//protected final ExtendedMolecule mol;
private final MMFFMolecule mMMFFMol;
public static Map<String, Tables> mTables = new HashMap<String, Tables>();
private List<EnergyTerm> mEnergies = new ArrayList<EnergyTerm>();
public static Map<String, Tables> mTables = new HashMap<>();
private final List<EnergyTerm> mEnergies = new ArrayList<>();


/**
Expand All @@ -114,25 +105,21 @@ public final class ForceFieldMMFF94 extends AbstractForceField {
* See class description of a list of options.
*/

public ForceFieldMMFF94(StereoMolecule m, String tablename,
Map<String, Object> options) {
public ForceFieldMMFF94(StereoMolecule m, String tablename, Map<String, Object> options)
throws BadAtomTypeException,BadRingAromException {
super(m);
mMMFFMol = new com.actelion.research.chem.forcefield.mmff.MMFFMolecule(m);
mMol.ensureHelperArrays(StereoMolecule.cHelperRings);
Tables table = mTables.get(tablename);

double nonBondedThresh = options.containsKey("nonbonded cutoff")
? ((Double)options.get("nonbonded cutoff")).doubleValue()
? (Double)options.get("nonbonded cutoff")
: 100.0;

double dielConst = options.containsKey("dielectric constant")
? ((Double)options.get("dielectric constant")).doubleValue() : 1.0;

boolean dielModel = options.containsKey("dielectric model")
? ((String)options.get("dielectric model")).equals("distance")
: false;

? (Double)options.get("dielectric constant") : 1.0;

boolean dielModel = options.containsKey("dielectric model") && (options.get("dielectric model")).equals("distance");

Separation sep = new Separation(mMMFFMol);

Expand Down Expand Up @@ -174,8 +161,8 @@ public ForceFieldMMFF94(StereoMolecule m, String tablename,
* must be a table with this name that has been loaded with
* "loadTable()".
*/
public ForceFieldMMFF94(StereoMolecule mol, String tablename) {
this(mol, tablename, new HashMap<String, Object>());
public ForceFieldMMFF94(StereoMolecule mol, String tablename) throws BadAtomTypeException,BadRingAromException {
this(mol, tablename, new HashMap<>());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,25 +36,24 @@
import com.actelion.research.chem.StereoMolecule;
import com.actelion.research.chem.RingCollection;

import java.util.Arrays;

/**
* MMFF molecule is a wrapper class for the ExtendedMolecule. It holds some
* additional data such as a cache of the atom types, whether the molecule is
* valid for MMFF and the ring mmff aromaticity property.
*/
public final class MMFFMolecule extends StereoMolecule {
private RingBoolean[] mRingArom;
private int[] mAtomTypes;
private int[] mHydrogenMap;
private final RingBoolean[] mRingArom;
private final int[] mAtomTypes;
private final int[] mHydrogenMap;

public MMFFMolecule(StereoMolecule mol) throws BadAtomTypeException,
BadRingAromException
{
public MMFFMolecule(StereoMolecule mol) throws BadAtomTypeException,BadRingAromException {
super(mol);
mHydrogenMap = getHandleHydrogenMap();
RingCollection rings = getRingSet();
mRingArom = new RingBoolean[rings.getSize()];
for (int i=0; i<mRingArom.length; i++)
mRingArom[i] = RingBoolean.NOT_SET;
Arrays.fill(mRingArom, RingBoolean.NOT_SET);

boolean allset = false, changed = true;
while (!allset && changed) {
Expand Down Expand Up @@ -109,7 +108,7 @@ public int[] getHydrogenMap() {
* @return True if the ring is aromatic, false otherwise.
*/
public boolean ringIsMMFFAromatic(int r) {
return mRingArom[r] == RingBoolean.TRUE ? true : false;
return mRingArom[r] == RingBoolean.TRUE;
}

/**
Expand All @@ -118,7 +117,7 @@ public boolean ringIsMMFFAromatic(int r) {
* @return True if the ring has had its flag set, false otherwise.
*/
public boolean isSetRingMMFFAromaticity(int r) {
return mRingArom[r] == RingBoolean.NOT_SET ? false : true;
return mRingArom[r] != RingBoolean.NOT_SET;
}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
package com.actelion.research.chem.phesaflex;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;

import com.actelion.research.chem.StereoMolecule;
import com.actelion.research.chem.alignment3d.PheSAAlignmentOptimizer.PheSASetting;
import com.actelion.research.chem.alignment3d.PheSAAlignmentOptimizer.SimilarityMode;
Expand All @@ -18,6 +13,11 @@
import com.actelion.research.chem.phesa.MolecularVolume;
import com.actelion.research.chem.phesa.PheSAAlignment;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;


/**
* Performs flexible Alignment of two Molecules that are prealigned. A fit molecule is thereby
Expand All @@ -44,11 +44,11 @@
public class FlexibleShapeAlignment {
private static final int MC_STEPS = 50;
public static final double ENERGY_CUTOFF = 10.0;
private StereoMolecule refMol;
private StereoMolecule fitMol;
private MolecularVolume refVol;
private MolecularVolume fitVol;
private Map<String, Object> ffOptions;
private final StereoMolecule refMol;
private final StereoMolecule fitMol;
private final MolecularVolume refVol;
private final MolecularVolume fitVol;
private final Map<String, Object> ffOptions;
private PheSASetting settings;

public PheSASetting getSettings() {
Expand All @@ -69,7 +69,7 @@ public FlexibleShapeAlignment(StereoMolecule refMol,StereoMolecule fitMol, Molec
this.fitMol = fitMol;
this.refVol = refVol;
this.fitVol = fitVol;
ffOptions = new HashMap<String, Object>();
ffOptions = new HashMap<>();
ffOptions.put("dielectric constant", 4.0);
settings = new PheSASetting();
}
Expand All @@ -80,7 +80,7 @@ public double[] align() {

double e0 = calcMin(fitMol);
if(Double.isNaN(e0)) {
System.err.print("no force field parameters for this structure");
System.err.println("no force field parameters for this structure");
return result;
}

Expand All @@ -89,7 +89,7 @@ public double[] align() {
boolean[] isHydrogen = new boolean[fitMol.getAllAtoms()];
for(int at=0;at<fitMol.getAllAtoms();at++) {

isHydrogen[at] = fitMol.getAtomicNo(at)==1 ? true : false;
isHydrogen[at] = fitMol.getAtomicNo(at) == 1;
}
Conformer fitConf = new Conformer(fitMol);
BondRotationHelper torsionHelper = new BondRotationHelper(fitConf.getMolecule(),true);
Expand Down Expand Up @@ -138,9 +138,7 @@ public double[] align() {
}

private double getSimilarity(EvaluableFlexibleOverlap eval, PheSAAlignment shapeAlign) {
boolean tversky = true;
if(settings.getSimMode()==SimilarityMode.TANIMOTO)
tversky=false;
boolean tversky = settings.getSimMode() != SimilarityMode.TANIMOTO;
double ppWeight = settings.getPpWeight();
double tverskyCoeff = settings.getSimMode()==SimilarityMode.TVERSKY ? PheSAAlignment.TVERSKY_COEFFICIENT : 1.0-PheSAAlignment.TVERSKY_COEFFICIENT;
double Obb = eval.getFGValueShapeSelf(new double[3*fitMol.getAllAtoms()], shapeAlign.getMolGauss(),false);
Expand All @@ -158,7 +156,7 @@ private double getSimilarity(EvaluableFlexibleOverlap eval, PheSAAlignment shape
double OaaPP = eval.getFGValueSelfPP(shapeAlign.getRefMolGauss(),true);
double OabPP = eval.getFGValuePP();
double Tpp = 0.0;
if(shapeAlign.getRefMolGauss().getPPGaussians().size()==0 && shapeAlign.getMolGauss().getPPGaussians().size()==0 )
if(shapeAlign.getRefMolGauss().getPPGaussians().isEmpty() && shapeAlign.getMolGauss().getPPGaussians().isEmpty())
Tpp = 1.0;
else {
if(tversky)
Expand All @@ -171,9 +169,8 @@ private double getSimilarity(EvaluableFlexibleOverlap eval, PheSAAlignment shape
Tshape = 1.0f;
if(!tversky && Tpp>1.0) //can happen because of weights
Tpp = 1.0f;
double T = (1.0f-(float)ppWeight)*Tshape + (float)ppWeight*Tpp;

return T;
return (1.0f-(float)ppWeight)*Tshape + (float)ppWeight*Tpp;
}


Expand All @@ -186,18 +183,17 @@ private double[] getResult() {
}

public double calcMin(StereoMolecule fitMol) {

ForceFieldMMFF94.initialize(ForceFieldMMFF94.MMFF94SPLUS);
ForceFieldMMFF94 forceField = new ForceFieldMMFF94(new StereoMolecule(fitMol), ForceFieldMMFF94.MMFF94SPLUS, ffOptions);
forceField.minimise();
double e0 = forceField.getTotalEnergy();
return e0;


try {
ForceFieldMMFF94.initialize(ForceFieldMMFF94.MMFF94SPLUS);
ForceFieldMMFF94 forceField = new ForceFieldMMFF94(new StereoMolecule(fitMol), ForceFieldMMFF94.MMFF94SPLUS, ffOptions);
forceField.minimise();
return forceField.getTotalEnergy();
} catch (RuntimeException rte) {
return Double.NaN;
}
}

public void restrainedRelaxation(StereoMolecule fitMol, double e0) {

ForceFieldMMFF94.initialize(ForceFieldMMFF94.MMFF94SPLUS);
double init = 0.2;
boolean notRelaxed = true;
Expand All @@ -212,12 +208,6 @@ public void restrainedRelaxation(StereoMolecule fitMol, double e0) {
notRelaxed = (e>e0) && (e-e0>ENERGY_CUTOFF);
init += 0.2;
cycles++;

}

}




}
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,13 @@ public double[][] alignRootAndExitAtoms(FragmentGeometry3D geometry, int permuta
return Coordinates.getRmsd(mAlignmentCoords, coords) > maxRMSD ? null : matrix;
}

public boolean hasMatchingExitVectors(FragmentGeometry3D geometry, Coordinates[] coords, int permutation, double maxDiversion) {
public boolean hasMatchingExitVectors(FragmentGeometry3D geometry, Coordinates[] coords, int permutation, double maxAngleDivergence) {
maxAngleDivergence *= Math.PI / 180;
for (int i = 0; i<mExitVector.length; i++) {
Coordinates v1 = mAlignmentCoords[mExitVector.length+i].subC(mAlignmentCoords[i]);
ExitVector ev2 = geometry.mExitVector[mPermutation[permutation][i]];
Coordinates v2 = coords[ev2.exitAtom].subC(coords[ev2.rootAtom]);
if (v1.getAngle(v2) > maxDiversion)
if (v1.getAngle(v2) > maxAngleDivergence)
return false;
}
return true;
Expand Down

0 comments on commit 9d70a31

Please sign in to comment.