getTversky throws exception

User 7c177bab3b

07-07-2010 11:07:38


Trying to use fp.getTverksy()  throws a null pointer exception.

Exception in thread "main" java.lang.NullPointerException
        at chemaxon.descriptors.MDParameters.getTverskyAlpha(
        at chemaxon.descriptors.ChemicalFingerprint.getTversky(

Printing the current parameters, cfp.toString(), shows the values as defined.

<?xml version="1.0" encoding="UTF-8"?>
<ChemicalFingerprintConfiguration Version="0.3" schemaLocation="cfp.xsd">
<Parameters Length="512" BondCount="7" BitCount="3"/>
        <ParametrizedMetric Name="Tanimoto" ActiveFamily="Generic" Metric="Tanimoto" Threshold="0.2"/>
        <ParametrizedMetric Name="Euclidean" ActiveFamily="Generic" Metric="Euclidean" Threshold="10"/>
        <ParametrizedMetric Name="Tversky" ActiveFamily="Generic" Metric="Tversky" Threshold="0.5" TverskyAlpha="1" TverskyBeta="1"/>
        <ParametrizedMetric Name="UnityTversky" ActiveFamily="Generic" Metric="Tversky" Threshold="0.5" TverskyAlpha="0." TverskyBeta="0."/>
<StandardizerConfiguration Version="0.1"><Actions><Action ID="dehydrogenize" Act="dehydrogenize"/><Action ID="aromatize" Act="aromatize"/></Actions></StandardizerConfiguration></ChemicalFingerprintConfiguration>

How can you change or set the Tversky parameters without needing to read an xml file?



ChemAxon 1b9e90b2e7

07-07-2010 14:05:49

Hi Stephen,

are you trying to use Tversky and chemical fingerprints via the API? If so please try the following code example.

Does it also produces exception?

Thank you for your report.



User 7c177bab3b

07-07-2010 15:38:38

Thanks Adrian

Your example works fine. I added this line after the getDissimilarity calls:

float val3 = cfq.getTversky(cft);

and get the same similarity result.

However, when I comment out the line:

float val2 = cfq.getDissimilarity(cft, 2);

then I see the error as before.


Presumably if I want to change the Tversky parameters then I need to read in a specific cfp.xml?

I tried to get to this through the SimilarityCalculator, as that seems a little more intuitive, allowing you to change the Tversky parameters more easily. The problem there is that the getSimilarity method requires an int array but you don't provide any methods to get this directly from the fingerprint object. A toIntArray() method would make life a little easier, rather than having to parse one of the other formats.

ChemAxon 1b9e90b2e7

07-07-2010 16:46:54

float val3 = cfq.getTversky(cft);

can work in the first case because in the previous line
float val2 = cfq.getDissimilarity(cft, 2);  
a Tversky metrics was selected as the current paramterized metrics.
If this line is commented out the last calculated metrics is Eucledian with id number 1. So the current metrics will be #1 and for this metrics there are no Tversky parameters. Thats why an Exception is thrown.

As getTversky uses a parametrized tversky metrics pointed by the "current parametrized metrics" index this index has to be setted before using getTversky. (see in the attached code example TveskyTest2)

Different paramters for Tversky can be incorporated using the xml file. Each parameter setting produces a distinct parametrized metrics.

Indeed usage  of SimilarityCalculator is somewhat more straightforward but as you noticed it needs the raw representation of the FP data. This raw data can be exposed as in the attached .

I agree these two solutions above are not too nice and also not quite well documented. We are working on much nicer more practical and safe API which will be available soon.

Sorry for your inconvenience.