Class ConcurrentReactorProcessor

java.lang.Object
chemaxon.reaction.ConcurrentReactorProcessor

@PublicAPI public class ConcurrentReactorProcessor extends Object
Executes a chemical reaction: creates products from reactants with reaction center data. If the reaction centers have not yet been searched for, uses substructure search to find and (optionally) store them. Provides command line interface and API to concurrent reaction processing.

See the documentation for details.

An example usage of the API:

 MolExporter exporter = new MolExporter(System.out, "smiles");
 Molecule rxnmol = new MolImporter("reaction.rxn").read();
 MolImporter[] importers = new MolImporter[] { new MolImporter("reactants1.smiles"), new MolImporter("reactants2.smiles") };

 // create Reactor
 Reactor reactor = new Reactor();

 // set reactor properties
 reactor.setIgnoreRules(Reactor.IGNORE_REACTIVITY | Reactor.IGNORE_SELECTIVITY);

 // set the reaction ('rxnmol' is the reaction molecule)
 // reaction rules are read from RDF/MRV tags
 reactor.setReaction(rxnmol);

 // create ConcurrentReactorProcessor
 ConcurrentReactorProcessor crp = new ConcurrentReactorProcessor();

 // set the reactor for ConcurrentReactorProcessor
 crp.setReactor(reactor);

 // set the reactant iterators and the processing mode for ConcurrentReactorProcessor
 crp.setReactantIterators(MoleculeIteratorFactory.getMoleculeIterators(importers), ConcurrentReactorProcessor.MODE_COMBINATORIAL);

 // react the reactants and export the output (reactions are performed in concurrent mode)
 Molecule[] products;
 while ((products = crp.react()) != null) {
     for (Molecule product : products) {
         exporter.write(product);
     }
 }
 
Since:
JChem 5.2
  • Field Details

    • MODE_SEQUENTIAL

      public static final int MODE_SEQUENTIAL
      Mode constant: sequential mode.
      See Also:
    • MODE_COMBINATORIAL

      public static final int MODE_COMBINATORIAL
      Mode constant: combinatorial mode.
      See Also:
  • Constructor Details

    • ConcurrentReactorProcessor

      public ConcurrentReactorProcessor()
  • Method Details

    • setReactor

      public void setReactor(Reactor reactor)
      Sets the Reactor object that will be used for reaction processing.
      Parameters:
      reactor - is the reactor object
    • setReactantIterators

      public void setReactantIterators(MoleculeIterator[] reactantIterators, int mode) throws ReactionException, IOException
      Sets the reactant iterators. Input reactants are read from reactant iterators, and enumerated in sequential or combinatorial mode, as set by the mode parameter.
      Parameters:
      reactantIterators - is the MoleculeIterator array from which the input molecules are read
      mode - is the enumeration mode: MODE_SEQUENTIAL or MODE_COMBINATORIAL
      Throws:
      ReactionException - if read error occurred
      IOException - in case of I/O error
    • setReactantIterators

      @Deprecated(forRemoval=true) @SubjectToRemoval(date=JUL_01_2025) public void setReactantIterators(MoleculeIterator[] reactantIterators, int mode, String cacheFormat, double reservedMemorySize, boolean ignoreError) throws ReactionException, IOException
      Deprecated, for removal: This API element is subject to removal in a future version.
      The last three arguments are not used anymore, call setReactantIterators(MoleculeIterator[], int) instead
      Sets the reactant iterators. Input reactants are read from reactant iterators, and enumerated in sequential or combinatorial mode, as set by the mode parameter.
      Parameters:
      reactantIterators - is the MoleculeIterator array from which the input molecules are read
      mode - is the enumeration mode: MODE_SEQUENTIAL or MODE_COMBINATORIAL
      cacheFormat - the format for storing molecules in cache
      reservedMemorySize - the memory size in MB that should be reserved
      ignoreError - is true if import errors should be ignored
      Throws:
      ReactionException - if read error occurred
      IOException - in case of I/O error
    • setReactantSetEnumerator

      @Deprecated(forRemoval=true) @SubjectToRemoval(date=JUL_01_2025) public void setReactantSetEnumerator(ReactantSetEnumeration e)
      Deprecated, for removal: This API element is subject to removal in a future version.
      calling this method may result in very poor performance, call setReactantIterators(MoleculeIterator[], int) instead
      Sets the reactant set enumerator. The reactant set enumerator enumerates the input reactants. The Molecule[] returned be ReactantSetEnumeration.next() will be used as input reactant array for Reactor.
      Parameters:
      e - is the reactant enumerator which enumerates the input reactants
      See Also:
    • initialize

      public void initialize() throws ReactionException
      For internal use only. Initialization is required only in very special cases.
      Throws:
      ReactionException - on reaction processing error
      Since:
      JChem 5.2.2.
    • react

      public Molecule[] react() throws ReactionException
      Generates the product list(s) for all reactant sets. Calls the Reactor.react() method for all reactant sets and returns the next product list, or null if there are no more product lists.

      The reactor and the reactant iterators or the reactant set enumerator should be set beforehand.

      Returns:
      the next product list, or null if there are no more product lists
      Throws:
      ReactionException - on reaction processing error
      See Also:
    • reactNext

      public List<Molecule[]> reactNext() throws ReactionException
      Reacts the next reactant set and returns all product sets in a list. Reactant sets which does not generate products are skipped. null is returned if there are no more reactant sets to process.
      Returns:
      all product sets in a list for the next reactant set
      Throws:
      ReactionException - on reaction processing error
      Since:
      JChem 5.5
      See Also:
    • getReactants

      public Molecule[] getReactants()
      Returns the input reactants of the last processed reaction. Should be called after react() or reactNext().
      Returns:
      the input reactants of the last processed reaction
      Since:
      JChem 5.5
    • setWorkerThreadCount

      public void setWorkerThreadCount(int workerThreadCount)
      Sets the number of worker threads.
      • 0: worker thread count = number of available CPU cores
      (default: 0)
      Parameters:
      workerThreadCount - number of worker threads
    • getProgress

      public double getProgress()
      Estimates the progress. Returns a number between 0 and 1, or returns -1. 0: none of the input molecules are processed, 1: all of the input molecules are processed, -1: information about progress can not be provided.
      Returns:
      a number that indicates the progress
    • cleanup

      public void cleanup(long joinTimeout) throws InterruptedException, ExecutionException, TimeoutException
      Cancels work currently executed, awaits termination of associated worker threads and releases any resource this processor has reserved.
      Parameters:
      joinTimeout - specifies in milliseconds at most how long this method is allowed to await the termination of each the worker threads. '0' means don't wait at all. This parameter is relevant when the worker threads have been cancelled as a result of the processor having been cancelled either explicitly by the user or internally reacting on an execution error.
      Throws:
      InterruptedException - if the current thread has been interrupted.
      ExecutionException - if any of the worker threads encountered an error during execution.
      TimeoutException
      Since:
      JChem 15.5.11