Skip to content

Commit

Permalink
Merge tag 'openchemlib-2024.2.1'
Browse files Browse the repository at this point in the history
[maven-release-plugin]  copy for tag openchemlib-2024.2.1
  • Loading branch information
targos committed Feb 9, 2024
2 parents e97da62 + b41ac91 commit 36dffe0
Show file tree
Hide file tree
Showing 27 changed files with 2,181 additions and 112 deletions.
4 changes: 2 additions & 2 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.1.3</version>
<version>2024.2.1</version>

<name>OpenChemLib</name>
<description>Open Source Chemistry Library</description>
Expand Down Expand Up @@ -209,7 +209,7 @@
<connection>scm:git:[email protected]:Actelion/openchemlib.git</connection>
<developerConnection>scm:git:[email protected]:Actelion/openchemlib.git</developerConnection>
<url>https://github.com/Actelion/openchemlib</url>
<tag>openchemlib-2024.1.3</tag>
<tag>openchemlib-2024.2.1</tag>
</scm>

<distributionManagement>
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/com/actelion/research/calc/Matrix.java
Original file line number Diff line number Diff line change
Expand Up @@ -2954,6 +2954,21 @@ public double getVarianceCol(int col) {
return var;
}

public double getVarianceRow(int row) {
double var = 0;

int cols = cols();
double mean = getMeanRow(row);
double dSum = 0;
for (int i = 0; i < cols; i++) {
dSum += (data[row][i] - mean) * (data[row][i] - mean);
}

var = dSum / (cols - 1.0);

return var;
}

public double getVarianceCentered() {
double var = 0;

Expand Down
7 changes: 4 additions & 3 deletions src/main/java/com/actelion/research/chem/AtomTypeList.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.TreeMap;
import java.util.TreeSet;

Expand Down Expand Up @@ -73,8 +74,8 @@ public AtomTypeList(int mode) {

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

if (filename.endsWith(".typ")) {
BufferedReader theReader = new BufferedReader(new InputStreamReader(this.getClass().getResourceAsStream(filename)));
BufferedReader theReader = new BufferedReader(new InputStreamReader(this.getClass().getResourceAsStream(filename), StandardCharsets.UTF_8));
String version =theReader.readLine();
if (!VERSION_STRING.equals(version)) {
throw new Exception("Outdated atom type list file.");
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/actelion/research/chem/MolfileParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import com.actelion.research.io.BOMSkipper;

import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.TreeMap;

public class MolfileParser
Expand Down Expand Up @@ -970,7 +971,7 @@ public boolean parse(StereoMolecule mol, File file)
{
mMol = mol;
try{
BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"));
BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8));
BOMSkipper.skip(reader);
return readMoleculeFromBuffer(reader);
} catch(IOException e){
Expand Down
Original file line number Diff line number Diff line change
@@ -1,41 +1,22 @@
package com.actelion.research.chem.chemicalspaces;

import java.io.BufferedReader;
import com.actelion.research.chem.*;
import com.actelion.research.chem.chemicalspaces.synthon.SynthonCreator;
import com.actelion.research.chem.chemicalspaces.synthon.SynthonReactor;
import com.actelion.research.chem.descriptor.DescriptorHandlerLongFFP512;
import com.actelion.research.chem.io.DWARFileCreator;
import com.actelion.research.chem.reaction.Reaction;
import com.actelion.research.chem.reaction.Reactor;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.Set;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.stream.Collectors;

import com.actelion.research.chem.CanonizerUtil;
import com.actelion.research.chem.IDCodeParser;
import com.actelion.research.chem.Molecule;
import com.actelion.research.chem.SSSearcher;
import com.actelion.research.chem.SSSearcherWithIndex;
import com.actelion.research.chem.StereoMolecule;
import com.actelion.research.chem.chemicalspaces.synthon.SynthonCreator;
import com.actelion.research.chem.chemicalspaces.synthon.SynthonReactor;
import com.actelion.research.chem.descriptor.DescriptorHandlerLongFFP512;
import com.actelion.research.chem.io.DWARFileCreator;
import com.actelion.research.chem.io.RXNFileParser;
import com.actelion.research.chem.io.SDFileParser;
import com.actelion.research.chem.reaction.Reaction;
import com.actelion.research.chem.reaction.Reactor;



public class ChemicalSpaceCreator {
Expand Down Expand Up @@ -87,7 +68,7 @@ public void create() {
ConcurrentMap<String,String> processedToOrigIDCode = new ConcurrentHashMap<String,String>();
ConcurrentMap<String,List<Map<String,String>>> reactionsWithSynthons = new ConcurrentHashMap<String,List<Map<String,String>>>();
processBuildingBlocks(this.bbs,processedToOrigIDCode,functionalizations);
fps = new ConcurrentHashMap<String,long[]>();
fps = new ConcurrentHashMap<>();
calcFragFPs(processedToOrigIDCode.keySet(),fps);
generateSynthons(reactions, processedToOrigIDCode, reactionsWithSynthons,fps,allSynthonTransformations);
generateCombinatoriaLibraries(reactionsWithSynthons, bbs, allSynthonTransformations);
Expand Down Expand Up @@ -179,7 +160,6 @@ private static void processReaction(Reaction rxn, ConcurrentMap<String,String>
reactionsWithSynthons.putIfAbsent(rxn.getName(), new ArrayList<>());

//System.out.println("bbs");


for(int i=0;i<reactants.size();i++) {
List<String> rList = reactants.get(i);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,19 @@
package com.actelion.research.chem.chemicalspaces.synthon;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import com.actelion.research.chem.Molecule;
import com.actelion.research.chem.RingCollection;
import com.actelion.research.chem.StereoMolecule;
import com.actelion.research.chem.coords.CoordinateInventor;
import com.actelion.research.chem.io.RXNFileCreator;
import com.actelion.research.chem.reaction.Reaction;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.Writer;
import java.util.*;

public class SynthonCreator {



/**
* only works for reactions with a single product
* @param rxn
Expand All @@ -32,18 +24,15 @@ public static Reaction[] create(Reaction rxn) throws Exception {
if(rxn.getProducts()>1)
throw new Exception("only reactions with one product are supported");
Reaction[] synthonTransformations = new Reaction[rxn.getReactants()];
Map<Integer,Integer> mappedAtomToReactant = new HashMap<Integer,Integer>(); //stores the information on which mapped atom in the product ist contributed by which reactant
Map<Integer,Integer> mappedAtomToReactant = new HashMap<>(); //stores the information on which mapped atom in the product ist contributed by which reactant
for(int r=0;r<rxn.getReactants();r++) {
if(rxn.getReactants()==0)
throw new Exception("cannot create Synthons for reactions with one reactant");
StereoMolecule reactant = rxn.getReactant(r);
for(int a=0;a<reactant.getAtoms();a++) {
int reactantMapNo = reactant.getAtomMapNo(a);
if(reactantMapNo==0)
continue;
else {
if(reactantMapNo!=0)
mappedAtomToReactant.put(reactantMapNo, r);
}
}
}
//find bonds in products that are formed between a) atoms from different reactants or b) between an unmapped and a mapped atom
Expand All @@ -58,10 +47,8 @@ public static Reaction[] create(Reaction rxn) throws Exception {
int[] atoms = rc.getRingAtoms(ringNo);
for(int a : atoms) {
int mappedA = product.getAtomMapNo(a);
if(mappedA==0)
continue;
int reactant = mappedAtomToReactant.get(mappedA);
ringReactant.add(reactant);
if(mappedA!=0)
ringReactant.add(mappedAtomToReactant.get(mappedA));
}
if(ringReactant.size()==1) {//homogeneous ring!
int[] ringBonds = rc.getRingBonds(ringNo);
Expand All @@ -78,17 +65,13 @@ public static Reaction[] create(Reaction rxn) throws Exception {
int mappedBondAtom1 = product.getAtomMapNo(bondAtom1);
int mappedBondAtom2 = product.getAtomMapNo(bondAtom2);
if(mappedBondAtom1==0) {
if(mappedBondAtom2==0) // both atoms unmapped
continue;
else //bond between a mapped and an unmapped atom
if(mappedBondAtom2!=0) //bond between a mapped and an unmapped atom
bondsToCut.add(b);

}
else if(mappedBondAtom2==0) { //bond between a mapped and an umapped atom
bondsToCut.add(b);
continue;
}
else if(mappedAtomToReactant.get(mappedBondAtom1)!=mappedAtomToReactant.get(mappedBondAtom2)) { //atoms from two different reactants
else if(!mappedAtomToReactant.get(mappedBondAtom1).equals(mappedAtomToReactant.get(mappedBondAtom2))) { //atoms from two different reactants
bondsToCut.add(b);
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/com/actelion/research/chem/conf/TorsionDB.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import com.actelion.research.chem.StereoMolecule;

import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.TreeMap;

public class TorsionDB {
Expand Down Expand Up @@ -298,14 +299,14 @@ protected static BufferedReader openReader(String resourceName) throws IOExcepti
InputStream is = TorsionDB.class.getResourceAsStream(cBasePath+DATABASE_CSD+resourceName);
if (is != null) {
sDatabase = DATABASE_CSD;
return new BufferedReader(new InputStreamReader(is));
return new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8));
}

sDatabase = DATABASE_COD;
}

return new BufferedReader(new InputStreamReader(TorsionDB.class.getResourceAsStream(
cBasePath+sDatabase+resourceName)));
cBasePath+sDatabase+resourceName), StandardCharsets.UTF_8));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;
Expand Down Expand Up @@ -71,7 +72,7 @@ private StatisticalTorsionPotential() {

private void initialize() {
BufferedReader torsionIDReader = new BufferedReader(new InputStreamReader(TorsionDB.class.getResourceAsStream(
BASE_PATH+database+TORSION_IDS_FILE)));
BASE_PATH+database+TORSION_IDS_FILE), StandardCharsets.UTF_8));

try {
readTorsionIDs(torsionIDReader);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.BitSet;
import java.util.Enumeration;
import java.util.Hashtable;
Expand Down Expand Up @@ -263,7 +264,7 @@ public static void main(String args[])
IDCodeParser p = new IDCodeParser(false);
StereoMolecule m = new StereoMolecule();
BitSet referencebs = null, querybs = null;
BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
BufferedReader r = new BufferedReader(new InputStreamReader(System.in, StandardCharsets.UTF_8));
FingerPrintGenerator fp = null;
try {
if (args.length > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,30 @@ public static void setDistHistToOne(MolDistHist mdh){
}
}

public static MolDistHist getEmptyMolDistHist(){
PPNode ppNode0 = new PPNode();
ppNode0.realize();

MolDistHist mdhEmpty = new MolDistHist(1);
mdhEmpty.addNode(ppNode0);
mdhEmpty.realize();

return mdhEmpty;
}
public static boolean isEmptyMolDistHist(MolDistHist mdh){

boolean empty = true;
if(mdh.getNumPPNodes()>1){
empty = false;
} else if(mdh.getNumPPNodes()==1){
if(mdh.getNode(0).getInteractionTypeCount()>0){
empty = false;
}
}

return empty;
}

public static MolDistHist getMostDistantPairOfNodes (MolDistHist mdh){

int n = mdh.getNumPPNodes();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;

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

try {
String line;
br = new BufferedReader(new InputStreamReader(Csv.class.getResourceAsStream(path)));
br = new BufferedReader(new InputStreamReader(Csv.class.getResourceAsStream(path), StandardCharsets.UTF_8));

int size = Integer.parseInt(br.readLine().trim());
String[] format = br.readLine().trim().split(",");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,17 @@
package com.actelion.research.chem.interactionstatistics;

import com.actelion.research.util.FastSpline;
import com.actelion.research.util.SmoothingSplineInterpolator;

import java.io.*;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

import com.actelion.research.util.FastSpline;
import com.actelion.research.util.SmoothingSplineInterpolator;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;

public class InteractionDistanceStatistics {

private static volatile InteractionDistanceStatistics instance = new InteractionDistanceStatistics(); //eager initialization
Expand Down Expand Up @@ -194,9 +188,9 @@ public void readFromFile() throws IOException {
}
InputStream is = url.openStream();
//InputStream is = new FileInputStream(file);
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
BufferedReader reader = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8));
String line;
while((line = reader.readLine())!=null && line.length()!=0) {
while((line = reader.readLine())!=null && !line.isEmpty()) {
String s[] = line.split(" ");

long l = Long.parseLong(s[0]);
Expand Down
Loading

0 comments on commit 36dffe0

Please sign in to comment.