2020-10-26 11:33:51 +01:00
|
|
|
#+TITLE: Hartree-Fock
|
|
|
|
|
|
|
|
#+PROPERTY
|
|
|
|
|
|
|
|
In this example, we write a program that makes a Hartree-Fock
|
|
|
|
caculation. The molecule is read in =xyz= format and a Gaussian
|
|
|
|
atomic basis set in GAMESS format.
|
|
|
|
|
|
|
|
* Header
|
|
|
|
|
|
|
|
#+BEGIN_SRC ocaml :comments link :exports code :tangle ex_hartree_fock.ml
|
|
|
|
module Command_line = Qcaml.Common.Command_line
|
|
|
|
module Util = Qcaml.Common.Util
|
|
|
|
|
|
|
|
let () =
|
|
|
|
#+END_SRC
|
|
|
|
|
|
|
|
* Command-line arguments
|
|
|
|
|
|
|
|
We use the =Command_line= module to define the following possible
|
|
|
|
arguments:
|
|
|
|
- =-b --basis= : The name of the file containing the basis set
|
|
|
|
- =-x --xyz= : The name of the file containing the atomic coordinates
|
|
|
|
- =-c --charge= : The charge of the molecule
|
|
|
|
- =-m --multiplicity= : The spin multiplicity
|
|
|
|
|
|
|
|
** Definition
|
|
|
|
|
|
|
|
#+BEGIN_SRC ocaml :comments link :exports code :tangle ex_hartree_fock.ml
|
|
|
|
let open Command_line in
|
|
|
|
begin
|
2023-04-24 13:05:01 +02:00
|
|
|
set_header_doc (Sys.argv.(0));
|
2020-10-26 11:33:51 +01:00
|
|
|
set_description_doc "Computes the one- and two-electron hartree_fock on the Gaussian atomic basis set.";
|
|
|
|
set_specs
|
|
|
|
[ { short='b' ; long="basis" ; opt=Mandatory;
|
|
|
|
arg=With_arg "<string>";
|
|
|
|
doc="Name of the file containing the basis set"; } ;
|
|
|
|
|
|
|
|
{ short='x' ; long="xyz" ; opt=Mandatory;
|
|
|
|
arg=With_arg "<string>";
|
|
|
|
doc="Name of the file containing the nuclear coordinates in xyz format"; } ;
|
|
|
|
|
|
|
|
{ short='m' ; long="multiplicity" ; opt=Optional;
|
|
|
|
arg=With_arg "<int>";
|
|
|
|
doc="Spin multiplicity (2S+1). Default is singlet"; } ;
|
|
|
|
|
|
|
|
{ short='c' ; long="charge" ; opt=Optional;
|
|
|
|
arg=With_arg "<int>";
|
|
|
|
doc="Total charge of the molecule. Specify negative charges with 'm' instead of the minus sign, for example m1 instead of -1. Default is 0"; } ;
|
|
|
|
|
|
|
|
]
|
|
|
|
end;
|
|
|
|
#+END_SRC
|
|
|
|
|
|
|
|
** Interpretation
|
|
|
|
|
|
|
|
#+BEGIN_SRC ocaml :comments link :exports code :tangle ex_hartree_fock.ml
|
|
|
|
let basis_file = Util.of_some @@ Command_line.get "basis" in
|
|
|
|
let nuclei_file = Util.of_some @@ Command_line.get "xyz" in
|
|
|
|
|
|
|
|
let charge =
|
|
|
|
match Command_line.get "charge" with
|
|
|
|
| Some x -> ( if x.[0] = 'm' then
|
|
|
|
~- (int_of_string (String.sub x 1 (String.length x - 1)))
|
|
|
|
else
|
|
|
|
int_of_string x )
|
|
|
|
| None -> 0
|
|
|
|
in
|
|
|
|
|
|
|
|
let multiplicity =
|
|
|
|
match Command_line.get "multiplicity" with
|
|
|
|
| Some x -> int_of_string x
|
|
|
|
| None -> 1
|
|
|
|
in
|
|
|
|
#+END_SRC
|
|
|
|
|
|
|
|
* Computation
|
2023-06-16 18:27:23 +02:00
|
|
|
|
2020-10-26 11:33:51 +01:00
|
|
|
We first read the =xyz= file to create a molecule:
|
2023-06-16 18:27:23 +02:00
|
|
|
|
2020-10-26 11:33:51 +01:00
|
|
|
#+BEGIN_SRC ocaml :comments link :exports code :tangle ex_hartree_fock.ml
|
|
|
|
let nuclei =
|
|
|
|
Qcaml.Particles.Nuclei.of_xyz_file nuclei_file
|
|
|
|
in
|
|
|
|
#+END_SRC
|
|
|
|
|
2023-06-16 18:27:23 +02:00
|
|
|
Then we create a Gaussian AO basis using the atomic coordinates:
|
2020-10-26 11:33:51 +01:00
|
|
|
#+BEGIN_SRC ocaml :comments link :exports code :tangle ex_hartree_fock.ml
|
|
|
|
let ao_basis =
|
|
|
|
Qcaml.Ao.Basis.of_nuclei_and_basis_filename ~nuclei basis_file
|
|
|
|
in
|
|
|
|
#+END_SRC
|
|
|
|
|
|
|
|
We create a simulation from the nuclei and the basis set:
|
|
|
|
#+BEGIN_SRC ocaml :comments link :exports code :tangle ex_hartree_fock.ml
|
2023-06-16 18:27:23 +02:00
|
|
|
let simulation = Qcaml.Simulation.make ~multiplicity ~charge ~nuclei ao_basis in
|
2020-10-26 11:33:51 +01:00
|
|
|
#+END_SRC
|
|
|
|
|
|
|
|
and we can make the Hartree-Fock computation:
|
|
|
|
#+BEGIN_SRC ocaml :comments link :exports code :tangle ex_hartree_fock.ml
|
|
|
|
let hf = Qcaml.Mo.Hartree_fock.make ~guess:`Huckel simulation in
|
|
|
|
#+END_SRC
|
|
|
|
|
|
|
|
* Output
|
|
|
|
|
|
|
|
We print the convergence of the calculation:
|
|
|
|
#+BEGIN_SRC ocaml :comments link :exports code :tangle ex_hartree_fock.ml
|
|
|
|
Format.printf "@[%a@]" (Mo.Hartree_fock.pp) hf
|
|
|
|
#+END_SRC
|
|
|
|
|
|
|
|
|