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

📄 hydrogenaddertest.java

📁 化学图形处理软件
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*  $RCSfile$ *  $Author: shk3 $ *  $Date: 2007-05-29 11:30:16 +0000 (Di, 29 Mai 2007) $ *  $Revision: 8337 $ * *  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. * *  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.tools;import java.io.InputStream;import javax.vecmath.Point2d;import junit.framework.Test;import junit.framework.TestSuite;import org.openscience.cdk.Atom;import org.openscience.cdk.Bond;import org.openscience.cdk.CDKConstants;import org.openscience.cdk.ChemObject;import org.openscience.cdk.Molecule;import org.openscience.cdk.aromaticity.HueckelAromaticityDetector;import org.openscience.cdk.interfaces.IAtom;import org.openscience.cdk.interfaces.IBond;import org.openscience.cdk.interfaces.IMolecule;import org.openscience.cdk.io.MDLReader;import org.openscience.cdk.test.CDKTestCase;import org.openscience.cdk.tools.HydrogenAdder;import org.openscience.cdk.tools.MFAnalyser;import org.openscience.cdk.tools.SaturationChecker;/** * Tests CDK's hydrogen adding capabilities in terms of * example molecules. * * @cdk.module test-valencycheck * * @author     egonw * @cdk.created    2003-06-18 */public class HydrogenAdderTest extends CDKTestCase {    protected HydrogenAdder adder = null;    public HydrogenAdderTest(String name) {        super(name);    }    /**     * The JUnit setup method     */    public void setUp() throws Exception {        adder = new HydrogenAdder();    }    /**     * A unit test suite for JUnit     *     * @return    The test suite     */    public static Test suite() {        TestSuite suite = new TestSuite(HydrogenAdderTest.class);        return suite;    }    public void testProton() throws Exception {        Molecule mol = new Molecule();        Atom proton = new Atom("H");        proton.setFormalCharge(+1);        mol.addAtom(proton);                adder.addExplicitHydrogensToSatisfyValency(mol);                assertEquals(1, mol.getAtomCount());        assertEquals(1, new MFAnalyser(mol).getAtomCount("H"));        assertEquals(0, mol.getConnectedBondsCount(proton));        assertEquals(0, proton.getHydrogenCount());    }        public void testHydrogen() throws Exception {        Molecule mol = new Molecule();        Atom proton = new Atom("H");        mol.addAtom(proton);                adder.addExplicitHydrogensToSatisfyValency(mol);                assertEquals(2, mol.getAtomCount());        assertEquals(2, new MFAnalyser(mol).getAtomCount("H"));        assertEquals(1, mol.getConnectedBondsCount(proton));        assertEquals(0, proton.getHydrogenCount());    }        public void testMethane() throws Exception {        Molecule mol = new Molecule();        Atom carbon = new Atom("C");        mol.addAtom(carbon);                adder.addExplicitHydrogensToSatisfyValency(mol);                assertEquals(5, mol.getAtomCount());        assertEquals(4, new MFAnalyser(mol).getAtomCount("H"));        assertEquals(4, mol.getConnectedBondsCount(carbon));    }        public void testAminomethane() throws Exception     {        Molecule aminomethane = new Molecule();        Atom carbon = new Atom("C");        Point2d carbonPos = new Point2d(0.0,0.0);        carbon.setPoint2d(carbonPos);        Atom nitrogen = new Atom("N");        Point2d nitrogenPos = new Point2d(1.0,1.0);        nitrogen.setPoint2d(nitrogenPos);        aminomethane.addAtom(carbon);        aminomethane.addAtom(nitrogen);        aminomethane.addBond(new Bond(carbon, nitrogen));                adder.addExplicitHydrogensToSatisfyValency(aminomethane);        assertEquals(7, aminomethane.getAtomCount());	    }        public void testAmmonia() throws Exception {        Molecule mol = new Molecule();        Atom nitrogen = new Atom("N");        mol.addAtom(nitrogen);                adder.addExplicitHydrogensToSatisfyValency(mol);                assertEquals(4, mol.getAtomCount());        assertEquals(3, new MFAnalyser(mol).getAtomCount("H"));        assertEquals(3, mol.getConnectedBondsCount(nitrogen));    }    public void testAmmonium() throws Exception {        Molecule mol = new Molecule();        Atom nitrogen = new Atom("N");        nitrogen.setFormalCharge(+1);        mol.addAtom(nitrogen);                adder.addExplicitHydrogensToSatisfyValency(mol);                assertEquals(5, mol.getAtomCount());        assertEquals(4, new MFAnalyser(mol).getAtomCount("H"));        assertEquals(4, mol.getConnectedBondsCount(nitrogen));    }    public void testWater() throws Exception {        Molecule mol = new Molecule();        Atom oxygen = new Atom("O");        mol.addAtom(oxygen);                adder.addExplicitHydrogensToSatisfyValency(mol);                assertEquals(3, mol.getAtomCount());        assertEquals(2, new MFAnalyser(mol).getAtomCount("H"));        assertEquals(2, mol.getConnectedBondsCount(oxygen));    }    public void testHydroxyl() throws Exception {        Molecule mol = new Molecule();        Atom oxygen = new Atom("O");        oxygen.setFormalCharge(-1);        mol.addAtom(oxygen);                adder.addExplicitHydrogensToSatisfyValency(mol);                assertEquals(2, mol.getAtomCount());        assertEquals(1, new MFAnalyser(mol).getAtomCount("H"));        assertEquals(1, mol.getConnectedBondsCount(oxygen));    }    public void testHydroxonium() throws Exception {        Molecule mol = new Molecule();        Atom oxygen = new Atom("O");        oxygen.setFormalCharge(+1);        mol.addAtom(oxygen);                adder.addExplicitHydrogensToSatisfyValency(mol);                assertEquals(4, mol.getAtomCount());        assertEquals(3, new MFAnalyser(mol).getAtomCount("H"));        assertEquals(3, mol.getConnectedBondsCount(oxygen));    }        public void testHalogens() throws Exception {        halogenTest("I");        halogenTest("F");        halogenTest("Cl");        halogenTest("Br");    }        private void halogenTest(String halogen) throws Exception {        Molecule mol = new Molecule();        Atom atom = new Atom(halogen);        mol.addAtom(atom);                adder.addExplicitHydrogensToSatisfyValency(mol);                assertEquals(2, mol.getAtomCount());        assertEquals(1, new MFAnalyser(mol).getAtomCount("H"));        assertEquals(1, mol.getConnectedBondsCount(atom));    }        public void testSulphur() throws Exception {        Molecule mol = new Molecule();        Atom atom = new Atom("S");        mol.addAtom(atom);                adder.addExplicitHydrogensToSatisfyValency(mol);                assertEquals(3, mol.getAtomCount());        assertEquals(2, new MFAnalyser(mol).getAtomCount("H"));        assertEquals(2, mol.getConnectedBondsCount(atom));    }        public void testSulfite() throws Exception {        Molecule mol = new Molecule();        Atom s = new Atom("S");        Atom o1 = new Atom("O");        Atom o2 = new Atom("O");        Atom o3 = new Atom("O");        mol.addAtom(s);        mol.addAtom(o1);        mol.addAtom(o2);        mol.addAtom(o3);        Bond b1 = new Bond(s, o1, 1.0);        Bond b2 = new Bond(s, o2, 1.0);        Bond b3 = new Bond(s, o3, 2.0);

⌨️ 快捷键说明

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