1 /* Copyright (C) 2004-2007  The Chemistry Development Kit (CDK) project
2  *
3  * Contact: cdk-devel@lists.sourceforge.net
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public License
7  * as published by the Free Software Foundation; either version 2.1
8  * of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 package org.openscience.cdk.qsar.descriptors.molecular;
20 
21 import java.io.InputStream;
22 import java.util.List;
23 
24 import org.junit.Assert;
25 import org.junit.Before;
26 import org.junit.Test;
27 import org.openscience.cdk.ChemFile;
28 import org.openscience.cdk.ChemObject;
29 import org.openscience.cdk.DefaultChemObjectBuilder;
30 import org.openscience.cdk.exception.CDKException;
31 import org.openscience.cdk.interfaces.IAtomContainer;
32 import org.openscience.cdk.io.ISimpleChemObjectReader;
33 import org.openscience.cdk.io.MDLV2000Reader;
34 import org.openscience.cdk.qsar.DescriptorValue;
35 import org.openscience.cdk.qsar.result.DoubleArrayResult;
36 import org.openscience.cdk.smiles.SmilesParser;
37 import org.openscience.cdk.tools.manipulator.ChemFileManipulator;
38 
39 /**
40  * TestSuite that runs all QSAR tests.
41  *
42  * @cdk.module test-qsarmolecular
43  */
44 
45 public class PetitjeanShapeIndexDescriptorTest extends MolecularDescriptorTest {
46 
PetitjeanShapeIndexDescriptorTest()47     public PetitjeanShapeIndexDescriptorTest() {}
48 
49     @Before
setUp()50     public void setUp() throws Exception {
51         setDescriptor(PetitjeanShapeIndexDescriptor.class);
52     }
53 
54     @Test
testPetitjeanShapeIndexDescriptor()55     public void testPetitjeanShapeIndexDescriptor() throws ClassNotFoundException, CDKException, Exception {
56         // first molecule is nbutane, second is naphthalene
57         String filename = "data/mdl/petitejean.sdf";
58         InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename);
59         ISimpleChemObjectReader reader = new MDLV2000Reader(ins);
60         ChemFile content = (ChemFile) reader.read((ChemObject) new ChemFile());
61         List cList = ChemFileManipulator.getAllAtomContainers(content);
62         IAtomContainer ac = (IAtomContainer) cList.get(0);
63 
64         DescriptorValue result = descriptor.calculate(ac);
65         DoubleArrayResult dar = (DoubleArrayResult) result.getValue();
66         Assert.assertEquals(0.5, dar.get(0), 0.00001);
67         Assert.assertEquals(0.606477, dar.get(1), 0.000001);
68 
69         ac = (IAtomContainer) cList.get(1);
70         result = descriptor.calculate(ac);
71         dar = (DoubleArrayResult) result.getValue();
72         Assert.assertEquals(0.666666, dar.get(0), 0.000001);
73         Assert.assertEquals(0.845452, dar.get(1), 0.000001);
74 
75     }
76 
77     @Test
testPetiteJeanShapeNo3D()78     public void testPetiteJeanShapeNo3D() throws Exception {
79         SmilesParser sp = new SmilesParser(DefaultChemObjectBuilder.getInstance());
80         IAtomContainer atomContainer = sp.parseSmiles("CCCOCCC(O)=O");
81         DescriptorValue result = descriptor.calculate(atomContainer);
82         DoubleArrayResult dar = (DoubleArrayResult) result.getValue();
83         Assert.assertTrue(Double.isNaN(dar.get(1)));
84 
85     }
86 }
87