Package chemaxon.reaction
Class ConcurrentReactorProcessor
java.lang.Object
chemaxon.reaction.ConcurrentReactorProcessor
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 Summary
Modifier and TypeFieldDescriptionstatic final int
Mode constant: combinatorial mode.static final int
Mode constant: sequential mode. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
cleanup
(long joinTimeout) Cancels work currently executed, awaits termination of associated worker threads and releases any resource this processor has reserved.double
Estimates the progress.Molecule[]
Returns the input reactants of the last processed reaction.void
For internal use only.Molecule[]
react()
Generates the product list(s) for all reactant sets.Reacts the next reactant set and returns all product sets in a list.void
setReactantIterators
(MoleculeIterator[] reactantIterators, int mode) Sets the reactant iterators.void
setReactantIterators
(MoleculeIterator[] reactantIterators, int mode, String cacheFormat, double reservedMemorySize, boolean ignoreError) Deprecated, for removal: This API element is subject to removal in a future version.void
Deprecated, for removal: This API element is subject to removal in a future version.calling this method may result in very poor performance, callsetReactantIterators(MoleculeIterator[], int)
insteadvoid
setReactor
(Reactor reactor) Sets the Reactor object that will be used for reaction processing.void
setWorkerThreadCount
(int workerThreadCount) Sets the number of worker threads.
-
Field Details
-
MODE_SEQUENTIAL
public static final int MODE_SEQUENTIALMode constant: sequential mode.- See Also:
-
MODE_COMBINATORIAL
public static final int MODE_COMBINATORIALMode constant: combinatorial mode.- See Also:
-
-
Constructor Details
-
ConcurrentReactorProcessor
public ConcurrentReactorProcessor()
-
-
Method Details
-
setReactor
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 themode
parameter.- Parameters:
reactantIterators
- is the MoleculeIterator array from which the input molecules are readmode
- is the enumeration mode:MODE_SEQUENTIAL
orMODE_COMBINATORIAL
- Throws:
ReactionException
- if read error occurredIOException
- 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, callsetReactantIterators(MoleculeIterator[], int)
insteadSets the reactant iterators. Input reactants are read from reactant iterators, and enumerated in sequential or combinatorial mode, as set by themode
parameter.- Parameters:
reactantIterators
- is the MoleculeIterator array from which the input molecules are readmode
- is the enumeration mode:MODE_SEQUENTIAL
orMODE_COMBINATORIAL
cacheFormat
- the format for storing molecules in cachereservedMemorySize
- the memory size in MB that should be reservedignoreError
- istrue
if import errors should be ignored- Throws:
ReactionException
- if read error occurredIOException
- 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, callsetReactantIterators(MoleculeIterator[], int)
insteadSets the reactant set enumerator. The reactant set enumerator enumerates the input reactants. TheMolecule
[] returned beReactantSetEnumeration.next()
will be used as input reactant array for Reactor.- Parameters:
e
- is the reactant enumerator which enumerates the input reactants- See Also:
-
initialize
For internal use only. Initialization is required only in very special cases.- Throws:
ReactionException
- on reaction processing error- Since:
- JChem 5.2.2.
-
react
Generates the product list(s) for all reactant sets. Calls theReactor.react()
method for all reactant sets and returns the next product list, ornull
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
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
Returns the input reactants of the last processed reaction. Should be called afterreact()
orreactNext()
.- 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
0
)- Parameters:
workerThreadCount
- number of worker threads
-
-
getProgress
public double getProgress()Estimates the progress. Returns a number between0
and1
, 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
-
setReactantIterators(MoleculeIterator[], int)
instead