Using Calculator Plugins via Java API

Contents

Introduction

Calculator Plugins are modules of ChemAxon's Marvin and JChem cheminformatics platforms which calculate physico-chemical and descriptive properties from chemical structures. They can be accessed through a number of interfaces: from Marvin GUI, command line, API or via ChemAxon's Chemical Terms language.

Using Calculator Plugins via API

The aim of the examples below is to show how to work with Calculator Plugins via Java API.

Steps when using Calculator Plugins via API

In this example ElementalAnalyserPlugin is used to demonstrate the usage of the Calculator Plugin API step-by-step. These steps are common to all types of Calculator Plugins.

Instantiate the plugin object

Calculator Plugin classes are placed in the chemaxon.marvin.calculations package.
    import chemaxon.marvin.calculations.ElementalAnalyserPlugin;
Instantiate a new ElementalAnalyserPlugin object with its default constructor.
    ElementalAnalyserPlugin plugin = new ElementalAnalyserPlugin();

Set the parameters of the calculation

After creating the ElementalAnalyserPlugin object the parameters of the calculation can be set with plugin specific setter methods. The precision of the results can be set with the setDoublePrecision(int) method.
    plugin.setDoublePrecision(2);

Set the input molecule

All calculator plugins take a molecule (a Molecule object) as input, and perform the calculation on one molecule at a time. The input molecule can be set with the setMolecule(Molecule) method.
    plugin.setMolecule(mol);

Run the calculation

To run the calculation the run() method of the plugin should be called.
    plugin.run();

Get the results

It is plugin specific how results of the calculation can be retrieved. ElementalAnalyserPlugin can return several kinds of results, some of these are:

In the file ElementalAnalyserPluginExample.java a complete code example can be found which uses the code parts above (download source). It reads input molecules from a file given as command line parameter and displays the results.

The input file example_mols.sdf contains a few chemical structures shown below.

example_mols.sdf

To compile the ElementalAnalyserPluginExample.java example MarvinBeans.jar has to be referenced in the CLASSPATH. After compiling the example can be run from command line.

Usage:

  java ElementalAnalyserPluginExample [molFile]

Example:

  java ElementalAnalyserPluginExample example_mols.sdf

The output is:

CC(=O)OC(CC(O)=O)C[N+](C)(C)C
  formula: C9H18NO4, mass: 204.2435, exact mass: 204.123583069
  number of atoms (32): C (9), C-14 (0)
  composition: C (52.93%), H (8.88%), N (6.86%), O (31.33%)

OC1[14CH]=CC=C(C1O)C(O)=O
  formula: C7H8O4, mass: 158.1286, exact mass: 158.045500732
  number of atoms (19): C (7), C-14 (1)
  composition: C (54.43%), H (5.1%), O (40.47%)

NCC(=O)COP(O)(O)=O
  formula: C3H8NO5P, mass: 169.0731, exact mass: 169.014008883
  number of atoms (18): C (3), C-14 (0)
  composition: C (21.31%), H (4.77%), N (8.28%), O (47.32%), P (18.32%)

CCN1[14CH]=[NH+]C2=C(N)[NH+]=[14CH]N=[14C]12
  formula: C7H11N5, mass: 171.1734, exact mass: 171.111171341
  number of atoms (23): C (7), C-14 (3)
  composition: C (52.61%), H (6.48%), N (40.91%)

Using multiple plugins, writing the results to SDF fields

In the second example MajorMicrospeciesPlugin is used to generate the major microspecies at pH 7.4, TPSAPlugin to calculate the polar surface areas, logDPlugin to calculate the logD values, and IUPACNamingPlugin to generate the names of molecules read from a molfile. The results of the calculations are written to an SDFile, the molecules in the file are the major microspecies of the input molecules, IUPAC names, surface area values and logD values are saved in SDF property fields.

The main steps in this example are the same as in the previous one, only the methods used for parameter settings and the methods used for getting the results are different.

Setting parameters and getting the results for MajorMicrospeciesPlugin

For setting the parameters method setpH(double) is used. Major microspecies at the specified pH will be generated.

    mmsPlugin.setpH(7.4); // major microspecies generation at pH = 7.4

For getting the results method getMajorMicrospecies() is used. It returns a Molecule object.

    Molecule majorms = mmsPlugin.getMajorMicrospecies();

Setting parameters and getting the results for TPSAPlugin

For setting the parameters method setpH(double) is used.

    tpsaPlugin.setpH(7.4); // surface area calculation at pH = 7.4

For getting the results method getSurfaceArea() is used.

    double surfaceArea = tpsaPlugin.getSurfaceArea();

Setting parameters and getting the results for logDPlugin

There are quite a few parameters that can be set for logD calculation. These are: Cl- ion concentration, Na+/K+ ion concentration, pH (for calculating logD at a single pH value), pH lower limit, pH upper limit, and pH step size.

    // set the Cl- and Na+/K+ concentration
    logDPlugin.setCloridIonConcentration(0.15);
    logDPlugin.setNaKIonConcentration(0.15);
    // set the pH range and pH step size
    logDPlugin.setpHLower(5.4);
    logDPlugin.setpHUpper(9.4);
    logDPlugin.setpHStep(2.0);

The results of the logD calculation are returned by the method getlogDs(), the pH values are returned by the method getpHs(). Both methods return a double array (double[]), the logD array contains the logD values for corresponding pH-s in the pH array.

    double[] pHs = logDPlugin.getpHs();
    double[] logDs = logDPlugin.getlogDs();

Getting the results for IUPACNamingPlugin

For getting the results method getPreferredIUPACName() is used, it returns the preferred IUPAC name. IUPACNamingPlugin has also the method getTraditionalName() to return the traditional name of the molecule.

    String name = iupacNamingPlugin.getPreferredIUPACName();

The complete code example can be found in the file PluginExample.java (download source). After compiling the example can be run from command line.

Usage:

java PluginExample [molFile]

Example:

java PluginExample example_mols.sdf > results.sdf

The result is written to the results.sdf file.

results.sdf

The above examples can also be run by run.sh shell script (Linux/UNIX) or RUN.BAT batch file (Windows).

API usage examples

Plugin API usage examples can be found in the apidoc headers of the plugin classes.

Note: To run the Calculator Plugins license keys issued by ChemAxon are required (only ElemantalAnalyserPlugin, TPSAPlugin and some calculations of the TopologyAnalyserPlugin do not require a license key to run). To obtain a license key please or contact our head office.