Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
targos committed Apr 10, 2024
2 parents 786df4f + 7b2d4d8 commit 1c3edb1
Show file tree
Hide file tree
Showing 28 changed files with 504 additions and 464 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.3.1</version>
<version>2024.4.1-SNAPSHOT</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.3.1</tag>
<tag>HEAD</tag>
</scm>

<distributionManagement>
Expand Down
10 changes: 9 additions & 1 deletion src/main/java/com/actelion/research/chem/AbstractDepictor.java
Original file line number Diff line number Diff line change
Expand Up @@ -1727,6 +1727,8 @@ else if (hydrogens == Molecule.cAtomQFNot3Hydrogen)
isoStr = append(isoStr, "h<3");
else if (hydrogens == Molecule.cAtomQFNot2Hydrogen+Molecule.cAtomQFNot3Hydrogen)
isoStr = append(isoStr, "h<2");
else if (hydrogens == Molecule.cAtomQFNot0Hydrogen+Molecule.cAtomQFNot3Hydrogen)
isoStr = append(isoStr, "h1-2");
}
if ((queryFeatures & Molecule.cAtomQFCharge) != 0) {
long charge = (queryFeatures & Molecule.cAtomQFCharge);
Expand Down Expand Up @@ -1766,6 +1768,12 @@ else if (neighbours == Molecule.cAtomQFNot0Neighbours+Molecule.cAtomQFNot1Neighb
isoStr = append(isoStr, "n>2");
else if (neighbours == (Molecule.cAtomQFNeighbours & ~Molecule.cAtomQFNot4Neighbours))
isoStr = append(isoStr, "n>3");
else if (neighbours == (Molecule.cAtomQFNot0Neighbours | Molecule.cAtomQFNot3Neighbours | Molecule.cAtomQFNot4Neighbours))
isoStr = append(isoStr, "n1-2");
else if (neighbours == (Molecule.cAtomQFNot0Neighbours | Molecule.cAtomQFNot4Neighbours))
isoStr = append(isoStr, "n1-3");
else if (neighbours == (Molecule.cAtomQFNot0Neighbours | Molecule.cAtomQFNot1Neighbour | Molecule.cAtomQFNot4Neighbours))
isoStr = append(isoStr, "n2-3");
}
if ((queryFeatures & Molecule.cAtomQFENeighbours) != 0) {
long eNegNeighbours = (queryFeatures & Molecule.cAtomQFENeighbours);
Expand All @@ -1791,7 +1799,7 @@ else if (eNegNeighbours == (Molecule.cAtomQFNot0ENeighbours | Molecule.cAtomQFNo
isoStr = append(isoStr, "e>2");
else if (eNegNeighbours == (Molecule.cAtomQFENeighbours & ~Molecule.cAtomQFNot4ENeighbours))
isoStr = append(isoStr, "e>3");
else if (eNegNeighbours == (Molecule.cAtomQFNot0ENeighbours | Molecule.cAtomQFNot3ENeighbours | Molecule.cAtomQFNot3ENeighbours))
else if (eNegNeighbours == (Molecule.cAtomQFNot0ENeighbours | Molecule.cAtomQFNot3ENeighbours | Molecule.cAtomQFNot4ENeighbours))
isoStr = append(isoStr, "e1-2");
else if (eNegNeighbours == (Molecule.cAtomQFNot0ENeighbours | Molecule.cAtomQFNot4ENeighbours))
isoStr = append(isoStr, "e1-3");
Expand Down
9 changes: 3 additions & 6 deletions src/main/java/com/actelion/research/chem/AtomTypeList.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,7 @@
import com.actelion.research.chem.io.DWARFileParser;
import com.actelion.research.chem.io.SDFileParser;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.InputStreamReader;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.TreeMap;
import java.util.TreeSet;
Expand Down Expand Up @@ -155,7 +152,7 @@ public synchronized void calculateProbabilities() {

public void writeTypeFile(String filename) {
try {
BufferedWriter writer = new BufferedWriter(new FileWriter(filename));
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(filename), StandardCharsets.UTF_8));
writer.write(VERSION_STRING);
writer.newLine();

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

Expand Down
19 changes: 18 additions & 1 deletion src/main/java/com/actelion/research/chem/Canonizer.java
Original file line number Diff line number Diff line change
Expand Up @@ -1665,6 +1665,14 @@ private boolean canCalcTHParity(int atom, int mode) {
if (mMol.getAtomicNo(atom) == 5 && mMol.getAllConnAtoms(atom) != 4)
return false;

if (mMol.isFragment()) { // don't calculate parities if atom or some neighbours are exclude groups
if ((mMol.getAtomQueryFeatures(atom) & Molecule.cAtomQFExcludeGroup) != 0)
return false;
for (int i=0; i<mMol.getAllConnAtoms(atom); i++)
if ((mMol.getAtomQueryFeatures(mMol.getConnAtom(atom, i)) & Molecule.cAtomQFExcludeGroup) != 0)
return false;
}

// don't consider tetrahedral nitrogen, unless found to qualify for parity calculation
if (mMol.getAtomicNo(atom) == 7
&& !mNitrogenQualifiesForParity[atom])
Expand Down Expand Up @@ -2077,6 +2085,15 @@ private boolean canCalcEZParity(int bond, int mode) {
if (mEZParity[bond] != 0)
return false;

if (mMol.isFragment()) { // don't calculate parities if some bond atoms or their neighbours are exclude groups
for (int i=0; i<2; i++) {
int atom = mMol.getBondAtom(i, bond);
for (int j=0; j<mMol.getAllConnAtoms(atom); j++)
if ((mMol.getAtomQueryFeatures(mMol.getConnAtom(atom, j)) & Molecule.cAtomQFExcludeGroup) != 0)
return false;
}
}

if (mMol.getBondOrder(bond) == 1)
return canCalcBINAPParity(bond, mode);

Expand Down Expand Up @@ -3754,7 +3771,7 @@ public int getTHParity(int atom) {


/**
* Returns the atoms's enhanced stereo representation type.
* Returns the atom's enhanced stereo representation type.
* @param atom
* @return one of the Molecule.cESRTypeXXX constants
*/
Expand Down
23 changes: 9 additions & 14 deletions src/main/java/com/actelion/research/chem/ExtendedMolecule.java
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ public int[] copyMoleculeByBonds(ExtendedMolecule destMol, boolean[] includeBond
destMol.mAllAtoms = 0;
for (int atom=0; atom<mAllAtoms;atom++) {
atomMap[atom] = -1;
for (int i=0; i< mConnAtoms[atom]; i++) {
for (int i=0; i<mConnAtoms[atom]; i++) {
if (includeBond[mConnBond[atom][i]]) {
atomMap[atom] = copyAtom(destMol, atom, 0, 0);

Expand Down Expand Up @@ -291,35 +291,30 @@ && isAtomStereoCenter(atom)) {
int lostStereoBond = -1;
int lostAtom = -1;
for (int i=0; i<mAllConnAtoms[atom]; i++) {
//if (mConnAtom.length>=atom || atomMap.length>=mConnAtom[atom][i])
// 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);
if (atomMap.length>mConnAtom[atom][i]
&& atomMap[mConnAtom[atom][i]] != -1)
if (bondMap[mConnBond[atom][i]] != -1)
remainingNeighbours++;
else if (mConnBondOrder[atom][i] == 1
&& isStereoBond(mConnBond[atom][i])
&& mBondAtom[0][mConnBond[atom][i]] == atom) {
&& isStereoBond(mConnBond[atom][i])
&& mBondAtom[0][mConnBond[atom][i]] == atom) {
lostStereoBond = mConnBond[atom][i];
lostAtom = mConnAtom[atom][i];
}
}
}
if (lostStereoBond != -1
&& remainingNeighbours >= 3) {
if (lostStereoBond != -1 && remainingNeighbours >= 3) {
double angle = getBondAngle(atom, lostAtom);
double minAngleDif = 10.0;
int minConnBond = -1;
for (int i=0; i<mAllConnAtoms[atom]; i++) {
if (mConnBondOrder[atom][i] == 1
&& (!isStereoBond(mConnBond[atom][i]) || mBondAtom[0][mConnBond[atom][i]] == atom)
&& atomMap.length>mConnAtom[atom][i]
&& atomMap[mConnAtom[atom][i]] != -1) {
&& (!isStereoBond(mConnBond[atom][i]) || mBondAtom[0][mConnBond[atom][i]] == atom)
&& bondMap[mConnBond[atom][i]] != -1) {
double angleDif = Math.abs(getAngleDif(angle, getBondAngle(atom, mConnAtom[atom][i])));
if (minAngleDif > angleDif) {
minAngleDif = angleDif;
minConnBond = mConnBond[atom][i];
}
}
}
}
if (minConnBond != -1) {
int destBond = bondMap[minConnBond];
destMol.setBondType(destBond, mBondType[minConnBond] == cBondTypeUp ? cBondTypeDown : cBondTypeUp);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,35 @@ public class ExtendedMoleculeFunctions {
public static final String [] arrRGroupsSymbol = {"R1","R2","R3","R4","R5","R6","R7","R8","R9","R10","R11","R12","R13","R14","R15","R16"};


public final static Coordinates getCenterGravity(ExtendedMolecule mol) {

int n = mol.getAllAtoms();

int [] indices = new int [n];

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

return getCenterGravity(mol, indices);
}

public final static Coordinates getCenterGravity(ExtendedMolecule mol, int[] indices) {

Coordinates c = new Coordinates();
for (int i = 0; i < indices.length; i++) {
c.x += mol.getAtomX(indices[i]);
c.y += mol.getAtomY(indices[i]);
c.z += mol.getAtomZ(indices[i]);
}
c.x /= indices.length;
c.y /= indices.length;
c.z /= indices.length;

return c;
}


public static void makeSkeleton(StereoMolecule mol) {
for (int bond=0; bond<mol.getAllBonds(); bond++)
mol.setBondType(bond, Molecule.cBondTypeSingle);
Expand Down
Loading

0 comments on commit 1c3edb1

Please sign in to comment.