Esempio n. 1
0
def tmp_population():
    bb1, bb2, bb3, bb4, c1, c2, c3, c4 = _population_members()
    return stk.Population(
        c3, stk.BuildingBlock('NCCCN'), bb1,
        stk.BuildingBlock('NCCCN', ['amine']), c1,
        stk.BuildingBlock('O=CCC=O'), c1,
        stk.BuildingBlock('O=CCC=O', ['aldehyde']),
        stk.Population(c1, stk.BuildingBlock('[Br]CC[Br]'), bb1, bb2, bb1), c2,
        stk.Population(bb1, stk.BuildingBlock('CCCC'),
                       stk.Population(bb3, stk.BuildingBlock('NNNN'), c4)))
Esempio n. 2
0
def progress():
    pop = stk.Population()
    for i in range(15):
        subpop = stk.Population(*(stk.BuildingBlock('C') for j in range(5)))
        pop.subpopulations.append(subpop)

    for i, mol in enumerate(pop):
        mol.fitness = i

    return pop
Esempio n. 3
0
def test_init(amine2, aldehyde2, amine3):
    """
    Tests the __init__ method of the stk.Population class.

    """

    pop = stk.Population(
        NewMol(), amine2, NewMol(),
        stk.Population(NewMol(), NewMol(), aldehyde2), stk.Population(),
        stk.Population(amine3, stk.Population(NewMol(), NewMol())), NewMol())

    assert len(pop) == 10
    assert len(pop.direct_members) == 4
    assert len(pop.subpopulations) == 3
Esempio n. 4
0
def test_init():
    """
    Tests the __init__ method of the stk.Population class.

    """
    def NewMol():
        return stk.MacroMolecule.__new__(stk.MacroMolecule)

    pop = stk.Population(NewMol(), NewMol(),
                         stk.Population(NewMol(), NewMol()), stk.Population(),
                         stk.Population(stk.Population(NewMol(), NewMol())),
                         NewMol())

    assert len(pop) == 7
    assert len(pop.members) == 3
    assert len(pop.populations) == 3
Esempio n. 5
0
def test_remove_duplicates_not_across_subpopulations():
    x = stk.BuildingBlock('C')
    y = stk.BuildingBlock('N')
    subpop = stk.Population(x, x, y, stk.Population(y, y))
    pop = subpop.clone() + subpop.clone()
    counts = Counter(pop)
    assert counts[x] == 4
    assert counts[y] == 6

    subpop_counts = Counter(pop.subpopulations[0].direct_members)
    assert subpop_counts[x] == 2
    assert subpop_counts[y] == 1

    pop.remove_duplicates(across_subpopulations=False)
    counts = Counter(pop)
    assert counts[x] == 2
    assert counts[y] == 4

    subpop_counts = Counter(pop.subpopulations[0].direct_members)
    assert subpop_counts[x] == 1
    assert subpop_counts[y] == 1
Esempio n. 6
0
def parallel_pop_update(collection, population_files):
    update_fn = globals()['update']
    with mp.Pool() as pool:
        p = stk.Population()
        for pop_file in population_files:
            p.add_members(stk.Population.load(pop_file,
                                              stk.Molecule.from_dict))

        updates = pool.map(update_fn, p)
        for mol, update in updates:
            key = (macromol_key
                   if isinstance(mol, stk.MacroMolecule) else struct_unit_key)
            collection.update_one(key(mol), **update)
Esempio n. 7
0
def generation():
    pop = stk.Population(*(stk.BuildingBlock('C') for i in range(10)))
    for i, mol in enumerate(pop):
        mol.fitness = i
    return pop