Library diversity

ChemAxon efa1591b5a

03-06-2004 15:52:46

[quoted from a user support request]

We have different corporate libraries at our company. We want to provide to our potential clients the diversity of them.

As a first step, I would like to compare all compounds in a pair-wise manner.

Can you send me a piece of Java code that helps?

ChemAxon efa1591b5a

03-06-2004 16:02:50

My sample code does part of the job, namely it compares your library to one single query. It contains all elements you will need to solve your problem.

This program uses molecular descriptors stored in your database, so before running ot you need to generate and store your descriptors (e.g. pharmacophore fingerprints). For instance:

generatemd c -a struc_table -k PF descr_name_i_give -c jchem/examples/config/pharma-frag.xml

Substitute struc_table with the name of your structure table, and descr_name_i_give with an arbitrary name you like. Also, if you need a molecular descriptor other than pharmacophore fingerprint, replace PF appropriately.

Then compile the attached code and execute it:


java ComparePairwise struc_table descr_name_i_give "c1ccccc1"

Hope this helps,



 * Copyright (c) 2004 ChemAxon Ltd. All Rights Reserved.






import java.sql.*;


import java.util.Properties;

import chemaxon.descriptors.*;

import chemaxon.struc.Molecule;

import chemaxon.formats.MolImporter;

import chemaxon.util.ConnectionHandler;

import chemaxon.jchem.db.SettingsHandler;

import chemaxon.jchem.db.MDTableHandler;


 * Demonstrates how molecular descriptors stored in a database table can be

 * used in dissimilarity calculations. This simple program calculates the

 * average dissimilarity of a compound library against a user defined query

 * structure. <br>

 * The application takes three parameters: the name of the JChem structure

 * table, the name of the molecular descriptor and the query molecule (e.g.

 * as a smiles string, but filename is not accepted here). Note, that the

 * name of the molecular descriptor is a user given name when the

 * <code>generatemd</code> command was executed.<br>

 * Be aware that database connection parameters are taken from the .jchem file

 * (i.e. settings used the last time when jcman was used).


public class ComparePairwise {

    public static void main(String[] args) {

        String strucTableName = args[ 0 ];

        String sqlSelect = "select cd_id from " + strucTableName;

        // names of molecular descriptors used in this dissimilarity calculation

        // this is the name of the descriptor you gave when the descriptor

        // (e.g. fingerprint) was generated with the generatemd command

        String[] mdNames = new String[ 1 ];

        mdNames[ 0 ] = args[ 1 ];

        String query = args[ 2 ];

        float dissim = 0.0F;

        int counter = 0;

        try {

            // open a database connection using settings stored in the .jchem file

            ConnectionHandler connHandler = new ConnectionHandler();


                    new Properties( new SettingsHandler().getSettings() ) );


            // mdTableHandler allows the retrieval of descriptors from database

            MDTableHandler mdTableHandler =

                    new MDTableHandler( connHandler, strucTableName );

            // dbReader gets fingerprints through mdTableHandler

            MDDBReader dbReader = new MDDBReader( strucTableName, connHandler,

                    mdNames, sqlSelect );

            // get the first molecular descriptor set from the descriptor table

            // note, that now the set has one component only

            MDSet md =;

            // create an identical descriptor set using the same parameters

            // this will store the molecular descriptor of the query molecule

            MDSet queryDescr = new MDSet( md );

            // create a Molecule object from the query string

            Molecule queryMol = MolImporter.importMol( query );

            // generate descriptor for the query molecule using the same

            // settings as found in the database

            queryDescr.generate( queryMol );

            // iterate through all descriptors and sum dissimilarities

            while ( md != null ) {

                dissim += md.getDissimilarity( queryDescr );

                md =;



            dissim = dissim / counter;

            System.out.println( "Number of descriptors retrieved = " + counter );

            System.out.println( "Average dissimilarity from " + query + " = "

                    + dissim );


        catch( Exception ex ) {





User 35e7bc7194

04-11-2004 12:27:00


I am spanish and I am working in a project with molecular descriptors and I need free JAVA libraries for this. I am obtained chemaxon library but it is not enough. Also I have found another library like JOELib. I hope somebody reply and tell me where I can find new libraries to my project.

Thanks you.-

P.D.- Sorry for my english.

ChemAxon efa1591b5a

04-11-2004 12:52:50

If you are an academic user, you may license JChem free of charge.

Please tell us what further functionalities or features you need.