Mutation¶
RandomTopology
Mutation is carried by Mutator objects. They inherit
Mutator and define a method mutate(). This
method must take a single molecule and return a mutant.
Examples of how mutators work can be seen the documentation of
the various Mutator classes, for example
RandomBuildingBlock, SimilarBuildingBlock
or RandomMutation.
Making New Mutators¶
Mutators must simply inherit the Mutator class. This is an
abstract base class and its virtual methods must be implemented.
-
exception
MutationError¶ Bases:
ExceptionUsed for errors which occuring during mutation operations.
-
__init__(self, /, *args, **kwargs)¶ Initialize self. See help(type(self)) for accurate signature.
-
args¶
-
with_traceback()¶ Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
-
-
class
Mutator¶ Bases:
stk.calculators.base_calculators.EAOperationCreates mutants.
Methods
mutate(self, mol)Return a mutant of mol.
set_cache_use(self, use_cache)Set use of the molecular cache on or off.
-
__init__(self, /, *args, **kwargs)¶ Initialize self. See help(type(self)) for accurate signature.
-
mutate(self, mol)¶ Return a mutant of mol.
-
set_cache_use(self, use_cache)¶ Set use of the molecular cache on or off.
- Parameters
use_cache (
bool) –Trueif the molecular cache is to be used.- Returns
The calculator.
- Return type
- Raises
NotImplementedError – This is a virtual method and needs to be implemented in a subclass.
-
-
class
RandomBuildingBlock(building_blocks, key, duplicate_building_blocks=False, random_seed=None, use_cache=False)¶ Bases:
stk.calculators.base_calculators._EAOperation,stk.calculators.ea.mutators.MutatorSubstitutes random building blocks.
This mutator takes a
ConstructedMoleculeand substitutes the building blocks with one chosen at random from a given set.Examples
import stk # Create a molecule which is to be mutated. bb1 = stk.BuildingBlock('NCCN', ['amine']) bb2 = stk.BuildingBlock('O=CCC=O', ['aldehyde']) polymer = stk.ConstructedMolecule( building_blocks=[bb1, bb2], topology_graphs=stk.polymer.Linear('AB', [0, 0], n=3) ) # Create molecules used to substitute building blocks. building_blocks = [ stk.BuildingBlock('NC[Si]CCN', ['amine']), stk.BuildingBlock('NCCCCCCCN', ['amine']), stk.BuildingBlock('NC1CCCCC1N', ['amine']) ] # Create the mutator. random_bb = stk.RandomBuildingBlock( building_blocks=building_blocks, key=lambda mol: mol.func_groups[0].fg_type.name == 'amine' ) # Mutate a molecule. mutant1 = random_bb.mutate(polymer) # Mutate the molecule a second time. mutant2 = random_bb.mutate(polymer) # Mutate a mutant. mutant3 = random_bb.mutate(mutant1)
Methods
mutate(self, mol)Return a mutant of mol.
set_cache_use(self, use_cache)Set use of the molecular cache on or off.
-
__init__(self, building_blocks, key, duplicate_building_blocks=False, random_seed=None, use_cache=False)¶ Initialize a
RandomBuildingBlockinstance.- Parameters
building_blocks (
tupleofMolecule) – A group of molecules which are used to replace building blocks in molecules being mutated.key (
function) – A function which takes aMoleculeand returnsTrueorFalse. This function is applied to every building block in the molecule being mutated. Building blocks which returnedTrueare liable for substition by one of the molecules in building_blocks.duplicate_building_blocks (
bool, optional) – Indicates whether the building blocks used to construct the mutant must all be unique.random_seed (
bool, optional) – The random seed to use.use_cache (
bool, optional) – Toggles use of the molecular cache.
-
mutate(self, mol)¶ Return a mutant of mol.
-
set_cache_use(self, use_cache)¶ Set use of the molecular cache on or off.
- Parameters
use_cache (
bool) –Trueif the molecular cache is to be used.- Returns
The calculator.
- Return type
-
-
class
RandomTopologyGraph(topology_graphs, random_seed=None, use_cache=False)¶ Bases:
stk.calculators.base_calculators._EAOperation,stk.calculators.ea.mutators.MutatorChanges topology graphs at random.
Examples
import stk # Create a molecule which is to be mutated. bb1 = stk.BuildingBlock('NCCN', ['amine']) bb2 = stk.BuildingBlock('O=CCC(=O)CC=O', ['aldehyde']) cage = stk.ConstructedMolecule( building_blocks=[bb1, bb2], topology_graph=stk.cage.FourPlusSix() ) # Create topologies used for substition. topology_graphs = [ stk.cage.TwoPlusThree(), stk.cage.EightPlusTwelve(), stk.cage.TwentyPlusThirty() ] # Create the mutator. random_topology = stk.RandomTopologyGraph(topology_graphs) # Mutate a molecule. mutant1 = random_topology.mutate(cage) # Mutate the molecule a second time. mutant2 = random_topology.mutate(cage) # Mutate a mutant. mutant3 = random_topology.mutate(mutant1)
Methods
mutate(self, mol)Return a mutant of mol.
set_cache_use(self, use_cache)Set use of the molecular cache on or off.
-
__init__(self, topology_graphs, random_seed=None, use_cache=False)¶ Initialize a
RandomTopologyinstance.- Parameters
topology_graphs (
listofTopologyGraph) – This lists holds the topology instances from which one is selected at random to form a new molecule.random_seed (
bool, optional) – The random seed to use.use_cache (
bool, optional) – Toggles use of the molecular cache.
-
mutate(self, mol)¶ Return a mutant of mol.
-
set_cache_use(self, use_cache)¶ Set use of the molecular cache on or off.
- Parameters
use_cache (
bool) –Trueif the molecular cache is to be used.- Returns
The calculator.
- Return type
-
-
class
SimilarBuildingBlock(building_blocks, key, duplicate_building_blocks, random_seed=None, use_cache=False)¶ Bases:
stk.calculators.base_calculators._EAOperation,stk.calculators.ea.mutators.MutatorSubstitutes similar building blocks.
This mutator takes a
ConstructedMoleculeand substitutes the building blocks with the most similar one from a given set.Examples
import stk # Create a molecule which is to be mutated. bb1 = stk.BuildingBlock('NCCN', ['amine']) bb2 = stk.BuildingBlock('O=CCC=O', ['aldehyde']) polymer = stk.ConstructedMolecule( building_blocks=[bb1, bb2], topology_graph=stk.polymer.Linear('AB', [0, 0], n=3) ) # Create molecules used to substitute building blocks. building_blocks = [ stk.BuildingBlock('NC[Si]CCN', ['amine']), stk.BuildingBlock('NCCCCCCCN', ['amine']), stk.BuildingBlock('NC1CCCCC1N', ['amine']) ] # Create the mutator. similar_bb = stk.SimilarBuildingBlock( building_blocks=building_blocks, key=lambda mol: mol.func_groups[0].fg_type.name == 'amine' ) # Mutate a molecule. mutant1 = random_bb.mutate(polymer) # Mutate the molecule a second time. mutant2 = random_bb.mutate(polymer) # Mutate a mutant. mutant3 = random_bb.mutate(mutant1)
Methods
mutate(self, mol)Return a mutant of mol.
set_cache_use(self, use_cache)Set use of the molecular cache on or off.
-
__init__(self, building_blocks, key, duplicate_building_blocks, random_seed=None, use_cache=False)¶ Initialize a
RandomBuildingBlockinstance.- Parameters
building_blocks (
tupleofMolecule) – A group of molecules which are used to replace building blocks in molecules being mutated.key (
function) – A function which takes aMoleculeand returnsTrueorFalse. This function is applied to every building block of the molecule being mutated. Building blocks which returnedTrueare liable for substition by one of the molecules inbuilding_blocks.duplicate_building_blocks (
bool, optional) – Indicates whether the building blocks used to construct the mutant must all be unique.random_seed (
bool, optional) – The random seed to use.use_cache (
bool, optional) – Toggles use of the molecular cache.
-
mutate(self, mol)¶ Return a mutant of mol.
-
set_cache_use(self, use_cache)¶ Set use of the molecular cache on or off.
- Parameters
use_cache (
bool) –Trueif the molecular cache is to be used.- Returns
The calculator.
- Return type
-