Пример #1
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),
        ),
    )
Пример #2
0

# Minimize synthetic accessibility and asymmetry.
# Maximise pore volume and window size.
fitness_normalizer = stk.TryCatch(
    stk.Sequence(
        save_fitness,
        stk.Power([1, 1, -1, -1], filter=valid_fitness),
        stk.DivideByMean(filter=valid_fitness),
        stk.Multiply([5, 1, 10, 10], filter=valid_fitness),
        stk.Sum(filter=valid_fitness),
        # Replace all fitness values that are lists or None with
        # a small value.
        stk.ReplaceFitness(replacement_fn=lambda population: 1e-8,
                           filter=lambda p, m: isinstance(
                               p.get_fitness_values()[m],
                               (list, type(None)),
                           )),
    ),
    stk.ReplaceFitness(replacement_fn=lambda population: 1e-8, ))

# #####################################################################
# Exit condition.
# #####################################################################

terminator = stk.NumGenerations(50)

# #####################################################################
# Make plotters.
# #####################################################################
Пример #3
0

def valid_fitness(population, mol):
    return None not in population.get_fitness_values()[mol]


fitness_normalizer = stk.Sequence(
    stk.Power([1, -1], filter=valid_fitness),
    stk.DivideByMean(filter=valid_fitness),
    stk.Multiply([1.0, 1.0], filter=valid_fitness),
    stk.Sum(filter=valid_fitness),
    stk.ReplaceFitness(
        replacement_fn=lambda population:
            min(
                f for _, f in population.get_fitness_values().items()
                if not isinstance(f, list)
            ) / 2,
        filter=lambda p, m:
            isinstance(p.get_fitness_values()[m], list),
    )
)


# #####################################################################
# Exit condition.
# #####################################################################

terminator = stk.NumGenerations(60)

# #####################################################################
# Make plotters.
Пример #4
0
    num_repeating_units=2,
)

topology_graph = stk.polymer.Linear(
    building_blocks=(stk.BuildingBlock('BrCCBr', [stk.BromoFactory()]), ),
    repeating_unit='A',
    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),