def test_atom_map(self): """Test get atom map""" from openeye import oechem tagged_smiles = '[H:5][C:1]#[N+:4][C:3]([H:9])([H:10])[C:2]([H:6])([H:7])[H:8]' mol_1 = openeye.smiles_to_oemol('CC[N+]#C') inf = get_fn('ethylmethylidyneamonium.mol2') ifs = oechem.oemolistream(inf) mol_2 = oechem.OEMol() oechem.OEReadMolecule(ifs, mol_2) atom_map = utils.get_atom_map(tagged_smiles, mol_1) for i, mapping in enumerate(atom_map): atom_1 = mol_1.GetAtom(oechem.OEHasAtomIdx(atom_map[mapping])) atom_1.SetAtomicNum(i+1) atom_2 = mol_2.GetAtom(oechem.OEHasAtomIdx(mapping-1)) atom_2.SetAtomicNum(i+1) self.assertEqual(oechem.OECreateCanSmiString(mol_1), oechem.OECreateCanSmiString(mol_2)) # Test aromatic molecule tagged_smiles = '[H:10][c:4]1[c:3]([c:2]([c:1]([c:6]([c:5]1[H:11])[H:12])[C:7]([H:13])([H:14])[H:15])[H:8])[H:9]' mol_1 = openeye.smiles_to_oemol('Cc1ccccc1') inf = get_fn('toluene.mol2') ifs = oechem.oemolistream(inf) mol_2 = oechem.OEMol() oechem.OEReadMolecule(ifs, mol_2) atom_map = utils.get_atom_map(tagged_smiles, mol_1) for i, mapping in enumerate(atom_map): atom_1 = mol_1.GetAtom(oechem.OEHasAtomIdx(atom_map[mapping])) atom_1.SetAtomicNum(i+1) atom_2 = mol_2.GetAtom(oechem.OEHasAtomIdx(mapping-1)) atom_2.SetAtomicNum(i+1) self.assertEqual(oechem.OECreateCanSmiString(mol_1), oechem.OECreateCanSmiString(mol_2))
def test_generat_torsions(self): """ Tests finding torsion to drive """ from openeye import oechem infile = get_fn('butane.pdb') ifs = oechem.oemolistream(infile) inp_mol = oechem.OEMol() oechem.OEReadMolecule(ifs, inp_mol) outfile_path = tempfile.mkdtemp()[1] qmscan.generate_torsions(inp_mol=inp_mol, output_path=outfile_path, interval=30, tar=False) input_files = [] pattern = '*.pdb' for path, subdir, files in os.walk(outfile_path): for name in files: if fnmatch(name, pattern): input_files.append(os.path.join(path, name)) contents = open(input_files[0]).read() pdb = get_fn('butane_10_7_4_3_0.pdb') compare_contents = open(pdb).read() self.assertEqual(contents, compare_contents) shutil.rmtree(outfile_path)
def test_extract_geom_opt(): """Tests extraction of optimized geometry""" 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()
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_param_from_db(self): """ Tests parameterizing from database """ param = CharmmParameterSet(get_fn('par_all36_cgenff.prm'), get_fn('top_all36_cgenff.rtf')) torsion = ('CG331', 'CG321', 'CG321', 'CG331') db = sqlite_plus.load(get_fn('butane.db')) par.add_missing(torsion, param, sample_n5=True) self.assertEqual(param.dihedral_types[torsion][0].phi_k, 0.03819) self.assertEqual(param.dihedral_types[torsion][1].phi_k, 0.03178) self.assertEqual(param.dihedral_types[torsion][2].phi_k, 0.0) self.assertEqual(param.dihedral_types[torsion][3].phi_k, 0.0) self.assertEqual(param.dihedral_types[torsion][4].phi_k, 0.0) self.assertEqual(param.dihedral_types[torsion][5].phi_k, 0.0) par.update_param_from_sample(param_list=torsion, param=param, db=db, rj=False, model_type='openmm') self.assertEqual(param.dihedral_types[torsion][0].phi_k, 0.086424) self.assertEqual(param.dihedral_types[torsion][1].phi_k, 0.019074) self.assertEqual(param.dihedral_types[torsion][2].phi_k, 0.0) self.assertEqual(param.dihedral_types[torsion][3].phi_k, -1.834546) self.assertEqual(param.dihedral_types[torsion][4].phi_k, -1.86807) self.assertEqual(param.dihedral_types[torsion][5].phi_k, -2.860622)
def test_set_phase_0(self): """ Test set phases to 0 """ param = CharmmParameterSet(get_fn('par_all36_cgenff.prm'), get_fn('top_all36_cgenff.rtf')) torsion = ('CG331', 'CG321', 'CG321', 'CG331') self.assertEqual(param.dihedral_types[torsion][1].phase, 180.0) par.set_phase_0(torsion, param) self.assertEqual(param.dihedral_types[torsion][1].phase, 0.0)
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_to_optimize(self): """Tests generate to_optimize list""" param = CharmmParameterSet(get_fn('top_all36_cgenff.rtf'), get_fn('par_all36_cgenff.prm')) stream = (get_fn('PRL.str')) to_optimize = qmdb.to_optimize(param, stream) self.assert_(len(to_optimize) == 19) reverse = tuple(reversed(to_optimize[0])) self.assert_(reverse not in to_optimize)
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_generate_input(self): """Test generate psi4 input files""" root = get_fn('torsion_scan/10_7_4_3') qmscan.generate_scan_input(root, 'pdb', 'butane', ['MP2'], ['aug-cc-pvtz'], symmetry='C1') contents = open(get_fn('torsion_scan/10_7_4_3/0/butane_10_7_4_3_0.dat')).read() compare_content = open(get_fn('butane_10_7_4_3_0.dat')).read() self.assertEqual(contents, compare_content)
def test_add_missing(self): """ Test add missing parameters """ param = CharmmParameterSet(get_fn('par_all36_cgenff.prm'), get_fn('top_all36_cgenff.rtf')) torsion = ('CG331', 'CG321', 'CG321', 'CG331') self.assertEqual(len(param.dihedral_types[torsion]), 2) par.add_missing(param=param, param_list=torsion) self.assertEqual(len(param.dihedral_types[torsion]), 5) par.add_missing(param=param, param_list=torsion, sample_n5=True) self.assertEqual(len(param.dihedral_types[torsion]), 6)
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_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_converged_structures(): """Tests that non converged coordinates in Gaussian log files are discarded""" structure = get_fn('MPR.psf') scan = qmdb.parse_gauss(get_fn('MPR.scan1.pos.log'), structure) log = Gaussian(get_fn('MPR.scan1.pos.log')) data = log.parse() assert_array_equal(data.atomcoords.shape, scan.xyz.shape) converted = convertor(data.scfenergies, "eV", "kJmol-1") - \ min(convertor(data.scfenergies[:len(data.atomcoords)], "eV", "kJmol-1")) assert_array_equal(converted[:47], scan.qm_energy)
def test_read_logfile(): """Tests the logfile parser""" structure = get_fn('PRL.psf') logfiles = [get_fn('PRL.scan2.neg.log'), get_fn('PRL.scan2.pos.log')] scan = qmdb.parse_gauss(logfiles, structure) scan1 = Gaussian(logfiles[0]) scan2 = Gaussian(logfiles[1]) data1 = scan1.parse() data2 = scan2.parse() assert_almost_equal(scan.xyz[:40]*10, data1.atomcoords, decimal=6) assert_almost_equal(scan.xyz[40:]*10, data2.atomcoords, decimal=6)
def test_read_logfile(): """Tests the logfile parser""" structure = get_fn('PRL.psf') logfiles = [get_fn('PRL.scan2.neg.log'), get_fn('PRL.scan2.pos.log')] scan = qmdb.parse_gauss(logfiles, structure) scan1 = Gaussian(logfiles[0]) scan2 = Gaussian(logfiles[1]) data1 = scan1.parse() data2 = scan2.parse() assert_almost_equal(scan.xyz[:40] * 10, data1.atomcoords, decimal=6) assert_almost_equal(scan.xyz[40:] * 10, data2.atomcoords, decimal=6)
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_generate_input(self): """Test generate psi4 input files""" root = get_fn('torsion_scan/10_7_4_3') qmscan.generate_scan_input(root, 'pdb', 'butane', ['MP2'], ['aug-cc-pvtz'], symmetry='C1') contents = open( get_fn('torsion_scan/10_7_4_3/0/butane_10_7_4_3_0.dat')).read() compare_content = open(get_fn('butane_10_7_4_3_0.dat')).read() self.assertEqual(contents, compare_content)
def test_sort_nrotors(self): """Tests sorting fragments by nrotors""" ifs = get_fn('frags.smi') out_dir = self.get_writes_dir() fragment._sort_by_rotbond(ifs, outdir=out_dir) mol = oechem.OEGraphMol() for n in range(1, 6): db = get_fn('nrotor_{}.smi'.format(n), written=True) moldb = oechem.OEMolDatabase(db) for idx in range(moldb.GetMaxMolIdx()): if moldb.GetMolecule(mol, idx): nrotor = sum([bond.IsRotor() for bond in mol.GetBonds()]) self.assertEquals(n, nrotor)
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_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_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_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_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_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_get_multiplicity_traces(self): """Tests turing multiplicity bitstring into multiplicity traces""" db = sqlite_plus.load(get_fn('butane.db')) param_list = db.get_sampled_torsions() mult = db.get_multiplicity_trace(param_list[0], n5=True) keys = ['1', '2', '3', '4', '5', '6'] self.assertEqual(set(mult.keys()), set(keys))
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_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)
def test_get_sampled_torsions(self): """ Tests get torsions sampled from db """ param_to_opt=[('CG331', 'CG321', 'CG321', 'CG331'), ('HGA3', 'CG331', 'CG321', 'HGA2'), ('HGA3', 'CG331', 'CG321', 'CG321'), ('HGA2', 'CG321', 'CG321', 'HGA2'), ('CG331', 'CG321', 'CG321', 'HGA2')] db = sqlite_plus.load(get_fn('butane.db')) param_list = db.get_sampled_torsions() self.assertEqual(set(param_list), set(param_to_opt))
def test_tagged_smiles(self): """Test index-tagges smiles""" from openeye import oechem inf = get_fn('ethylmethylidyneamonium.mol2') ifs = oechem.oemolistream(inf) inp_mol = oechem.OEMol() oechem.OEReadMolecule(ifs, inp_mol) tagged_smiles = utils.create_mapped_smiles(inp_mol) # Tags should always be the same as mol2 molecule ordering self.assertEqual(tagged_smiles, '[H:5][C:1]#[N+:4][C:3]([H:9])([H:10])[C:2]([H:6])([H:7])[H:8]')
def test_generat_torsions(self): """ Tests finding torsion to drive """ from openeye import oechem infile = get_fn('butane.pdb') ifs = oechem.oemolistream(infile) inp_mol = oechem.OEMol() oechem.OEReadMolecule(ifs, inp_mol) outfile_path = tempfile.mkdtemp()[1] qmscan.generate_torsions(inp_mol=inp_mol, output_path=outfile_path, interval=30, tar=False) input_files = [] pattern = '*.pdb' for path, subdir, files in os.walk(outfile_path): for name in files: if fnmatch(name, pattern): input_files.append(os.path.join(path, name)) contents = open(input_files[0]).read() pdb = get_fn('butane_10_7_4_3_0.pdb') compare_contents = open(pdb).read() self.assertEqual(contents, compare_contents ) shutil.rmtree(outfile_path)
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_tagged_smiles(self): """Test index-tagges smiles""" from openeye import oechem inf = get_fn('ethylmethylidyneamonium.mol2') ifs = oechem.oemolistream(inf) inp_mol = oechem.OEMol() oechem.OEReadMolecule(ifs, inp_mol) tagged_smiles = utils.create_mapped_smiles(inp_mol) # Tags should always be the same as mol2 molecule ordering self.assertEqual( tagged_smiles, '[H:5][C:1]#[N+:4][C:3]([H:9])([H:10])[C:2]([H:6])([H:7])[H:8]')
def test_atom_map(self): """Test get atom map""" from openeye import oechem tagged_smiles = '[H:5][C:1]#[N+:4][C:3]([H:9])([H:10])[C:2]([H:6])([H:7])[H:8]' mol_1 = openeye.smiles_to_oemol('CC[N+]#C') inf = get_fn('ethylmethylidyneamonium.mol2') ifs = oechem.oemolistream(inf) mol_2 = oechem.OEMol() oechem.OEReadMolecule(ifs, mol_2) atom_map = utils.get_atom_map(tagged_smiles, mol_1) for i, mapping in enumerate(atom_map): atom_1 = mol_1.GetAtom(oechem.OEHasAtomIdx(atom_map[mapping])) atom_1.SetAtomicNum(i + 1) atom_2 = mol_2.GetAtom(oechem.OEHasAtomIdx(mapping - 1)) atom_2.SetAtomicNum(i + 1) self.assertEqual(oechem.OECreateCanSmiString(mol_1), oechem.OECreateCanSmiString(mol_2)) # Test aromatic molecule tagged_smiles = '[H:10][c:4]1[c:3]([c:2]([c:1]([c:6]([c:5]1[H:11])[H:12])[C:7]([H:13])([H:14])[H:15])[H:8])[H:9]' mol_1 = openeye.smiles_to_oemol('Cc1ccccc1') inf = get_fn('toluene.mol2') ifs = oechem.oemolistream(inf) mol_2 = oechem.OEMol() oechem.OEReadMolecule(ifs, mol_2) atom_map = utils.get_atom_map(tagged_smiles, mol_1) for i, mapping in enumerate(atom_map): atom_1 = mol_1.GetAtom(oechem.OEHasAtomIdx(atom_map[mapping])) atom_1.SetAtomicNum(i + 1) atom_2 = mol_2.GetAtom(oechem.OEHasAtomIdx(mapping - 1)) atom_2.SetAtomicNum(i + 1) self.assertEqual(oechem.OECreateCanSmiString(mol_1), oechem.OECreateCanSmiString(mol_2))
def test_residual_energy(self): """ Tests that total energy is resonable. """ db = sqlite_plus.load(get_fn('butane_np.sqlite')) dih_list = [('CG331', 'CG321', 'CG321', 'CG331'), ('HGA2', 'CG321', 'CG321', 'HGA2'), ('CG331', 'CG321', 'CG321', 'HGA2')] par.add_missing(param_list=dih_list, param=param, sample_n5=True) par.update_param_from_sample(param_list=dih_list, param=param, db=db, n_5=True, rj=False, model_type='numpy') frag.compute_energy(param=param) self.assertTrue((frag.delta_energy._value > -0.5).all() and (frag.delta_energy._value < 0.5).all())
def test_mapped_xyz(self): """Test writing out mapped xyz""" from openeye import oechem, oeomega tagged_smiles = '[H:10][c:4]1[c:3]([c:2]([c:1]([c:6]([c:5]1[H:11])[H:12])[C:7]([H:13])([H:14])[H:15])[H:8])[H:9]' mol_1 = openeye.smiles_to_oemol('Cc1ccccc1') inf = get_fn('toluene.mol2') ifs = oechem.oemolistream(inf) mol_2 = oechem.OEMol() oechem.OEReadMolecule(ifs, mol_2) atom_map = utils.get_atom_map(tagged_smiles, mol_1) for i, mapping in enumerate(atom_map): atom_1 = mol_1.GetAtom(oechem.OEHasAtomIdx(atom_map[mapping])) atom_1.SetAtomicNum(i + 1) atom_2 = mol_2.GetAtom(oechem.OEHasAtomIdx(mapping - 1)) atom_2.SetAtomicNum(i + 1) xyz_1 = utils.to_mapped_xyz(mol_1, atom_map) # molecule generated from mol2 should be in the right order. atom_map_mol2 = { 1: 0, 2: 1, 3: 2, 4: 3, 5: 4, 6: 5, 7: 6, 8: 7, 9: 8, 10: 9, 11: 10, 12: 11, 13: 12, 14: 13, 15: 14 } xyz_2 = utils.to_mapped_xyz(mol_2, atom_map_mol2) for ele1, ele2 in zip(xyz_1.split('\n')[:-1], xyz_2.split('\n')[:-1]): self.assertEqual(ele1.split(' ')[2], ele2.split(' ')[2])
def test_mapped_xyz(self): """Test writing out mapped xyz""" from openeye import oechem, oeomega tagged_smiles = '[H:10][c:4]1[c:3]([c:2]([c:1]([c:6]([c:5]1[H:11])[H:12])[C:7]([H:13])([H:14])[H:15])[H:8])[H:9]' mol_1 = openeye.smiles_to_oemol('Cc1ccccc1') inf = get_fn('toluene.mol2') ifs = oechem.oemolistream(inf) mol_2 = oechem.OEMol() oechem.OEReadMolecule(ifs, mol_2) atom_map = utils.get_atom_map(tagged_smiles, mol_1) for i, mapping in enumerate(atom_map): atom_1 = mol_1.GetAtom(oechem.OEHasAtomIdx(atom_map[mapping])) atom_1.SetAtomicNum(i+1) atom_2 = mol_2.GetAtom(oechem.OEHasAtomIdx(mapping-1)) atom_2.SetAtomicNum(i+1) xyz_1 = utils.to_mapped_xyz(mol_1, atom_map) # molecule generated from mol2 should be in the right order. atom_map_mol2 = {1:0, 2:1, 3:2, 4:3, 5:4, 6:5, 7:6, 8:7, 9:8, 10:9, 11:10, 12:11, 13:12, 14:13, 15:14} xyz_2 = utils.to_mapped_xyz(mol_2, atom_map_mol2) for ele1, ele2 in zip(xyz_1.split('\n')[:-1], xyz_2.split('\n')[:-1]): self.assertEqual(ele1.split(' ')[2], ele2.split(' ')[2])
from torsionfit.backends import sqlite_plus import torsionfit.parameters as par 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_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)
def test_generate_fragments(self): """Test wrapper generate fragment function""" out_dir = self.get_writes_dir() fragment.generate_fragments(inputf=get_fn('kinase_inhibitors.smi'), output_dir=out_dir)
from torsionfit.backends import sqlite_plus import torsionfit.parameters as par 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_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):
def test_extract_geom_opt(): """Tests extraction of optimized geometry""" 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()