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

📄 hueckelaromaticitydetectortest.java

📁 化学图形处理软件
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*  $RCSfile$ *  $Author: egonw $ *  $Date: 2007-04-21 00:23:13 +0000 (Sa, 21 Apr 2007) $ *  $Revision: 8225 $ * *  Copyright (C) 1997-2007  The Chemistry Development Kit (CDK) project * *  Contact: cdk-devel@list.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.aromaticity;import java.io.InputStream;import javax.vecmath.Point2d;import junit.framework.Test;import junit.framework.TestSuite;import org.openscience.cdk.CDKConstants;import org.openscience.cdk.ChemObject;import org.openscience.cdk.DefaultChemObjectBuilder;import org.openscience.cdk.Molecule;import org.openscience.cdk.Ring;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.interfaces.IRing;import org.openscience.cdk.interfaces.IRingSet;import org.openscience.cdk.io.MDLReader;import org.openscience.cdk.ringsearch.AllRingsFinder;import org.openscience.cdk.ringsearch.SSSRFinder;import org.openscience.cdk.smiles.SmilesParser;import org.openscience.cdk.templates.MoleculeFactory;import org.openscience.cdk.test.CDKTestCase;import org.openscience.cdk.tools.LoggingTool;/** *  Description of the Class * * @cdk.module test-standard * *@author     steinbeck *@cdk.created    2002-10-06 */public class HueckelAromaticityDetectorTest extends CDKTestCase{	boolean standAlone = false;	private static LoggingTool logger = new LoggingTool(HueckelAromaticityDetectorTest.class);	/**	 *  Constructor for the HueckelAromaticityDetectorTest object	 *	 *@param  name  Description of the Parameter	 */	public HueckelAromaticityDetectorTest(String name)	{		super(name);	}	/**	 *  A unit test suite for JUnit	 *	 *@return    The test suite	 */	public static Test suite()	{		return new TestSuite(HueckelAromaticityDetectorTest.class);	}	/**	 *  Sets the standAlone attribute of the HueckelAromaticityDetectorTest object	 *	 *@param  standAlone  The new standAlone value	 */	public void setStandAlone(boolean standAlone)	{		this.standAlone = standAlone;	}	public void testDetectAromaticity_IAtomContainer() throws Exception	{		IMolecule mol = makeAromaticMolecule();		HueckelAromaticityDetector.detectAromaticity(mol);		int numberOfAromaticAtoms = 0;		for (int i = 0; i < mol.getAtomCount(); i++) {			if (((IAtom)mol.getAtom(i)).getFlag(CDKConstants.ISAROMATIC))				numberOfAromaticAtoms++;		}		assertEquals(6, numberOfAromaticAtoms);		int numberOfAromaticBonds= 0;		for (int i = 0; i < mol.getBondCount(); i++) {			if (((IBond)mol.getBond(i)).getFlag(CDKConstants.ISAROMATIC))				numberOfAromaticBonds++;		}		assertEquals(6, numberOfAromaticBonds);				}		public void testDetectAromaticity_IAtomContainer_IRingSet() throws Exception	{				IMolecule mol = makeAromaticMolecule();		IRingSet rs = (new AllRingsFinder()).findAllRings(mol);		HueckelAromaticityDetector.detectAromaticity(mol, rs);		int numberOfAromaticAtoms = 0;		for (int i = 0; i < mol.getAtomCount(); i++) {			if (((IAtom)mol.getAtom(i)).getFlag(CDKConstants.ISAROMATIC))				numberOfAromaticAtoms++;		}		assertEquals(6, numberOfAromaticAtoms);		int numberOfAromaticBonds= 0;		for (int i = 0; i < mol.getBondCount(); i++) {			if (((IBond)mol.getBond(i)).getFlag(CDKConstants.ISAROMATIC))				numberOfAromaticBonds++;		}		assertEquals(6, numberOfAromaticBonds);				}		public void testDetectAromaticity_IAtomContainer_boolean() throws Exception	{				IMolecule mol = makeAromaticMolecule();		for (int i = 0; i < mol.getAtomCount(); ++i) mol.getAtom(i).setFlag(CDKConstants.ISAROMATIC, true);		HueckelAromaticityDetector.detectAromaticity(mol, false);		int numberOfAromaticAtoms = 0;		for (int i = 0; i < mol.getAtomCount(); i++) {			if (((IAtom)mol.getAtom(i)).getFlag(CDKConstants.ISAROMATIC))				numberOfAromaticAtoms++;		}		assertEquals(10, numberOfAromaticAtoms);		int numberOfAromaticBonds= 0;		for (int i = 0; i < mol.getBondCount(); i++) {			if (((IBond)mol.getBond(i)).getFlag(CDKConstants.ISAROMATIC))				numberOfAromaticBonds++;		}		assertEquals(11, numberOfAromaticBonds);					mol = makeAromaticMolecule();		for (int i = 0; i < mol.getAtomCount(); ++i) mol.getAtom(i).setFlag(CDKConstants.ISAROMATIC, true);		HueckelAromaticityDetector.detectAromaticity(mol, true);		numberOfAromaticAtoms = 0;		for (int i = 0; i < mol.getAtomCount(); i++) {			if (((IAtom)mol.getAtom(i)).getFlag(CDKConstants.ISAROMATIC))				numberOfAromaticAtoms++;		}		assertEquals(6, numberOfAromaticAtoms);		numberOfAromaticBonds= 0;		for (int i = 0; i < mol.getBondCount(); i++) {			if (((IBond)mol.getBond(i)).getFlag(CDKConstants.ISAROMATIC))				numberOfAromaticBonds++;		}		assertEquals(6, numberOfAromaticBonds);				}		public void testDetectAromaticity_IAtomContainer_boolean_AllRingsFinder() throws Exception	{		IMolecule mol = makeAromaticMolecule();		for (int i = 0; i < mol.getAtomCount(); ++i) mol.getAtom(i).setFlag(CDKConstants.ISAROMATIC, true);		HueckelAromaticityDetector.detectAromaticity(mol, false, new AllRingsFinder());		int numberOfAromaticAtoms = 0;		for (int i = 0; i < mol.getAtomCount(); i++) {			if (((IAtom)mol.getAtom(i)).getFlag(CDKConstants.ISAROMATIC))				numberOfAromaticAtoms++;		}		assertEquals(10, numberOfAromaticAtoms);		int numberOfAromaticBonds= 0;		for (int i = 0; i < mol.getBondCount(); i++) {			if (((IBond)mol.getBond(i)).getFlag(CDKConstants.ISAROMATIC))				numberOfAromaticBonds++;		}		assertEquals(11, numberOfAromaticBonds);					mol = makeAromaticMolecule();		for (int i = 0; i < mol.getAtomCount(); ++i) mol.getAtom(i).setFlag(CDKConstants.ISAROMATIC, true);		HueckelAromaticityDetector.detectAromaticity(mol, true, new AllRingsFinder());		numberOfAromaticAtoms = 0;		for (int i = 0; i < mol.getAtomCount(); i++) {			if (((IAtom)mol.getAtom(i)).getFlag(CDKConstants.ISAROMATIC))				numberOfAromaticAtoms++;		}		assertEquals(6, numberOfAromaticAtoms);		numberOfAromaticBonds= 0;		for (int i = 0; i < mol.getBondCount(); i++) {			if (((IBond)mol.getBond(i)).getFlag(CDKConstants.ISAROMATIC))				numberOfAromaticBonds++;		}		assertEquals(6, numberOfAromaticBonds);				}		public void testDetectAromaticity_IAtomContainer_IRingSet_boolean() throws Exception	{		IMolecule mol = makeAromaticMolecule();		for (int i = 0; i < mol.getAtomCount(); ++i) mol.getAtom(i).setFlag(CDKConstants.ISAROMATIC, true);		IRingSet rs = (new AllRingsFinder()).findAllRings(mol);		HueckelAromaticityDetector.detectAromaticity(mol, rs, false);		int numberOfAromaticAtoms = 0;		for (int i = 0; i < mol.getAtomCount(); i++) {			if (((IAtom)mol.getAtom(i)).getFlag(CDKConstants.ISAROMATIC))				numberOfAromaticAtoms++;		}		assertEquals(10, numberOfAromaticAtoms);		int numberOfAromaticBonds= 0;		for (int i = 0; i < mol.getBondCount(); i++) {			if (((IBond)mol.getBond(i)).getFlag(CDKConstants.ISAROMATIC))				numberOfAromaticBonds++;		}		assertEquals(11, numberOfAromaticBonds);					mol = makeAromaticMolecule();		for (int i = 0; i < mol.getAtomCount(); ++i) mol.getAtom(i).setFlag(CDKConstants.ISAROMATIC, true);		rs = (new AllRingsFinder()).findAllRings(mol);		HueckelAromaticityDetector.detectAromaticity(mol, rs, true);		numberOfAromaticAtoms = 0;		for (int i = 0; i < mol.getAtomCount(); i++) {			if (((IAtom)mol.getAtom(i)).getFlag(CDKConstants.ISAROMATIC))				numberOfAromaticAtoms++;		}		assertEquals(6, numberOfAromaticAtoms);		numberOfAromaticBonds= 0;		for (int i = 0; i < mol.getBondCount(); i++) {			if (((IBond)mol.getBond(i)).getFlag(CDKConstants.ISAROMATIC))				numberOfAromaticBonds++;		}		assertEquals(6, numberOfAromaticBonds);				}		/**	 *  A unit test for JUnit	 */	public void testSetRingFlags_IRingSet() throws Exception	{		IMolecule mol = makeAromaticMolecule();		IRingSet rs = (new AllRingsFinder()).findAllRings(mol);		HueckelAromaticityDetector.detectAromaticity(mol, rs, true);		IRingSet ringset = (new SSSRFinder(mol)).findSSSR();		HueckelAromaticityDetector.setRingFlags(ringset);		int numberOfAromaticRings = 0;		for (int i = 0; i < ringset.getAtomContainerCount(); i++) {			if (((Ring)ringset.getAtomContainer(i)).getFlag(CDKConstants.ISAROMATIC))				numberOfAromaticRings++;		}		assertEquals(numberOfAromaticRings, 1);	}		public void testGetRingSet() throws Exception	{		IMolecule mol = makeAromaticMolecule();		HueckelAromaticityDetector.detectAromaticity(mol);		IRingSet rs = HueckelAromaticityDetector.getRingSet();		assertEquals(3, rs.getAtomContainerCount());				}		public void testSetTimeout_long() throws Exception	{		HueckelAromaticityDetector.setTimeout(1);		IMolecule mol = makeAromaticMolecule();		try {			HueckelAromaticityDetector.detectAromaticity(mol);			int numberOfAromaticAtoms = 0;			for (int i = 0; i < mol.getAtomCount(); i++) {				if (((IAtom)mol.getAtom(i)).getFlag(CDKConstants.ISAROMATIC))					numberOfAromaticAtoms++;			}			fail("Should have failed with an time out exception");					} catch (Exception exc)		{			if (exc.getMessage().equals("Timeout for AllringsFinder exceeded")) {				HueckelAromaticityDetector.setTimeout(5000); // reset timeout to default				return;			}			throw exc;		}	}	//	public void testSetRingFinder_AllRingsFinder()//	{//		// Will fail because it never uses the instance of HAD (static method)//		AllRingsFinder finder = new AllRingsFinder();//		finder.setTimeout(0);//		HueckelAromaticityDetector detector = new HueckelAromaticityDetector(); //		detector.setRingFinder(finder);//		IMolecule mol = makeAromaticMolecule();//		try {//			detector.detectAromaticity(mol);//			int numberOfAromaticAtoms = 0;//			for (int i = 0; i < mol.getAtomCount(); i++) {//				if (((IAtom)mol.getAtom(i)).getFlag(CDKConstants.ISAROMATIC))//					numberOfAromaticAtoms++;//			}//			assertEquals(0, numberOfAromaticAtoms);//			//		} catch (Exception exc)//		{//			if (exc.getMessage().equals("Timeout for AllringsFinder exceeded")) {//				return;//			}//			if (standAlone)//			{//				exc.printStackTrace();//			}//			fail(exc.toString());//		}//	}		public void testHueckelAromaticityDetector()	{		// For autogenerated constructor		HueckelAromaticityDetector detector = new HueckelAromaticityDetector(); 		assertNotNull(detector);	}		public void testPyridine() throws Exception	{		SmilesParser sp = new SmilesParser(DefaultChemObjectBuilder.getInstance());		IMolecule mol = sp.parseSmiles("c1ccncc1");		IRingSet rs = (new AllRingsFinder()).findAllRings(mol);		HueckelAromaticityDetector.detectAromaticity(mol, rs, true);		IRingSet ringset = (new SSSRFinder(mol)).findSSSR();		HueckelAromaticityDetector.setRingFlags(ringset);		int numberOfAromaticRings = 0;		for (int i = 0; i < ringset.getAtomContainerCount(); i++) {			if (((Ring)ringset.getAtomContainer(i)).getFlag(CDKConstants.ISAROMATIC))				numberOfAromaticRings++;		}		assertEquals(numberOfAromaticRings, 1);	}			/**	 *  A unit test for JUnit The special difficulty with Azulene is that only the	 *  outermost larger 10-ring is aromatic according to Hueckel rule.	 */	public void testAzulene() throws Exception	{		boolean[] testResult =				{true,				true,				true,				true,				true,				true,				true,				true,				true,

⌨️ 快捷键说明

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