How do i generate the chemical fingerprint for a SMILES ?

User 0224fcf261

03-05-2005 16:24:59

Hi,





Sorry for the basic question, but i have used the API as described in other posts to generate the CFP and PFP for an SD file, but i now want to generate the fingerprints for individual SMILES in code. I have the following:





Code:



   CFParameters cfparams = new CFParameters(new File("C:\\JChem3.08\\jchem\\examples\\config\\cfp.xml"));





    ChemicalFingerprint cf = new ChemicalFingerprint(cfparams);





    try


    {


      String[] sa = cf.generate(MolImporter.importMol(smiles));


      for (int i = 0; i < sa.length; i++)





      {


        System.out.println(sa[i]);


      }     





    }


    catch (Exception e)


    {


      e.printStackTrace();


    }














However the generate() method returns Null. Can you tell me what i have missed out ? Am i not using the right classes ?





Many thanks


Alistair

ChemAxon efa1591b5a

03-05-2005 20:13:13

Hello Alistair,





cf.generate() generates and stores the fingerprint inside the'cf' object (that is, 'cf' itself is the fingerprint).


The return value of the generate() method contains the names of fields (properties) set by generate() in the corresponding molecule (that one passed as a parameter). In the case of chemical fingerprints this is null, as no extra fields are set by generate(), however, in the case of pharmacophore fingerprints, for instance, a field named PMAP is set by default.





This may look foolish: why does generate() return something other than the fingerprint, but the logic behind is that the Molecule object passed as parameter is altered in some cases, and the user of the generate() method should be aware of the new fields added to the Molecule.


On the other hand, the fingerprint is the 'cf' object itself which receives the generete() call. The object 'cf' can directly be used in dissimilarity calculations, that is, if you have cf1 and cf2 then you can call cf1.getTanimoto(cf2) etc.


The ChemicalFingerprint class also provides various functions to get the fingerprint in printable format, as well as in binary format to be stored in JChem database.





Thus, if you wish to print the fingerprint in a readable format just do this:








cf.generate( MolImporter.importMol(smiles) ); // omit return value, it's null anyway


System.out.println( cf ); // this calls cf.toString() which generates readable decimal output








If you prefer 0-s and 1-s then you can call





System.out.println( cf.toBinaryString() );








I hope this helps.





Regards


Miklos





p.s. Sorry, it's long i know, but i wanted to explain concepts behind as it appears that these are far not obvious. Comments are most welcome!

User 0224fcf261

04-05-2005 16:28:23

Thanks for the reply, it all makes sense now ! :-)