mirror of
https://github.com/TREX-CoE/qmckl.git
synced 2025-01-03 10:06:09 +01:00
Fix tests
This commit is contained in:
parent
e00e034497
commit
bd299126c1
114
org/examples.org
114
org/examples.org
@ -3,10 +3,117 @@
|
||||
#+INCLUDE: ../tools/lib.org
|
||||
|
||||
In this section, we present examples of usage of QMCkl.
|
||||
For simplicity, we assume that the wave function parameters are stores
|
||||
For simplicity, we assume that the wave function parameters are stored
|
||||
in a [[https://github.com/TREX-CoE/trexio][TREXIO]] file.
|
||||
|
||||
* Checking errors
|
||||
* Python
|
||||
|
||||
** Check numerically that MOs are orthonormal
|
||||
|
||||
In this example, we will compute the numerically the overlap
|
||||
between the molecular orbitals:
|
||||
|
||||
\[
|
||||
S_{ij} = \int \phi_i(\mathbf{r}) \phi_j(\mathbf{r})
|
||||
\text{d}\mathbf{r} \sim \sum_{k=1}^{N} \phi_i(\mathbf{r}_k)
|
||||
\phi_j(\mathbf{r}_k) \delta \mathbf{r}
|
||||
\]
|
||||
|
||||
|
||||
#+begin_src python :session
|
||||
import numpy as np
|
||||
import qmckl
|
||||
#+end_src
|
||||
|
||||
#+RESULTS:
|
||||
|
||||
|
||||
First, we create a context for the QMCkl calculation, and load the
|
||||
wave function stored in =h2o_5z.h5= inside it:
|
||||
|
||||
#+begin_src python :session
|
||||
trexio_filename = "..//share/qmckl/test_data/h2o_5z.h5"
|
||||
|
||||
context = qmckl.context_create()
|
||||
qmckl.trexio_read(context, trexio_filename)
|
||||
#+end_src
|
||||
|
||||
#+RESULTS:
|
||||
: None
|
||||
|
||||
We now define the grid points as a regular grid around the
|
||||
molecule.
|
||||
|
||||
We fetch the nuclear coordinates from the context,
|
||||
|
||||
#+begin_src python :session :results output
|
||||
nucl_num = qmckl.get_nucleus_num(context)
|
||||
|
||||
nucl_charge = qmckl.get_nucleus_charge(context, nucl_num)
|
||||
|
||||
nucl_coord = qmckl.get_nucleus_coord(context, 'N', nucl_num*3)
|
||||
nucl_coord = np.reshape(nucl_coord, (3, nucl_num))
|
||||
|
||||
for i in range(nucl_num):
|
||||
print("%d %+f %+f %+f"%(int(nucl_charge[i]),
|
||||
nucl_coord[i,0],
|
||||
nucl_coord[i,1],
|
||||
nucl_coord[i,2]) )
|
||||
#+end_src
|
||||
|
||||
#+RESULTS:
|
||||
: 8 +0.000000 +0.000000 +0.000000
|
||||
: 1 -1.430429 +0.000000 -1.107157
|
||||
: 1 +1.430429 +0.000000 -1.107157
|
||||
|
||||
and compute the coordinates of the grid points:
|
||||
|
||||
#+begin_src python :session
|
||||
nx = ( 40, 40, 40 )
|
||||
point_num = nx[0] * nx[1] * nx[2]
|
||||
|
||||
rmin = np.array( list([ np.min(nucl_coord[:,a]) for a in range(3) ]) )
|
||||
rmax = np.array( list([ np.max(nucl_coord[:,a]) for a in range(3) ]) )
|
||||
|
||||
shift = np.array([5.,5.,5.])
|
||||
|
||||
linspace = [ None for i in range(3) ]
|
||||
step = [ None for i in range(3) ]
|
||||
for a in range(3):
|
||||
linspace[a], step[a] = np.linspace(rmin[a]-shift[a],
|
||||
rmax[a]+shift[a],
|
||||
num=nx[a],
|
||||
retstep=True)
|
||||
|
||||
dr = step[0] * step[1] * step[2]
|
||||
dr
|
||||
#+end_src
|
||||
|
||||
#+RESULTS:
|
||||
: 0.024081249137090373
|
||||
|
||||
Now the grid is ready, we can create the list of grid points on
|
||||
which the MOs will be evaluated, and transfer them to the QMCkl
|
||||
context:
|
||||
|
||||
#+begin_src python :session
|
||||
point = []
|
||||
for x in linspace[0]:
|
||||
for y in linspace[1]:
|
||||
for z in linspace[2]:
|
||||
point += [x, y, z]
|
||||
|
||||
#point = np.array(point)
|
||||
qmckl.set_point(context, 'N', point, len(point)/3)
|
||||
#+end_src
|
||||
|
||||
#+RESULTS:
|
||||
|
||||
Then, will first evaluate all the MOs at the grid points, and then we will
|
||||
compute the overlap between all the MOs.
|
||||
|
||||
* Fortran
|
||||
** Checking errors
|
||||
|
||||
All QMCkl functions return an error code. A convenient way to handle
|
||||
errors is to write an error-checking function that displays the
|
||||
@ -29,7 +136,7 @@ subroutine qmckl_check_error(rc, message)
|
||||
end subroutine qmckl_check_error
|
||||
#+end_src
|
||||
|
||||
* Computing an atomic orbital on a grid
|
||||
** Computing an atomic orbital on a grid
|
||||
:PROPERTIES:
|
||||
:header-args: :tangle ao_grid.f90
|
||||
:END:
|
||||
@ -197,3 +304,4 @@ program ao_grid
|
||||
deallocate( nucl_coord, points, ao_vgl )
|
||||
end program ao_grid
|
||||
#+end_src
|
||||
|
||||
|
@ -1289,7 +1289,7 @@ end function qmckl_compute_local_energy_f
|
||||
|
||||
double local_energy[chbrclf_walk_num];
|
||||
|
||||
rc = qmckl_get_local_energy(context, &(local_energy[0]), walk_num);
|
||||
rc = qmckl_get_local_energy(context, &(local_energy[0]), chbrclf_walk_num);
|
||||
assert (rc == QMCKL_SUCCESS);
|
||||
|
||||
#+end_src
|
||||
|
Loading…
Reference in New Issue
Block a user