QCaml/run_fci.ml

100 lines
2.7 KiB
OCaml
Raw Normal View History

2020-02-27 01:02:00 +01:00
open Lacaml.D
2019-02-26 11:58:53 +01:00
let () =
let open Command_line in
begin
set_header_doc (Sys.argv.(0) ^ " - QCaml command");
2020-02-27 01:02:00 +01:00
set_description_doc "Runs a Full CI calculation";
2019-02-26 11:58:53 +01:00
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. Default is 0"; } ;
2020-02-27 01:02:00 +01:00
{ short='f' ; long="frozen-core" ; opt=Optional;
arg=Without_arg ;
doc="Freeze core MOs. Default is false."; } ;
{ short='s' ; long="state" ; opt=Optional;
arg=With_arg "<int>";
doc="Requested state. Default is 1."; } ;
2019-02-26 11:58:53 +01:00
]
end;
(* Handle options *)
2019-03-01 21:56:46 +01:00
let basis_file = Util.of_some @@ Command_line.get "basis" in
2019-02-26 11:58:53 +01:00
2019-03-01 21:56:46 +01:00
let nuclei_file = Util.of_some @@ Command_line.get "xyz" in
2019-02-26 11:58:53 +01:00
let charge =
match Command_line.get "charge" with
2020-02-27 01:02:00 +01:00
| Some x -> ( if x.[0] = 'm' then
~- (int_of_string (String.sub x 1 (String.length x - 1)))
else
int_of_string x )
2019-02-26 11:58:53 +01:00
| None -> 0
in
2020-02-27 01:02:00 +01:00
let state =
match Command_line.get "state" with
| Some x -> int_of_string x
| None -> 1
in
2019-02-26 11:58:53 +01:00
let multiplicity =
match Command_line.get "multiplicity" with
| Some x -> int_of_string x
| None -> 1
in
2019-03-02 18:50:12 +01:00
let ppf =
if Parallel.master then Format.std_formatter
else Printing.ppf_dev_null
in
2020-02-27 01:02:00 +01:00
let simulation =
2019-02-26 11:58:53 +01:00
Simulation.of_filenames ~charge ~multiplicity ~nuclei:nuclei_file basis_file
in
2020-02-27 01:02:00 +01:00
let hf = HartreeFock.make simulation in
if Parallel.master then
Format.fprintf ppf "@[%a@]@." HartreeFock.pp hf;
2019-03-02 18:50:12 +01:00
2020-02-27 01:02:00 +01:00
let mo_basis =
2019-02-26 11:58:53 +01:00
MOBasis.of_hartree_fock hf
in
2019-03-02 18:50:12 +01:00
2020-02-27 01:02:00 +01:00
let frozen_core =
Command_line.get_bool "frozen-core"
in
2019-02-26 11:58:53 +01:00
let space =
2020-02-27 01:02:00 +01:00
DeterminantSpace.fci_of_mo_basis ~frozen_core mo_basis
2019-02-26 11:58:53 +01:00
in
2020-02-27 01:02:00 +01:00
let ci = CI.make space ~n_states:state in
if Parallel.master then
Format.fprintf ppf "FCI energy : ";
Vec.iteri (fun i x -> if i <= state then
Format.fprintf ppf "%20.16f@; " (x +. Simulation.nuclear_repulsion simulation) )
(CI.eigenvalues ci);
2019-02-26 11:58:53 +01:00
(*
let s2 = Util.xt_o_x ~o:(CI.s2_matrix ci) ~x:(CI.eigenvectors ci) in
2019-03-04 22:56:03 +01:00
Util.list_range 1 (DeterminantSpace.size space)
2019-02-26 11:58:53 +01:00
|> List.iter (fun i -> Format.printf "@[%f@]@;" s2.{i,i});
*)
2020-02-27 01:02:00 +01:00
Format.fprintf ppf "@.";