stk.SimilarBuildingBlock

class stk.SimilarBuildingBlock(building_blocks, is_replaceable, key_maker=Inchi(), name='SimilarBuildingBlock', random_seed=None)[source]

Bases: object

Substitutes similar building blocks.

This mutator takes a ConstructedMolecule and substitutes the building blocks with the most similar one from a given set. Repeated mutations on the same molecule will substituted the next most similar molecule from the set.

Examples

Constructed Molecule Mutation

import stk

# Create a molecule which is to be mutated.
bb1 = stk.BuildingBlock('NCCN', [stk.PrimaryAminoFactory()])
bb2 = stk.BuildingBlock('O=CCC=O', [stk.AldehydeFactory()])
polymer = stk.MoleculeRecord(
    topology_graph=stk.polymer.Linear((bb1, bb2), 'AB', 3),
)

# Create molecules used to substitute building blocks.
building_blocks = (
    stk.BuildingBlock(
        smiles='NC[Si]CCN',
        functional_groups=[stk.PrimaryAminoFactory()],
    ),
    stk.BuildingBlock(
        smiles='NCCCCCCCN',
        functional_groups=[stk.PrimaryAminoFactory()],
    ),
    stk.BuildingBlock(
        smiles='NC1CCCCC1N',
        functional_groups=[stk.PrimaryAminoFactory()],
    ),
)

# Create the mutator.

def has_primary_amino_group(building_block):
    fg, = building_block.get_functional_groups(0)
    return type(fg) is stk.PrimaryAmino

similar_bb = stk.SimilarBuildingBlock(
    building_blocks=building_blocks,
    is_replaceable=has_primary_amino_group,
)

# Mutate a molecule.
mutation_record1 = similar_bb.mutate(polymer)

# Mutate the molecule a second time.
mutation_record2 = similar_bb.mutate(polymer)
Parameters:
  • building_blocks (list[BuildingBlock]) – A group of molecules which are used to replace building blocks in molecules being mutated.

  • is_replaceable (Callable[[BuildingBlock], bool]) – This function is applied to every building block in the molecule being mutated. Building blocks which returned True are liable for substitution by one of the molecules in building_blocks.

  • key_maker (MoleculeKeyMaker) – Molecules which return the same key, will iterate through the same set of similar molecules.

  • name (str) – A name to help identify the mutator instance.

  • random_seed (int | Generator | None) – The random seed to use.

Methods

mutate

Return a mutant of record.

mutate(record)[source]

Return a mutant of record.

Parameters:

record (MoleculeRecord[T]) – The molecule to be mutated.

Returns:

A record of the mutation.

Return type:

MutationRecord[MoleculeRecord[T]]