Skip to content

Commit

Permalink
Merge branch 'cdk-1.4.x' of git@github.com:cdk/cdk into cdk-1.4.x
Browse files Browse the repository at this point in the history
  • Loading branch information
rajarshi committed Jan 23, 2012
2 parents e2344ff + 03ef86b commit 652b5e2
Show file tree
Hide file tree
Showing 9 changed files with 190 additions and 34 deletions.
1 change: 1 addition & 0 deletions build.xml
Expand Up @@ -303,6 +303,7 @@
<param name="module" value="${module}"/>
</antcall>

<ant antfile="javadoc.xml" target="compileDocTests"/>
<ant antfile="javadoc.xml" target="ojdcheck-module">
<property name="module" value="${module}"/>
</ant>
Expand Down
1 change: 1 addition & 0 deletions javadoc.xml
Expand Up @@ -241,6 +241,7 @@
<classpath>
<fileset dir="develjar/">
<include name="ojdcheck.jar" />
<include name="com-sun-*.jar" />
</fileset>
</classpath>
</javac>
Expand Down
17 changes: 11 additions & 6 deletions src/main/org/openscience/cdk/io/MDLV2000Reader.java
Expand Up @@ -29,6 +29,7 @@
import org.openscience.cdk.config.IsotopeFactory;
import org.openscience.cdk.exception.CDKException;
import org.openscience.cdk.interfaces.IAtom;
import org.openscience.cdk.interfaces.IAtomContainer;
import org.openscience.cdk.interfaces.IBond;
import org.openscience.cdk.interfaces.IChemFile;
import org.openscience.cdk.interfaces.IChemModel;
Expand Down Expand Up @@ -64,7 +65,7 @@

/**
* Reads content from MDL molfiles and SD files.
* It can read a {@link IMolecule} or {@link IChemModel} from an MDL molfile, and
* It can read a {@link IAtomContainer} or {@link IChemModel} from an MDL molfile, and
* a {@link IChemFile} from a SD file, with a {@link IChemSequence} of
* {@link IChemModel}'s, where each IChemModel will contain one IMolecule.
*
Expand Down Expand Up @@ -164,6 +165,7 @@ public boolean accepts(Class<? extends IChemObject> classObject) {
if (IChemFile.class.equals(interfaces[i])) return true;
if (IChemModel.class.equals(interfaces[i])) return true;
if (IMolecule.class.equals(interfaces[i])) return true;
if (IAtomContainer.class.equals(interfaces[i])) return true;
}
Class superClass = classObject.getSuperclass();
if (superClass != null) return this.accepts(superClass);
Expand All @@ -187,6 +189,8 @@ public <T extends IChemObject> T read(T object) throws CDKException {
return (T)readChemModel((IChemModel)object);
} else if (object instanceof IMolecule) {
return (T)readMolecule((IMolecule)object);
} else if (object instanceof IAtomContainer) {
return (T)readMolecule(object.getBuilder().newInstance(IMolecule.class, object));
} else {
throw new CDKException("Only supported are ChemFile and Molecule.");
}
Expand Down Expand Up @@ -478,15 +482,16 @@ private IMolecule readMolecule(IMolecule molecule) throws CDKException {
}
}
else {
atom = molecule.getBuilder().newInstance(IPseudoAtom.class,"R");
atom = molecule.getBuilder().newInstance(IPseudoAtom.class,element);
}
} else {
handleError(
"Invalid element type. Must be an existing " +
"element, or one in: A, Q, L, LP, *.",
linecount, 32, 35
"Invalid element type. Must be an existing " +
"element, or one in: A, Q, L, LP, *.",
linecount, 32, 35
);
atom = molecule.getBuilder().newInstance(IPseudoAtom.class,element);
atom = molecule.getBuilder().newInstance(IPseudoAtom.class, element);
atom.setSymbol(element);
}

// store as 3D for now, convert to 2D (if totalZ == 0.0) later
Expand Down
43 changes: 18 additions & 25 deletions src/main/org/openscience/cdk/io/MDLV3000Reader.java
Expand Up @@ -20,22 +20,6 @@
*/
package org.openscience.cdk.io;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.StringReader;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.vecmath.Point2d;
import javax.vecmath.Point3d;

import org.openscience.cdk.CDKConstants;
import org.openscience.cdk.annotations.TestClass;
import org.openscience.cdk.annotations.TestMethod;
Expand All @@ -55,6 +39,21 @@
import org.openscience.cdk.tools.LoggingToolFactory;
import org.openscience.cdk.tools.manipulator.BondManipulator;

import javax.vecmath.Point2d;
import javax.vecmath.Point3d;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.StringReader;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
* Class that implements the MDL mol V3000 format. This reader reads the
* element symbol and 2D or 3D coordinates from the ATOM block.
Expand Down Expand Up @@ -129,14 +128,15 @@ public boolean accepts(Class classObject) {
Class[] interfaces = classObject.getInterfaces();
for (int i=0; i<interfaces.length; i++) {
if (IMolecule.class.equals(interfaces[i])) return true;
if (IAtomContainer.class.equals(interfaces[i])) return true;
}
Class superClass = classObject.getSuperclass();
if (superClass != null) return this.accepts(superClass);
return false;
}

public <T extends IChemObject> T read(T object) throws CDKException {
if (object instanceof IMolecule) {
if (object instanceof IAtomContainer) {
return (T)readMolecule(object.getBuilder());
}
return null;
Expand Down Expand Up @@ -272,6 +272,7 @@ public void readAtomBlock(IAtomContainer readData) throws CDKException {
throw new CDKException("Invalid element type. Must be an existing element, or one in: A, Q, L, LP, *.");
}
atom = readData.getBuilder().newInstance(IPseudoAtom.class,element);
atom.setSymbol(element);
}

// parse atom coordinates (in Angstrom)
Expand Down Expand Up @@ -585,14 +586,6 @@ public boolean isReady() throws CDKException {
}
}

@TestMethod("testAccepts")
public boolean accepts(IChemObject object) {
if (object instanceof IMolecule) {
return true;
}
return false;
}

@TestMethod("testClose")
public void close() throws IOException {
input.close();
Expand Down
78 changes: 78 additions & 0 deletions src/test/data/mdl/pseudoatoms.sdf
@@ -0,0 +1,78 @@

-OEChem-01171208162D

31 32 0 1 0 0 0 0 0999 V2000
2.2700 -0.5000 0.0000 C 0 0 3 0 0 0 0 0 0 0 0 0
-1.2200 -0.1300 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
2.9600 -0.7000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
-0.6200 1.4900 0.0000 N 0 0 0 0 0 0 0 0 0 0 0 0
-0.1200 -1.4500 0.0000 Gln 0 0 0 0 0 0 0 0 0 0 0 0
-0.8400 -0.9400 0.0000 Ile 0 0 0 0 0 0 0 0 0 0 0 0
0.7600 -1.5400 0.0000 Asn 0 0 0 0 0 0 0 0 0 0 0 0
-1.1200 0.7400 0.0000 C 0 0 3 0 0 0 0 0 0 0 0 0
1.7600 -1.2400 0.0000 N 0 0 0 0 0 0 0 0 0 0 0 0
0.2000 1.8500 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
3.1800 -1.5400 0.0000 Pro 0 0 0 0 0 0 0 0 0 0 0 0
4.0200 -1.7800 0.0000 Leu 0 0 0 0 0 0 0 0 0 0 0 0
4.2600 -2.6500 0.0000 Gly 0 0 0 0 0 0 0 0 0 0 0 0
-2.1000 -0.2500 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0
3.5800 -0.0700 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0
-1.8400 1.2800 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
0.0400 2.7500 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0
5.1000 -2.8900 0.0000 N 0 0 0 0 0 0 0 0 0 0 0 0
-2.6800 0.9200 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
2.5400 -1.2400 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
2.4300 0.5500 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
2.0800 -1.9900 0.0000 S 0 0 0 0 0 0 0 0 0 0 0 0
-4.3000 0.1700 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
-3.4000 1.4300 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
-2.7800 0.0200 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
-4.2200 1.0700 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
-3.5800 -0.3400 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
-5.1200 -0.1900 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0
1.0900 1.8600 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
1.9800 1.4100 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
-5.2200 -1.0600 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
2 6 1 0 0 0 0
1 3 1 0 0 0 0
4 10 1 0 0 0 0
5 7 1 0 0 0 0
5 6 1 0 0 0 0
7 9 1 0 0 0 0
4 8 1 0 0 0 0
1 9 1 0 0 0 0
10 29 1 0 0 0 0
3 11 1 0 0 0 0
11 12 1 0 0 0 0
12 13 1 0 0 0 0
2 14 2 0 0 0 0
3 15 2 0 0 0 0
8 16 1 0 0 0 0
10 17 2 0 0 0 0
13 18 1 0 0 0 0
16 19 1 0 0 0 0
1 20 1 0 0 0 0
1 21 1 0 0 0 0
20 22 1 0 0 0 0
23 26 2 0 0 0 0
19 24 2 0 0 0 0
19 25 1 0 0 0 0
24 26 1 0 0 0 0
25 27 2 0 0 0 0
23 28 1 0 0 0 0
29 30 1 0 0 0 0
21 30 1 0 0 0 0
28 31 1 0 0 0 0
2 8 1 0 0 0 0
23 27 1 0 0 0 0
M END
> <Index_Number>
00819

> <Name>
Carbetocin

> <Entry_Date>
6/19/1990

$$$$
32 changes: 32 additions & 0 deletions src/test/data/mdl/pseudoatomsv3000.mol
@@ -0,0 +1,32 @@

Marvin 01211213222D

0 0 0 0 0 999 V3000
M V30 BEGIN CTAB
M V30 COUNTS 10 10 0 0 0
M V30 BEGIN ATOM
M V30 1 C -1.925 0.935 0 0
M V30 2 C -3.2587 0.165 0 0
M V30 3 C -3.2587 -1.375 0 0
M V30 4 C -1.925 -2.145 0 0
M V30 5 C -0.5913 -1.375 0 0
M V30 6 C -0.5913 0.165 0 0
M V30 7 C 0.8962 0.5636 0 0
M V30 8 C 2.2299 -0.2064 0 0
M V30 9 C 3.7174 0.1922 0 0
M V30 10 Leu 0.8962 2.1036 0 0
M V30 END ATOM
M V30 BEGIN BOND
M V30 1 1 1 2
M V30 2 2 1 6
M V30 3 2 2 3
M V30 4 1 3 4
M V30 5 2 4 5
M V30 6 1 5 6
M V30 7 1 6 7
M V30 8 1 7 8
M V30 9 1 8 9
M V30 10 1 7 10
M V30 END BOND
M V30 END CTAB
M END
14 changes: 14 additions & 0 deletions src/test/org/openscience/cdk/io/MDLV2000ReaderTest.java
Expand Up @@ -56,6 +56,7 @@
import java.util.Properties;
import java.util.Set;


/**
* TestCase for the reading MDL mol files using one test file.
* A test case for SDF files is available as separate Class.
Expand Down Expand Up @@ -905,4 +906,17 @@ public void testAliasAtomNaming() throws Exception {
}
Assert.assertEquals(2, r1Count);
}

@Test
public void testPseudoAtomLabels() throws Exception {
InputStream in = ClassLoader.getSystemResourceAsStream("data/mdl/pseudoatoms.sdf");
MDLV2000Reader reader = new MDLV2000Reader(in);
IAtomContainer molecule = DefaultChemObjectBuilder.getInstance().newInstance(IAtomContainer.class);
molecule = reader.read(molecule);
Assert.assertTrue(molecule.getAtom(4) instanceof IPseudoAtom);
Assert.assertEquals("Gln", molecule.getAtom(4).getSymbol());
IPseudoAtom pa = (IPseudoAtom) molecule.getAtom(4);
Assert.assertEquals("Gln", pa.getLabel());
}

}
23 changes: 20 additions & 3 deletions src/test/org/openscience/cdk/io/MDLV2000WriterTest.java
Expand Up @@ -23,8 +23,9 @@
*/
package org.openscience.cdk.io;

import java.io.StringWriter;

import java.io.InputStream;
import java.io.StringWriter;
import java.util.Properties;

import javax.vecmath.Point2d;
Expand All @@ -33,7 +34,6 @@
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.Bond;
Expand All @@ -45,6 +45,7 @@
import org.openscience.cdk.PseudoAtom;
import org.openscience.cdk.exception.CDKException;
import org.openscience.cdk.interfaces.IAtom;
import org.openscience.cdk.interfaces.IAtomContainer;
import org.openscience.cdk.interfaces.IBond;
import org.openscience.cdk.interfaces.IBond.Order;
import org.openscience.cdk.interfaces.IChemModel;
Expand Down Expand Up @@ -358,5 +359,21 @@ public void testUnsupportedBondOrder() throws Exception {
mdlWriter.write(benzene);
Assert.assertTrue(writer.toString().indexOf("2 1 4 0 0 0 0") != -1);
}


@Test
public void testWritePseudoAtoms() throws Exception {
InputStream in = ClassLoader.getSystemResourceAsStream("data/mdl/pseudoatoms.sdf");
MDLV2000Reader reader = new MDLV2000Reader(in);
IAtomContainer molecule = DefaultChemObjectBuilder.getInstance().newInstance(IAtomContainer.class);
molecule = reader.read(molecule);

StringWriter writer = new StringWriter();
MDLV2000Writer mwriter = new MDLV2000Writer(writer);
mwriter.write(molecule);

String output = writer.toString();
Assert.assertTrue(output.indexOf("Gln") != -1);
Assert.assertTrue(output.indexOf("Leu") != -1);
}

}
15 changes: 15 additions & 0 deletions src/test/org/openscience/cdk/io/MDLV3000ReaderTest.java
Expand Up @@ -30,10 +30,13 @@
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.openscience.cdk.DefaultChemObjectBuilder;
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.interfaces.IMolecule;
import org.openscience.cdk.interfaces.IPseudoAtom;
import org.openscience.cdk.nonotify.NNMolecule;
import org.openscience.cdk.tools.ILoggingTool;
import org.openscience.cdk.tools.LoggingToolFactory;
Expand Down Expand Up @@ -91,4 +94,16 @@ public class MDLV3000ReaderTest extends SimpleChemObjectReaderTest {
}
}

@Test
public void testPseudoAtomLabels() throws Exception {
InputStream in = ClassLoader.getSystemResourceAsStream("data/mdl/pseudoatomsv3000.mol");
MDLV3000Reader reader = new MDLV3000Reader(in);
IAtomContainer molecule = DefaultChemObjectBuilder.getInstance().newInstance(IAtomContainer.class);
molecule = reader.read(molecule);
Assert.assertTrue(molecule.getAtom(9) instanceof IPseudoAtom);
Assert.assertEquals("Leu", molecule.getAtom(9).getSymbol());
IPseudoAtom pa = (IPseudoAtom) molecule.getAtom(9);
Assert.assertEquals("Leu", pa.getLabel());
}

}

0 comments on commit 652b5e2

Please sign in to comment.