Skip to content

Commit 60a559e

Browse files
committed
Make sure we have correct storage order in a bond when reading from InChI.
1 parent 7ff6a22 commit 60a559e

File tree

2 files changed

+36
-6
lines changed

2 files changed

+36
-6
lines changed

storage/inchi/src/main/java/org/openscience/cdk/inchi/InChIToStructure.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@
2323
import io.github.dan2097.jnainchi.InchiBondStereo;
2424
import io.github.dan2097.jnainchi.InchiBondType;
2525
import io.github.dan2097.jnainchi.InchiInput;
26+
import io.github.dan2097.jnainchi.InchiInputFromInchiOutput;
27+
import io.github.dan2097.jnainchi.InchiOptions;
2628
import io.github.dan2097.jnainchi.InchiStatus;
2729
import io.github.dan2097.jnainchi.InchiStereo;
2830
import io.github.dan2097.jnainchi.InchiStereoParity;
2931
import io.github.dan2097.jnainchi.InchiStereoType;
30-
import net.sf.jniinchi.INCHI_RET;
31-
import io.github.dan2097.jnainchi.InchiInputFromInchiOutput;
32-
import io.github.dan2097.jnainchi.InchiOptions;
3332
import io.github.dan2097.jnainchi.JnaInchi;
33+
import net.sf.jniinchi.INCHI_RET;
3434
import org.openscience.cdk.config.Elements;
3535
import org.openscience.cdk.config.Isotopes;
3636
import org.openscience.cdk.exception.CDKException;
@@ -362,7 +362,8 @@ protected void generateAtomContainerFromInchi(IChemObjectBuilder builder) throws
362362
if (ends[0] != a)
363363
flip(stereoBond);
364364
} else {
365-
flip(stereoBond);
365+
if (!stereoBond.getBegin().equals(a))
366+
flip(stereoBond);
366367
}
367368

368369
int config = IStereoElement.TOGETHER;

storage/inchi/src/test/java/org/openscience/cdk/inchi/InChIToStructureTest.java

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
import org.junit.Assert;
2424
import org.junit.Test;
25+
import org.openscience.cdk.interfaces.IBond;
2526
import org.openscience.cdk.test.CDKTestCase;
2627
import org.openscience.cdk.DefaultChemObjectBuilder;
2728
import org.openscience.cdk.exception.CDKException;
@@ -35,6 +36,7 @@
3536
import org.openscience.cdk.stereo.ExtendedTetrahedral;
3637

3738
import java.util.Iterator;
39+
import java.util.List;
3840

3941
import static org.hamcrest.CoreMatchers.instanceOf;
4042
import static org.hamcrest.CoreMatchers.is;
@@ -272,12 +274,39 @@ public void testExtendedCisTrans() throws Exception {
272274
SilentChemObjectBuilder.getInstance()).getAtomContainer();
273275
assertNotNull(mol);
274276
int nExtendedCisTrans = 0;
275-
for (IStereoElement se : mol.stereoElements()) {
276-
if (se.getConfig() != IStereoElement.CU)
277+
for (IStereoElement<?,?> se : mol.stereoElements()) {
278+
if (se.getConfigClass() == IStereoElement.CU)
277279
nExtendedCisTrans++;
278280
else
279281
Assert.fail("Expected onl extended cis/trans");
280282
}
281283
Assert.assertEquals(1, nExtendedCisTrans);
282284
}
285+
286+
/**
287+
* Make sure the IBond{beg,end} storage order is correct for the
288+
* IStereoElement
289+
* @throws Exception
290+
*/
291+
@Test
292+
@SuppressWarnings("unchecked")
293+
public void ensureBondStorageOrder() throws Exception {
294+
IAtomContainer mol = InChIGeneratorFactory.getInstance()
295+
.getInChIToStructure("InChI=1S/C16H25NO/c1-14(2)8-6-9-15(3)10-7-11-16(18)17-12-4-5-13-17/h7-8,10-11H,4-6,9,12-13H2,1-3H3/b11-7+,15-10+",
296+
SilentChemObjectBuilder.getInstance()).getAtomContainer();
297+
assertNotNull(mol);
298+
int nCisTrans = 0;
299+
for (IStereoElement<?,?> se : mol.stereoElements()) {
300+
if (se.getConfigClass() == IStereoElement.CisTrans) {
301+
nCisTrans++;
302+
IStereoElement<IBond,IBond> ctse = (IStereoElement<IBond,IBond>)se;
303+
IBond bond = ctse.getFocus();
304+
List<IBond> carriers = ctse.getCarriers();
305+
Assert.assertEquals(2, carriers.size());
306+
Assert.assertTrue(carriers.get(0).contains(bond.getBegin()));
307+
Assert.assertTrue(carriers.get(1).contains(bond.getEnd()));
308+
}
309+
}
310+
Assert.assertEquals(2, nCisTrans);
311+
}
283312
}

0 commit comments

Comments
 (0)