⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cmlfragmentstest.java

📁 化学图形处理软件
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* $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 javax.vecmath.Vector3d;import junit.framework.Test;import junit.framework.TestSuite;import org.openscience.cdk.CDKConstants;import org.openscience.cdk.interfaces.IAtom;import org.openscience.cdk.interfaces.IChemFile;import org.openscience.cdk.interfaces.IMolecule;import org.openscience.cdk.io.CMLReader;import org.openscience.cdk.test.CDKTestCase;/** * Atomic tests for the reading CML documents. All tested CML strings are valid CML 2, * as can be determined in cdk/src/org/openscience/cdk/test/io/cml/cmlTestFramework.xml. * * @cdk.module test-io * * @author Egon Willighagen <egonw@sci.kun.nl> */public class CMLFragmentsTest extends CDKTestCase {    public CMLFragmentsTest(String name) {        super(name);    }    public static Test suite() {        return new TestSuite(CMLFragmentsTest.class);    }    public void testAtomId() throws Exception {        String cmlString = "<molecule id='m1'><atomArray><atom id='a1'/></atomArray></molecule>";                IChemFile chemFile = parseCMLString(cmlString);        IMolecule mol = checkForSingleMoleculeFile(chemFile);        assertEquals(1, mol.getAtomCount());        IAtom atom = mol.getAtom(0);        assertEquals("a1", atom.getID());    }        public void testAtomId2() throws Exception {        String cmlString = "<molecule id='m1'><atomArray><stringArray builtin='id'>a1</stringArray></atomArray></molecule>";                IChemFile chemFile = parseCMLString(cmlString);        IMolecule mol = checkForSingleMoleculeFile(chemFile);        assertEquals(1, mol.getAtomCount());        IAtom atom = mol.getAtom(0);        assertEquals("a1", atom.getID());    }        public void testAtomId3() throws Exception {        String cmlString = "<molecule id='m1'><atomArray atomID='a1 a2 a3'/></molecule>";                IChemFile chemFile = parseCMLString(cmlString);        IMolecule mol = checkForSingleMoleculeFile(chemFile);        assertEquals(3, mol.getAtomCount());        IAtom atom = mol.getAtom(1);        assertEquals("a2", atom.getID());    }        public void testAtomElementType() throws Exception {        String cmlString = "<molecule id='m1'><atomArray><stringArray builtin='elementType'>C</stringArray></atomArray></molecule>";                IChemFile chemFile = parseCMLString(cmlString);        IMolecule mol = checkForSingleMoleculeFile(chemFile);        assertEquals(1, mol.getAtomCount());        IAtom atom = mol.getAtom(0);        assertEquals("C", atom.getSymbol());    }        public void testAtomElementType2() throws Exception {        String cmlString = "<molecule id='m1'><atomArray><atom id='a1'><string builtin='elementType'>C</string></atom></atomArray></molecule>";                IChemFile chemFile = parseCMLString(cmlString);        IMolecule mol = checkForSingleMoleculeFile(chemFile);        assertEquals(1, mol.getAtomCount());        IAtom atom = mol.getAtom(0);        assertEquals("C", atom.getSymbol());    }        public void testAtomElementType3() throws Exception {        String cmlString = "<molecule id='m1'><atomArray atomID='a1' elementType='C'/></molecule>";                IChemFile chemFile = parseCMLString(cmlString);        IMolecule mol = checkForSingleMoleculeFile(chemFile);        assertEquals(1, mol.getAtomCount());        IAtom atom = mol.getAtom(0);        assertEquals("C", atom.getSymbol());    }        public void test2dCoord() throws Exception {        String cmlString = "<molecule id='m1'><atomArray><atom id='a1'><coordinate2 builtin='xy2'>84 138</coordinate2></atom></atomArray></molecule>";                IChemFile chemFile = parseCMLString(cmlString);        IMolecule mol = checkForSingleMoleculeFile(chemFile);        assertEquals(1, mol.getAtomCount());        IAtom atom = mol.getAtom(0);        assertNull(atom.getPoint3d());        assertNotNull(atom.getPoint2d());        assertEquals(84, (int)atom.getPoint2d().x);        assertEquals(138, (int)atom.getPoint2d().y);    }        public void test2dCoord2() throws Exception {        String cmlString = "<molecule id='m1'><atomArray><stringArray builtin='id'>a1</stringArray><floatArray builtin='x2'>2.0833</floatArray><floatArray builtin='y2'>4.9704</floatArray></atomArray></molecule>";                IChemFile chemFile = parseCMLString(cmlString);        IMolecule mol = checkForSingleMoleculeFile(chemFile);        assertEquals(1, mol.getAtomCount());        IAtom atom = mol.getAtom(0);        assertNull(atom.getPoint3d());        assertNotNull(atom.getPoint2d());        assertTrue(2.0833 == atom.getPoint2d().x);        assertTrue(4.9704 == atom.getPoint2d().y);    }        public void testBond() throws Exception {        String cmlString = "<molecule id='m1'><atomArray><atom id='a1'/><atom id='a2'/></atomArray><bondArray><bond id='b1' atomRefs2='a1 a2'/></bondArray></molecule>";                IChemFile chemFile = parseCMLString(cmlString);        IMolecule mol = checkForSingleMoleculeFile(chemFile);        assertEquals(2, mol.getAtomCount());        assertEquals(1, mol.getBondCount());        org.openscience.cdk.interfaces.IBond bond = mol.getBond(0);        assertEquals(2, bond.getAtomCount());        IAtom atom1 = bond.getAtom(0);        IAtom atom2 = bond.getAtom(1);        assertEquals("a1", atom1.getID());        assertEquals("a2", atom2.getID());    }    public void testBond2() throws Exception {        String cmlString = "<molecule id='m1'><atomArray><stringArray builtin='id'>a1 a2</stringArray></atomArray><bondArray><stringArray builtin='atomRefs'>a1</stringArray><stringArray builtin='atomRefs'>a2</stringArray></bondArray></molecule>";                IChemFile chemFile = parseCMLString(cmlString);        IMolecule mol = checkForSingleMoleculeFile(chemFile);        assertEquals(2, mol.getAtomCount());        assertEquals(1, mol.getBondCount());        org.openscience.cdk.interfaces.IBond bond = mol.getBond(0);        assertEquals(2, bond.getAtomCount());        IAtom atom1 = bond.getAtom(0);        IAtom atom2 = bond.getAtom(1);        assertEquals("a1", atom1.getID());        assertEquals("a2", atom2.getID());    }        public void testBond3() throws Exception {        String cmlString = "<molecule id='m1'><atomArray><stringArray builtin='id'>a1 a2</stringArray></atomArray><bondArray><bond id='b1'><string builtin='atomRef'>a1</string><string builtin='atomRef'>a2</string></bond></bondArray></molecule>";                IChemFile chemFile = parseCMLString(cmlString);        IMolecule mol = checkForSingleMoleculeFile(chemFile);        assertEquals(2, mol.getAtomCount());        assertEquals(1, mol.getBondCount());        org.openscience.cdk.interfaces.IBond bond = mol.getBond(0);        assertEquals(2, bond.getAtomCount());        IAtom atom1 = bond.getAtom(0);        IAtom atom2 = bond.getAtom(1);        assertEquals("a1", atom1.getID());        assertEquals("a2", atom2.getID());    }        public void testBond4() throws Exception {        String cmlString = "<molecule id='m1'><atomArray atomID='a1 a2 a3'/><bondArray atomRef1='a1 a1' atomRef2='a2 a3' bondID='b1 b2'/></molecule>";                IChemFile chemFile = parseCMLString(cmlString);        IMolecule mol = checkForSingleMoleculeFile(chemFile);        assertEquals(3, mol.getAtomCount());        assertEquals(2, mol.getBondCount());        org.openscience.cdk.interfaces.IBond bond = mol.getBond(0);        assertEquals(2, bond.getAtomCount());        IAtom atom1 = bond.getAtom(0);        IAtom atom2 = bond.getAtom(1);        assertEquals("a1", atom1.getID());        assertEquals("a2", atom2.getID());        assertEquals("b2", mol.getBond(1).getID());    }    public void testBond5() throws Exception {        String cmlString = "<molecule id='m1'><atomArray atomID='a1 a2 a3'/><bondArray atomRef1='a1 a1' atomRef2='a2 a3' order='1 1'/></molecule>";                IChemFile chemFile = parseCMLString(cmlString);        IMolecule mol = checkForSingleMoleculeFile(chemFile);        assertEquals(3, mol.getAtomCount());        assertEquals(2, mol.getBondCount());        org.openscience.cdk.interfaces.IBond bond = mol.getBond(0);        assertEquals(2, bond.getAtomCount());        assertEquals(1.0, bond.getOrder(), 0.0001);        bond = mol.getBond(1);        assertEquals(2, bond.getAtomCount());        assertEquals(1.0, bond.getOrder(), 0.0001);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -