Permalink
Browse files

Updated casting to remove usage of Molecule

Signed-off-by: Egon Willighagen <egonw@users.sourceforge.net>
  • Loading branch information...
1 parent 6e6cf8e commit 04b1542ae9d38819c9e773027d2280f9072881fc @rajarshi rajarshi committed with egonw Dec 11, 2011
@@ -45,7 +45,7 @@
@Test public void testClone() throws Exception
{
IAtomContainer molecule = MoleculeFactory.makeAlphaPinene();
- Molecule clonedMol = (Molecule)molecule.clone();
+ IAtomContainer clonedMol = (IAtomContainer)molecule.clone();
Assert.assertTrue(molecule.getAtomCount() == clonedMol.getAtomCount());
for (int f = 0; f < molecule.getAtomCount(); f++)
{
@@ -18,14 +18,6 @@
*/
package org.openscience.cdk.geometry;
-import java.awt.geom.Rectangle2D;
-import java.io.InputStream;
-import java.util.HashMap;
-import java.util.Map;
-
-import javax.vecmath.Point2d;
-import javax.vecmath.Point3d;
-
import org.junit.Assert;
import org.junit.Test;
import org.openscience.cdk.Atom;
@@ -49,6 +41,13 @@
import org.openscience.cdk.isomorphism.AtomMappingTools;
import org.openscience.cdk.tools.diff.AtomContainerDiff;
+import javax.vecmath.Point2d;
+import javax.vecmath.Point3d;
+import java.awt.geom.Rectangle2D;
+import java.io.InputStream;
+import java.util.HashMap;
+import java.util.Map;
+
/**
* This class defines regression tests that should ensure that the source code
* of the {@link GeometryTools} is not broken.
@@ -123,15 +122,15 @@
String filenameMolTwo = "data/mdl/murckoTest6_3d.mol";
//String filenameMolTwo = "data/mdl/murckoTest6_3d_2.mol";
InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filenameMolOne);
- Molecule molOne=null;
- Molecule molTwo=null;
+ IAtomContainer molOne;
+ IAtomContainer molTwo;
Map mappedAtoms=new HashMap();
MDLV2000Reader reader = new MDLV2000Reader(ins, Mode.STRICT);
- molOne = (Molecule)reader.read(new Molecule());
+ molOne = reader.read(new Molecule());
ins = this.getClass().getClassLoader().getResourceAsStream(filenameMolTwo);
reader = new MDLV2000Reader(ins, Mode.STRICT);
- molTwo = (Molecule)reader.read(new Molecule());
+ molTwo = reader.read(new Molecule());
mappedAtoms=AtomMappingTools.mapAtomsOfAlignedStructures(molOne, molTwo, mappedAtoms);
//logger.debug("mappedAtoms:"+mappedAtoms.toString());
@@ -21,18 +21,13 @@
*/
package org.openscience.cdk.graph.invariant;
-import java.io.ByteArrayInputStream;
-import java.io.InputStream;
-import java.io.StringWriter;
-import java.util.Iterator;
-
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.openscience.cdk.CDKTestCase;
import org.openscience.cdk.ChemFile;
-import org.openscience.cdk.Molecule;
import org.openscience.cdk.DefaultChemObjectBuilder;
+import org.openscience.cdk.Molecule;
import org.openscience.cdk.atomtype.CDKAtomTypeMatcher;
import org.openscience.cdk.interfaces.IAtom;
import org.openscience.cdk.interfaces.IAtomContainer;
@@ -42,13 +37,18 @@
import org.openscience.cdk.interfaces.IMolecule;
import org.openscience.cdk.io.CMLReader;
import org.openscience.cdk.io.CMLWriter;
-import org.openscience.cdk.io.MDLReader;
import org.openscience.cdk.io.IChemObjectReader.Mode;
+import org.openscience.cdk.io.MDLReader;
import org.openscience.cdk.smiles.InvPair;
import org.openscience.cdk.smiles.SmilesParser;
import org.openscience.cdk.tools.CDKHydrogenAdder;
import org.openscience.cdk.tools.manipulator.AtomTypeManipulator;
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.io.StringWriter;
+import java.util.Iterator;
+
/**
* Checks the functionality of the CanonicalLabeler.
*
@@ -126,7 +126,7 @@ public void testSomeMoleculeWithDifferentStartingOrder() throws Exception {
String filename = "data/mdl/bug1014344-1.mol";
InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename);
MDLReader reader = new MDLReader(ins, Mode.STRICT);
- Molecule mol1 = (Molecule) reader.read(new Molecule());
+ IAtomContainer mol1 = reader.read(new Molecule());
addImplicitHydrogens(mol1);
StringWriter output=new StringWriter();
CMLWriter cmlWriter = new CMLWriter(output);
@@ -20,12 +20,6 @@
*/
package org.openscience.cdk.gui.smiles;
-import java.io.IOException;
-import java.io.InputStream;
-
-import javax.vecmath.Point2d;
-import javax.vecmath.Vector2d;
-
import org.junit.Assert;
import org.junit.Test;
import org.openscience.cdk.Atom;
@@ -44,7 +38,6 @@
import org.openscience.cdk.interfaces.IAtomType.Hybridization;
import org.openscience.cdk.interfaces.IBond;
import org.openscience.cdk.interfaces.IChemFile;
-import org.openscience.cdk.interfaces.IMolecule;
import org.openscience.cdk.io.CMLReader;
import org.openscience.cdk.io.IChemObjectReader.Mode;
import org.openscience.cdk.io.MDLReader;
@@ -58,6 +51,11 @@
import org.openscience.cdk.tools.manipulator.AtomContainerManipulator;
import org.openscience.cdk.tools.manipulator.ChemFileManipulator;
+import javax.vecmath.Point2d;
+import javax.vecmath.Vector2d;
+import java.io.IOException;
+import java.io.InputStream;
+
/**
*@author steinbeck
*@cdk.created February 9, 2004
@@ -239,7 +237,7 @@ public void setStandAlone(boolean standAlone)
@Test public void testCisResorcinol() throws Exception
{
HydrogenPlacer hydrogenPlacer = new HydrogenPlacer();
- Molecule mol1 = new Molecule();
+ IAtomContainer mol1 = new Molecule();
SmilesGenerator sg = new SmilesGenerator();
mol1.addAtom(new Atom("O", new Point2d(3, 1)));
// 1
@@ -314,7 +312,7 @@ public void setStandAlone(boolean standAlone)
}
Assert.assertNotNull(smiles1);
Assert.assertEquals("[H]O[C@]1(C([H])([H])C([H])([H])C([H])([H])C([H])([H])[C@]1(O[H])([H]))([H])", smiles1);
- mol1 = (Molecule) AtomContainerManipulator.removeHydrogens(mol1);
+ mol1 = AtomContainerManipulator.removeHydrogens(mol1);
try
{
smiles1 = sg.createSMILES(mol1);
@@ -832,13 +830,13 @@ private void fixCarbonHCount(IAtomContainer mol)
String filename = "data/mdl/l-ala.mol";
InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename);
MDLReader reader = new MDLReader(ins, Mode.STRICT);
- Molecule mol1 = (Molecule) reader.read(new Molecule());
+ IAtomContainer mol1 = reader.read(new Molecule());
addExplicitHydrogens(mol1);
new HydrogenPlacer().placeHydrogens2D(mol1, 1.0);
filename = "data/mdl/d-ala.mol";
ins = this.getClass().getClassLoader().getResourceAsStream(filename);
reader = new MDLReader(ins, Mode.STRICT);
- Molecule mol2 = (Molecule) reader.read(new Molecule());
+ IAtomContainer mol2 = reader.read(new Molecule());
addExplicitHydrogens(mol2);
new HydrogenPlacer().placeHydrogens2D(mol2, 1.0);
SmilesGenerator sg = new SmilesGenerator();
@@ -862,13 +860,13 @@ private void fixCarbonHCount(IAtomContainer mol)
String filename = "data/mdl/D-mannose.mol";
InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename);
MDLReader reader = new MDLReader(ins, Mode.STRICT);
- Molecule mol1 = (Molecule) reader.read(new Molecule());
+ IAtomContainer mol1 = reader.read(new Molecule());
addExplicitHydrogens(mol1);
new HydrogenPlacer().placeHydrogens2D(mol1, 1.0);
filename = "data/mdl/D+-glucose.mol";
ins = this.getClass().getClassLoader().getResourceAsStream(filename);
reader = new MDLReader(ins, Mode.STRICT);
- Molecule mol2 = (Molecule) reader.read(new Molecule());
+ IAtomContainer mol2 = reader.read(new Molecule());
addExplicitHydrogens(mol2);
new HydrogenPlacer().placeHydrogens2D(mol2, 1.0);
SmilesGenerator sg = new SmilesGenerator();
@@ -907,7 +905,7 @@ private void display(IAtomContainer molecule)
String filename = "data/mdl/cyclooctan.mol";
InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename);
MDLV2000Reader reader = new MDLV2000Reader(ins, Mode.STRICT);
- Molecule mol1 = (Molecule) reader.read(new Molecule());
+ IAtomContainer mol1 = reader.read(new Molecule());
SmilesGenerator sg = new SmilesGenerator();
String moleculeSmile = sg.createSMILES(mol1);
Assert.assertEquals(moleculeSmile, "C1=CCCCCCC1");
@@ -930,7 +928,7 @@ private void display(IAtomContainer molecule)
String filename = "data/mdl/cycloocten.mol";
InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename);
MDLV2000Reader reader = new MDLV2000Reader(ins, Mode.STRICT);
- Molecule mol1 = (Molecule) reader.read(new Molecule());
+ IAtomContainer mol1 = reader.read(new Molecule());
SmilesGenerator sg = new SmilesGenerator();
String moleculeSmile = sg.createSMILES(mol1);
Assert.assertEquals(moleculeSmile, "C1C=CCCCCC1");
@@ -953,7 +951,7 @@ private void display(IAtomContainer molecule)
String filename = "data/mdl/cyclooctadien.mol";
InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename);
MDLV2000Reader reader = new MDLV2000Reader(ins, Mode.STRICT);
- Molecule mol1 = (Molecule) reader.read(new Molecule());
+ IAtomContainer mol1 = reader.read(new Molecule());
SmilesGenerator sg = new SmilesGenerator();
String moleculeSmile = sg.createSMILES(mol1);
Assert.assertEquals(moleculeSmile, "C=1CCC=CCCC=1");
@@ -977,7 +975,7 @@ private void display(IAtomContainer molecule)
String filename = "data/mdl/bug1089770-1.mol";
InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename);
MDLV2000Reader reader = new MDLV2000Reader(ins, Mode.STRICT);
- Molecule mol1 = (Molecule) reader.read(new Molecule());
+ IAtomContainer mol1 = reader.read(new Molecule());
SmilesGenerator sg = new SmilesGenerator();
String moleculeSmile = sg.createSMILES(mol1);
//logger.debug(filename + " -> " + moleculeSmile);
@@ -1002,7 +1000,7 @@ private void display(IAtomContainer molecule)
String filename = "data/mdl/bug1089770-2.mol";
InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename);
MDLV2000Reader reader = new MDLV2000Reader(ins, Mode.STRICT);
- Molecule mol1 = (Molecule) reader.read(new Molecule());
+ IAtomContainer mol1 = reader.read(new Molecule());
SmilesGenerator sg = new SmilesGenerator();
String moleculeSmile = sg.createSMILES(mol1);
//logger.debug(filename + " -> " + moleculeSmile);
@@ -1025,7 +1023,7 @@ private void display(IAtomContainer molecule)
AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(mol);
SmilesGenerator sg = new SmilesGenerator();
sg.setUseAromaticityFlag(true);
- String s1 = sg.createSMILES((IMolecule) mol);
+ String s1 = sg.createSMILES(mol);
String filename = "data/cml/bug1535055.cml";
InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename);
@@ -1037,7 +1035,7 @@ private void display(IAtomContainer molecule)
IAtomContainer mol2 = ChemFileManipulator.getAllAtomContainers(chemFile).get(0);
CDKHueckelAromaticityDetector.detectAromaticity(mol2);
AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(mol2);
- String s2 = sg.createSMILES((IMolecule) mol2);
+ String s2 = sg.createSMILES(mol2);
Assert.assertTrue(s1.contains("[nH]"));
Assert.assertTrue(s2.contains("[nH]"));
@@ -27,16 +27,17 @@
* */
package org.openscience.cdk.io;
-import java.io.ByteArrayInputStream;
-import java.io.InputStream;
-import java.io.StringWriter;
-
import org.junit.Assert;
import org.junit.Test;
-import org.openscience.cdk.Molecule;
import org.openscience.cdk.CDKTestCase;
+import org.openscience.cdk.Molecule;
+import org.openscience.cdk.interfaces.IAtomContainer;
import org.openscience.cdk.interfaces.IChemFile;
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.io.StringWriter;
+
/**
* Combined TestCase for the reading/writing of mdl and cml files.
*
@@ -60,7 +61,7 @@ public void testBug1649526() throws Exception{
String filename = "data/mdl/bug-1649526.mol";
InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename);
MDLReader reader = new MDLReader(ins);
- Molecule mol = (Molecule)reader.read(new Molecule());
+ IAtomContainer mol = reader.read(new Molecule());
//Write it as cml
StringWriter writer = new StringWriter();
CMLWriter cmlWriter = new CMLWriter(writer);
@@ -141,7 +141,7 @@
" 1 0 0 0 0 1\n" +
" -0.0073 -0.5272 0.9655 H 0 3 0 0 0\n";
MDLReader reader = new MDLReader(new StringReader(mdl), Mode.STRICT);
- Molecule mol = (Molecule)reader.read(new Molecule());
+ IAtomContainer mol = reader.read(new Molecule());
Assert.assertNotNull(mol);
Assert.assertEquals(1, mol.getAtomCount());
Assert.assertEquals(0, mol.getBondCount());
@@ -227,9 +227,9 @@
public void testHas2DCoordinates_With000() throws CDKException {
String filenameMol = "data/mdl/with000coordinate.mol";
InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filenameMol);
- Molecule molOne=null;
+ IAtomContainer molOne=null;
MDLReader reader = new MDLReader(ins, Mode.RELAXED);
- molOne = (Molecule)reader.read(new Molecule());
+ molOne = reader.read(new Molecule());
Assert.assertNotNull(molOne.getAtom(0).getPoint2d());
}
}
@@ -701,7 +701,7 @@
logger.info("Testing: " + filename);
InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename);
MDLV2000Reader reader = new MDLV2000Reader(ins);
- Molecule mol = (Molecule)reader.read(new Molecule());
+ IAtomContainer mol = reader.read(new Molecule());
for(IBond bond: mol.bonds() ) {
IPseudoAtom rGroup = null;
IAtom partner=null;
@@ -743,9 +743,9 @@
logger.info("Testing: " + filename);
InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename);
MDLV2000Reader reader = new MDLV2000Reader(ins);
- Molecule mol = (Molecule)reader.read(new Molecule());
+ IAtomContainer mol = reader.read(DefaultChemObjectBuilder.getInstance().newInstance(IAtomContainer.class));
for(IBond bond: mol.bonds() ) {
- IPseudoAtom rGroup = null;
+ IPseudoAtom rGroup;
if (bond.getAtom(0) instanceof IPseudoAtom )
rGroup = (IPseudoAtom)bond.getAtom(0);
else
@@ -816,9 +816,9 @@ private void testShortLinesForMode (IChemObjectReader.Mode mode) throws Exceptio
@Test public void testHas2DCoordinates_With000() throws CDKException {
String filenameMol = "data/mdl/with000coordinate.mol";
InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filenameMol);
- Molecule molOne=null;
+ IAtomContainer molOne=null;
MDLV2000Reader reader = new MDLV2000Reader(ins, Mode.STRICT);
- molOne = (Molecule)reader.read(new Molecule());
+ molOne = reader.read(new Molecule());
Assert.assertNotNull(molOne.getAtom(0).getPoint2d());
Assert.assertNotNull(molOne.getAtom(0).getPoint3d());
}
@@ -827,8 +827,8 @@ private void testShortLinesForMode (IChemObjectReader.Mode mode) throws Exceptio
String filename = "data/mdl/atomValueLines.mol";
InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename);
MDLV2000Reader reader = new MDLV2000Reader(ins);
- Molecule testMolecule = new Molecule();
- Molecule result = reader.read(testMolecule);
+ IAtomContainer testMolecule = DefaultChemObjectBuilder.getInstance().newInstance(IAtomContainer.class);
+ IAtomContainer result = reader.read(testMolecule);
IAtom oxygen = result.getAtom(0);
Assert.assertTrue(oxygen.getSymbol().equals("O"));
Assert.assertEquals(oxygen.getProperty(CDKConstants.COMMENT), "Oxygen comment");
@@ -32,7 +32,6 @@
import org.openscience.cdk.CDKConstants;
import org.openscience.cdk.CDKTestCase;
import org.openscience.cdk.DefaultChemObjectBuilder;
-import org.openscience.cdk.Molecule;
import org.openscience.cdk.exception.CDKException;
import org.openscience.cdk.geometry.GeometryTools;
import org.openscience.cdk.interfaces.IAtomContainer;
@@ -122,7 +121,7 @@ public boolean ready() throws IOException {
Object object = reader.next();
Assert.assertNotNull(object);
Assert.assertTrue(object instanceof IAtomContainer);
- Assert.assertEquals("2-methylbenzo-1,4-quinone", ((Molecule) object).getProperty(CDKConstants.TITLE));
+ Assert.assertEquals("2-methylbenzo-1,4-quinone", ((IAtomContainer) object).getProperty(CDKConstants.TITLE));
Assert.assertEquals(MDLV2000Format.getInstance(), reader.getFormat());
}
@@ -139,7 +138,7 @@ public boolean ready() throws IOException {
Object object = reader.next();
Assert.assertNotNull(object);
Assert.assertTrue(object instanceof IAtomContainer);
- Molecule m = (Molecule) object;
+ IAtomContainer m = (IAtomContainer) object;
Assert.assertEquals("1", m.getProperty("E_NSC"));
Assert.assertEquals("553-97-9", m.getProperty("E_CAS"));
}
Oops, something went wrong. Retry.

0 comments on commit 04b1542

Please sign in to comment.