From bed435d35505447e998c19b58ea00b1c9cb97bf7 Mon Sep 17 00:00:00 2001 From: korffmo Date: Mon, 1 Jul 2024 07:14:37 +0200 Subject: [PATCH 1/5] Update PDB Parser --- .../pdb/parser/HeteroStructureAssembler.java | 135 ------------------ 1 file changed, 135 deletions(-) delete mode 100644 src/main/java/com/actelion/research/chem/io/pdb/parser/HeteroStructureAssembler.java diff --git a/src/main/java/com/actelion/research/chem/io/pdb/parser/HeteroStructureAssembler.java b/src/main/java/com/actelion/research/chem/io/pdb/parser/HeteroStructureAssembler.java deleted file mode 100644 index 46df1298..00000000 --- a/src/main/java/com/actelion/research/chem/io/pdb/parser/HeteroStructureAssembler.java +++ /dev/null @@ -1,135 +0,0 @@ -package com.actelion.research.chem.io.pdb.parser; - -import com.actelion.research.chem.Molecule3D; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; -import java.util.stream.IntStream; - -/** - * Cloned from StructureAssembler (Joel Wahl) - * - * Considers only hetero atom records - * - * Was implemented to extract covalent bond ligands. i.e. Nirmatrelvir in 8h4y.pdb - * - * @author MvK - * June 2024 - */ - - -public class HeteroStructureAssembler { - - - private Map> groups; - private List bondList; - - private List hetAtomRecords; - Map> mols; - - - public HeteroStructureAssembler(List bondList, List hetAtomRecords) { - this.bondList = bondList; - this.hetAtomRecords = hetAtomRecords; - groups = new HashMap>(); - mols = new HashMap>(); - } - - - public Map> assemble() { - group(); - - mols.putIfAbsent(StructureAssembler.SOLVENT_GROUP, new ArrayList()); - mols.putIfAbsent(StructureAssembler.LIGAND_GROUP, new ArrayList()); - buildHetResidues(); - mols.forEach((k,v) -> v.forEach(e -> coupleBonds(e))); - return mols; - - } - - private void group() { - - hetAtomRecords.forEach(e -> { - String s = e.getString(); - - - - if(groups.get(s)!=null) { - List li = groups.get(s); - li.add(e); - } - else { - List li = new ArrayList(); - li.add(e); - groups.put(s, li); - } - }); - for(int[] bond : bondList) { - try { - processBond(bond); - } - catch(Exception e) { - continue; - } - } - } - - - private void buildHetResidues() { - for(String group : groups.keySet()) { - List records = groups.get(group); - Residue atomGroup = new Residue(records); - Molecule3D fragment = atomGroup.getMolecule(); - if(fragment.getAtomAmino(0).equals("HOH")) { - mols.putIfAbsent(StructureAssembler.SOLVENT_GROUP, new ArrayList()); - mols.get(StructureAssembler.SOLVENT_GROUP).add(fragment); - } - else { - mols.putIfAbsent(StructureAssembler.LIGAND_GROUP, new ArrayList()); - mols.get(StructureAssembler.LIGAND_GROUP).add(fragment); - } - } - } - - private void coupleBonds(Molecule3D mol) { - for(int[] bond:bondList) { - int [] bondedAtoms = {-1,-1}; - IntStream.range(0,mol.getAllAtoms()).forEach( e -> { - int pdbAtomID = mol.getAtomSequence(e); - if(pdbAtomID==bond[0]) - bondedAtoms[0]=e; - else if(pdbAtomID==bond[1]) - bondedAtoms[1]=e; - }); - if(bondedAtoms[0]!=-1 && bondedAtoms[1]!=-1) - mol.addBond(bondedAtoms[0], bondedAtoms[1]); - } - } - - /** - * merge atom groups that are connected by a bond - * @param bond - */ - private void processBond(int[] bond) { - int atom1 = bond[0]; - int atom2 = bond[1]; - String[] grps = new String[2]; - groups.forEach((k,v) -> { - List atoms = v.stream().map(e -> e.getSerialId()).collect(Collectors.toList()); - if(atoms.contains(atom1)) - grps[0] = k; - if(atoms.contains(atom2)) - grps[1] = k; - }); - - if(grps[0].equals(grps[1])) - return; - else { - groups.get(grps[0]).addAll(groups.get(grps[1])); - groups.remove(grps[1]); - } - } -} From de1e46244fec6761544ba597a06bbe85d4f676b1 Mon Sep 17 00:00:00 2001 From: Bamboo Date: Sat, 13 Jul 2024 02:05:01 +0000 Subject: [PATCH 2/5] [maven-release-plugin] prepare release openchemlib-2024.7.1 --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 49510f8d..03e9903e 100644 --- a/pom.xml +++ b/pom.xml @@ -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) --> - 2024.7.1-SNAPSHOT + 2024.7.1 OpenChemLib Open Source Chemistry Library @@ -209,7 +209,7 @@ scm:git:git@github.com:Actelion/openchemlib.git scm:git:git@github.com:Actelion/openchemlib.git https://github.com/Actelion/openchemlib - HEAD + openchemlib-2024.7.1 From b6c3b3b463c3cae0d2488fdf24e583012cddc2ee Mon Sep 17 00:00:00 2001 From: Bamboo Date: Sat, 13 Jul 2024 02:05:05 +0000 Subject: [PATCH 3/5] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 03e9903e..a73997fd 100644 --- a/pom.xml +++ b/pom.xml @@ -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) --> - 2024.7.1 + 2024.7.2-SNAPSHOT OpenChemLib Open Source Chemistry Library @@ -209,7 +209,7 @@ scm:git:git@github.com:Actelion/openchemlib.git scm:git:git@github.com:Actelion/openchemlib.git https://github.com/Actelion/openchemlib - openchemlib-2024.7.1 + HEAD From 498ee584b2a69b7b44fb439d932a93aeebae3b44 Mon Sep 17 00:00:00 2001 From: korffmo Date: Sat, 13 Jul 2024 11:00:47 +0200 Subject: [PATCH 4/5] Update Flexophore, added weights for MolDistHistViz --- .../descriptor/flexophore/IMolDistHist.java | 4 +- .../descriptor/flexophore/MolDistHist.java | 5 ++- .../descriptor/flexophore/MolDistHistViz.java | 29 +++++++++++- ...ctiveBlurFlexophoreHardMatchUncovered.java | 45 ++++++++++++++----- 4 files changed, 68 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/actelion/research/chem/descriptor/flexophore/IMolDistHist.java b/src/main/java/com/actelion/research/chem/descriptor/flexophore/IMolDistHist.java index 2702aa0a..27495889 100644 --- a/src/main/java/com/actelion/research/chem/descriptor/flexophore/IMolDistHist.java +++ b/src/main/java/com/actelion/research/chem/descriptor/flexophore/IMolDistHist.java @@ -45,7 +45,9 @@ public interface IMolDistHist extends ICompleteGraph { byte [] getDistHist(int indexAt1, int indexAt2, byte[] arr); boolean isInevitablePharmacophorePoint(int indexNode); - + + double getWeightPharmacophorePoint(int indexNode); + int getNumInevitablePharmacophorePoints(); diff --git a/src/main/java/com/actelion/research/chem/descriptor/flexophore/MolDistHist.java b/src/main/java/com/actelion/research/chem/descriptor/flexophore/MolDistHist.java index 87996859..c33af385 100644 --- a/src/main/java/com/actelion/research/chem/descriptor/flexophore/MolDistHist.java +++ b/src/main/java/com/actelion/research/chem/descriptor/flexophore/MolDistHist.java @@ -459,9 +459,12 @@ public int getNumInevitablePharmacophorePoints() { @Override public boolean isInevitablePharmacophorePoint(int indexNode) { - // TODO Auto-generated method stub return false; } + @Override + public double getWeightPharmacophorePoint(int indexNode) { + return 1.0; + } public static int getNumBytesEntry(){ return PPNode.getNumBytesEntry()+1; diff --git a/src/main/java/com/actelion/research/chem/descriptor/flexophore/MolDistHistViz.java b/src/main/java/com/actelion/research/chem/descriptor/flexophore/MolDistHistViz.java index 36fb7374..a3a39582 100644 --- a/src/main/java/com/actelion/research/chem/descriptor/flexophore/MolDistHistViz.java +++ b/src/main/java/com/actelion/research/chem/descriptor/flexophore/MolDistHistViz.java @@ -104,7 +104,8 @@ public class MolDistHistViz extends DistHist implements Serializable, IMolDistHi private boolean finalized; private HashSet hsIndexInevitablePPPoints; - + private double [] arrWeight; + // List of the original distance table generated by the conformations. private List liDistanceTable; @@ -191,6 +192,13 @@ public void addInevitablePharmacophorePoint(int indexPPNode){ hsIndexInevitablePPPoints.add(indexPPNode); } + public void setNodeWeight(int indexNode, double weight){ + if(!finalized){ + throw new RuntimeException("MolDistHistViz not finalized!"); + } + arrWeight[indexNode]=weight; + } + public void removeInevitablePharmacophorePoint(int indexPPNode){ hsIndexInevitablePPPoints.remove(indexPPNode); } @@ -301,6 +309,10 @@ public void copy(MolDistHistViz copy){ copy.hsIndexInevitablePPPoints.clear(); copy.hsIndexInevitablePPPoints.addAll(hsIndexInevitablePPPoints); + + copy.arrWeight = new double[this.arrWeight.length]; + + System.arraycopy(this.arrWeight, 0, copy.arrWeight, 0, this.arrWeight.length); } @@ -571,6 +583,12 @@ public void swapNodes(int n1, int n2){ setDistHist(n2,i, histTmp); } } + + double w1 = arrWeight[n1]; + + arrWeight[n1]=arrWeight[n2]; + arrWeight[n2]=w1; + } private int compare(byte [] arr1, byte [] arr2) { @@ -616,7 +634,10 @@ public boolean isInevitablePharmacophorePoint(int indexNode){ return hsIndexInevitablePPPoints.contains(indexNode); } - + @Override + public double getWeightPharmacophorePoint(int indexNode) { + return 1.0; + } public boolean isAliphatic(int indexNode) { boolean aliphatic = true; @@ -757,6 +778,10 @@ private int calcNumCExclusiveNodes(){ * Must be called after changes in the nodes or distance histograms. */ public void realize() { + + arrWeight = new double[liPPNodeViz.size()]; + Arrays.fill(arrWeight, 1.0); + for(PPNodeViz node : liPPNodeViz){ node.realize(); } diff --git a/src/main/java/com/actelion/research/chem/descriptor/flexophore/completegraphmatcher/ObjectiveBlurFlexophoreHardMatchUncovered.java b/src/main/java/com/actelion/research/chem/descriptor/flexophore/completegraphmatcher/ObjectiveBlurFlexophoreHardMatchUncovered.java index 26b8b2c9..407914af 100644 --- a/src/main/java/com/actelion/research/chem/descriptor/flexophore/completegraphmatcher/ObjectiveBlurFlexophoreHardMatchUncovered.java +++ b/src/main/java/com/actelion/research/chem/descriptor/flexophore/completegraphmatcher/ObjectiveBlurFlexophoreHardMatchUncovered.java @@ -1,5 +1,6 @@ package com.actelion.research.chem.descriptor.flexophore.completegraphmatcher; +import com.actelion.research.calc.ArrayUtilsCalc; import com.actelion.research.calc.Matrix; import com.actelion.research.calc.graph.MinimumSpanningTree; import com.actelion.research.chem.descriptor.DescriptorHandlerFlexophore; @@ -93,6 +94,8 @@ public class ObjectiveBlurFlexophoreHardMatchUncovered implements IObjectiveComp private double [][] arrRelativeDistanceMatrixBase; + private double [] arrSimilarityTmp; + private Matrix maHelperAdjacencyQuery; private Matrix maHelperAdjacencyBase; @@ -192,6 +195,8 @@ private void initSimilarityMatrices(){ arrSimilarityHistograms[i] = new float [maxNumHistograms]; Arrays.fill(arrSimilarityHistograms[i], INIT_VAL); } + + arrSimilarityTmp=new double[ConstantsFlexophore.MAX_NUM_NODES_FLEXOPHORE]; } /** @@ -467,10 +472,17 @@ public float getSimilarity(SolutionCompleteGraph solution) { } - double sumPairwiseMapping = 0; + // double sumPairwiseMapping = 0; // double productPairwiseMapping = 0; + int cc=0; + + int nMappings = ((heap * heap)-heap) / 2; + + double [] arrMappingWeights = new double[nMappings]; + double [] arrSimilarityWeighted = new double[nMappings]; + for (int i = 0; i < heap; i++) { int indexNode1Query = solution.getIndexQueryFromHeap(i); @@ -484,17 +496,25 @@ public float getSimilarity(SolutionCompleteGraph solution) { double scorePairwiseMapping = getScorePairwiseMapping(indexNode1Query, indexNode2Query, indexNode1Base, indexNode2Base); - sumPairwiseMapping += scorePairwiseMapping; + double w = + mdhvQuery.getWeightPharmacophorePoint(indexNode1Query) + * mdhvQuery.getWeightPharmacophorePoint(indexNode2Query); + + arrMappingWeights[cc]=w; + + arrSimilarityWeighted[cc++]=scorePairwiseMapping * w; if(verbose) { System.out.println("scorePairwiseMapping " + Formatter.format2(scorePairwiseMapping)); } } } - - double mappings = ((heap * heap)-heap) / 2.0; - - avrPairwiseMappingScaled = sumPairwiseMapping/mappings; + // double mappings = ((heap * heap)-heap) / 2.0; + + double sumMappingWeights = ArrayUtilsCalc.sum(arrMappingWeights); + double sumSimilarityWeighted = ArrayUtilsCalc.sum(arrSimilarityWeighted); + + avrPairwiseMappingScaled = sumSimilarityWeighted/sumMappingWeights; coverageQuery = getRatioMinimumSpanningTreeQuery(solution); @@ -633,16 +653,19 @@ public float getSimilarityNodes(SolutionCompleteGraph solution) { return (float)similarity; } - double sumSimilarityNodes = 0; + double sumSimilarityNodesWeighted = 0; + + double sumWeights = 0; for (int i = 0; i < heap; i++) { int indexNodeQuery = solution.getIndexQueryFromHeap(i); + double w = mdhvQuery.getWeightPharmacophorePoint(indexNodeQuery); int indexNodeBase = solution.getIndexCorrespondingBaseNode(indexNodeQuery); - double similarityNodePair = getSimilarityNodes(indexNodeQuery, indexNodeBase); - sumSimilarityNodes += similarityNodePair; + double similarityNodePairWeighted = getSimilarityNodes(indexNodeQuery, indexNodeBase)*w; + sumSimilarityNodesWeighted += similarityNodePairWeighted; + sumWeights+=w; } - double mappings = heap; - avrPairwiseMappingScaled = sumSimilarityNodes/mappings; + avrPairwiseMappingScaled = sumSimilarityNodesWeighted / sumWeights; coverageQuery = 0; coverageBase = 0; double ratioNodesMatchQuery = Math.min(nodesQuery, heap) / (double)Math.max(nodesQuery, heap); From 67d97fd7a0451d4571144c42492466f88557b6b5 Mon Sep 17 00:00:00 2001 From: korffmo Date: Sat, 13 Jul 2024 17:50:54 +0200 Subject: [PATCH 5/5] Update Flexophore, added weights for MolDistHistViz --- .../chem/descriptor/flexophore/MolDistHistViz.java | 11 +++-------- .../ObjectiveBlurFlexophoreHardMatchUncovered.java | 3 --- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/actelion/research/chem/descriptor/flexophore/MolDistHistViz.java b/src/main/java/com/actelion/research/chem/descriptor/flexophore/MolDistHistViz.java index a3a39582..c11d01d8 100644 --- a/src/main/java/com/actelion/research/chem/descriptor/flexophore/MolDistHistViz.java +++ b/src/main/java/com/actelion/research/chem/descriptor/flexophore/MolDistHistViz.java @@ -168,19 +168,14 @@ public MolDistHistViz(MolDistHist mdh) { if(mdh.getNumPPNodes()==0){ throw new RuntimeException("Empty object given into constructor."); } - mdh.copy(this); - modeFlexophore = mdh.getModeFlexophore(); - - liPPNodeViz=new ArrayList(mdh.getNumPPNodes()); + liPPNodeViz=new ArrayList<>(mdh.getNumPPNodes()); for (int i = 0; i < mdh.getNumPPNodes(); i++) { PPNodeViz node = new PPNodeViz(mdh.getNode(i)); liPPNodeViz.add(node); } - - hsIndexInevitablePPPoints = new HashSet(); - + hsIndexInevitablePPPoints = new HashSet<>(); realize(); } @@ -636,7 +631,7 @@ public boolean isInevitablePharmacophorePoint(int indexNode){ } @Override public double getWeightPharmacophorePoint(int indexNode) { - return 1.0; + return arrWeight[indexNode]; } public boolean isAliphatic(int indexNode) { diff --git a/src/main/java/com/actelion/research/chem/descriptor/flexophore/completegraphmatcher/ObjectiveBlurFlexophoreHardMatchUncovered.java b/src/main/java/com/actelion/research/chem/descriptor/flexophore/completegraphmatcher/ObjectiveBlurFlexophoreHardMatchUncovered.java index 407914af..43b5e9ee 100644 --- a/src/main/java/com/actelion/research/chem/descriptor/flexophore/completegraphmatcher/ObjectiveBlurFlexophoreHardMatchUncovered.java +++ b/src/main/java/com/actelion/research/chem/descriptor/flexophore/completegraphmatcher/ObjectiveBlurFlexophoreHardMatchUncovered.java @@ -325,11 +325,8 @@ public boolean isValidSolution(SolutionCompleteGraph solution) { // if(mapping){ for (int i = 0; i < heap; i++) { - int indexNodeQuery = solution.getIndexQueryFromHeap(i); - int indexNodeBase = solution.getIndexCorrespondingBaseNode(indexNodeQuery); - if(!areNodesMapping(indexNodeQuery, indexNodeBase)) { mapping = false; break;