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

Truncate wave function with -ndet flag of qp_edit

This commit is contained in:
Anthony Scemama 2017-04-12 13:15:44 +02:00
parent 4715857b07
commit 51cff0d890
3 changed files with 90 additions and 27 deletions

View File

@ -7,6 +7,7 @@ module Determinants_by_hand : sig
{ n_int : N_int_number.t; { n_int : N_int_number.t;
bit_kind : Bit_kind.t; bit_kind : Bit_kind.t;
n_det : Det_number.t; n_det : Det_number.t;
n_states : States_number.t;
expected_s2 : Positive_float.t; expected_s2 : Positive_float.t;
psi_coef : Det_coef.t array; psi_coef : Det_coef.t array;
psi_det : Determinant.t array; psi_det : Determinant.t array;
@ -18,11 +19,13 @@ module Determinants_by_hand : sig
val to_rst : t -> Rst_string.t val to_rst : t -> Rst_string.t
val of_rst : Rst_string.t -> t option val of_rst : Rst_string.t -> t option
val read_n_int : unit -> N_int_number.t val read_n_int : unit -> N_int_number.t
val update_ndet : Det_number.t -> unit
end = struct end = struct
type t = type t =
{ n_int : N_int_number.t; { n_int : N_int_number.t;
bit_kind : Bit_kind.t; bit_kind : Bit_kind.t;
n_det : Det_number.t; n_det : Det_number.t;
n_states : States_number.t;
expected_s2 : Positive_float.t; expected_s2 : Positive_float.t;
psi_coef : Det_coef.t array; psi_coef : Det_coef.t array;
psi_det : Determinant.t array; psi_det : Determinant.t array;
@ -200,6 +203,7 @@ end = struct
expected_s2 = read_expected_s2 () ; expected_s2 = read_expected_s2 () ;
psi_coef = read_psi_coef () ; psi_coef = read_psi_coef () ;
psi_det = read_psi_det () ; psi_det = read_psi_det () ;
n_states = read_n_states () ;
} }
else else
failwith "No molecular orbitals, so no determinants" failwith "No molecular orbitals, so no determinants"
@ -222,10 +226,12 @@ end = struct
expected_s2 ; expected_s2 ;
psi_coef ; psi_coef ;
psi_det ; psi_det ;
n_states ;
} = } =
write_n_int n_int ; write_n_int n_int ;
write_bit_kind bit_kind; write_bit_kind bit_kind;
write_n_det n_det; write_n_det n_det;
write_n_states n_states;
write_expected_s2 expected_s2; write_expected_s2 expected_s2;
write_psi_coef ~n_det:n_det psi_coef ; write_psi_coef ~n_det:n_det psi_coef ;
write_psi_det ~n_int:n_int ~n_det:n_det psi_det; write_psi_det ~n_int:n_int ~n_det:n_det psi_det;
@ -298,6 +304,7 @@ Determinants ::
n_int = %s n_int = %s
bit_kind = %s bit_kind = %s
n_det = %s n_det = %s
n_states = %s
expected_s2 = %s expected_s2 = %s
psi_coef = %s psi_coef = %s
psi_det = %s psi_det = %s
@ -305,6 +312,7 @@ psi_det = %s
(b.n_int |> N_int_number.to_string) (b.n_int |> N_int_number.to_string)
(b.bit_kind |> Bit_kind.to_string) (b.bit_kind |> Bit_kind.to_string)
(b.n_det |> Det_number.to_string) (b.n_det |> Det_number.to_string)
(b.n_states |> States_number.to_string)
(b.expected_s2 |> Positive_float.to_string) (b.expected_s2 |> Positive_float.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:", ")
@ -433,14 +441,52 @@ psi_det = %s
|> Bit_kind.to_int) |> Bit_kind.to_int)
and n_int = and n_int =
Printf.sprintf "(n_int %d)" (N_int_number.get_max ()) Printf.sprintf "(n_int %d)" (N_int_number.get_max ())
and n_states =
Printf.sprintf "(n_states %d)" (States_number.to_int @@ read_n_states ())
in in
let s = let s =
String.concat [ header ; bitkind ; n_int ; psi_coef ; psi_det] String.concat [ header ; bitkind ; n_int ; n_states ; psi_coef ; psi_det]
in in
Generic_input_of_rst.evaluate_sexp t_of_sexp s Generic_input_of_rst.evaluate_sexp t_of_sexp s
;; ;;
let update_ndet n_det_new =
let n_det_new =
Det_number.to_int n_det_new
in
let det =
read ()
in
let n_det_old, n_states =
Det_number.to_int det.n_det,
States_number.to_int det.n_states
in
if n_det_new = n_det_old then
()
;
if n_det_new > n_det_new then
failwith @@ Printf.sprintf "Requested n_det should be less than %d" n_det_old
;
for j=0 to (n_states-1) do
let ishift_old, ishift_new =
j*n_det_old,
j*n_det_new
in
for i=0 to (n_det_new-1) do
det.psi_coef.(i+ishift_new) <- det.psi_coef.(i+ishift_old)
done
done
;
let new_det =
{ det with n_det = (Det_number.of_int n_det_new) }
in
write new_det
;;
end end

View File

@ -3,7 +3,7 @@
convert output of gamess/GAU$$IAN to ezfio convert output of gamess/GAU$$IAN to ezfio
Usage: Usage:
qp_convert_output_to_ezfio.py <file.out> [--ezfio=<ezfio_directory>] qp_convert_output_to_ezfio.py <file.out> [-o <ezfio_directory>]
Option: Option:
file.out is the file to check (like gamess.out) file.out is the file to check (like gamess.out)
@ -431,8 +431,8 @@ if __name__ == '__main__':
file_ = get_full_path(arguments['<file.out>']) file_ = get_full_path(arguments['<file.out>'])
if arguments["--ezfio"]: if arguments["-o"]:
ezfio_file = get_full_path(arguments["--ezfio"]) ezfio_file = get_full_path(arguments["<ezfio_directory>"])
else: else:
ezfio_file = "{0}.ezfio".format(file_) ezfio_file = "{0}.ezfio".format(file_)

View File

@ -1,6 +1,10 @@
open Qputils;; (*
open Qptypes;; vim::syntax=ocaml
open Core.Std;; *)
open Qputils
open Qptypes
open Core.Std
(** Interactive editing of the input. (** Interactive editing of the input.
@ -18,7 +22,7 @@ type keyword =
| Mo_basis | Mo_basis
| Nuclei | Nuclei
{keywords} {keywords}
;;
let keyword_to_string = function let keyword_to_string = function
@ -28,7 +32,7 @@ let keyword_to_string = function
| Mo_basis -> "MO basis" | Mo_basis -> "MO basis"
| Nuclei -> "Molecule" | Nuclei -> "Molecule"
{keywords_to_string} {keywords_to_string}
;;
@ -42,7 +46,7 @@ let file_header filename =
Editing file `%s` Editing file `%s`
" filename " filename
;;
(** Creates the header of a section *) (** Creates the header of a section *)
@ -50,7 +54,7 @@ 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"
;;
(** Returns the rst string of section [s] *) (** Returns the rst string of section [s] *)
@ -82,7 +86,7 @@ let get s =
| Sys_error msg -> (Printf.eprintf "Info: %s\n%!" msg ; "") | Sys_error msg -> (Printf.eprintf "Info: %s\n%!" msg ; "")
in in
rst rst
;;
(** Applies the changes from the string [str] corresponding to section [s] *) (** Applies the changes from the string [str] corresponding to section [s] *)
@ -121,7 +125,7 @@ let set str s =
| Ao_basis -> () (* TODO *) | Ao_basis -> () (* TODO *)
| Mo_basis -> () (* TODO *) | Mo_basis -> () (* TODO *)
end end
;;
(** Creates the temporary file for interactive editing *) (** Creates the temporary file for interactive editing *)
@ -135,11 +139,19 @@ let create_temp_file ezfio_filename fields =
) )
end end
; temp_filename ; temp_filename
;;
let run check_only ezfio_filename =
let run check_only ?ndet ezfio_filename =
(* Set check_only if the arguments are not empty *)
let check_only =
match ndet with
| None -> check_only
| Some _ -> true
in
(* Open EZFIO *) (* Open EZFIO *)
if (not (Sys.file_exists_exn ezfio_filename)) then if (not (Sys.file_exists_exn ezfio_filename)) then
@ -147,6 +159,13 @@ let run check_only ezfio_filename =
Ezfio.set_file ezfio_filename; Ezfio.set_file ezfio_filename;
begin
match ndet with
| None -> ()
| Some n -> Input.Determinants_by_hand.update_ndet (Det_number.of_int n)
end;
(* (*
let output = (file_header ezfio_filename) :: ( let output = (file_header ezfio_filename) :: (
List.map ~f:get [ List.map ~f:get [
@ -196,7 +215,7 @@ let run check_only ezfio_filename =
(* Remove temp_file *) (* Remove temp_file *)
Sys.remove temp_filename Sys.remove temp_filename
;;
(** Create a backup file in case of an exception *) (** Create a backup file in case of an exception *)
@ -207,7 +226,7 @@ let create_backup ezfio_filename =
" "
ezfio_filename ezfio_filename ezfio_filename ezfio_filename ezfio_filename ezfio_filename
|> Sys.command_exn |> Sys.command_exn
;;
(** Restore the backup file when an exception occuprs *) (** Restore the backup file when an exception occuprs *)
@ -215,7 +234,7 @@ let restore_backup ezfio_filename =
Printf.sprintf "tar -zxf %s/backup.tgz" Printf.sprintf "tar -zxf %s/backup.tgz"
ezfio_filename ezfio_filename
|> Sys.command_exn |> Sys.command_exn
;;
let spec = let spec =
@ -223,12 +242,10 @@ let spec =
empty empty
+> flag "-c" no_arg +> flag "-c" no_arg
~doc:"Checks the input data" ~doc:"Checks the input data"
(* +> flag "ndet" (optional int)
+> flag "o" (optional string) ~doc:"int Truncate the wavefunction to the target number of determinants"
~doc:"Prints output data"
*)
+> anon ("ezfio_file" %: string) +> anon ("ezfio_file" %: string)
;;
let command = let command =
Command.basic Command.basic
@ -245,9 +262,9 @@ Edit input data
with with
| _ msg -> print_string ("\n\nError\n\n"^msg^"\n\n") | _ msg -> print_string ("\n\nError\n\n"^msg^"\n\n")
*) *)
(fun c ezfio_file () -> (fun c ndet ezfio_file () ->
try try
run c ezfio_file ; run c ?ndet ezfio_file ;
(* create_backup ezfio_file; *) (* create_backup ezfio_file; *)
with with
| Failure exc | Failure exc
@ -268,12 +285,12 @@ Edit input data
raise e raise e
end end
) )
;;
let () = let () =
Command.run command; Command.run command;
exit 0 exit 0
;;