コード例 #1
0
ファイル: test_optimizers.py プロジェクト: fiszczyp/stk
def test_cache_use(tmp_polymer):
    opt1 = stk.NullOptimizer()
    assert not opt1._cache
    opt1.optimize(tmp_polymer)
    assert not opt1._cache

    opt2 = stk.NullOptimizer(use_cache=True)
    assert not opt2._cache
    opt2.optimize(tmp_polymer)
    assert tmp_polymer in opt2._cache
コード例 #2
0
def test_optimize(tmp_polymer_pop):
    optimizer = stk.NullOptimizer(use_cache=True)
    assert not optimizer.cache
    tmp_polymer_pop.optimize(optimizer)
    assert len(optimizer.cache) == len(tmp_polymer_pop)

    raiser = stk.RaisingOptimizer(optimizer, 1)
    with pytest.raises(stk.RaisingOptimizerError):
        tmp_polymer_pop.optimize(raiser)
コード例 #3
0
ファイル: test_populations.py プロジェクト: fiszczyp/stk
def test_optimize(tmp_population):
    optimizer = stk.NullOptimizer(use_cache=True)
    assert not optimizer._cache
    tmp_population.optimize(optimizer)
    assert len(optimizer._cache) == len(set(tmp_population))

    raiser = stk.RaisingOptimizer(optimizer, 1)
    with pytest.raises(stk.RaisingOptimizerError):
        tmp_population.optimize(raiser)
コード例 #4
0
        random_seed=random_seed,
    ),
    stk.SimilarBuildingBlock(
        aldehyde_building_blocks,
        key=lambda mol: mol.func_groups[0].fg_type.name == "aldehyde",
        duplicate_building_blocks=False,
        random_seed=random_seed,
    ),
)

# #####################################################################
# Optimizer.
# #####################################################################

# Optimizer for full-run.
failed_optimizer = stk.NullOptimizer(use_cache=True)

optimizer = stk.TryCatch(
    stk.Sequence(
        stk.MacroModelForceField(
            macromodel_path=macromodel_path,
            restricted=True,
            use_cache=True,
            timeout=10800,
        ),
        stk.MacroModelForceField(
            macromodel_path=macromodel_path,
            restricted=False,
            use_cache=True,
            timeout=10800,
        ),
コード例 #5
0
ファイル: serial.py プロジェクト: fiszczyp/stk
crosser = stk.Jumble(num_offspring_building_blocks=3)

# #####################################################################
# Mutator.
# #####################################################################

mutator = stk.RandomMutation(
    stk.RandomTopologyGraph(topology_graphs),
    stk.RandomBuildingBlock(building_blocks, lambda mol: True),
    stk.SimilarBuildingBlock(building_blocks, lambda mol: True, False))

# #####################################################################
# Optimizer.
# #####################################################################

optimizer = stk.NullOptimizer(use_cache=True)

# #####################################################################
# Fitness calculator.
# #####################################################################


def num_atoms(mol):
    return len(mol.atoms)


fitness_calculator = stk.PropertyVector(num_atoms)

# #####################################################################
# Fitness normalizer.
# #####################################################################
コード例 #6
0
ファイル: test_optimizers.py プロジェクト: fiszczyp/stk
def test_is_caching():
    caching = stk.NullOptimizer(use_cache=True)
    assert caching.is_caching()
    not_caching = stk.NullOptimizer(use_cache=False)
    assert not not_caching.is_caching()