=============================================================================
Three years ago, there was a Hartree Fock program written in C (https://github.com/Walter-Feng/Hartree-Fock). During that time, I only learned C, so I needed to write all the structures myself - tons of pointers, stupid recursion, and so on. The code was super inefficient, buggy, maybe with some memory leaks.
Things changed. I learned C++ and software engineering practice, read some good code, wrote a lot more code in different languages. Externally, C is no longer popular among undergraduates. Therefore, reviewing the original C-style Hartree-Fock code, I thought instantly "hey this code need a complete reconstruction", so making it a lot easier for newcomers to understand the math, run the code, and get a taste of what good code is.
"Well... but you could have used Python which is more friendly"
No. I refuse to use python for this project. Learn some static programming!
=============================================================================
Back to the topic, this is a Hartree-Fock program that aims to show how Hartree-Fock really works in every process, but in full C++ standard. (Hopefully) it is well documented with good variable names so that you can read the code without much effort and understand what is going on. A good tex document that illustrates the mathematics and C++ features is (probably) on the way.
As a comparison, the features in this program are:
-
The programming style is completely in C++ - OOP, templates, but no more pointers.
-
Tons of dependencies, including Boost (you need to install yourself)
Armadillo (same as above)
sunqm/libcint (but only using its rys quadrature roots generator)
catchorg/Catch2
Taywee/args
fmtlib/fmt
nlohmann/json
-
It is (in principle) able to use all the bases that have been published in Basis Set Exchange (https://www.basissetexchange.org).
-
No special trick is used generally, but some C++ tricks may need to be learned.
-
Templates may prevent understanding the code via some debug techniques.
And something good:
-
GOOOOOOD PROGRAMMING STYLE
-
The output is mostly handled by printer functions, so easier to mess around.
To clone the repository, don't forget to add "--recursive" to include all the dependencies,
git clone --recursive https://github.com/Walter-Feng/Hartree-Fock-in-CPP.git
CMake is used to generate the executable:
Hartree-Fock-in-CPP-repo-directory: $ mkdir build
Hartree-Fock-in-CPP-repo-directory/build: $ cmake ..
Hartree-Fock-in-CPP-repo-directory/build: $ make
Type
./hfincpp -h
to unlock all options.
To run the example:
Hartree-Fock-in-CPP-repo-directory/build: $ ./hfincpp ../example/H2_6_31g.json
The output should be something like:
============================================================
|Iter| Time / s | Energy / a.u. | Energy Diff |
============================================================
0 0 -0.90365255 0
1 2.0781e-05 -0.91596619 -0.012313641
2 3.5345e-05 -0.91626362 -0.00029743166
3 4.6462e-05 -0.91627108 -7.4536724e-06
4 5.6896e-05 -0.91627126 -1.8785583e-07
============================================================
Total time elapsed: 0.032478466 s
Json file format is used for input, and due to lack of default parameters, any missing keywords will generate a non-trackable error. So for now it is advised to only change the values in example json input file.