Skip to content

Commit c1e2290

Browse files
committed
Storage of stereo groups on IStereoElements.
1 parent a027f66 commit c1e2290

File tree

2 files changed

+99
-1
lines changed

2 files changed

+99
-1
lines changed

base/core/src/main/java/org/openscience/cdk/stereo/AbstractStereo.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public int getConfigOrder() {
101101
*/
102102
@Override
103103
public int getConfig() {
104-
return value;
104+
return value & 0xffff;
105105
}
106106

107107
/**
@@ -112,6 +112,15 @@ public void setConfigOrder(int cfg) {
112112
value = getConfigClass() | cfg;
113113
}
114114

115+
public int getGroupInfo() {
116+
return value & IStereoElement.GRP_MASK;
117+
}
118+
119+
public void setGrpConfig(int grp) {
120+
value &= ~IStereoElement.GRP_MASK;
121+
value |= (grp & IStereoElement.GRP_MASK);
122+
}
123+
115124
/**
116125
* {@inheritDoc}
117126
*/

base/interfaces/src/main/java/org/openscience/cdk/interfaces/IStereoElement.java

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,46 @@
7171
* <li>{@link #HBPY9}: Heptagonal Bipyramidal</li>
7272
* </ul>
7373
*
74+
* <b><u>Stereo Groups (Enhanced stereo):</u></b>
75+
* Stereochemistry group information, aka "enhanced stereochemistry" in V3000 MOLFile etc allows you to specify
76+
* racemic and unknown enantiomers. In V2000 MOLfile the if chiral flag was 0 it indicates the structure was a mixture
77+
* of enantiomers. V3000 extended this concept to not only encode mixtures (and enantiomer) but also unknown
78+
* stereochemistry (or enantiomer) and to be per chiral centre. Reading an MDLV2000 molfile a chiral flag of 0 is
79+
* equivalent to setting all stereocentres to {@link #GRP_AND1}. This information can also be encoded in CXSMILES. By
80+
* default all stereocentres are {@link #GRP_ABS}.
81+
*
82+
* The stereo group information is stored in the high bytes of the stereo configuration. You can access the basic
83+
* information as follows:
84+
* <pre>{@code
85+
* int grpconfig = stereo.getGroupInfo();
86+
* if (grpconfig & IStereoElement.GRP_AND1) {
87+
* // group is AND1
88+
* } else if (config & IStereoElement.GRP_OR1) {
89+
* // group is OR1
90+
* }
91+
* }</pre>
92+
*
93+
* You can also unpack the various parts of the information manually.
94+
*
95+
* <pre>{@code
96+
* int grpconfig = stereo.getGroupInfo();
97+
* switch (grpconfig & IStereoElement.GRP_TYPE_MASK) {
98+
* case IStereoElement.GRP_ABS:
99+
* break;
100+
* case IStereoElement.GRP_AND:
101+
* break;
102+
* case IStereoElement.GRP_OR:
103+
* break;
104+
* }
105+
*
106+
* // the group number 1, 2, 3, 4 is a little more tricky, you can mask off the value as
107+
* // follows but it's shifted up into position
108+
* int num = grpconfig & IStereoElement.GRP_NUM_MASK;
109+
*
110+
* // to get the number 1, 2, 3, etc you can simply shift it down as follows
111+
* int num_act = grpconfig >>> IStereoElement.GRP_NUM_SHIFT;
112+
* }</pre>
113+
*
74114
* @cdk.module interfaces
75115
* @cdk.githash
76116
*
@@ -174,6 +214,43 @@ public interface IStereoElement<F extends IChemObject, C extends IChemObject>
174214
/** Square Planar Configutation in Z Shape */
175215
public static final int SPZ = SP | 3;
176216

217+
/** Mask for the stereo group information */
218+
public static final int GRP_MASK = 0xff_0000;
219+
/** Mask for the stereo group type information, GRP_ABS, GRP_AND, GRP_OR */
220+
public static final int GRP_TYPE_MASK = 0x03_0000;
221+
/** Mask for the stereo group number information, 0x0 .. 0xf (1..15) */
222+
public static final int GRP_NUM_MASK = 0xfc_0000;
223+
public static final int GRP_NUM_SHIFT = 18; // Integer.numberOfTrailingZeros(0xfc_0000);
224+
225+
/** Stereo group type ABS (absolute) */
226+
public static final int GRP_ABS = 0x00_0000;
227+
/** Stereo group type AND (and enantiomer) */
228+
public static final int GRP_AND = 0x01_0000;
229+
/** Stereo group type OR (or enantiomer) */
230+
public static final int GRP_OR = 0x02_0000;
231+
232+
/** Convenience field for testing if the stereo is group AND1 (&amp;1). */
233+
public static final int GRP_AND1 = GRP_AND | (1 << GRP_NUM_SHIFT);
234+
/** Convenience field for testing if the stereo is group AND2 (&amp;2). */
235+
public static final int GRP_AND2 = GRP_AND | (2 << GRP_NUM_SHIFT);
236+
/** Convenience field for testing if the stereo is group AND3 (&amp;3). */
237+
public static final int GRP_AND3 = GRP_AND | (3 << GRP_NUM_SHIFT);
238+
/** Convenience field for testing if the stereo is group AND4 (&amp;4). */
239+
public static final int GRP_AND4 = GRP_AND | (4 << GRP_NUM_SHIFT);
240+
/** Convenience field for testing if the stereo is group AND5 (&amp;5). */
241+
public static final int GRP_AND5 = GRP_AND | (5 << GRP_NUM_SHIFT);
242+
243+
/** Convenience field for testing if the stereo is group OR1 (&amp;1). */
244+
public static final int GRP_OR1 = GRP_OR | (1 << GRP_NUM_SHIFT);
245+
/** Convenience field for testing if the stereo is group OR2 (&amp;2). */
246+
public static final int GRP_OR2 = GRP_OR | (2 << GRP_NUM_SHIFT);
247+
/** Convenience field for testing if the stereo is group OR3 (&amp;3). */
248+
public static final int GRP_OR3 = GRP_OR | (3 << GRP_NUM_SHIFT);
249+
/** Convenience field for testing if the stereo is group OR4 (&amp;4). */
250+
public static final int GRP_OR4 = GRP_OR | (4 << GRP_NUM_SHIFT);
251+
/** Convenience field for testing if the stereo is group OR5 (&amp;5). */
252+
public static final int GRP_OR5 = GRP_OR | (5 << GRP_NUM_SHIFT);
253+
177254
/**
178255
* The focus atom or bond at the 'centre' of the stereo-configuration.
179256
* @return the focus
@@ -210,6 +287,18 @@ public interface IStereoElement<F extends IChemObject, C extends IChemObject>
210287
*/
211288
int getConfig();
212289

290+
/**
291+
* Access the stereo group information - see class doc.
292+
* @return the group info
293+
*/
294+
int getGroupInfo();
295+
296+
/**
297+
* Set the stereo group information - see class doc.
298+
* @param grp the group info
299+
*/
300+
void setGrpConfig(int grp);
301+
213302
/**
214303
* Does the stereo element contain the provided atom.
215304
*

0 commit comments

Comments
 (0)