Class 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


    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 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 an AutoMapper 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 use
        reactions - 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 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:
        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 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,
                                       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

        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 iterator
        options - 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 iterator
        mappers - 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 interface Mapper<RxnMolecule>
        Parameters:
        reaction - is the reaction to be mapped
        Returns:
        true if mapping was successful
      • 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