From bc04139a543371b18bfa3421ff602cd492753867 Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Thu, 5 Mar 2020 16:19:20 +0100 Subject: [PATCH] Started working on OCaml. Need to go further for qp_edit --- ocaml/Input_determinants_by_hand.ml | 100 ++++++++++++++++++---------- ocaml/Input_mo_basis.ml | 14 ++-- 2 files changed, 71 insertions(+), 43 deletions(-) diff --git a/ocaml/Input_determinants_by_hand.ml b/ocaml/Input_determinants_by_hand.ml index dee338e3..3ed6429d 100644 --- a/ocaml/Input_determinants_by_hand.ml +++ b/ocaml/Input_determinants_by_hand.ml @@ -37,7 +37,9 @@ end = struct } [@@deriving sexp] ;; - let get_default = Qpackage.get_ezfio_default "determinants";; + let get_default = Qpackage.get_ezfio_default "determinants" + + let is_complex = lazy (Ezfio.get_nuclei_is_complex () ) let read_n_int () = if not (Ezfio.has_determinants_n_int()) then @@ -48,12 +50,12 @@ end = struct ; Ezfio.get_determinants_n_int () |> N_int_number.of_int - ;; + let write_n_int n = N_int_number.to_int n |> Ezfio.set_determinants_n_int - ;; + let read_bit_kind () = @@ -64,12 +66,12 @@ end = struct ; Ezfio.get_determinants_bit_kind () |> Bit_kind.of_int - ;; + let write_bit_kind b = Bit_kind.to_int b |> Ezfio.set_determinants_bit_kind - ;; + let read_n_det () = if not (Ezfio.has_determinants_n_det ()) then @@ -77,7 +79,7 @@ end = struct ; Ezfio.get_determinants_n_det () |> Det_number.of_int - ;; + let read_n_det_qp_edit () = if not (Ezfio.has_determinants_n_det_qp_edit ()) then @@ -87,18 +89,18 @@ end = struct end; Ezfio.get_determinants_n_det_qp_edit () |> Det_number.of_int - ;; + let write_n_det n = Det_number.to_int n |> Ezfio.set_determinants_n_det - ;; + let write_n_det_qp_edit n = let n_det = read_n_det () |> Det_number.to_int in min n_det (Det_number.to_int n) |> Ezfio.set_determinants_n_det_qp_edit - ;; + let read_n_states () = if not (Ezfio.has_determinants_n_states ()) then @@ -106,7 +108,7 @@ end = struct ; Ezfio.get_determinants_n_states () |> States_number.of_int - ;; + let write_n_states n = let n_states = @@ -130,7 +132,7 @@ end = struct Ezfio.ezfio_array_of_list ~rank:1 ~dim:[| n_states |] ~data |> Ezfio.set_determinants_state_average_weight end - ;; + let write_state_average_weight data = let n_states = @@ -143,7 +145,7 @@ end = struct in Ezfio.ezfio_array_of_list ~rank:1 ~dim:[| n_states |] ~data |> Ezfio.set_determinants_state_average_weight - ;; + let read_state_average_weight () = let n_states = @@ -171,7 +173,7 @@ end = struct |> Array.map Positive_float.of_float in (write_state_average_weight data; data) - ;; + let read_expected_s2 () = if not (Ezfio.has_determinants_expected_s2 ()) then @@ -186,12 +188,12 @@ end = struct ; Ezfio.get_determinants_expected_s2 () |> Positive_float.of_float - ;; + let write_expected_s2 s2 = Positive_float.to_float s2 |> Ezfio.set_determinants_expected_s2 - ;; + let read_psi_coef ~read_only () = if not (Ezfio.has_determinants_psi_coef ()) then @@ -200,19 +202,36 @@ end = struct read_n_states () |> States_number.to_int in - Ezfio.ezfio_array_of_list ~rank:2 ~dim:[| 1 ; n_states |] - ~data:(List.init n_states (fun i -> if (i=0) then 1. else 0. )) + ( + if Lazy.force is_complex then + Ezfio.ezfio_array_of_list ~rank:2 ~dim:[| 1 ; n_states |] + ~data:(List.init (2*n_states) (fun i -> if (i=0) then 1. else 0. )) |> Ezfio.set_determinants_psi_coef + else + Ezfio.ezfio_array_of_list ~rank:3 ~dim:[| 2 ; 1 ; n_states |] + ~data:(List.init n_states (fun i -> if (i=0) then 1. else 0. )) + |> Ezfio.set_determinants_psi_coef_complex + ) end; begin if read_only then - Ezfio.get_determinants_psi_coef_qp_edit () + begin + if Lazy.force is_complex then + Ezfio.get_determinants_psi_coef_complex_qp_edit () + else + Ezfio.get_determinants_psi_coef_qp_edit () + end else - Ezfio.get_determinants_psi_coef () + begin + if Lazy.force is_complex then + Ezfio.get_determinants_psi_coef_complex () + else + Ezfio.get_determinants_psi_coef () + end end |> Ezfio.flattened_ezfio |> Array.map Det_coef.of_float - ;; + let write_psi_coef ~n_det ~n_states c = let n_det = Det_number.to_int n_det @@ -222,12 +241,23 @@ end = struct and n_states = States_number.to_int n_states in - let r = - Ezfio.ezfio_array_of_list ~rank:2 ~dim:[| n_det ; n_states |] ~data:c - in - Ezfio.set_determinants_psi_coef r; - Ezfio.set_determinants_psi_coef_qp_edit r - ;; + if Lazy.force is_complex then + begin + let r = + Ezfio.ezfio_array_of_list ~rank:3 ~dim:[| 2 ; n_det ; n_states |] ~data:c + in + Ezfio.set_determinants_psi_coef_complex r; + Ezfio.set_determinants_psi_coef_complex_qp_edit r + end + else + begin + let r = + Ezfio.ezfio_array_of_list ~rank:2 ~dim:[| n_det ; n_states |] ~data:c + in + Ezfio.set_determinants_psi_coef r; + Ezfio.set_determinants_psi_coef_qp_edit r + end + let read_psi_det ~read_only () = @@ -276,7 +306,7 @@ end = struct |> Array.map (Determinant.of_int64_array ~n_int:(N_int_number.of_int n_int) ~alpha:n_alpha ~beta:n_beta ) - ;; + let write_psi_det ~n_int ~n_det d = let data = Array.to_list d @@ -288,7 +318,7 @@ end = struct in Ezfio.set_determinants_psi_det r; Ezfio.set_determinants_psi_det_qp_edit r - ;; + let read ?(full=true) () = @@ -316,7 +346,7 @@ end = struct else (* No molecular orbitals, so no determinants *) None - ;; + let write ?(force=false) { n_int ; @@ -341,7 +371,7 @@ end = struct write_psi_det ~n_int:n_int ~n_det:n_det psi_det end; write_state_average_weight state_average_weight - ;; + let to_rst b = @@ -557,10 +587,8 @@ psi_det = %s in - - Generic_input_of_rst.evaluate_sexp t_of_sexp s - ;; + let update_ndet n_det_new = Printf.printf "Reducing n_det to %d\n" (Det_number.to_int n_det_new); @@ -596,7 +624,7 @@ psi_det = %s { det with n_det = (Det_number.of_int n_det_new) } in write ~force:true new_det - ;; + let extract_state istate = Printf.printf "Extracting state %d\n" (States_number.to_int istate); @@ -628,7 +656,7 @@ psi_det = %s { det with n_states = (States_number.of_int 1) } in write ~force:true new_det - ;; + let extract_states range = Printf.printf "Extracting states %s\n" (Range.to_string range); @@ -673,7 +701,7 @@ psi_det = %s { det with n_states = (States_number.of_int @@ List.length sorted_list) } in write ~force:true new_det - ;; + end diff --git a/ocaml/Input_mo_basis.ml b/ocaml/Input_mo_basis.ml index 46f8240e..e39aeb14 100644 --- a/ocaml/Input_mo_basis.ml +++ b/ocaml/Input_mo_basis.ml @@ -43,7 +43,7 @@ end = struct mo_coef = Array.map (fun mo -> Array.init (Array.length mo) (fun i -> mo.(ordering.(i))) - ) b.mo_coef + ) b.mo_coef } let read_ao_md5 () = @@ -73,7 +73,7 @@ end = struct let elec_alpha_num = Ezfio.get_electrons_elec_alpha_num () in - let result = + let result = Ezfio.get_mo_basis_mo_num () in if result < elec_alpha_num then @@ -116,7 +116,7 @@ end = struct let read_mo_coef () = - let a = + let a = ( if Lazy.force is_complex then Ezfio.get_mo_basis_mo_coef_complex () @@ -129,7 +129,7 @@ end = struct let mo_num = read_mo_num () |> MO_number.to_int in let ao_num = (Array.length a)/mo_num in Array.init mo_num (fun j -> - Array.sub a (j*ao_num) (ao_num) + Array.sub a (j*ao_num) (ao_num) ) @@ -247,7 +247,7 @@ mo_coef = %s (b.mo_occ |> Array.to_list |> List.map (MO_occ.to_string) |> String.concat ", " ) (b.mo_coef |> Array.map - (fun x-> Array.map MO_coef.to_string x |> + (fun x-> Array.map MO_coef.to_string x |> Array.to_list |> String.concat "," ) |> Array.to_list |> String.concat "\n" ) @@ -285,7 +285,7 @@ mo_coef = %s let write_mo_coef a = let mo_num = Array.length a in - let ao_num = + let ao_num = let x = Array.length a.(0) in if Lazy.force is_complex then x/2 else x in @@ -303,7 +303,7 @@ mo_coef = %s |> Ezfio.set_mo_basis_mo_coef ) - let write + let write { mo_num : MO_number.t ; mo_label : MO_label.t; mo_class : MO_class.t array;