Concurrent plugin API usage examples

ChemAxon's concurrent framework is based on the Java 5.0 java.util.concurrent API.

There are three examples which show code samples making use of ChemAxon's concurrent framework. The common code is written in ConcurrentPluginApplication: it starts a ConcurrentProcessor with a specified InputProducer and WorkUnitFactory. The InputProducer is supposed to produce the plugin inputs: the input molecules and possibly the plugin objects which perform the calculation. The WorkUnit objects produced by the WorkUnitFactory are run concurrently by the ConcurrentProcessor and supposed to execute the plugin calculation (the CalculatorPlugin.run() method). Finally, the results are collected in ConcurrentPluginApplication.consume(Object result) in the main thread. It is important to process the results in a single thread so that the order of the results was the same as the order of the input molecules.

Our examples show different ways to provide the inputs and outputs for the concurrent processor. Input molecules are read from System.in if the molecule file is omitted.
The following API is used:

In the following examples we use the test.smiles input molecule file:

  • logDPluginApplication is a simple application showing concurrrent logD calculation. The input is the molecule, the output is the logD value at a given pH (the default pH is 7.4).
    Usage:
      java logDPluginApplication [pH] [molFile]
    
    Example:
      java logDPluginApplication 5.2 test.smiles
    
  • pKaPluginApplication shows concurrent pKa calculation. The input is the molecule, the output is a result record storing the given number of strongest pKa values (or all, if this number is omitted).
    Usage:
      java pKaPluginApplication [count] [molFile]
    
    Example:
      java pKaPluginApplication 2 test.smiles
    
  • TautomerizationPluginApplication shows concurrent tautomer generation. This example is more complex since the result may be a huge molecule array (with several thousand molecules). Therefore we do not store the result in memory. Instead, we use the plugin object itself as result object, which generates the tautomers on-the-fly. We face the problem of reusing the plugin objects: it would be too much overhead to create a new plugin for each input molecule. We have to fetch all results from the plugin before we can start the next computation using the same plugin object, therefore the work unit returns the plugin object as calculation result, as well as gets the plugin object to work with from the input producer together with the input molecule. The consume(Object result) (in the main thread) gets the tautomers from the plugin and writes the tautomer with minimal logD. Finally, it returns the plugin object for reuse to the input producer.

    The input is the plugin object together with the molecule, the output is the plugin object. The application writes the tautomer with minimal logD. The number of plugin objects to be generated initially can be specified (10 if omitted).

    Usage:
      java TautomerizationPluginApplication [pluginCount] [molFile]
    
    Example:
      java TautomerizationPluginApplication 16 test.smiles
    

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

Do you have a question? Would you like to learn more? Please browse among the related topics on our support forum or search the website. If you want to suggest modifications or improvements to our documentation email our support directly!