Permalink
Browse files

non-null atomic numbers when reading from InChi [bug:1293]

Change-Id: Ib6c5e9291913705ccb6f8ef6bd2813f3dd77745c
Signed-off-by: Egon Willighagen <egonw@users.sourceforge.net>
  • Loading branch information...
johnmay authored and egonw committed Mar 14, 2013
1 parent 471a20c commit 3117f4ca82fd45db523ce83924fb1f83d671615a
@@ -46,6 +46,7 @@
import org.openscience.cdk.interfaces.IAtomParity;
import org.openscience.cdk.interfaces.IBond;
import org.openscience.cdk.interfaces.IChemObjectBuilder;
import org.openscience.cdk.tools.periodictable.PeriodicTable;
/**
* <p>This class generates a CDK IAtomContainer from an InChI string. It places
@@ -163,9 +164,10 @@ protected void generateAtomContainerFromInchi(IChemObjectBuilder builder) throws
cAt.setID("a" + i);
cAt.setSymbol(iAt.getElementType());
cAt.setAtomicNumber(PeriodicTable.getAtomicNumber(cAt.getSymbol()));
// Ignore coordinates - all zero
int charge = iAt.getCharge();
if (charge != 0) {
cAt.setFormalCharge(charge);
@@ -25,11 +25,14 @@
import org.openscience.cdk.CDKTestCase;
import org.openscience.cdk.DefaultChemObjectBuilder;
import org.openscience.cdk.exception.CDKException;
import org.openscience.cdk.interfaces.IAtom;
import org.openscience.cdk.interfaces.IAtomContainer;
import org.openscience.cdk.interfaces.IBond.Order;
import org.openscience.cdk.silent.AtomContainer;
import org.openscience.cdk.silent.SilentChemObjectBuilder;
import static org.junit.Assert.assertNotNull;
/**
* TestCase for the {@link InChIToStructure} class.
*
@@ -44,7 +47,7 @@ public void testConstructor_String_IChemObjectBuilder()
"InChI=1S/CH4/h1H4",
DefaultChemObjectBuilder.getInstance()
);
Assert.assertNotNull(parser);
assertNotNull(parser);
}
@Test
@@ -54,18 +57,33 @@ public void testGetAtomContainer() throws CDKException {
DefaultChemObjectBuilder.getInstance()
);
IAtomContainer container = parser.getAtomContainer();
Assert.assertNotNull(container);
assertNotNull(container);
Assert.assertEquals(1, container.getAtomCount());
}
/** @cdk.bug 1293 */
@Test
public void nonNullAtomicNumbers() throws CDKException {
InChIToStructure parser = new InChIToStructure(
"InChI=1S/CH4/h1H4",
DefaultChemObjectBuilder.getInstance()
);
IAtomContainer container = parser.getAtomContainer();
for(IAtom atom : container.atoms()){
assertNotNull(atom.getAtomicNumber());
}
assertNotNull(container);
Assert.assertEquals(1, container.getAtomCount());
}
@Test
public void testFixedHydrogens() throws CDKException {
InChIToStructure parser = new InChIToStructure(
"InChI=1/CH2O2/c2-1-3/h1H,(H,2,3)/f/h2H",
DefaultChemObjectBuilder.getInstance()
);
IAtomContainer container = parser.getAtomContainer();
Assert.assertNotNull(container);
assertNotNull(container);
Assert.assertEquals(3, container.getAtomCount());
Assert.assertEquals(2, container.getBondCount());
Assert.assertTrue(
@@ -82,7 +100,7 @@ public void testGetReturnStatus_EOF() throws CDKException {
);
parser.getAtomContainer();
INCHI_RET returnStatus = parser.getReturnStatus();
Assert.assertNotNull(returnStatus);
assertNotNull(returnStatus);
Assert.assertEquals(INCHI_RET.EOF, returnStatus);
}
@@ -93,7 +111,7 @@ public void testGetMessage() throws CDKException {
);
parser.getAtomContainer();
String message = parser.getMessage();
Assert.assertNotNull(message);
assertNotNull(message);
}
@Test
@@ -113,7 +131,7 @@ public void testGetLog() throws CDKException {
);
parser.getAtomContainer();
String message = parser.getMessage();
Assert.assertNotNull(message);
assertNotNull(message);
}
@Test
@@ -123,7 +141,7 @@ public void testGetWarningFlags() throws CDKException {
);
parser.getAtomContainer();
long[][] flags = parser.getWarningFlags();
Assert.assertNotNull(flags);
assertNotNull(flags);
Assert.assertEquals(2, flags.length);
Assert.assertEquals(2, flags[0].length);
Assert.assertEquals(2, flags[1].length);

0 comments on commit 3117f4c

Please sign in to comment.