Defines Reactor.

Extending stk: Adding complex reactions.

See Reactor.

class Reactor(mol)

Bases: object

Performs reactions between functional groups of a molecule.

The Reactor is initialized with the ConstructedMolecule instance on which it will perform reactions.

reactor = Reactor(mol)

The Reactor registers which functional groups need to have reactions performed with add_reaction()

fg1, fg2, fg3, fg4, fg5, fg6, fg7 = mol.func_groups

# Register a reaction between the atoms in fg1 and fg2.
reactor.add_reaction(fg1, fg2)

# Register a reaction between atoms in fg3 and fg4.
reactor.add_reaction(fg3, fg4)

# Some reactions can take multiple functional groups.
# You can put in as many functional groups as you like, given
# an appropriate reaction is defined.
reactor.add_reaction(fg5, fg6, fg7)

Once all the reactions have been registered, they are perfomed in a single step

reactor.finalize()

An obvious question given this tutorial, is what reaction does react() carry out? This is documented by react(). However, react() in most cases, will carry out a default reaction, which adds a bond between the bonder atoms of two functional groups. The bond order of the added bond is single by default but can be modified by editing _bond_orders. Here you will specify the _ReactionKey for a reaction and what bond order you want that reaction to use.

For some reactions you may wish to forgo the default reaction and do something more complex. This is neccessary because some reactions cannot be described by the simple combination of adding a bond while deleting some existing atoms. For example, consider the aldol reaction:

CH3C(=O)CH3 + CH3C(=O)CH3 –> CH3(=O)CH2C(OH)(CH3)CH3

Here a ketone is converted into an alcohol. If you wish to support a complex reaction, add it as a method within this class. The method will need take some FunctionalGroup instances as arguments. These are the functional groups which react.

Once the method is defined, _custom_reactions needs to be updated.

Methods

add_reaction(self, func_groups, periodicity)

Create bonds between functional groups.

finalize(self)

Finish performing reactions.

__init__(self, mol)

Initialize a Reactor.

Parameters

mol (ConstructedMolecule) – The molecule on which the reactor adds and removes atoms and bonds.

add_reaction(self, func_groups, periodicity)

Create bonds between functional groups.

This function first looks at the functional groups provided via the func_groups argument and checks which functional groups are involved in the reaction. If the functional groups are handled by one of the custom reactions specified in _custom_reactions then that function is executed.

In all other cases the function is assumed to have received two functional groups to react. In these functional groups, the bonder atoms have a bond added. The bond is single, unless otherwise specified in _bond_orders.

Parameters
  • func_groups (tuple of FunctionalGroup) – The functional groups to react.

  • periodicity (tuple of int) – Specifies the periodicity of the bonds added by the reaction, which bridge the func_groups. See Bond.periodicity.

Returns

None

Return type

NoneType

finalize(self)

Finish performing reactions.

Returns

None

Return type

NoneType