How to use the stk.polymer.Linear function in stk

To help you get started, we’ve selected a few stk examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github lukasturcani / stk / tests / data / ga_input_files / serial.py View on Github external
logging_level = logging.DEBUG

# #####################################################################
# Initial population.
# #####################################################################

carbon = 'C'
building_blocks = [
    stk.BuildingBlock(f'[Br]{carbon*i}[Br]', ['bromine'])
    for i in range(2, 27)
]

topology_graphs = [
    stk.polymer.Linear('A', [0], 3),
    stk.polymer.Linear('A', [0], 6),
    stk.polymer.Linear('A', [0], 12)
]

population = stk.GAPopulation.init_random(
    building_blocks=[building_blocks],
    topology_graphs=topology_graphs,
    size=25,
    use_cache=True
)

# #####################################################################
# Selector for selecting the next generation.
# #####################################################################

generation_selector = stk.SelectorSequence(
    stk.Fittest(num_batches=3, duplicates=False),
    stk.Roulette(num_batches=22, duplicates=False)
github lukasturcani / stk / tests / molecular / test_reactor.py View on Github external
def test_react_any_single(make_reactor, amine2):
    reactor = make_reactor(
        building_blocks=[amine2, amine2],
        topology_graph=stk.polymer.Linear('AB', 3)
    )
    _test_reaction(
        reactor=reactor,
        atom_change_per_reaction=-4,
        bond_change_per_reaction=-3,
        costruction_bonds_per_reaction=1,
        periodic_bonds_per_periodic_reaction=1,
        expected_construction_bond_order=lambda bond: 1
    )
github lukasturcani / stk / tests / calculators / ea / test_mutators.py View on Github external
def test_random_topology_graph(polymer):
    chain1 = stk.polymer.Linear('AB', 4)
    chain2 = stk.polymer.Linear('AB', 5)
    expected1 = stk.ConstructedMolecule(
        building_blocks=list(polymer.building_block_vertices.keys()),
        topology_graph=chain1
    )
    expected2 = stk.ConstructedMolecule(
        building_blocks=list(polymer.building_block_vertices.keys()),
        topology_graph=chain2
    )
    mutator = stk.RandomTopologyGraph([chain1, chain2])
    mutant = mutator.mutate(polymer)

    expected = {
        expected1.get_identity_key(),
        expected2.get_identity_key()
    }
github lukasturcani / stk / tests / fixtures / populations.py View on Github external
c1 = stk.ConstructedMolecule(
        building_blocks=[bb2],
        topology_graph=stk.polymer.Linear('A', 3)
    )
    c2 = stk.ConstructedMolecule(
        building_blocks=[bb1, bb4],
        topology_graph=stk.cage.FourPlusSix()
    )
    c3 = stk.ConstructedMolecule(
        building_blocks=[bb1, bb4],
        topology_graph=stk.cage.EightPlusTwelve()
    )
    c4 = stk.ConstructedMolecule(
        building_blocks=[bb2, bb3],
        topology_graph=stk.polymer.Linear('AB', 3)
    )

    return bb1, bb2, bb3, bb4, c1, c2, c3, c4
github lukasturcani / stk / tests / calculators / ea / test_mutators.py View on Github external
def test_random_mutation(polymer):
    chain1 = stk.polymer.Linear('AB', 4)
    chain2 = stk.polymer.Linear('AB', 5)
    t1 = stk.RandomTopologyGraph([chain1])
    t2 = stk.RandomTopologyGraph([chain2])
    mutator1 = stk.Random(t1, t2, probabilities=[1, 0])
    mutator2 = stk.Random(t1, t2, probabilities=[0, 1])

    mutant1 = mutator1.mutate(polymer)
    expected1 = stk.ConstructedMolecule(
        building_blocks=list(polymer.building_block_vertices.keys()),
        topology_graph=chain1
    )
    assert mutant1.get_identity_key() == expected1.get_identity_key()

    expected2 = stk.ConstructedMolecule(
        building_blocks=list(polymer.building_block_vertices.keys()),
        topology_graph=chain2
    )
github lukasturcani / stk / tests / molecular / test_reactor.py View on Github external
def test_react_diol_with_dihalogen(
    make_reactor,
    diol2,
    difluorene_dibromine
):
    reactor = make_reactor(
        building_blocks=[diol2, difluorene_dibromine],
        topology_graph=stk.polymer.Linear('AB', 3)
    )
    _test_reaction(
        reactor=reactor,
        atom_change_per_reaction=-4,
        bond_change_per_reaction=-2,
        costruction_bonds_per_reaction=2,
        periodic_bonds_per_periodic_reaction=2,
        expected_construction_bond_order=lambda bond: 1
    )
github lukasturcani / stk / tests / calculators / ea / test_mutators.py View on Github external
expected = stk.ConstructedMolecule(
        building_blocks=[
            amine2,
            max(alts, key=lambda m: stk.dice_similarity(m, aldehyde2))
        ],
        topology_graph=stk.polymer.Linear('AB', 3)
    )
    assert mutant.get_identity_key() == expected.get_identity_key()

    mutant = mutator.mutate(polymer)
    expected = stk.ConstructedMolecule(
        building_blocks=[
            amine2,
            min(alts, key=lambda m: stk.dice_similarity(m, aldehyde2))
        ],
        topology_graph=stk.polymer.Linear('AB', 3)
    )
    assert mutant.get_identity_key() == expected.get_identity_key()
github lukasturcani / stk / tests / databases / constructed_molecule / fixtures / constructed_molecule_mongo_db.py View on Github external
                topology_graph=stk.polymer.Linear(
                    building_blocks=(
                        stk.BuildingBlock(
                            smiles='BrCCBr',
                            functional_groups=[stk.BromoFactory()],
                        ),
                    ),
                    repeating_unit='A',
                    num_repeating_units=2,
                ),
            ),
            key={
                'InChIKey':
                    rdkit.MolToInchiKey(rdkit.MolFromSmiles(
                        SMILES='BrCCCCBr'
                    )),
            },