Example #1
0
def above_average_population_2() -> tuple[stk.MoleculeRecord, ...]:
    return (
        stk.MoleculeRecord(
            topology_graph=get_topology_graph(7), ).with_fitness_value(100),
        stk.MoleculeRecord(
            topology_graph=get_topology_graph(8), ).with_fitness_value(1),
    )
Example #2
0
def get_generation(*fitness_values):
    v1, v2, v3, *_ = fitness_values
    return (stk.MoleculeRecord(
        topology_graph=topology_graph, ).with_fitness_value(v1),
            stk.MoleculeRecord(
                topology_graph=topology_graph, ).with_fitness_value(v2),
            stk.MoleculeRecord(
                topology_graph=topology_graph, ).with_fitness_value(v3),
            stk.MoleculeRecord(topology_graph=topology_graph, ))
Example #3
0
def worst_population_2() -> tuple[stk.MoleculeRecord, ...]:
    return (
        stk.MoleculeRecord(
            topology_graph=get_topology_graph(6), ).with_fitness_value(100),
        stk.MoleculeRecord(
            topology_graph=get_topology_graph(6), ).with_fitness_value(100),
        stk.MoleculeRecord(
            topology_graph=get_topology_graph(8), ).with_fitness_value(1),
    )
Example #4
0
def remove_batches_population_1() -> tuple[stk.MoleculeRecord, ...]:
    return (
        stk.MoleculeRecord(
            topology_graph=get_topology_graph(2), ).with_fitness_value(10),
        stk.MoleculeRecord(
            topology_graph=get_topology_graph(3), ).with_fitness_value(9),
        stk.MoleculeRecord(
            topology_graph=get_topology_graph(4), ).with_fitness_value(2),
        stk.MoleculeRecord(
            topology_graph=get_topology_graph(5), ).with_fitness_value(1),
        stk.MoleculeRecord(
            topology_graph=get_topology_graph(6), ).with_fitness_value(1),
    )
Example #5
0
def tournament_population_1() -> tuple[stk.MolecularRecord, ...]:
    return (
        stk.MoleculeRecord(
            topology_graph=get_topology_graph(2), ).with_fitness_value(10),
        stk.MoleculeRecord(
            topology_graph=get_topology_graph(3), ).with_fitness_value(9),
        stk.MoleculeRecord(
            topology_graph=get_topology_graph(4), ).with_fitness_value(2),
        stk.MoleculeRecord(
            topology_graph=get_topology_graph(5), ).with_fitness_value(1),
        stk.MoleculeRecord(
            topology_graph=get_topology_graph(6), ).with_fitness_value(0),
    )
def stochastic_universal_sampling_population_1(
) -> tuple[stk.MoleculeRecord, ...]:
    return (
        stk.MoleculeRecord(
            topology_graph=get_topology_graph(2), ).with_fitness_value(10),
        stk.MoleculeRecord(
            topology_graph=get_topology_graph(3), ).with_fitness_value(9),
        stk.MoleculeRecord(
            topology_graph=get_topology_graph(4), ).with_fitness_value(2),
        stk.MoleculeRecord(
            topology_graph=get_topology_graph(5), ).with_fitness_value(1),
        stk.MoleculeRecord(
            topology_graph=get_topology_graph(6), ).with_fitness_value(1),
    )
Example #7
0
def _get_case_data_1() -> CaseData:
    topology_graph = stk.polymer.Linear(
        building_blocks=(stk.BuildingBlock('BrCCBr', [stk.BromoFactory()]), ),
        repeating_unit='A',
        num_repeating_units=2,
    )
    return CaseData(
        fitness_normalizer=stk.ReplaceFitness(
            get_replacement=lambda population: min(record.get_fitness_value()
                                                   for record in population
                                                   if record.get_fitness_value(
                                                   ) is not None) / 2,
            filter=lambda population, record: record.get_fitness_value() is
            None,
        ),
        population=(
            stk.MoleculeRecord(
                topology_graph=topology_graph, ).with_fitness_value(1),
            stk.MoleculeRecord(
                topology_graph=topology_graph, ).with_fitness_value(2),
            stk.MoleculeRecord(
                topology_graph=topology_graph, ).with_fitness_value(3),
            stk.MoleculeRecord(topology_graph),
        ),
        normalized=(
            stk.MoleculeRecord(
                topology_graph=topology_graph, ).with_fitness_value(1),
            stk.MoleculeRecord(
                topology_graph=topology_graph, ).with_fitness_value(2),
            stk.MoleculeRecord(
                topology_graph=topology_graph, ).with_fitness_value(3),
            stk.MoleculeRecord(
                topology_graph=topology_graph, ).with_fitness_value(0.5),
        ),
    )
Example #8
0
def _get_case_data_1() -> CaseData:

    topology_graph = stk.polymer.Linear(
        building_blocks=(stk.BuildingBlock('BrCCBr', [stk.BromoFactory()]), ),
        repeating_unit='A',
        num_repeating_units=2,
    )
    return CaseData(
        fitness_normalizer=stk.Sum(filter=lambda population, record: record.
                                   get_fitness_value() is not None,
                                   ),
        population=(
            stk.MoleculeRecord(
                topology_graph=topology_graph, ).with_fitness_value(
                    (1, -5, 5)),
            stk.MoleculeRecord(
                topology_graph=topology_graph, ).with_fitness_value(
                    (3, -10, 2)),
            stk.MoleculeRecord(
                topology_graph=topology_graph, ).with_fitness_value(
                    (2, 20, 1)),
            stk.MoleculeRecord(topology_graph),
        ),
        normalized=(
            stk.MoleculeRecord(
                topology_graph=topology_graph, ).with_fitness_value(1),
            stk.MoleculeRecord(
                topology_graph=topology_graph, ).with_fitness_value(-5),
            stk.MoleculeRecord(
                topology_graph=topology_graph, ).with_fitness_value(23),
            stk.MoleculeRecord(topology_graph),
        ),
    )
def get_initial_population(fluoros, bromos):
    for fluoro, bromo in it.product(fluoros[:5], bromos[:5]):
        yield stk.MoleculeRecord(topology_graph=stk.polymer.Linear(
            building_blocks=(fluoro, bromo),
            repeating_unit='AB',
            num_repeating_units=1,
        ), )
Example #10
0
def _get_case_data_1() -> CaseData:
    bb1 = stk.BuildingBlock('BrCCBr', [stk.BromoFactory()])
    graph1 = stk.polymer.Linear((bb1, ), 'A', 2)

    bb2 = stk.BuildingBlock('BrCNCBr', [stk.BromoFactory()])
    graph2 = stk.polymer.Linear((bb2, ), 'A', 2)

    return CaseData(
        mutator=stk.RandomMutator(mutators=(stk.RandomBuildingBlock(
            building_blocks=(bb2, ),
            is_replaceable=has_bromo,
        ), ), ),
        record=stk.MoleculeRecord(graph1),
        mutation_record=stk.MutationRecord(
            molecule_record=stk.MoleculeRecord(graph2),
            mutator_name='RandomBuildingBlock',
        ),
    )
Example #11
0
def _get_case_data_1() -> CaseData:

    topology_graph = stk.polymer.Linear(
        building_blocks=(stk.BuildingBlock('BrCCBr', [stk.BromoFactory()]), ),
        repeating_unit='A',
        num_repeating_units=2,
    )

    return CaseData(
        fitness_normalizer=stk.NullFitnessNormalizer(),
        population=(
            stk.MoleculeRecord(
                topology_graph=topology_graph, ).with_fitness_value(1),
            stk.MoleculeRecord(
                topology_graph=topology_graph, ).with_fitness_value(2),
            stk.MoleculeRecord(
                topology_graph=topology_graph, ).with_fitness_value(3),
        ),
        normalized=(
            stk.MoleculeRecord(
                topology_graph=topology_graph, ).with_fitness_value(1),
            stk.MoleculeRecord(
                topology_graph=topology_graph, ).with_fitness_value(2),
            stk.MoleculeRecord(
                topology_graph=topology_graph, ).with_fitness_value(3),
        ),
    )
Example #12
0
def _get_case_data_1() -> CaseData:
    topology_graph = stk.polymer.Linear(
        building_blocks=(
            stk.BuildingBlock('BrCCBr', [stk.BromoFactory()]),
        ),
        repeating_unit='A',
        num_repeating_units=2,
    )
    return CaseData(
        fitness_normalizer=stk.Add(
            number=(1, 2, 3),
            filter=lambda population, record:
                record.get_fitness_value() is not None,
        ),
        population=(
            stk.MoleculeRecord(
                topology_graph=topology_graph,
            ).with_fitness_value((1, 10, 100)),
            stk.MoleculeRecord(
                topology_graph=topology_graph,
            ).with_fitness_value((2, 20, 200)),
            stk.MoleculeRecord(
                topology_graph=topology_graph,
            ).with_fitness_value((3, 30, 300)),
            stk.MoleculeRecord(topology_graph),
        ),
        normalized=(
            stk.MoleculeRecord(
                topology_graph=topology_graph,
            ).with_fitness_value((2, 12, 103)),
            stk.MoleculeRecord(
                topology_graph=topology_graph,
            ).with_fitness_value((3, 22, 203)),
            stk.MoleculeRecord(
                topology_graph=topology_graph,
            ).with_fitness_value((4, 32, 303)),
            stk.MoleculeRecord(topology_graph),
        ),
    )
Example #13
0
def _get_case_data_1() -> CaseData:
    topology_graph = stk.polymer.Linear(
        building_blocks=(stk.BuildingBlock('BrCCBr', [stk.BromoFactory()]), ),
        repeating_unit='A',
        num_repeating_units=2,
    )
    return CaseData(
        fitness_normalizer=stk.NormalizerSequence(fitness_normalizers=(
            stk.Multiply(
                coefficient=(1, 2, 4),
                filter=lambda population, record: record.get_fitness_value() is
                not None,
            ),
            stk.Sum(filter=lambda population, record: record.get_fitness_value(
            ) is not None,
                    ),
        ), ),
        population=(
            stk.MoleculeRecord(
                topology_graph=topology_graph, ).with_fitness_value(
                    (4, 10, 1)),
            stk.MoleculeRecord(
                topology_graph=topology_graph, ).with_fitness_value(
                    (9, 20, 2)),
            stk.MoleculeRecord(
                topology_graph=topology_graph, ).with_fitness_value(
                    (16, 30, 4)),
            stk.MoleculeRecord(topology_graph),
        ),
        normalized=(
            stk.MoleculeRecord(
                topology_graph=topology_graph, ).with_fitness_value(28),
            stk.MoleculeRecord(
                topology_graph=topology_graph, ).with_fitness_value(57),
            stk.MoleculeRecord(
                topology_graph=topology_graph, ).with_fitness_value(92),
            stk.MoleculeRecord(topology_graph),
        ),
    )
Example #14
0
    ),
    repeating_unit='A',
    num_repeating_units=2,
)


@pytest.fixture(
    params=(
        CaseData(
            fitness_normalizer=stk.Sum(
                filter=lambda population, record:
                    record.get_fitness_value() is not None,
            ),
            population=(
                stk.MoleculeRecord(
                    topology_graph=topology_graph,
                ).with_fitness_value((1, -5, 5)),
                stk.MoleculeRecord(
                    topology_graph=topology_graph,
                ).with_fitness_value((3, -10, 2)),
                stk.MoleculeRecord(
                    topology_graph=topology_graph,
                ).with_fitness_value((2, 20, 1)),
                stk.MoleculeRecord(topology_graph),
            ),
            normalized=(
                stk.MoleculeRecord(
                    topology_graph=topology_graph,
                ).with_fitness_value(1),
                stk.MoleculeRecord(
                    topology_graph=topology_graph,
Example #15
0
    building_blocks=(stk.BuildingBlock('BrCCBr', [stk.BromoFactory()]), ),
    repeating_unit='A',
    num_repeating_units=2,
)


@pytest.fixture(
    params=(CaseData(
        fitness_normalizer=stk.Add(
            number=(1, 2, 3),
            filter=lambda population, record: record.get_fitness_value() is
            not None,
        ),
        population=(
            stk.MoleculeRecord(
                topology_graph=topology_graph, ).with_fitness_value(
                    (1, 10, 100)),
            stk.MoleculeRecord(
                topology_graph=topology_graph, ).with_fitness_value(
                    (2, 20, 200)),
            stk.MoleculeRecord(
                topology_graph=topology_graph, ).with_fitness_value(
                    (3, 30, 300)),
            stk.MoleculeRecord(topology_graph),
        ),
        normalized=(
            stk.MoleculeRecord(
                topology_graph=topology_graph, ).with_fitness_value(
                    (2, 12, 103)),
            stk.MoleculeRecord(
                topology_graph=topology_graph, ).with_fitness_value(
Example #16
0
from ..case_data import CaseData


def has_bromo(building_block):
    fg, = building_block.get_functional_groups(0)
    return fg.__class__ is stk.Bromo


bb1 = stk.BuildingBlock('BrCCBr', [stk.BromoFactory()])
graph1 = stk.polymer.Linear((bb1, ), 'A', 2)

bb2 = stk.BuildingBlock('BrCNCBr', [stk.BromoFactory()])
graph2 = stk.polymer.Linear((bb2, ), 'A', 2)


@pytest.fixture(
    params=(CaseData(
        mutator=stk.RandomBuildingBlock(
            building_blocks=(bb2, ),
            is_replaceable=has_bromo,
        ),
        record=stk.MoleculeRecord(graph1),
        mutation_record=stk.MutationRecord(
            molecule_record=stk.MoleculeRecord(graph2),
            mutator_name='RandomBuildingBlock',
        ),
    ), ), )
def random_building_block(request):
    return request.param
Example #17
0
    building_blocks=(stk.BuildingBlock('BrCCBr', [stk.BromoFactory()]), ),
    repeating_unit='A',
    num_repeating_units=2,
)


@pytest.fixture(
    params=(CaseData(
        fitness_normalizer=stk.Multiply(
            coefficient=(1, 2, 3),
            filter=lambda population, record: record.get_fitness_value() is
            not None,
        ),
        population=(
            stk.MoleculeRecord(
                topology_graph=topology_graph, ).with_fitness_value(
                    (1, 10, 100)),
            stk.MoleculeRecord(
                topology_graph=topology_graph, ).with_fitness_value(
                    (2, 20, 200)),
            stk.MoleculeRecord(
                topology_graph=topology_graph, ).with_fitness_value(
                    (3, 30, 300)),
            stk.MoleculeRecord(topology_graph),
        ),
        normalized=(
            stk.MoleculeRecord(
                topology_graph=topology_graph, ).with_fitness_value(
                    (1, 20, 300)),
            stk.MoleculeRecord(
                topology_graph=topology_graph, ).with_fitness_value(
Example #18
0

def get_topology_graph(num_repeating_units):
    return stk.polymer.Linear(
        building_blocks=(stk.BuildingBlock('BrCCBr', [stk.BromoFactory()]), ),
        repeating_unit='A',
        num_repeating_units=num_repeating_units,
    )


@pytest.fixture(
    scope='session',
    params=(lambda: CaseData(
        selector=stk.Roulette(num_batches=50),
        population=(
            stk.MoleculeRecord(topology_graph=get_topology_graph(2),
                               ).with_fitness_value(1),
            stk.MoleculeRecord(topology_graph=get_topology_graph(3),
                               ).with_fitness_value(2),
            stk.MoleculeRecord(topology_graph=get_topology_graph(4), ).
            with_fitness_value(3),
            stk.MoleculeRecord(topology_graph=get_topology_graph(5),
                               ).with_fitness_value(4),
            stk.MoleculeRecord(topology_graph=get_topology_graph(6),
                               ).with_fitness_value(5),
            stk.MoleculeRecord(topology_graph=get_topology_graph(7),
                               ).with_fitness_value(6),
            stk.MoleculeRecord(topology_graph=get_topology_graph(8),
                               ).with_fitness_value(7),
            stk.MoleculeRecord(topology_graph=get_topology_graph(9),
                               ).with_fitness_value(8),
            stk.MoleculeRecord(topology_graph=get_topology_graph(10),
Example #19
0
@pytest.fixture(
    params=(CaseData(
        fitness_normalizer=stk.NormalizerSequence(fitness_normalizers=(
            stk.Multiply(
                coefficient=(1, 2, 4),
                filter=lambda population, record: record.get_fitness_value() is
                not None,
            ),
            stk.Sum(filter=lambda population, record: record.get_fitness_value(
            ) is not None,
                    ),
        ), ),
        population=(
            stk.MoleculeRecord(
                topology_graph=topology_graph, ).with_fitness_value(
                    (4, 10, 1)),
            stk.MoleculeRecord(
                topology_graph=topology_graph, ).with_fitness_value(
                    (9, 20, 2)),
            stk.MoleculeRecord(
                topology_graph=topology_graph, ).with_fitness_value(
                    (16, 30, 4)),
            stk.MoleculeRecord(topology_graph),
        ),
        normalized=(
            stk.MoleculeRecord(
                topology_graph=topology_graph, ).with_fitness_value(28),
            stk.MoleculeRecord(
                topology_graph=topology_graph, ).with_fitness_value(57),
            stk.MoleculeRecord(
Example #20
0
    building_blocks=(stk.BuildingBlock('BrCCBr', [stk.BromoFactory()]), ),
    repeating_unit='A',
    num_repeating_units=2,
)


@pytest.fixture(
    params=(CaseData(
        fitness_normalizer=stk.Power(
            power=(0.5, 0, -1),
            filter=lambda population, record: record.get_fitness_value() is
            not None,
        ),
        population=(
            stk.MoleculeRecord(
                topology_graph=topology_graph, ).with_fitness_value(
                    (4, 10, 1)),
            stk.MoleculeRecord(
                topology_graph=topology_graph, ).with_fitness_value(
                    (9, 20, 2)),
            stk.MoleculeRecord(
                topology_graph=topology_graph, ).with_fitness_value(
                    (16, 30, 4)),
            stk.MoleculeRecord(topology_graph),
        ),
        normalized=(
            stk.MoleculeRecord(
                topology_graph=topology_graph, ).with_fitness_value((2, 1, 1)),
            stk.MoleculeRecord(
                topology_graph=topology_graph, ).with_fitness_value(
                    (3, 1, 0.5)),
Example #21
0
from ..case_data import CaseData


def get_topology_graph(num_repeating_units):
    return stk.polymer.Linear(
        building_blocks=(
            stk.BuildingBlock('BrCCBr', [stk.BromoFactory()]),
        ),
        repeating_unit='A',
        num_repeating_units=num_repeating_units,
    )


population1 = (
    stk.MoleculeRecord(
        topology_graph=get_topology_graph(2),
    ).with_fitness_value(10),
    stk.MoleculeRecord(
        topology_graph=get_topology_graph(3),
    ).with_fitness_value(9),
    stk.MoleculeRecord(
        topology_graph=get_topology_graph(4),
    ).with_fitness_value(2),
    stk.MoleculeRecord(
        topology_graph=get_topology_graph(5),
    ).with_fitness_value(1),
    stk.MoleculeRecord(
        topology_graph=get_topology_graph(6),
    ).with_fitness_value(1),
)
population2 = (
Example #22
0
def get_eight_plus_twelve(graph):
    return stk.cage.EightPlusTwelve(graph.get_building_blocks())


@pytest.fixture(
    scope='session',
    params=(lambda: CaseData(
        mutator=stk.RandomTopologyGraph(replacement_funcs=(
            get_eight_plus_twelve, ), ),
        record=stk.MoleculeRecord(topology_graph=stk.cage.FourPlusSix(
            building_blocks=(
                stk.BuildingBlock(
                    smiles='BrCCBr',
                    functional_groups=[stk.BromoFactory()],
                ),
                stk.BuildingBlock(
                    smiles='BrCC(CBr)CBr',
                    functional_groups=[stk.BromoFactory()],
                ),
            ), ), ),
        mutation_record=stk.MutationRecord(
            molecule_record=stk.MoleculeRecord(
                topology_graph=stk.cage.EightPlusTwelve(building_blocks=(
                    stk.BuildingBlock(
                        smiles='BrCCBr',
                        functional_groups=[stk.BromoFactory()],
                    ),
                    stk.BuildingBlock(
                        smiles='BrCC(CBr)CBr',
                        functional_groups=[stk.BromoFactory()],
Example #23
0
bb1 = stk.BuildingBlock('BrCCBr', [stk.BromoFactory()])
bb2 = stk.BuildingBlock('BrCC(CBr)CBr', [stk.BromoFactory()])
graph1 = stk.cage.FourPlusSix((bb1, bb2))

bb3 = stk.BuildingBlock('BrCNCBr', [stk.BromoFactory()])
bb4 = stk.BuildingBlock('BrCC(CNCBr)CBr', [stk.BromoFactory()])
graph2 = stk.cage.EightPlusTwelve((bb3, bb4))


@pytest.fixture(
    scope='session',
    params=(lambda: CaseData(
        crosser=stk.RandomCrosser(crossers=(stk.GeneticRecombination(get_gene=(
            stk.BuildingBlock.get_num_functional_groups), ), ), ),
        records=(
            stk.MoleculeRecord(graph1),
            stk.MoleculeRecord(graph2),
        ),
        crossover_records=(stk.CrossoverRecord(
            molecule_record=stk.MoleculeRecord(topology_graph=graph1, ),
            crosser_name='GeneticRecombination',
        ),
                           stk.CrossoverRecord(
                               molecule_record=stk.MoleculeRecord(
                                   topology_graph=graph1.with_building_blocks(
                                       building_block_map={bb1: bb3}, ), ),
                               crosser_name='GeneticRecombination',
                           ),
                           stk.CrossoverRecord(
                               molecule_record=stk.MoleculeRecord(
                                   topology_graph=graph1.with_building_blocks(
Example #24
0
    num_repeating_units=2,
)


@pytest.fixture(
    params=(CaseData(
        fitness_normalizer=stk.ReplaceFitness(
            get_replacement=lambda population: min(record.get_fitness_value()
                                                   for record in population
                                                   if record.get_fitness_value(
                                                   ) is not None) / 2,
            filter=lambda population, record: record.get_fitness_value() is
            None,
        ),
        population=(
            stk.MoleculeRecord(
                topology_graph=topology_graph, ).with_fitness_value(1),
            stk.MoleculeRecord(
                topology_graph=topology_graph, ).with_fitness_value(2),
            stk.MoleculeRecord(
                topology_graph=topology_graph, ).with_fitness_value(3),
            stk.MoleculeRecord(topology_graph),
        ),
        normalized=(
            stk.MoleculeRecord(
                topology_graph=topology_graph, ).with_fitness_value(1),
            stk.MoleculeRecord(
                topology_graph=topology_graph, ).with_fitness_value(2),
            stk.MoleculeRecord(
                topology_graph=topology_graph, ).with_fitness_value(3),
            stk.MoleculeRecord(
                topology_graph=topology_graph, ).with_fitness_value(0.5),