Using Calculator Plugins via API

    Steps using Calculator Plugins via API

    In this example of the ElementalAnalysisPlugin we demonstrate how to use the Calculator Plugin API step-by-step. These steps are common for all types of plugins.

    Instantiate the plugin object

    Calculator Plugin classes are placed in the chemaxon.marvin.calculations package. First import the necessary classes:

    
    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()](https://apidocs.chemaxon.com/marvin/help/developer/beans/api/chemaxon/marvin/calculations/ElementalAnalyserPlugin.html#run()) method of the plugin should be invoked:

    
     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:

    • mass and exact mass

      
      double mass = plugin.getMass(); 
       double exactMass = plugin.getExactMass();
    • count of atoms and count of all atoms

      
      // the number of all atoms in the molecule 
       int atomCount = plugin.getAllAtomCount(); 
      // carbon atom count 
      int countOfC = plugin.getAtomCount(6); 
      // carbon-14 isotope count 
      int countOfC14 = plugin.getAtomCount(6, 14);
    • formula

      
      String formula = plugin.getFormula();
    • composition

      
      String composition = plugin.getComposition();

    In the file ElementalAnalyserPluginExample.java a complete code example can be found which uses the code parts above. It reads input molecules from a file given as command line parameter and displays the results. The input file example_mols.sdf contains the chemical structures shown below:

    images/download/attachments/1806713/example_mols.png

    To compile the example, MarvinBeans.jar has to be referenced in the CLASSPATH. After compiling the example can be run from command line like this:

     java ElementalAnalyserPluginExample [molFile]

    For 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 four plugins are used: the MajorMicrospeciesPlugin to generate the major microspecies at pH 7.4; the TPSAPlugin to calculate the polar surface areas; the logDPlugin to calculate the logD values and the IUPACNamingPlugin to generate the names of molecules read from a molfile. The results of the calculations are written to an SD file: they are the major microspecies of the input molecules, the IUPAC names, the surface area values and logD values.

    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)](https://apidocs.chemaxon.com/marvin/help/developer/beans/api/chemaxon/marvin/calculations/MajorMicrospeciesPlugin.html#setpH(double)); // major microspecies generation at pH = 7.4

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

     Molecule majorms = mmsPlugin.[getMajorMicrospecies()](https://apidocs.chemaxon.com/marvin/help/developer/beans/api/chemaxon/marvin/calculations/MajorMicrospeciesPlugin.html#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()](https://apidocs.chemaxon.com/marvin/help/developer/beans/api/chemaxon/marvin/calculations/IUPACNamingPlugin.html#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. After compiling the example can be run from command line:

    java PluginExample [molFile]
    

    Example:

    
    java PluginExample example_mols.sdf > results.sdf

    The result is written to the results.sdf file.

    images/download/attachments/1806713/results.png

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