Skip to content

Commit 95ce0dd

Browse files
committed
Merge remote-tracking branch 'origin/master'
2 parents 37d7d97 + bc18323 commit 95ce0dd

File tree

12 files changed

+390
-117
lines changed

12 files changed

+390
-117
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
Please follow the naming scheme YEAR.MONTH.RELEASE_NO_OF_MONTH
99
(eg. 2016.4.1 for second release in Apr 2016)
1010
-->
11-
<version>2026.1.5-SNAPSHOT</version>
11+
<version>2026.2.1-SNAPSHOT</version>
1212

1313
<name>OpenChemLib</name>
1414
<description>Open Source Chemistry Library</description>

src/main/java/com/actelion/research/chem/ExtendedMoleculeFunctions.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1547,10 +1547,32 @@ public static float getSimilarity(StereoMolecule m1, StereoMolecule m2, Descript
15471547
public static StereoMolecule getSphere(StereoMolecule mol, int rootAtom, int depth){
15481548
mol.ensureHelperArrays(Molecule.cHelperRings);
15491549
StereoMolecule fragment = new StereoMolecule(mol.getAtoms(), mol.getBonds());
1550+
15501551
boolean[] atomMask = getSphereAtomMask(mol, rootAtom, depth);
1551-
mol.copyMoleculeByAtoms(fragment, atomMask, true, null);
1552+
1553+
int [] atomMap = new int[atomMask.length];
1554+
mol.copyMoleculeByAtoms(fragment, atomMask, true, atomMap);
1555+
fragment.ensureHelperArrays(Molecule.cHelperRings);
1556+
fragment.setFragment(true);
1557+
for (int i = 0; i < atomMap.length; i++) {
1558+
int indAtFrag = atomMap[i];
1559+
if(indAtFrag==-1) continue;
1560+
long queryFeatures = 0;
1561+
if(mol.isRingAtom(i))
1562+
queryFeatures |= Molecule.cAtomQFNotChain;
1563+
else
1564+
queryFeatures |= Molecule.cAtomQFNot2RingBonds | Molecule.cAtomQFNot3RingBonds | Molecule.cAtomQFNot4RingBonds ;
1565+
if(mol.isAromaticAtom(i))
1566+
queryFeatures |= Molecule.cAtomQFAromatic;
1567+
else
1568+
queryFeatures |= Molecule.cAtomQFNotAromatic;
1569+
1570+
fragment.setAtomQueryFeature(indAtFrag, queryFeatures, true);
1571+
}
15521572
return fragment;
15531573
}
1574+
1575+
15541576
public static StereoMolecule getSphereWithDummyAtom(StereoMolecule mol, int rootAtom, int depth, int atNoDummy){
15551577

15561578
mol.ensureHelperArrays(Molecule.cHelperRings);

src/main/java/com/actelion/research/chem/descriptor/DescriptorWeightsHelper.java

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,35 @@
88
import java.util.List;
99

1010
/*
11-
12-
Copyright (c) 2024 Alipheron AG. All rights reserved.
13-
14-
This file is part of the Alipheron AG software suite.
15-
16-
Licensed under the Alipheron AG Software License Agreement (the "License");
17-
you may not use this file except in compliance with the License.
18-
You may obtain a copy of the License at the company's official website or upon request.
19-
20-
Unless required by applicable law or agreed to in writing, software
21-
distributed under the License is distributed on an "AS IS" BASIS,
22-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23-
See the License for the specific language governing permissions and
24-
limitations under the License.
25-
26-
Created by Modest von Korff
27-
26/07/2024
28-
11+
* Copyright (c) 1997 - 2016
12+
* Actelion Pharmaceuticals Ltd.
13+
* Gewerbestrasse 16
14+
* CH-4123 Allschwil, Switzerland
15+
*
16+
* All rights reserved.
17+
*
18+
* Redistribution and use in source and binary forms, with or without
19+
* modification, are permitted provided that the following conditions are met:
20+
*
21+
* 1. Redistributions of source code must retain the above copyright notice, this
22+
* list of conditions and the following disclaimer.
23+
* 2. Redistributions in binary form must reproduce the above copyright notice,
24+
* this list of conditions and the following disclaimer in the documentation
25+
* and/or other materials provided with the distribution.
26+
* 3. Neither the name of the the copyright holder nor the
27+
* names of its contributors may be used to endorse or promote products
28+
* derived from this software without specific prior written permission.
29+
*
30+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
31+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
32+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
33+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
34+
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
35+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
36+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
37+
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
38+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
39+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2940
*/
3041
public class DescriptorWeightsHelper {
3142

src/main/java/com/actelion/research/chem/descriptor/flexophore/MolDistHistHelper.java

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,40 @@
66
import com.actelion.research.util.ByteArray;
77

88
import java.util.*;
9-
9+
/**
10+
* Copyright (c) 2026
11+
* Alipheron AG
12+
* Hochbergerstrasse 60C
13+
* CH-4057 Basel
14+
* Switzerland
15+
*
16+
* All rights reserved.
17+
*
18+
* Redistribution and use in source and binary forms, with or without
19+
* modification, are permitted provided that the following conditions are met:
20+
*
21+
* 1. Redistributions of source code must retain the above copyright notice, this
22+
* list of conditions and the following disclaimer.
23+
* 2. Redistributions in binary form must reproduce the above copyright notice,
24+
* this list of conditions and the following disclaimer in the documentation
25+
* and/or other materials provided with the distribution.
26+
* 3. Neither the name of the copyright holder nor the
27+
* names of its contributors may be used to endorse or promote products
28+
* derived from this software without specific prior written permission.
29+
*
30+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
31+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
32+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
33+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
34+
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
35+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
36+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
37+
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
38+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
39+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40+
*
41+
* @author Modest v. Korff
42+
*/
1043
public class MolDistHistHelper {
1144

1245

@@ -287,4 +320,30 @@ public static void reNormalizeDistHist(MolDistHist mdh, int margin){
287320
}
288321
}
289322

323+
public static Comparator<MolDistHist> getComparator() {
324+
325+
return new Comparator<MolDistHist>() {
326+
@Override
327+
public int compare(MolDistHist o1, MolDistHist o2) {
328+
int cmp = 0;
329+
330+
if(o1.getNumPPNodes()>o2.getNumPPNodes()){
331+
cmp=1;
332+
} else if(o1.getNumPPNodes()<o2.getNumPPNodes()){
333+
cmp=-1;
334+
} else {
335+
for (int i = 0; i < o1.getNumPPNodes(); i++) {
336+
PPNode n1 = o1.getNode(i);
337+
PPNode n2 = o2.getNode(i);
338+
cmp = n1.compareTo(n2);
339+
if(cmp!=0){
340+
break;
341+
}
342+
}
343+
}
344+
return cmp;
345+
}
346+
};
347+
}
348+
290349
}

src/main/java/com/actelion/research/chem/descriptor/flexophore/MolDistHistViz.java

Lines changed: 59 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,7 @@
4747
import java.io.Serializable;
4848
import java.util.*;
4949

50-
/**
51-
* Class for Flexophore visualization and atom tracking. Information about corresponding atoms is stored in PPNodeViz.
52-
*/
50+
5351
public class MolDistHistViz extends DistHist implements Serializable, IMolDistHist, ICompleteGraph {
5452

5553
private static final long serialVersionUID = 15052013;
@@ -289,7 +287,48 @@ public void copy(MolDistHistViz copy){
289287
copy.arrWeight = new double[this.arrWeight.length];
290288
System.arraycopy(this.arrWeight, 0, copy.arrWeight, 0, this.arrWeight.length);
291289
}
292-
290+
public MolDistHistViz copy(boolean [] nodes){
291+
292+
int n = 0;
293+
for (boolean node : nodes) {
294+
if(node)n++;
295+
}
296+
297+
MolDistHistViz copy = new MolDistHistViz(n);
298+
299+
copy.liPPNodeViz = new ArrayList<PPNodeViz>();
300+
for (int i = 0; i < liPPNodeViz.size(); i++) {
301+
if(nodes[i]) {
302+
copy.liPPNodeViz.add(new PPNodeViz(liPPNodeViz.get(i)));
303+
}
304+
}
305+
306+
int ind1=0;
307+
for (int i = 0; i < liPPNodeViz.size(); i++) {
308+
if(!nodes[i])
309+
continue;
310+
int ind2=ind1+1;
311+
for (int j = i+1; j < liPPNodeViz.size(); j++) {
312+
if(!nodes[j])
313+
continue;
314+
byte [] distHist = getDistHist(i,j);
315+
copy.setDistHist(ind1,ind2,distHist);
316+
ind2++;
317+
}
318+
ind1++;
319+
}
320+
321+
copy.flagsDescribe = flagsDescribe;
322+
if(molecule3D !=null) {
323+
copy.molecule3D = new Molecule3D(molecule3D);
324+
copy.molecule3D.ensureHelperArrays(Molecule.cHelperRings);
325+
}
326+
327+
copy.realize();
328+
329+
return copy;
330+
}
331+
293332
/**
294333
* Recalculates the coordinates off the pharmacophore nodes.
295334
* Has to be called after changing the coordinates for the Molecule3D.
@@ -403,7 +442,10 @@ public void set(Molecule3D ff ){
403442
if(ff!=null)
404443
molecule3D = new Molecule3D(ff);
405444
}
406-
445+
public void setMoleculeNull(){
446+
molecule3D = null;
447+
}
448+
407449
public void setMappingIndex(int index, int info) {
408450
getNode(index).setMappingIndex(info);
409451
}
@@ -454,7 +496,6 @@ public void canonize(){
454496
fin=true;
455497
for (int i = 1; i < liPPNodeViz.size(); i++) {
456498
int cmp = compareNodes(i, i-1);
457-
458499
if(cmp<0){
459500
fin=false;
460501
swapNodes(i, i-1);
@@ -997,18 +1038,20 @@ public String toStringNodesText(){
9971038
public String toStringNodesShort(){
9981039
if(!finalized)
9991040
realize();
1000-
StringBuffer b = new StringBuffer();
1001-
b.append("[");
1002-
for (int i = 0; i < getNumPPNodes(); i++) {
1003-
PPNodeViz ppNodeViz = getNode(i);
1004-
b.append(ppNodeViz.toStringShort());
1005-
if(i<getNumPPNodes()-1){
1006-
b.append(" ");
1007-
} else {
1008-
b.append("]");
1041+
StringBuilder sb = new StringBuilder();
1042+
sb.append("[");
1043+
if(getNumPPNodes()==0){
1044+
sb.append("()");
1045+
} else {
1046+
for (int i = 0; i < getNumPPNodes(); i++) {
1047+
sb.append(getNode(i).toStringShort());
1048+
if(i<getNumPPNodes()-1){
1049+
sb.append(" ");
1050+
}
10091051
}
10101052
}
1011-
return b.toString();
1053+
sb.append("]");
1054+
return sb.toString();
10121055
}
10131056
public String toStringPPNodesText(){
10141057

src/main/java/com/actelion/research/chem/descriptor/flexophore/MolDistHistVizHelper.java

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,4 +105,59 @@ public static void setWeightsFromCategory(MolDistHistViz mdhv, int [] arrWeightC
105105
}
106106
}
107107
}
108+
109+
public static MolDistHistViz mergeDistHists(List<MolDistHistViz> mdhvs){
110+
111+
MolDistHistViz mdhvMerged = null;
112+
113+
if(mdhvs.size()==0) return mdhvMerged;
114+
MolDistHistViz mdhv0 = mdhvs.get(0);
115+
if(mdhvs.size()==1) {
116+
mdhvMerged = new MolDistHistViz(mdhv0);
117+
return mdhvMerged;
118+
}
119+
120+
String strNodes0 = mdhv0.toStringNodesShort();
121+
List<PPNodeViz> nodes = mdhv0.getNodes();
122+
int nNodes = nodes.size();
123+
124+
mdhvMerged = new MolDistHistViz(nodes.size());
125+
for (PPNodeViz node : nodes) {
126+
mdhvMerged.addNode(node);
127+
}
128+
mdhvMerged.set(mdhv0.getMolecule());
129+
130+
for (MolDistHistViz mdhv : mdhvs) {
131+
String strNodes = mdhv.toStringNodesShort();
132+
if(!strNodes0.equals(strNodes)){
133+
throw new RuntimeException("Nodes in Flexophore differ! " + strNodes0 + " vs " + strNodes);
134+
}
135+
}
136+
137+
for (int i = 0; i < nNodes; i++) {
138+
for (int j = i + 1; j < nNodes; j++) {
139+
byte[][] arrDistHist = new byte[mdhvs.size()][];
140+
for (int k = 0; k < mdhvs.size(); k++) {
141+
MolDistHistViz mdh = mdhvs.get(k);
142+
byte[] distHist = mdh.getDistHist(i, j);
143+
arrDistHist[k] = distHist;
144+
}
145+
byte[] distHistMax = new byte[arrDistHist[0].length];
146+
for (int k = 0; k < distHistMax.length; k++) {
147+
byte max = 0;
148+
for (int l = 0; l < mdhvs.size(); l++) {
149+
if (arrDistHist[l][k] > max) {
150+
max = arrDistHist[l][k];
151+
}
152+
}
153+
distHistMax[k] = max;
154+
}
155+
byte[] distHistMaxNormalized = DistHistHelper.normalize(distHistMax);
156+
157+
mdhvMerged.setDistHist(i, j, distHistMaxNormalized);
158+
}
159+
}
160+
mdhvMerged.realize();
161+
return mdhvMerged;
162+
}
108163
}

src/main/java/com/actelion/research/chem/descriptor/flexophore/PPNode.java

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -128,16 +128,10 @@ public void addAtoms(PPNode node){
128128

129129
public int compareTo(PPNode o) {
130130
int cmp=0;
131-
132-
133131
int size1 = getInteractionTypeCount();
134-
135132
int size2 = o.getInteractionTypeCount();
136-
137133
int max1 = getMaximumInteractionType(this);
138-
139134
int max2 = getMaximumInteractionType(o);
140-
141135
if(max1 > max2)
142136
cmp=1;
143137
else if(max1 < max2)
@@ -148,19 +142,17 @@ else if(max1 < max2)
148142
else if(size1 < size2)
149143
cmp=-1;
150144
else {
151-
152145
for (int i = 0; i < size1; i++) {
153-
154-
int id1 = getInteractionType(i);
155-
156-
int id2 = o.getInteractionType(i);
157-
158-
if(id1 > id2){
146+
InterActionTypeFreq iaf1 = getInteraction(i);
147+
InterActionTypeFreq iaf2 = o.getInteraction(i);
148+
int p1 = iaf1.frequency*iaf1.interactionType;
149+
int p2 = iaf2.frequency*iaf2.interactionType;
150+
if(p1 > p2){
159151
cmp=1;
160-
161-
} else if(id1 < id2){
162-
152+
break;
153+
} else if(p1 < p2){
163154
cmp=-1;
155+
break;
164156
}
165157
}
166158
}

0 commit comments

Comments
 (0)