Skip to content

Commit

Permalink
feat: update OCL to v2024.10.0
Browse files Browse the repository at this point in the history
  • Loading branch information
targos committed Oct 7, 2024
1 parent cc7042f commit 2cee300
Show file tree
Hide file tree
Showing 18 changed files with 705 additions and 95 deletions.
2 changes: 1 addition & 1 deletion openchemlib
Submodule openchemlib updated 47 files
+1 −1 buildOpenChemLib
+2 −2 pom.xml
+13 −4 src/main/java/com/actelion/research/calc/ArrayUtilsCalc.java
+8 −11 src/main/java/com/actelion/research/calc/Matrix.java
+23 −1 src/main/java/com/actelion/research/calc/combinatorics/CombinationGenerator.java
+10 −1 src/main/java/com/actelion/research/calc/histogram/Histogram.java
+16 −12 src/main/java/com/actelion/research/calc/statistics/median/MedianStatisticFunctions.java
+7 −1 src/main/java/com/actelion/research/chem/AromaticityResolver.java
+37 −6 src/main/java/com/actelion/research/chem/AtomFunctionAnalyzer.java
+51 −13 src/main/java/com/actelion/research/chem/Canonizer.java
+16 −9 src/main/java/com/actelion/research/chem/ExtendedMolecule.java
+36 −5 src/main/java/com/actelion/research/chem/ExtendedMoleculeFunctions.java
+12 −1 src/main/java/com/actelion/research/chem/IDCodeParserWithoutCoordinateInvention.java
+1 −1 src/main/java/com/actelion/research/chem/SmilesParser.java
+1 −2 src/main/java/com/actelion/research/chem/conf/AtomAssembler.java
+36 −33 src/main/java/com/actelion/research/chem/conf/MolecularFlexibilityCalculator.java
+18 −2 src/main/java/com/actelion/research/chem/descriptor/DescriptorHandlerFlexophore.java
+8 −9 src/main/java/com/actelion/research/chem/descriptor/DescriptorHelper.java
+151 −0 src/main/java/com/actelion/research/chem/descriptor/DescriptorWeightsHelper.java
+3 −6 src/main/java/com/actelion/research/chem/descriptor/flexophore/ConstantsFlexophore.java
+48 −0 src/main/java/com/actelion/research/chem/descriptor/flexophore/DistHistHelper.java
+26 −12 src/main/java/com/actelion/research/chem/descriptor/flexophore/MolDistHist.java
+17 −0 src/main/java/com/actelion/research/chem/descriptor/flexophore/MolDistHistHelper.java
+31 −3 src/main/java/com/actelion/research/chem/descriptor/flexophore/MolDistHistViz.java
+18 −7 src/main/java/com/actelion/research/chem/descriptor/flexophore/MolDistHistVizHelper.java
+18 −0 src/main/java/com/actelion/research/chem/descriptor/flexophore/SlidingWindowDistHist.java
+10 −14 ...in/java/com/actelion/research/chem/descriptor/flexophore/completegraphmatcher/HistogramMatchCalculator.java
+23 −19 ...ion/research/chem/descriptor/flexophore/completegraphmatcher/ObjectiveBlurFlexophoreHardMatchUncovered.java
+2 −1 src/main/java/com/actelion/research/chem/descriptor/flexophore/generator/ConstantsFlexophoreGenerator.java
+83 −4 src/main/java/com/actelion/research/chem/descriptor/flexophore/generator/CreatorMolDistHistViz.java
+3 −17 src/main/java/com/actelion/research/chem/descriptor/flexophore/generator/MultCoordFragIndex.java
+8 −1 src/main/java/com/actelion/research/chem/descriptor/flexophore/redgraph/SubGraphIndices.java
+1 −1 src/main/java/com/actelion/research/chem/io/CompoundFileHelper.java
+1 −0 src/main/java/com/actelion/research/chem/io/CompoundTableConstants.java
+122 −16 src/main/java/com/actelion/research/chem/io/DWARFileParser.java
+2 −1 src/main/java/com/actelion/research/chem/phesa/DescriptorHandlerShape.java
+7 −12 src/main/java/com/actelion/research/chem/phesa/pharmacophore/IonizableGroupDetector.java
+5 −4 src/main/java/com/actelion/research/chem/shredder/Fragment3D.java
+305 −0 src/main/java/com/actelion/research/chem/shredder/FragmentGeometry3D.java
+34 −26 src/main/java/com/actelion/research/chem/shredder/Fragmenter3D.java
+16 −16 src/main/java/com/actelion/research/chem/shredder/MoleculeShredder.java
+1 −1 src/main/java/com/actelion/research/gui/JFileChooserOverwrite.java
+22 −0 src/main/java/com/actelion/research/util/ArrayUtils.java
+7 −14 src/main/java/com/actelion/research/util/CommandLineParser.java
+29 −0 src/main/java/com/actelion/research/util/StringFunctions.java
+38 −7 src/main/java/com/actelion/research/util/graph/complete/CompleteGraphMatcher.java
+5 −6 src/main/java/com/actelion/research/util/graph/complete/SolutionCompleteGraph.java
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,13 @@ public boolean locateDelocalizedDoubleBonds(boolean[] isAromaticBond, boolean ma
}
}

if (!bondsPromoted) {

if (bondsPromoted) {
promoteObviousBonds();
continue;
}

if (!bondsPromoted) {
// find and promote one aromatic bond
// (should never happen, but to prevent an endless loop nonetheless)
for (int bond=0; bond<mMol.getBonds(); bond++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,12 @@ public static boolean hasUnbalancedAtomCharge(StereoMolecule mol, int atom) {
}

public static boolean isAcidicOxygen(StereoMolecule mol, int atom) {
return isAcidicOxygen(mol, atom, true);
}

public static boolean isAcidicOxygen(StereoMolecule mol, int atom, boolean considerCharge) {
if (mol.getAtomicNo(atom) != 8
|| mol.getAtomCharge(atom) != 0
|| (considerCharge && mol.getAtomCharge(atom) != 0)
|| mol.getConnAtoms(atom) != 1
|| mol.getConnBondOrder(atom, 0) != 1)
return false;
Expand Down Expand Up @@ -246,13 +250,18 @@ public static boolean isAcidicOxygen(StereoMolecule mol, int atom) {

if(nDoubleBondedO2S == 2)
return true;
} else if(isAcidicOxygenAtPhosphoricAcid(mol, atom)) // CP=O(OH)(OH)

} else if(isAcidicOxygenAtPhosphoricAcid(mol, atom, considerCharge)) // CP=O(OH)(OH)
return true;

return false;
}

public static boolean isAcidicOxygenAtPhosphoricAcid(StereoMolecule mol, int atom) {
return isAcidicOxygenAtPhosphoricAcid(mol, atom, true);
}

public static boolean isAcidicOxygenAtPhosphoricAcid(StereoMolecule mol, int atom, boolean considerCharge) {
if (mol.getAtomicNo(atom) != 8)
return false;

Expand Down Expand Up @@ -351,11 +360,15 @@ public static boolean isNitroGroupN(StereoMolecule mol, int atom) {
return nitro;
}




public static boolean isBasicNitrogen(StereoMolecule mol, int atom) {
return isBasicNitrogen(mol, atom, true);
}


public static boolean isBasicNitrogen(StereoMolecule mol, int atom, boolean considerCharge) {
if (mol.getAtomicNo(atom) != 7
|| mol.getAtomCharge(atom) != 0
|| (considerCharge && mol.getAtomCharge(atom) != 0)
|| (mol.getConnAtoms(atom) + mol.getAtomPi(atom) > 3))
return false;

Expand Down Expand Up @@ -552,5 +565,23 @@ && getFakeOxoCount(mol, mol.getConnAtom(conn, j)) != 0)
}
}
return false;
}

public static boolean isAmphiphilic(StereoMolecule mol) {
boolean amphiphilic=true;

boolean acidic=false;
boolean basic=false;
for (int at = 0; at < mol.getAtoms(); at++) {
if(isAcidicOxygen(mol, at)){
acidic=true;
}
if(isBasicNitrogen(mol, at)){
basic=true;
}
}

amphiphilic = basic && acidic;
return amphiphilic;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ public class Canonizer {
private ArrayList<int[]> mTHParityNormalizationGroupList;
private int mMode,mNoOfRanks,mNoOfPseudoGroups;
private boolean mIsOddParityRound;
private boolean mZCoordinatesAvailable;
private boolean mZCoordinatesAvailable,mAllHydrogensAreExplicit;
private boolean mCIPParityNoDistinctionProblem;
private boolean mEncodeAvoid127;

Expand Down Expand Up @@ -226,6 +226,18 @@ public Canonizer(StereoMolecule mol, int mode) {

mZCoordinatesAvailable = ((mode & COORDS_ARE_3D) != 0) || mMol.is3D();

mAllHydrogensAreExplicit = false;
if (mMol.getAllAtoms() > mMol.getAtoms()
&& !mMol.isFragment()) {
mAllHydrogensAreExplicit = true;
for (int i=0; i<mMol.getAtoms(); i++) {
if (mMol.getImplicitHydrogens(i) != 0) {
mAllHydrogensAreExplicit = false;
break;
}
}
}

if ((mMode & NEGLECT_ANY_STEREO_INFORMATION) == 0) {
mTHParity = new byte[mMol.getAtoms()];
mTHParityIsPseudo = new boolean[mMol.getAtoms()];
Expand Down Expand Up @@ -3175,6 +3187,43 @@ private void idCodeCreate() {
}
}

if (mAllHydrogensAreExplicit && (mMode & ENCODE_ATOM_SELECTION) != 0) {
count = 0;
int connBits = 0;
for (int i=0; i<mMol.getAtoms(); i++) {
int atom = mGraphAtom[i];
int conns = 0;
for (int j=mMol.getConnAtoms(atom); j<mMol.getAllConnAtoms(atom); j++) {
if (mMol.isSelectedAtom(mMol.getConnAtom(atom, j))) {
int hIndex = j - mMol.getConnAtoms(atom);
conns |= (1 << hIndex);
connBits = Math.max(connBits, hIndex+1);
}
}
if (conns != 0)
count++;
}
if (count != 0) {
encodeFeatureNo(38); // 38 = datatype 'selected hydrogens'
encodeBits(count, nbits);
encodeBits(connBits, 3);
for (int i=0; i<mMol.getAtoms(); i++) {
int atom = mGraphAtom[i];
int conns = 0;
for (int j=mMol.getConnAtoms(atom); j<mMol.getAllConnAtoms(atom); j++) {
if (mMol.isSelectedAtom(mMol.getConnAtom(atom, j))) {
int hIndex = j - mMol.getConnAtoms(atom);
conns |= (1 << hIndex);
}
}
if (conns != 0) {
encodeBits(atom, nbits);
encodeBits(conns, connBits);
}
}
}
}

encodeBits(0, 1);
mIDCode = encodeBitsEnd();
}
Expand Down Expand Up @@ -3370,18 +3419,7 @@ private void encodeCoordinates(boolean keepPositionAndScale, Coordinates[] coord
}

// if we have 3D-coords and explicit hydrogens and if all hydrogens are explicit then encode hydrogen coordinates
boolean includeHydrogenCoordinates = false;
if (mZCoordinatesAvailable
&& mMol.getAllAtoms() > mMol.getAtoms()
&& !mMol.isFragment()) {
includeHydrogenCoordinates = true;
for (int i=0; i<mMol.getAtoms(); i++) {
if (mMol.getImplicitHydrogens(i) != 0) {
includeHydrogenCoordinates = false;
break;
}
}
}
boolean includeHydrogenCoordinates = mZCoordinatesAvailable & mAllHydrogensAreExplicit;

int resolutionBits = mZCoordinatesAvailable ? 16 : 8; // must be an even number
encodeBitsStart(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1437,7 +1437,7 @@ public int getSubstituentSize(int coreAtom, int firstAtom) {
public boolean supportsImplicitHydrogen(int atom) {
if ((mAtomFlags[atom] & cAtomFlagsValence) != 0)
return true;
if (mAtomicNo[atom] == 1)
if (mAtomicNo[atom] <= 1)
return false;
return isOrganicAtom(atom)
|| mAtomicNo[atom] == 13 // Al
Expand All @@ -1463,6 +1463,9 @@ public int getImplicitHydrogens(int atom) {
if (!supportsImplicitHydrogen(atom))
return 0;

if ("*".equals(getAtomCustomLabel(atom)))
return 0;

ensureHelperArrays(cHelperNeighbours);

int occupiedValence = 0;
Expand Down Expand Up @@ -3476,8 +3479,11 @@ public int getHelperArrayStatus() {
* bonds leading to them are moved to the end of the bond table. This way algorithms can skip
* hydrogen atoms easily. For every atom directly connected atoms and bonds (with and without
* hydrogens) are determined. The number of pi electrons is counted.<br>
* If this Molecule is a substructure (mFragment=true) and has no 3-dimensional atom coordinates,
* then all explicit hydrogen atoms are converted into query features, unless setHydrogenProtection(true)
* was called before on this Molecule.<br>
* <i>cHelperRings</i>: Aromatic and non-aromatic rings are detected. Atom and bond ring
* properties are set and a ring collection provides a total set of small rings (7 or less atoms).
* properties are set and a ring collection provides a total set of small rings (7 or fewer atoms).
* Atoms being in allylic/benzylic or stabilized (neighbor of a carbonyl or similar group) position
* are flagged as such.<br>
* <i>cHelperParities</i>: Atom (tetrahedral or axial) and bond (E/Z or atrop) parities are calculated
Expand All @@ -3501,7 +3507,7 @@ public void ensureHelperArrays(int required) {
calculateNeighbours();
mValidHelperArrays |= cHelperBitNeighbours;

if (convertHydrogenToQueryFeatures()) {
if (mIsFragment && !is3D() && convertHydrogenToQueryFeatures()) {
handleHydrogens();
calculateNeighbours();
mValidHelperArrays |= cHelperBitNeighbours;
Expand Down Expand Up @@ -3989,9 +3995,6 @@ else if (atomRingBondCount[atom] > 3)
* @return true if hydrogens were deleted and, thus, mConnAtoms are invalid
*/
private boolean convertHydrogenToQueryFeatures() {
if (!mIsFragment)
return false;

// if an atom has no free valence then cAtomQFNoMoreNeighbours is not necessary
// and cAtomQFMoreNeighbours is not possible
// unless it is an uncharged N- or O-family atom that could be e.g. methylated
Expand All @@ -4001,12 +4004,15 @@ private boolean convertHydrogenToQueryFeatures() {
mAtomQueryFeatures[atom] &= ~(cAtomQFNoMoreNeighbours | cAtomQFMoreNeighbours);
}

// approximate explicit hydrogens by query features
// and remove explicit hydrogens except those with stereo bonds
if (mProtectHydrogen)
return false;

// approximate explicit hydrogens by query features
// and remove explicit hydrogens except those with stereo bonds
boolean deleteHydrogens = false;
for (int atom=0; atom<mAtoms; atom++) {
int explicitHydrogens = getExplicitHydrogens(atom);
if (!mProtectHydrogen && explicitHydrogens > 0) {
if (explicitHydrogens > 0) {
if ((mAtomQueryFeatures[atom] & cAtomQFNoMoreNeighbours) == 0) {
// add query feature hydrogen to explicit hydrogens
int queryFeatureHydrogens =
Expand Down Expand Up @@ -4048,6 +4054,7 @@ private boolean convertHydrogenToQueryFeatures() {
}
}
}

if (deleteHydrogens)
compressMolTable();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@
package com.actelion.research.chem;

import com.actelion.research.calc.ArrayUtilsCalc;
import com.actelion.research.calc.statistics.StatisticsOverview;
import com.actelion.research.calc.statistics.median.MedianStatisticFunctions;
import com.actelion.research.chem.descriptor.DescriptorEncoder;
import com.actelion.research.chem.descriptor.DescriptorHandler;
import com.actelion.research.util.BurtleHasher;
Expand Down Expand Up @@ -770,6 +772,23 @@ public final static boolean atomAtomSubStrucMatch(StereoMolecule molecule, int a
return arr;
}

public final static int [] getTopologicalDistances(int [][] topoDistMatrix, int [] at1, int [] at2) {

int [] d = new int[at1.length*at2.length];
int cc=0;
for (int i = 0; i < at1.length; i++) {
for (int j = 0; j < at2.length; j++) {
d[cc++]=topoDistMatrix[at1[i]][at2[j]];
}
}

return d;
}
public final static int getMedianTopologicalDistance(int [][] topoDistMatrix, int [] at1, int [] at2) {
int [] d = getTopologicalDistances(topoDistMatrix, at1, at2);
int medTopoDist = MedianStatisticFunctions.getMedianForInteger(d).median;
return medTopoDist;
}

public final static int getTopologicalDistance(ExtendedMolecule mol, int at1, int at2) {
int dist = 0;
Expand Down Expand Up @@ -1271,19 +1290,31 @@ public static int getNumCyanoGroups(StereoMolecule mol){
}


public static int getNumAlcoholicOxygen(StereoMolecule mol){

public static int getTotalCharge(StereoMolecule mol){
int n = 0;

for (int i = 0; i < mol.getAllAtoms(); i++) {
n+=mol.getAtomCharge(i);
}
return n;
}
public static int getNumAtomsCharged(StereoMolecule mol){
int n = 0;
for (int i = 0; i < mol.getAllAtoms(); i++) {
if(mol.getAtomCharge(i)!=0){
n++;
}
}
return n;
}

public static int getNumAlcoholicOxygen(StereoMolecule mol){
int n = 0;
for (int i = 0; i < mol.getAllAtoms(); i++) {
if(isAlcoholicOxygen(mol, i)){
n++;
}
}

return n;

}

public static int getNumThioEther(StereoMolecule mol){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public void neglectSpaceDelimitedCoordinates() {
* @return
*/
public StereoMolecule getCompactMolecule(String idcode) {
return (idcode == null || idcode.isEmpty()) ? null : getCompactMolecule(idcode.getBytes(StandardCharsets.UTF_8), null);
return (idcode == null || idcode.isEmpty()) ? null : getCompactMolecule(idcode.getBytes(StandardCharsets.UTF_8));
}

/**
Expand Down Expand Up @@ -433,6 +433,7 @@ public void parse(StereoMolecule mol, byte[] idcode, byte[] coordinates, int idc
mMol.setFragment(decodeBits(1) == 1);

int[] aromaticSPBond = null;
int[] selectedHydrogenBits = null;

int offset = 0;
while (decodeBits(1) == 1) {
Expand Down Expand Up @@ -724,6 +725,13 @@ public void parse(StereoMolecule mol, byte[] idcode, byte[] coordinates, int idc
mMol.setBondType(bond, bondType);
}
break;
case 38: // datatype 'selected hydrogen'
no = decodeBits(abits);
int connBits = decodeBits(3);
selectedHydrogenBits = new int[allAtoms];
for (int i=0; i<no; i++)
selectedHydrogenBits[decodeBits(abits)] = decodeBits(connBits);
break;
}
}

Expand Down Expand Up @@ -786,6 +794,9 @@ public void parse(StereoMolecule mol, byte[] idcode, byte[] coordinates, int idc
mMol.setAtomY(hydrogen, mMol.getAtomY(atom) + (decodeBits(resolutionBits) - binCount / 2.0));
if (coordsAre3D)
mMol.setAtomZ(hydrogen, mMol.getAtomZ(atom) + (decodeBits(resolutionBits) - binCount / 2.0));

if (selectedHydrogenBits != null && (selectedHydrogenBits[atom] & (1 << i)) != 0)
mMol.setAtomSelection(hydrogen, true);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -812,7 +812,7 @@ else if (!mMakeHydrogenExplicit && (mSmartsFeatureFound || mSmartsMode == SMARTS

if (parityMap != null) {
for (THParity parity:parityMap.values())
mMol.setAtomParity(parity.mCentralAtom, parity.calculateParity(handleHydrogenAtomMap), false);
mMol.setAtomParity(handleHydrogenAtomMap[parity.mCentralAtom], parity.calculateParity(handleHydrogenAtomMap), false);

mMol.setParitiesValid(0);
}
Expand Down
Loading

0 comments on commit 2cee300

Please sign in to comment.