📄 cml2test.java
字号:
/* $RCSfile$ * $Author: egonw $ * $Date: 2007-05-05 12:00:36 +0000 (Sa, 05 Mai 2007) $ * $Revision: 8301 $ * * Copyright (C) 2003-2007 The Chemistry Development Kit (CDK) project * * 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.test.io.cml;import java.io.ByteArrayInputStream;import java.io.InputStream;import java.io.StringWriter;import junit.framework.Test;import junit.framework.TestSuite;import org.openscience.cdk.geometry.GeometryToolsInternalCoordinates;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.IMolecule;import org.openscience.cdk.interfaces.IReaction;import org.openscience.cdk.io.CMLReader;import org.openscience.cdk.io.CMLWriter;import org.openscience.cdk.io.IChemObjectReader;import org.openscience.cdk.io.PDBReader;import org.openscience.cdk.nonotify.NNChemFile;import org.openscience.cdk.protein.data.PDBPolymer;import org.openscience.cdk.test.CDKTestCase;/** * TestCase for the reading CML 2 files using a few test files * in data/cmltest. * * @cdk.module test-io * @cdk.require java1.5+ */public class CML2Test extends CDKTestCase { private org.openscience.cdk.tools.LoggingTool logger; public CML2Test(String name) { super(name); logger = new org.openscience.cdk.tools.LoggingTool(this); } public static Test suite() { return new TestSuite(CML2Test.class); } public void testCOONa() throws Exception { String filename = "data/cml/COONa.cml"; logger.info("Testing: " + filename); InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); CMLReader reader = new CMLReader(ins); IChemFile chemFile = (IChemFile)reader.read(new org.openscience.cdk.ChemFile()); // test the resulting ChemFile content assertNotNull(chemFile); assertEquals(chemFile.getChemSequenceCount(), 1); org.openscience.cdk.interfaces.IChemSequence seq = chemFile.getChemSequence(0); assertNotNull(seq); assertEquals(seq.getChemModelCount(), 1); org.openscience.cdk.interfaces.IChemModel model = seq.getChemModel(0); assertNotNull(model); assertEquals(model.getMoleculeSet().getMoleculeCount(), 1); // test the molecule org.openscience.cdk.interfaces.IMolecule mol = model.getMoleculeSet().getMolecule(0); assertNotNull(mol); assertEquals(4, mol.getAtomCount()); assertEquals(2, mol.getBondCount()); assertTrue(GeometryToolsInternalCoordinates.has3DCoordinates(mol)); assertTrue(!GeometryToolsInternalCoordinates.has2DCoordinates(mol)); java.util.Iterator atoms = mol.atoms(); while (atoms.hasNext()) { org.openscience.cdk.interfaces.IAtom atom = (IAtom)atoms.next(); if (atom.getSymbol().equals("Na")) assertEquals(+1, atom.getFormalCharge()); } } public void testNitrate() throws Exception { String filename = "data/cml/nitrate.cml"; logger.info("Testing: " + filename); InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); CMLReader reader = new CMLReader(ins); IChemFile chemFile = (IChemFile)reader.read(new org.openscience.cdk.ChemFile()); // test the resulting ChemFile content assertNotNull(chemFile); assertEquals(chemFile.getChemSequenceCount(), 1); org.openscience.cdk.interfaces.IChemSequence seq = chemFile.getChemSequence(0); assertNotNull(seq); assertEquals(seq.getChemModelCount(), 1); org.openscience.cdk.interfaces.IChemModel model = seq.getChemModel(0); assertNotNull(model); assertEquals(model.getMoleculeSet().getMoleculeCount(), 1); // test the molecule org.openscience.cdk.interfaces.IMolecule mol = model.getMoleculeSet().getMolecule(0); assertNotNull(mol); assertEquals(4, mol.getAtomCount()); assertEquals(3, mol.getBondCount()); assertTrue(GeometryToolsInternalCoordinates.has3DCoordinates(mol)); assertTrue(!GeometryToolsInternalCoordinates.has2DCoordinates(mol)); java.util.Iterator atoms = mol.atoms(); while (atoms.hasNext()) { org.openscience.cdk.interfaces.IAtom atom = (IAtom)atoms.next(); if (atom.getSymbol().equals("N")) assertEquals(+1, atom.getFormalCharge()); } } public void testCMLOK1() throws Exception { String filename = "data/cml/cs2a.cml"; logger.info("Testing: " + filename); InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); CMLReader reader = new CMLReader(ins); IChemFile chemFile = (IChemFile)reader.read(new org.openscience.cdk.ChemFile()); // test the resulting ChemFile content assertNotNull(chemFile); assertEquals(chemFile.getChemSequenceCount(), 1); org.openscience.cdk.interfaces.IChemSequence seq = chemFile.getChemSequence(0); assertNotNull(seq); assertEquals(seq.getChemModelCount(), 1); org.openscience.cdk.interfaces.IChemModel model = seq.getChemModel(0); assertNotNull(model); assertEquals(model.getMoleculeSet().getMoleculeCount(), 1); // test the molecule org.openscience.cdk.interfaces.IMolecule mol = model.getMoleculeSet().getMolecule(0); assertNotNull(mol); assertEquals(38, mol.getAtomCount()); assertEquals(48, mol.getBondCount()); assertTrue(GeometryToolsInternalCoordinates.has3DCoordinates(mol)); assertFalse(GeometryToolsInternalCoordinates.has2DCoordinates(mol)); } public void testCMLOK2() throws Exception { String filename = "data/cml/cs2a.mol.cml"; logger.info("Testing: " + filename); InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); CMLReader reader = new CMLReader(ins); IChemFile chemFile = (IChemFile)reader.read(new org.openscience.cdk.ChemFile()); // test the resulting ChemFile content assertNotNull(chemFile); assertEquals(chemFile.getChemSequenceCount(), 1); org.openscience.cdk.interfaces.IChemSequence seq = chemFile.getChemSequence(0); assertNotNull(seq); assertEquals(seq.getChemModelCount(), 1); org.openscience.cdk.interfaces.IChemModel model = seq.getChemModel(0); assertNotNull(model); assertEquals(model.getMoleculeSet().getMoleculeCount(), 1); // test the molecule org.openscience.cdk.interfaces.IMolecule mol = model.getMoleculeSet().getMolecule(0); assertNotNull(mol); assertEquals(38, mol.getAtomCount()); assertEquals(29, mol.getBondCount()); assertTrue(GeometryToolsInternalCoordinates.has3DCoordinates(mol)); assertFalse(GeometryToolsInternalCoordinates.has2DCoordinates(mol)); } public void testCMLOK3() throws Exception { String filename = "data/cml/nsc2dmol.1.cml"; logger.info("Testing: " + filename); InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); CMLReader reader = new CMLReader(ins); IChemFile chemFile = (IChemFile)reader.read(new org.openscience.cdk.ChemFile()); // test the resulting ChemFile content assertNotNull(chemFile); assertEquals(chemFile.getChemSequenceCount(), 1); org.openscience.cdk.interfaces.IChemSequence seq = chemFile.getChemSequence(0); assertNotNull(seq); assertEquals(seq.getChemModelCount(), 1); org.openscience.cdk.interfaces.IChemModel model = seq.getChemModel(0); assertNotNull(model); assertEquals(model.getMoleculeSet().getMoleculeCount(), 1); // test the molecule org.openscience.cdk.interfaces.IMolecule mol = model.getMoleculeSet().getMolecule(0); assertNotNull(mol); assertEquals(13, mol.getAtomCount()); assertEquals(12, mol.getBondCount()); assertFalse(GeometryToolsInternalCoordinates.has3DCoordinates(mol)); assertTrue(GeometryToolsInternalCoordinates.has2DCoordinates(mol)); } public void testCMLOK4() throws Exception { String filename = "data/cml/nsc2dmol.2.cml"; logger.info("Testing: " + filename); InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); CMLReader reader = new CMLReader(ins); IChemFile chemFile = (IChemFile)reader.read(new org.openscience.cdk.ChemFile()); // test the resulting ChemFile content assertNotNull(chemFile); assertEquals(chemFile.getChemSequenceCount(), 1); org.openscience.cdk.interfaces.IChemSequence seq = chemFile.getChemSequence(0); assertNotNull(seq); assertEquals(seq.getChemModelCount(), 1); org.openscience.cdk.interfaces.IChemModel model = seq.getChemModel(0); assertNotNull(model); assertEquals(model.getMoleculeSet().getMoleculeCount(), 1); // test the molecule org.openscience.cdk.interfaces.IMolecule mol = model.getMoleculeSet().getMolecule(0); assertNotNull(mol); assertEquals(13, mol.getAtomCount()); assertEquals(12, mol.getBondCount()); assertFalse(GeometryToolsInternalCoordinates.has3DCoordinates(mol)); assertTrue(GeometryToolsInternalCoordinates.has2DCoordinates(mol)); } public void testCMLOK5() throws Exception { String filename = "data/cml/nsc2dmol.a1.cml"; logger.info("Testing: " + filename); InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); CMLReader reader = new CMLReader(ins); IChemFile chemFile = (IChemFile)reader.read(new org.openscience.cdk.ChemFile()); // test the resulting ChemFile content assertNotNull(chemFile); assertEquals(chemFile.getChemSequenceCount(), 1); org.openscience.cdk.interfaces.IChemSequence seq = chemFile.getChemSequence(0); assertNotNull(seq); assertEquals(seq.getChemModelCount(), 1); org.openscience.cdk.interfaces.IChemModel model = seq.getChemModel(0); assertNotNull(model); assertEquals(model.getMoleculeSet().getMoleculeCount(), 1); // test the molecule org.openscience.cdk.interfaces.IMolecule mol = model.getMoleculeSet().getMolecule(0); assertNotNull(mol); assertEquals(13, mol.getAtomCount()); assertEquals(12, mol.getBondCount()); assertFalse(GeometryToolsInternalCoordinates.has3DCoordinates(mol)); assertTrue(GeometryToolsInternalCoordinates.has2DCoordinates(mol)); } public void testCMLOK6() throws Exception { String filename = "data/cml/nsc2dmol.a2.cml"; logger.info("Testing: " + filename); InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); CMLReader reader = new CMLReader(ins); IChemFile chemFile = (IChemFile)reader.read(new org.openscience.cdk.ChemFile()); // test the resulting ChemFile content assertNotNull(chemFile); assertEquals(chemFile.getChemSequenceCount(), 1); org.openscience.cdk.interfaces.IChemSequence seq = chemFile.getChemSequence(0); assertNotNull(seq); assertEquals(seq.getChemModelCount(), 1); org.openscience.cdk.interfaces.IChemModel model = seq.getChemModel(0); assertNotNull(model); assertEquals(model.getMoleculeSet().getMoleculeCount(), 1); // test the molecule org.openscience.cdk.interfaces.IMolecule mol = model.getMoleculeSet().getMolecule(0); assertNotNull(mol); assertEquals(13, mol.getAtomCount()); assertEquals(12, mol.getBondCount()); assertFalse(GeometryToolsInternalCoordinates.has3DCoordinates(mol)); assertTrue(GeometryToolsInternalCoordinates.has2DCoordinates(mol)); } public void testCMLOK7() throws Exception { String filename = "data/cml/nsc3dcml.xml"; logger.info("Testing: " + filename); InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); CMLReader reader = new CMLReader(ins); IChemFile chemFile = (IChemFile)reader.read(new org.openscience.cdk.ChemFile()); // test the resulting ChemFile content assertNotNull(chemFile); assertEquals(chemFile.getChemSequenceCount(), 1); org.openscience.cdk.interfaces.IChemSequence seq = chemFile.getChemSequence(0); assertNotNull(seq); assertEquals(seq.getChemModelCount(), 1); org.openscience.cdk.interfaces.IChemModel model = seq.getChemModel(0); assertNotNull(model); assertEquals(model.getMoleculeSet().getMoleculeCount(), 1); // test the molecule org.openscience.cdk.interfaces.IMolecule mol = model.getMoleculeSet().getMolecule(0); assertNotNull(mol); assertEquals(27, mol.getAtomCount()); assertEquals(27, mol.getBondCount()); assertTrue(GeometryToolsInternalCoordinates.has3DCoordinates(mol)); assertFalse(GeometryToolsInternalCoordinates.has2DCoordinates(mol)); } public void testCMLOK8() throws Exception { String filename = "data/cml/nsc2dcml.xml"; logger.info("Testing: " + filename); InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); CMLReader reader = new CMLReader(ins); IChemFile chemFile = (IChemFile)reader.read(new org.openscience.cdk.ChemFile()); // test the resulting ChemFile content assertNotNull(chemFile); assertEquals(chemFile.getChemSequenceCount(), 1);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -