From 06efe7ca16332e560e16115e80abc2571e7b41d0 Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Wed, 12 Apr 2017 14:46:12 +0200 Subject: [PATCH] Added -state option to qp_edit --- ocaml/Input_determinants_by_hand.ml | 38 ++++++++++++++++++-- plugins/Full_CI_ZMQ/pt2_stoch_routines.irp.f | 8 +++-- scripts/ezfio_interface/qp_edit_template | 20 +++++++---- 3 files changed, 54 insertions(+), 12 deletions(-) diff --git a/ocaml/Input_determinants_by_hand.ml b/ocaml/Input_determinants_by_hand.ml index 64376a26..6cc83745 100644 --- a/ocaml/Input_determinants_by_hand.ml +++ b/ocaml/Input_determinants_by_hand.ml @@ -20,6 +20,7 @@ module Determinants_by_hand : sig val of_rst : Rst_string.t -> t option val read_n_int : unit -> N_int_number.t val update_ndet : Det_number.t -> unit + val extract_state : States_number.t -> unit end = struct type t = { n_int : N_int_number.t; @@ -132,12 +133,12 @@ end = struct |> Array.map ~f:Det_coef.of_float ;; - let write_psi_coef ~n_det c = + let write_psi_coef ~n_det ~n_states c = let n_det = Det_number.to_int n_det and c = Array.to_list c |> List.map ~f:Det_coef.to_float and n_states = - read_n_states () |> States_number.to_int + States_number.to_int n_states in Ezfio.ezfio_array_of_list ~rank:2 ~dim:[| n_det ; n_states |] ~data:c |> Ezfio.set_determinants_psi_coef @@ -233,7 +234,7 @@ end = struct write_n_det n_det; write_n_states n_states; write_expected_s2 expected_s2; - write_psi_coef ~n_det:n_det psi_coef ; + write_psi_coef ~n_det:n_det ~n_states:n_states psi_coef ; write_psi_det ~n_int:n_int ~n_det:n_det psi_det; ;; @@ -455,6 +456,7 @@ psi_det = %s ;; let update_ndet n_det_new = + Printf.printf "Reducing n_det to %d\n" (Det_number.to_int n_det_new); let n_det_new = Det_number.to_int n_det_new in @@ -487,6 +489,36 @@ psi_det = %s write new_det ;; + let extract_state istate = + Printf.printf "Extracting state %d\n" (States_number.to_int istate); + let det = + read () + in + let n_det, n_states = + Det_number.to_int det.n_det, + States_number.to_int det.n_states + in + if (States_number.to_int istate) > n_states then + failwith "State to extract should not be greater than n_states" + ; + let j = + (States_number.to_int istate) - 1 + in + begin + if (j>0) then + let ishift = + j*n_det + in + for i=0 to (n_det-1) do + det.psi_coef.(i) <- det.psi_coef.(i+ishift) + done + end; + let new_det = + { det with n_states = (States_number.of_int 1) } + in + write new_det + ;; + end diff --git a/plugins/Full_CI_ZMQ/pt2_stoch_routines.irp.f b/plugins/Full_CI_ZMQ/pt2_stoch_routines.irp.f index eb706ccb..fe13390d 100644 --- a/plugins/Full_CI_ZMQ/pt2_stoch_routines.irp.f +++ b/plugins/Full_CI_ZMQ/pt2_stoch_routines.irp.f @@ -32,7 +32,7 @@ subroutine ZMQ_pt2(pt2,relative_error) sum2above = 0d0 Nabove = 0d0 - provide nproc fragment_first fragment_count mo_bielec_integrals_in_map mo_mono_elec_integral + provide nproc fragment_first fragment_count mo_bielec_integrals_in_map mo_mono_elec_integral pt2_weight !call random_seed() @@ -515,8 +515,10 @@ end subroutine pt2_cweight(i) = pt2_cweight(i-1) + psi_coef_generators(i,1)**2 end do - pt2_weight = pt2_weight / pt2_cweight(N_det_generators) - pt2_cweight = pt2_cweight / pt2_cweight(N_det_generators) + do i=1,N_det_generators + pt2_weight(i) = pt2_weight(i) / pt2_cweight(N_det_generators) + pt2_cweight(i) = pt2_cweight(i) / pt2_cweight(N_det_generators) + enddo norm_left = 1d0 diff --git a/scripts/ezfio_interface/qp_edit_template b/scripts/ezfio_interface/qp_edit_template index f3829e6b..af9b295c 100644 --- a/scripts/ezfio_interface/qp_edit_template +++ b/scripts/ezfio_interface/qp_edit_template @@ -144,13 +144,13 @@ let create_temp_file ezfio_filename fields = -let run check_only ?ndet ezfio_filename = +let run check_only ?ndet ?state ezfio_filename = (* Set check_only if the arguments are not empty *) let check_only = - match ndet with - | None -> check_only - | Some _ -> true + match ndet, state with + | None, None -> check_only + | _ -> true in (* Open EZFIO *) @@ -165,6 +165,12 @@ let run check_only ?ndet ezfio_filename = | Some n -> Input.Determinants_by_hand.update_ndet (Det_number.of_int n) end; + begin + match state with + | None -> () + | Some n -> Input.Determinants_by_hand.extract_state (States_number.of_int n) + end; + (* let output = (file_header ezfio_filename) :: ( @@ -244,6 +250,8 @@ let spec = ~doc:"Checks the input data" +> flag "ndet" (optional int) ~doc:"int Truncate the wavefunction to the target number of determinants" + +> flag "state" (optional int) + ~doc:"int Pick the state as a new wavefunction." +> anon ("ezfio_file" %: string) @@ -262,9 +270,9 @@ Edit input data with | _ msg -> print_string ("\n\nError\n\n"^msg^"\n\n") *) - (fun c ndet ezfio_file () -> + (fun c ndet state ezfio_file () -> try - run c ?ndet ezfio_file ; + run c ?ndet ?state ezfio_file ; (* create_backup ezfio_file; *) with | Failure exc