def test_temperature_corrections(QH, E, ZPE, H, TS, TqhS, G, qhG): temp = 200 conc = GV.atmos / (GV.GAS_CONSTANT * temp) freq_cutoff, freq_scale_factor, solv, spc = 100.0, 1.0, 'none', False bbe298 = GV.calc_bbe(datapath('Al_298K.out'), QH, freq_cutoff, temp, conc, freq_scale_factor, solv, spc) bbe400 = GV.calc_bbe(datapath('Al_400K.out'), QH, freq_cutoff, temp, conc, freq_scale_factor, solv, spc) precision = 6 assert E == round(bbe298.scf_energy, precision) == round(bbe400.scf_energy, precision) assert ZPE == round(bbe298.zpe, precision) == round(bbe400.zpe, precision) assert H == round(bbe298.enthalpy, precision) == round(bbe400.enthalpy, precision) assert TS == round(temp * bbe298.entropy, precision) == round(temp * bbe400.entropy, precision) assert TqhS == round(temp * bbe298.qh_entropy, precision) == round(temp * bbe400.qh_entropy, precision) assert G == round(bbe298.gibbs_free_energy, precision) == round(bbe400.gibbs_free_energy, precision) assert qhG == round(bbe298.qh_gibbs_free_energy, precision) == round(bbe400.qh_gibbs_free_energy, precision)
def rotamers(individual, path, position, seed): individual.genes['Molecule'] = Molecule(parent=individual, path=datapath(path)) individual.genes['Rotamers'] = rotamers = Rotamers(parent=individual, with_original=True, residues=[('Molecule', position)]) individual.__ready__() individual.__expression_hooks__() rotamers.allele = [seed] return rotamers
def test_nwchem(individual, ligand, energy): individual.genes['Ligand'] = Molecule(parent=individual, path=datapath(ligand)) individual.__ready__() individual.__expression_hooks__() objective = NWChem(targets=['Ligand'], title='test', weight=-1.0) with expressed(individual): assert abs(energy - objective.evaluate(individual)) < 0.0001
def nma_gene(individual, path, **kwargs): individual.genes['Molecule'] = Molecule(parent=individual, path=datapath(path)) individual.genes['NMA'] = nma = NormalModes.with_validation( parent=individual, precision=3, **kwargs) individual.__ready__() individual.__expression_hooks__() return nma
def energy(individual, path): individual.genes['Molecule'] = Molecule(parent=individual, path=datapath(path)) individual.__ready__() individual.__expression_hooks__() objective = Energy() with expressed(individual): return objective.evaluate(individual)
def search_gene(individual, path, **kwargs): individual.genes['Molecule'] = Molecule(parent=individual, path=datapath(path)) individual.genes['Search'] = search = Search.with_validation( parent=individual, precision=3, **kwargs) individual.__ready__() individual.__expression_hooks__() return search
def test_scaling_factor_search(filename, freq_scale_factor, zpe): temp = 298.15 conc = GV.atmos / (GV.GAS_CONSTANT * temp) QH, freq_cutoff, solv, spc = 'grimme', 100.0, 'none', False precision = 6 bbe = GV.calc_bbe(datapath('ethane.out'), QH, freq_cutoff, temp, conc, freq_scale_factor, solv, spc) assert zpe == round(bbe.zpe, precision)
def test_molecule(individual, individual2, path1, path2, threshold): absolute_path1 = os.path.abspath(datapath(path1)) absolute_path2 = os.path.abspath(datapath(path2)) individual.genes['Molecule'] = Molecule(parent=individual, path=absolute_path1) individual.__ready__() individual.__expression_hooks__() individual2.genes['Molecule'] = Molecule(parent=individual2, path=absolute_path2) individual2.__ready__() individual2.__expression_hooks__() with expressed(individual, individual2): sqrmsd = _rmsd_squared( individual.genes['Molecule']._expressed_coordinates, individual2.genes['Molecule']._expressed_coordinates) assert abs(sqrmsd - threshold * threshold) < 0.01 assert rmsd(individual, individual2, ['Molecule'], threshold)
def test_molecule(individual, path, atoms): absolute_path = os.path.abspath(datapath(path)) individual.genes['Molecule'] = Molecule(parent=individual, path=absolute_path) individual.__ready__() individual.__expression_hooks__() assert individual.genes['Molecule'].compound.mol.numAtoms == atoms assert individual.genes['Molecule'].compound.mol.openedAs[0] == absolute_path with expressed(individual): assert individual.expressed is True
def dsx(individual, protein, ligand, **kwargs): individual.genes['Protein'] = Molecule(parent=individual, path=datapath(protein)) individual.genes['Ligand'] = Molecule(parent=individual, path=datapath(ligand)) individual.__ready__() individual.__expression_hooks__() options = dict(weight=-1.0, terms=[True, False, False, True, False], proteins=['Protein'], ligands=['Ligand'], sorting=1, cofactor_mode=0, with_metals=False) options.update(kwargs) objective = DSX(**options) with expressed(individual): return objective.evaluate(individual)
def test_scaling_factor_search(filename, freq_scale_factor, zpe): temp = 298.15 conc = GV.ATMOS / (GV.GAS_CONSTANT * temp) QS, QH, s_freq_cutoff, h_freq_cutoff, solv, spc, invert = 'grimme', True, 100.0, 100.0, 'none', False, False precision = 6 bbe = GV.calc_bbe(datapath('ethane.out'), QS, QH, s_freq_cutoff, h_freq_cutoff, temp, conc, freq_scale_factor, solv, spc, invert) assert zpe == round(bbe.zpe, precision)
def interactions(individual, path, which): individual.genes['Molecule'] = Molecule(parent=individual, path=datapath(path)) individual.__ready__() individual.__expression_hooks__() kwargs = dict(probes=['Molecule'], radius=10 * random(), which=which) objective = Contacts(**kwargs) with expressed(individual): return objective.evaluate(individual)
def torsions(individual, path, angle, **kwargs): individual.genes['Molecule'] = Molecule(parent=individual, path=datapath(path)) individual.genes['Torsion'] = torsion = Torsion(parent=individual, target='Molecule', **kwargs) individual.__ready__() individual.__expression_hooks__() torsion.allele = [angle] * torsion.max_bonds return torsion
def test_temperature_corrections(QH, E, ZPE, H, TS, TqhS, G, qhG): temp = 200 conc = GV.atmos / (GV.GAS_CONSTANT * temp) freq_cutoff, freq_scale_factor, solv, spc = 100.0, 1.0, 'none', False bbe298 = GV.calc_bbe(datapath('Al_298K.out'), QH, freq_cutoff, temp, conc, freq_scale_factor, solv, spc) bbe400 = GV.calc_bbe(datapath('Al_400K.out'), QH, freq_cutoff, temp, conc, freq_scale_factor, solv, spc) precision = 6 assert E == round(bbe298.scf_energy, precision) == round( bbe400.scf_energy, precision) assert ZPE == round(bbe298.zpe, precision) == round(bbe400.zpe, precision) assert H == round(bbe298.enthalpy, precision) == round( bbe400.enthalpy, precision) assert TS == round(temp * bbe298.entropy, precision) == round( temp * bbe400.entropy, precision) assert TqhS == round(temp * bbe298.qh_entropy, precision) == round( temp * bbe400.qh_entropy, precision) assert G == round(bbe298.gibbs_free_energy, precision) == round( bbe400.gibbs_free_energy, precision) assert qhG == round(bbe298.qh_gibbs_free_energy, precision) == round( bbe400.qh_gibbs_free_energy, precision)
def test_coordination_uncorrected(individual, path, metal, ligands, geometry, score): individual.genes['Molecule'] = Molecule(parent=individual, path=datapath(path)) individual.__ready__() individual.__expression_hooks__() objective = Coordination(probe=('Molecule', metal), residues=[('Molecule', '*')], atom_elements=('C N O S'.split()), geometry=geometry, weight=-1.0) with expressed(individual): sphere = objective.coordination_sphere(individual)[:objective.n_vertices] assert len(sphere) == len(ligands) assert sorted(ligands) == sorted([a.serialNumber for (d, a) in sphere]) fitness = objective.evaluate(individual) assert abs(fitness - score) < 0.0001
def test_topology(individual, path, atoms, bonds, residues): individual.genes['Molecule'] = Molecule(parent=individual, path=datapath(path)) individual.__ready__() individual.__expression_hooks__() objective = Energy() with expressed(individual): molecules = objective.molecules(individual) topology = objective.chimera_molecule_to_openmm_topology(*molecules) assert topology.getNumAtoms() == sum(m.numAtoms for m in molecules) assert len(list(topology.bonds())) == sum(m.numBonds for m in molecules) assert topology.getNumResidues() == sum(m.numResidues for m in molecules)
def test_all(path, QH, temp, E, ZPE, H, TS, TqhS, G, qhG): # Defaults, no temp interval, no conc interval path = datapath(path) conc = GV.atmos / (GV.GAS_CONSTANT * temp) freq_cutoff, freq_scale_factor, solv, spc = 100.0, 1.0, 'none', False bbe = GV.calc_bbe(path, QH, freq_cutoff, temp, conc, freq_scale_factor, solv, spc) precision = 6 # if temp == 298.15 else 4e-4 assert E == round(bbe.scf_energy, precision) if hasattr(bbe, "gibbs_free_energy"): assert ZPE == round(bbe.zpe, precision) assert H == round(bbe.enthalpy, precision) assert TS == round(temp * bbe.entropy, precision) assert TqhS == round(temp * bbe.qh_entropy, precision) assert G == round(bbe.gibbs_free_energy, precision) assert qhG == round(bbe.qh_gibbs_free_energy, precision)
def test_single_point_correction(spc, E_spc, E, ZPE, H, TS, TqhS, GT, qhGT): temp = 298.15 conc = GV.atmos / (GV.GAS_CONSTANT * temp) QH, freq_cutoff, freq_scale_factor, solv = 'grimme', 100.0, 1.0, 'none' precision = 6 bbe = GV.calc_bbe(datapath('ethane.out'), QH, freq_cutoff, temp, conc, freq_scale_factor, solv, spc) if E_spc: assert E_spc == round(bbe.sp_energy, precision) assert E == round(bbe.scf_energy, precision) assert ZPE == round(bbe.zpe, precision) assert H == round(bbe.enthalpy, precision) assert TS == round(temp * bbe.entropy, precision) assert TqhS == round(temp * bbe.qh_entropy, precision) assert GT == round(bbe.gibbs_free_energy, precision) assert qhGT == round(bbe.qh_gibbs_free_energy, precision)
def test_concentration_correction(path, conc, QS, E, ZPE, H, TS, TqhS, G, qhG): path = datapath(path) QH, s_freq_cutoff, h_freq_cutoff, freq_scale_factor, temp, solv, spc, invert = False, 100.0, 100.0, 1.0, 298.15, 'none', False, False if conc == False: conc = GV.ATMOS / (GV.GAS_CONSTANT * temp) bbe = GV.calc_bbe(path, QS, QH, s_freq_cutoff, h_freq_cutoff, temp, conc, freq_scale_factor, solv, spc, invert) precision = 6 assert E == round(bbe.scf_energy, precision) if hasattr(bbe, "gibbs_free_energy"): assert ZPE == round(bbe.zpe, precision) assert H == round(bbe.enthalpy, precision) assert TS == round(temp * bbe.entropy, precision) assert TqhS == round(temp * bbe.qh_entropy, precision) assert G == round(bbe.gibbs_free_energy, precision) assert qhG == round(bbe.qh_gibbs_free_energy, precision)
def test_QS(path, QS, temp, E, ZPE, H, TS, TqhS, G, qhG): # Defaults, no temp interval, no conc interval path = datapath(path) conc = GV.ATMOS / (GV.GAS_CONSTANT * temp) QH, s_freq_cutoff, h_freq_cutoff, freq_scale_factor, solv, spc, invert = False, 100.0, 100.0, 1.0, 'none', False, False bbe = GV.calc_bbe(path, QS, QH, s_freq_cutoff, h_freq_cutoff, temp, conc, freq_scale_factor, solv, spc, invert) precision = 6 # if temp == 298.15 else 4e-4 assert E == round(bbe.scf_energy, precision) if hasattr(bbe, "gibbs_free_energy"): assert ZPE == round(bbe.zpe, precision) assert H == round(bbe.enthalpy, precision) assert TS == round(temp * bbe.entropy, precision) assert TqhS == round(temp * bbe.qh_entropy, precision) assert G == round(bbe.gibbs_free_energy, precision) assert qhG == round(bbe.qh_gibbs_free_energy, precision)
def test_temperature_interval(path, ti, H, TS, TqhS, GT, qhGT): QS, QH, s_freq_cutoff, h_freq_cutoff, freq_scale_factor, solv, spc, invert, d3 = 'grimme', False, 100.0, 100.0, 1.0, 'none', False, False, 0 precision = 6 temperature_interval = [float(temp) for temp in ti.split(',')] interval = range(int(temperature_interval[0]), int(temperature_interval[1] + 1), int(temperature_interval[2])) for i in range(len(interval)): temp = float(interval[i]) conc = GV.ATMOS / (GV.GAS_CONSTANT * temp) bbe = GV.calc_bbe(datapath(path), QS, QH, s_freq_cutoff, h_freq_cutoff, temp, conc, freq_scale_factor, solv, spc, invert, d3) assert H[i] == round(bbe.enthalpy, precision) assert TS[i] == round(temp * bbe.entropy, precision) assert TqhS[i] == round(temp * bbe.qh_entropy, precision) assert GT[i] == round(bbe.gibbs_free_energy, precision) assert qhGT[i] == round(bbe.qh_gibbs_free_energy, precision)
#!/usr/bin/env python # -*- coding: utf-8 -*- # Imports import chimera import gaudi.parse from pgaudi import similarity, treatment from conftest import datapath # Definitions cfg = gaudi.parse.Settings(datapath("input.yaml")) population = treatment.parse_zip(datapath("example_output/input2")) def test_rmsd_equal(): assert similarity.rmsd( population[0], population[0], *cfg.similarity.args, **cfg.similarity.kwargs ) def test_rmsd_dif(): assert not similarity.rmsd( population[0], population[1], *cfg.similarity.args, **cfg.similarity.kwargs ) def test_rmsd_squared(): coord1 = chimera.openModels.open(population[0]["Metal"])[ 0 ].activeCoordSet.xyzArray() coord2 = chimera.openModels.open(population[1]["Metal"])[
def test_parse_zip(): population = treatment.parse_zip(datapath("example_output/input0")) assert isinstance(population, list) assert len(population) != 0
def test_pes(E, ZPE, H, TS, TqhS, GT, qhGT): temp = 298.15 conc = GV.ATMOS / (GV.GAS_CONSTANT * temp) QS, QH, s_freq_cutoff, h_freq_cutoff, freq_scale_factor, solv, invert = 'grimme', False, 100.0, 100.0, 1.0, 'none', False invert, spc, gconf = False, False, True precision = 6 files = [ 'pes/Int-III_Oax_cis_a.log', 'pes/Int-II_Oax_cis_a.log', 'pes/Int-I_Oax.log', 'pes/TolS.log', 'pes/TolSH.log' ] files = [datapath(file) for file in files] log = GV.Logger("GoodVibes", 'test', False) bbe_vals = [] for file in files: # loop over all specified output files and compute thermochemistry bbe = GV.calc_bbe(file, QS, QH, s_freq_cutoff, h_freq_cutoff, temp, conc, freq_scale_factor, solv, spc, invert) bbe_vals.append(bbe) fileList = [file for file in files] thermo_data = dict(zip( fileList, bbe_vals)) # the collected thermochemical data for all files pes = GV.get_pes(datapath('pes/Cis_complete_pathway.yaml'), thermo_data, log, temp, gconf, QH) zero_vals = [ pes.e_zero[0][0], pes.zpe_zero[0][0], pes.h_zero[0][0], temp * pes.ts_zero[0][0], temp * pes.qhts_zero[0][0], pes.g_zero[0][0], pes.qhg_zero[0][0] ] for i, path in enumerate(pes.path): for j, e_abs in enumerate(pes.e_abs[i]): species = [ pes.e_abs[i][j], pes.zpe_abs[i][j], pes.h_abs[i][j], temp * pes.s_abs[i][j], temp * pes.qs_abs[i][j], pes.g_abs[i][j], pes.qhg_abs[i][j] ] relative = [ species[x] - zero_vals[x] for x in range(len(zero_vals)) ] formatted_list = [GV.KCAL_TO_AU * x for x in relative] assert E[j] == round(formatted_list[0], precision) assert ZPE[j] == round(formatted_list[1], precision) assert H[j] == round(formatted_list[2], precision) assert TS[j] == round(formatted_list[3], precision) assert TqhS[j] == round(formatted_list[4], precision) assert GT[j] == round(formatted_list[5], precision) assert qhGT[j] == round(formatted_list[6], precision) log.Finalize() # @pytest.mark.parametrize("yaml, gconf, E, ZPE, H, TS, TqhS, GT, qhGT", [ # #test cat conformers # ('gconf_ee_boltz/gconf_TS.yaml', True, [0.0,5.053763],[0.0,-0.497994],[0.0,3.936414],[0.0,-14.426341],[0.0,-15.107289],[0.0,18.362755],[0.0,19.043703]), # ('gconf_ee_boltz/gconf_TS.yaml', False, [0.0,5.053763],[0.0,-0.497994],[0.0,3.936414],[0.0,-14.823888],[0.0,-15.504836],[0.0,18.760302],[0.0,19.44125]), # #test TS conformers # ('gconf_ee_boltz/gconf_aminox_cat.yaml', True, [0.0,4.716292],[0.0,-0.460919],[0.0,3.534549],[0.0,-15.852617],[0.0,-16.367881],[0.0,19.387166],[0.0,19.90243]), # ('gconf_ee_boltz/gconf_aminox_cat.yaml', False, [0.0,4.716292],[0.0,-0.460919],[0.0,3.534549],[0.0,-15.245404],[0.0,-15.760668],[0.0,18.779954],[0.0,19.295218]) # # ]) # def test_gconf(yaml, gconf, E, ZPE, H, TS, TqhS, GT, qhGT): # temp = 298.15 # conc = GV.ATMOS / (GV.GAS_CONSTANT * temp) # QS, QH, s_freq_cutoff, h_freq_cutoff, freq_scale_factor, solv, invert = 'grimme', False, 100.0, 100.0, 1.0, 'none', False # invert, spc = False, False # files = ['gconf_ee_boltz/Aminoxylation_TS1_R.log', 'gconf_ee_boltz/Aminoxylation_TS2_S.log', 'gconf_ee_boltz/aminox_cat_conf212_S.log', 'gconf_ee_boltz/aminox_cat_conf280_R.log', 'gconf_ee_boltz/aminox_cat_conf65_S.log','gconf_ee_boltz/aminox_subs_conf713.log'] # files = [datapath(file) for file in files] # log = GV.Logger("GoodVibes",'test',False) # yaml = datapath(yaml) # # bbe_vals = [] # for file in files: # loop over all specified output files and compute thermochemistry # bbe = GV.calc_bbe(file, QS, QH, s_freq_cutoff, h_freq_cutoff, temp, # conc, freq_scale_factor, solv, spc, invert) # bbe_vals.append(bbe) # fileList = [file for file in files] # thermo_data = dict(zip(fileList, bbe_vals)) # the collected thermochemical data for all files # # pes = GV.get_pes(yaml,thermo_data,log,temp,gconf,QH) # # zero_vals = [pes.e_zero[0][0], pes.zpe_zero[0][0], pes.h_zero[0][0], temp * pes.ts_zero[0][0], temp * pes.qhts_zero[0][0], pes.g_zero[0][0], pes.qhg_zero[0][0]] # # for i, path in enumerate(pes.path): # for j, e_abs in enumerate(pes.e_abs[i]): # species = [pes.e_abs[i][j], pes.zpe_abs[i][j], pes.h_abs[i][j], temp * pes.s_abs[i][j], temp * pes.qs_abs[i][j], pes.g_abs[i][j], pes.qhg_abs[i][j]] # relative = [species[x]-zero_vals[x] for x in range(len(zero_vals))] # formatted_list = [GV.KCAL_TO_AU * x for x in relative] # assert '{:13.2f}'.format(E[j]) == '{:13.2f}'.format(formatted_list[0]) # assert '{:13.2f}'.format(ZPE[j]) == '{:13.2f}'.format(formatted_list[1]) # assert '{:13.2f}'.format(H[j]) == '{:13.2f}'.format(formatted_list[2]) # assert '{:13.2f}'.format(TS[j]) == '{:13.2f}'.format(formatted_list[3]) # assert '{:13.2f}'.format(TqhS[j]) == '{:13.2f}'.format(formatted_list[4]) # assert '{:13.2f}'.format(GT[j]) == '{:13.2f}'.format(formatted_list[5]) # assert '{:13.2f}'.format(qhGT[j]) == '{:13.2f}'.format(formatted_list[6]) # log.Finalize()
def test_run(): main.run(datapath("input.yaml"), 4, False)
#!/usr/bin/env python # -*- coding: utf-8 -*- # Imports import gaudi.parse import subprocess import itertools import os from conftest import datapath from pgaudi import parallel, treatment # Definitions yaml = datapath("input.yaml") cfg = gaudi.parse.Settings(yaml) population_1 = treatment.parse_zip(datapath("example_output/input2")) population_2 = treatment.parse_zip(datapath("example_output/input3")) pair_list = [population_1, population_2] def test_divide_cfg(): pcfg_names, pcfgs = parallel.divide_cfg(cfg, 4, False) assert isinstance(pcfg_names, list) assert isinstance(pcfgs, list) assert len(pcfg_names) != 0 assert len(pcfgs) != 0 for name in pcfg_names: assert os.path.isfile(name) os.remove(name) def test_gaudi_parallel():
def test_script(): out = check_output(['pychimera', datapath('helloworld.py')], universal_newlines=True) assert out == 'Hello world! \n'
#!/usr/bin/env python # -*- coding: utf-8 -*- # Imports import os import filecmp import chimera import gaudi.parse from pgaudi import create_output, parallel, treatment from conftest import datapath # Definitions cfg = gaudi.parse.Settings(datapath("input.yaml")) infiles = map( datapath, [ "example_output/input_0.yaml", "example_output/input_1.yaml", "example_output/input_2.yaml", "example_output/input_3.yaml", ], ) pcfgs = [gaudi.parse.Settings(infile) for infile in infiles] subpop = [treatment.parse_zip(pcfg.output.path) for pcfg in pcfgs] population = subpop[0] + subpop[1] + subpop[2] + subpop[3] def test_merge_log(): create_output.merge_log(pcfgs, cfg) gaudi_log = os.path.join(cfg.output.path, cfg.output.name + ".gaudi-log") assert os.path.isfile(gaudi_log)
def test_merge_log(): create_output.merge_log(pcfgs, cfg) gaudi_log = os.path.join(cfg.output.path, cfg.output.name + ".gaudi-log") assert os.path.isfile(gaudi_log) assert filecmp.cmp(gaudi_log, datapath("example_output/original.gaudi-log"))
def test_qmmm_energy(path, value): p = ESIgenReport(datapath(path)) assert p.data_as_dict()['scfenergies'][-1] == value