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

📄 cmlfragmentstest.java

📁 化学图形处理软件
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    }    public void testBondAromatic() throws Exception {        String cmlString = "<molecule id='m1'><atomArray atomID='a1 a2'/><bondArray atomRef1='a1' atomRef2='a2' order='A'/></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(CDKConstants.BONDORDER_SINGLE, bond.getOrder(), 0.0001);        assertEquals(true, bond.getFlag(CDKConstants.ISAROMATIC));    }        public void testBondId() 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("b1", bond.getID());    }        public void testList() throws Exception {        String cmlString =           "<list>" +           "<molecule id='m1'><atomArray><atom id='a1'/><atom id='a2'/></atomArray><bondArray><bond id='b1' atomRefs2='a1 a2'/></bondArray></molecule>" +          "<molecule id='m2'><atomArray><atom id='a1'/><atom id='a2'/></atomArray><bondArray><bond id='b1' atomRefs2='a1 a2'/></bondArray></molecule>" +          "</list>";                IChemFile chemFile = parseCMLString(cmlString);        checkForXMoleculeFile(chemFile, 2);    }    public void testCoordinates2D() throws Exception {        String cmlString = "<molecule id='m1'><atomArray atomID='a1 a2' x2='0.0 0.1' y2='1.2 1.3'/></molecule>";                IChemFile chemFile = parseCMLString(cmlString);        IMolecule mol = checkForSingleMoleculeFile(chemFile);                assertEquals(2, mol.getAtomCount());        assertNotNull(mol.getAtom(0).getPoint2d());        assertNotNull(mol.getAtom(1).getPoint2d());        assertNull(mol.getAtom(0).getPoint3d());        assertNull(mol.getAtom(1).getPoint3d());    }      public void testCoordinates3D() throws Exception {        String cmlString = "<molecule id='m1'><atomArray atomID='a1 a2' x3='0.0 0.1' y3='1.2 1.3' z3='2.1 2.5'/></molecule>";                IChemFile chemFile = parseCMLString(cmlString);        IMolecule mol = checkForSingleMoleculeFile(chemFile);                assertEquals(2, mol.getAtomCount());        assertNull(mol.getAtom(0).getPoint2d());        assertNull(mol.getAtom(1).getPoint2d());        assertNotNull(mol.getAtom(0).getPoint3d());        assertNotNull(mol.getAtom(1).getPoint3d());    }        public void testFractional3D() throws Exception {        String cmlString = "<molecule id='m1'><atomArray atomID='a1 a2' xFract='0.0 0.1' yFract='1.2 1.3' zFract='2.1 2.5'/></molecule>";                IChemFile chemFile = parseCMLString(cmlString);        IMolecule mol = checkForSingleMoleculeFile(chemFile);                assertEquals(2, mol.getAtomCount());        assertNull(mol.getAtom(0).getPoint3d());        assertNull(mol.getAtom(1).getPoint3d());        assertNotNull(mol.getAtom(0).getFractionalPoint3d());        assertNotNull(mol.getAtom(1).getFractionalPoint3d());    }        public void testMissing2DCoordinates() throws Exception {        String cmlString =           "<molecule id='m1'><atomArray><atom id='a1' xy2='0.0 0.1'/><atom id='a2'/><atom id='a3' xy2='0.1 0.0'/></atomArray></molecule>";                  IChemFile chemFile = parseCMLString(cmlString);        IMolecule mol = checkForSingleMoleculeFile(chemFile);                assertEquals(3, mol.getAtomCount());        IAtom atom1 = mol.getAtom(0);        IAtom atom2 = mol.getAtom(1);        IAtom atom3 = mol.getAtom(2);                assertNotNull(atom1.getPoint2d());        assertNull   (atom2.getPoint2d());        assertNotNull(atom3.getPoint2d());    }    public void testMissing3DCoordinates() throws Exception {        String cmlString =           "<molecule id='m1'><atomArray><atom id='a1' xyz3='0.0 0.1 0.2'/><atom id='a2'/><atom id='a3' xyz3='0.1 0.0 0.2'/></atomArray></molecule>";                  IChemFile chemFile = parseCMLString(cmlString);        IMolecule mol = checkForSingleMoleculeFile(chemFile);                assertEquals(3, mol.getAtomCount());        IAtom atom1 = mol.getAtom(0);        IAtom atom2 = mol.getAtom(1);        IAtom atom3 = mol.getAtom(2);                assertNotNull(atom1.getPoint3d());        assertNull   (atom2.getPoint3d());        assertNotNull(atom3.getPoint3d());    }        public void testCrystal() throws Exception {        StringBuffer cmlStringB = new StringBuffer("  <molecule id=\"m1\">\n");        cmlStringB.append("    <crystal z=\"4\">\n");        cmlStringB.append("      <scalar id=\"sc1\" title=\"a\" errorValue=\"0.001\" units=\"units:angstrom\">4.500</scalar>\n");        cmlStringB.append("      <scalar id=\"sc2\" title=\"b\" errorValue=\"0.001\" units=\"units:angstrom\">4.500</scalar>\n");        cmlStringB.append("      <scalar id=\"sc3\" title=\"c\" errorValue=\"0.001\" units=\"units:angstrom\">4.500</scalar>\n");        cmlStringB.append("      <scalar id=\"sc4\" title=\"alpha\" units=\"units:degrees\">90</scalar>\n");        cmlStringB.append("      <scalar id=\"sc5\" title=\"beta\" units=\"units:degrees\">90</scalar>\n");        cmlStringB.append("      <scalar id=\"sc6\" title=\"gamma\" units=\"units:degrees\">90</scalar>\n");        cmlStringB.append("      <symmetry id=\"s1\" spaceGroup=\"Fm3m\"/>\n");        cmlStringB.append("    </crystal>\n");        cmlStringB.append("    <atomArray>\n");        cmlStringB.append("      <atom id=\"a1\" elementType=\"Na\" formalCharge=\"1\" xyzFract=\"0.0 0.0 0.0\"\n");        cmlStringB.append("        xy2=\"+23.1 -21.0\"></atom>\n");        cmlStringB.append("      <atom id=\"a2\" elementType=\"Cl\" formalCharge=\"-1\" xyzFract=\"0.5 0.0 0.0\"></atom>\n");        cmlStringB.append("    </atomArray>\n");        cmlStringB.append("  </molecule>\n");                IChemFile chemFile = parseCMLString(cmlStringB.toString());        org.openscience.cdk.interfaces.ICrystal crystal = checkForCrystalFile(chemFile);        assertEquals(4, crystal.getZ());        assertEquals("Fm3m", crystal.getSpaceGroup());        assertEquals(2, crystal.getAtomCount());        Vector3d aaxis = crystal.getA();        assertEquals(4.5, aaxis.x, 0.1);        assertEquals(0.0, aaxis.y, 0.1);        assertEquals(0.0, aaxis.z, 0.1);        Vector3d baxis = crystal.getB();        assertEquals(0.0, baxis.x, 0.1);        assertEquals(4.5, baxis.y, 0.1);        assertEquals(0.0, baxis.z, 0.1);        Vector3d caxis = crystal.getC();        assertEquals(0.0, caxis.x, 0.1);        assertEquals(0.0, caxis.y, 0.1);        assertEquals(4.5, caxis.z, 0.1);    }    public void testMoleculeId() throws Exception {        String cmlString = "<molecule id='m1'><atomArray><atom id='a1'/></atomArray></molecule>";                IChemFile chemFile = parseCMLString(cmlString);        IMolecule mol = checkForSingleMoleculeFile(chemFile);        assertEquals("m1", mol.getID());    }        public void testBondArrayCML1() throws Exception {        String cml1String = "  <molecule title=\"NSC 25\">\n" +"   <atomArray>\n" +"    <stringArray builtin=\"atomId\">a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13</stringArray>\n" +"    <stringArray builtin=\"elementType\">Br N C C C C C C C O C C C</stringArray>\n" +"    <integerArray builtin=\"formalCharge\">0 0 0 0 0 0 0 0 0 0 0 0 0</integerArray>\n" +"    <floatArray builtin=\"x2\">-2.350500 0.850500 -2.160500 -1.522400 -2.798500 -1.522400 -2.798500 -2.160500 -0.889500 -1.259400 0.850500 0.850500 2.880500</floatArray>\n" +"    <floatArray builtin=\"y2\">-2.129900 0.767900 0.769900 0.401900 0.401900 -0.334900 -0.334900 -0.703000 0.767900 1.408800 -0.652000 2.088000 0.767900</floatArray>\n" +"   </atomArray>\n" +"   <bondArray>\n" +"    <stringArray builtin=\"atomRef\">a2 a2 a2 a2 a3 a3 a4 a4 a5 a6 a7 a9</stringArray>\n" +"    <stringArray builtin=\"atomRef\">a9 a11 a12 a13 a5 a4 a6 a9 a7 a8 a8 a10</stringArray>\n" +"    <stringArray builtin=\"order\">1 1 1 1 2 1 2 1 1 1 2 2</stringArray>\n" +"   </bondArray>\n" +"  </molecule>\n";        IChemFile chemFile = parseCMLString(cml1String);        IMolecule mol = checkForSingleMoleculeFile(chemFile);        assertEquals(13, mol.getAtomCount());        assertEquals(12, mol.getBondCount());    }        private IChemFile parseCMLString(String cmlString) throws Exception {        IChemFile chemFile = null;        CMLReader reader = new CMLReader(new ByteArrayInputStream(cmlString.getBytes()));        chemFile = (IChemFile)reader.read(new org.openscience.cdk.ChemFile());        return chemFile;    }    /**     * Tests wether the file is indeed a single molecule file     */    private IMolecule checkForSingleMoleculeFile(IChemFile chemFile) {        return checkForXMoleculeFile(chemFile, 1);    }        private IMolecule checkForXMoleculeFile(IChemFile chemFile, int numberOfMolecules) {        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);                org.openscience.cdk.interfaces.IMoleculeSet moleculeSet = model.getMoleculeSet();        assertNotNull(moleculeSet);                assertEquals(moleculeSet.getMoleculeCount(), numberOfMolecules);        IMolecule mol = null;        for (int i=0; i<numberOfMolecules; i++) {            mol = moleculeSet.getMolecule(i);            assertNotNull(mol);        }        return mol;    }    private org.openscience.cdk.interfaces.ICrystal checkForCrystalFile(IChemFile chemFile) {        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);                org.openscience.cdk.interfaces.ICrystal crystal = model.getCrystal();        assertNotNull(crystal);                return crystal;    }}

⌨️ 快捷键说明

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