1 /* Copyright (C) 2018  Jeffrey Plante (Lhasa Limited)  <Jeffrey.Plante@lhasalimited.org>
2  *
3  * This program is free software; you can redistribute it and/or
4  * modify it under the terms of the GNU Lesser General Public License
5  * as published by the Free Software Foundation; either version 2.1
6  * of the License, or (at your option) any later version.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  * GNU Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
16  */
17 package org.openscience.cdk.qsar.descriptors.molecular;
18 
19 import static org.junit.Assert.*;
20 
21 import java.util.Map;
22 
23 import org.junit.Test;
24 import org.openscience.cdk.aromaticity.Aromaticity;
25 import org.openscience.cdk.exception.CDKException;
26 import org.openscience.cdk.interfaces.IAtomContainer;
27 import org.openscience.cdk.qsar.DescriptorSpecification;
28 import org.openscience.cdk.qsar.DescriptorValue;
29 import org.openscience.cdk.qsar.descriptors.molecular.JPlogPDescriptor;
30 import org.openscience.cdk.qsar.result.DoubleResult;
31 import org.openscience.cdk.silent.SilentChemObjectBuilder;
32 import org.openscience.cdk.smiles.SmilesParser;
33 import org.openscience.cdk.tools.manipulator.AtomContainerManipulator;
34 
35 public class JPlogPDescriptorTest {
36 
37 	static SmilesParser parser = null;
38 
39 	@Test
testPyridine()40 	public void testPyridine() throws CDKException {
41 		parser = new SmilesParser(SilentChemObjectBuilder.getInstance());
42 		IAtomContainer struct = parseSmiles("c1ncccc1");
43 		JPlogPDescriptor desc = new JPlogPDescriptor();
44 		DescriptorValue answer = desc.calculate(struct);
45 		DoubleResult result = (DoubleResult) answer.getValue();
46 		double output = result.doubleValue();
47 		assertEquals(0.9, output, 0.1);
48 	}
49 
50 	@Test
testPropionicAcid()51 	public void testPropionicAcid() throws CDKException {
52 		parser = new SmilesParser(SilentChemObjectBuilder.getInstance());
53 		IAtomContainer struct = parseSmiles("CCC(=O)O");
54 		JPlogPDescriptor desc = new JPlogPDescriptor();
55 		DescriptorValue answer = desc.calculate(struct);
56 		DoubleResult result = (DoubleResult) answer.getValue();
57 		double output = result.doubleValue();
58 		assertEquals(0.3, output, 0.1);
59 	}
60 
61 	@Test
testAcetonitrile()62 	public void testAcetonitrile() throws CDKException {
63 		parser = new SmilesParser(SilentChemObjectBuilder.getInstance());
64 		IAtomContainer struct = parseSmiles("CC#N");
65 		JPlogPDescriptor desc = new JPlogPDescriptor();
66 		DescriptorValue answer = desc.calculate(struct);
67 		DoubleResult result = (DoubleResult) answer.getValue();
68 		double output = result.doubleValue();
69 		assertEquals(0.4, output, 0.1);
70 	}
71 
72 	@Test
testAniline()73 	public void testAniline() throws CDKException {
74 		parser = new SmilesParser(SilentChemObjectBuilder.getInstance());
75 		IAtomContainer struct = parseSmiles("Nc1ccccc1");
76 		JPlogPDescriptor desc = new JPlogPDescriptor();
77 		DescriptorValue answer = desc.calculate(struct);
78 		DoubleResult result = (DoubleResult) answer.getValue();
79 		double output = result.doubleValue();
80 		assertEquals(1.2, output, 0.1);
81 	}
82 
83 	@Test
testFluorobenzene()84 	public void testFluorobenzene() throws CDKException {
85 		parser = new SmilesParser(SilentChemObjectBuilder.getInstance());
86 		IAtomContainer struct = parseSmiles("Fc1ccccc1");
87 		JPlogPDescriptor desc = new JPlogPDescriptor();
88 		DescriptorValue answer = desc.calculate(struct);
89 		DoubleResult result = (DoubleResult) answer.getValue();
90 		double output = result.doubleValue();
91 		assertEquals(2.0, output, 0.1);
92 	}
93 
94 	@Test
testSimpleTextFields()95 	public void testSimpleTextFields() {
96 		JPlogPDescriptor desc = new JPlogPDescriptor();
97 		DescriptorSpecification specification = desc.getSpecification();
98 		String name = desc.getDescriptorNames()[0];
99 		assertEquals("JPlogP developed at Lhasa Limited www.lhasalimited.org",
100 				specification.getSpecificationReference());
101 		assertEquals("Jeffrey Plante - Lhasa Limited", specification.getImplementationVendor());
102 		assertEquals("JPLogP", name);
103 		assertEquals(1, desc.getParameterNames().length);
104 		assertEquals("addImplicitH", desc.getParameterNames()[0]);
105 	}
106 
107 	@Test
testGetHologram()108 	public void testGetHologram() throws CDKException {
109 		JPlogPDescriptor desc = new JPlogPDescriptor();
110 		parser = new SmilesParser(SilentChemObjectBuilder.getInstance());
111 		IAtomContainer molecule = parseSmiles("c1ccccc1");
112 		Map<Integer, Integer> holo = desc.jplogp.getMappedHologram(molecule);
113 		assertEquals(2, holo.keySet().size());
114 		assertEquals(6, holo.get(106204).intValue());
115 	}
116 
117 
118 
parseSmiles(String smiles)119 	private static IAtomContainer parseSmiles(String smiles) throws CDKException {
120 		parser = new SmilesParser(SilentChemObjectBuilder.getInstance());
121 		IAtomContainer molecule = parser.parseSmiles(smiles);
122 		AtomContainerManipulator.percieveAtomTypesAndConfigureUnsetProperties(molecule);
123 		AtomContainerManipulator.convertImplicitToExplicitHydrogens(molecule);
124 		Aromaticity.cdkLegacy().apply(molecule);
125 		return molecule;
126 	}
127 
128 }
129