def test_adv_plt_2dhistogram(): # Advanced: Combine wave functions from across 5 simulations tot_cds = [] tot_dw = [] for sim_num in range(5): temp_sim = pv.SimInfo( f'pyvibdmc/sample_sim_data/tutorial_water_{sim_num}_sim_info.hdf5') # 5 independent DMC sims! cds, dw = temp_sim.get_wfns([2500, 3500]) tot_cds.append(cds) tot_dw.append(dw) tot_cds = np.concatenate(tot_cds, axis=0) tot_dw = np.concatenate(tot_dw) # Advanced: 2D Histogram analyzer = pv.AnalyzeWfn(tot_cds) # initialize analyzer object bond_len_OH1 = analyzer.bond_length(0, 2) bond_len_OH2 = analyzer.bond_length(1, 2) # bond_angle = np.rad2deg(analyzer.bond_angle(atm1=0,atm_vert=2,atm3=1)) bins_x, bins_y, amp = analyzer.projection_2d(bond_len_OH1, bond_len_OH2, desc_weights=tot_dw, bins=[15, 15], range=[[0.5, 1.5], [0.5, 1.5]], normalize=True) pv.Plotter.plt_hist2d(binsx=bins_x, binsy=bins_y, hist_2d=amp, xlabel="ROH 1 (Angstroms)", ylabel="ROH 2 (Angstroms)", save_name=f"{savefigpth}2d_histogram.png")
def test_zpe_std(): zpes = [] for sim_num in range(5): test_sim = pv.SimInfo( f'pyvibdmc/sample_sim_data/tutorial_water_{sim_num}_sim_info.hdf5') # 5 independent DMC sims! this_zpe = test_sim.get_zpe(onwards=100) zpes.append(this_zpe) final_zpe = np.average(zpes) final_std_dev = np.std(zpes)
def test_adv_plt_many_vrefs(): """Plot lots of vrefs on top of each other""" # My favorite plotting settings params = {'text.usetex': False, 'mathtext.fontset': 'dejavusans', 'font.size': 14} plt.rcParams.update(params) # Time to plot! fig, ax = plt.subplots() for sim_num in range(5): temp_sim = pv.SimInfo( f'pyvibdmc/sample_sim_data/tutorial_water_{sim_num}_sim_info.hdf5') # 5 independent DMC sims! this_vref = temp_sim.get_vref() ax.plot(this_vref[:, 0], this_vref[:, 1]) ax.set_xlabel("Time Step") ax.set_ylabel(r"Vref ($\rm{cm^{-1}}$)") fig.savefig(f"{savefigpth}ManyVrefs.png", dpi=300, bbox_inches='tight') plt.close()
def test_mass_increase_dmc(): potDir = os.path.join(os.path.dirname(__file__), '../sample_potentials/PythonPots/') pyFile = 'harmonicOscillator1D.py' potFunc = 'oh_stretch_harm' harm_pot = pv.Potential(potential_function=potFunc, python_file=pyFile, potential_directory=potDir, num_cores=2) myDMC = pv.DMC_Sim( sim_name="harm_osc_cont", output_folder=sim_ex_dir, weighting='discrete', num_walkers=5000, num_timesteps=1000, equil_steps=200, chkpt_every=100, wfn_every=500, desc_wt_steps=499, atoms=["X"], delta_t=5, potential=harm_pot, log_every=50, start_structures=np.zeros((1, 1, 1)), cur_timestep=0, # cont_wt_thresh=[0.002, 15], masses=pv.Constants.reduced_mass('O-H') * 50, DEBUG_mass_change={ 'change_every': 100, 'factor_per_change': 0.5 }) myDMC.run() sim = pv.SimInfo(f'{sim_ex_dir}/harm_osc_cont_sim_info.hdf5') pv.Plotter.plt_vref_vs_tau(sim.get_vref()) pv.Plotter.plt_pop_vs_tau(sim.get_pop()) assert True
import numpy as np import matplotlib.pyplot as plt import pytest import sys import pyvibdmc as pv test_sim = pv.SimInfo('pyvibdmc/sample_sim_data/tutorial_water_0_sim_info.hdf5') savefigpth = 'pyvibdmc/tests/' # Test writing and reading xyz coords from file def test_write_xyz_file(): cds, dws = test_sim.get_wfns([2500, 3500]) # get two wave functions just for testing atm_str_list = ["H", "H", "O"] pv.XYZNPY.write_xyz(coords=cds, fname=f'{savefigpth}water_cds.xyz', atm_strings=atm_str_list, cmt='from dmc simulation') cds_back = pv.XYZNPY.extract_xyz(f'{savefigpth}water_cds.xyz', num_atoms=len(atm_str_list)) assert np.allclose(cds, cds_back) def test_get_all_siminfo(): vref_vs_tau = test_sim.get_vref() pop_vs_tau = test_sim.get_pop() atom_nums = test_sim.get_atomic_nums() atom_masses = test_sim.get_atom_masses() # Basic SimInfoStuff def test_sim_data_zpe(): zpe = test_sim.get_zpe(onwards=100)