diff --git a/org/qmckl_examples.org b/org/qmckl_examples.org index 0408d16e..8cc12926 100644 --- a/org/qmckl_examples.org +++ b/org/qmckl_examples.org @@ -8,6 +8,9 @@ in a [[https://github.com/TREX-CoE/trexio][TREXIO]] file. * Python ** Check numerically that MOs are orthonormal + :PROPERTIES: + :header-args: :tangle mo_ortho.py + :END: In this example, we will compute numerically the overlap between the molecular orbitals: @@ -127,7 +130,7 @@ before = time.time() mo_value = qmckl.get_mo_basis_mo_value(context, point_num*mo_num) after = time.time() -mo_value = np.reshape( mo_value, (point_num, mo_num) ) +mo_value = np.reshape( mo_value, (point_num, mo_num) ).T # Transpose to get mo_num x point_num print("Number of MOs: ", mo_num) print("Number of grid points: ", point_num) @@ -138,14 +141,14 @@ print("Execution time : ", (after - before), "seconds") #+begin_example Number of MOs: 201 Number of grid points: 1728000 -Execution time : 3.511528968811035 seconds +Execution time : 5.577778577804565 seconds #+end_example and finally we compute the overlap between all the MOs as - $M^\dagger M$. + $M.M^\dagger$. #+begin_src python :exports code -overlap = mo_value.T @ mo_value * dr +overlap = mo_value @ mo_value.T * dr print (overlap) #+end_src @@ -167,6 +170,9 @@ print (overlap) * C ** Check numerically that MOs are orthonormal, with cusp fitting + :PROPERTIES: + :header-args: :tangle mo_ortho.c + :END: In this example, we will compute numerically the overlap between the molecular orbitals: @@ -188,6 +194,9 @@ print (overlap) #+begin_src c :exports code #include #include +#include +//#include +#include int main(int argc, char** argv) { @@ -201,10 +210,6 @@ int main(int argc, char** argv) #+begin_src c :exports code qmckl_context context = qmckl_context_create(); - if (context == NULL) { - fprintf(stderr, "Error creating context\n"); - exit(1); - } rc = qmckl_trexio_read(context, trexio_filename, strlen(trexio_filename)); @@ -221,7 +226,7 @@ int main(int argc, char** argv) To identify which atom is an oxygen and which are hydrogens, we fetch the nuclear charges from the context. - #+begin_src python :exports code + #+begin_src c :exports code int64_t nucl_num; rc = qmckl_get_nucleus_num(context, &nucl_num); @@ -234,7 +239,7 @@ int main(int argc, char** argv) double nucl_charge[nucl_num]; - rc = qmckl_get_nucleus_charge(context, &(nucl_charge[0])); + rc = qmckl_get_nucleus_charge(context, &(nucl_charge[0]), nucl_num); if (rc != QMCKL_SUCCESS) { fprintf(stderr, "Error getting nucl_charge:\n%s\n", qmckl_string_of_error(rc)); @@ -242,28 +247,43 @@ int main(int argc, char** argv) } - double r_c[nucl_num]; + double r_cusp[nucl_num]; for (size_t i=0 ; i rmax[j] ? nucl_coord[i][j] : rmax[j]; + } + } -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) + rmin[0] -= shift[0]; rmin[1] -= shift[1]; rmin[2] -= shift[2]; + rmax[0] += shift[0]; rmax[1] += shift[1]; rmax[2] += shift[2]; -dr = step[0] * step[1] * step[2] + double step[3]; + + double* linspace[3]; + for (int i=0 ; i<3 ; ++i) { + + linspace[i] = (double*) calloc( sizeof(double), nx[i] ); + + if (linspace[i] == NULL) { + fprintf(stderr, "Allocation failed (linspace)\n"); + exit(1); + } + + step[i] = (rmax[i] - rmin[i]) / ((double) (nx[i]-1)); + + for (size_t j=0 ; j