How to use the stk.polymer 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 / molecular / molecules / test_constructed_molecule.py View on Github external
def test_init(amine2, aldehyde2):
    polymer = stk.ConstructedMolecule(
        building_blocks=[amine2, aldehyde2],
        topology_graph=stk.polymer.Linear('AB', 3),
        use_cache=True
    )
    polymer2 = stk.ConstructedMolecule(
        building_blocks=[amine2, aldehyde2],
        topology_graph=stk.polymer.Linear('AB', 3),
        use_cache=True
    )
    assert polymer is polymer2

    polymer3 = stk.ConstructedMolecule(
        building_blocks=[amine2, aldehyde2],
        topology_graph=stk.polymer.Linear('AB', 3),
        use_cache=False
    )
    assert polymer is not polymer3

    polymer4 = stk.ConstructedMolecule(
        building_blocks=[amine2, aldehyde2],
        topology_graph=stk.polymer.Linear('AB', 3, (1, 0.5)),
        use_cache=True
    )
github lukasturcani / stk / tests / data / ea_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', 3),
    stk.polymer.Linear('A', 6),
    stk.polymer.Linear('A', 12)
]

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

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

generation_selector = stk.SelectorSequence(
    stk.Fittest(num_batches=3, duplicates=False),
github lukasturcani / stk / tests / data / ea_input_files / parallel.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', 3),
    stk.polymer.Linear('A', 6),
    stk.polymer.Linear('A', 12)
]

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

# #####################################################################
# Selector for selecting the next generation.
# #####################################################################
github lukasturcani / stk / tests / fixtures / populations.py View on Github external
def _population_members():
    bb1 = stk.BuildingBlock('NC(CCO)CN', ['amine'])
    bb2 = stk.BuildingBlock('[Br]CCCC[Br]', ['bromine'])
    bb3 = stk.BuildingBlock('[I]COCC[I]', ['iodine'])
    bb4 = stk.BuildingBlock('O=CC(C=O)CC=O', ['aldehyde'])

    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 / 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(
github lukasturcani / stk / tests / data / ea_input_files / parallel.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', 3),
    stk.polymer.Linear('A', 6),
    stk.polymer.Linear('A', 12)
]

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

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

generation_selector = stk.SelectorSequence(
github lukasturcani / stk / tests / calculators / ea / test_mutators.py View on Github external
def test_random_building_block(
    polymer,
    amine2,
    aldehyde2,
    aldehyde2_alt1
):
    mutator = stk.RandomBuildingBlock(
        building_blocks=[aldehyde2_alt1],
        key=lambda mol: mol.func_groups[0].fg_type.name == 'aldehyde'
    )
    mutant = mutator.mutate(polymer)
    expected = stk.ConstructedMolecule(
        building_blocks=[amine2, aldehyde2_alt1],
        topology_graph=stk.polymer.Linear('AB', 3)
    )
    assert mutant.get_identity_key() == expected.get_identity_key()
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()
    }
    assert mutant.get_identity_key() in expected
github lukasturcani / stk / tests / fixtures / topology_graphs.py View on Github external
def tmp_ab_chain3():
    return stk.polymer.Linear('AB', 3)