1package denoptim.fitness;
22import static org.junit.jupiter.api.Assertions.assertEquals;
23import static org.junit.jupiter.api.Assertions.assertTrue;
24import static org.junit.jupiter.api.Assertions.fail;
27import java.util.HashMap;
31import org.junit.jupiter.api.BeforeEach;
32import org.junit.jupiter.api.Test;
33import org.junit.jupiter.api.io.TempDir;
34import org.openscience.cdk.interfaces.IAtomContainer;
35import org.openscience.cdk.silent.SilentChemObjectBuilder;
36import org.openscience.cdk.smiles.SmilesParser;
38import denoptim.io.DenoptimIO;
49 private SmilesParser
sp;
50 private static final String
SEP = System.getProperty(
"file.separator");
58 assertTrue(
tempDir.isDirectory(),
"Should be a directory ");
59 sp =
new SmilesParser(SilentChemObjectBuilder.getInstance());
67 String fileName =
tempDir.getAbsolutePath() +
SEP +
"ref.sdf";
68 IAtomContainer ref =
sp.parseSmiles(
"CNC(=O)c1cc(OC)ccc1");
72 String[] lines =
new String[] {
73 "FP-Equation=${taniSym + taniBis + 3.3 * Zagreb - aHyb_1 + "
75 "FP-DescriptorSpecs=${Variable.atomSpecific('aHyb_1','aHyb','[$([C])]')}",
76 "FP-DescriptorSpecs=${Variable.atomSpecific('aHyb_2','aHyb','[$([N])]')}",
77 "FP-DescriptorSpecs=${Variable.parametrized('taniSym',"
78 +
"'TanimotoSimilarity','PubchemFingerprinter, "
79 +
"FILE:" + fileName +
"')}",
80 "FP-DescriptorSpecs=${Variable.parametrized('taniBis',"
81 +
"'TanimotoSimilarity','Fingerprinter, "
82 +
"FILE:" + fileName +
"')}"};
83 for (
int i=0; i<lines.length; i++)
85 String line = lines[i];
92 assertEquals(4,descriptors.size(),
93 "Number of descriptor implementation");
95 Map<String,Integer> counts =
new HashMap<String,Integer>();
98 String key = d.getShortName();
99 if (counts.containsKey(key))
100 counts.put(key,counts.get(key) + 1);
104 String[] expectedNames =
new String[] {
"aHyb",
105 "TanimotoSimilarity",
"Zagreb"};
106 int[] expectedCount =
new int[] {1,2,1};
107 for (
int i=0; i<3; i++)
109 assertEquals(expectedCount[i], counts.get(expectedNames[i]),
110 "Number of " + expectedNames[i] +
" implementations");
113 boolean foundA =
false;
114 boolean foundB =
false;
115 for (
int i=0; i<descriptors.size(); i++)
124 assertEquals(2,variables.size(),
125 "Number of variable names for #"+i+
" "+descName);
126 boolean foundOne =
false;
127 boolean foundTwo =
false;
130 if (
"aHyb_1".equals(actual.getName()))
132 if (
"aHyb_2".equals(actual.getName()))
135 assertTrue(foundOne,
"Found first variable aHyb");
136 assertTrue(foundTwo,
"Found second variable aHyb");
140 assertEquals(1,variables.size(),
141 "Number of variable names for #"+i+
" "+descName);
142 assertEquals(
"Zagreb",variables.get(0).getName(),
143 "Name of variable for #"+i);
146 case "TanimotoSimilarity":
147 assertEquals(1,variables.size(),
148 "Number of variable names for #"+i+
" "+descName);
149 if (
"taniSym".equals(variables.get(0).getName()))
151 if (
"taniBis".equals(variables.get(0).getName()))
156 fail(
"Unexpected descriptor name "+descName);
159 assertTrue(foundA,
"Tanimoto-variable A");
160 assertTrue(foundB,
"Tanimoto-variable B");
This is a reference to a specific descriptor value.
List< Variable > getVariables()
Get the variables that make use of values produced by this descriptor.
Unit test for parser of fitness-defining expressions.
void testProcessExpressions()
Settings defining the calculation of fitness.
void processParameters()
Processes all parameters and initialize related objects.
List< DescriptorForFitness > getDescriptors()
void interpretKeyword(String key, String value)
Processes a keyword/value pair and assign the related parameters.
A variable in the expression defining the fitness.
Utility methods for input/output.
static void writeSDFFile(String fileName, IAtomContainer mol)
Writes IAtomContainer to SDF file.