5454import org .openscience .cdk .interfaces .IAtomContainer ;
5555import org .openscience .cdk .interfaces .IAtomParity ;
5656import org .openscience .cdk .interfaces .IBond ;
57+ import org .openscience .cdk .interfaces .IDoubleBondStereochemistry ;
5758import org .openscience .cdk .interfaces .IStereoElement ;
5859import org .openscience .cdk .interfaces .ITetrahedralChirality ;
5960import org .openscience .cdk .interfaces .ITetrahedralChirality .Stereo ;
@@ -283,6 +284,7 @@ private void generateInchiFromCDKAtomContainer(IAtomContainer atomContainer) thr
283284
284285
285286 // Process bonds
287+ Map <IBond , JniInchiBond > bondMap = new HashMap <IBond , JniInchiBond >();
286288 Iterator <IBond > bonds = atomContainer .bonds ().iterator ();
287289 while (bonds .hasNext ()) {
288290 IBond bond = bonds .next ();
@@ -308,6 +310,7 @@ private void generateInchiFromCDKAtomContainer(IAtomContainer atomContainer) thr
308310
309311 // Create InChI bond
310312 JniInchiBond ibond = new JniInchiBond (at0 , at1 , order );
313+ bondMap .put (bond , ibond );
311314 input .addBond (ibond );
312315
313316 // Check for bond stereo definitions
@@ -393,6 +396,52 @@ else if (stereo == CDKConstants.UNSET) {
393396 JniInchiStereo0D jniStereo = new JniInchiStereo0D (atC , at0 , at1 , at2 , at3 ,
394397 INCHI_STEREOTYPE .TETRAHEDRAL , p );
395398 input .addStereo0D (jniStereo );
399+ } else if (stereoElem instanceof IDoubleBondStereochemistry ) {
400+ IDoubleBondStereochemistry dbStereo = (IDoubleBondStereochemistry )stereoElem ;
401+ IBond [] surroundingBonds = dbStereo .getBonds ();
402+ if (surroundingBonds [0 ] == null || surroundingBonds [1 ] == null )
403+ throw new CDKException ("Cannot generate an InChI with incomplete double bond info" );
404+ org .openscience .cdk .interfaces .IDoubleBondStereochemistry .
405+ Conformation stereoType = dbStereo .getStereo ();
406+
407+ IBond stereoBond = dbStereo .getStereoBond ();
408+ JniInchiAtom at0 = null ;
409+ JniInchiAtom at1 = null ;
410+ JniInchiAtom at2 = null ;
411+ JniInchiAtom at3 = null ;
412+ // TODO: I should check for two atom bonds... or maybe that should happen when you
413+ // create a double bond stereochemistry
414+ if (stereoBond .contains (surroundingBonds [0 ].getAtom (0 ))) {
415+ // first atom is A
416+ at1 = (JniInchiAtom ) atomMap .get (surroundingBonds [0 ].getAtom (0 ));
417+ at0 = (JniInchiAtom ) atomMap .get (surroundingBonds [0 ].getAtom (1 ));
418+ } else {
419+ // first atom is X
420+ at0 = (JniInchiAtom ) atomMap .get (surroundingBonds [0 ].getAtom (0 ));
421+ at1 = (JniInchiAtom ) atomMap .get (surroundingBonds [0 ].getAtom (1 ));
422+ }
423+ if (stereoBond .contains (surroundingBonds [1 ].getAtom (0 ))) {
424+ // first atom is B
425+ at2 = (JniInchiAtom ) atomMap .get (surroundingBonds [1 ].getAtom (0 ));
426+ at3 = (JniInchiAtom ) atomMap .get (surroundingBonds [1 ].getAtom (1 ));
427+ } else {
428+ // first atom is Y
429+ at2 = (JniInchiAtom ) atomMap .get (surroundingBonds [1 ].getAtom (1 ));
430+ at3 = (JniInchiAtom ) atomMap .get (surroundingBonds [1 ].getAtom (0 ));
431+ }
432+ INCHI_PARITY p = INCHI_PARITY .UNKNOWN ;
433+ if (stereoType == org .openscience .cdk .interfaces .IDoubleBondStereochemistry .Conformation .TOGETHER ) {
434+ p = INCHI_PARITY .ODD ;
435+ } else if (stereoType == org .openscience .cdk .interfaces .IDoubleBondStereochemistry .Conformation .OPPOSITE ) {
436+ p = INCHI_PARITY .EVEN ;
437+ } else {
438+ throw new CDKException ("Unknown double bond stereochemistry" );
439+ }
440+
441+ JniInchiStereo0D jniStereo = new JniInchiStereo0D (
442+ null , at0 , at1 , at2 , at3 , INCHI_STEREOTYPE .DOUBLEBOND , p
443+ );
444+ input .addStereo0D (jniStereo );
396445 }
397446 }
398447
0 commit comments