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. 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


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
  • Field Details

    • DEFAULT_CACHE_SIZE_PROPERTY

      public static final String DEFAULT_CACHE_SIZE_PROPERTY
      cache size property key
      See Also:
    • DEFAULT_CACHE_SIZE

      public static final int DEFAULT_CACHE_SIZE
      default cache size
      See Also:
  • Constructor Details

    • AutoMapper

      public AutoMapper()
      Initializes an AutoMapper object
  • Method Details

    • 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 use
      reactions - the array of reactions to map
      See Also:
    • 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 use
      reactions - 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 map
      options - 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 map
      mappers - 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 from
      exporter - the exporter to write mapped reactions to
      Throws:
      MolExportException - on export failure
      IOException - 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 from
      exporter - the exporter to write mapped reactions to
      options - the mapping options to use for mapping
      Throws:
      MolExportException - on export failure
      IOException - 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 from
      exporter - the exporter to write mapped reactions to
      mappers - the mappers to use
      Throws:
      MolExportException - on export failure
      IOException - on export failure
    • iterator

      Deprecated.
      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().
    • closeableIterator

      public static 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 added

      NOTE: 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.
      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 iterator
      options - 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 added

      NOTE: only use this iterator with try-with-resources statement

      Parameters:
      iterator - the input data iterator
      options - the mapping options to use
      Returns:
      an auto-closeable iterator that provides the mapped molecules, may not support Iterator.remove().
      See Also:
    • iterator

      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 iterator
      mappers - 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 added

      NOTE: only use this iterator with try-with-resources statement

      Parameters:
      iterator - the input data iterator
      mappers - the mappers to use
      Returns:
      an auto-closeable iterator that provides the mapped molecules, may not support Iterator.remove().
    • map

      public boolean map(RxnMolecule reaction)
      Maps the reaction.
      Specified by:
      map in interface Mapper<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 interface Mapper<RxnMolecule>
      Parameters:
      style - the mapping style to set
      See Also:
    • 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 interface Mapper<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 interface Mapper<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 interface Mapper<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