Dice Python Frontend Documentation
dice_visualise.py
Go to the documentation of this file.
1 
9 
10 import netCDF4 as nd
11 from netCDF4 import Dataset
12 import matplotlib.pyplot as plt
13 import numpy as np
14 import scipy.signal as sps
15 import plotly.graph_objects as go
16 import plotly.figure_factory as ff
17 from plotly.subplots import make_subplots
18 import ipywidgets as widgets
19 from ipywidgets import fixed
20 
21 plt.rcParams["figure.figsize"] = 18,10
22 
23 #----------------------------------------------------
24 # Energy/Wavefunction Plotting FUNCTION DEFINITIONS -
25 #----------------------------------------------------
26 
27 def QHOProbPlot(chain_file):
28  '''
29  @brief
30  Wrapper function for QHO_prob_plot()
31 
32  @details
33  Loads in the netCDF dataset and extracts position and energy
34  arrays, passes them off to QHO_prob_plot().
35 
36  @param[in] chain_file The main netCDF output file from a Full VQMC run with write_chains=.TRUE.
37  '''
38  dat = Dataset(chain_file, 'r', format='NETCDF4')
39 
40  positions = dat.variables['positions'][:]
41  energies = dat.variables['energies'][:]
42 
43  fig = QHO_prob_plot(positions, energies)
44 
45  fig.show()
46 
47 
48 def QHO_prob_plot(positions,energies):
49  '''
50  @brief
51  Fancy Plotly plotter for QHO Markov chains
52 
53  @param[in] positions Position array from Markov chain
54  @param[in] energies Energy array from Markov chain
55  '''
56  hist = ff.create_distplot([positions], ['Position Distribution'],
57  bin_size=.2, show_rug=False)
58 
59  fig = make_subplots(specs=[[{"secondary_y": True}]])
60  fig.add_trace(go.Scatter(x=positions, y=energies, mode ='markers', name="Energy",
61  marker=dict(
62  color=energies,
63  colorscale ='Viridis',
64  line=dict(
65  width=0
66  ))))
67  fig.add_trace(go.Histogram(hist['data'][0]),secondary_y=True,)
68  fig.add_trace(go.Scatter(hist['data'][1]),secondary_y=True,)
69  fig['layout']['yaxis']['autorange'] = "reversed"
70  fig['layout']['yaxis2']['showgrid'] = False
71 
72  return fig
73 
74 
75 def HydProbPlot(chain_file, opacity=0.2):
76  '''
77  @brief
78  Wrapper function for H2_prob_plot()
79 
80  @details
81  Loads in the netCDF dataset and extracts position and energy
82  arrays, passes them off to H2_prob_plot().
83 
84  @param[in] chain_file The main netCDF output file from a Full VQMC run with write_chains=.TRUE.
85  @param[in] opacity (Optional, default=0.2) Opacity of the electron position scatter plot
86  '''
87  dat = Dataset(chain_file, 'r', format='NETCDF4')
88 
89  positions = dat.variables['positions'][:, :]
90  energies = dat.variables['energies'][:]
91  bond_length = dat.bond_length
92 
93  R1 = [-bond_length/2, 0.0, 0.0]
94  R2 = [bond_length/2, 0.0, 0.0]
95 
96  print(len(positions))
97 
98  fig = H2_prob_plot(positions, energies, R1, R2, opacity)
99 
100  fig.show()
101 
102 def H2_prob_plot(positions,energies,R1, R2, opacity):
103  """
104  @brief
105  Plots the sampled wavefunction for H2plus/H2
106 
107  @param[in] positions XYZ coordinates of Markov chain
108  @param[in] energies Energies of the Markov chains
109  @param[in] R1 The XYZ coordinates of the first atom
110  @param[in] R2 The XYZ coordinates of the second atom
111  @param[in] opacity Opacity of the electron position scatter plot
112  @retval fig Plotly figure object
113  """
114 
115  X = positions[:,0]
116  Y = positions[:,1]
117  Z = positions[:,2]
118 
119  fig = go.Figure()
120 
121  #Plots the positions of the Markov chain, with energies corresponding to a certain color
122  fig.add_trace(
123  go.Scatter3d(
124  mode='markers',
125  x=X,
126  y=Y,
127  z=Z,
128  opacity=opacity,
129  marker=dict(
130  color=energies,
131  size=3,
132  colorscale ='Viridis',
133  line=dict(
134  width=0
135  )
136  ),
137  name='Markov Chain positions'
138  )
139  )
140 
141  #Adds points to show the location of the atoms within the object
142  fig.add_trace(
143  go.Scatter3d(
144  mode='markers',
145  x=[R1[0],R2[0]],
146  y=[R1[1],R2[1]],
147  z=[R1[2],R2[2]],
148  opacity=1.0,
149  marker=dict(
150  color='#AAAAAA',
151  size=20,
152  line=dict(
153  color='Black',
154  width=2
155  )
156  ),
157  name='Atoms'
158  )
159  )
160 
161  #Resizes the layout
162  fig.update_layout(
163  autosize=False,
164  width=800,
165  height=800,
166  margin=dict(
167  l=5,
168  r=5,
169  b=5,
170  t=100,
171  pad=1
172  )
173  )
174 
175  return fig
176 
177 
178 def QHOEnergyPlot(results_file, sliceby=(None, None)):
179  '''
180  @brief
181  Energy against @f$ \alpha @f$ plotter for the QHO problem.
182 
183  @details
184  Plots the VQMC wavefunction energy at each of an array of values for the
185  variational parameter @f$ \alpha @f$, alongside error bars of the standard
186  deviation in each energy.
187 
188  @param[in] results_file The main netCDF output file from a QHO run
189  @param[in] sliceby (Optional) Tuple containing slice intervals for arrays
190  '''
191  dat = nd.Dataset(results_file, 'r', format='NETCDF4')
192 
193  alpha_array = dat.variables['Alpha_array'][sliceby[0]:sliceby[1]]
194  energies = dat.variables['total_energies'][sliceby[0]:sliceby[1]]
195  variances = dat.variables['Uncertainties'][sliceby[0]:sliceby[1]]
196 
197  stdevs = np.sqrt(variances)
198  min_energy = min(energies)
199  min_energy_stdev = stdevs[np.argmin(energies)]
200  opt_alpha = alpha_array[np.argmin(energies)]
201 
202  fig, ax1 = plt.subplots(1, 1, figsize=(8, 8))
203 
204  ax1.set_title(r'Quantum Harmonic Oscillator Energy with Varying $\alpha$')
205  ax1.plot(alpha_array, energies, marker='o', ls='--', color='blue')
206  ax1.fill_between(alpha_array, energies+stdevs, energies-stdevs, alpha=0.3, color='purple')
207  ax1.axvline(0.5, ls='-', color='black', alpha=0.3)
208  ax1.set_xlabel(r'$\alpha$')
209  ax1.set_ylabel('Energy')
210 
211  fig.show()
212 
213  print(f'Optimum alpha: {opt_alpha}')
214  print(f'Energy: {min_energy} ± {min_energy_stdev}')
215 
216 
217 def QHOWfnPlot(chain_file, show_analytic=False):
218  '''
219  @brief
220  Scatter plotter of the sampled QHO wavefunction.
221 
222  @details
223  Plots the sampled positions of a trial QHO wavefunction against the
224  energies at those positions, to illustrate the shape of that wavefunction.
225  Chain output requires the @em write_chains parameter to be @em TRUE.
226 
227  @param[in] chain_file A netCDF dataset of Markov chain and corresponding energies of a VQMC run
228  @param[in] show_analytic Also display the analytical wavefunction
229  '''
230  dat = nd.Dataset(chain_file, 'r', format='NETCDF4')
231 
232  positions = dat.variables['positions'][:]
233  energies = dat.variables['energies'][:]
234  alpha = dat.alpha
235 
236  plt.figure(figsize=(8, 8))
237  plt.title(rf'Sampled QHO Wavefunction at $\alpha$ = {alpha}')
238  plt.plot(positions, energies, 'o', color='purple', markersize=4.0, alpha=0.5, label='Sampled Positions')
239  plt.xlabel('Sampled Position')
240  plt.ylabel('Energy')
241 
242  if show_analytic:
243  pos_array = np.linspace(min(positions), max(positions), 100)
244  analytic = np.exp(-alpha * pos_array**2)
245  plt.plot(pos_array, analytic, color='red', alpha=0.8, label='Analytic Probability Distribution')
246  plt.legend()
247 
248  plt.show()
249 
250 
251 def H2plusEnergyPlot(results_file, sliceby=(None, None)):
252  '''
253  @brief
254  @f$ H_{2}^{+} @f$ H-H bond energy and parameter plotter.
255 
256  @details
257  Plots the H-H bond potential energy curve generated by VQMC at the optimum
258  parameters for each bond length. Plots standard deviation of each energy as
259  a measure of uncertainty. Also plots variational parameter @f$ c @f$ against
260  bond length. Reports equilibrium bond length for the molecule and optimum
261  energy.
262 
263  @param[in] results_file The main netCDF output file from a @f$ H_{2}^{+} @f$ run
264  @param[in] sliceby (Optional) Tuple containing slice intervals for arrays
265  '''
266  dat = nd.Dataset(results_file, 'r', format='NETCDF4')
267 
268  bond_lengths = dat.variables['Bondlength_array'][sliceby[0]:sliceby[1]]
269  c_opt = dat.variables['Parameter_array'][sliceby[0]:sliceby[1]]
270  energies = dat.variables['total_energies'][sliceby[0]:sliceby[1]]
271  variances = dat.variables['Uncertainties'][sliceby[0]:sliceby[1]]
272 
273  stdevs = np.sqrt(variances)
274  min_energy = min(energies)
275  min_energy_stdev = stdevs[np.argmin(energies)]
276  min_bond_length = bond_lengths[np.argmin(energies)]
277 
278  fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(18, 8))
279 
280  ax1.set_title(r'$H_{2}^{+}$ bond energy curve')
281  # ax1.plot(bond_lengths, energies, marker='o')
282  ax1.plot(bond_lengths, energies, marker='o', ls='--', color='blue')
283  ax1.fill_between(bond_lengths, energies+stdevs, energies-stdevs, alpha=0.3, color='purple')
284  ax1.axhline(-0.5, ls='-', color='black', alpha=0.3)
285  ax1.set_xlabel(r'Bond Length / $a_{0}$')
286  ax1.set_ylabel('Energy / Ha')
287 
288  ax2.set_title(r'Optimised parameter $c$')
289  ax2.plot(bond_lengths, c_opt)
290  ax2.axhline(1/np.sqrt(2), ls='-', color='black', alpha=0.3)
291  ax2.set_xlabel(r'Bond Length / $a_{0}$')
292  ax2.set_ylabel(r'$c$')
293 
294  fig.tight_layout()
295  fig.show()
296 
297  print(f'Equilibrium bond length: {min_bond_length} Bohr')
298  print(f' = {min_bond_length*0.529177} Angstroms')
299  print(f' at energy: {min_energy} ± {min_energy_stdev} Ha')
300 
301 
302 
303 def H2EnergyPlot(results_file, sliceby=(None, None)):
304  '''
305  @brief
306  @f$ H_{2} @f$ H-H bond energy and parameter plotter.
307 
308  @details
309  Plots the H-H bond potential energy curve generated by VQMC at the optimum
310  parameters for each bond length. Plots standard deviation of each energy as
311  a measure of uncertainty. Also plots variational parameters @f$ a @f$ and
312  @f$ \beta @f$ against bond length. Reports equilibrium bond length for the
313  molecule and optimum energy.
314 
315  @param[in] results_file The main netCDF output file from a @f$ H_{2} @f$ run
316  @param[in] sliceby (Optional) Tuple containing slice intervals for arrays
317  '''
318  dat = nd.Dataset(results_file, 'r', format='NETCDF4')
319 
320  bond_lengths = dat.variables['Bondlength_array'][sliceby[0]:sliceby[1]]
321  a_opt = dat.variables['Parameter_a_array'][sliceby[0]:sliceby[1]]
322  beta_opt = dat.variables['Parameter_beta_array'][sliceby[0]:sliceby[1]]
323  energies = dat.variables['total_energies'][sliceby[0]:sliceby[1]]
324  variances = dat.variables['Uncertainties'][sliceby[0]:sliceby[1]]
325 
326  stdevs = np.sqrt(variances)
327  min_energy = min(energies)
328  min_energy_stdev = stdevs[np.argmin(energies)]
329  min_bond_length = bond_lengths[np.argmin(energies)]
330 
331  fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(18, 8))
332 
333  ax1.set_title(r'$H_{2}$ bond energy curve')
334  ax1.errorbar(bond_lengths, energies, yerr=stdevs, marker='o', ls='--', color='blue')
335  ax1.fill_between(bond_lengths, energies+stdevs, energies-stdevs, alpha=0.3, color='purple')
336  ax1.set_xlabel(r'Bond Length / $a_{0}$')
337  ax1.set_ylabel('Energy / Ha')
338 
339  ax2.set_title(r'Optimised parameters')
340  ax2.plot(bond_lengths, a_opt, color='red')
341  ax2.set_xlabel(r'Bond Length / $a_{0}$')
342  ax2.set_ylabel(r'$a$', color='red')
343  ax2.tick_params(axis='y', labelcolor='red')
344 
345  ax2a = ax2.twinx()
346  ax2a.plot(bond_lengths, beta_opt, color='blue')
347  ax2a.set_ylabel(r'$\beta$', color='blue')
348  ax2a.tick_params(axis='y', labelcolor='blue')
349 
350  fig.tight_layout()
351  fig.show()
352 
353  print(f'Equilibrium bond length: {min_bond_length} Bohr')
354  print(f' = {min_bond_length*0.529177} Angstroms')
355  print(f' at energy: {min_energy} ± {min_energy_stdev} Ha')
356 
357 
358 #------------------------------------
359 # Burn / Thin FUNCTION DEFINITIONS -
360 #------------------------------------
361 
362 
366 def view_original_trace(equil_file):
367  rootgrp = Dataset(equil_file, "r", format = "NETCDF4")
368  chain = np.array(rootgrp['positions'][:])
369  if len(chain.shape) == 1:
370  plt.plot(range(len(chain)), chain, linewidth=1.0)
371  plt.xlabel("Position in chain")
372  plt.ylabel("Chain value")
373  plt.title("Original Chain")
374  plt.show()
375 
376  else:
377  chainx = chain[:,0]
378  chainy = chain[:,1]
379  chainz = chain[:,2]
380 
381  fig, (ax1,ax2,ax3) = plt.subplots(3,1)
382  ax1.plot(range(len(chainx)), chainx, linewidth=1.0)
383  ax2.plot(range(len(chainy)), chainy, linewidth=1.0)
384  ax3.plot(range(len(chainz)), chainz, linewidth=1.0)
385 
386  return
387 
388 def BurnThinUI(equil_file):
389  '''
390  @brief
391  Wrapper function for interacting with get_autocorrelation_time()
392 
393  @param[in] equil_file Filename of MCMC equilibration run
394  '''
395  widgets.interact_manual(get_autocorrelation_time, filename=fixed(equil_file),
396  burn=(0, int(0.1*len(np.array(Dataset(equil_file, "r", format = "NETCDF4")['positions'][:]))), 10),
397  tuning=[(1.0),(1e-1),(1e-2),(1e-3),(1e-4)])
398 
399 
415 def get_autocorrelation_time(filename, burn, tuning, plotting=True):
416  rootgrp = Dataset(filename, "r", format = "NETCDF4")
417  chain = np.array(rootgrp['positions'][:])
418  if len(chain.shape) == 1:
419  acp = sps.fftconvolve(chain,chain[::-1],mode='full')
420  acp = acp[int(acp.size / 2):]
421  acp = acp / max(acp)
422  acp = acp[burn:]
423 
424  thin = np.argmax(abs(acp) < tuning)
425  if thin == 0:
426  if acp[thin] < tuning:
427  thin = 1
428  else:
429  print("No thinning value found - tuning may be too aggressive. Defaulting to no thinning, thin=1.")
430  print()
431  thin = 1
432 
433  print("burning parameter = ", burn)
434  print("proposed thinning parameter = ", thin)
435 
436  chain_new = chain[burn::thin]
437  print("length of new chain = ", len(chain_new))
438 
439  if plotting==True:
440  plt.plot(range(len(acp)), acp, linewidth=1.0)
441  plt.xlabel("Position in chain / Lag time")
442  plt.ylabel("ACF")
443  plt.title("Autocorrelation function vs lag time")
444  plt.show()
445 
446  plt.plot(range(len(chain_new)), chain_new, linewidth=1.0)
447  plt.xlabel("Position in chain")
448  plt.ylabel("Chain value")
449  plt.title("New Chain")
450  plt.show()
451 
452  return burn, thin
453 
454  else:
455  chainx = chain[:,0]
456  chainy = chain[:,1]
457  chainz = chain[:,2]
458 
459  threed_thin = []
460  chain_lengths = []
461 
462  for c in [chainx,chainy,chainz]:
463  acp = sps.fftconvolve(c,c[::-1],mode='full')
464  acp = acp[int(acp.size / 2):]
465  acp = acp / max(acp)
466  acp = acp[burn:]
467 
468  thin = np.argmax(abs(acp) < tuning)
469  if thin == 0:
470  if acp[thin] < tuning:
471  thin = 1
472  else:
473  print("No thinning value found - tuning may be too aggressive. Defaulting to no thinning, thin=1.")
474  print()
475  thin = 1
476 
477  threed_thin.append(thin)
478 
479  chain_new = c[burn::thin]
480  chain_lengths.append(len(chain_new))
481 
482  if plotting==True:
483  plt.plot(range(len(acp)), acp, linewidth=1.0)
484  plt.xlabel("Position in chain / Lag time")
485  plt.ylabel("ACF")
486  plt.title("Autocorrelation function vs lag time")
487  plt.show()
488 
489 # plt.plot(range(len(chain_new)), chain_new, linewidth=1.0)
490 # plt.xlabel("Position in chain")
491 # plt.ylabel("Chain value")
492 # plt.title("New Chain")
493 # plt.show()
494  print("burning parameter = ", burn)
495  print("proposed thinning parameters from the 3 chains: ", threed_thin)
496  print("chain lengths from proposed thins", chain_lengths)
497 
498  return burn, threed_thin
499 
500 
501 
502 #------------------------------------
503 # Deprecated Functions
504 #------------------------------------
505 
506 def load_results(filename = 'results.nc'):
507 
508  """Loads the results as a dataset NetCDF object to be passed to other functions
509 
510  Parameters:
511  filename: The name of the file containing the results, defaults to 'results.nc'. """
512 
513  try:
514  rootgrp = Dataset(filename)
515  except OSError as err:
516  print(f"OS error: {err}")
517  return rootgrp
518 
519 
520 def load_global_attr(rootgrp, verbose = True):
521  """Loads the global metadata in the results file into a dictionary
522 
523  Parameters:
524  rootgrp: NetCDF4 dataset object which loaded in using 'load_results()'.
525  verbose: Defaults to true. Prints the value of global attributes which have been loaded
526  """
527  global_dict ={}
528 
529  for name in rootgrp.ncattrs():
530  if verbose:
531  print("{} = {}".format(name, getattr(rootgrp, name)))
532 
533  global_dict[name] = getattr(rootgrp, name)
534 
535 
536  return global_dict
537 
538 
539 def load_variables(rootgrp, verbose = True):
540  """Loads the variables in the results file into a dictionary
541 
542  Parameters:
543  rootgrp: NetCDF4 dataset object which loaded in using 'load_results()'
544  verbose: Defaults to true. Prints the value of variables which have been loaded
545  """
546  var_dict = {}
547  for k in rootgrp.variables.keys():
548  if verbose:
549  print("{} = {}".format(k, rootgrp[k][:]))
550  var_dict[k] = rootgrp[k][:]
551 
552  return var_dict
553 
554 
555 def H2_eng_plot(variables):
556  """Plots the energies against the parameters checked during the grid search
557  Parameters:
558  variables: Dictionary which contains data about the variables in the netcdf4 object"""
559 
560  fig = go.Figure()
561 
562  fig.add_trace(
563  go.Scatter(
564  x=variables['Bondlength_array'],
565  y=variables['total_energies'],
566  error_y=dict(
567  type='data',
568  array=variables['Uncertainties'],
569  visible=True)
570  )
571  )
572 
573  fig.update_layout(
574  title=f"Energies vs Bond Lengths",
575  xaxis_title="Bond Length",
576  yaxis_title="Energy"
577  )
578 
579  fig.show()
580 
581  return fig
582 
583 
584 def QHO_eng_plot(rootgrp,equil=False):
585  """energy_plot()
586  Plots the energy at each step as the MC converges
587  """
588 
589  energies = np.array(rootgrp.variables['energy_at_alphas_array'][:])
590 
591  alphas = np.array((rootgrp.variables['Alpha_array'][:]))
592 
593  if (equil):
594  pass
595 
596  data = go.Scatter(x=alphas, y=energies, mode='markers')
597  fig = go.Figure(data)
598  fig.show()
599 
600  return data
601 
602 
603 def plot_3D(X,Y,Z,wfn):
604  #for plotting wavefunctions, to be removed
605  fig = go.Figure(data=go.Volume(
606  x=X.flatten(),
607  y=Y.flatten(),
608  z=Z.flatten(),
609  value=wfn.flatten(),
610  isomin=0.0,
611  isomax=1.2,
612  opacity=0.1,
613  surface_count=21,
614  ))
615 
616  #fig.save("wavefunction.png")
617 
618  return fig
619 
620 
621 def process_main_results(filename='results.nc', verbose = True):
622  """Processes the results output as a result of the parameter search from the NetCDF4 file
623 
624  Parameters:
625  filename: Defaults to 'results.nc'. The file which contains the data output by the parameter search
626  """
627 
628 
629 
630  rootgrp = load_results(filename)
631 
632  global_attr = load_global_attr(rootgrp, verbose)
633 
634  variables = load_variables(rootgrp, verbose)
635 
636 
637  if (global_attr['system'] == 'QHO'):
638  pass
639  #data1 = QHO_eng_plot(rootgrp)
640  #fig = QHO_prob_plot(rootgrp)
641  elif(global_attr['system'] == 'H2plus'):
642  main_fig = H2_eng_plot(variables)
643 
644 
645  elif(global_attr['system'] == 'H2'):
646  pass
647 
648  else:
649  raise Exception("Invalid system input into visualisation")
650 
651  return global_attr,variables,main_fig
652 
653 
654 def plot_markov_chain(filename):
655 
656  dset = nc.Dataset(filename)
657 
658  energies = dset['energies'][:]
659 
660  positions = dset['positions'][:]
661 
662  if dset.system == 'QHO':
663 
664  fig = QHO_prob_plot(positions)
665 
666  return fig
667 
668  elif dset.system == 'H2' or dset.system == 'H2plus':
669 
670  R1 = [-0.5*dset.bond_length, 0, 0]
671  R2 = [0.5*dset.bond_length, 0, 0]
672 
673  fig = vis.H2_prob_plot(positions, energies, R1, R2)
674 
675  return fig
676 
677 
678 
679 
680 def orb_1s(X,Y,Z, R_a): #R_a is the location of the atoms
681  x_a,y_a,z_a = R_a
682  a0 = 1
683  orbital = 1/(((a0**1.5)*(np.sqrt(np.pi)))*\
684  np.exp(np.sqrt((X-x_a)**2+(Y-y_a)**2+(Z-z_a)**2)/a0))
685  return orbital
686 
687 
688 def orb_2s(r,R_a):
689  a0 = 1
690  orbital = (2-np.linalg.norm(r-R_a)()/a0)/((4*(a0**1.5)*(np.sqrt(2*np.pi)))*np.exp(np.linalg.norm(r-R_a)/(2*a0)))
691  return orbital
692 
693 
694 def polar_to_cart(r,theta, phi):
695  X = r*np.sin(phi)*np.cos(theta)
696  Y = r*np.sin(phi)*np.sin(theta)
697  Z = r*np.cos(phi)
698 
699  return X,Y,Z
700 
701 
702 def lcao_wfn(X,Y,Z, R1, R2, pqn = 1):
703  #for the linear combination of wavefunctions, to be added to and to be remove
704  if pqn == 1:
705  wfn = np.sqrt(2)*orb_1s(X,Y,Z,R1) + np.sqrt(2)*orb_1s(X,Y,Z,R2)
706  if pqn == 2:
707  pass
708 
709  return wfn
710 
711 
712 def plot_3D(X,Y,Z,wfn,R1,R2):
713  """ Function for plotting the wavefunction analytically. Meshgrids can be generated using np.meshgrid(x,y,z)
714 
715  Parameters:
716  X: Meshgrid of X coordinates
717  Y: Meshgrid of Y coordinates
718  Z: Meshgrid of Z coordinates
719  """
720 
721  fig = go.Figure()
722  #for plotting wavefunctions, to be removed
723  fig.add_trace(go.Volume(
724  x=X.flatten(),
725  y=Y.flatten(),
726  z=Z.flatten(),
727  value=wfn.flatten(),
728  opacity=0.1,
729  surface_count=21,
730  ))
731 
732  fig.add_trace(go.Scatter3d(
733  mode='markers',
734  x=[R1[0],R2[0]],
735  y=[R1[1],R2[1]],
736  z=[R1[2],R2[2]],
737  opacity=1.0,
738  marker=dict(
739  color='#AAAAAA',
740  size=10,
741  line=dict(
742  color='Black',
743  width=2
744  )
745  ),
746  name='Atoms'
747  )
748  )
749  return fig
750 
751 
752 def example_H1s_wfn(bond_length=2.0):
753 
754  x, y, z = np.mgrid[-3:3:40j, -3:3:40j, -3:3:40j]
755 
756  R_1 = (-0.5*bond_length, 0,0)
757  R_2 = (0.5*bond_length, 0,0)
758 
759  wfn = lcao_wfn(x,y,z,R_1,R_2)
760  density = wfn**2
761 
762  density_plot = plot_3D(x,y,z,density,R_1,R_2)
763  return density_plot
764 
765  return wfn
def H2_prob_plot(positions, energies, R1, R2, opacity)
Plots the sampled wavefunction for H2plus/H2.
def H2plusEnergyPlot(results_file, sliceby=(None, None))
H-H bond energy and parameter plotter.
def load_variables(rootgrp, verbose=True)
Loads the variables in the results file into a dictionary.
def QHOEnergyPlot(results_file, sliceby=(None, None))
Energy against plotter for the QHO problem.
def view_original_trace(equil_file)
Plots the original trace(s) of an MCMC run.
def QHOWfnPlot(chain_file, show_analytic=False)
Scatter plotter of the sampled QHO wavefunction.
def load_results(filename='results.nc')
Loads the results as a dataset NetCDF object to be passed to other functions.
def BurnThinUI(equil_file)
Wrapper function for interacting with get_autocorrelation_time()
def example_H1s_wfn(bond_length=2.0)
def orb_1s(X, Y, Z, R_a)
functions plotting the wavefunction ab initio #######
def QHO_prob_plot(positions, energies)
Fancy Plotly plotter for QHO Markov chains.
def polar_to_cart(r, theta, phi)
def QHO_eng_plot(rootgrp, equil=False)
energy_plot() Plots the energy at each step as the MC converges
def H2_eng_plot(variables)
Plots the energies against the parameters checked during the grid search Parameters: variables: Dicti...
def plot_3D(X, Y, Z, wfn)
def H2EnergyPlot(results_file, sliceby=(None, None))
H-H bond energy and parameter plotter.
def lcao_wfn(X, Y, Z, R1, R2, pqn=1)
def get_autocorrelation_time(filename, burn, tuning, plotting=True)
Function which suggests a thinning parameter for a MCMC chain.
def process_main_results(filename='results.nc', verbose=True)
Processes the results output as a result of the parameter search from the NetCDF4 file.
def QHOProbPlot(chain_file)
Wrapper function for QHO_prob_plot()
def HydProbPlot(chain_file, opacity=0.2)
Wrapper function for H2_prob_plot()
def load_global_attr(rootgrp, verbose=True)
Loads the global metadata in the results file into a dictionary.