Skip to content

Commit

Permalink
Only set stereochemistry if specificed.
Browse files Browse the repository at this point in the history
  • Loading branch information
johnmay authored and egonw committed Feb 7, 2022
1 parent a51c386 commit 996035d
Showing 1 changed file with 42 additions and 40 deletions.
Expand Up @@ -235,50 +235,52 @@ public IAtomContainer readConnectionTable(IChemObjectBuilder builder) throws CDK
if (atom.getPoint3d() == null)
is3d = false;
}
if (is3d) { // has 3D coordinates
readData.setStereoElements(StereoElementFactory.using3DCoordinates(readData)
.createAll());
} else { // has 2D coordinates (set as 2D coordinates)
readData.setStereoElements(StereoElementFactory.using2DCoordinates(readData)
.createAll());
}
if (optStereoPerc.isSet()) {
if (is3d) { // has 3D coordinates
readData.setStereoElements(StereoElementFactory.using3DCoordinates(readData)
.createAll());
} else { // has 2D coordinates (set as 2D coordinates)
readData.setStereoElements(StereoElementFactory.using2DCoordinates(readData)
.createAll());
}

if (stereoflags != null && !stereoflags.isEmpty()) {

// work out the next available group, if we have &1, &2, etc then we choose &3
// this is only needed if
int defaultRacGrp = 0;
if (!chiral) {
int max = 0;
for (Integer val : stereoflags.values()) {
if ((val&IStereoElement.GRP_TYPE_MASK) == IStereoElement.GRP_RAC) {
int num = val >>> IStereoElement.GRP_NUM_SHIFT;
if (num > max)
max = num;
if (stereoflags != null && !stereoflags.isEmpty()) {

// work out the next available group, if we have &1, &2, etc then we choose &3
// this is only needed if
int defaultRacGrp = 0;
if (!chiral) {
int max = 0;
for (Integer val : stereoflags.values()) {
if ((val & IStereoElement.GRP_TYPE_MASK) == IStereoElement.GRP_RAC) {
int num = val >>> IStereoElement.GRP_NUM_SHIFT;
if (num > max)
max = num;
}
}
defaultRacGrp = IStereoElement.GRP_RAC | (((max + 1) << IStereoElement.GRP_NUM_SHIFT));
}
defaultRacGrp = IStereoElement.GRP_RAC | (((max + 1) << IStereoElement.GRP_NUM_SHIFT));
}

for (IStereoElement<?, ?> se : readData.stereoElements()) {
if (se.getConfigClass() != IStereoElement.TH)
continue;
IAtom focus = (IAtom) se.getFocus();
int idx = readData.indexOf(focus);
if (idx < 0)
continue;
Integer grpinfo = stereoflags.get(idx);
if (grpinfo != null)
se.setGroupInfo(grpinfo);
else if (!chiral)
se.setGroupInfo(defaultRacGrp);
}
} else if (!chiral) {
// chiral flag not set which means this molecule is this stereoisomer "and" the enantiomer, mark all
// Tetrahedral stereo as AND1 (&1)
for (IStereoElement<?, ?> se : readData.stereoElements()) {
if (se.getConfigClass() == IStereoElement.TH) {
se.setGroupInfo(IStereoElement.GRP_RAC1);
for (IStereoElement<?, ?> se : readData.stereoElements()) {
if (se.getConfigClass() != IStereoElement.TH)
continue;
IAtom focus = (IAtom) se.getFocus();
int idx = readData.indexOf(focus);
if (idx < 0)
continue;
Integer grpinfo = stereoflags.get(idx);
if (grpinfo != null)
se.setGroupInfo(grpinfo);
else if (!chiral)
se.setGroupInfo(defaultRacGrp);
}
} else if (!chiral) {
// chiral flag not set which means this molecule is this stereoisomer "and" the enantiomer, mark all
// Tetrahedral stereo as AND1 (&1)
for (IStereoElement<?, ?> se : readData.stereoElements()) {
if (se.getConfigClass() == IStereoElement.TH) {
se.setGroupInfo(IStereoElement.GRP_RAC1);
}
}
}
}
Expand Down

0 comments on commit 996035d

Please sign in to comment.