Skip to content

Commit

Permalink
Merge tag 'openchemlib-2024.10.2'
Browse files Browse the repository at this point in the history
[maven-release-plugin]  copy for tag openchemlib-2024.10.2
  • Loading branch information
targos committed Oct 29, 2024
2 parents e30c9f8 + 4ba6aeb commit 6cb49c8
Show file tree
Hide file tree
Showing 20 changed files with 473 additions and 300 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ jobs:
strategy:
matrix:
# test against latest update of each major Java version:
java: [ 8, 11, 17 ]
java: [ 8, 11, 17, 21 ]
name: Java ${{ matrix.java }}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Setup java
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: ${{ matrix.java }}
Expand Down
20 changes: 9 additions & 11 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
Please follow the naming scheme YEAR.MONTH.RELEASE_NO_OF_MONTH
(eg. 2016.4.1 for second release in Apr 2016)
-->
<version>2024.10.1</version>
<version>2024.10.2</version>

<name>OpenChemLib</name>
<description>Open Source Chemistry Library</description>
Expand Down Expand Up @@ -48,6 +48,9 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
<javafx.version>11.0.2</javafx.version>
</properties>

<!-- Disable doclint for Java 8 -->
Expand Down Expand Up @@ -97,17 +100,17 @@
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>11.0.2</version>
<version>${javafx.version}</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-swing</artifactId>
<version>11.0.2</version>
<version>${javafx.version}</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-web</artifactId>
<version>11.0.2</version>
<version>${javafx.version}</version>
</dependency>
</dependencies>
</profile>
Expand All @@ -127,12 +130,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
<version>3.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down Expand Up @@ -209,7 +207,7 @@
<connection>scm:git:git@github.com:Actelion/openchemlib.git</connection>
<developerConnection>scm:git:git@github.com:Actelion/openchemlib.git</developerConnection>
<url>https://github.com/Actelion/openchemlib</url>
<tag>openchemlib-2024.10.1</tag>
<tag>openchemlib-2024.10.2</tag>
</scm>

<distributionManagement>
Expand Down
33 changes: 12 additions & 21 deletions src/main/java/com/actelion/research/chem/Canonizer.java
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,12 @@ public class Canonizer {
private boolean[] mNitrogenQualifiesForParity;
private ArrayList<CanonizerFragment> mFragmentList;
private ArrayList<int[]> mTHParityNormalizationGroupList;
private int mMode,mNoOfRanks,mNoOfPseudoGroups;
private final int mMode;
private int mNoOfRanks,mNoOfPseudoGroups;
private boolean mIsOddParityRound;
private boolean mZCoordinatesAvailable,mAllHydrogensAreExplicit;
private final boolean mZCoordinatesAvailable,mAllHydrogensAreExplicit;
private boolean mCIPParityNoDistinctionProblem;
private boolean mEncodeAvoid127;

private boolean mGraphGenerated;
private int mGraphRings,mFeatureBlock;
private int[] mGraphAtom;
Expand All @@ -184,9 +184,10 @@ public class Canonizer {
private int[] mGraphFrom;
private int[] mGraphClosure;

private String mIDCode, mEncodedCoords,mMapping;
private StringBuilder mEncodingBuffer;
private int mEncodingBitsAvail,mEncodingTempData,mAtomBits,mMaxConnAtoms;
private String mIDCode, mEncodedCoords,mMapping;
private StringBuilder mEncodingBuffer;
private int mEncodingBitsAvail,mEncodingTempData,mMaxConnAtoms;
private final int mAtomBits;

/**
* Runs a canonicalization procedure for the given molecule that creates unique atom ranks,
Expand All @@ -204,7 +205,7 @@ public Canonizer(StereoMolecule mol) {
* If mode includes ENCODE_ATOM_CUSTOM_LABELS, than custom atom labels are
* considered for the atom ranking and are encoded into the idcode.<br>
* If mode includes COORDS_ARE_3D, then getEncodedCoordinates() always returns
* a 3D-encoding even if all z-coordinates are 0.0. Otherwise coordinates are
* a 3D-encoding even if all z-coordinates are 0.0. Otherwise, coordinates are
* encoded in 3D only, if at least one of the z-coords is not 0.0.
* @param mol
* @param mode 0 or one or more of CONSIDER...TOPICITY, CREATE..., ENCODE_ATOM_CUSTOM_LABELS, ASSIGN_PARITIES_TO_TETRAHEDRAL_N, COORDS_ARE_3D
Expand All @@ -226,17 +227,7 @@ 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;
}
}
}
mAllHydrogensAreExplicit = (mMol.getImplicitHydrogens() == 0);

if ((mMode & NEGLECT_ANY_STEREO_INFORMATION) == 0) {
mTHParity = new byte[mMol.getAtoms()];
Expand Down Expand Up @@ -639,7 +630,7 @@ private boolean canInnerBreakTiesByHeteroTopicity() {
private void canBreakTiesRandomly() {
for (int atom=0; atom<mMol.getAtoms(); atom++) {
mCanBase[atom].init(atom);
mCanBase[atom].add(mAtomBits+1, 2*mCanRank[atom]);
mCanBase[atom].add(mAtomBits+1, (long)2*mCanRank[atom]);
}

// promote randomly one atom of lowest shared rank.
Expand Down Expand Up @@ -895,7 +886,7 @@ private void canRecursivelyFindAllParities() {
thParityInfo |= mTHESRGroup[atom];
}

mCanBase[atom].add(2 * parityInfoBits, thParityInfo << parityInfoBits); // generate space for bond parity
mCanBase[atom].add(2 * parityInfoBits, (long)thParityInfo << parityInfoBits); // generate space for bond parity
}

for (int bond=0; bond<mMol.getBonds(); bond++) {
Expand Down Expand Up @@ -3371,7 +3362,7 @@ public String getEncodedCoordinates() {
* original molecule including coordinates.<br>
* If keepPositionAndScale==false, then coordinate encoding will be relative,
* i.e. scale and absolute positions get lost during the encoding.
* Otherwise the encoding retains scale and absolute positions.<br>
* Otherwise, the encoding retains scale and absolute positions.<br>
* If the molecule has 3D-coordinates and if there are no implicit hydrogen atoms,
* i.e. all hydrogen atoms are explicitly available with their coordinates, then
* hydrogen 3D-coordinates are also encoded despite the fact that the idcode itself does
Expand Down
28 changes: 25 additions & 3 deletions src/main/java/com/actelion/research/chem/ExtendedMolecule.java
Original file line number Diff line number Diff line change
Expand Up @@ -1445,7 +1445,28 @@ public boolean supportsImplicitHydrogen(int atom) {
}

/**
* Calculates and return the number of implicit hydrogens at atom.
* Calculates and returns the number of implicit hydrogens of the molecule.
* For hydrogens atoms, metals except Al, or a noble gases, 0 is assumed.
* For all other atom kinds the number of implicit hydrogens is basically
* the lowest typical valence that is compatible with the occupied valence,
* minus the occupied valence corrected by atom charge and radical state.
* If this molecule is a fragment, then 0 is returned.
* @return number of implicit hydrogens of the molecule
*/
public int getImplicitHydrogens() {
if (mIsFragment)
return 0;

ensureHelperArrays(cHelperNeighbours);
int implicitHydrogens = 0;
for (int atom=0; atom<mAtoms; atom++)
implicitHydrogens += getImplicitHydrogens(atom);

return implicitHydrogens;
}

/**
* Calculates and returns the number of implicit hydrogens at atom.
* If atom is itself a hydrogen atom, a metal except Al, or a noble gas,
* then 0 is returned. For all other atom kinds the number of
* implicit hydrogens is basically the lowest typical valence that is compatible
Expand All @@ -1463,8 +1484,9 @@ public int getImplicitHydrogens(int atom) {
if (!supportsImplicitHydrogen(atom))
return 0;

if ("*".equals(getAtomCustomLabel(atom)))
return 0;
// attachment points have at least a valence of 1, i.e. they must be connected to something
if (mAtomicNo[atom] == 0 || "*".equals(getAtomCustomLabel(atom)))
return mAllConnAtoms[atom] == 0 ? 1 : 0;

ensureHelperArrays(cHelperNeighbours);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -820,7 +820,7 @@ private void appendBondOrderSymbol(int bond, int parentAtom, StringBuilder build
if (mEZHalfParity[bond] != 0)
builder.append(mEZHalfParity[bond] == 1 ? '/' : '\\');
if (mMode == MODE_CREATE_SMARTS) {
int bondTypes = mMol.getBondQueryFeatures(Molecule.cBondQFBondTypes | Molecule.cBondQFRareBondTypes);
int bondTypes = mMol.getBondQueryFeatures(bond) & (Molecule.cBondQFBondTypes | Molecule.cBondQFRareBondTypes);
if (bondTypes != 0) {
if ((bondTypes & Molecule.cBondTypeSingle) != 0 && mEZHalfParity[bond] == 0) {
builder.append('-');
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/com/actelion/research/chem/SSSearcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -1322,6 +1322,14 @@ public boolean areBondsSimilar(int moleculeBond, int fragmentBond) {
&& ringSize == (mMolecule.getBondQueryFeatures(fragmentBond) & Molecule.cBondQFRingSize) >> Molecule.cBondQFRingSizeShift)
return true;

if (ringSize <= 2) { // ring size 8-11 is encoded as 1; ring size >=12 is encoded as 2
int moleculeRingSize = mMolecule.getBondRingSize(moleculeBond);
if (ringSize == 1)
return (moleculeRingSize >= 8) && (moleculeRingSize <= 12);
else
return moleculeRingSize >= 12;
}

boolean found = false;
RingCollection ringSet = mMolecule.getRingSet();
for (int i=0; i<ringSet.getSize(); i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public DescriptorWeightsHelper() {
* - Charged pp points are set mandatory.
* @param liSubGraphIndices
* @param molecule3D
* @return
* @return array with dimension molecule3D.getAtoms().
*/
public static int [] calcWeightLabels(List<SubGraphIndices> liSubGraphIndices, Molecule3D molecule3D){

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import com.actelion.research.chem.interactionstatistics.InteractionAtomTypeCalculator;
import com.actelion.research.chem.phesa.pharmacophore.PharmacophoreCalculator;
import com.actelion.research.chem.phesa.pharmacophore.pp.IPharmacophorePoint;
import com.actelion.research.util.Formatter;
import com.actelion.research.util.graph.complete.ICompleteGraph;

import java.io.Serializable;
Expand Down Expand Up @@ -1056,7 +1057,40 @@ public String toStringShort(){

return b.toString();
}


/**
* Shows the weights
* @return
*/
public String toStringShortWithWeights(){

if(!finalized)
realize();
StringBuffer b = new StringBuffer();

b.append("[");
for (int i = 0; i < getNumPPNodes(); i++) {
b.append(Formatter.format1(arrWeight[i]));
b.append(getNode(i).toStringShort());
if(i<getNumPPNodes()-1){
b.append(" ");
} else {
b.append("]");
}
}

for (int i = 0; i < getNumPPNodes(); i++) {
for (int j = i+1; j < getNumPPNodes(); j++) {
byte [] arrHist = getDistHist(i,j);

if(arrHist!=null)
b.append("[" + ArrayUtilsCalc.toString(arrHist) + "]");
}
}

return b.toString();
}


public boolean equals(Object o) {
boolean bEQ=true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ public static MolDistHistViz create(List<PPNodeVizMultCoord> liPPNodeVizMultCoor
return molDistHistViz;
}

/**
* Sets the weights in MolDistHistViz. Rule based unification of weight labels for a pharmacophore node.
* @param mdhv
* @param arrWeightLabel Array dimension must equal number of atoms in the molecule in mdhv.
*/
public static void setWeights(MolDistHistViz mdhv, int [] arrWeightLabel){

// The molecule in the descriptor contains the pharmacophore points as additional single atoms.
Expand All @@ -75,6 +80,9 @@ public static void setWeights(MolDistHistViz mdhv, int [] arrWeightLabel){
throw new RuntimeException("Weight vector differs in dimension to number of atoms!");
}

//
// Rule based unification of weight labels for a pharmacophore node
//
for (PPNodeViz ppNodeViz : mdhv.getNodes()) {
int [] a = ppNodeViz.getArrayIndexOriginalAtoms();
int [] w = new int[a.length];
Expand All @@ -84,7 +92,7 @@ public static void setWeights(MolDistHistViz mdhv, int [] arrWeightLabel){

int maxWeightLabel = ArrayUtils.max(w);

// If label is not high, low is king.
// If label is not high, low is king. Means the standard wight label is overruled.
if(maxWeightLabel< DescriptorWeightsHelper.LABEL_WEIGHT_MANDATORY){
maxWeightLabel = ArrayUtils.min(w);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public class HistogramMatchCalculator {
* @param indexDistHist2At2
* @return integral of overlap
*/
public static double getSimilarity(DistHist dh1, int indexDistHist1At1, int indexDistHist1At2, DistHist dh2, int indexDistHist2At1, int indexDistHist2At2){
public static double getFractionOverlapIntegral(DistHist dh1, int indexDistHist1At1, int indexDistHist1At2, DistHist dh2, int indexDistHist2At1, int indexDistHist2At2){
int indexPostStartDistHist1 = dh1.getIndexPosStartForDistHist(indexDistHist1At1, indexDistHist1At2);
int indexPostStartDistHist2 = dh2.getIndexPosStartForDistHist(indexDistHist2At1, indexDistHist2At2);
int n = ConstantsFlexophoreGenerator.BINS_HISTOGRAM;
Expand All @@ -73,6 +73,26 @@ public static double getSimilarity(DistHist dh1, int indexDistHist1At1, int inde
double score = sumMin / sumMax;
return score;
}
public static double getFractionOverlappingBins(DistHist dh1, int indexDistHist1At1, int indexDistHist1At2, DistHist dh2, int indexDistHist2At1, int indexDistHist2At2){
int indexPostStartDistHist1 = dh1.getIndexPosStartForDistHist(indexDistHist1At1, indexDistHist1At2);
int indexPostStartDistHist2 = dh2.getIndexPosStartForDistHist(indexDistHist2At1, indexDistHist2At2);
int n = ConstantsFlexophoreGenerator.BINS_HISTOGRAM;
double sumMin = 0;
double sumMax = 0;

double sum1=0;
double sum2=0;
for (int i = 0; i < n; i++) {
int v1 = (dh1.getValueAtAbsolutePosition(indexPostStartDistHist1+i)==0)?0:1;
int v2 = (dh2.getValueAtAbsolutePosition(indexPostStartDistHist2+i)==0)?0:1;
sum1 += v1;
sum2 += v2;
sumMin += Math.min(v1, v2);
sumMax += Math.max(v1, v2);
}
double score = sumMin / Math.min(sum1, sum2);
return score;
}

public static double getPercentageOverlap(DistHist dh1, int indexDistHist1At1, int indexDistHist1At2, DistHist dh2, int indexDistHist2At1, int indexDistHist2At2){
int indexPostStartDistHist1 = dh1.getIndexPosStartForDistHist(indexDistHist1At1, indexDistHist1At2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1156,7 +1156,7 @@ public float getSimilarityHistogram(int indexNode1Query, int indexNode2Query, in
if(arrSimilarityHistograms[indexHistogramQuery][indexHistogramBase] < 0){
float similarityHistogram = 0;
similarityHistogram =
(float)HistogramMatchCalculator.getSimilarity(
(float)HistogramMatchCalculator.getFractionOverlappingBins(
mdhvQueryBlurredHist, indexNode1Query, indexNode2Query, mdhvBaseBlurredHist, indexNode1Base, indexNode2Base);
arrSimilarityHistograms[indexHistogramQuery][indexHistogramBase]=similarityHistogram;
}
Expand Down
Loading

0 comments on commit 6cb49c8

Please sign in to comment.