Improved FCI and CAS

This commit is contained in:
Anthony Scemama 2020-02-27 01:02:00 +01:00
parent 01b56ea5f8
commit f2b71bff7b
2 changed files with 72 additions and 19 deletions

View File

@ -20,6 +20,14 @@ let () =
arg=With_arg "<int>"; arg=With_arg "<int>";
doc="Total charge of the molecule. Default is 0"; } ; doc="Total charge of the molecule. Default is 0"; } ;
{ 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."; } ;
{ short='n' ; long="n_elec" ; opt=Mandatory; { short='n' ; long="n_elec" ; opt=Mandatory;
arg=With_arg "<int>"; arg=With_arg "<int>";
doc="Number of electrons in the active space."; } ; doc="Number of electrons in the active space."; } ;
@ -40,10 +48,19 @@ let () =
let charge = let charge =
match Command_line.get "charge" with match Command_line.get "charge" with
| Some x -> int_of_string x | 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 | None -> 0
in in
let state =
match Command_line.get "state" with
| Some x -> int_of_string x
| None -> 1
in
let multiplicity = let multiplicity =
match Command_line.get "multiplicity" with match Command_line.get "multiplicity" with
| Some x -> int_of_string x | Some x -> int_of_string x
@ -60,31 +77,35 @@ let () =
in in
let hf = HartreeFock.make s in let hf = HartreeFock.make s in
Format.fprintf ppf "@[%a@]@." HartreeFock.pp hf; if Parallel.master then
Format.fprintf ppf "@[%a@]@." HartreeFock.pp hf;
let mos = let mo_basis =
MOBasis.of_hartree_fock hf MOBasis.of_hartree_fock hf
in in
let space = let frozen_core =
DeterminantSpace.cas_of_mo_basis mos ~frozen_core:true n m Command_line.get_bool "frozen-core"
in in
let ci = CI.make space in
Format.fprintf ppf "CAS-CI energy : %20.16f@." ((CI.eigenvalues ci).{1} +. Simulation.nuclear_repulsion s); let space =
DeterminantSpace.cas_of_mo_basis ~frozen_core mo_basis n m
in
let ci = CI.make space ~n_states:state in
if Parallel.master then
Format.fprintf ppf "CAS-CI energy : %20.16f@." ((CI.eigenvalues ci).{1} +. Simulation.nuclear_repulsion s);
(* (*
let pt2 = CI.pt2_mp ci in let pt2 = CI.pt2_mp ci in
Format.fprintf ppf "CAS-MP2 energy : %20.16f@." ((CI.eigenvalues ci).{1} +. Simulation.nuclear_repulsion s +. pt2); Format.fprintf ppf "CAS-MP2 energy : %20.16f@." ((CI.eigenvalues ci).{1} +. Simulation.nuclear_repulsion s +. pt2);
*) *)
(*
let pt2 = CI.pt2_en ci in let pt2 = CI.pt2_en ci in
Format.fprintf ppf "CAS-EN2 energy : %20.16f@." ((CI.eigenvalues ci).{1} +. Simulation.nuclear_repulsion s +. pt2); Format.fprintf ppf "CAS-EN2 energy : %20.16f@." ((CI.eigenvalues ci).{1} +. Simulation.nuclear_repulsion s +. pt2);
let pt2 = CI.pt2_en_reference ci in let pt2 = CI.pt2_en_reference ci in
Format.fprintf ppf "CAS-EN2 energy (reference) : %20.16f@." ((CI.eigenvalues ci).{1} +. Simulation.nuclear_repulsion s +. pt2); Format.fprintf ppf "CAS-EN2 energy (reference) : %20.16f@." ((CI.eigenvalues ci).{1} +. Simulation.nuclear_repulsion s +. pt2);
*)
(* (*
let variance = CI.variance ci in let variance = CI.variance ci in
@ -97,3 +118,4 @@ let () =
|> List.iter (fun i -> Format.printf "@[%f@]@;" s2.{i,i}); |> List.iter (fun i -> Format.printf "@[%f@]@;" s2.{i,i});
*) *)
Format.fprintf ppf "@.";

View File

@ -1,8 +1,10 @@
open Lacaml.D
let () = let () =
let open Command_line in let open Command_line in
begin begin
set_header_doc (Sys.argv.(0) ^ " - QCaml command"); set_header_doc (Sys.argv.(0) ^ " - QCaml command");
set_description_doc "Runs a Hartree-Fock calculation"; set_description_doc "Runs a Full CI calculation";
set_specs set_specs
[ { short='b' ; long="basis" ; opt=Mandatory; [ { short='b' ; long="basis" ; opt=Mandatory;
arg=With_arg "<string>"; arg=With_arg "<string>";
@ -19,6 +21,14 @@ let () =
{ short='c' ; long="charge" ; opt=Optional; { short='c' ; long="charge" ; opt=Optional;
arg=With_arg "<int>"; arg=With_arg "<int>";
doc="Total charge of the molecule. Default is 0"; } ; doc="Total charge of the molecule. Default is 0"; } ;
{ 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."; } ;
] ]
end; end;
@ -29,10 +39,19 @@ let () =
let charge = let charge =
match Command_line.get "charge" with match Command_line.get "charge" with
| Some x -> int_of_string x | 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 | None -> 0
in in
let state =
match Command_line.get "state" with
| Some x -> int_of_string x
| None -> 1
in
let multiplicity = let multiplicity =
match Command_line.get "multiplicity" with match Command_line.get "multiplicity" with
| Some x -> int_of_string x | Some x -> int_of_string x
@ -44,25 +63,37 @@ let () =
else Printing.ppf_dev_null else Printing.ppf_dev_null
in in
let s = let simulation =
Simulation.of_filenames ~charge ~multiplicity ~nuclei:nuclei_file basis_file Simulation.of_filenames ~charge ~multiplicity ~nuclei:nuclei_file basis_file
in in
let hf = HartreeFock.make s in let hf = HartreeFock.make simulation in
Format.fprintf ppf "@[%a@]@." HartreeFock.pp hf; if Parallel.master then
Format.fprintf ppf "@[%a@]@." HartreeFock.pp hf;
let mos = let mo_basis =
MOBasis.of_hartree_fock hf MOBasis.of_hartree_fock hf
in in
let space = let frozen_core =
DeterminantSpace.fci_of_mo_basis ~frozen_core:false mos Command_line.get_bool "frozen-core"
in in
let ci = CI.make space in
Format.fprintf ppf "FCI energy : %20.16f@." ((CI.eigenvalues ci).{1} +. Simulation.nuclear_repulsion s); let space =
DeterminantSpace.fci_of_mo_basis ~frozen_core mo_basis
in
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);
(* (*
let s2 = Util.xt_o_x ~o:(CI.s2_matrix ci) ~x:(CI.eigenvectors ci) in let s2 = Util.xt_o_x ~o:(CI.s2_matrix ci) ~x:(CI.eigenvectors ci) in
Util.list_range 1 (DeterminantSpace.size space) Util.list_range 1 (DeterminantSpace.size space)
|> List.iter (fun i -> Format.printf "@[%f@]@;" s2.{i,i}); |> List.iter (fun i -> Format.printf "@[%f@]@;" s2.{i,i});
*) *)
Format.fprintf ppf "@.";