def test_update_param_struct_cont(self): """ Tests that update parameter updates assigned parameters in the structure """ param = CharmmParameterSet(get_fn('top_all36_cgenff.rtf'), get_fn('par_all36_cgenff.prm')) structure = get_fn('butane.psf') logfiles = get_fn('MP2_torsion_scan/') frag = qmdb.parse_psi4_out(logfiles, structure) frag = frag.remove_nonoptimized() to_optimize = [('CG331', 'CG321', 'CG321', 'CG331')] model = TorsionFitModelOMM(param=param, frags=frag, param_to_opt=to_optimize, sample_phase=True, continuous_phase=True) par.update_param_from_sample(model.parameters_to_optimize, param, model=model, rj=model.rj, phase=model.sample_phase, n_5=model.sample_n5, model_type='openmm') torsion = frag.structure.dihedrals[0] self.assertEqual( torsion.type, param.dihedral_types[(torsion.atom1.type, torsion.atom2.type, torsion.atom3.type, torsion.atom4.type)])
def test_remove_nonoptimized(self): """ Test remove non_optimized structures """ structure = get_fun('butane.psf') scan = get_fun('MP2_torsion_scan/') test_scan = qmdb.parse_psi4_out(scan, structure, pattern="*.out2") self.assertEqual(test_scan.n_frames, 14) scan_opt = test_scan.remove_nonoptimized() self.assertEqual(scan_opt.n_frames, 13)
def test_remove_nonoptimized(self): """ Test remove non_optimized structures """ structure = get_fn('butane.psf') scan = get_fn('MP2_torsion_scan/') test_scan = qmdb.parse_psi4_out(scan, structure, pattern="*.out2") self.assertEqual(test_scan.n_frames, 14) scan_opt = test_scan.remove_nonoptimized() self.assertEqual(scan_opt.n_frames, 13)
def test_create_context(self): """ Test create context """ structure = get_fun('butane.psf') scan = get_fun('MP2_torsion_scan/') test_scan = qmdb.parse_psi4_out(scan, structure) param = CharmmParameterSet(get_fun('top_all36_cgenff.rtf'), get_fun('par_all36_cgenff.prm')) test_scan.integrator = mm.VerletIntegrator(0.004*u.picoseconds) test_scan.create_context(param)
def test_copy_torsions(self): """ Test copy torsions""" structure = get_fun('butane.psf') scan = get_fun('MP2_torsion_scan/') test_scan = qmdb.parse_psi4_out(scan, structure) param = CharmmParameterSet(get_fun('top_all36_cgenff.rtf'), get_fun('par_all36_cgenff.prm')) test_scan.compute_energy(param) test_scan.copy_torsions()
def test_create_context(self): """ Test create context """ structure = get_fn('butane.psf') scan = get_fn('MP2_torsion_scan/') test_scan = qmdb.parse_psi4_out(scan, structure) param = CharmmParameterSet(get_fn('top_all36_cgenff.rtf'), get_fn('par_all36_cgenff.prm')) test_scan.integrator = mm.VerletIntegrator(0.004 * u.picoseconds) test_scan.create_context(param)
def test_copy_torsions(self): """ Test copy torsions""" structure = get_fn('butane.psf') scan = get_fn('MP2_torsion_scan/') test_scan = qmdb.parse_psi4_out(scan, structure) param = CharmmParameterSet(get_fn('top_all36_cgenff.rtf'), get_fn('par_all36_cgenff.prm')) test_scan.compute_energy(param) test_scan.copy_torsions()
def test_to_dataframe(self): """ Tests to dataframe """ structure = get_fun('butane.psf') scan = get_fun('MP2_torsion_scan/') test_scan = qmdb.parse_psi4_out(scan, structure) test_scan.to_dataframe() structure = get_fun('MPR.psf') scan = qmdb.parse_gauss([get_fun('MPR.scan1.pos.log'), get_fun('MPR.scan1.neg.log')], structure) scan.extract_geom_opt() scan.to_dataframe(psi4=False)
def test_to_dataframe(self): """ Tests to dataframe """ structure = get_fn('butane.psf') scan = get_fn('MP2_torsion_scan/') test_scan = qmdb.parse_psi4_out(scan, structure) test_scan.to_dataframe() structure = get_fn('MPR.psf') scan = qmdb.parse_gauss( [get_fn('MPR.scan1.pos.log'), get_fn('MPR.scan1.neg.log')], structure) scan.extract_geom_opt() scan.to_dataframe(psi4=False)
def test_turn_off_param(self): """ Test turning off parameters """ structure = CharmmPsfFile(get_fn('butane_charge_off.psf')) param = CharmmParameterSet(get_fn('par_all36_cgenff.prm'), get_fn('top_all36_cgenff.rtf')) par.turn_off_params(structure, param, bonds=True, angles=True, dihedral=True, urey_bradley=True, lj=True, copy=False) scan = get_fn('MP2_torsion_scan/') butane_scan = qmdb.parse_psi4_out(scan, get_fn('butane_charge_off.psf')) butane_scan.compute_energy(param) self.assertTrue((butane_scan.mm_energy.value_in_unit(unit.kilojoule_per_mole) == 0).all())
def test_compute_energy(self): """ Tests compute mm energy""" structure = get_fun('butane.psf') scan = get_fun('MP2_torsion_scan/') test_scan = qmdb.parse_psi4_out(scan, structure, pattern="*.out2") param = CharmmParameterSet(get_fun('top_all36_cgenff.rtf'), get_fun('par_all36_cgenff.prm')) self.assertFalse(test_scan._have_mm_energy) scan_opt = test_scan.remove_nonoptimized() scan_opt.compute_energy(param) self.assertTrue(scan_opt._have_mm_energy) mm_energy = np.array([22.66381775, 13.11040092, 3.04552792, 7.83767718, 15.21426107, 7.0116804 , 0. , 7.00802623, 15.21461956, 7.83696204, 3.04525798, 13.10813678, 22.66375837]) np.testing.assert_almost_equal(scan_opt.mm_energy._value, mm_energy, 4)
def test_parse_psi4_out(self): """ Tests psi4 outfile parser""" structure = get_fn('butane.psf') scan = get_fn('MP2_torsion_scan/') butane_scan = qmdb.parse_psi4_out(scan, structure, pattern="*.out2") butane_scan = butane_scan.remove_nonoptimized() self.assertEqual(butane_scan.n_atoms, 14) self.assertEqual(butane_scan.n_chains, 1) self.assertEqual(butane_scan.n_residues, 1) self.assertEqual(butane_scan.n_frames, 13) self.assertEqual(butane_scan.qm_energy.shape, (13, )) angles = np.arange(0, 370, 30) np.testing.assert_equal(butane_scan.angles, angles) torsion = np.array([3, 6, 9, 13]) np.testing.assert_equal(butane_scan.torsion_index[0], torsion)
def test_update_param_continuous(self): """ Tests that update parameter updates the reverse dihedral too in continuous """ param = CharmmParameterSet(get_fun('top_all36_cgenff.rtf'), get_fun('par_all36_cgenff.prm')) structure = get_fun('butane.psf') logfiles = get_fun('MP2_torsion_scan/') frag = qmdb.parse_psi4_out(logfiles, structure) frag = frag.remove_nonoptimized() to_optimize = [('CG331', 'CG321', 'CG321', 'CG331')] model = TorsionFitModelOMM(param=param, frags=frag, param_to_opt=to_optimize, sample_phase=True, continuous_phase=True) torsion = model.parameters_to_optimize[0] torsion_reverse = tuple(reversed(torsion)) self.assertEqual(param.dihedral_types[torsion], param.dihedral_types[torsion_reverse])
def test_parse_psi4_out(self): """ Tests psi4 outfile parser""" structure = get_fun('butane.psf') scan = get_fun('MP2_torsion_scan/') butane_scan = qmdb.parse_psi4_out(scan, structure, pattern="*.out2") butane_scan = butane_scan.remove_nonoptimized() self.assertEqual(butane_scan.n_atoms, 14) self.assertEqual(butane_scan.n_chains, 1) self.assertEqual(butane_scan.n_residues, 1) self.assertEqual(butane_scan.n_frames, 13) self.assertEqual(butane_scan.qm_energy.shape, (13,)) angles = np.arange(0, 370, 30) np.testing.assert_equal(butane_scan.angles, angles) torsion = np.array([3, 6, 9, 13]) np.testing.assert_equal(butane_scan.torsion_index[0], torsion)
def test_update_param_struct_cont(self): """ Tests that update parameter updates assigned parameters in the structure """ param = CharmmParameterSet(get_fun('top_all36_cgenff.rtf'), get_fun('par_all36_cgenff.prm')) structure = get_fun('butane.psf') logfiles = get_fun('MP2_torsion_scan/') frag = qmdb.parse_psi4_out(logfiles, structure) frag = frag.remove_nonoptimized() to_optimize = [('CG331', 'CG321', 'CG321', 'CG331')] model = TorsionFitModelOMM(param=param, frags=frag, param_to_opt=to_optimize, sample_phase=True, continuous_phase=True) par.update_param_from_sample(model.parameters_to_optimize, param, model=model, rj=model.rj, phase=model.sample_phase, n_5=model.sample_n5, model_type='openmm') torsion = frag.structure.dihedrals[0] self.assertEqual(torsion.type, param.dihedral_types[(torsion.atom1.type, torsion.atom2.type, torsion.atom3.type, torsion.atom4.type)])
def test_compute_energy(self): """ Tests compute mm energy""" structure = get_fn('butane.psf') scan = get_fn('MP2_torsion_scan/') test_scan = qmdb.parse_psi4_out(scan, structure, pattern="*.out2") param = CharmmParameterSet(get_fn('top_all36_cgenff.rtf'), get_fn('par_all36_cgenff.prm')) self.assertFalse(test_scan._have_mm_energy) scan_opt = test_scan.remove_nonoptimized() scan_opt.compute_energy(param) self.assertTrue(scan_opt._have_mm_energy) mm_energy = np.array([ 22.66381775, 13.11040092, 3.04552792, 7.83767718, 15.21426107, 7.0116804, 0., 7.00802623, 15.21461956, 7.83696204, 3.04525798, 13.10813678, 22.66375837 ]) np.testing.assert_almost_equal(scan_opt.mm_energy._value, mm_energy, 4)
def test_add_missing_cond(self): """ Tests that add_missing adds missing terms to parameters_to_optimize """ param = CharmmParameterSet(get_fun('top_all36_cgenff.rtf'), get_fun('par_all36_cgenff.prm')) structure = get_fun('butane.psf') logfiles = get_fun('MP2_torsion_scan/') frag = qmdb.parse_psi4_out(logfiles, structure) frag = frag.remove_nonoptimized() to_optimize = [('CG331', 'CG321', 'CG321', 'HGA2')] model = TorsionFitModelOMM(param=param, frags=frag, param_to_opt=to_optimize, sample_phase=True, continuous_phase=True) par.add_missing(param_list=to_optimize, param=param) for i in model.frags[0].structure.dihedrals: key = (i.atom1.type, i.atom2.type, i.atom3.type, i.atom4.type) key_reverse = tuple(reversed(key)) if key in model.parameters_to_optimize or key_reverse in model.parameters_to_optimize: self.assert_(len(i.type) == 5)
def test_update_param_continuous(self): """ Tests that update parameter updates the reverse dihedral too in continuous """ param = CharmmParameterSet(get_fn('top_all36_cgenff.rtf'), get_fn('par_all36_cgenff.prm')) structure = get_fn('butane.psf') logfiles = get_fn('MP2_torsion_scan/') frag = qmdb.parse_psi4_out(logfiles, structure) frag = frag.remove_nonoptimized() to_optimize = [('CG331', 'CG321', 'CG321', 'CG331')] model = TorsionFitModelOMM(param=param, frags=frag, param_to_opt=to_optimize, sample_phase=True, continuous_phase=True) torsion = model.parameters_to_optimize[0] torsion_reverse = tuple(reversed(torsion)) self.assertEqual(param.dihedral_types[torsion], param.dihedral_types[torsion_reverse])
def test_turn_off_param(self): """ Test turning off parameters """ structure = CharmmPsfFile(get_fn('butane_charge_off.psf')) param = CharmmParameterSet(get_fn('par_all36_cgenff.prm'), get_fn('top_all36_cgenff.rtf')) par.turn_off_params(structure, param, bonds=True, angles=True, dihedral=True, urey_bradley=True, lj=True, copy=False) scan = get_fn('MP2_torsion_scan/') butane_scan = qmdb.parse_psi4_out(scan, get_fn('butane_charge_off.psf')) butane_scan.compute_energy(param) self.assertTrue((butane_scan.mm_energy.value_in_unit( unit.kilojoule_per_mole) == 0).all())
def test_add_missing_cond(self): """ Tests that add_missing adds missing terms to parameters_to_optimize """ param = CharmmParameterSet(get_fn('top_all36_cgenff.rtf'), get_fn('par_all36_cgenff.prm')) structure = get_fn('butane.psf') logfiles = get_fn('MP2_torsion_scan/') frag = qmdb.parse_psi4_out(logfiles, structure) frag = frag.remove_nonoptimized() to_optimize = [('CG331', 'CG321', 'CG321', 'HGA2')] model = TorsionFitModelOMM(param=param, frags=frag, param_to_opt=to_optimize, sample_phase=True, continuous_phase=True) par.add_missing(param_list=to_optimize, param=param) for i in model.frags[0].structure.dihedrals: key = (i.atom1.type, i.atom2.type, i.atom3.type, i.atom4.type) key_reverse = tuple(reversed(key)) if key in model.parameters_to_optimize or key_reverse in model.parameters_to_optimize: self.assert_(len(i.type) == 5)
import pymc from parmed.charmm import CharmmParameterSet import unittest try: from simtk.openmm import app import simtk.openmm as mm HAVE_OPENMM = True except ImportError: HAVE_OPENMM = False param = CharmmParameterSet(get_fn('top_all36_cgenff.rtf'), get_fn('par_all36_cgenff.prm')) structure = get_fn('butane.psf') logfiles = get_fn('MP2_torsion_scan/') frag = qmdb.parse_psi4_out(logfiles, structure) frag = frag.remove_nonoptimized() to_optimize = [('CG331', 'CG321', 'CG321', 'CG331')] model_omm = TorsionFitModelOMM(param=param, frags=frag, param_to_opt=to_optimize, init_random=False) class TestFitModel(unittest.TestCase): """ Tests pymc model""" def test_pymc_model(self): """ Tests sampler """ sampler = MCMC(model_omm.pymc_parameters) self.assert_(isinstance(model_omm, TorsionFitModelOMM))
from pymc import MCMC import pymc from parmed.charmm import CharmmParameterSet import unittest try: from simtk.openmm import app import simtk.openmm as mm HAVE_OPENMM = True except ImportError: HAVE_OPENMM = False param = CharmmParameterSet(get_fun('top_all36_cgenff.rtf'), get_fun('par_all36_cgenff.prm')) structure = get_fun('butane.psf') logfiles = get_fun('MP2_torsion_scan/') frag = qmdb.parse_psi4_out(logfiles, structure) frag = frag.remove_nonoptimized() to_optimize = [('CG331', 'CG321', 'CG321', 'CG331')] model_omm = TorsionFitModelOMM(param=param, frags=frag, param_to_opt=to_optimize, init_random=False) class TestFitModel(unittest.TestCase): """ Tests pymc model""" def test_pymc_model(self): """ Tests sampler """ sampler = MCMC(model_omm.pymc_parameters) self.assert_(isinstance(model_omm, TorsionFitModelOMM)) self.assert_(isinstance(sampler, pymc.MCMC))
path = '../../../n5/10000/random_{}_{}/random_{}_{}.sqlite'.format( args.iterations, args.repeats, args.iterations, args.repeats) print(path) db = sqlite_plus.load(path) par.add_missing(param_list=param_to_opt, param=param, sample_n5=True) par.set_phase_0(param_list=param_to_opt, param=param) par.update_param_from_sample(param_list=param_to_opt, param=param, db=db, i=-1, rj=False, n_5=True, phase=False) print(param.dihedral_types[param_to_opt[0]]) butane_scan = ScanSet.parse_psi4_out(scan, structure) optimized = butane_scan.remove_nonoptimized() model = Model.TorsionFitModel(param=param, frags=optimized, init_random=False, param_to_opt=param_to_opt, rj=True, sample_n5=True) sampler = MCMC(model.pymc_parameters, db=sqlite_plus, dbname=args.db_name, verbose=5) sampler.sample(args.iterations)