Class AutoMapper
- All Implemented Interfaces:
Mapper<RxnMolecule>
AutoMapper
is a tool that performs automated chemical reaction mapping. The term mapping refers to the
association of reactant side atoms to product side atoms. It can also identify and mark the reaction center during
mapping. Please note, that when potential tetrahedral stereo centers need to be taken into account for correct
mapping, it is necessary to provide coordinates for all the atoms in the reaction.
AutoMapper
supports three mapping styles:
Helper functions are added to support concurrent mapping of reactions coming from various sources, such as
- files
- collections (
Collection
) - iterators (
Iterator
).
API usage examples
Basic example, shows how to map a single reaction:
RxnMolecule reaction = RxnMolecule.getReaction(MolImporter .importMol("COC1OC(CO)C(OC)C(O)C1O.OS(O)(=O)=O>>COC1OC(COS(O)(=O)=O)C(OC)C(O)C1O.[H]O[H]")); AutoMapper mapper = new AutoMapper(); mapper.map(reaction); System.out.println(MolExporter.exportToFormat(reaction, "smiles"));
Map all reactions in a file, and mark the reaction centers:
MolImporter importer = new MolImporter("unmapped.smiles"); MolExporter exporter = new MolExporter("mapped.mrv", "mrv"); AutoMapper.mapReaction(importer, exporter, new AutoMapper.Options().setMarkBonds(true)); importer.close(); exporter.close();
Map reactions during iteration:
MolImporter importer = new MolImporter("unmapped.smiles"); Iterator<Molecule> mappedMoleculeIterator = AutoMapper.iterator(importer.iterator()); while (mappedMoleculeIterator.hasNext()) { Molecule mappedReaction = mappedMoleculeIterator.next(); // do something with the mapped reaction ... } importer.close();
In concurrent mode reactions are cached. The default cache size is 1000, which can be overridden with "chemaxon.automapper.AutoMapper.cacheSize" Java system property. In case of invalid cache size (not positive, or not a valid number) the default value is used.
- Since:
- 6.0
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic final class
Option object for set common options when mapping called by static way.Nested classes/interfaces inherited from interface com.chemaxon.mapper.Mapper
Mapper.MappingStyle
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
default cache sizestatic final String
cache size property key -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic CloseableIterator<Molecule>
closeableIterator
(Iterator<Molecule> iterator) Returns an auto-closeable iterator that will return the mapped molecules from the specified iterator.
NOTE: the returned iterator provides the same molecule instances with maps addedstatic CloseableIterator<Molecule>
closeableIterator
(Iterator<Molecule> iterator, AutoMapper.Options options) Returns an auto-closeable iterator that will return the mapped molecules from the specified iterator using the specified number of threads for mapping.
NOTE: the returned iterator provides the same molecule instances with maps addedstatic CloseableIterator<Molecule>
closeableIterator
(Iterator<Molecule> iterator, Mapper<RxnMolecule>... mappers) Returns an auto-closeable iterator that will return the mapped molecules from the specified iterator using the specified mappers for mapping.Returns the mapping style of the mapper.boolean
Returns if the mapper will keep the initial mapping or not.boolean
Returns if the mapper marks the reaction center bonds or not.Deprecated.iterator
(Iterator<Molecule> iterator, AutoMapper.Options options) Deprecated.usecloseableIterator(Iterator, Options)
insteaditerator
(Iterator<Molecule> iterator, Mapper<RxnMolecule>... mappers) Deprecated.boolean
map
(RxnMolecule reaction) Maps the reaction.static void
mapReaction
(MolImporter importer, MolExporter exporter) Reads the reactions from the importer, maps them, and writes to the exporter.static void
mapReaction
(MolImporter importer, MolExporter exporter, AutoMapper.Options options) Reads the reactions from the importer, maps them, and writes to the exporter.static void
mapReaction
(MolImporter importer, MolExporter exporter, Mapper<RxnMolecule>... mappers) Reads the reactions from the importer, maps them, and writes to the exporter.static void
mapReaction
(Molecule... reactions) Maps the reactions in the specified collection using multiple threads if possible.static void
mapReaction
(AutoMapper.Options options, Molecule... reactions) Maps the reactions in the specified collection using the specified options.static void
mapReaction
(Mapper<RxnMolecule>[] mappers, Molecule... reactions) Maps the reactions in the specified collection using the specified mappers in multiple threads.static void
mapReaction
(Collection<Molecule> reactions) Maps the reactions in the specified collection using multiple threads if possible.static void
mapReaction
(Collection<Molecule> reactions, AutoMapper.Options options) Maps the reactions in the specified collection using the specified options.static void
mapReaction
(Collection<Molecule> reactions, Mapper<RxnMolecule>... mappers) Maps the reactions in the specified collection using the specified mappers in multiple threads.void
setKeepMapping
(boolean keepMapping) Sets if the initial mapping of the given object should be kept or not.void
Sets the mapping stylevoid
setMarkBonds
(boolean markResult) Sets if the changing bonds should be marked or not.void
setTimeLimit
(long timeLimitMilliseconds) Sets time limit for calculation.static void
Remove atom maps from the given structure
-
Field Details
-
DEFAULT_CACHE_SIZE_PROPERTY
cache size property key- See Also:
-
DEFAULT_CACHE_SIZE
public static final int DEFAULT_CACHE_SIZEdefault cache size- See Also:
-
-
Constructor Details
-
AutoMapper
public AutoMapper()Initializes anAutoMapper
object
-
-
Method Details
-
mapReaction
Maps the reactions in the specified collection using multiple threads if possible.- Parameters:
reactions
- the array of reactions to map
-
mapReaction
Maps the reactions in the specified collection using the specified options.- Parameters:
options
- the mapping options to usereactions
- the array of reactions to map- See Also:
-
mapReaction
Maps the reactions in the specified collection using the specified mappers in multiple threads. The number of mappers specifies the number of threads to use.- Parameters:
mappers
- the mappers to usereactions
- the collections of reactions to map
-
mapReaction
Maps the reactions in the specified collection using multiple threads if possible.- Parameters:
reactions
- the collection of reactions to map
-
mapReaction
Maps the reactions in the specified collection using the specified options.- Parameters:
reactions
- the collections of reactions to mapoptions
- the mapping options to use- See Also:
-
mapReaction
@SafeVarargs public static void mapReaction(Collection<Molecule> reactions, Mapper<RxnMolecule>... mappers) Maps the reactions in the specified collection using the specified mappers in multiple threads. The number of mappers specifies the number of threads to use.- Parameters:
reactions
- the collections of reactions to mapmappers
- the mappers to use
-
mapReaction
public static void mapReaction(MolImporter importer, MolExporter exporter) throws MolExportException, IOException Reads the reactions from the importer, maps them, and writes to the exporter. Uses multiple threads for mapping if possible.- Parameters:
importer
- the importer to read reactions fromexporter
- the exporter to write mapped reactions to- Throws:
MolExportException
- on export failureIOException
- on export failure
-
mapReaction
public static void mapReaction(MolImporter importer, MolExporter exporter, AutoMapper.Options options) throws MolExportException, IOException Reads the reactions from the importer, maps them, and writes to the exporter. Uses the specified number of threads for mapping.- Parameters:
importer
- the importer to read reactions fromexporter
- the exporter to write mapped reactions tooptions
- the mapping options to use for mapping- Throws:
MolExportException
- on export failureIOException
- on export failure- See Also:
-
mapReaction
public static void mapReaction(MolImporter importer, MolExporter exporter, Mapper<RxnMolecule>... mappers) throws MolExportException, IOException Reads the reactions from the importer, maps them, and writes to the exporter. Uses the specified mappers for mapping. The number of mappers specified the number of threads to use.- Parameters:
importer
- the importer to read reactions fromexporter
- the exporter to write mapped reactions tomappers
- the mappers to use- Throws:
MolExportException
- on export failureIOException
- on export failure
-
iterator
@Deprecated @SubjectToRemoval(date=JUL_01_2025) public static Iterator<Molecule> iterator(Iterator<Molecule> iterator) Deprecated.usecloseableIterator(Iterator)
insteadReturns an iterator that will return the mapped molecules from the specified iterator.
NOTE: the returned iterator provides the same molecule instances with maps added- Parameters:
iterator
- the input data iterator- Returns:
- an iterator that provides the mapped molecules, may not support
Iterator.remove()
.
-
closeableIterator
Returns an auto-closeable iterator that will return the mapped molecules from the specified iterator.
NOTE: the returned iterator provides the same molecule instances with maps addedNOTE: only use this iterator with try-with-resources statement
- Parameters:
iterator
- the input data iterator- Returns:
- an auto-closeable iterator that provides the mapped molecules, may not support
Iterator.remove()
.
-
iterator
@Deprecated @SubjectToRemoval(date=JUL_01_2025) public static Iterator<Molecule> iterator(Iterator<Molecule> iterator, AutoMapper.Options options) Deprecated.usecloseableIterator(Iterator, Options)
insteadReturns an iterator that will return the mapped molecules from the specified iterator using the specified number of threads for mapping.
NOTE: the returned iterator provides the same molecule instances with maps added- Parameters:
iterator
- the input data iteratoroptions
- the mapping options to use- Returns:
- an iterator that provides the mapped molecules, may not support
Iterator.remove()
. - See Also:
-
closeableIterator
public static CloseableIterator<Molecule> closeableIterator(Iterator<Molecule> iterator, AutoMapper.Options options) Returns an auto-closeable iterator that will return the mapped molecules from the specified iterator using the specified number of threads for mapping.
NOTE: the returned iterator provides the same molecule instances with maps addedNOTE: only use this iterator with try-with-resources statement
- Parameters:
iterator
- the input data iteratoroptions
- the mapping options to use- Returns:
- an auto-closeable iterator that provides the mapped molecules, may not support
Iterator.remove()
. - See Also:
-
iterator
@Deprecated @SubjectToRemoval(date=JUL_01_2025) @SafeVarargs public static Iterator<Molecule> iterator(Iterator<Molecule> iterator, Mapper<RxnMolecule>... mappers) Deprecated.Returns an iterator that will return the mapped molecules from the specified iterator using the specified mappers for mapping. The number of mappers specifies the number of threads to use.
NOTE: the returned iterator provides the same molecule instances with maps added- Parameters:
iterator
- the input data iteratormappers
- the mappers to use- Returns:
- an iterator that provides the mapped molecules, may not support
Iterator.remove()
.
-
closeableIterator
@SafeVarargs public static CloseableIterator<Molecule> closeableIterator(Iterator<Molecule> iterator, Mapper<RxnMolecule>... mappers) Returns an auto-closeable iterator that will return the mapped molecules from the specified iterator using the specified mappers for mapping. The number of mappers specifies the number of threads to use.
NOTE: the returned iterator provides the same molecule instances with maps addedNOTE: only use this iterator with try-with-resources statement
- Parameters:
iterator
- the input data iteratormappers
- the mappers to use- Returns:
- an auto-closeable iterator that provides the mapped molecules, may not support
Iterator.remove()
.
-
map
Maps the reaction.- Specified by:
map
in interfaceMapper<RxnMolecule>
- Parameters:
reaction
- is the reaction to be mapped- Returns:
true
if mapping was successful
-
setMappingStyle
Sets the mapping style- Specified by:
setMappingStyle
in interfaceMapper<RxnMolecule>
- Parameters:
style
- the mapping style to set- See Also:
-
getMappingStyle
Returns the mapping style of the mapper.- Returns:
- the mapping style of the mapper
-
setMarkBonds
public void setMarkBonds(boolean markResult) Description copied from interface:Mapper
Sets if the changing bonds should be marked or not.- Specified by:
setMarkBonds
in interfaceMapper<RxnMolecule>
- Parameters:
markResult
- if the reaction center should be marked or not
-
isMarkBonds
public boolean isMarkBonds()Returns if the mapper marks the reaction center bonds or not.- Returns:
- if the mapper marks the reaction center bonds or not
-
setKeepMapping
public void setKeepMapping(boolean keepMapping) Description copied from interface:Mapper
Sets if the initial mapping of the given object should be kept or not.- Specified by:
setKeepMapping
in interfaceMapper<RxnMolecule>
- Parameters:
keepMapping
- if the initial mapping of the given object should be kept or not
-
setTimeLimit
public void setTimeLimit(long timeLimitMilliseconds) Description copied from interface:Mapper
Sets time limit for calculation. Upon elapsing time limit the molecule is mapped with the so far calculated mapping.- Specified by:
setTimeLimit
in interfaceMapper<RxnMolecule>
- Parameters:
timeLimitMilliseconds
- timeout limit in milliseconds. -1 means disabled.
-
isKeepMapping
public boolean isKeepMapping()Returns if the mapper will keep the initial mapping or not.- Returns:
- if the mapper will keep the initial mapping or not
-
unmap
Remove atom maps from the given structure- Parameters:
item
- the structure to unmap
-
closeableIterator(Iterator)
instead