Skip to content

Commit

Permalink
Merge tag 'openchemlib-2024.10.0'
Browse files Browse the repository at this point in the history
[maven-release-plugin]  copy for tag openchemlib-2024.10.0
  • Loading branch information
targos committed Oct 7, 2024
2 parents 17d264c + 816e25e commit 9a3b202
Show file tree
Hide file tree
Showing 47 changed files with 1,332 additions and 302 deletions.
2 changes: 1 addition & 1 deletion buildOpenChemLib
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ rm -rf ./build
mkdir build
cp -r ./src/main/resources/* ./build/
find . -name "*.java" > sources.txt
javac -target 8 -d ./build @sources.txt
javac -target 8 -source 8 -d ./build @sources.txt
rm sources.txt
jar -cf build/OpenChemLib.jar -C ./build .
ls -al build/OpenChemLib.jar
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.7.3-SNAPSHOT</version>
<version>2024.10.0</version>

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

<distributionManagement>
Expand Down
17 changes: 13 additions & 4 deletions src/main/java/com/actelion/research/calc/ArrayUtilsCalc.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,12 @@ public class ArrayUtilsCalc {

public final static int [] cat(int [] a, int [] b) {
int [] c = new int [a.length + b.length];

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

for (int i = 0; i < b.length; i++) {
c[a.length+i]=b[i];
}

return c;
}

Expand All @@ -80,6 +77,16 @@ public final static boolean contains(int [] a, int b) {
}
return bFound;
}
public final static boolean containsAll(int [] a, int [] b) {
boolean bFound = true;
for (int i = 0; i < b.length; i++) {
if(!contains(a, b[i])){
bFound=false;
break;
}
}
return bFound;
}

public final static int [] copy(int [] a) {
int [] b = new int [a.length];
Expand Down Expand Up @@ -195,6 +202,8 @@ public final static boolean findIdentical(int [] a, int [] b) {

return bFound;
}


public static final double getCorrPearson(List<PointDouble> li) {

final double [] a = new double [li.size()];
Expand All @@ -206,7 +215,7 @@ public static final double getCorrPearson(List<PointDouble> li) {

return getCorrPearson(a, b);
}

public static final double getCorrPearson(Matrix A, Matrix B) {


Expand Down
19 changes: 8 additions & 11 deletions src/main/java/com/actelion/research/calc/Matrix.java
Original file line number Diff line number Diff line change
Expand Up @@ -2047,7 +2047,7 @@ public boolean areRowsEqual(int row1, int row2) {
public boolean equal(Matrix ma) {
boolean bEQ = true;

if(equalDimension(ma) == true) {
if(equalDimension(ma)) {
for (int i = 0; i < getRowDim(); i++) {
for (int j = 0; j < getColDim(); j++) {
if(data[i][j] != ma.data[i][j]) {
Expand All @@ -2066,7 +2066,7 @@ public boolean equal(Matrix ma) {
public boolean equal(Matrix ma, double dLimit) {
boolean bEQ = true;

if(equalDimension(ma) == true) {
if(equalDimension(ma)) {
for (int i = 0; i < getRowDim(); i++) {
for (int j = 0; j < getColDim(); j++) {
double dDiff = Math.abs(data[i][j] - ma.data[i][j]);
Expand Down Expand Up @@ -2305,7 +2305,7 @@ final public Matrix multiply(boolean transA, boolean transB, Matrix ma) {
//

// C = A * B
if ( (transA == false) && (transB == false)) {
if (!transA && !transB) {

int n = cols();

Expand Down Expand Up @@ -2364,7 +2364,7 @@ final public Matrix multiply(boolean transA, boolean transB, Matrix ma) {
// C = A' * B
//
// Matrix A is transposed
if ( (transA == true) && (transB == false)) {
if (transA && !transB) {

// Reverse n
int n = rows();
Expand Down Expand Up @@ -2429,7 +2429,7 @@ final public Matrix multiply(boolean transA, boolean transB, Matrix ma) {
// C = A * B'
//
// Matrix B is transposed
if ( (transA == false) && (transB == true)) {
if (!transA && transB) {
int n = cols();

int m = rows();
Expand Down Expand Up @@ -2483,7 +2483,7 @@ final public Matrix multiply(boolean transA, boolean transB, Matrix ma) {
// C = A' * B'
//
// Matrix A + B are transposed
if ( (transA == true) && (transB == true)) {
if (transA && transB) {

// Reverse n
int n = rows();
Expand Down Expand Up @@ -2792,7 +2792,7 @@ public void resize(int rowsNew, int colsNew) {
public List<Double> getRowAsList(int row) {
List<Double> list = new ArrayList<Double>();
for (int ii = 0; ii < data[0].length; ii++) {
list.add(new Double(data[row][ii]));
list.add(data[row][ii]);
}
return list;
}
Expand Down Expand Up @@ -3878,9 +3878,6 @@ public String toStringWithRowTags(List<String> liRowTags, DecimalFormat nf, Stri
return sbAll.toString();
}




public void writeSerialized(File fiOut) throws IOException {
FileOutputStream fos = new FileOutputStream(fiOut);
ObjectOutputStream oos = new ObjectOutputStream(fos);
Expand Down Expand Up @@ -3934,7 +3931,7 @@ public void write(String sFile, boolean bApppend, int digits, int totalWidth) {
BufferedWriter writer = new BufferedWriter(new FileWriter(new File(
sFile), bApppend));

StringBuffer sVal = new StringBuffer();
StringBuffer sVal;
for (int ii = 0; ii < data.length; ii++) {
sVal = new StringBuffer();
for (int jj = 0; jj < data[0].length; jj++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
package com.actelion.research.calc.combinatorics;

import com.actelion.research.util.ListUtils;
import com.actelion.research.util.StringFunctions;

import java.math.BigInteger;
import java.util.ArrayList;
Expand Down Expand Up @@ -312,7 +313,7 @@ public static BigInteger getBinomialCoefficient(int n, int k){
}

public static void main(String[] args) {
examplePermutations();
exampleGetAllOutOf2();

}
public static void examplePermutations() {
Expand Down Expand Up @@ -355,6 +356,27 @@ public static void exampleCombinations() {
}
}

public static void exampleGetAllOutOf() {

int object = 4;
int sampleSize = 3;
List<int[]> liComb = getAllOutOf(object, sampleSize);
for(int [] a : liComb) {
System.out.println(StringFunctions.toString(a, ","));
}
}
public static void exampleGetAllOutOf2() {

int object = 4;
for (int sampleSize = 1; sampleSize < object; sampleSize++) {
List<int[]> liComb = getAllOutOf(object, sampleSize);
for(int [] a : liComb) {
System.out.println(StringFunctions.toString(a, ","));
}
}

}




Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.text.NumberFormat;
import java.util.Collection;
import java.util.Locale;
import java.util.Random;

Expand Down Expand Up @@ -83,6 +84,15 @@ public Histogram(double [] arrRaw, double min, double max, int bins) {
initialize(arrRaw,min,max,bins);
}

public Histogram(Collection<Double> values, double min, double max, int bins) {
double [] v = new double[values.size()];
int c=0;
for (Double value : values) {
v[c++]=value;
}
initialize(v,min,max,bins);
}

public Histogram(double [] arrRaw, int bins) {

double max = -Double.MAX_VALUE;
Expand All @@ -96,7 +106,6 @@ public Histogram(double [] arrRaw, int bins) {
min=v;
}
}

initialize(arrRaw,min,max,bins);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@

package com.actelion.research.calc.statistics.median;

import com.actelion.research.util.ArrayUtils;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

Expand Down Expand Up @@ -212,23 +216,18 @@ public static double getPercentileFromSortedLong(List<Long> liScore, double frac
* @return
*/
public static ModelMedianInteger getMedianForInteger(List<Integer> liScore) {

Collections.sort(liScore);

ModelMedianInteger modelMedian = new ModelMedianInteger();

modelMedian.lowerQuartile = (int)(MedianStatisticFunctions.getPercentileFromSortedInt(liScore, 0.25) + 0.5);

modelMedian.median = (int)(MedianStatisticFunctions.getPercentileFromSortedInt(liScore, 0.5) + 0.5);

modelMedian.upperQuartile = (int)(MedianStatisticFunctions.getPercentileFromSortedInt(liScore, 0.75) + 0.5);

modelMedian.size = liScore.size();

return modelMedian;

}

public static ModelMedianInteger getMedianForInteger(int [] a) {
return getMedianForInteger(ArrayUtils.toList(a));
}

public static ModelMedianLong getMedianForLong(List<Long> liScore) {

Collections.sort(liScore);
Expand All @@ -249,11 +248,16 @@ public static ModelMedianLong getMedianForLong(List<Long> liScore) {

/**
*
* @param liScore the list is sorted in the method.
* @param
* @return
*/
public static ModelMedianDouble getMedianForDouble(List<Double> liScore) {

public static ModelMedianDouble getMedianForDouble(Collection<Double> liScoreRaw) {

if(liScoreRaw.size()<1)
return null;

List<Double> liScore = new ArrayList<>(liScoreRaw);

Collections.sort(liScore);

ModelMedianDouble modelMedian = new ModelMedianDouble();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,13 @@ public boolean locateDelocalizedDoubleBonds(boolean[] isAromaticBond, boolean ma
}
}

if (!bondsPromoted) {

if (bondsPromoted) {
promoteObviousBonds();
continue;
}

if (!bondsPromoted) {
// find and promote one aromatic bond
// (should never happen, but to prevent an endless loop nonetheless)
for (int bond=0; bond<mMol.getBonds(); bond++) {
Expand Down
43 changes: 37 additions & 6 deletions src/main/java/com/actelion/research/chem/AtomFunctionAnalyzer.java
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,12 @@ public static boolean hasUnbalancedAtomCharge(StereoMolecule mol, int atom) {
}

public static boolean isAcidicOxygen(StereoMolecule mol, int atom) {
return isAcidicOxygen(mol, atom, true);
}

public static boolean isAcidicOxygen(StereoMolecule mol, int atom, boolean considerCharge) {
if (mol.getAtomicNo(atom) != 8
|| mol.getAtomCharge(atom) != 0
|| (considerCharge && mol.getAtomCharge(atom) != 0)
|| mol.getConnAtoms(atom) != 1
|| mol.getConnBondOrder(atom, 0) != 1)
return false;
Expand Down Expand Up @@ -246,13 +250,18 @@ public static boolean isAcidicOxygen(StereoMolecule mol, int atom) {

if(nDoubleBondedO2S == 2)
return true;
} else if(isAcidicOxygenAtPhosphoricAcid(mol, atom)) // CP=O(OH)(OH)

} else if(isAcidicOxygenAtPhosphoricAcid(mol, atom, considerCharge)) // CP=O(OH)(OH)
return true;

return false;
}

public static boolean isAcidicOxygenAtPhosphoricAcid(StereoMolecule mol, int atom) {
return isAcidicOxygenAtPhosphoricAcid(mol, atom, true);
}

public static boolean isAcidicOxygenAtPhosphoricAcid(StereoMolecule mol, int atom, boolean considerCharge) {
if (mol.getAtomicNo(atom) != 8)
return false;

Expand Down Expand Up @@ -351,11 +360,15 @@ public static boolean isNitroGroupN(StereoMolecule mol, int atom) {
return nitro;
}




public static boolean isBasicNitrogen(StereoMolecule mol, int atom) {
return isBasicNitrogen(mol, atom, true);
}


public static boolean isBasicNitrogen(StereoMolecule mol, int atom, boolean considerCharge) {
if (mol.getAtomicNo(atom) != 7
|| mol.getAtomCharge(atom) != 0
|| (considerCharge && mol.getAtomCharge(atom) != 0)
|| (mol.getConnAtoms(atom) + mol.getAtomPi(atom) > 3))
return false;

Expand Down Expand Up @@ -552,5 +565,23 @@ && getFakeOxoCount(mol, mol.getConnAtom(conn, j)) != 0)
}
}
return false;
}

public static boolean isAmphiphilic(StereoMolecule mol) {
boolean amphiphilic=true;

boolean acidic=false;
boolean basic=false;
for (int at = 0; at < mol.getAtoms(); at++) {
if(isAcidicOxygen(mol, at)){
acidic=true;
}
if(isBasicNitrogen(mol, at)){
basic=true;
}
}

amphiphilic = basic && acidic;
return amphiphilic;
}
}
Loading

0 comments on commit 9a3b202

Please sign in to comment.