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

📄 forcefieldtests.java

📁 化学图形处理软件
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
/* $Revision: 8201 $ $Author: egonw $ $Date: 2007-04-16 08:40:19 +0000 (Mo, 16 Apr 2007) $ * *  Copyright (C) 2005-2007  Violeta Labarta Beceiro <vlabarta@yahoo.com> * *  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.modeling.forcefield;import java.io.FileWriter;import java.io.InputStream;import java.util.Hashtable;import javax.vecmath.GVector;import javax.vecmath.Point3d;import junit.framework.Test;import junit.framework.TestSuite;import org.openscience.cdk.RingSet;import org.openscience.cdk.exception.CDKException;import org.openscience.cdk.interfaces.IAtomContainer;import org.openscience.cdk.interfaces.IMolecule;import org.openscience.cdk.io.MDLReader;import org.openscience.cdk.io.MDLWriter;import org.openscience.cdk.modeling.builder3d.ForceFieldConfigurator;import org.openscience.cdk.modeling.forcefield.AngleBending;import org.openscience.cdk.modeling.forcefield.BondStretching;import org.openscience.cdk.modeling.forcefield.ElectrostaticInteractions;import org.openscience.cdk.modeling.forcefield.ForceField;import org.openscience.cdk.modeling.forcefield.ForceFieldTools;import org.openscience.cdk.modeling.forcefield.GeometricMinimizer;import org.openscience.cdk.modeling.forcefield.MMFF94EnergyFunction;import org.openscience.cdk.modeling.forcefield.SmoothingFunctions;import org.openscience.cdk.modeling.forcefield.StretchBendInteractions;import org.openscience.cdk.modeling.forcefield.Torsions;import org.openscience.cdk.modeling.forcefield.VanDerWaalsInteractions;import org.openscience.cdk.test.CDKTestCase;import org.openscience.cdk.tools.LoggingTool;/** *  Check forcefield package using some examples. * *@author         vlabarta *@cdk.module     test-forcefield *@cdk.created    2005-01-17 */public class ForceFieldTests extends CDKTestCase {	IMolecule molecule = null;	IAtomContainer ac = null;	GVector moleculeCoordinates = null;	GeometricMinimizer gm = new GeometricMinimizer();	Hashtable mmff94Tables = null;	MMFF94EnergyFunction mmff94Energy = null;	double[] molecule3Coord = {9, 9, 0};	GVector molecule3Coordinates = new GVector(molecule3Coord);	TestPotentialFunction tpf = new TestPotentialFunction();	double[] testResult3C = {0, 0, 0};		String input;	private LoggingTool logger;	private boolean standAlone = false;	/**	 *  Constructor for ForceFieldTests object	 */	public ForceFieldTests() {		logger = new LoggingTool(this);	}		public void setUp() throws Exception {		input = "Ethane-TestFF";		InputStream is = this.getClass().getClassLoader().getResourceAsStream("data/mdl/" + input + ".mol");		MDLReader mdlReader = new MDLReader(is);		molecule = (IMolecule)mdlReader.read(new org.openscience.cdk.Molecule());		mdlReader.close();		//logger.debug("molecule: " +  molecule);		gm.setMMFF94Tables(molecule);		mmff94Tables = gm.getPotentialParameterSet();		moleculeCoordinates = ForceFieldTools.getCoordinates3xNVector(molecule);	}	/**	 *  A unit test suite for JUnit	 *	 *@return    The test suite	 */	public static Test suite() {		return new TestSuite(ForceFieldTests.class);	}	/**	 *  Get MMFF94 energy of a molecule (methylbenzol).	 */	public void testGetMMFF94EnergyOfAMolecule() throws Exception {				double testResult_mmff94Energy = 92473.5759007652; //(methylbenzol)				//logger.debug("");		//logger.debug("FORCEFIELDTESTS Get MMFF94 energy of a molecule (methylbenzol)");		double energy = 0;		String localInput = "methylbenzol";				InputStream is = this.getClass().getClassLoader().getResourceAsStream("data/mdl/" + localInput + ".mol");		//FileReader fileReader = new FileReader("data/mdl/" + localInput + ".mol");		MDLReader mdlReader = new MDLReader(is);		molecule = (IMolecule)mdlReader.read(new org.openscience.cdk.Molecule());		mdlReader.close();		//logger.debug("molecule: " +  molecule);		ForceFieldConfigurator ffc = new ForceFieldConfigurator();		ffc.setForceFieldConfigurator("mmff94");		RingSet rs = (RingSet) ffc.assignAtomTyps((IMolecule) molecule);		mmff94Tables = ffc.getParameterSet();		mmff94Energy = new MMFF94EnergyFunction(molecule, mmff94Tables);		energy = mmff94Energy.energyFunctionOfAMolecule(molecule);		//logger.debug("molecule energy = " + energy);		assertEquals(testResult_mmff94Energy, energy, 0.00001);	}		/**	 *  A unit test for JUnit (Steepest Descents Method minimization)	 */	public void testSteepestDescentsMinimization() throws Exception {		//logger.debug("");		//logger.debug("FORCEFIELDTESTS with Steepest Descents Minimization");		gm.setConvergenceParametersForSDM(100, 0.00001);		gm.steepestDescentsMinimization(molecule3Coordinates, tpf);		for (int i = 0; i < molecule3Coordinates.getSize(); i++) {			assertEquals(testResult3C[i], gm.getSteepestDescentsMinimum().getElement(i), 0.0001);		}	} 	/**	 *  A unit test for JUnit (Conjugate Gradient Method minimization)	 */	public void testConjugateGradientMinimization() throws Exception {		//logger.debug("");		//logger.debug("FORCEFIELDTESTS with Conjugate Gradient Minimization");		gm.setConvergenceParametersForCGM(100, 0.00001);		gm.conjugateGradientMinimization(molecule3Coordinates, tpf);		for (int i = 0; i < molecule3Coordinates.getSize(); i++) {			assertEquals(testResult3C[i], gm.getConjugateGradientMinimum().getElement(i), 0.00001);		}	}	/**	 *  A unit test for JUnit (Newton-Raphson Method minimization)	 */	public void testNewtonRaphsonMinimization() {		//logger.debug("");		//logger.debug("FORCEFIELDTESTS with Newton-Raphson Minimization");		gm.setConvergenceParametersForNRM(1000, 0.00001);		gm.newtonRaphsonMinimization(molecule3Coordinates, tpf);		for (int i = 0; i < molecule3Coordinates.getSize(); i++) {			assertEquals(testResult3C[i], gm.getNewtonRaphsonMinimum().getElement(i), 0.00001);		}	}

⌨️ 快捷键说明

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