19package denoptim.fitness.descriptors;
21import java.lang.reflect.Constructor;
23import org.openscience.cdk.DefaultChemObjectBuilder;
24import org.openscience.cdk.exception.CDKException;
25import org.openscience.cdk.fingerprint.IBitFingerprint;
26import org.openscience.cdk.fingerprint.IFingerprinter;
27import org.openscience.cdk.fingerprint.ShortestPathFingerprinter;
28import org.openscience.cdk.interfaces.IAtomContainer;
29import org.openscience.cdk.interfaces.IChemObjectBuilder;
30import org.openscience.cdk.qsar.AbstractMolecularDescriptor;
31import org.openscience.cdk.qsar.DescriptorSpecification;
32import org.openscience.cdk.qsar.DescriptorValue;
33import org.openscience.cdk.qsar.IMolecularDescriptor;
34import org.openscience.cdk.qsar.result.DoubleResult;
35import org.openscience.cdk.qsar.result.DoubleResultType;
36import org.openscience.cdk.qsar.result.IDescriptorResult;
37import org.openscience.cdk.similarity.Tanimoto;
38import org.openscience.cdk.tools.manipulator.AtomContainerManipulator;
40import denoptim.fitness.IDenoptimDescriptor;
56 private static final String[]
PARAMNAMES =
new String[] {
57 "fingerprinterImplementation",
"referenceFingerprint"};
59 private static final String[]
NAMES = {
"TanimotoSimilarity"};
65 DefaultChemObjectBuilder.getInstance();
93 return new DescriptorSpecification(
"Denoptim source code",
94 this.getClass().getName(), paramID,
"DENOPTIM project");
116 return IBitFingerprint.class;
120 throw new IllegalArgumentException(
"No parameter for name: "+name);
136 if (params.length != 2)
138 throw new IllegalArgumentException(
"TanimotoMolSimilarity only "
139 +
"expects two parameter");
141 if (!(params[1] instanceof IBitFingerprint))
143 throw new IllegalArgumentException(
"Parameter does not implemet "
144 +
"IBitFingerprint.");
146 if (!(params[0] instanceof String))
148 throw new IllegalArgumentException(
"Parameter is not String ("
149 + params[0].getClass().getName() +
").");
165 IFingerprinter fp =
null;
168 Class<?> cl = Class.forName(
"org.openscience.cdk.fingerprint."
170 for (Constructor<?> constructor : cl.getConstructors())
172 Class<?>[] params = constructor.getParameterTypes();
173 if (params.length == 0)
175 fp = (IFingerprinter) constructor.newInstance();
176 }
else if (params[0].equals(IChemObjectBuilder.class))
179 fp = (IFingerprinter) constructor.newInstance(
cdkBuilder);
182 }
catch (Throwable t)
185 throw new CDKException(
"Could not make new instance of '"
186 + classShortName +
"'.", t);
190 throw new CDKException(
"Could not make new instance of '"
191 + classShortName +
"'. No suitable constructor found.");
202 Object[] params =
new Object[2];
227 AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(mol);
228 }
catch (CDKException e1)
230 throw new IllegalStateException(
"Could not assign atom types "
231 +
"to calculate fingerprint of input molecule.",
239 throw new IllegalStateException(
"Reference fingerprint not set. "
240 +
"Cannot calculate Tanimoto similarity.");
244 throw new IllegalStateException(
"Fingerprinter not set. "
245 +
"Cannot calculate Tanimoto similarity.");
252 }
catch (IllegalArgumentException e)
255 result =
new DoubleResult(Double.NaN);
256 }
catch (CDKException e)
259 result =
new DoubleResult(Double.NaN);
275 return new DoubleResultType();
284 return "Tanimoto Molecular Similarity";
293 return "The Tanimoto Molecular Similarity is calculated between the "
294 +
"reference fingerprint given upon definition of the "
295 +
"descriptor (see parameters), and a molecule given as "
296 +
"argument when calculating the value of the descriptor. "
297 +
"Fingerprints are obtained from a new instance of"
298 +
"<code>IFingerprinter</code>, which is created according to "
299 +
"the parameter <code>" +
PARAMNAMES[0] +
"</code>, "
300 +
"and take the form of "
301 +
"<code>IFingerprinter.getBitFingerprint(mol)</code>";
310 return new String[] {
"molecular"};
Calculates the molecular similarity against a target compound the fingerprint of which is given as pa...
DescriptorValue calculate(IAtomContainer mol)
void setParameters(Object[] params)
Set the parameters attribute of TanimotoMolSimilarity object.
String getDictionaryDefinition()
Get a string that describes the descriptor in detail.Might contain mathematical formulation....
static IFingerprinter makeIFingerprinter(String classShortName)
DescriptorSpecification getSpecification()
Get the specification attribute of Tanimoto molecular similarity.
static final String[] PARAMNAMES
String[] getParameterNames()
Gets the parameterNames attribute of the TanimotoMolSimilarity object.
IBitFingerprint referenceFingerprint
TanimotoMolSimilarity()
Constructor for a TanimotoMolSimilarity object.
Object getParameterType(String name)
static IChemObjectBuilder cdkBuilder
Utility for constructing CDK objects.
String[] getDescriptorNames()
String[] getDictionaryClass()
Get the classification of this descriptor.A descriptor can belong to one or more classes simultaneous...
IFingerprinter fingerprinter
static final String[] NAMES
IDescriptorResult getDescriptorResultType()
String getDictionaryTitle()
Gets the title of this descriptor as it should be in the dictionary.the title
This interface forces descriptors that are not defined in the CDK ontology to provide information tha...