Ejemplo n.º 1
0
def test_restricted_md(tmp_four_plus_six, macromodel_path):

    mm_energy = stk.MacroModelEnergy(macromodel_path, force_field=16)
    init_energy = mm_energy.get_energy(tmp_four_plus_six)
    tmp_four_plus_six.write(join(test_dir, 'rmm_md_before.mol'))

    # Freeze one of the bonders.
    bonder = tmp_four_plus_six.func_groups[0].bonders[0].id
    rdkit_mol = tmp_four_plus_six.to_rdkit_mol()
    restricted_bonds = []
    for neighbor in rdkit_mol.GetAtomWithIdx(bonder).GetNeighbors():
        restricted_bonds.append(frozenset((bonder, neighbor.GetIdx())))

    mm = stk.MacroModelMD(macromodel_path=macromodel_path,
                          output_dir='rmm_md',
                          minimum_gradient=1,
                          simulation_time=20,
                          eq_time=2,
                          conformers=2,
                          time_step=0.1,
                          force_field=16,
                          restricted_bonds=restricted_bonds)
    mm.optimize(tmp_four_plus_six)
    tmp_four_plus_six.write(join(test_dir, 'rmm_md_after.mol'))

    assert mm_energy.get_energy(tmp_four_plus_six) < init_energy
Ejemplo n.º 2
0
def FF_optimize_cage(name, cage, settings, output_dir, macromodel_path):
    """
    Optimize cage with stk.

    """

    ff = stk.MacroModelForceField(macromodel_path=macromodel_path,
                                  output_dir=join(output_dir, f'{name}_FFout'),
                                  restricted=True)
    # MD process - run MD, collect N conformers, optimize each,
    # return lowest energy conformer.
    md = stk.MacroModelMD(macromodel_path=macromodel_path,
                          output_dir=join(output_dir, f'{name}_MDout'),
                          timeout=settings['timeout'],
                          force_field=settings['force_field'],
                          temperature=settings['temperature'],
                          conformers=settings['conformers'],
                          time_step=settings['time_step'],
                          eq_time=settings['eq_time'],
                          simulation_time=settings['simulation_time'],
                          maximum_iterations=settings['maximum_iterations'],
                          minimum_gradient=settings['minimum_gradient'],
                          use_cache=settings['use_cache'])
    seq = stk.Sequence(ff, md)
    seq.optimize(mol=cage)
    return cage
Ejemplo n.º 3
0
def test_md_com_exceptions(amine2):
    with pytest.raises(stk.MacroModelInputError):
        mm = stk.MacroModelMD(macromodel_path='dummy_path', conformers=10000)

    with pytest.raises(stk.MacroModelInputError):
        mm = stk.MacroModelMD(macromodel_path='dummy_path',
                              simulation_time=1000000)

    with pytest.raises(stk.MacroModelInputError):
        mm = stk.MacroModelMD(macromodel_path='dummy_path', time_step=100000)

    with pytest.raises(stk.MacroModelInputError):
        mm = stk.MacroModelMD(macromodel_path='dummy_path', eq_time=1000000)

    with pytest.raises(stk.MacroModelInputError):
        mm = stk.MacroModelMD(macromodel_path='dummy_path',
                              maximum_iterations=1000000)

    with pytest.raises(stk.MacroModelInputError):
        mm = stk.MacroModelMD(macromodel_path='dummy_path',
                              minimum_gradient=0.00001)

    mm = stk.MacroModelMD(macromodel_path='dummy_path',
                          simulation_time=100000,
                          eq_time=100000)

    mm._generate_com(amine2, join(test_dir, 'com_test'))
    with open(join(test_dir, 'com_test.com'), 'r') as o:
        comfile = o.read().splitlines()
        expect1 = (' MDYN       0      0      0      0     1.0000 -10'
                   '00.0000   300.0000     0.0000')
        expect2 = (' MDYN       1      0      0      0     1.0000 -10'
                   '00.0000   300.0000     0.0000')
        assert comfile[5] == expect1
        assert comfile[7] == expect2
Ejemplo n.º 4
0
def test_unrestricted_md(tmp_cc3, macromodel_path):
    tmp_cc3.write(join(outdir, 'umm_md_before.mol'), conformer=0)

    mm = stk.MacroModelMD(macromodel_path=macromodel_path,
                          output_dir='umm_md',
                          minimum_gradient=1,
                          simulation_time=20,
                          eq_time=2,
                          conformers=2)
    mm.optimize(tmp_cc3, conformer=0)
    tmp_cc3.write(join(outdir, 'umm_md_after.mol'), conformer=0)
Ejemplo n.º 5
0
def test_unrestricted_md(tmp_four_plus_six, macromodel_path):

    mm_energy = stk.MacroModelEnergy(macromodel_path, force_field=16)
    init_energy = mm_energy.get_energy(tmp_four_plus_six)
    tmp_four_plus_six.write(join(test_dir, 'umm_md_before.mol'))

    mm = stk.MacroModelMD(macromodel_path=macromodel_path,
                          output_dir='umm_md',
                          minimum_gradient=1,
                          simulation_time=20,
                          eq_time=2,
                          conformers=2,
                          time_step=0.1,
                          force_field=16)
    mm.optimize(tmp_four_plus_six)
    tmp_four_plus_six.write(join(test_dir, 'umm_md_after.mol'))

    assert mm_energy.get_energy(tmp_four_plus_six) < init_energy
Ejemplo n.º 6
0
def test_restricted_md(tmp_cc3, macromodel_path):
    tmp_cc3.write(join(outdir, 'rmm_md_before.mol'), conformer=0)

    # Freeze one of the bonders.
    bonder = tmp_cc3.func_groups[0].bonder_ids[0]
    restricted_bonds = []
    for neighbor in tmp_cc3.mol.GetAtomWithIdx(bonder).GetNeighbors():
        restricted_bonds.append(frozenset((bonder, neighbor.GetIdx())))

    mm = stk.MacroModelMD(macromodel_path=macromodel_path,
                          output_dir='rmm_md',
                          minimum_gradient=1,
                          simulation_time=20,
                          eq_time=2,
                          conformers=2,
                          time_step=0.1,
                          restricted_bonds=restricted_bonds)
    mm.optimize(tmp_cc3, conformer=0)
    tmp_cc3.write(join(outdir, 'rmm_md_after.mol'), conformer=0)
Ejemplo n.º 7
0
            macromodel_path=macromodel_path,
            restricted=True,
            use_cache=True,
            timeout=10800,
        ),
        stk.MacroModelForceField(
            macromodel_path=macromodel_path,
            restricted=False,
            use_cache=True,
            timeout=10800,
        ),
        stk.TryCatch(
            stk.MacroModelMD(
                macromodel_path=macromodel_path,
                temperature=700,
                eq_time=100,
                use_cache=True,
                timeout=10800,
            ),
            stk.NullOptimizer(use_cache=True, ),
        ),
    ),
    failed_optimizer,
    use_cache=True,
)

# #####################################################################
# Fitness Attributes to Dump.
# #####################################################################

dump_attrs = [
Ejemplo n.º 8
0
def poly(file_1, func_1, file_2, func_2, units):

    # turn off cache
    stk.OPTIONS['cache'] = False

    # make polymer
    name_base =  '_diol_difluorene_poly'
    name_1 = file_1.replace('.mol', '')
    name_2 = file_2.replace('.mol', '')

    global NAME
    NAME = name_1+'_'+name_2+name_base

    unit_1 = stk.StructUnit2(file_1, func_1)
    unit_2 = stk.StructUnit2(file_2, func_2)
    polymer = stk.Polymer([unit_1, unit_2], stk.Linear('AB', [0, 0], n=units, ends='h'))
    print(f'Creating polymer: {NAME}')
    polymer.write(NAME+'.mol')
    mol_polymer = Chem.MolFromMolFile(NAME + '.mol')
    
    # optimization
    print(f'Optimizing {NAME}')
    macromodel_dir = 'pathMacroModel/'
    rff = stk.MacroModelForceField(
    macromodel_path=macromodel_dir,
    restricted=True
    )

    uff = stk.MacroModelForceField(
    macromodel_path=macromodel_dir,
    restricted=False
    )

    md = stk.MacroModelMD(
    macromodel_path=macromodel_dir,
    temperature=700,
    simulation_time=2000,
    time_step=1,
    eq_time=100
    )
    
    macromodel = stk.OptimizerSequence(rff, uff, md)
    macromodel.optimize(polymer)
    print (f'Optimization completed: {NAME}')
    
    # save files
    # make different directories
    if name_base == '_anhydride_poly':
        new_dir_1 = file_dir+'Dianhydride/'
        if not os.path.exists(new_dir_1):
            os.makedirs(new_dir_1)
        else:
        	pass
        polymer.write(new_dir_1+NAME+'.mol')
        print (f'{NAME} has been saved as dianhydride.')
        return (new_dir_1+NAME+'.mol')

    else:
        new_dir_2 = file_dir+'Polybenzodioxane/'
        if not os.path.exists(new_dir_2):
            os.makedirs(new_dir_2)
        else:
        	pass
        polymer.write(new_dir_2+NAME+'.mol')
        print (f'{NAME} has been saved as polybenzodioxane.')
        return (new_dir_2+NAME+'.mol')