1 /* 2 * Copyright (C) 2004-2007 The Chemistry Development Kit (CDK) project 3 * 4 * Contact: cdk-devel@lists.sourceforge.net 5 * 6 * This program is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU Lesser General Public License 8 * as published by the Free Software Foundation; either version 2.1 9 * of the License, or (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU Lesser General Public License for more details. 15 * 16 * You should have received a copy of the GNU Lesser General Public License 17 * along with this program; if not, write to the Free Software 18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 19 */ 20 package org.openscience.cdk.qsar.descriptors.molecular; 21 22 import java.io.InputStream; 23 import java.util.List; 24 25 import org.junit.Assert; 26 import org.junit.Before; 27 import org.junit.Test; 28 import org.openscience.cdk.ChemFile; 29 import org.openscience.cdk.ChemObject; 30 import org.openscience.cdk.DefaultChemObjectBuilder; 31 import org.openscience.cdk.exception.CDKException; 32 import org.openscience.cdk.exception.InvalidSmilesException; 33 import org.openscience.cdk.interfaces.IAtomContainer; 34 import org.openscience.cdk.io.HINReader; 35 import org.openscience.cdk.io.ISimpleChemObjectReader; 36 import org.openscience.cdk.qsar.DescriptorValue; 37 import org.openscience.cdk.qsar.result.DoubleArrayResult; 38 import org.openscience.cdk.smiles.SmilesParser; 39 import org.openscience.cdk.tools.manipulator.ChemFileManipulator; 40 41 /** 42 * TestSuite that runs all QSAR tests. 43 * 44 * @cdk.module test-qsarmolecular 45 */ 46 47 public class MomentOfInertiaDescriptorTest extends MolecularDescriptorTest { 48 MomentOfInertiaDescriptorTest()49 public MomentOfInertiaDescriptorTest() {} 50 51 @Before setUp()52 public void setUp() throws Exception { 53 setDescriptor(MomentOfInertiaDescriptor.class); 54 } 55 56 /** 57 * @cdk.bug 1956139 58 * @throws InvalidSmilesException 59 */ 60 @Test testMOIFromSmiles()61 public void testMOIFromSmiles() throws InvalidSmilesException { 62 SmilesParser sp = new SmilesParser(DefaultChemObjectBuilder.getInstance()); 63 IAtomContainer mol = sp.parseSmiles("CCCC"); 64 DescriptorValue value = descriptor.calculate(mol); 65 Assert.assertNotNull("The Exception should be non-null since we don't have 3D coords", value.getException()); 66 67 } 68 69 @Test testMomentOfInertia1()70 public void testMomentOfInertia1() throws ClassNotFoundException, CDKException, java.lang.Exception { 71 String filename = "data/hin/gravindex.hin"; 72 InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); 73 ISimpleChemObjectReader reader = new HINReader(ins); 74 ChemFile content = (ChemFile) reader.read((ChemObject) new ChemFile()); 75 List cList = ChemFileManipulator.getAllAtomContainers(content); 76 IAtomContainer ac = (IAtomContainer) cList.get(0); 77 78 DoubleArrayResult retval = (DoubleArrayResult) descriptor.calculate(ac).getValue(); 79 80 Assert.assertEquals(1820.692519, retval.get(0), 0.00001); 81 Assert.assertEquals(1274.532522, retval.get(1), 0.00001); 82 Assert.assertEquals(979.210423, retval.get(2), 0.00001); 83 Assert.assertEquals(1.428517, retval.get(3), 0.00001); 84 Assert.assertEquals(1.859347, retval.get(4), 0.00001); 85 Assert.assertEquals(1.301592, retval.get(5), 0.00001); 86 Assert.assertEquals(5.411195, retval.get(6), 0.00001); 87 } 88 89 @Test testMomentOfInertia2()90 public void testMomentOfInertia2() throws ClassNotFoundException, CDKException, java.lang.Exception { 91 String filename = "data/hin/momi2.hin"; 92 InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); 93 ISimpleChemObjectReader reader = new HINReader(ins); 94 ChemFile content = (ChemFile) reader.read((ChemObject) new ChemFile()); 95 List cList = ChemFileManipulator.getAllAtomContainers(content); 96 IAtomContainer ac = (IAtomContainer) cList.get(0); 97 98 DoubleArrayResult retval = (DoubleArrayResult) descriptor.calculate(ac).getValue(); 99 100 Assert.assertEquals(10068.419360, retval.get(0), 0.00001); 101 Assert.assertEquals(9731.078356, retval.get(1), 0.00001); 102 Assert.assertEquals(773.612799, retval.get(2), 0.00001); 103 Assert.assertEquals(1.034666, retval.get(3), 0.00001); 104 Assert.assertEquals(13.014804, retval.get(4), 0.00001); 105 Assert.assertEquals(12.578745, retval.get(5), 0.00001); 106 Assert.assertEquals(8.2966226, retval.get(6), 0.00001); 107 } 108 109 } 110