10
0
mirror of https://github.com/LCPQ/quantum_package synced 2024-12-22 20:35:19 +01:00

Working on qp_edit

This commit is contained in:
Anthony Scemama 2014-10-29 00:12:45 +01:00
parent b983563551
commit b74a8f1035
16 changed files with 287 additions and 69 deletions

View File

@ -37,7 +37,7 @@ let read_element in_channel at_number element =
let to_string b = let to_string b =
let new_nucleus n = let new_nucleus n =
Printf.sprintf "Atom %d:" n Printf.sprintf "Atom %d" n
in in
let rec do_work accu current_nucleus = function let rec do_work accu current_nucleus = function

54
ocaml/Determinant.ml Normal file
View File

@ -0,0 +1,54 @@
open Core.Std;;
open Qptypes;;
type t = int64 array with sexp
let to_int64_array (x:t) = (x:int64 array)
;;
let of_int64_array n_int x =
assert ((Array.length x) = (N_int_number.to_int n_int)*2) ;
x
;;
let to_alpha_beta x =
let x = to_int64_array x in
let n_int = (Array.length x)/2 in
( Array.init n_int ~f:(fun i -> x.(i)) ,
Array.init n_int ~f:(fun i -> x.(i+n_int)) )
;;
let to_bitlist_couple x =
let (xa,xb) = to_alpha_beta x in
let xa = to_int64_array xa
|> Array.to_list
|> Bitlist.of_int64_list
and xb = to_int64_array xb
|> Array.to_list
|> Bitlist.of_int64_list
in (xa,xb)
;;
let of_bitlist_couple (xa,xb) =
let ba = Bitlist.to_int64_list xa in
let bb = Bitlist.to_int64_list xb in
let n_int = Bitlist.n_int_of_mo_tot_num (List.length ba) in
of_int64_array n_int (Array.of_list (ba@bb))
;;
let bitlist_to_string ~mo_tot_num x =
List.map x ~f:(fun i -> match i with
| Bit.Zero -> "-"
| Bit.One -> "+" )
|> String.concat
|> String.sub ~pos:0 ~len:(MO_number.to_int mo_tot_num)
;;
let to_string ~mo_tot_num x =
let (xa,xb) = to_bitlist_couple x in
[ bitlist_to_string ~mo_tot_num:mo_tot_num xa ;
bitlist_to_string ~mo_tot_num:mo_tot_num xb ]
|> String.concat ~sep:"\n"
;;

26
ocaml/Determinant.mli Normal file
View File

@ -0,0 +1,26 @@
(** Determinants are stored as follows :
* <-------- N_int ---------->
* [| i1_alpha ; i2_alpha ; ... ;
* i1_beta ; i2_beta ; ... ; |]
* where each int64 is a list of 64 MOs. When the bit is set
* to 1, the MO is occupied.
*)
type t = int64 array with sexp
(** Transform to an int64 array *)
val to_int64_array : t -> int64 array
(** Create from an int64 array *)
val of_int64_array : Qptypes.N_int_number.t -> int64 array -> t
(** Split into an alpha-only and a beta-only determinant *)
val to_alpha_beta : t -> (int64 array)*(int64 array)
(** Transform to a bit list *)
val to_bitlist_couple : t -> Bitlist.t * Bitlist.t
(** Create from a bit list *)
val of_bitlist_couple : Bitlist.t * Bitlist.t -> t
(** String representation *)
val to_string : mo_tot_num:Qptypes.MO_number.t -> t -> string

View File

@ -142,8 +142,21 @@ end = struct
let to_string b = let to_string b =
let short_basis = to_basis b in let short_basis = to_basis b in
Printf.sprintf "Basis name : %s\n\n%s\n" b.ao_basis Printf.sprintf "
(Basis.to_string short_basis) Name of the AO basis ::
ao_basis = %s
Basis set ::
%s
" b.ao_basis
(Basis.to_string short_basis
|> String.split ~on:'\n'
|> List.map ~f:(fun x-> " "^x)
|> String.concat ~sep:"\n"
)
;; ;;
let to_md5 b = let to_md5 b =

View File

@ -115,13 +115,26 @@ end = struct
;; ;;
let to_string b = let to_string b =
Printf.sprintf "read_ao_integrals = %s Printf.sprintf "
read_mo_integrals = %s Read AO/MO integrals from disk ::
write_ao_integrals = %s
write_mo_integrals = %s read_ao_integrals = %s
threshold_ao = %s read_mo_integrals = %s
threshold_mo = %s
direct = %s Write AO/MO integrals to disk ::
write_ao_integrals = %s
write_mo_integrals = %s
Thresholds on integrals ::
threshold_ao = %s
threshold_mo = %s
Direct calculation of integrals ::
direct = %s
" "
(Bool.to_string b.read_ao_integrals) (Bool.to_string b.read_ao_integrals)
(Bool.to_string b.read_mo_integrals) (Bool.to_string b.read_mo_integrals)

View File

@ -95,12 +95,27 @@ end = struct
let to_string b = let to_string b =
Printf.sprintf " Printf.sprintf "
n_state_cis = %s Number of states ::
n_core_cis = %s
n_act_cis = %s n_state_cis = %s
mp2_dressing = %s
standard_doubles = %s Core and active MOs ::
en_2_2 = %s
n_core_cis = %s
n_act_cis = %s
Dress with MP2 perturbation ::
mp2_dressing = %s
Use standard double-excitations ::
standard_doubles = %s
Epstein-Nesbet 2x2 diagonalization ::
en_2_2 = %s
" "
(States_number.to_string b.n_state_cis) (States_number.to_string b.n_state_cis)
(Positive_int.to_string b.n_core_cis) (Positive_int.to_string b.n_core_cis)

View File

@ -61,9 +61,19 @@ end = struct
;; ;;
let to_string b = let to_string b =
Printf.sprintf "n_det_max_cisd_sc2 = %s Printf.sprintf "
pt2_max = %s Stop when the `n_det` > `n_det_max_cisd_sc2` ::
do_pt2_end = %s
n_det_max_cisd_sc2 = %s
Stop when -E(PT2) < `pt2_max` ::
pt2_max = %s
Compute E(PT2) at the end ::
do_pt2_end = %s
" "
(Det_number_max.to_string b.n_det_max_cisd_sc2) (Det_number_max.to_string b.n_det_max_cisd_sc2)
(PT2_energy.to_string b.pt2_max) (PT2_energy.to_string b.pt2_max)

View File

@ -22,6 +22,7 @@ module Determinants : sig
;; ;;
val read : unit -> t val read : unit -> t
val to_string : t -> string val to_string : t -> string
val debug : t -> string
end = struct end = struct
type t = type t =
{ n_int : N_int_number.t; { n_int : N_int_number.t;
@ -191,12 +192,12 @@ end = struct
Ezfio.ezfio_array_of_list ~rank:3 ~dim:[| N_int_number.to_int n_int ; 2 ; 1 |] ~data:data Ezfio.ezfio_array_of_list ~rank:3 ~dim:[| N_int_number.to_int n_int ; 2 ; 1 |] ~data:data
|> Ezfio.set_determinants_psi_det |> Ezfio.set_determinants_psi_det
end ; end ;
let n_int = N_int_number.to_int n_int in (*
let rec transform accu1 accu2 n_rest = function let rec transform accu1 accu2 n_rest = function
| [] -> | [] ->
let accu1 = List.rev accu1 let accu1 = List.rev accu1
|> Array.of_list |> Array.of_list
|> Determinant.of_int64_array |> Determinant.of_int64_array n_int
in in
List.rev (accu1::accu2) |> Array.of_list List.rev (accu1::accu2) |> Array.of_list
| i::rest -> | i::rest ->
@ -205,14 +206,25 @@ end = struct
else else
let accu1 = List.rev accu1 let accu1 = List.rev accu1
|> Array.of_list |> Array.of_list
|> Determinant.of_int64_array |> Determinant.of_int64_array n_int
in in
let n_int = N_int_number.to_int n_int in
transform [] (accu1::accu2) (2*n_int) rest transform [] (accu1::accu2) (2*n_int) rest
in in
(Ezfio.get_determinants_psi_det ()).Ezfio.data *)
|> Ezfio.flattened_ezfio_data let n_int = N_int_number.to_int n_int in
|> Array.to_list let psi_det_array = Ezfio.get_determinants_psi_det () in
|> transform [] [] (2*n_int) let dim = psi_det_array.Ezfio.dim
and data = Ezfio.flattened_ezfio_data psi_det_array.Ezfio.data
in
assert (n_int = dim.(0));
assert (dim.(1) = 2);
assert (dim.(2) = (Det_number.to_int (read_n_det ())));
List.init dim.(2) ~f:(fun i ->
Array.sub ~pos:(2*n_int*i) ~len:(2*n_int) data)
|> List.map ~f:(Determinant.of_int64_array
(N_int_number.of_int n_int))
|> Array.of_list
;; ;;
let read () = let read () =
@ -234,30 +246,74 @@ end = struct
;; ;;
let to_string b = let to_string b =
Printf.sprintf "read_wf = %s let mo_tot_num = Ezfio.get_mo_basis_mo_tot_num ()
n_det = %s |> MO_number.of_int in
n_states = %s let det_text =
threshold_generators = %s List.map2_exn ~f:(fun coef det ->
threshold_selectors = %s Printf.sprintf " %f\n%s\n"
n_det_max_jacobi = %s (Det_coef.to_float coef)
n_states_diag = %s (Determinant.to_string ~mo_tot_num:mo_tot_num det
s2_eig = %s |> String.split ~on:'\n'
expected_s2 = %s |> List.map ~f:(fun x -> " "^x)
mo_label = \"%s\" |> String.concat ~sep:"\n"
)
) (Array.to_list b.psi_coef) (Array.to_list b.psi_det)
|> String.concat ~sep:"\n"
in
Printf.sprintf "
Read the current wave function ::
read_wf = %s
Label of the MOs on which the determinants were computed ::
mo_label = %s
Force the selected wave function to be an eigenfunction of S^2.
If true, input the expected value of S^2 ::
s2_eig = %s
expected_s2 = %s
Thresholds on generators and selectors (fraction of the norm) ::
threshold_generators = %s
threshold_selectors = %s
Number of requested states, and number of states used for the
Davidson diagonalization ::
n_states = %s
n_states_diag = %s
Maximum size of the Hamiltonian matrix that will be fully diagonalized ::
n_det_max_jacobi = %s
Number of determinants ::
n_det = %s
Determinants ::
%s
" "
(b.read_wf |> Bool.to_string) (b.read_wf |> Bool.to_string)
(b.n_det |> Det_number.to_string) (b.mo_label |> Non_empty_string.to_string)
(b.n_states |> States_number.to_string)
(b.threshold_generators |> Threshold.to_string)
(b.threshold_selectors |> Threshold.to_string)
(b.n_det_max_jacobi |> Strictly_positive_int.to_string)
(b.n_states_diag |> States_number.to_string)
(b.s2_eig |> Bool.to_string) (b.s2_eig |> Bool.to_string)
(b.expected_s2 |> Positive_float.to_string) (b.expected_s2 |> Positive_float.to_string)
(b.mo_label |> Non_empty_string.to_string) (b.threshold_generators |> Threshold.to_string)
(b.threshold_selectors |> Threshold.to_string)
(b.n_states |> States_number.to_string)
(b.n_states_diag |> States_number.to_string)
(b.n_det_max_jacobi |> Strictly_positive_int.to_string)
(b.n_det |> Det_number.to_string)
det_text
;; ;;
let debug b = let debug b =
let mo_tot_num = Ezfio.get_mo_basis_mo_tot_num ()
|> MO_number.of_int in
Printf.sprintf " Printf.sprintf "
n_int = %s n_int = %s
bit_kind = %s bit_kind = %s
@ -288,11 +344,8 @@ psi_det = %s
(b.s2_eig |> Bool.to_string) (b.s2_eig |> Bool.to_string)
(b.psi_coef |> Array.to_list |> List.map ~f:Det_coef.to_string (b.psi_coef |> Array.to_list |> List.map ~f:Det_coef.to_string
|> String.concat ~sep:", ") |> String.concat ~sep:", ")
(b.psi_det |> Array.map ~f:(fun x -> Determinant.to_int64_array x (b.psi_det |> Array.to_list |> List.map ~f:(Determinant.to_string
|> Array.map ~f:(fun x-> ~mo_tot_num:mo_tot_num) |> String.concat ~sep:"\n\n")
Int64.to_string x )|> Array.to_list |>
String.concat ~sep:", ") |> Array.to_list
|> String.concat ~sep:" | ")
;; ;;
end end

View File

@ -47,9 +47,17 @@ end = struct
;; ;;
let to_string b = let to_string b =
Printf.sprintf "elec_alpha_num = %s Printf.sprintf "
elec_beta_num = %s Spin multiplicity is %s.
Number of alpha and beta electrons ::
elec_alpha_num = %s
elec_beta_num = %s
" "
(Multiplicity.of_alpha_beta b.elec_alpha_num b.elec_beta_num
|> Multiplicity.to_string)
(Elec_alpha_number.to_string b.elec_alpha_num) (Elec_alpha_number.to_string b.elec_alpha_num)
(Elec_beta_number.to_string b.elec_beta_num) (Elec_beta_number.to_string b.elec_beta_num)
;; ;;

View File

@ -59,9 +59,19 @@ end = struct
;; ;;
let to_string b = let to_string b =
Printf.sprintf "n_det_max_fci = %s Printf.sprintf "
pt2_max = %s Stop when the `n_det` > `n_det_max_fci` ::
do_pt2_end = %s
n_det_max_fci = %s
Stop when -E(PT2) < `pt2_max` ::
pt2_max = %s
Compute E(PT2) at the end ::
do_pt2_end = %s
" "
(Det_number_max.to_string b.n_det_max_fci) (Det_number_max.to_string b.n_det_max_fci)
(PT2_energy.to_string b.pt2_max) (PT2_energy.to_string b.pt2_max)

View File

@ -46,8 +46,15 @@ end = struct
;; ;;
let to_string b = let to_string b =
Printf.sprintf "n_it_scf_max = %s Printf.sprintf "
thresh_scf = %s Max number of SCF iterations ::
n_it_scf_max = %s
SCF convergence criterion (on energy) ::
thresh_scf = %s
" "
(Strictly_positive_int.to_string b.n_it_scf_max) (Strictly_positive_int.to_string b.n_it_scf_max)
(Threshold.to_string b.thresh_scf) (Threshold.to_string b.thresh_scf)

View File

@ -71,8 +71,14 @@ end = struct
let to_string b = let to_string b =
Printf.sprintf " Printf.sprintf "
mo_label = %s Label of the molecular orbitals ::
mo_tot_num = %s
mo_label = %s
Total number of MOs ::
mo_tot_num = %s
" "
(Non_empty_string.to_string b.mo_label) (Non_empty_string.to_string b.mo_label)
(MO_number.to_string b.mo_tot_num) (MO_number.to_string b.mo_tot_num)

View File

@ -11,7 +11,7 @@ module Nuclei : sig
} with sexp } with sexp
;; ;;
val read : unit -> t val read : unit -> t
val to_string : t -> string val debug : t -> string
end = struct end = struct
type t = type t =
{ nucl_num : Nucl_number.t ; { nucl_num : Nucl_number.t ;
@ -65,7 +65,7 @@ end = struct
} }
;; ;;
let to_string b = let debug b =
Printf.sprintf " Printf.sprintf "
nucl_num = %s nucl_num = %s
nucl_label = %s nucl_label = %s

View File

@ -3,14 +3,14 @@ open Qptypes;;
open Core.Std;; open Core.Std;;
let instructions filename = Printf.sprintf let instructions filename = Printf.sprintf
"# =============== "
# Quantum Package ==================================================================
# =============== Quantum Package
# ==================================================================
# File : %s
# Editing file `%s`
# Lines starting with a '#' sign are commented.
#" filename " filename
type keyword = type keyword =
| Ao_basis | Ao_basis
@ -37,7 +37,7 @@ let keyword_to_string = function
let make_header kw = let make_header kw =
let s = keyword_to_string kw in let s = keyword_to_string kw in
let l = String.length s in let l = String.length s in
"\n\n# "^s^"\n"^"# "^(String.init l ~f:(fun _ -> '='))^"\n\n" "\n\n"^s^"\n"^(String.init l ~f:(fun _ -> '='))^"\n\n"
;; ;;
let get s = let get s =

View File

@ -132,6 +132,7 @@ let input_data = "
;; ;;
let untouched = " let untouched = "
(*
module Determinant : sig module Determinant : sig
type t with sexp type t with sexp
val to_int64_array : t -> int64 array val to_int64_array : t -> int64 array
@ -151,6 +152,7 @@ end = struct
|> List.map ~f:Int64.to_string |> List.map ~f:Int64.to_string
|> String.concat ~sep:\", \" |> String.concat ~sep:\", \"
end end
*)
" "

View File

@ -39,6 +39,7 @@ let test_dets () =
Ezfio.set_file "F2.ezfio" ; Ezfio.set_file "F2.ezfio" ;
let b = Input.Determinants.read () let b = Input.Determinants.read ()
in in
(*print_endline (Input.Determinants.debug b);*)
print_endline (Input.Determinants.to_string b); print_endline (Input.Determinants.to_string b);
;; ;;
@ -95,5 +96,5 @@ test_hf ();;
test_mo ();; test_mo ();;
test_nucl (); test_nucl ();
*) *)
test_ao ();; test_dets();;