class scm.reactmap.Reaction(reactant, product, name=None)

The main class for inputting (reactant, product) pairs to specify a reaction and investigating the results of a mapping.

The Reaction class is intended as the minimal workspace for users of reactmap. The Reaction class contains the reactant and product molecules and, once the problem has been solved, the optimal mapping and its associated cost.

Keyword Arguments
  • reactant (reactmap.Molecule) – The reactant in the reaction

  • product (reactmap.Molecule) – The product in the reaction

  • name (str) – A name for the reaction. If no name is supplied, a generic reaction name is generated.


Let’s find the (hypothetical) mapping between CCCCO and CCOCC using the Reaction class to input the molecules. Then, we’ll print the mapping using the value stored in the Reaction instance.:

>>> import reactmap as rm
>>> reac = rm.Molecule(smiles='CCCCO')
>>> prod = rm.Molecule(smiles='CCOCC')
>>> reaction = rm.Reaction(reactant = reac, product = prod)
>>> rm.Map(reaction)
>>> print(reaction.mapping)
[4, 3, 0, 1, 2, 12, 13, 14, 10, 11, 5, 6, 8, 9, 7]



A networkx bipartite graph between the reactant and product atoms.


The bonds that are removed from the reactant molecule in the optimal mapping.


The bonds that are formed in the product molecule in the optimal mapping.


True/False if this reaction is treating the reactants/products using implicit H’s


Either 0 or 1, The parity of the feasible solutions.


A list of the reactant atoms to distinguish the reactant and product atoms.



When a mapping has been calculated from reactant to product. Return an inverted mapping from product to reactant.


the reaction mapping problem has a solution if and only if the size of atom type sets is the same for reactant and product i.e., if we have 2 Oxygen atoms and 4 Carbon atoms for the reactants and 1 oxygen and 5 carbons for the products, then there is no feasible mapping


Generates 2 .svg files showing an atom mapping between the reactants and the products.


filename (str) – the base name for the two output .svg files

The two output files will be called <filename>_reactants.svg and <filename>_products.svg. The reactants will show broken bonds in red and the products will show formed bonds in green. The atom indices in both images refer to the reactant indices. This means that the reactant indices correspond to the same indices as were given in the input. The product indices, however, correspond to the index of the reactant atom that was mapped to that product atom. As a concrete example, atom 15 in the reactants image always maps to atom 15 in the products image. Atom 15 in the reactants is also atom 15 in the original reactants input, but atom 15 in the products images may refer to atom 17 (for example) in the original product input.


Displays the results of the reaction mapping in a human-readable way.

Keyword Arguments

initial_index (int) – The index of the first atom. You may want to set this to 1 if you prefer the first atom to have index ‘1’.

The output shows several pieces of information.

  • Problem details

    • Number of atoms

    • Atom counts

    • Number of reactant/product bonds

  • Atom mapping details

    • Reactant index - the index of the reactant atom

    • Product index - the index of the product atom mapped to by the corresponding reactant atom

    • Atom type - the chemical symbol of the atom

    • Atom Status - any of the following

      • A - an active atom

      • I - an inactive atom

      • D - a (duplicate) atom that was filtered out of the reaction (and not mapped) because it was part of a molecule that occurred in both reactants and products

  • Bond change details - a list of bonds that are broken and formed given the atom mapping

  • Solution details

    • Time to find the solution

    • The cost of the mapping