Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
thsa committed Oct 9, 2024
2 parents ca37389 + e9a041c commit fa90e89
Show file tree
Hide file tree
Showing 8 changed files with 125 additions and 36 deletions.
2 changes: 1 addition & 1 deletion 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.9.4-SNAPSHOT</version>
<version>2024.10.1-SNAPSHOT</version>

<name>OpenChemLib</name>
<description>Open Source Chemistry Library</description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

import com.actelion.research.calc.ArrayUtilsCalc;
import com.actelion.research.calc.statistics.median.ModelMedianInteger;
import com.actelion.research.chem.descriptor.flexophore.generator.ConstantsFlexophoreGenerator;
import com.actelion.research.util.datamodel.IntArray;

/**
Expand Down Expand Up @@ -174,6 +175,53 @@ public static RangeStatistics getRangeStatistics(MolDistHist mdh){
return rangeStatisticsTotal;
}

public static int count(byte [] a){
int c = 0;
for (int i = 0; i < a.length; i++) {
c += a[i];
}
return c;
}

public static byte [] normalize(double [] arrHistRaw){

int countValuesInHistogram = 0;
for (int i = 0; i < arrHistRaw.length; i++) {
countValuesInHistogram += arrHistRaw[i];
}
byte [] arrHistPercent = new byte [arrHistRaw.length];

for (int i = 0; i < arrHistRaw.length; i++) {
arrHistPercent[i]= (byte) (((arrHistRaw[i] / countValuesInHistogram) * ConstantsFlexophoreGenerator.SUM_VAL_HIST) + 0.5);
}

// System.out.println(StringFunctions.toString(arrHistPercent));

return arrHistPercent;

}
public static byte [] normalize(byte [] arrHistRaw){

double countValuesInHistogram = 0;
for (int i = 0; i < arrHistRaw.length; i++) {
countValuesInHistogram += arrHistRaw[i];
}
byte [] arrHistPercent = new byte [arrHistRaw.length];

for (int i = 0; i < arrHistRaw.length; i++) {

double v = ((arrHistRaw[i] / countValuesInHistogram) * ConstantsFlexophoreGenerator.SUM_VAL_HIST) + 0.5;


arrHistPercent[i]= (byte) v;
}

// System.out.println(StringFunctions.toString(arrHistPercent));

return arrHistPercent;

}


public static class RangeStatistics {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,24 +129,16 @@ public void copy(MolDistHist copy){
}

public boolean equals(Object o) {
boolean bEQ=true;
if(!equalNodes(o)){
return false;
}
MolDistHist mdh=null;
try {
mdh = (MolDistHist)o;
} catch (RuntimeException e) {
return false;
}
if(getNumPPNodes() != mdh.getNumPPNodes())
return false;

for (int i = 0; i < getNumPPNodes(); i++) {
PPNode n1 = getNode(i);
PPNode n2 = mdh.getNode(i);
if(!n1.equals(n2)){
bEQ = false;
break;
}
}
boolean bEQ=true;

for (int i = 0; i < getNumPPNodes(); i++) {
for (int j = i+1; j < getNumPPNodes(); j++) {
Expand All @@ -163,6 +155,28 @@ public boolean equals(Object o) {

return bEQ;
}
public boolean equalNodes(Object o) {
boolean bEQ=true;
MolDistHist mdh=null;
try {
mdh = (MolDistHist)o;
} catch (RuntimeException e) {
return false;
}
if(getNumPPNodes() != mdh.getNumPPNodes())
return false;

for (int i = 0; i < getNumPPNodes(); i++) {
PPNode n1 = getNode(i);
PPNode n2 = mdh.getNode(i);
if(!n1.equals(n2)){
bEQ = false;
break;
}
}

return bEQ;
}

public byte getModeFlexophore() {
return modeFlexophore;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.actelion.research.chem.descriptor.flexophore;

import com.actelion.research.chem.descriptor.flexophore.generator.ConstantsFlexophoreGenerator;
import com.actelion.research.chem.descriptor.flexophore.generator.SubFlexophoreGenerator;
import com.actelion.research.util.ArrayUtils;
import com.actelion.research.util.ByteArray;
Expand Down Expand Up @@ -258,4 +259,20 @@ public static MolDistHist createFromNodes (Collection<PPNode> col){
return a;
}

public static void reNormalizeDistHist(MolDistHist mdh, int margin){
int n = mdh.getNumPPNodes();
for (int i = 0; i < n; i++) {
for (int j = i+1; j < n; j++) {
byte [] b = mdh.getDistHist(i,j);
int c = DistHistHelper.count(b);
if(Math.abs(ConstantsFlexophoreGenerator.SUM_VAL_HIST-c) > margin){
byte [] distHistNew = DistHistHelper.normalize(b);
mdh.setDistHist(i,j,distHistNew);
// int c2 = DistHistHelper.count(distHistNew);
// System.out.println(c2);
}
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

public class ConstantsFlexophoreGenerator {


public static final double SUM_VAL_HIST = 100.0;
/**
* Defines the resolution for the range. This is also the length for the DistHist vector.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.actelion.research.calc.Matrix;
import com.actelion.research.calc.histogram.MatrixBasedHistogram;
import com.actelion.research.chem.Coordinates;
import com.actelion.research.chem.descriptor.flexophore.DistHistHelper;
import com.actelion.research.chem.descriptor.flexophore.redgraph.SubGraphIndices;
import com.actelion.research.util.Formatter;
import com.actelion.research.util.datamodel.DoubleArray;
Expand Down Expand Up @@ -80,27 +81,12 @@ public int[] getArrIndexFrag() {

Matrix maHist = MatrixBasedHistogram.getHistogram(daDistances.get(), maBins);

double [] arrHist = maHist.getRow(2);
double [] arrHistRaw = maHist.getRow(2);

// System.out.println(StringFunctions.toString(daDistances.get()));
// System.out.println(StringFunctions.toString(arrHist));

int countValuesInHistogram = 0;

for (int i = 0; i < arrHist.length; i++) {
countValuesInHistogram += arrHist[i];
}

// Here, the percentage values for the histograms are calculated.
byte [] arrHistPercent = new byte [maHist.getColDim()];

for (int i = 0; i < arrHist.length; i++) {
arrHistPercent[i]= (byte) (((arrHist[i] / countValuesInHistogram) * 100.0) + 0.5);
}

// System.out.println(StringFunctions.toString(arrHistPercent));

return arrHistPercent;
return DistHistHelper.normalize(arrHistRaw);

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public class CompleteGraphMatcher<T extends ICompleteGraph> {
public static final boolean DEBUG = false;

// We need at least two pharmacophore points.
public static final double TINY_SIM = 0.000001;
public static final int MIN_NUM_NODES_SIM = 2;

public static final int MAX_NUM_NODES = 127;
Expand Down Expand Up @@ -82,7 +83,8 @@ public class CompleteGraphMatcher<T extends ICompleteGraph> {
private byte [] arrIndexQueryTmp;

private SolutionCompleteGraph solutionBest;

private List<SolutionCompleteGraph> solutionsTop;

private long validSolutions;

private long createdSolutions;
Expand Down Expand Up @@ -129,7 +131,7 @@ private void init(){
arrIndexQueryTmp = new byte [MAX_NUM_NODES];

solutionBest = new SolutionCompleteGraph();

solutionsTop = new ArrayList<>();
nodeSimilarityWithoutSizeDifference = false;
}

Expand Down Expand Up @@ -172,6 +174,7 @@ private void initSearch(){
}

solutionBest = new SolutionCompleteGraph();
solutionsTop.clear();

// System.out.println(liSolution.size());
}
Expand All @@ -197,11 +200,21 @@ public double calculateSimilarity () {
double simMax=0;
for (SolutionCompleteGraph solutionCompleteGraph : liSolution) {
double sim = objectiveCompleteGraph.getSimilarity(solutionCompleteGraph);
solutionCompleteGraph.setSimilarity(sim);
if(sim>simMax){
simMax=sim;
solutionBest=solutionCompleteGraph;
}
}

solutionsTop.clear();
double simMaxMargin=simMax-TINY_SIM;
for (SolutionCompleteGraph scg : liSolution) {
if(scg.getSimilarity()>simMaxMargin){
solutionsTop.add(scg);
}
}

return simMax;
}

Expand Down Expand Up @@ -267,10 +280,22 @@ public double calculateSimilarity () {
}

double similarity = solutionBest.getSimilarity();


solutionsTop.clear();
double simMaxMargin=similarity-TINY_SIM;
for (SolutionCompleteGraph scg : li) {
if(scg.getSimilarity()>simMaxMargin){
solutionsTop.add(scg);
}
}

return similarity;
}

public List<SolutionCompleteGraph> getSolutionsTop() {
return solutionsTop;
}

/**
* Be careful! The histogram similarity is still considered if not explicitly set to false in the objective.
* @return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,12 @@ public byte getIndexCorrespondingBaseNode(int indexQueryNode) {
/**
* The index is the index of the node in the query molecule.
* The value at 'index' is the index of the node in the base molecule.
* Can contain -1 if a node is not mapping.
*/
public byte [] getSolution (){
return arrSolution;
}



public boolean equals(Object obj) {

boolean eq = true;
Expand Down

0 comments on commit fa90e89

Please sign in to comment.