stk.FilterBatches

class stk.FilterBatches(filter, selector)[source]

Bases: Selector[T]

Allows a Selector to select only some batches.

Examples

Using a Selection Algorithm on a Subset of Batches

You only want the Best 10 batches to participate in Roulette

import stk

# Select the 10 best batches first, and then run roulette on
# those.
selector = stk.FilterBatches(
    filter=stk.Best(10),
    selector=stk.Roulette(7),
)

population = {
    stk.MoleculeRecord(
        topology_graph=stk.polymer.Linear(
            building_blocks=[
                stk.BuildingBlock('BrCCBr', stk.BromoFactory()),
            ],
            repeating_unit='A',
            num_repeating_units=2,
        ),
    ): i
    for i in range(100)
}

for batch in selector.select(population):
    # Do stuff with batch. It is one of the 10 best batches and
    # was selected using roulette selection.
    pass
Parameters:
  • filter (Selector[T]) – Selects batches which can be yielded by selector.

  • selector (Selector[T]) – Selects batches, but only if they were also selected by filter.

Methods

select

Yield batches of molecule records from population.

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

Yield batches of molecule records from population.

Parameters:
  • population (dict[T, float]) – A collection of molecules from which batches are selected.

  • included_batches (set[BatchKey] | None) – 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 (set[BatchKey] | None) – The identity keys of batches which are not allowed to be yielded. If None, no batch is forbidden from being yielded.

Yields:

A batch of selected molecule records.