Skip to content

Commit

Permalink
Merge branch 'egon/369-14x-inchiCleaning' into cdk-1.4.x
Browse files Browse the repository at this point in the history
  • Loading branch information
rajarshi committed Mar 17, 2012
2 parents ca8f142 + e63ff94 commit 055646a
Show file tree
Hide file tree
Showing 8 changed files with 268 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/META-INF/test-inchi.cdkdepends
Expand Up @@ -9,3 +9,4 @@ cdk-valencycheck.jar
cdk-test.jar
cdk-inchi.jar
cdk-smiles.jar
cdk-silent.jar
3 changes: 3 additions & 0 deletions src/main/org/openscience/cdk/inchi/InChIGenerator.java
Expand Up @@ -416,20 +416,23 @@ public String getInchiKey() throws CDKException {
/**
* Gets auxillary information.
*/
@TestMethod("testGetAuxInfo")
public String getAuxInfo() {
return(output.getAuxInfo());
}

/**
* Gets generated (error/warning) messages.
*/
@TestMethod("testGetMessage,testGetWarningMessage")
public String getMessage() {
return(output.getMessage());
}

/**
* Gets generated log.
*/
@TestMethod("testGetLog")
public String getLog() {
return(output.getLog());
}
Expand Down
10 changes: 10 additions & 0 deletions src/main/org/openscience/cdk/inchi/InChIGeneratorFactory.java
Expand Up @@ -26,6 +26,8 @@
import net.sf.jniinchi.JniInchiWrapper;
import net.sf.jniinchi.LoadNativeLibraryException;

import org.openscience.cdk.annotations.TestClass;
import org.openscience.cdk.annotations.TestMethod;
import org.openscience.cdk.exception.CDKException;
import org.openscience.cdk.interfaces.IAtomContainer;
import org.openscience.cdk.interfaces.IChemObjectBuilder;
Expand Down Expand Up @@ -64,6 +66,7 @@
* @cdk.module inchi
* @cdk.githash
*/
@TestClass("org.openscience.cdk.inchi.InChIGeneratorFactoryTest")
public class InChIGeneratorFactory {

private static InChIGeneratorFactory INSTANCE;
Expand Down Expand Up @@ -92,6 +95,7 @@ private InChIGeneratorFactory() throws CDKException {
* @throws CDKException if unable to load native code when attempting
* to create the factory
*/
@TestMethod("testGetInstance")
public static InChIGeneratorFactory getInstance() throws CDKException {
synchronized ( InChIGeneratorFactory.class ) {
if ( INSTANCE == null ) {
Expand All @@ -108,6 +112,7 @@ public static InChIGeneratorFactory getInstance() throws CDKException {
* @return the InChI generator object
* @throws CDKException if the generator cannot be instantiated
*/
@TestMethod("testGetInChIGenerator_IAtomContainer")
public InChIGenerator getInChIGenerator(IAtomContainer container)
throws CDKException {
return(new InChIGenerator(container));
Expand All @@ -121,6 +126,7 @@ public InChIGenerator getInChIGenerator(IAtomContainer container)
* @return the InChI generator object
* @throws CDKException if the generator cannot be instantiated
*/
@TestMethod("testGetInChIGenerator_IAtomContainer_String")
public InChIGenerator getInChIGenerator(IAtomContainer container,
String options)
throws CDKException {
Expand All @@ -135,6 +141,7 @@ public InChIGenerator getInChIGenerator(IAtomContainer container,
* @return the InChI generator object
* @throws CDKException if the generator cannot be instantiated
*/
@TestMethod("testGetInChIGenerator_IAtomContainer_List")
public InChIGenerator getInChIGenerator(IAtomContainer container,
List<INCHI_OPTION> options) throws CDKException {
return(new InChIGenerator(container, options));
Expand All @@ -148,6 +155,7 @@ public InChIGenerator getInChIGenerator(IAtomContainer container,
* @return the InChI structure generator object
* @throws CDKException if the generator cannot be instantiated
*/
@TestMethod("testGetInChIToStructure_String_IChemObjectBuilder")
public InChIToStructure getInChIToStructure(String inchi,
IChemObjectBuilder builder)
throws CDKException {
Expand All @@ -163,6 +171,7 @@ public InChIToStructure getInChIToStructure(String inchi,
* @return the InChI structure generator object
* @throws CDKException if the generator cannot be instantiated
*/
@TestMethod("testGetInChIToStructure_String_IChemObjectBuilder_NullString")
public InChIToStructure getInChIToStructure(String inchi,
IChemObjectBuilder builder,
String options)
Expand All @@ -179,6 +188,7 @@ public InChIToStructure getInChIToStructure(String inchi,
* @return the InChI structure generator object
* @throws CDKException if the generator cannot be instantiated
*/
@TestMethod("testGetInChIToStructure_String_IChemObjectBuilder_List")
public InChIToStructure getInChIToStructure(String inchi,
IChemObjectBuilder builder,
List<String> options)
Expand Down
4 changes: 4 additions & 0 deletions src/main/org/openscience/cdk/inchi/InChIToStructure.java
Expand Up @@ -142,6 +142,7 @@ protected InChIToStructure(String inchi, IChemObjectBuilder builder, List<String
*
* @throws CDKException
*/
@TestMethod("testGetAtomContainer_IChemObjectBuilder")
protected void generateAtomContainerFromInchi(IChemObjectBuilder builder) throws CDKException {
try {
output = JniInchiWrapper.getStructureFromInchi(input);
Expand Down Expand Up @@ -289,13 +290,15 @@ public INCHI_RET getReturnStatus() {
/**
* Gets generated (error/warning) messages.
*/
@TestMethod("testGetMessage")
public String getMessage() {
return(output.getMessage());
}

/**
* Gets generated log.
*/
@TestMethod("testGetLog")
public String getLog() {
return(output.getLog());
}
Expand All @@ -309,6 +312,7 @@ public String getLog() {
* <br>y=1 => Main layer or Mobile-H
* <br>y=0 => Fixed-H layer
*/
@TestMethod("testGetWarningFlags")
public long[][] getWarningFlags() {
return(output.getWarningFlags());
}
Expand Down
146 changes: 146 additions & 0 deletions src/test/org/openscience/cdk/inchi/InChIGeneratorFactoryTest.java
@@ -0,0 +1,146 @@
/* Copyright (C) 2006 Sam Adams <sea36@users.sf.net>
* 2007 Rajarshi Guha <rajarshi.guha@gmail.com>
* 2010,2012 Egon Willighagen <egonw@users.sf.net>
*
* Contact: cdk-devel@lists.sourceforge.net
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*/
package org.openscience.cdk.inchi;

import java.util.ArrayList;
import java.util.List;

import net.sf.jniinchi.INCHI_OPTION;
import net.sf.jniinchi.INCHI_RET;

import org.junit.Assert;
import org.junit.Test;
import org.openscience.cdk.Atom;
import org.openscience.cdk.AtomContainer;
import org.openscience.cdk.DefaultChemObjectBuilder;
import org.openscience.cdk.exception.CDKException;
import org.openscience.cdk.interfaces.IAtom;
import org.openscience.cdk.interfaces.IAtomContainer;

/**
* @cdk.module test-inchi
*/
public class InChIGeneratorFactoryTest {

@Test
public void testGetInstance() throws CDKException {
InChIGeneratorFactory factory = InChIGeneratorFactory.getInstance();
Assert.assertNotNull(factory);
}

/**
* Because we are not setting any options, we get an Standard InChI.
*/
@Test public void testGetInChIGenerator_IAtomContainer() throws Exception {
IAtomContainer ac = new AtomContainer();
IAtom a = new Atom("Cl");
a.setImplicitHydrogenCount(1);
ac.addAtom(a);
InChIGenerator gen = InChIGeneratorFactory.getInstance().getInChIGenerator(ac);
Assert.assertEquals(gen.getReturnStatus(), INCHI_RET.OKAY);
Assert.assertEquals("InChI=1S/ClH/h1H", gen.getInchi());
}

/**
* Because we are setting an options, we get a non-standard InChI.
*/
@Test public void testGetInChIGenerator_IAtomContainer_String() throws Exception {
IAtomContainer ac = new AtomContainer();
IAtom a = new Atom("Cl");
a.setImplicitHydrogenCount(1);
ac.addAtom(a);
InChIGenerator gen = InChIGeneratorFactory.getInstance().getInChIGenerator(ac, "FixedH");
Assert.assertEquals(gen.getReturnStatus(), INCHI_RET.OKAY);
Assert.assertEquals("InChI=1/ClH/h1H", gen.getInchi());
}

/**
* Because we are setting no option, we get a Standard InChI.
*/
@Test public void testGetInChIGenerator_IAtomContainer_NullString() throws Exception {
IAtomContainer ac = new AtomContainer();
IAtom a = new Atom("Cl");
a.setImplicitHydrogenCount(1);
ac.addAtom(a);
InChIGenerator gen = InChIGeneratorFactory.getInstance().getInChIGenerator(ac, (String)null);
Assert.assertEquals(gen.getReturnStatus(), INCHI_RET.OKAY);
Assert.assertEquals("InChI=1S/ClH/h1H", gen.getInchi());
}

/**
* Because we are setting an options, we get a non-standard InChI.
*/
@Test public void testGetInChIGenerator_IAtomContainer_List() throws Exception {
IAtomContainer ac = new AtomContainer();
IAtom a = new Atom("Cl");
a.setImplicitHydrogenCount(1);
ac.addAtom(a);
List<INCHI_OPTION> options = new ArrayList<INCHI_OPTION>();
options.add(INCHI_OPTION.FixedH);
InChIGenerator gen = InChIGeneratorFactory.getInstance().getInChIGenerator(ac, options);
Assert.assertEquals(gen.getReturnStatus(), INCHI_RET.OKAY);
Assert.assertEquals("InChI=1/ClH/h1H", gen.getInchi());
}

/**
* Because we are setting an options, we get a non-standard InChI.
*/
@Test(expected=IllegalArgumentException.class)
public void testGetInChIGenerator_IAtomContainer_NullList() throws Exception {
IAtomContainer ac = new AtomContainer();
IAtom a = new Atom("Cl");
a.setImplicitHydrogenCount(1);
ac.addAtom(a);
InChIGeneratorFactory.getInstance().getInChIGenerator(ac, (List<INCHI_OPTION>)null);
}

@Test
public void testGetInChIToStructure_String_IChemObjectBuilder() throws CDKException {
InChIToStructure parser = InChIGeneratorFactory.getInstance().getInChIToStructure(
"InChI=1/ClH/h1H", DefaultChemObjectBuilder.getInstance()
);
Assert.assertNotNull(parser);
}

@Test(expected=IllegalArgumentException.class)
public void testGetInChIToStructure_String_IChemObjectBuilder_NullString() throws CDKException {
InChIGeneratorFactory.getInstance().getInChIToStructure(
"InChI=1/ClH/h1H", DefaultChemObjectBuilder.getInstance(), (String)null
);
}

@Test(expected=IllegalArgumentException.class)
public void testGetInChIToStructure_String_IChemObjectBuilder_NullList() throws CDKException {
InChIGeneratorFactory.getInstance().getInChIToStructure(
"InChI=1/ClH/h1H", DefaultChemObjectBuilder.getInstance(), (List<String>)null
);
}

/**
* No options set.
*/
@Test public void testGetInChIToStructure_String_IChemObjectBuilder_List() throws CDKException {
InChIToStructure parser = InChIGeneratorFactory.getInstance().getInChIToStructure(
"InChI=1/ClH/h1H", DefaultChemObjectBuilder.getInstance(), new ArrayList<String>()
);
Assert.assertNotNull(parser);
}
}
46 changes: 44 additions & 2 deletions src/test/org/openscience/cdk/inchi/InChIGeneratorTest.java
@@ -1,5 +1,5 @@
/* Copyright (C) 2006-2007 Sam Adams <sea36@users.sf.net>
* 2010 Egon Willighagen <egonw@users.sf.net>
* 2010,2012 Egon Willighagen <egonw@users.sf.net>
*
* Contact: cdk-devel@lists.sourceforge.net
*
Expand All @@ -25,6 +25,7 @@
import org.openscience.cdk.*;
import org.openscience.cdk.interfaces.IAtom;
import org.openscience.cdk.interfaces.IAtomContainer;
import org.openscience.cdk.interfaces.IBond.Order;

import javax.vecmath.Point2d;
import javax.vecmath.Point3d;
Expand Down Expand Up @@ -60,7 +61,48 @@ protected InChIGeneratorFactory getFactory() throws Exception {
Assert.assertEquals(gen.getReturnStatus(), INCHI_RET.OKAY);
Assert.assertEquals("InChI=1/ClH/h1H", gen.getInchi());
}


@Test public void testGetLog() throws Exception {
IAtomContainer ac = new AtomContainer();
ac.addAtom(new Atom("Cl"));
InChIGenerator gen = getFactory().getInChIGenerator(ac,"FixedH");
Assert.assertNotNull(gen.getLog());
}

@Test public void testGetAuxInfo() throws Exception {
IAtomContainer ac = new AtomContainer();
IAtom a1 = new Atom("C");
IAtom a2 = new Atom("C");
a1.setImplicitHydrogenCount(3);
a2.setImplicitHydrogenCount(3);
ac.addAtom(a1);
ac.addAtom(a2);
ac.addBond(new Bond(a1, a2, CDKConstants.BONDORDER_SINGLE));
InChIGenerator gen = getFactory().getInChIGenerator(ac);
Assert.assertNotNull(gen.getAuxInfo());
Assert.assertTrue(gen.getAuxInfo().startsWith("AuxInfo="));
}

@Test public void testGetMessage() throws Exception {
IAtomContainer ac = new AtomContainer();
ac.addAtom(new Atom("Cl"));
InChIGenerator gen = getFactory().getInChIGenerator(ac,"FixedH");
Assert.assertNull(
"Because this generation should work, I expected a null message String.",
gen.getMessage()
);
}

@Test public void testGetWarningMessage() throws Exception {
IAtomContainer ac = new AtomContainer();
ac.addAtom(new Atom("Cl"));
ac.addAtom(new Atom("H"));
ac.addBond(0, 1, Order.TRIPLE);
InChIGenerator gen = getFactory().getInChIGenerator(ac);
Assert.assertNotNull(gen.getMessage());
Assert.assertTrue(gen.getMessage().contains("Accepted unusual valence"));
}

/**
* Tests charge is correctly passed to InChI.
*
Expand Down

0 comments on commit 055646a

Please sign in to comment.