Permalink
Browse files

Removes instanceof and .class usage of Molecule

Signed-off-by: Egon Willighagen <egonw@users.sourceforge.net>
  • Loading branch information...
1 parent 5da1d1b commit 436dba589d018e50b7164fa74d15d57c468a5ee2 @rajarshi rajarshi committed with egonw Dec 11, 2011
@@ -20,29 +20,27 @@
*/
package org.openscience.cdk.atomtype;
-import java.io.InputStream;
-import java.util.List;
-
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
import org.openscience.cdk.CDKConstants;
import org.openscience.cdk.CDKTestCase;
import org.openscience.cdk.ChemFile;
import org.openscience.cdk.DefaultChemObjectBuilder;
-import org.openscience.cdk.Molecule;
import org.openscience.cdk.interfaces.IAtom;
import org.openscience.cdk.interfaces.IAtomContainer;
import org.openscience.cdk.interfaces.IAtomType;
import org.openscience.cdk.interfaces.IBond;
import org.openscience.cdk.interfaces.IChemFile;
-import org.openscience.cdk.interfaces.IMolecule;
import org.openscience.cdk.io.ISimpleChemObjectReader;
import org.openscience.cdk.io.MDLV2000Reader;
import org.openscience.cdk.io.PDBReader;
import org.openscience.cdk.silent.AtomContainer;
import org.openscience.cdk.tools.manipulator.ChemFileManipulator;
+import java.io.InputStream;
+import java.util.List;
+
/**
* This class tests the matching of atom types defined in the
* cdk atom type list, using the test files in <code>src/test/data</code>.
@@ -228,11 +226,11 @@ private TestResults testFile(String dir, String filename, ISimpleChemObjectReade
InputStream ins = this.getClass().getClassLoader().getResourceAsStream(dir+filename);
reader.setReader(ins);
IAtomContainer mol = null;
- if (reader.accepts(Molecule.class)) {
- mol = (IMolecule)reader.read(new AtomContainer());
+ if (reader.accepts(AtomContainer.class)) {
+ mol = reader.read(new AtomContainer());
} else if (reader.accepts(ChemFile.class)) {
- IChemFile cf = (IChemFile)reader.read(new ChemFile());
- mol = new AtomContainer();
+ IChemFile cf = reader.read(new ChemFile());
+ mol = DefaultChemObjectBuilder.getInstance().newInstance(IAtomContainer.class);
List<IAtomContainer> containers = ChemFileManipulator.getAllAtomContainers(cf);
for (IAtomContainer container : containers) mol.add(container);
}
@@ -22,13 +22,10 @@
*/
package org.openscience.cdk.fingerprint;
-import java.io.IOException;
-import java.io.StringReader;
-import java.util.BitSet;
-
import org.junit.Assert;
import org.junit.Test;
-import org.openscience.cdk.Molecule;
+import org.openscience.cdk.AtomContainer;
+import org.openscience.cdk.DefaultChemObjectBuilder;
import org.openscience.cdk.exception.CDKException;
import org.openscience.cdk.interfaces.IAtomContainer;
import org.openscience.cdk.io.ISimpleChemObjectReader;
@@ -39,6 +36,10 @@
import org.openscience.cdk.tools.ILoggingTool;
import org.openscience.cdk.tools.LoggingToolFactory;
+import java.io.IOException;
+import java.io.StringReader;
+import java.util.BitSet;
+
/**
* @cdk.module test-standard
*/
@@ -81,15 +82,14 @@ public void testFingerprint() throws Exception {
* @throws Exception
*
* @cdk.bug 1626894
- *
- * @see testExtendedFingerPrint()
+ *
*/
@Test
public void testFingerPrint() throws Exception {
IFingerprinter printer = new GraphOnlyFingerprinter();
- Molecule mol1 = createMolecule(molecule_test_2);
- Molecule mol2 = createMolecule(ethanolamine);
+ IAtomContainer mol1 = createMolecule(molecule_test_2);
+ IAtomContainer mol2 = createMolecule(ethanolamine);
Assert.assertTrue("SubGraph does NOT match", UniversalIsomorphismTester.isSubgraph(mol1, mol2));
BitSet bs1 = printer.getFingerprint((IAtomContainer) mol1.clone());
@@ -101,13 +101,13 @@ public void testFingerPrint() throws Exception {
logger.debug("Subset (with fingerprint) does match");
}
- private static Molecule createMolecule(String molecule) throws IOException, CDKException {
- Molecule structure = null;
+ private static IAtomContainer createMolecule(String molecule) throws IOException, CDKException {
+ IAtomContainer structure = null;
if (molecule != null) {
ISimpleChemObjectReader reader = new MDLV2000Reader(new StringReader(molecule));
Assert.assertNotNull("Could not create reader", reader);
- if (reader.accepts(Molecule.class)) {
- structure = (Molecule) reader.read(new Molecule());
+ if (reader.accepts(AtomContainer.class)) {
+ structure = reader.read(DefaultChemObjectBuilder.getInstance().newInstance(IAtomContainer.class));
}
}
return structure;
@@ -24,16 +24,15 @@
package org.openscience.cdk.io;
import groovy.lang.GroovyShell;
-
-import java.io.StringWriter;
-
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.openscience.cdk.Atom;
import org.openscience.cdk.AtomContainer;
import org.openscience.cdk.Molecule;
+import java.io.StringWriter;
+
/**
* TestCase for the writer CDK source code files using one test file.
*
@@ -48,7 +47,6 @@
}
@Test public void testAccepts() throws Exception {
- Assert.assertTrue(chemObjectIO.accepts(Molecule.class));
Assert.assertTrue(chemObjectIO.accepts(AtomContainer.class));
}
@@ -28,15 +28,12 @@
*/
package org.openscience.cdk.io;
-import java.io.InputStream;
-
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.openscience.cdk.AtomContainerSet;
import org.openscience.cdk.ChemFile;
import org.openscience.cdk.ChemModel;
-import org.openscience.cdk.Molecule;
import org.openscience.cdk.Reaction;
import org.openscience.cdk.ReactionSet;
import org.openscience.cdk.exception.CDKException;
@@ -46,9 +43,12 @@
import org.openscience.cdk.interfaces.IChemObject;
import org.openscience.cdk.interfaces.IReaction;
import org.openscience.cdk.interfaces.IReactionSet;
+import org.openscience.cdk.silent.AtomContainer;
import org.openscience.cdk.tools.ILoggingTool;
import org.openscience.cdk.tools.LoggingToolFactory;
+import java.io.InputStream;
+
/**
* TestCase for the reading MDL RXN files using one test file.
*
@@ -72,7 +72,7 @@
Assert.assertTrue(reader.accepts(Reaction.class));
Assert.assertTrue(reader.accepts(ReactionSet.class));
Assert.assertFalse(reader.accepts(AtomContainerSet.class));
- Assert.assertFalse(reader.accepts(Molecule.class));
+ Assert.assertFalse(reader.accepts(AtomContainer.class));
}
@Test public void testReadReactions1() throws Exception {
@@ -24,10 +24,6 @@
* */
package org.openscience.cdk.io;
-import java.io.InputStream;
-import java.io.StringReader;
-import java.util.List;
-
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -48,6 +44,10 @@
import org.openscience.cdk.tools.LoggingToolFactory;
import org.openscience.cdk.tools.manipulator.ChemFileManipulator;
+import java.io.InputStream;
+import java.io.StringReader;
+import java.util.List;
+
/**
* TestCase for the reading MDL mol files using one test file.
* A test case for SDF files is available as separate Class.
@@ -71,7 +71,7 @@
reader.setReaderMode(Mode.STRICT);
Assert.assertTrue(reader.accepts(ChemFile.class));
Assert.assertTrue(reader.accepts(ChemModel.class));
- Assert.assertTrue(reader.accepts(Molecule.class));
+ Assert.assertTrue(reader.accepts(AtomContainer.class));
}
@Test public void testReadFromStringReader() throws Exception {
@@ -24,14 +24,6 @@
* */
package org.openscience.cdk.io;
-import java.io.InputStream;
-import java.io.StringReader;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-import java.util.Set;
-
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -58,6 +50,14 @@
import org.openscience.cdk.tools.manipulator.AtomContainerManipulator;
import org.openscience.cdk.tools.manipulator.ChemFileManipulator;
+import java.io.InputStream;
+import java.io.StringReader;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+
/**
* TestCase for the reading MDL mol files using one test file.
@@ -81,7 +81,6 @@
MDLV2000Reader reader = new MDLV2000Reader();
Assert.assertTrue(reader.accepts(ChemFile.class));
Assert.assertTrue(reader.accepts(ChemModel.class));
- Assert.assertTrue(reader.accepts(Molecule.class));
Assert.assertTrue(reader.accepts(AtomContainer.class));
}
@@ -23,12 +23,6 @@
*/
package org.openscience.cdk.io;
-import java.io.StringWriter;
-import java.util.Properties;
-
-import javax.vecmath.Point2d;
-import javax.vecmath.Point3d;
-
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -56,6 +50,11 @@
import org.openscience.cdk.smiles.SmilesParser;
import org.openscience.cdk.templates.MoleculeFactory;
+import javax.vecmath.Point2d;
+import javax.vecmath.Point3d;
+import java.io.StringWriter;
+import java.util.Properties;
+
/**
* TestCase for the writer MDL mol files using one test file.
@@ -77,7 +76,6 @@
MDLV2000Writer reader = new MDLV2000Writer();
Assert.assertTrue(reader.accepts(ChemFile.class));
Assert.assertTrue(reader.accepts(ChemModel.class));
- Assert.assertTrue(reader.accepts(Molecule.class));
Assert.assertTrue(reader.accepts(AtomContainer.class));
}
@@ -24,20 +24,19 @@
* */
package org.openscience.cdk.io;
-import java.io.InputStream;
-import java.io.StringReader;
-
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
-import org.openscience.cdk.Molecule;
import org.openscience.cdk.exception.CDKException;
import org.openscience.cdk.interfaces.IAtom;
import org.openscience.cdk.interfaces.IAtomContainer;
import org.openscience.cdk.silent.AtomContainer;
import org.openscience.cdk.tools.ILoggingTool;
import org.openscience.cdk.tools.LoggingToolFactory;
+import java.io.InputStream;
+import java.io.StringReader;
+
/**
* TestCase for the reading MDL V3000 mol files using one test file.
*
@@ -57,7 +56,7 @@
@Test public void testAccepts() {
MDLV3000Reader reader = new MDLV3000Reader();
- Assert.assertTrue(reader.accepts(Molecule.class));
+ Assert.assertTrue(reader.accepts(AtomContainer.class));
}
/**
@@ -27,14 +27,6 @@
* */
package org.openscience.cdk.io;
-import java.io.BufferedReader;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.StringReader;
-import java.util.Iterator;
-import java.util.List;
-import java.util.zip.GZIPInputStream;
-
import org.junit.Assert;
import org.junit.Assume;
import org.junit.BeforeClass;
@@ -49,12 +41,21 @@
import org.openscience.cdk.interfaces.IChemFile;
import org.openscience.cdk.interfaces.IChemModel;
import org.openscience.cdk.interfaces.IMolecule;
+import org.openscience.cdk.silent.AtomContainer;
import org.openscience.cdk.silent.SilentChemObjectBuilder;
import org.openscience.cdk.tools.ILoggingTool;
import org.openscience.cdk.tools.LoggingToolFactory;
import org.openscience.cdk.tools.manipulator.ChemFileManipulator;
import org.openscience.cdk.tools.manipulator.ChemModelManipulator;
+import java.io.BufferedReader;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.StringReader;
+import java.util.Iterator;
+import java.util.List;
+import java.util.zip.GZIPInputStream;
+
/**
* TestCase for the reading SYBYL mol2 files using a test file.
*
@@ -75,7 +76,7 @@
Mol2Reader reader = new Mol2Reader();
Assert.assertTrue(reader.accepts(ChemFile.class));
Assert.assertTrue(reader.accepts(ChemModel.class));
- Assert.assertTrue(reader.accepts(Molecule.class));
+ Assert.assertTrue(reader.accepts(AtomContainer.class));
}
/**
Oops, something went wrong.

0 comments on commit 436dba5

Please sign in to comment.