Remove Molecules

class RemoveMolecules(remover, selector)[source]

Bases: stk.ea.selection.selectors.selector.Selector

Prevents a Selector from selecting some molecules.

Examples

Removing Molecules From Selection

import stk

selector = stk.RemoveMolecules(
    # Do not select any molecules from the top 5 batches
    # of size 3.
    remover=stk.Best(num_batches=5, batch_size=3),
    # Select the ret of the molecules using roulette.
    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. The batch is guaranteed not to
    # contain any molecules which are found in the best 5
    # batches of size 3.
    pass

Methods

select(population[, included_batches, ...])

Yield batches of molecule records from population.

__init__(remover, selector)[source]

Initialize a RemoveMolecules instance.

Parameters
  • remover (Selector) – Selects batches molecules, any molecule selected cannot be selected by selector.

  • selector (Selector) – Selects batches of molecules, not containing any molecules selected by remover.

select(population, included_batches=None, excluded_batches=None)[source]

Yield batches of molecule records from population.

Parameters
  • population (tuple of MoleculeRecord) – A collection of molecules from which batches are selected.

  • included_batches (set, optional) – The identity keys of batches which are allowed to be yielded, if None all batches can be yielded. If not None 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 of MoleculeRecord – A batch of selected molecule records.