Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added double bond stereo

Change-Id: I7a3ece179bc3b9136976634108d18cd69a20645e
  • Loading branch information...
commit 670783676f9e5c01695cc782d3cc5b4bbbd191ae 1 parent 670c525
@egonw authored
View
49 src/main/org/openscience/cdk/inchi/InChIGenerator.java
@@ -54,6 +54,7 @@
import org.openscience.cdk.interfaces.IAtomContainer;
import org.openscience.cdk.interfaces.IAtomParity;
import org.openscience.cdk.interfaces.IBond;
+import org.openscience.cdk.interfaces.IDoubleBondStereochemistry;
import org.openscience.cdk.interfaces.IStereoElement;
import org.openscience.cdk.interfaces.ITetrahedralChirality;
import org.openscience.cdk.interfaces.ITetrahedralChirality.Stereo;
@@ -283,6 +284,7 @@ private void generateInchiFromCDKAtomContainer(IAtomContainer atomContainer) thr
// Process bonds
+ Map<IBond, JniInchiBond> bondMap = new HashMap<IBond, JniInchiBond>();
Iterator<IBond> bonds = atomContainer.bonds().iterator();
while (bonds.hasNext()) {
IBond bond = bonds.next();
@@ -308,6 +310,7 @@ private void generateInchiFromCDKAtomContainer(IAtomContainer atomContainer) thr
// Create InChI bond
JniInchiBond ibond = new JniInchiBond(at0, at1, order);
+ bondMap.put(bond, ibond);
input.addBond(ibond);
// Check for bond stereo definitions
@@ -393,6 +396,52 @@ else if (stereo == CDKConstants.UNSET) {
JniInchiStereo0D jniStereo = new JniInchiStereo0D(atC, at0, at1, at2, at3,
INCHI_STEREOTYPE.TETRAHEDRAL, p);
input.addStereo0D(jniStereo);
+ } else if (stereoElem instanceof IDoubleBondStereochemistry) {
+ IDoubleBondStereochemistry dbStereo = (IDoubleBondStereochemistry)stereoElem;
+ IBond[] surroundingBonds = dbStereo.getBonds();
+ if (surroundingBonds[0] == null || surroundingBonds[1] == null)
+ throw new CDKException("Cannot generate an InChI with incomplete double bond info");
+ org.openscience.cdk.interfaces.IDoubleBondStereochemistry.
+ Conformation stereoType = dbStereo.getStereo();
+
+ IBond stereoBond = dbStereo.getStereoBond();
+ JniInchiAtom at0 = null;
+ JniInchiAtom at1 = null;
+ JniInchiAtom at2 = null;
+ JniInchiAtom at3 = null;
+ // TODO: I should check for two atom bonds... or maybe that should happen when you
+ // create a double bond stereochemistry
+ if (stereoBond.contains(surroundingBonds[0].getAtom(0))) {
+ // first atom is A
+ at1 = (JniInchiAtom) atomMap.get(surroundingBonds[0].getAtom(0));
+ at0 = (JniInchiAtom) atomMap.get(surroundingBonds[0].getAtom(1));
+ } else {
+ // first atom is X
+ at0 = (JniInchiAtom) atomMap.get(surroundingBonds[0].getAtom(0));
+ at1 = (JniInchiAtom) atomMap.get(surroundingBonds[0].getAtom(1));
+ }
+ if (stereoBond.contains(surroundingBonds[1].getAtom(0))) {
+ // first atom is B
+ at2 = (JniInchiAtom) atomMap.get(surroundingBonds[1].getAtom(0));
+ at3 = (JniInchiAtom) atomMap.get(surroundingBonds[1].getAtom(1));
+ } else {
+ // first atom is Y
+ at2 = (JniInchiAtom) atomMap.get(surroundingBonds[1].getAtom(1));
+ at3 = (JniInchiAtom) atomMap.get(surroundingBonds[1].getAtom(0));
+ }
+ INCHI_PARITY p = INCHI_PARITY.UNKNOWN;
+ if (stereoType == org.openscience.cdk.interfaces.IDoubleBondStereochemistry.Conformation.TOGETHER) {
+ p = INCHI_PARITY.ODD;
+ } else if (stereoType == org.openscience.cdk.interfaces.IDoubleBondStereochemistry.Conformation.OPPOSITE) {
+ p = INCHI_PARITY.EVEN;
+ } else {
+ throw new CDKException("Unknown double bond stereochemistry");
+ }
+
+ JniInchiStereo0D jniStereo = new JniInchiStereo0D(
+ null, at0, at1, at2, at3, INCHI_STEREOTYPE.DOUBLEBOND, p
+ );
+ input.addStereo0D(jniStereo);
}
}
View
41 src/test/org/openscience/cdk/inchi/InChIGeneratorTest.java
@@ -25,9 +25,12 @@
import org.openscience.cdk.*;
import org.openscience.cdk.interfaces.IAtom;
import org.openscience.cdk.interfaces.IAtomContainer;
+import org.openscience.cdk.interfaces.IBond;
+import org.openscience.cdk.interfaces.IDoubleBondStereochemistry;
import org.openscience.cdk.interfaces.ITetrahedralChirality;
import org.openscience.cdk.interfaces.IBond.Order;
import org.openscience.cdk.interfaces.ITetrahedralChirality.Stereo;
+import org.openscience.cdk.stereo.DoubleBondStereochemistry;
import org.openscience.cdk.stereo.TetrahedralChirality;
import javax.vecmath.Point2d;
@@ -277,8 +280,7 @@ protected InChIGeneratorFactory getFactory() throws Exception {
Assert.assertEquals(genZ.getReturnStatus(), INCHI_RET.OKAY);
Assert.assertEquals("InChI=1/C2H2Cl2/c3-1-2-4/h1-2H/b2-1-", genZ.getInchi());
}
-
-
+
/**
* Tests 3D coordinates are correctly passed to InChI.
*
@@ -680,4 +682,39 @@ public void testTetrahedralStereo() throws Exception {
genL.getInchi()
);
}
+
+ @Test public void testDoubleBondStereochemistry() throws Exception {
+ // (E)-1,2-dichloroethene
+ IAtomContainer acE = new AtomContainer();
+ IAtom a1E = new Atom("C");
+ IAtom a2E = new Atom("C");
+ IAtom a3E = new Atom("Cl");
+ IAtom a4E = new Atom("Cl");
+ a1E.setImplicitHydrogenCount(1);
+ a2E.setImplicitHydrogenCount(1);
+ acE.addAtom(a1E);
+ acE.addAtom(a2E);
+ acE.addAtom(a3E);
+ acE.addAtom(a4E);
+
+ acE.addBond(new Bond(a1E, a2E, CDKConstants.BONDORDER_DOUBLE));
+ acE.addBond(new Bond(a1E, a3E, CDKConstants.BONDORDER_SINGLE));
+ acE.addBond(new Bond(a2E, a4E, CDKConstants.BONDORDER_SINGLE));
+
+ IBond[] ligands = new IBond[2];
+ ligands[0] = acE.getBond(1);
+ ligands[1] = acE.getBond(2);
+ IDoubleBondStereochemistry stereo = new DoubleBondStereochemistry(
+ acE.getBond(0), ligands, org.openscience.cdk.interfaces.IDoubleBondStereochemistry.Conformation.OPPOSITE
+ );
+ acE.addStereoElement(stereo);
+
+ InChIGenerator genE = getFactory().getInChIGenerator(acE);
+ Assert.assertEquals(INCHI_RET.OKAY, genE.getReturnStatus());
+ System.out.println(genE.getMessage());
+ Assert.assertEquals(
+ "InChI=1S/C2H2Cl2/c3-1-2-4/h1-2H/b2-1+",
+ genE.getInchi()
+ );
+ }
}
Please sign in to comment.
Something went wrong with that request. Please try again.