Functional Groups

The purpose of functional groups is to identify which atoms of a building block are modified during construction. See FunctionalGroup for more details.

See the documentation of Reactor to see how reactions between functional groups are performed.

Adding Functional Groups

During initialization of a BuildingBlock instance, the names of FGType instances are supplied. These are used to create the FunctionalGroup instances found in BuildingBlock.func_groups and therefore the ones used in the construction of ConstructedMolecule instances. If you want to be able to use a new FGType with building blocks in this way, simply add a new FGType instance to fg_types. This can be done in this file or externally. For example, if you want make stk use a new FGType without touching the source code you can just do

import stk

new_fg_type = FGType(
    name='my_fg_type',
    func_group_smarts='[N]([H])[H]',
    bonder_smarts=['[$([N]([H])[H])]'],
    deleter_smarts=['[$([H][N][H])]']*2
)
stk.fg_types[new_fg_type.name] = new_fg_type

# You can now use the new_fg_type with BuildingBlocks.
bb = stk.BuildingBlock('NCCCN', ['my_fg_type'])

Note that when adding SMARTS, if you want to make a SMARTS that targets an atom in an environment, for example, a bromine connected to a carbon:

[$([Br][C])]

The atom you are targeting needs to be written first. The above SMARTS works but:

[$([C][Br])]

does not.

class FGType(name, func_group_smarts, bonder_smarts, deleter_smarts)

Bases: object

Creates FunctionalGroup instances.

name

A name for the FGType. Helps with identification.

Type

str

Methods

get_functional_groups(self, mol)

Yield the functional groups in mol.

__init__(self, name, func_group_smarts, bonder_smarts, deleter_smarts)

Initialize a FGType instance.

Parameters
  • name (str) – A name for the FGType. Helps with identification.

  • func_group_smarts (str) – A SMARTS string which matches all atoms in a functional group.

  • bonder_smarts (list of str) – A list of SMARTS strings, each of which matches a single atom in a functional group. The matched atom is added to FunctionalGroup.bonders. A SMARTS string needs to be repeated if a single functional group has multiple equivalent atoms, each of which appears in the same FunctionalGroup.

  • deleter_smarts (list of str) – A list of SMARTS strings, each of which matches a single atom in a functional group. The matched atom is added to FunctionalGroup.deleters. A SMARTS string needs to be repeated if a single functional group has multiple equivalent atoms, each of which appears in the same FunctionalGroup.

get_functional_groups(self, mol)

Yield the functional groups in mol.

Parameters

mol (Molecule) – The molecule which is to have functional groups identified.

Yields

FunctionalGroup – A FunctionalGroup for every matched functional group in the mol.

Examples

import stk

mol = stk.BuildingBlock('NCCN')
amine = stk.FGType(
    func_group_smarts='[N]([H])[H]',
    bonder_smarts=['[$([N]([H])[H])]'],
    deleter_smarts=['[$([H][N][H])]']*2
)

# Make mol use amine functional groups during construction
# of ConstructedMolecule.
mol.func_groups = tuple(amine.get_functional_groups(mol))
class FunctionalGroup(atoms, bonders, deleters, fg_type)

Bases: object

Represents a functional group in a molecule.

Instances of this class should only be made via FGType.get_functional_groups().

atoms

The atoms in the functional group.

Type

tuple of Atom

bonders

The bonder atoms in the functional group. These are atoms which have bonds added during the construction of a ConstructedMolecule.

Type

tuple of Atom

deleters

The deleter atoms in the functional group. These are atoms which are deleted during construction of a ConstructedMolecule.

Type

tuple of Atom

fg_type

The FGType instance which created the FunctionalGroup.

Type

FGType

Methods

clone(self[, atom_map])

Return a clone.

get_atom_ids(self)

Yield the ids of atoms in order.

get_bonder_ids(self)

Yield the ids of bonders in order.

get_deleter_ids(self)

Yield the ids of deleters in order.

__init__(self, atoms, bonders, deleters, fg_type)

Initialize a FunctionalGroup.

Parameters
  • atoms (tuple of Atom) – The atoms in the functional group.

  • bonders (tuple of Atom) – The bonder atoms in the functional group.

  • deleters (tuple of Atom) – The deleter atoms in the functional group.

  • fg_type (FGType) – The FGType instance which created the FunctionalGroup.

clone(self, atom_map=None)

Return a clone.

Parameters

atom_map (dict, optional) – If the clone should hold different Atom instances, then a dict should be provided, which maps atoms in the current FunctionalGroup to the atoms which should be used in the clone. Only atoms which need to be remapped need to be present in the atom_map.

Returns

A clone.

Return type

FunctionalGroup

Examples

import stk

c0 = stk.C(0)
c1 = stk.C(1)
bb = stk.BuildingBlock('NCCN', ['amine'])
fg = bb.func_groups[0]
a0, a1 = fg.atoms[:2]

# fg_clone is a clone of fg, except that in all places
# fg holds a0 fg_clone holds c0 and in all places where
# fg holds a1, fg_clone holds c1.
fg_clone = fg.clone({
    a0: c0
    a1: c1
})
get_atom_ids(self)

Yield the ids of atoms in order.

Yields

int – The id an Atom in atoms.

get_bonder_ids(self)

Yield the ids of bonders in order.

Yields

int – The id of an Atom in bonders.

get_deleter_ids(self)

Yield the ids of deleters in order.

Yields

int – The id of an Atom in deleters.