Skip to content

Commit

Permalink
Factored out the test for PDB atom customization; also fixed the test…
Browse files Browse the repository at this point in the history
… to register the customizer (but there is more wrong)

Change-Id: I02ada008ab0736a0137544266566ef96c21d4c56
Signed-off-by: John May <john.wilkinsonmay@gmail.com>

Conflicts:
	build.xml
	src/test/org/openscience/cdk/io/cml/CML2Test.java
  • Loading branch information
egonw authored and johnmay committed Jun 24, 2013
1 parent 2c48981 commit eb7e2b9
Show file tree
Hide file tree
Showing 7 changed files with 163 additions and 68 deletions.
4 changes: 2 additions & 2 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@
list="test-qsarprotein,test-qsarionpot,test-smsd,test-tautomer"/>
<foreach target="compile-module" param="module"
parallel="${parallel}" maxthreads="${threadCount}"
list="test-signature"/>
list="test-signature,test-pdbcml"/>
<foreach target="compile-module" param="module"
parallel="${parallel}" maxthreads="${threadCount}"
list="test-renderbasic"/>
Expand Down Expand Up @@ -1147,7 +1147,7 @@
structgen,libiomd,libiocml,formula,render,extra,fragment,sdg,
ioformats,log4j,smsd,signature,iordf,cip,tautomer,
isomorphism,renderbasic,renderawt,renderextra,silent,group,
hash"/>
hash,pdbcml"/>
</target>

<target id="limitations" name="limitations" depends="noJunit, dist-all"
Expand Down
11 changes: 11 additions & 0 deletions src/META-INF/test-pdbcml.cdkdepends
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
cdk-annotation.jar
cdk-core.jar
cdk-data.jar
cdk-pdb.jar
cdk-standard.jar
cdk-interfaces.jar
cdk-libiocml.jar
cdk-pdbcml.jar
cdk-io.jar
cdk-test.jar
cdk-testdata.jar
4 changes: 4 additions & 0 deletions src/META-INF/test-pdbcml.devellibdepends
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
junit-4.11.jar
hamcrest-core-1.3.jar


5 changes: 5 additions & 0 deletions src/META-INF/test-pdbcml.libdepends
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
vecmath*.jar
xom*.jar
cmlxom-2.5-b1.jar
log4j*.jar

67 changes: 1 addition & 66 deletions src/test/org/openscience/cdk/io/cml/CML2Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,12 @@
* */
package org.openscience.cdk.io.cml;

import java.io.ByteArrayInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.Iterator;

import org.junit.Assert;
import org.junit.Assume;
import org.junit.Test;
import org.openscience.cdk.CDKConstants;
import org.openscience.cdk.CDKTestCase;
Expand All @@ -44,16 +41,11 @@
import org.openscience.cdk.geometry.GeometryTools;
import org.openscience.cdk.interfaces.IAtom;
import org.openscience.cdk.interfaces.IAtomContainer;
import org.openscience.cdk.interfaces.IBioPolymer;
import org.openscience.cdk.interfaces.IChemFile;
import org.openscience.cdk.interfaces.IChemModel;
import org.openscience.cdk.interfaces.IChemSequence;
import org.openscience.cdk.interfaces.IReaction;
import org.openscience.cdk.io.CMLReader;
import org.openscience.cdk.io.CMLWriter;
import org.openscience.cdk.io.ISimpleChemObjectReader;
import org.openscience.cdk.io.PDBReader;
import org.openscience.cdk.protein.data.PDBPolymer;
import org.openscience.cdk.tools.ILoggingTool;
import org.openscience.cdk.tools.LoggingToolFactory;
import org.openscience.cdk.tools.manipulator.ChemFileManipulator;
Expand Down Expand Up @@ -686,64 +678,7 @@ public class CML2Test extends CDKTestCase {
// FIXME: REACT: It should return two different formulas
Assert.assertEquals("[C 18 H 21 Cl 2 Mn 1 N 5 O 1, C 4 H 10]", mol.getProperty(CDKConstants.FORMULA).toString());
}
/**
* @cdk.bug 1085912
*/
@Test public void testSFBug1085912_1() throws Exception {
Assume.assumeTrue(runSlowTests());

String filename_pdb = "data/pdb/1CKV.pdb";
// String filename_cml = "data/cml/1CKV_1.cml";
InputStream ins1 = this.getClass().getClassLoader().getResourceAsStream(filename_pdb);
// InputStream ins2 = this.getClass().getClassLoader().getResourceAsStream(filename_cml);

/*1*/
ISimpleChemObjectReader reader = new PDBReader(ins1);
IChemFile chemFile1 = (IChemFile) reader.read(new ChemFile());
IChemSequence seq1 = chemFile1.getChemSequence(0);
IChemModel model1 = seq1.getChemModel(0);
IAtomContainer container = model1.getMoleculeSet().getAtomContainer(0);
IBioPolymer polymer1 = (IBioPolymer)container;
int countchemFile1 = chemFile1.getChemSequenceCount();
// int countseq1 = seq1.getChemModelCount();
int countmodel1 = model1.getMoleculeSet().getAtomContainerCount();
int countpolymer1 = polymer1.getAtomCount();


StringWriter writer = new StringWriter();
CMLWriter cmlWriter = new CMLWriter(writer);
cmlWriter.write(polymer1);
String cmlContent1 = writer.toString();


/*2*/
CMLReader reader2 = new CMLReader(new ByteArrayInputStream(cmlContent1.getBytes()));
IChemFile chemFil2 = (IChemFile)reader2.read(new ChemFile());
IChemSequence seq2 = chemFil2.getChemSequence(0);
IChemModel model2 = seq2.getChemModel(0);
PDBPolymer polymer2 = (PDBPolymer) model2.getMoleculeSet().getAtomContainer(0);


int countchemFile2 = chemFil2.getChemSequenceCount();
// int countseq2 = seq2.getChemModelCount();
int countmodel2 = model2.getMoleculeSet().getAtomContainerCount();
int countpolymer2 = polymer2.getAtomCount();

Assert.assertEquals(countchemFile1, countchemFile2);
// Assert.assertEquals(countseq1,countseq2); /*not the same because the pdb file has more models*/
Assert.assertEquals(countmodel1,countmodel2);
Assert.assertEquals(countpolymer1,countpolymer2);


writer = new StringWriter();
cmlWriter = new CMLWriter(writer);
cmlWriter.write(polymer2);
String cmlContent2 = writer.toString();

String conte1 = cmlContent1.substring(0, 1000);
String conte2 = cmlContent2.substring(0, 1000);
Assert.assertEquals(conte1,conte2);
}

/**
* This test tests whether the CMLReader is able to ignore the CMLReaction part
* of a CML file, while extracting the reaction.
Expand Down
105 changes: 105 additions & 0 deletions src/test/org/openscience/cdk/io/cml/PDBAtomCustomizerTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/* Copyright (C) 2003-2007 The Chemistry Development Kit (CDK) project
* 2013 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.
* All we ask is that proper credit is given for our work, which includes
* - but is not limited to - adding the above copyright notice to the beginning
* of your source code files, and to any copyright notice that you may distribute
* with programs based on this work.
*
* 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.io.cml;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.io.StringWriter;

import org.junit.Assert;
import org.junit.Test;
import org.openscience.cdk.CDKTestCase;
import org.openscience.cdk.ChemFile;
import org.openscience.cdk.interfaces.IAtomContainer;
import org.openscience.cdk.interfaces.IBioPolymer;
import org.openscience.cdk.interfaces.IChemFile;
import org.openscience.cdk.interfaces.IChemModel;
import org.openscience.cdk.interfaces.IChemSequence;
import org.openscience.cdk.io.CMLReader;
import org.openscience.cdk.io.CMLWriter;
import org.openscience.cdk.io.ISimpleChemObjectReader;
import org.openscience.cdk.io.PDBReader;
import org.openscience.cdk.libio.cml.PDBAtomCustomizer;
import org.openscience.cdk.protein.data.PDBPolymer;

/**
* TestCase for the {@link PDBAtomCustomizer} class.
*
* @cdk.module test-pdbcml
*/
public class PDBAtomCustomizerTest extends CDKTestCase {

/**
* A roundtripping test to see of PDB atom customization works.
*
* @cdk.bug 1085912
*/
@Test public void testSFBug1085912_1() throws Exception {
String filename_pdb = "data/pdb/1CKV.pdb";
InputStream ins1 = this.getClass().getClassLoader().getResourceAsStream(filename_pdb);

ISimpleChemObjectReader reader = new PDBReader(ins1);
IChemFile chemFile1 = (IChemFile) reader.read(new ChemFile());
IChemSequence seq1 = chemFile1.getChemSequence(0);
IChemModel model1 = seq1.getChemModel(0);
IAtomContainer container = model1.getMoleculeSet().getAtomContainer(0);
IBioPolymer polymer1 = (IBioPolymer)container;
int countchemFile1 = chemFile1.getChemSequenceCount();
int countmodel1 = model1.getMoleculeSet().getAtomContainerCount();
int countpolymer1 = polymer1.getAtomCount();

StringWriter writer = new StringWriter();
CMLWriter cmlWriter = new CMLWriter(writer);
cmlWriter.registerCustomizer(new PDBAtomCustomizer());
cmlWriter.write(polymer1);
String cmlContent1 = writer.toString();
System.out.println(cmlContent1.substring(0, 500));

CMLReader reader2 = new CMLReader(new ByteArrayInputStream(cmlContent1.getBytes()));
IChemFile chemFil2 = (IChemFile)reader2.read(new ChemFile());
IChemSequence seq2 = chemFil2.getChemSequence(0);
IChemModel model2 = seq2.getChemModel(0);
PDBPolymer polymer2 = (PDBPolymer) model2.getMoleculeSet().getAtomContainer(0);

int countchemFile2 = chemFil2.getChemSequenceCount();
int countmodel2 = model2.getMoleculeSet().getAtomContainerCount();
int countpolymer2 = polymer2.getAtomCount();

Assert.assertEquals(countchemFile1, countchemFile2);
Assert.assertEquals(countmodel1,countmodel2);
Assert.assertEquals(countpolymer1,countpolymer2);

writer = new StringWriter();
cmlWriter = new CMLWriter(writer);
cmlWriter.registerCustomizer(new PDBAtomCustomizer());
cmlWriter.write(polymer2);
String cmlContent2 = writer.toString();
System.out.println(cmlContent2.substring(0, 500));

String conte1 = cmlContent1.substring(0, 1000);
String conte2 = cmlContent2.substring(0, 1000);
Assert.assertEquals(conte1,conte2);
}

}
35 changes: 35 additions & 0 deletions src/test/org/openscience/cdk/modulesuites/MpdbcmlTests.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/* Copyright (C) 2013 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.modulesuites;

import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
import org.openscience.cdk.io.cml.PDBAtomCustomizerTest;

/**
* TestSuite that runs all the unit tests for the CDK module pdbcml.
*
* @cdk.module test-pdbcml
*/
@RunWith(value=Suite.class)
@SuiteClasses(value={
PDBAtomCustomizerTest.class
})
public class MpdbcmlTests {}

0 comments on commit eb7e2b9

Please sign in to comment.