Skip to content

Commit 1c3edb1

Browse files
committed
Merge remote-tracking branch 'upstream/master'
2 parents 786df4f + 7b2d4d8 commit 1c3edb1

28 files changed

+504
-464
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.3.1</version>
11+
<version>2024.4.1-SNAPSHOT</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.3.1</tag>
212+
<tag>HEAD</tag>
213213
</scm>
214214

215215
<distributionManagement>

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

+9-1
Original file line numberDiff line numberDiff line change
@@ -1727,6 +1727,8 @@ else if (hydrogens == Molecule.cAtomQFNot3Hydrogen)
17271727
isoStr = append(isoStr, "h<3");
17281728
else if (hydrogens == Molecule.cAtomQFNot2Hydrogen+Molecule.cAtomQFNot3Hydrogen)
17291729
isoStr = append(isoStr, "h<2");
1730+
else if (hydrogens == Molecule.cAtomQFNot0Hydrogen+Molecule.cAtomQFNot3Hydrogen)
1731+
isoStr = append(isoStr, "h1-2");
17301732
}
17311733
if ((queryFeatures & Molecule.cAtomQFCharge) != 0) {
17321734
long charge = (queryFeatures & Molecule.cAtomQFCharge);
@@ -1766,6 +1768,12 @@ else if (neighbours == Molecule.cAtomQFNot0Neighbours+Molecule.cAtomQFNot1Neighb
17661768
isoStr = append(isoStr, "n>2");
17671769
else if (neighbours == (Molecule.cAtomQFNeighbours & ~Molecule.cAtomQFNot4Neighbours))
17681770
isoStr = append(isoStr, "n>3");
1771+
else if (neighbours == (Molecule.cAtomQFNot0Neighbours | Molecule.cAtomQFNot3Neighbours | Molecule.cAtomQFNot4Neighbours))
1772+
isoStr = append(isoStr, "n1-2");
1773+
else if (neighbours == (Molecule.cAtomQFNot0Neighbours | Molecule.cAtomQFNot4Neighbours))
1774+
isoStr = append(isoStr, "n1-3");
1775+
else if (neighbours == (Molecule.cAtomQFNot0Neighbours | Molecule.cAtomQFNot1Neighbour | Molecule.cAtomQFNot4Neighbours))
1776+
isoStr = append(isoStr, "n2-3");
17691777
}
17701778
if ((queryFeatures & Molecule.cAtomQFENeighbours) != 0) {
17711779
long eNegNeighbours = (queryFeatures & Molecule.cAtomQFENeighbours);
@@ -1791,7 +1799,7 @@ else if (eNegNeighbours == (Molecule.cAtomQFNot0ENeighbours | Molecule.cAtomQFNo
17911799
isoStr = append(isoStr, "e>2");
17921800
else if (eNegNeighbours == (Molecule.cAtomQFENeighbours & ~Molecule.cAtomQFNot4ENeighbours))
17931801
isoStr = append(isoStr, "e>3");
1794-
else if (eNegNeighbours == (Molecule.cAtomQFNot0ENeighbours | Molecule.cAtomQFNot3ENeighbours | Molecule.cAtomQFNot3ENeighbours))
1802+
else if (eNegNeighbours == (Molecule.cAtomQFNot0ENeighbours | Molecule.cAtomQFNot3ENeighbours | Molecule.cAtomQFNot4ENeighbours))
17951803
isoStr = append(isoStr, "e1-2");
17961804
else if (eNegNeighbours == (Molecule.cAtomQFNot0ENeighbours | Molecule.cAtomQFNot4ENeighbours))
17971805
isoStr = append(isoStr, "e1-3");

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

+3-6
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,7 @@
3838
import com.actelion.research.chem.io.DWARFileParser;
3939
import com.actelion.research.chem.io.SDFileParser;
4040

41-
import java.io.BufferedReader;
42-
import java.io.BufferedWriter;
43-
import java.io.FileWriter;
44-
import java.io.InputStreamReader;
41+
import java.io.*;
4542
import java.nio.charset.StandardCharsets;
4643
import java.util.TreeMap;
4744
import java.util.TreeSet;
@@ -155,7 +152,7 @@ public synchronized void calculateProbabilities() {
155152

156153
public void writeTypeFile(String filename) {
157154
try {
158-
BufferedWriter writer = new BufferedWriter(new FileWriter(filename));
155+
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(filename), StandardCharsets.UTF_8));
159156
writer.write(VERSION_STRING);
160157
writer.newLine();
161158

@@ -187,7 +184,7 @@ public void writeTypeFile(String filename) {
187184
*/
188185
public void writeTextFile(String textfilename, int mode) {
189186
try {
190-
BufferedWriter writer = new BufferedWriter(new FileWriter(textfilename));
187+
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(textfilename), StandardCharsets.UTF_8));
191188
writer.write("AtomType\tFrequency\t"+AtomTypeCalculator.getHeaderString(mode));
192189
writer.newLine();
193190

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

+18-1
Original file line numberDiff line numberDiff line change
@@ -1665,6 +1665,14 @@ private boolean canCalcTHParity(int atom, int mode) {
16651665
if (mMol.getAtomicNo(atom) == 5 && mMol.getAllConnAtoms(atom) != 4)
16661666
return false;
16671667

1668+
if (mMol.isFragment()) { // don't calculate parities if atom or some neighbours are exclude groups
1669+
if ((mMol.getAtomQueryFeatures(atom) & Molecule.cAtomQFExcludeGroup) != 0)
1670+
return false;
1671+
for (int i=0; i<mMol.getAllConnAtoms(atom); i++)
1672+
if ((mMol.getAtomQueryFeatures(mMol.getConnAtom(atom, i)) & Molecule.cAtomQFExcludeGroup) != 0)
1673+
return false;
1674+
}
1675+
16681676
// don't consider tetrahedral nitrogen, unless found to qualify for parity calculation
16691677
if (mMol.getAtomicNo(atom) == 7
16701678
&& !mNitrogenQualifiesForParity[atom])
@@ -2077,6 +2085,15 @@ private boolean canCalcEZParity(int bond, int mode) {
20772085
if (mEZParity[bond] != 0)
20782086
return false;
20792087

2088+
if (mMol.isFragment()) { // don't calculate parities if some bond atoms or their neighbours are exclude groups
2089+
for (int i=0; i<2; i++) {
2090+
int atom = mMol.getBondAtom(i, bond);
2091+
for (int j=0; j<mMol.getAllConnAtoms(atom); j++)
2092+
if ((mMol.getAtomQueryFeatures(mMol.getConnAtom(atom, j)) & Molecule.cAtomQFExcludeGroup) != 0)
2093+
return false;
2094+
}
2095+
}
2096+
20802097
if (mMol.getBondOrder(bond) == 1)
20812098
return canCalcBINAPParity(bond, mode);
20822099

@@ -3754,7 +3771,7 @@ public int getTHParity(int atom) {
37543771

37553772

37563773
/**
3757-
* Returns the atoms's enhanced stereo representation type.
3774+
* Returns the atom's enhanced stereo representation type.
37583775
* @param atom
37593776
* @return one of the Molecule.cESRTypeXXX constants
37603777
*/

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

+9-14
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ public int[] copyMoleculeByBonds(ExtendedMolecule destMol, boolean[] includeBond
209209
destMol.mAllAtoms = 0;
210210
for (int atom=0; atom<mAllAtoms;atom++) {
211211
atomMap[atom] = -1;
212-
for (int i=0; i< mConnAtoms[atom]; i++) {
212+
for (int i=0; i<mConnAtoms[atom]; i++) {
213213
if (includeBond[mConnBond[atom][i]]) {
214214
atomMap[atom] = copyAtom(destMol, atom, 0, 0);
215215

@@ -291,35 +291,30 @@ && isAtomStereoCenter(atom)) {
291291
int lostStereoBond = -1;
292292
int lostAtom = -1;
293293
for (int i=0; i<mAllConnAtoms[atom]; i++) {
294-
//if (mConnAtom.length>=atom || atomMap.length>=mConnAtom[atom][i])
295-
// System.out.println("mConnAtom.length:"+mConnAtom.length+" atom:"+atom+" atomMap.length:"+atomMap.length+" i:"+i+" mConnAtom[atom][i]:"+mConnAtom[atom][i]+" mAtoms:"+mAtoms+" mAllAtoms:"+mAllAtoms);
296-
if (atomMap.length>mConnAtom[atom][i]
297-
&& atomMap[mConnAtom[atom][i]] != -1)
294+
if (bondMap[mConnBond[atom][i]] != -1)
298295
remainingNeighbours++;
299296
else if (mConnBondOrder[atom][i] == 1
300-
&& isStereoBond(mConnBond[atom][i])
301-
&& mBondAtom[0][mConnBond[atom][i]] == atom) {
297+
&& isStereoBond(mConnBond[atom][i])
298+
&& mBondAtom[0][mConnBond[atom][i]] == atom) {
302299
lostStereoBond = mConnBond[atom][i];
303300
lostAtom = mConnAtom[atom][i];
301+
}
304302
}
305-
}
306-
if (lostStereoBond != -1
307-
&& remainingNeighbours >= 3) {
303+
if (lostStereoBond != -1 && remainingNeighbours >= 3) {
308304
double angle = getBondAngle(atom, lostAtom);
309305
double minAngleDif = 10.0;
310306
int minConnBond = -1;
311307
for (int i=0; i<mAllConnAtoms[atom]; i++) {
312308
if (mConnBondOrder[atom][i] == 1
313-
&& (!isStereoBond(mConnBond[atom][i]) || mBondAtom[0][mConnBond[atom][i]] == atom)
314-
&& atomMap.length>mConnAtom[atom][i]
315-
&& atomMap[mConnAtom[atom][i]] != -1) {
309+
&& (!isStereoBond(mConnBond[atom][i]) || mBondAtom[0][mConnBond[atom][i]] == atom)
310+
&& bondMap[mConnBond[atom][i]] != -1) {
316311
double angleDif = Math.abs(getAngleDif(angle, getBondAngle(atom, mConnAtom[atom][i])));
317312
if (minAngleDif > angleDif) {
318313
minAngleDif = angleDif;
319314
minConnBond = mConnBond[atom][i];
315+
}
320316
}
321317
}
322-
}
323318
if (minConnBond != -1) {
324319
int destBond = bondMap[minConnBond];
325320
destMol.setBondType(destBond, mBondType[minConnBond] == cBondTypeUp ? cBondTypeDown : cBondTypeUp);

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

+29
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,35 @@ public class ExtendedMoleculeFunctions {
9393
public static final String [] arrRGroupsSymbol = {"R1","R2","R3","R4","R5","R6","R7","R8","R9","R10","R11","R12","R13","R14","R15","R16"};
9494

9595

96+
public final static Coordinates getCenterGravity(ExtendedMolecule mol) {
97+
98+
int n = mol.getAllAtoms();
99+
100+
int [] indices = new int [n];
101+
102+
for (int i = 0; i < indices.length; i++) {
103+
indices[i]=i;
104+
}
105+
106+
return getCenterGravity(mol, indices);
107+
}
108+
109+
public final static Coordinates getCenterGravity(ExtendedMolecule mol, int[] indices) {
110+
111+
Coordinates c = new Coordinates();
112+
for (int i = 0; i < indices.length; i++) {
113+
c.x += mol.getAtomX(indices[i]);
114+
c.y += mol.getAtomY(indices[i]);
115+
c.z += mol.getAtomZ(indices[i]);
116+
}
117+
c.x /= indices.length;
118+
c.y /= indices.length;
119+
c.z /= indices.length;
120+
121+
return c;
122+
}
123+
124+
96125
public static void makeSkeleton(StereoMolecule mol) {
97126
for (int bond=0; bond<mol.getAllBonds(); bond++)
98127
mol.setBondType(bond, Molecule.cBondTypeSingle);

0 commit comments

Comments
 (0)