Skip to content

Commit 36dffe0

Browse files
committed
Merge tag 'openchemlib-2024.2.1'
[maven-release-plugin] copy for tag openchemlib-2024.2.1
2 parents e97da62 + b41ac91 commit 36dffe0

27 files changed

+2181
-112
lines changed

pom.xml

+2-2
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>2024.1.3</version>
11+
<version>2024.2.1</version>
1212

1313
<name>OpenChemLib</name>
1414
<description>Open Source Chemistry Library</description>
@@ -209,7 +209,7 @@
209209
<connection>scm:git:[email protected]:Actelion/openchemlib.git</connection>
210210
<developerConnection>scm:git:[email protected]:Actelion/openchemlib.git</developerConnection>
211211
<url>https://github.com/Actelion/openchemlib</url>
212-
<tag>openchemlib-2024.1.3</tag>
212+
<tag>openchemlib-2024.2.1</tag>
213213
</scm>
214214

215215
<distributionManagement>

src/main/java/com/actelion/research/calc/Matrix.java

+15
Original file line numberDiff line numberDiff line change
@@ -2954,6 +2954,21 @@ public double getVarianceCol(int col) {
29542954
return var;
29552955
}
29562956

2957+
public double getVarianceRow(int row) {
2958+
double var = 0;
2959+
2960+
int cols = cols();
2961+
double mean = getMeanRow(row);
2962+
double dSum = 0;
2963+
for (int i = 0; i < cols; i++) {
2964+
dSum += (data[row][i] - mean) * (data[row][i] - mean);
2965+
}
2966+
2967+
var = dSum / (cols - 1.0);
2968+
2969+
return var;
2970+
}
2971+
29572972
public double getVarianceCentered() {
29582973
double var = 0;
29592974

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

+4-3
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import java.io.BufferedWriter;
4343
import java.io.FileWriter;
4444
import java.io.InputStreamReader;
45+
import java.nio.charset.StandardCharsets;
4546
import java.util.TreeMap;
4647
import java.util.TreeSet;
4748

@@ -73,8 +74,8 @@ public AtomTypeList(int mode) {
7374

7475
/**
7576
* Creates a new AtomTypeList from a given file using the given mode.
76-
* If the the filename references a .typ file, then the mode is checked, whether it matches the file's content.
77-
* If the the filename references a compound file, then the molecules are parsed and a new AtomTypeList is created
77+
* If the filename references a .typ file, then the mode is checked, whether it matches the file's content.
78+
* If the filename references a compound file, then the molecules are parsed and a new AtomTypeList is created
7879
* reflecting the all contained atom types.
7980
* @param filename either .typ file or a .dwar or .sdf compound file
8081
* @param mode
@@ -84,7 +85,7 @@ public AtomTypeList(String filename, int mode) throws Exception {
8485
this(mode);
8586

8687
if (filename.endsWith(".typ")) {
87-
BufferedReader theReader = new BufferedReader(new InputStreamReader(this.getClass().getResourceAsStream(filename)));
88+
BufferedReader theReader = new BufferedReader(new InputStreamReader(this.getClass().getResourceAsStream(filename), StandardCharsets.UTF_8));
8889
String version =theReader.readLine();
8990
if (!VERSION_STRING.equals(version)) {
9091
throw new Exception("Outdated atom type list file.");

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import com.actelion.research.io.BOMSkipper;
4848

4949
import java.io.*;
50+
import java.nio.charset.StandardCharsets;
5051
import java.util.TreeMap;
5152

5253
public class MolfileParser
@@ -970,7 +971,7 @@ public boolean parse(StereoMolecule mol, File file)
970971
{
971972
mMol = mol;
972973
try{
973-
BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"));
974+
BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8));
974975
BOMSkipper.skip(reader);
975976
return readMoleculeFromBuffer(reader);
976977
} catch(IOException e){

src/main/java/com/actelion/research/chem/chemicalspaces/ChemicalSpaceCreator.java

+10-30
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,22 @@
11
package com.actelion.research.chem.chemicalspaces;
22

3-
import java.io.BufferedReader;
3+
import com.actelion.research.chem.*;
4+
import com.actelion.research.chem.chemicalspaces.synthon.SynthonCreator;
5+
import com.actelion.research.chem.chemicalspaces.synthon.SynthonReactor;
6+
import com.actelion.research.chem.descriptor.DescriptorHandlerLongFFP512;
7+
import com.actelion.research.chem.io.DWARFileCreator;
8+
import com.actelion.research.chem.reaction.Reaction;
9+
import com.actelion.research.chem.reaction.Reactor;
10+
411
import java.io.BufferedWriter;
512
import java.io.File;
6-
import java.io.FileNotFoundException;
7-
import java.io.FileReader;
813
import java.io.FileWriter;
914
import java.io.IOException;
10-
import java.util.ArrayList;
11-
import java.util.Arrays;
12-
import java.util.Collection;
13-
import java.util.Collections;
14-
import java.util.HashMap;
15-
import java.util.HashSet;
16-
import java.util.List;
17-
import java.util.Map;
18-
import java.util.Random;
19-
import java.util.Set;
15+
import java.util.*;
2016
import java.util.concurrent.ConcurrentHashMap;
2117
import java.util.concurrent.ConcurrentMap;
2218
import java.util.stream.Collectors;
2319

24-
import com.actelion.research.chem.CanonizerUtil;
25-
import com.actelion.research.chem.IDCodeParser;
26-
import com.actelion.research.chem.Molecule;
27-
import com.actelion.research.chem.SSSearcher;
28-
import com.actelion.research.chem.SSSearcherWithIndex;
29-
import com.actelion.research.chem.StereoMolecule;
30-
import com.actelion.research.chem.chemicalspaces.synthon.SynthonCreator;
31-
import com.actelion.research.chem.chemicalspaces.synthon.SynthonReactor;
32-
import com.actelion.research.chem.descriptor.DescriptorHandlerLongFFP512;
33-
import com.actelion.research.chem.io.DWARFileCreator;
34-
import com.actelion.research.chem.io.RXNFileParser;
35-
import com.actelion.research.chem.io.SDFileParser;
36-
import com.actelion.research.chem.reaction.Reaction;
37-
import com.actelion.research.chem.reaction.Reactor;
38-
3920

4021

4122
public class ChemicalSpaceCreator {
@@ -87,7 +68,7 @@ public void create() {
8768
ConcurrentMap<String,String> processedToOrigIDCode = new ConcurrentHashMap<String,String>();
8869
ConcurrentMap<String,List<Map<String,String>>> reactionsWithSynthons = new ConcurrentHashMap<String,List<Map<String,String>>>();
8970
processBuildingBlocks(this.bbs,processedToOrigIDCode,functionalizations);
90-
fps = new ConcurrentHashMap<String,long[]>();
71+
fps = new ConcurrentHashMap<>();
9172
calcFragFPs(processedToOrigIDCode.keySet(),fps);
9273
generateSynthons(reactions, processedToOrigIDCode, reactionsWithSynthons,fps,allSynthonTransformations);
9374
generateCombinatoriaLibraries(reactionsWithSynthons, bbs, allSynthonTransformations);
@@ -179,7 +160,6 @@ private static void processReaction(Reaction rxn, ConcurrentMap<String,String>
179160
reactionsWithSynthons.putIfAbsent(rxn.getName(), new ArrayList<>());
180161

181162
//System.out.println("bbs");
182-
183163

184164
for(int i=0;i<reactants.size();i++) {
185165
List<String> rList = reactants.get(i);

src/main/java/com/actelion/research/chem/chemicalspaces/synthon/SynthonCreator.java

+12-29
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,19 @@
11
package com.actelion.research.chem.chemicalspaces.synthon;
22

3-
import java.io.BufferedWriter;
4-
import java.io.FileWriter;
5-
import java.io.IOException;
6-
import java.io.Writer;
7-
import java.util.ArrayList;
8-
import java.util.Arrays;
9-
import java.util.HashMap;
10-
import java.util.HashSet;
11-
import java.util.List;
12-
import java.util.Map;
13-
import java.util.Set;
14-
153
import com.actelion.research.chem.Molecule;
164
import com.actelion.research.chem.RingCollection;
175
import com.actelion.research.chem.StereoMolecule;
186
import com.actelion.research.chem.coords.CoordinateInventor;
197
import com.actelion.research.chem.io.RXNFileCreator;
208
import com.actelion.research.chem.reaction.Reaction;
219

10+
import java.io.BufferedWriter;
11+
import java.io.FileWriter;
12+
import java.io.Writer;
13+
import java.util.*;
14+
2215
public class SynthonCreator {
23-
24-
16+
2517
/**
2618
* only works for reactions with a single product
2719
* @param rxn
@@ -32,18 +24,15 @@ public static Reaction[] create(Reaction rxn) throws Exception {
3224
if(rxn.getProducts()>1)
3325
throw new Exception("only reactions with one product are supported");
3426
Reaction[] synthonTransformations = new Reaction[rxn.getReactants()];
35-
Map<Integer,Integer> mappedAtomToReactant = new HashMap<Integer,Integer>(); //stores the information on which mapped atom in the product ist contributed by which reactant
27+
Map<Integer,Integer> mappedAtomToReactant = new HashMap<>(); //stores the information on which mapped atom in the product ist contributed by which reactant
3628
for(int r=0;r<rxn.getReactants();r++) {
3729
if(rxn.getReactants()==0)
3830
throw new Exception("cannot create Synthons for reactions with one reactant");
3931
StereoMolecule reactant = rxn.getReactant(r);
4032
for(int a=0;a<reactant.getAtoms();a++) {
4133
int reactantMapNo = reactant.getAtomMapNo(a);
42-
if(reactantMapNo==0)
43-
continue;
44-
else {
34+
if(reactantMapNo!=0)
4535
mappedAtomToReactant.put(reactantMapNo, r);
46-
}
4736
}
4837
}
4938
//find bonds in products that are formed between a) atoms from different reactants or b) between an unmapped and a mapped atom
@@ -58,10 +47,8 @@ public static Reaction[] create(Reaction rxn) throws Exception {
5847
int[] atoms = rc.getRingAtoms(ringNo);
5948
for(int a : atoms) {
6049
int mappedA = product.getAtomMapNo(a);
61-
if(mappedA==0)
62-
continue;
63-
int reactant = mappedAtomToReactant.get(mappedA);
64-
ringReactant.add(reactant);
50+
if(mappedA!=0)
51+
ringReactant.add(mappedAtomToReactant.get(mappedA));
6552
}
6653
if(ringReactant.size()==1) {//homogeneous ring!
6754
int[] ringBonds = rc.getRingBonds(ringNo);
@@ -78,17 +65,13 @@ public static Reaction[] create(Reaction rxn) throws Exception {
7865
int mappedBondAtom1 = product.getAtomMapNo(bondAtom1);
7966
int mappedBondAtom2 = product.getAtomMapNo(bondAtom2);
8067
if(mappedBondAtom1==0) {
81-
if(mappedBondAtom2==0) // both atoms unmapped
82-
continue;
83-
else //bond between a mapped and an unmapped atom
68+
if(mappedBondAtom2!=0) //bond between a mapped and an unmapped atom
8469
bondsToCut.add(b);
85-
8670
}
8771
else if(mappedBondAtom2==0) { //bond between a mapped and an umapped atom
8872
bondsToCut.add(b);
89-
continue;
9073
}
91-
else if(mappedAtomToReactant.get(mappedBondAtom1)!=mappedAtomToReactant.get(mappedBondAtom2)) { //atoms from two different reactants
74+
else if(!mappedAtomToReactant.get(mappedBondAtom1).equals(mappedAtomToReactant.get(mappedBondAtom2))) { //atoms from two different reactants
9275
bondsToCut.add(b);
9376
}
9477
}

src/main/java/com/actelion/research/chem/conf/TorsionDB.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import com.actelion.research.chem.StereoMolecule;
3939

4040
import java.io.*;
41+
import java.nio.charset.StandardCharsets;
4142
import java.util.TreeMap;
4243

4344
public class TorsionDB {
@@ -298,14 +299,14 @@ protected static BufferedReader openReader(String resourceName) throws IOExcepti
298299
InputStream is = TorsionDB.class.getResourceAsStream(cBasePath+DATABASE_CSD+resourceName);
299300
if (is != null) {
300301
sDatabase = DATABASE_CSD;
301-
return new BufferedReader(new InputStreamReader(is));
302+
return new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8));
302303
}
303304

304305
sDatabase = DATABASE_COD;
305306
}
306307

307308
return new BufferedReader(new InputStreamReader(TorsionDB.class.getResourceAsStream(
308-
cBasePath+sDatabase+resourceName)));
309+
cBasePath+sDatabase+resourceName), StandardCharsets.UTF_8));
309310
}
310311

311312
/**

src/main/java/com/actelion/research/chem/conf/torsionstrain/StatisticalTorsionPotential.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import java.io.IOException;
1010
import java.io.InputStream;
1111
import java.io.InputStreamReader;
12+
import java.nio.charset.StandardCharsets;
1213
import java.util.*;
1314
import java.util.concurrent.ConcurrentHashMap;
1415
import java.util.concurrent.atomic.AtomicInteger;
@@ -71,7 +72,7 @@ private StatisticalTorsionPotential() {
7172

7273
private void initialize() {
7374
BufferedReader torsionIDReader = new BufferedReader(new InputStreamReader(TorsionDB.class.getResourceAsStream(
74-
BASE_PATH+database+TORSION_IDS_FILE)));
75+
BASE_PATH+database+TORSION_IDS_FILE), StandardCharsets.UTF_8));
7576

7677
try {
7778
readTorsionIDs(torsionIDReader);

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939

4040
import java.io.BufferedReader;
4141
import java.io.InputStreamReader;
42+
import java.nio.charset.StandardCharsets;
4243
import java.util.BitSet;
4344
import java.util.Enumeration;
4445
import java.util.Hashtable;
@@ -263,7 +264,7 @@ public static void main(String args[])
263264
IDCodeParser p = new IDCodeParser(false);
264265
StereoMolecule m = new StereoMolecule();
265266
BitSet referencebs = null, querybs = null;
266-
BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
267+
BufferedReader r = new BufferedReader(new InputStreamReader(System.in, StandardCharsets.UTF_8));
267268
FingerPrintGenerator fp = null;
268269
try {
269270
if (args.length > 0) {

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

+24
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,30 @@ public static void setDistHistToOne(MolDistHist mdh){
123123
}
124124
}
125125

126+
public static MolDistHist getEmptyMolDistHist(){
127+
PPNode ppNode0 = new PPNode();
128+
ppNode0.realize();
129+
130+
MolDistHist mdhEmpty = new MolDistHist(1);
131+
mdhEmpty.addNode(ppNode0);
132+
mdhEmpty.realize();
133+
134+
return mdhEmpty;
135+
}
136+
public static boolean isEmptyMolDistHist(MolDistHist mdh){
137+
138+
boolean empty = true;
139+
if(mdh.getNumPPNodes()>1){
140+
empty = false;
141+
} else if(mdh.getNumPPNodes()==1){
142+
if(mdh.getNode(0).getInteractionTypeCount()>0){
143+
empty = false;
144+
}
145+
}
146+
147+
return empty;
148+
}
149+
126150
public static MolDistHist getMostDistantPairOfNodes (MolDistHist mdh){
127151

128152
int n = mdh.getNumPPNodes();

src/main/java/com/actelion/research/chem/forcefield/mmff/Csv.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import java.io.FileReader;
3939
import java.io.IOException;
4040
import java.io.InputStreamReader;
41+
import java.nio.charset.StandardCharsets;
4142

4243
/**
4344
* Basic CSV parser. The Csv class provides very basic CSV file parsing
@@ -91,7 +92,7 @@ public static Object[][] readFile(String path) {
9192

9293
try {
9394
String line;
94-
br = new BufferedReader(new InputStreamReader(Csv.class.getResourceAsStream(path)));
95+
br = new BufferedReader(new InputStreamReader(Csv.class.getResourceAsStream(path), StandardCharsets.UTF_8));
9596

9697
int size = Integer.parseInt(br.readLine().trim());
9798
String[] format = br.readLine().trim().split(",");

src/main/java/com/actelion/research/chem/interactionstatistics/InteractionDistanceStatistics.java

+8-14
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,17 @@
11
package com.actelion.research.chem.interactionstatistics;
22

3+
import com.actelion.research.util.FastSpline;
4+
import com.actelion.research.util.SmoothingSplineInterpolator;
5+
6+
import java.io.*;
7+
import java.net.URL;
8+
import java.nio.charset.StandardCharsets;
39
import java.util.*;
410
import java.util.concurrent.ConcurrentHashMap;
511
import java.util.concurrent.atomic.AtomicInteger;
612
import java.util.stream.Collectors;
713
import java.util.stream.IntStream;
814

9-
import com.actelion.research.util.FastSpline;
10-
import com.actelion.research.util.SmoothingSplineInterpolator;
11-
12-
import java.io.BufferedReader;
13-
import java.io.BufferedWriter;
14-
import java.io.FileInputStream;
15-
import java.io.FileWriter;
16-
import java.io.IOException;
17-
import java.io.InputStream;
18-
import java.io.InputStreamReader;
19-
import java.net.URL;
20-
2115
public class InteractionDistanceStatistics {
2216

2317
private static volatile InteractionDistanceStatistics instance = new InteractionDistanceStatistics(); //eager initialization
@@ -194,9 +188,9 @@ public void readFromFile() throws IOException {
194188
}
195189
InputStream is = url.openStream();
196190
//InputStream is = new FileInputStream(file);
197-
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
191+
BufferedReader reader = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8));
198192
String line;
199-
while((line = reader.readLine())!=null && line.length()!=0) {
193+
while((line = reader.readLine())!=null && !line.isEmpty()) {
200194
String s[] = line.split(" ");
201195

202196
long l = Long.parseLong(s[0]);

0 commit comments

Comments
 (0)