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

📄 smilesgeneratortest.java

📁 化学图形处理软件
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*  $RCSfile$ *  $Author: shk3 $ *  $Date: 2007-05-01 15:50:23 +0000 (Di, 01 Mai 2007) $ *  $Revision: 8287 $ * *  Copyright (C) 1997-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.smiles;import java.io.ByteArrayInputStream;import java.io.InputStream;import java.io.StringWriter;import javax.vecmath.Point2d;import junit.framework.Test;import junit.framework.TestSuite;import org.openscience.cdk.Atom;import org.openscience.cdk.AtomContainer;import org.openscience.cdk.CDKConstants;import org.openscience.cdk.ChemFile;import org.openscience.cdk.Molecule;import org.openscience.cdk.PseudoAtom;import org.openscience.cdk.Reaction;import org.openscience.cdk.config.IsotopeFactory;import org.openscience.cdk.graph.AtomContainerAtomPermutor;import org.openscience.cdk.graph.AtomContainerBondPermutor;import org.openscience.cdk.interfaces.IAtomContainer;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.io.CMLReader;import org.openscience.cdk.io.CMLWriter;import org.openscience.cdk.io.MDLReader;import org.openscience.cdk.layout.HydrogenPlacer;import org.openscience.cdk.layout.StructureDiagramGenerator;import org.openscience.cdk.smiles.SmilesGenerator;import org.openscience.cdk.templates.MoleculeFactory;import org.openscience.cdk.test.CDKTestCase;import org.openscience.cdk.tools.HydrogenAdder;import org.openscience.cdk.tools.manipulator.AtomContainerManipulator;/** * @author         steinbeck * @cdk.created    2004-02-09 * @cdk.module     test-smiles */public class SmilesGeneratorTest extends CDKTestCase {		/**	 *  Constructor for the SmilesGeneratorTest object	 *	 *@param  name  Description of the Parameter	 */	public SmilesGeneratorTest(String name)	{		super(name);	}	/**	 *  A unit test suite for JUnit	 *	 *@return    The test suite	 */	public static Test suite()	{		return new TestSuite(SmilesGeneratorTest.class);	}	/**	 *  A unit test for JUnit	 */	public void testSmilesGenerator()	{        Molecule mol2 = MoleculeFactory.makeAlphaPinene();		SmilesGenerator sg = new SmilesGenerator();		fixCarbonHCount(mol2);		String smiles2 = sg.createSMILES(mol2);		assertNotNull(smiles2);		assertEquals("C1=C(C)C2CC(C1)C2(C)(C)", smiles2);	}	/**	 *  A unit test for JUnit	 */	public void testEthylPropylPhenantren()	{		Molecule mol1 = MoleculeFactory.makeEthylPropylPhenantren();        SmilesGenerator sg = new SmilesGenerator();		fixCarbonHCount(mol1);		String smiles1 = sg.createSMILES(mol1);		assertNotNull(smiles1);		assertEquals("C=2C=C1C=3C=CC(=CC=3(C=CC1=C(C=2)CC))CCC", smiles1);	}			/**	 *  A unit test for JUnit	 */	public void testPropylCycloPropane()	{		Molecule mol1 = MoleculeFactory.makePropylCycloPropane();        SmilesGenerator sg = new SmilesGenerator();		fixCarbonHCount(mol1);		String smiles1 = sg.createSMILES(mol1);		assertNotNull(smiles1);		assertEquals("CCCC1CC1", smiles1);	}			/**	 *  A unit test for JUnit	 *	 */	public void testAlanin() throws Exception	{		HydrogenPlacer hydrogenPlacer = new HydrogenPlacer();        Molecule mol1 = new Molecule();		SmilesGenerator sg = new SmilesGenerator();		mol1.addAtom(new Atom("N", new Point2d(1, 0)));		// 1		mol1.addAtom(new Atom("C", new Point2d(1, 2)));		// 2		mol1.addAtom(new Atom("F", new Point2d(1, 2)));		// 3		mol1.addAtom(new Atom("C", new Point2d(0, 0)));		// 4		mol1.addAtom(new Atom("C", new Point2d(1, 4)));		// 5		mol1.addAtom(new Atom("O", new Point2d(1, 5)));		// 6		mol1.addAtom(new Atom("O", new Point2d(1, 6)));		// 7		mol1.addBond(0, 1, 1);		// 1		mol1.addBond(1, 2, 1, CDKConstants.STEREO_BOND_UP);		// 2		mol1.addBond(1, 3, 1, CDKConstants.STEREO_BOND_DOWN);		// 3		mol1.addBond(1, 4, 1);		// 4		mol1.addBond(4, 5, 1);		// 5		mol1.addBond(4, 6, 2);		// 6		new HydrogenAdder().addHydrogensToSatisfyValency(mol1);		hydrogenPlacer.placeHydrogens2D(mol1, 1.0);		IsotopeFactory ifac = IsotopeFactory.getInstance(mol1.getBuilder());		ifac.configureAtoms(mol1);		String smiles1 = sg.createSMILES(mol1, true, new boolean[mol1.getBondCount()]);		assertNotNull(smiles1);		assertEquals("[H]OC(=O)[C@](F)(N([H])[H])C([H])([H])[H]", smiles1);				//by setting additional stereo descriptors, we should get another smiles		mol1.getBond(1).setStereo(CDKConstants.STEREO_BOND_DOWN);		mol1.getBond(2).setStereo(CDKConstants.STEREO_BOND_UP);		smiles1 = sg.createSMILES(mol1, true, new boolean[mol1.getBondCount()]);		assertNotNull(smiles1);		assertEquals("[H]OC(=O)[C@](F)(C([H])([H])[H])N([H])[H]", smiles1);	}	/**	 *  A unit test for JUnit	 *	 *@exception  Exception  Description of the Exception	 */	public void testCisResorcinol() throws Exception	{		HydrogenPlacer hydrogenPlacer = new HydrogenPlacer();        Molecule mol1 = new Molecule();		SmilesGenerator sg = new SmilesGenerator();		mol1.addAtom(new Atom("O", new Point2d(3, 1)));		// 1		mol1.addAtom(new Atom("H", new Point2d(2, 0)));		// 2		mol1.addAtom(new Atom("C", new Point2d(2, 1)));		// 3		mol1.addAtom(new Atom("C", new Point2d(1, 1)));		// 4		mol1.addAtom(new Atom("C", new Point2d(1, 4)));		// 5		mol1.addAtom(new Atom("C", new Point2d(1, 5)));		// 6		mol1.addAtom(new Atom("C", new Point2d(1, 2)));		// 7		mol1.addAtom(new Atom("C", new Point2d(2, 2)));		// 1		mol1.addAtom(new Atom("O", new Point2d(3, 2)));		// 2		mol1.addAtom(new Atom("H", new Point2d(2, 3)));		// 3		mol1.addBond(0, 2, 1, CDKConstants.STEREO_BOND_DOWN);		// 1		mol1.addBond(1, 2, 1, CDKConstants.STEREO_BOND_UP);		// 2		mol1.addBond(2, 3, 1);		// 3		mol1.addBond(3, 4, 1);		// 4		mol1.addBond(4, 5, 1);		// 5		mol1.addBond(5, 6, 1);		// 6		mol1.addBond(6, 7, 1);		// 3		mol1.addBond(7, 8, 1, CDKConstants.STEREO_BOND_UP);		// 4		mol1.addBond(7, 9, 1, CDKConstants.STEREO_BOND_DOWN);		// 5		mol1.addBond(7, 2, 1);		// 6		new HydrogenAdder().addHydrogensToSatisfyValency(mol1);		hydrogenPlacer.placeHydrogens2D(mol1, 1.0);		IsotopeFactory ifac = IsotopeFactory.getInstance(mol1.getBuilder());		ifac.configureAtoms(mol1);		String smiles1 = sg.createSMILES(mol1, true, new boolean[mol1.getBondCount()]);		assertNotNull(smiles1);		assertEquals("[H]O[C@]1(C([H])([H])C([H])([H])C([H])([H])C([H])([H])[C@]1(O[H])([H]))([H])", smiles1);		mol1 = (Molecule) AtomContainerManipulator.removeHydrogens(mol1);		smiles1 = sg.createSMILES(mol1);		assertNotNull(smiles1);		assertEquals("OC1CCCCC1(O)", smiles1);	}	/**	 *  A unit test for JUnit	 *	 *@exception  Exception  Description of the Exception	 */	public void testCisTransDecalin() throws Exception	{		HydrogenPlacer hydrogenPlacer = new HydrogenPlacer();        Molecule mol1 = new Molecule();		SmilesGenerator sg = new SmilesGenerator();		mol1.addAtom(new Atom("H", new Point2d(1, 0)));		// 1		mol1.addAtom(new Atom("C", new Point2d(1, 2)));		// 2		mol1.addAtom(new Atom("C", new Point2d(1, 2)));		// 3		mol1.addAtom(new Atom("C", new Point2d(0, 0)));		// 4		mol1.addAtom(new Atom("C", new Point2d(1, 4)));		// 5		mol1.addAtom(new Atom("C", new Point2d(1, 5)));		// 6		mol1.addAtom(new Atom("C", new Point2d(1, 6)));		// 7		mol1.addAtom(new Atom("H", new Point2d(1, 0)));		// 1		mol1.addAtom(new Atom("C", new Point2d(1, 2)));		// 2		mol1.addAtom(new Atom("C", new Point2d(1, 2)));		// 3		mol1.addAtom(new Atom("C", new Point2d(1, 2)));		// 2		mol1.addAtom(new Atom("C", new Point2d(1, 2)));		// 3		mol1.addBond(0, 1, 1, CDKConstants.STEREO_BOND_DOWN);		// 1		mol1.addBond(1, 2, 1);		// 2		mol1.addBond(2, 3, 1);		// 3		mol1.addBond(3, 4, 1);		// 4		mol1.addBond(4, 5, 1);		// 5		mol1.addBond(5, 6, 1);		// 6		mol1.addBond(6, 7, 1, CDKConstants.STEREO_BOND_DOWN);		// 3		mol1.addBond(6, 8, 1);		// 4		mol1.addBond(8, 9, 1);		// 5		mol1.addBond(9, 10, 1);		// 6		mol1.addBond(10, 11, 1);		// 6		mol1.addBond(11, 1, 1);		// 6		mol1.addBond(1, 6, 1);		// 6		new HydrogenAdder().addHydrogensToSatisfyValency(mol1);		hydrogenPlacer.placeHydrogens2D(mol1, 1.0);		IsotopeFactory ifac = IsotopeFactory.getInstance(mol1.getBuilder());		ifac.configureAtoms(mol1);		String smiles1 = sg.createSMILES(mol1, true, new boolean[mol1.getBondCount()]);		assertNotNull(smiles1);		assertEquals("[H]C1([H])(C([H])([H])C([H])([H])C\\2([H])(C([H])([H])C([H])([H])C([H])([H])C([H])([H])C\\2([H])(C1([H])([H]))))", smiles1);		mol1.getBond(6).setStereo(CDKConstants.STEREO_BOND_UP);		String smiles3 = sg.createSMILES(mol1, true, new boolean[mol1.getBondCount()]);		assertNotSame(smiles1, smiles3);	}	/**	 *  A unit test for JUnit	 *	 *@exception  Exception  Description of the Exception	 */	public void testDoubleBondConfiguration() throws Exception	{		HydrogenPlacer hydrogenPlacer = new HydrogenPlacer();		Molecule mol1 = new Molecule();        SmilesGenerator sg = new SmilesGenerator();		mol1.addAtom(new Atom("S", new Point2d(0, 0)));		// 1		mol1.addAtom(new Atom("C", new Point2d(1, 1)));		// 2		mol1.addAtom(new Atom("F", new Point2d(2, 0)));		// 3		mol1.addAtom(new Atom("C", new Point2d(1, 2)));		// 4		mol1.addAtom(new Atom("F", new Point2d(2, 3)));		// 5		mol1.addAtom(new Atom("S", new Point2d(0, 3)));		// 1		mol1.addBond(0, 1, 1);		// 1		mol1.addBond(1, 2, 1);		// 2		mol1.addBond(1, 3, 2);		// 3		mol1.addBond(3, 4, 1);		// 4		mol1.addBond(3, 5, 1);		// 4		IsotopeFactory ifac = IsotopeFactory.getInstance(mol1.getBuilder());		ifac.configureAtoms(mol1);		boolean[] bool = new boolean[mol1.getBondCount()];		bool[2] = true;		String smiles1 = sg.createSMILES(mol1, true, bool);		assertNotNull(smiles1);		assertTrue(smiles1.equals("F/C(=C/(F)S)S"));		mol1.getAtom(4).setPoint2d(new Point2d(0, 3));		mol1.getAtom(5).setPoint2d(new Point2d(2, 3));				smiles1 = sg.createSMILES(mol1, true, bool);		assertNotNull(smiles1);		assertTrue(smiles1.equals("F/C(=C\\(F)S)S"));		new HydrogenAdder().addHydrogensToSatisfyValency(mol1);		hydrogenPlacer.placeHydrogens2D(mol1, 1.0);		bool = new boolean[mol1.getBondCount()];		bool[2] = true;		smiles1 = sg.createSMILES(mol1, true, bool);		assertTrue(smiles1.equals("[H]S/C(F)=C/(F)S[H]"));				mol1.getAtom(5).setPoint2d(new Point2d(0, 3));		mol1.getAtom(4).setPoint2d(new Point2d(2, 3));		smiles1 = sg.createSMILES(mol1, true, bool);		assertTrue(smiles1.equals("[H]S/C(F)=C\\(F)S[H]"));	}	/**	 *  A unit test for JUnit	 */	public void testPartitioning()	{		String smiles = "";		Molecule molecule = new Molecule();        SmilesGenerator sg = new SmilesGenerator();		Atom sodium = new Atom("Na");		sodium.setFormalCharge(+1);		Atom hydroxyl = new Atom("O");

⌨️ 快捷键说明

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