Selection Plotter

class SelectionPlotter(filename, selector, x_label='Molecule: InChIKey - Fitness Value', record_label=<function SelectionPlotter.<lambda>>, heat_map_value=<function SelectionPlotter.<lambda>>, heat_map_label='Fitness', order_by=<function SelectionPlotter.<lambda>>)[source]

Bases: object

Plots which molecule records a Selector selects.

Examples

Plotting Which Molecule Records Got Selected

import stk

# Make a selector.
roulette = stk.Roulette(num_batches=10)

# Make a population.
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(100)
)

# Make a plotter. You do not have to assign it to a variable.
stk.SelectionPlotter('roulette_counter', roulette)

# Select the molecule records.
selected = tuple(roulette.select(population))

# There should now be a file called "roulette_counter_1.png"
# which shows a graph of all the selected records.

# Select records again.
selected2 = tuple(roulette.select(population))

# There should now be a file called "roulette_counter_2.png"
# which shows a graph of all the selected molecules.

# And so on every time you use "roulette.select()".
__init__(filename, selector, x_label='Molecule: InChIKey - Fitness Value', record_label=<function SelectionPlotter.<lambda>>, heat_map_value=<function SelectionPlotter.<lambda>>, heat_map_label='Fitness', order_by=<function SelectionPlotter.<lambda>>)[source]

Initialize a SelectionPlotter instance.

Parameters:
  • filename (str) – The basename of the files. This means it should not include file extensions.

  • selector (Selector) – The Selector whose selection of molecule records is plotted.

  • x_label (str, optional) – The label use for the x axis.

  • record_label (callable, optional) – A callable which takes a MoleculeRecord for each record, which is to be included on the x-axis of the counter plot. It should return a string, which is the label used for the MoleculeRecord on the plot.

  • heat_map_value (callable, optional) – A callable, which takes a MoleculeRecord for each record, which is to be included on the x-axis, and returns a value. The value is used for coloring the heat map used in the plot.

  • heat_map_label (str, optional) – The label used for the heat map key.

  • order_by (callable, optional) – A callable, which takes a MoleculeRecord for each record, which is to be included on the x-axis, and returns a value. The value is used to sort the plotted records along the x-axis in descending order.