$darkmode
DENOPTIM
TanimotoMolSimilarityTest.java
Go to the documentation of this file.
1/*
2 * DENOPTIM
3 * Copyright (C) 2022 Marco Foscato <marco.foscato@uib.no>
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Affero General Public License as published
7 * by the Free Software Foundation, either version 3 of the License, or
8 * (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 Affero General Public License for more details.
14 *
15 * You should have received a copy of the GNU Affero General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19package denoptim.fitness.descriptors;
20
21import static org.junit.jupiter.api.Assertions.assertTrue;
22
23import java.lang.reflect.Constructor;
24
25import org.junit.jupiter.api.BeforeEach;
26import org.junit.jupiter.api.Test;
27import org.openscience.cdk.DefaultChemObjectBuilder;
28import org.openscience.cdk.fingerprint.IBitFingerprint;
29import org.openscience.cdk.fingerprint.PubchemFingerprinter;
30import org.openscience.cdk.interfaces.IAtomContainer;
31import org.openscience.cdk.qsar.result.DoubleResult;
32import org.openscience.cdk.smiles.SmilesParser;
33
41{
43
44 @BeforeEach
45 public void setUp() throws Exception
46 {
47 Constructor<TanimotoMolSimilarity> defaultConstructor =
48 TanimotoMolSimilarity.class.getConstructor();
49 this.descriptor = defaultConstructor.newInstance();
50 this.descriptor.initialise(DefaultChemObjectBuilder.getInstance());
51 }
52
53//------------------------------------------------------------------------------
54
55 @Test
56 public void testTanimotoMolSimilarity() throws Exception
57 {
58 SmilesParser sp = new SmilesParser(DefaultChemObjectBuilder.getInstance());
59 IAtomContainer ref = sp.parseSmiles("CNC(=O)c1cc(OC)ccc1");
60 PubchemFingerprinter fpMaker = new PubchemFingerprinter(
61 DefaultChemObjectBuilder.getInstance());
62 IBitFingerprint fpRef = fpMaker.getBitFingerprint(ref);
63
64 Object[] params = {"PubchemFingerprinter", fpRef};
66
67 IAtomContainer mol1 = sp.parseSmiles("COc1ccccc1");
68 double value = ((DoubleResult) descriptor.calculate(mol1).getValue())
69 .doubleValue();
70 assertTrue(closeEnough(0.6,value), "Tanimoto similarity with mol1: "
71 + value);
72
73 IAtomContainer mol2 = sp.parseSmiles("P");
74 value = ((DoubleResult) descriptor.calculate(mol2).getValue())
75 .doubleValue();
76 assertTrue(closeEnough(0.0,value), "Tanimoto similarity with mol2: "
77 + value);
78
79 IAtomContainer mol3 = sp.parseSmiles("COc1cc(C(=O)NC)ccc1");
80 value = ((DoubleResult) descriptor.calculate(mol3).getValue())
81 .doubleValue();
82 assertTrue(closeEnough(1.0,value), "Tanimoto similarity with mol3: "
83 + value);
84 }
85
86//------------------------------------------------------------------------------
87
88 private boolean closeEnough(double expected, double actual)
89 {
90 double threshold = 0.0001;
91 double delta = Math.abs(expected-actual);
92 return delta < threshold;
93 }
94
95//------------------------------------------------------------------------------
96
97}
Calculates the molecular similarity against a target compound the fingerprint of which is given as pa...
void setParameters(Object[] params)
Set the parameters attribute of TanimotoMolSimilarity object.
Unit test for descriptor TanimotoMolSimilarity.