Package com.chemaxon.mapper
Class AutoMapper
- java.lang.Object
-
- com.chemaxon.mapper.AutoMapper
-
- All Implemented Interfaces:
Mapper<RxnMolecule>
@PublicAPI public final class AutoMapper extends Object implements 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.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
Nested Classes Modifier and Type Class Description static class
AutoMapper.Options
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
Fields Modifier and Type Field Description static int
DEFAULT_CACHE_SIZE
default cache sizestatic String
DEFAULT_CACHE_SIZE_PROPERTY
cache size property key
-
Constructor Summary
Constructors Constructor Description AutoMapper()
Initializes anAutoMapper
object
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Mapper.MappingStyle
getMappingStyle()
Returns the mapping style of the mapper.boolean
isKeepMapping()
Returns if the mapper will keep the initial mapping or not.boolean
isMarkBonds()
Returns if the mapper marks the reaction center bonds or not.static Iterator<Molecule>
iterator(Iterator<Molecule> iterator)
Returns an iterator that will return the mapped molecules from the specified iterator.
NOTE: the returned iterator provides the same molecule instances with maps addedstatic Iterator<Molecule>
iterator(Iterator<Molecule> iterator, AutoMapper.Options options)
Returns 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 addedstatic Iterator<Molecule>
iterator(Iterator<Molecule> iterator, Mapper<RxnMolecule>... mappers)
Returns an iterator that will return the mapped molecules from the specified iterator using the specified mappers for mapping.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
setMappingStyle(Mapper.MappingStyle style)
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
unmap(Molecule item)
Remove atom maps from the given structure
-
-
-
Field Detail
-
DEFAULT_CACHE_SIZE_PROPERTY
public static final String DEFAULT_CACHE_SIZE_PROPERTY
cache size property key- See Also:
- Constant Field Values
-
DEFAULT_CACHE_SIZE
public static final int DEFAULT_CACHE_SIZE
default cache size- See Also:
- Constant Field Values
-
-
Constructor Detail
-
AutoMapper
public AutoMapper()
Initializes anAutoMapper
object
-
-
Method Detail
-
mapReaction
public static void mapReaction(Molecule... reactions)
Maps the reactions in the specified collection using multiple threads if possible.- Parameters:
reactions
- the array of reactions to map
-
mapReaction
public static void mapReaction(AutoMapper.Options options, Molecule... reactions)
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:
AutoMapper.Options
-
mapReaction
public static void mapReaction(Mapper<RxnMolecule>[] mappers, Molecule... reactions)
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
public static void mapReaction(Collection<Molecule> reactions)
Maps the reactions in the specified collection using multiple threads if possible.- Parameters:
reactions
- the collection of reactions to map
-
mapReaction
public static void mapReaction(Collection<Molecule> reactions, AutoMapper.Options options)
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:
AutoMapper.Options
-
mapReaction
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:
AutoMapper.Options
-
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
public static Iterator<Molecule> iterator(Iterator<Molecule> iterator)
Returns 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()
.
-
iterator
public static Iterator<Molecule> iterator(Iterator<Molecule> iterator, AutoMapper.Options options)
Returns 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:
AutoMapper.Options
-
iterator
public static Iterator<Molecule> iterator(Iterator<Molecule> iterator, Mapper<RxnMolecule>... mappers)
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()
.
-
map
public boolean map(RxnMolecule reaction)
Maps the reaction.- Specified by:
map
in interfaceMapper<RxnMolecule>
- Parameters:
reaction
- is the reaction to be mapped- Returns:
true
if mapping was successful
-
setMappingStyle
public void setMappingStyle(Mapper.MappingStyle style)
Sets the mapping style- Specified by:
setMappingStyle
in interfaceMapper<RxnMolecule>
- Parameters:
style
- the mapping style to set- See Also:
Mapper.MappingStyle.COMPLETE
,Mapper.MappingStyle.CHANGING
,Mapper.MappingStyle.MATCHING
-
getMappingStyle
public Mapper.MappingStyle 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
public static void unmap(Molecule item)
Remove atom maps from the given structure- Parameters:
item
- the structure to unmap
-
-