Skip to content

Commit

Permalink
Make sure we have correct storage order in a bond when reading from I…
Browse files Browse the repository at this point in the history
…nChI.
  • Loading branch information
johnmay committed Jan 11, 2022
1 parent 7ff6a22 commit 60a559e
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@
import io.github.dan2097.jnainchi.InchiBondStereo;
import io.github.dan2097.jnainchi.InchiBondType;
import io.github.dan2097.jnainchi.InchiInput;
import io.github.dan2097.jnainchi.InchiInputFromInchiOutput;
import io.github.dan2097.jnainchi.InchiOptions;
import io.github.dan2097.jnainchi.InchiStatus;
import io.github.dan2097.jnainchi.InchiStereo;
import io.github.dan2097.jnainchi.InchiStereoParity;
import io.github.dan2097.jnainchi.InchiStereoType;
import net.sf.jniinchi.INCHI_RET;
import io.github.dan2097.jnainchi.InchiInputFromInchiOutput;
import io.github.dan2097.jnainchi.InchiOptions;
import io.github.dan2097.jnainchi.JnaInchi;
import net.sf.jniinchi.INCHI_RET;
import org.openscience.cdk.config.Elements;
import org.openscience.cdk.config.Isotopes;
import org.openscience.cdk.exception.CDKException;
Expand Down Expand Up @@ -362,7 +362,8 @@ protected void generateAtomContainerFromInchi(IChemObjectBuilder builder) throws
if (ends[0] != a)
flip(stereoBond);
} else {
flip(stereoBond);
if (!stereoBond.getBegin().equals(a))
flip(stereoBond);
}

int config = IStereoElement.TOGETHER;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import org.junit.Assert;
import org.junit.Test;
import org.openscience.cdk.interfaces.IBond;
import org.openscience.cdk.test.CDKTestCase;
import org.openscience.cdk.DefaultChemObjectBuilder;
import org.openscience.cdk.exception.CDKException;
Expand All @@ -35,6 +36,7 @@
import org.openscience.cdk.stereo.ExtendedTetrahedral;

import java.util.Iterator;
import java.util.List;

import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
Expand Down Expand Up @@ -272,12 +274,39 @@ public void testExtendedCisTrans() throws Exception {
SilentChemObjectBuilder.getInstance()).getAtomContainer();
assertNotNull(mol);
int nExtendedCisTrans = 0;
for (IStereoElement se : mol.stereoElements()) {
if (se.getConfig() != IStereoElement.CU)
for (IStereoElement<?,?> se : mol.stereoElements()) {
if (se.getConfigClass() == IStereoElement.CU)
nExtendedCisTrans++;
else
Assert.fail("Expected onl extended cis/trans");
}
Assert.assertEquals(1, nExtendedCisTrans);
}

/**
* Make sure the IBond{beg,end} storage order is correct for the
* IStereoElement
* @throws Exception
*/
@Test
@SuppressWarnings("unchecked")
public void ensureBondStorageOrder() throws Exception {
IAtomContainer mol = InChIGeneratorFactory.getInstance()
.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+",
SilentChemObjectBuilder.getInstance()).getAtomContainer();
assertNotNull(mol);
int nCisTrans = 0;
for (IStereoElement<?,?> se : mol.stereoElements()) {
if (se.getConfigClass() == IStereoElement.CisTrans) {
nCisTrans++;
IStereoElement<IBond,IBond> ctse = (IStereoElement<IBond,IBond>)se;
IBond bond = ctse.getFocus();
List<IBond> carriers = ctse.getCarriers();
Assert.assertEquals(2, carriers.size());
Assert.assertTrue(carriers.get(0).contains(bond.getBegin()));
Assert.assertTrue(carriers.get(1).contains(bond.getEnd()));
}
}
Assert.assertEquals(2, nCisTrans);
}
}

0 comments on commit 60a559e

Please sign in to comment.