Filter Molecules
- class FilterMolecules(filter, selector)[source]
Bases:
Selector
Allows a
Selector
to select only some molecules.Examples
Using a Selection Algorithm on a Subset of Batches
import stk selector = stk.FilterMolecules( # Use only molecules in the top 5 batches of size 3. filter=stk.Best(num_batches=5, batch_size=3), # Select from those molecules using roulette selection. selector=stk.Roulette(num_batches=20, batch_size=3), ) population = tuple( stk.MoleculeRecord( topology_graph=stk.polymer.Linear( building_blocks=( stk.BuildingBlock( smiles='BrCCBr', functional_groups=[stk.BromoFactory()], ), ), repeating_unit='A', num_repeating_units=2, ), ).with_fitness_value(i) for i in range(10) ) for batch in selector.select(population): # Do stuff with batch. All the molecules in the batch # belong to the top 5 batches of size 3. The batch # was selected using roulette selection. pass
Methods
select
(population[, included_batches, ...])Yield batches of molecule records from population.
- __init__(filter, selector)[source]
Initialize a
FilterMolecules
instance.
- select(population, included_batches=None, excluded_batches=None)[source]
Yield batches of molecule records from population.
- Parameters:
population (
tuple
ofMoleculeRecord
) – A collection of molecules from which batches are selected.included_batches (
set
, optional) – The identity keys of batches which are allowed to be yielded, ifNone
all batches can be yielded. If notNone
only batches included_batches will be yielded.excluded_batches (class:set, optional) – The identity keys of batches which are not allowed to be yielded. If
None
, no batch is forbidden from being yielded.
- Yields:
Batch
ofMoleculeRecord
– A batch of selected molecule records.