1 /* Copyright (C) 2010 Egon Willighagen <egonw@users.sf.net> 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 org.junit.Assert; 22 import org.junit.Before; 23 import org.junit.Test; 24 import org.openscience.cdk.AtomContainer; 25 import org.openscience.cdk.interfaces.IAtom; 26 import org.openscience.cdk.interfaces.IAtomContainer; 27 import org.openscience.cdk.interfaces.IBond; 28 import org.openscience.cdk.interfaces.IChemObjectBuilder; 29 import org.openscience.cdk.qsar.result.IntegerResult; 30 import org.openscience.cdk.silent.SilentChemObjectBuilder; 31 import org.openscience.cdk.smiles.SmilesParser; 32 import org.openscience.cdk.tools.manipulator.AtomContainerManipulator; 33 34 /** 35 * @cdk.module test-qsarmolecular 36 */ 37 public class BasicGroupCountDescriptorTest extends MolecularDescriptorTest { 38 39 @Before setUp()40 public void setUp() throws Exception { 41 setDescriptor(BasicGroupCountDescriptor.class); 42 } 43 44 @Test testConstructor()45 public void testConstructor() throws Exception { 46 Assert.assertNotNull(new BasicGroupCountDescriptor()); 47 } 48 49 @Test testAmine()50 public void testAmine() throws Exception { 51 SmilesParser sp = new SmilesParser(SilentChemObjectBuilder.getInstance()); 52 IAtomContainer mol = sp.parseSmiles("NC"); 53 IntegerResult result = (IntegerResult) descriptor.calculate(mol).getValue(); 54 Assert.assertEquals(1, result.intValue()); 55 } 56 57 @Test(expected = IllegalStateException.class) uninitalisedError()58 public void uninitalisedError() { 59 new BasicGroupCountDescriptor().calculate(new AtomContainer()); 60 } 61 62 /** 63 * @cdk.inchi InChI=1S/C2H4N2/c1-4-2-3/h2-3H,1H2 64 */ 65 @Test test()66 public void test() throws Exception { 67 IChemObjectBuilder builder = SilentChemObjectBuilder.getInstance(); 68 IAtomContainer mol = builder.newInstance(IAtomContainer.class); 69 IAtom a1 = builder.newInstance(IAtom.class, "N"); 70 mol.addAtom(a1); 71 IAtom a2 = builder.newInstance(IAtom.class, "N"); 72 mol.addAtom(a2); 73 IAtom a3 = builder.newInstance(IAtom.class, "C"); 74 mol.addAtom(a3); 75 IAtom a4 = builder.newInstance(IAtom.class, "C"); 76 mol.addAtom(a4); 77 IAtom a5 = builder.newInstance(IAtom.class, "H"); 78 mol.addAtom(a5); 79 IAtom a6 = builder.newInstance(IAtom.class, "H"); 80 mol.addAtom(a6); 81 IAtom a7 = builder.newInstance(IAtom.class, "H"); 82 mol.addAtom(a7); 83 IAtom a8 = builder.newInstance(IAtom.class, "H"); 84 mol.addAtom(a8); 85 IBond b1 = builder.newInstance(IBond.class, a1, a3, IBond.Order.SINGLE); 86 mol.addBond(b1); 87 IBond b2 = builder.newInstance(IBond.class, a1, a4, IBond.Order.DOUBLE); 88 mol.addBond(b2); 89 IBond b3 = builder.newInstance(IBond.class, a2, a3, IBond.Order.DOUBLE); 90 mol.addBond(b3); 91 IBond b4 = builder.newInstance(IBond.class, a2, a8, IBond.Order.SINGLE); 92 mol.addBond(b4); 93 IBond b5 = builder.newInstance(IBond.class, a3, a5, IBond.Order.SINGLE); 94 mol.addBond(b5); 95 IBond b6 = builder.newInstance(IBond.class, a4, a6, IBond.Order.SINGLE); 96 mol.addBond(b6); 97 IBond b7 = builder.newInstance(IBond.class, a4, a7, IBond.Order.SINGLE); 98 mol.addBond(b7); 99 100 AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(mol); 101 addImplicitHydrogens(mol); 102 103 IntegerResult result = (IntegerResult) descriptor.calculate(mol).getValue(); 104 // two SMARTS matches 105 Assert.assertEquals(2, result.intValue()); 106 } 107 } 108