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

📄 mol2readertest.java

📁 化学图形处理软件
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* $RCSfile$ * $Author: egonw $ * $Date: 2007-05-08 11:48:15 +0000 (Di, 08 Mai 2007) $ * $Revision: 8312 $ * * Copyright (C) 2004-2007  The Chemistry Development Kit (CDK) project *  * Contact: cdk-devel@slists.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;import java.io.BufferedReader;import java.io.IOException;import java.io.InputStream;import java.io.InputStreamReader;import java.io.StringReader;import java.util.Iterator;import java.util.List;import java.util.zip.GZIPInputStream;import junit.framework.Test;import junit.framework.TestSuite;import org.openscience.cdk.ChemFile;import org.openscience.cdk.ChemModel;import org.openscience.cdk.ChemObject;import org.openscience.cdk.exception.CDKException;import org.openscience.cdk.interfaces.IAtom;import org.openscience.cdk.interfaces.IAtomContainer;import org.openscience.cdk.interfaces.IChemFile;import org.openscience.cdk.interfaces.IChemModel;import org.openscience.cdk.io.Mol2Reader;import org.openscience.cdk.nonotify.NoNotificationChemObjectBuilder;import org.openscience.cdk.test.CDKTestCase;import org.openscience.cdk.tools.LoggingTool;import org.openscience.cdk.tools.manipulator.ChemModelManipulator;/** * TestCase for the reading SYBYL mol2 files using a test file. * * @cdk.module test-io * * @see org.openscience.cdk.io.Mol2Reader */public class Mol2ReaderTest extends CDKTestCase {    private org.openscience.cdk.tools.LoggingTool logger;    public Mol2ReaderTest(String name) {        super(name);        logger = new LoggingTool(this);    }    public static Test suite() {        return new TestSuite(Mol2ReaderTest.class);    }    public void testAccepts() {    	Mol2Reader reader = new Mol2Reader();    	assertTrue(reader.accepts(ChemFile.class));    	assertTrue(reader.accepts(ChemModel.class));    }    /**     * Test example from website. See     * <a href="http://www.tripos.com/custResources/mol2Files/mol2_format3.html">Tripos example</a>.     */    public void testExampleFromWebsite() throws Exception {        String filename = "data/mol2/fromWebsite.mol2";        logger.info("Testing: ", filename);        InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename);        Mol2Reader reader = new Mol2Reader(ins);        ChemFile chemFile = (ChemFile)reader.read((ChemObject)new ChemFile());        assertNotNull(chemFile);        assertEquals(1, chemFile.getChemSequenceCount());        org.openscience.cdk.interfaces.IChemSequence seq = chemFile.getChemSequence(0);        assertNotNull(seq);        assertEquals(1, seq.getChemModelCount());        org.openscience.cdk.interfaces.IChemModel model = seq.getChemModel(0);        assertNotNull(model);        org.openscience.cdk.interfaces.IMoleculeSet som = model.getMoleculeSet();        assertNotNull(som);        assertEquals(1, som.getMoleculeCount());        org.openscience.cdk.interfaces.IMolecule m = som.getMolecule(0);        assertNotNull(m);        assertEquals(12, m.getAtomCount());        assertEquals(12, m.getBondCount());        assertEquals("C.ar", m.getAtom(0).getAtomTypeName());        assertEquals("C", m.getAtom(0).getSymbol());        assertEquals("H", m.getAtom(6).getAtomTypeName());        assertEquals("H", m.getAtom(6).getSymbol());    }        /**     * Tests the Mol2Reader with about 30% of the NCI molecules.     *      * @throws IOException if an I/O error occurs     * @throws CDKException if an CDK error occurs     */    public void testNCIfeb03_2D() throws Exception {    	if (!runSlowTests()) fail("Not running time consuming test");    	        String filename = "data/mol2/NCI_feb03_2D.mol2.gz";        InputStream in = new GZIPInputStream(Mol2ReaderTest.class.getClassLoader().getResourceAsStream(filename));        BufferedReader br = new BufferedReader(new InputStreamReader(in));        StringBuilder buf = new StringBuilder();        String line;        while ((line = br.readLine()) != null) {            if (line.startsWith("@<TRIPOS>MOLECULE") && (buf.length() > 0)) {                checkMol(buf);                buf.delete(0, buf.length() - 1);            }            buf.append(line).append('\n');        }        if (buf.length() > 0) {            checkMol(buf);        }    }        public void testBug1714794() throws Exception {        String problematicMol2 = "@<TRIPOS>MOLECULE\n"            + "mol_197219.smi\n"            + " 129 135 0 0 0\n"            + "SMALL\n"            + "GASTEIGER\n"            + "Energy = 0\n"            + "\n"            + "@<TRIPOS>ATOM\n"            + "      1 N1          0.0000    0.0000    0.0000 N.am    1  <1>        -0.2782\n"            + "      2 H1          0.0000    0.0000    0.0000 H       1  <1>         0.1552\n"            + "      3 C1          0.0000    0.0000    0.0000 C.ar    1  <1>         0.0886\n"            + "      4 C2          0.0000    0.0000    0.0000 C.ar    1  <1>         0.1500\n"            + "      5 C3          0.0000    0.0000    0.0000 C.ar    1  <1>         0.0714\n"            + "      6 C4          0.0000    0.0000    0.0000 C.ar    1  <1>         0.0456\n"            + "      7 C5          0.0000    0.0000    0.0000 C.ar    1  <1>         0.0788\n"            + "      8 C6          0.0000    0.0000    0.0000 C.ar    1  <1>         0.1435\n"            + "      9 C7          0.0000    0.0000    0.0000 C.ar    1  <1>         0.0342\n"            + "     10 C8          0.0000    0.0000    0.0000 C.ar    1  <1>         0.1346\n"            + "     11 O1          0.0000    0.0000    0.0000 O.3     1  <1>        -0.5057\n"            + "     12 H2          0.0000    0.0000    0.0000 H       1  <1>         0.2922\n"            + "     13 C9          0.0000    0.0000    0.0000 C.3     1  <1>        -0.0327\n"            + "     14 H3          0.0000    0.0000    0.0000 H       1  <1>         0.0280\n"            + "     15 H4          0.0000    0.0000    0.0000 H       1  <1>         0.0280\n"            + "     16 H5          0.0000    0.0000    0.0000 H       1  <1>         0.0280\n"            + "     17 O2          0.0000    0.0000    0.0000 O.3     1  <1>        -0.4436\n"            + "     18 C10         0.0000    0.0000    0.0000 C.3     1  <1>         0.3143\n"            + "     19 O3          0.0000    0.0000    0.0000 O.2     1  <1>        -0.4528\n"            + "     20 C11         0.0000    0.0000    0.0000 C.2     1  <1>         0.0882\n"            + "     21 H6          0.0000    0.0000    0.0000 H       1  <1>         0.1022\n"            + "     22 C12         0.0000    0.0000    0.0000 C.2     1  <1>        -0.0208\n"            + "     23 H7          0.0000    0.0000    0.0000 H       1  <1>         0.0628\n"            + "     24 C13         0.0000    0.0000    0.0000 C.3     1  <1>         0.0854\n"            + "     25 H8          0.0000    0.0000    0.0000 H       1  <1>         0.0645\n"            + "     26 C14         0.0000    0.0000    0.0000 C.3     1  <1>         0.0236\n"            + "     27 H9          0.0000    0.0000    0.0000 H       1  <1>         0.0362\n"            + "     28 C15         0.0000    0.0000    0.0000 C.3     1  <1>         0.1131\n"            + "     29 H10         0.0000    0.0000    0.0000 H       1  <1>         0.0741\n"            + "     30 C16         0.0000    0.0000    0.0000 C.3     1  <1>         0.0200\n"            + "     31 H11         0.0000    0.0000    0.0000 H       1  <1>         0.0359\n"            + "     32 C17         0.0000    0.0000    0.0000 C.3     1  <1>         0.0661\n"            + "     33 H12         0.0000    0.0000    0.0000 H       1  <1>         0.0600\n"            + "     34 C18         0.0000    0.0000    0.0000 C.3     1  <1>         0.0091\n"            + "     35 H13         0.0000    0.0000    0.0000 H       1  <1>         0.0348\n"            + "     36 C19         0.0000    0.0000    0.0000 C.3     1  <1>         0.0661\n"            + "     37 H14         0.0000    0.0000    0.0000 H       1  <1>         0.0602\n"            + "     38 C20         0.0000    0.0000    0.0000 C.3     1  <1>         0.0009\n"            + "     39 H15         0.0000    0.0000    0.0000 H       1  <1>         0.0365\n"            + "     40 C21         0.0000    0.0000    0.0000 C.2     1  <1>        -0.0787\n"            + "     41 H16         0.0000    0.0000    0.0000 H       1  <1>         0.0576\n"            + "     42 C22         0.0000    0.0000    0.0000 C.2     1  <1>        -0.0649\n"            + "     43 H17         0.0000    0.0000    0.0000 H       1  <1>         0.0615\n"            + "     44 C23         0.0000    0.0000    0.0000 C.2     1  <1>        -0.0542\n"            + "     45 H18         0.0000    0.0000    0.0000 H       1  <1>         0.0622\n"            + "     46 C24         0.0000    0.0000    0.0000 C.2     1  <1>         0.0115\n"            + "     47 C25         0.0000    0.0000    0.0000 C.2     1  <1>         0.2441\n"            + "     48 O4          0.0000    0.0000    0.0000 O.2     1  <1>        -0.2702\n"            + "     49 C26         0.0000    0.0000    0.0000 C.3     1  <1>        -0.0348\n"            + "     50 H19         0.0000    0.0000    0.0000 H       1  <1>         0.0279\n"            + "     51 H20         0.0000    0.0000    0.0000 H       1  <1>         0.0279\n"            + "     52 H21         0.0000    0.0000    0.0000 H       1  <1>         0.0279\n"            + "     53 C27         0.0000    0.0000    0.0000 C.3     1  <1>        -0.0566\n"            + "     54 H22         0.0000    0.0000    0.0000 H       1  <1>         0.0236\n"            + "     55 H23         0.0000    0.0000    0.0000 H       1  <1>         0.0236\n"            + "     56 H24         0.0000    0.0000    0.0000 H       1  <1>         0.0236\n"            + "     57 O5          0.0000    0.0000    0.0000 O.3     1  <1>        -0.3909\n"            + "     58 H25         0.0000    0.0000    0.0000 H       1  <1>         0.2098\n"            + "     59 C28         0.0000    0.0000    0.0000 C.3     1  <1>        -0.0577\n"            + "     60 H26         0.0000    0.0000    0.0000 H       1  <1>         0.0234\n"            + "     61 H27         0.0000    0.0000    0.0000 H       1  <1>         0.0234\n"            + "     62 H28         0.0000    0.0000    0.0000 H       1  <1>         0.0234\n"            + "     63 O6          0.0000    0.0000    0.0000 O.3     1  <1>        -0.3910\n"            + "     64 H29         0.0000    0.0000    0.0000 H       1  <1>         0.2098\n"            + "     65 C29         0.0000    0.0000    0.0000 C.3     1  <1>        -0.0567\n"            + "     66 H30         0.0000    0.0000    0.0000 H       1  <1>         0.0234\n"            + "     67 H31         0.0000    0.0000    0.0000 H       1  <1>         0.0234\n"            + "     68 H32         0.0000    0.0000    0.0000 H       1  <1>         0.0234\n"            + "     69 O7          0.0000    0.0000    0.0000 O.3     1  <1>        -0.4608\n"            + "     70 C30         0.0000    0.0000    0.0000 C.2     1  <1>         0.3042\n"            + "     71 O8          0.0000    0.0000    0.0000 O.2     1  <1>        -0.2512\n"            + "     72 C31         0.0000    0.0000    0.0000 C.3     1  <1>         0.0332\n"            + "     73 H33         0.0000    0.0000    0.0000 H       1  <1>         0.0342\n"

⌨️ 快捷键说明

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