From ddb60709721c98509c15be62a40584f2153aca51 Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Fri, 7 Nov 2014 13:26:47 +0100 Subject: [PATCH 01/10] Repaired irpman --- Makefile | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index bce7735c..d7ed573f 100644 --- a/Makefile +++ b/Makefile @@ -28,13 +28,14 @@ EZFIO: bin/irpf90 bin/irpf90: $(info $(BLUE)===== Fetching IRPF90 from the web ===== $(BLACK)) @sleep 1 - @$(FETCH_FROM_WEB) "$(WWW_SERVER)/$(IRPF90_TGZ)" $(IRPF90_TGZ) || \ - (echo Unable to download IRPF90 : $(WWW_SERVER)/$(IRPF90_TGZ) ; exit 1) - tar -zxf $(IRPF90_TGZ) && rm $(IRPF90_TGZ) - $(MAKE) -C irpf90 | tee install_irpf90.log - rm -rf -- $$PWD/bin/irpf90 $$PWD/bin/irpman - ln -s $$PWD/irpf90/bin/irpf90 $$PWD/bin/irpf90 - ln -s $$PWD/irpf90/bin/irpman $$PWD/bin/irpman + #@$(FETCH_FROM_WEB) "$(WWW_SERVER)/$(IRPF90_TGZ)" $(IRPF90_TGZ) || \ + # (echo Unable to download IRPF90 : $(WWW_SERVER)/$(IRPF90_TGZ) ; exit 1) + #tar -zxf $(IRPF90_TGZ) && rm $(IRPF90_TGZ) + #$(MAKE) -C irpf90 | tee install_irpf90.log + #rm -rf -- $$PWD/bin/irpf90 $$PWD/bin/irpman + echo $$PWD/irpf90/bin/irpf90 $$\@ > $$PWD/bin/irpf90 + echo $$PWD/irpf90/bin/irpman $$\@ > $$PWD/bin/irpman + chmod +x $$PWD/bin/irpf90 $$PWD/bin/irpman doc: $(MAKE) -C doc From 7db57da1fdb229a01ec3b62253d95d0e17fd9298 Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Wed, 12 Nov 2014 11:27:03 +0100 Subject: [PATCH 02/10] Link in ocaml/README.rst --- ocaml/README.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ocaml/README.rst b/ocaml/README.rst index 2f33b268..3973e31d 100644 --- a/ocaml/README.rst +++ b/ocaml/README.rst @@ -8,5 +8,6 @@ with the user. All executables start with `qp_` and all tests start with `test_`. Modules file names start with a capital letter. -Info on how to extend the `qp_edit` tool is given in `README_qp_edit.rst`. +Info on how to extend the `qp_edit` tool is given in +`README_qp_edit.rst `_. From a700718078c4087968df7cb74e3f48da89fbeedb Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Wed, 12 Nov 2014 17:17:44 +0100 Subject: [PATCH 03/10] qp_edit fails better --- ocaml/Input_bi_integrals.ml | 18 ++---------- ocaml/Input_cis.ml | 5 ++++ ocaml/Input_cisd_sc2.ml | 20 ++----------- ocaml/Input_determinants.ml | 6 ++-- ocaml/Input_electrons.ml | 18 ++---------- ocaml/Input_full_ci.ml | 18 ++---------- ocaml/Input_hartree_fock.ml | 19 ++---------- ocaml/Input_nuclei.ml | 22 +++++++------- ocaml/Makefile | 2 +- ocaml/README_qp_edit.rst | 43 ++++++++++----------------- ocaml/qp_edit.ml | 58 +++++++++++++++++-------------------- 11 files changed, 79 insertions(+), 150 deletions(-) diff --git a/ocaml/Input_bi_integrals.ml b/ocaml/Input_bi_integrals.ml index 8cc8203c..2d864aca 100644 --- a/ocaml/Input_bi_integrals.ml +++ b/ocaml/Input_bi_integrals.ml @@ -17,7 +17,7 @@ module Bielec_integrals : sig val write : t -> unit val to_string : t -> string val to_rst : t -> Rst_string.t - val of_rst : Rst_string.t -> t + val of_rst : Rst_string.t -> t option end = struct type t = { read_ao_integrals : bool; @@ -220,20 +220,8 @@ Direct calculation of integrals :: |> Rst_string.of_string ;; - let of_rst s = - let s = Rst_string.to_string s - |> String.split ~on:'\n' - |> List.filter ~f:(fun line -> - String.contains line '=') - |> List.map ~f:(fun line -> - "("^( - String.tr line ~target:'=' ~replacement:' ' - )^")" ) - |> String.concat - in - Sexp.of_string ("("^s^")") - |> t_of_sexp - ;; + include Generic_input_of_rst;; + let of_rst = of_rst t_of_sexp;; end diff --git a/ocaml/Input_cis.ml b/ocaml/Input_cis.ml index 79cf03e8..d5be2a6a 100644 --- a/ocaml/Input_cis.ml +++ b/ocaml/Input_cis.ml @@ -15,6 +15,7 @@ module Cis_dressed : sig val read : unit -> t val to_string : t -> string val to_rst : t -> Rst_string.t + val of_rst : Rst_string.t -> t option end = struct type t = { n_state_cis : States_number.t; @@ -145,6 +146,10 @@ Epstein-Nesbet 2x2 diagonalization :: |> Rst_string.of_string ;; + + include Generic_input_of_rst;; + let of_rst = of_rst t_of_sexp;; + end diff --git a/ocaml/Input_cisd_sc2.ml b/ocaml/Input_cisd_sc2.ml index 47dca5e5..6870e69d 100644 --- a/ocaml/Input_cisd_sc2.ml +++ b/ocaml/Input_cisd_sc2.ml @@ -13,7 +13,7 @@ module Cisd_sc2 : sig val write : t -> unit val to_string : t -> string val to_rst : t -> Rst_string.t - val of_rst : Rst_string.t -> t + val of_rst : Rst_string.t -> t option end = struct type t = { n_det_max_cisd_sc2 : Det_number_max.t; @@ -118,22 +118,8 @@ Compute E(PT2) at the end :: |> Rst_string.of_string ;; - let of_rst s = - let s = Rst_string.to_string s - |> String.split ~on:'\n' - |> List.filter ~f:(fun line -> - String.contains line '=') - |> List.map ~f:(fun line -> - "("^( - String.tr line ~target:'=' ~replacement:' ' - )^")" ) - |> String.concat - in - Sexp.of_string ("("^s^")") - |> t_of_sexp - ;; - - + include Generic_input_of_rst;; + let of_rst = of_rst t_of_sexp;; end diff --git a/ocaml/Input_determinants.ml b/ocaml/Input_determinants.ml index f4eeee6a..bc476c12 100644 --- a/ocaml/Input_determinants.ml +++ b/ocaml/Input_determinants.ml @@ -23,7 +23,7 @@ module Determinants : sig val write : t -> unit val to_string : t -> string val to_rst : t -> Rst_string.t - val of_rst : Rst_string.t -> t + val of_rst : Rst_string.t -> t option end = struct type t = { n_int : N_int_number.t; @@ -538,8 +538,8 @@ psi_det = %s and n_int = Printf.sprintf "(n_int %d)" (N_int_number.get_max ()) in let s = String.concat [ header ; bitkind ; n_int ; psi_coef ; psi_det] in - Sexp.of_string ("("^s^")") - |> t_of_sexp + + Generic_input_of_rst.evaluate_sexp t_of_sexp s ;; end diff --git a/ocaml/Input_electrons.ml b/ocaml/Input_electrons.ml index e4bc3ee2..c3480d04 100644 --- a/ocaml/Input_electrons.ml +++ b/ocaml/Input_electrons.ml @@ -13,7 +13,7 @@ module Electrons : sig val read_elec_num : unit -> Elec_number.t val to_string : t -> string val to_rst : t -> Rst_string.t - val of_rst : Rst_string.t -> t + val of_rst : Rst_string.t -> t option end = struct type t = { elec_alpha_num : Elec_alpha_number.t; @@ -91,20 +91,8 @@ elec_num = %s (Elec_number.to_string (read_elec_num ())) ;; - let of_rst s = - let s = Rst_string.to_string s - |> String.split ~on:'\n' - |> List.filter ~f:(fun line -> - String.contains line '=') - |> List.map ~f:(fun line -> - "("^( - String.tr line ~target:'=' ~replacement:' ' - )^")" ) - |> String.concat - in - Sexp.of_string ("("^s^")") - |> t_of_sexp - ;; + include Generic_input_of_rst;; + let of_rst = of_rst t_of_sexp;; end diff --git a/ocaml/Input_full_ci.ml b/ocaml/Input_full_ci.ml index 08c305c8..95c15232 100644 --- a/ocaml/Input_full_ci.ml +++ b/ocaml/Input_full_ci.ml @@ -13,7 +13,7 @@ module Full_ci : sig val write : t-> unit val to_string : t -> string val to_rst : t -> Rst_string.t - val of_rst : Rst_string.t -> t + val of_rst : Rst_string.t -> t option end = struct type t = { n_det_max_fci : Det_number_max.t; @@ -117,20 +117,8 @@ Compute E(PT2) at the end :: |> Rst_string.of_string ;; - let of_rst s = - let s = Rst_string.to_string s - |> String.split ~on:'\n' - |> List.filter ~f:(fun line -> - String.contains line '=') - |> List.map ~f:(fun line -> - "("^( - String.tr line ~target:'=' ~replacement:' ' - )^")" ) - |> String.concat - in - Sexp.of_string ("("^s^")") - |> t_of_sexp - ;; + include Generic_input_of_rst;; + let of_rst = of_rst t_of_sexp;; end diff --git a/ocaml/Input_hartree_fock.ml b/ocaml/Input_hartree_fock.ml index 56b18b31..27fd9b0e 100644 --- a/ocaml/Input_hartree_fock.ml +++ b/ocaml/Input_hartree_fock.ml @@ -12,7 +12,7 @@ module Hartree_fock : sig val write : t -> unit val to_string : t -> string val to_rst : t -> Rst_string.t - val of_rst : Rst_string.t -> t + val of_rst : Rst_string.t -> t option end = struct type t = { n_it_scf_max : Strictly_positive_int.t; @@ -93,21 +93,8 @@ SCF convergence criterion (on energy) :: |> Rst_string.of_string ;; - let of_rst s = - let s = Rst_string.to_string s - |> String.split ~on:'\n' - |> List.filter ~f:(fun line -> - String.contains line '=') - |> List.map ~f:(fun line -> - "("^( - String.tr line ~target:'=' ~replacement:' ' - )^")" ) - |> String.concat - in - Sexp.of_string ("("^s^")") - |> t_of_sexp - ;; - + include Generic_input_of_rst;; + let of_rst = of_rst t_of_sexp;; end diff --git a/ocaml/Input_nuclei.ml b/ocaml/Input_nuclei.ml index 11eeb7d4..3526d721 100644 --- a/ocaml/Input_nuclei.ml +++ b/ocaml/Input_nuclei.ml @@ -14,7 +14,7 @@ module Nuclei : sig val write : t -> unit val to_string : t -> string val to_rst : t -> Rst_string.t - val of_rst : Rst_string.t -> t + val of_rst : Rst_string.t -> t option end = struct type t = { nucl_num : Nucl_number.t ; @@ -203,15 +203,17 @@ Nuclear coordinates in xyz format (Angstroms) :: | _ -> failwith "Error in xyz format" in (* Create the Nuclei.t data structure *) - { nucl_num = List.length atom_list - |> Nucl_number.of_int ~max:nmax; - nucl_label = List.map atom_list ~f:(fun x -> - x.Atom.element) |> Array.of_list ; - nucl_charge = List.map atom_list ~f:(fun x -> - x.Atom.charge ) |> Array.of_list ; - nucl_coord = List.map atom_list ~f:(fun x -> - x.Atom.coord ) |> Array.of_list ; - } + let result = + { nucl_num = List.length atom_list + |> Nucl_number.of_int ~max:nmax; + nucl_label = List.map atom_list ~f:(fun x -> + x.Atom.element) |> Array.of_list ; + nucl_charge = List.map atom_list ~f:(fun x -> + x.Atom.charge ) |> Array.of_list ; + nucl_coord = List.map atom_list ~f:(fun x -> + x.Atom.coord ) |> Array.of_list ; + } + in Some result ;; end diff --git a/ocaml/Makefile b/ocaml/Makefile index 61e531a3..9e137a64 100644 --- a/ocaml/Makefile +++ b/ocaml/Makefile @@ -10,7 +10,7 @@ endif LIBS= PKGS= -OCAMLCFLAGS="-g" +OCAMLCFLAGS="-g -warn-error A" OCAMLBUILD=ocamlbuild -j 0 -syntax camlp4o -cflags $(OCAMLCFLAGS) -lflags $(OCAMLCFLAGS) MLFILES=$(wildcard *.ml) ezfio.ml Qptypes.ml MLIFILES=$(wildcard *.mli) diff --git a/ocaml/README_qp_edit.rst b/ocaml/README_qp_edit.rst index 4525d21a..dfadea20 100644 --- a/ocaml/README_qp_edit.rst +++ b/ocaml/README_qp_edit.rst @@ -23,9 +23,8 @@ of the block. ;; val read : unit -> t val write : t -> unit - val to_string : t -> string val to_rst : t -> Rst_string.t - val of_rst : Rst_string.t -> t + val of_rst : Rst_string.t -> t option end = struct type t = { r_x : Type_of_x.t @@ -42,12 +41,14 @@ of the block. end -The following functions need to be defined:: +The following functions need to be defined + +.. code-block:: ocaml val read : unit -> t val write : t -> unit val to_rst : t -> Rst_string.t - val of_rst : Rst_string.t -> t + val of_rst : Rst_string.t -> t option The type `t` has to be defined in a same way in the `sig` and the `struct`. @@ -135,26 +136,12 @@ Finally, create the functions to write an RST string as ;; -and you can use this function to read it back: +and you can use the generic `of_rst` function to read it back: .. code-block:: ocaml - let of_rst s = - let s = Rst_string.to_string s - |> String.split ~on:'\n' - |> List.filter ~f:(fun line -> - String.contains line '=') - |> List.map ~f:(fun line -> - "("^( - String.tr line ~target:'=' ~replacement:' ' - )^")" ) - |> String.concat - in - Sexp.of_string ("("^s^")") - |> t_of_sexp - ;; - - + include Generic_input_of_rst;; + let of_rst = of_rst t_of_sexp;; @@ -201,10 +188,11 @@ vim search strings are given in brackets. let get s = let header = (make_header s) - and rst = match s with + and rst = let open Input in + match s with ... | New_keyword -> - Input.New_keyword.(to_rst (read ())) + New_keyword.(to_rst (read ())) ... @@ -212,9 +200,10 @@ vim search strings are given in brackets. .. code-block:: ocaml - match s with - ... - | New_keyword -> - Input.New_keyword.(write (of_rst str)) + let open Input in + match s with + ... + | New_keyword -> write New_keyword.(of_rst, write) + ... ;; diff --git a/ocaml/qp_edit.ml b/ocaml/qp_edit.ml index e8c93b9f..a6241882 100644 --- a/ocaml/qp_edit.ml +++ b/ocaml/qp_edit.ml @@ -44,25 +44,26 @@ let make_header kw = let get s = let header = (make_header s) - and rst = match s with + and rst = let open Input in + match s with | Full_ci -> - Input.Full_ci.(to_rst (read ())) + Full_ci.(to_rst (read ())) | Hartree_fock -> - Input.Hartree_fock.(to_rst (read ())) + Hartree_fock.(to_rst (read ())) | Mo_basis -> - Input.Mo_basis.(to_rst (read ())) + Mo_basis.(to_rst (read ())) | Electrons -> - Input.Electrons.(to_rst (read ())) + Electrons.(to_rst (read ())) | Determinants -> - Input.Determinants.(to_rst (read ())) + Determinants.(to_rst (read ())) | Cisd_sc2 -> - Input.Cisd_sc2.(to_rst (read ())) + Cisd_sc2.(to_rst (read ())) | Nuclei -> - Input.Nuclei.(to_rst (read ())) + Nuclei.(to_rst (read ())) | Ao_basis -> - Input.Ao_basis.(to_rst (read ())) + Ao_basis.(to_rst (read ())) | Bielec_integrals -> - Input.Bielec_integrals.(to_rst (read ())) + Bielec_integrals.(to_rst (read ())) in header^(Rst_string.to_string rst) ;; @@ -81,27 +82,22 @@ let set str s = let str = String.sub ~pos:index_begin ~len:l str |> Rst_string.of_string in - match s with - (* - | Mo_basis -> - *) - | Hartree_fock -> - Input.Hartree_fock.(write (of_rst str )) - | Full_ci -> - Input.Full_ci.(write (of_rst str)) - | Electrons -> - Input.Electrons.(write (of_rst str)) - | Determinants -> - Input.Determinants.(write (of_rst str)) - | Cisd_sc2 -> - Input.Cisd_sc2.(write (of_rst str)) - | Nuclei -> - Input.Nuclei.(write (of_rst str)) - | Bielec_integrals -> - Input.Bielec_integrals.(write (of_rst str)) - (* - | Ao_basis -> - *) + let write (of_rst,w) = + match of_rst str with + | Some data -> w data + | None -> () + in + let open Input in + match s with + | Hartree_fock -> write Hartree_fock.(of_rst, write) + | Full_ci -> write Full_ci.(of_rst, write) + | Electrons -> write Electrons.(of_rst, write) + | Cisd_sc2 -> write Cisd_sc2.(of_rst, write) + | Bielec_integrals -> write Bielec_integrals.(of_rst, write) + | Determinants -> write Determinants.(of_rst, write) + | Nuclei -> write Nuclei.(of_rst, write) + | Ao_basis -> () (* TODO *) + | Mo_basis -> () (* TODO *) ;; From be4baee2e88649c0723846c621e24f5cdb2e5639 Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Wed, 12 Nov 2014 21:58:13 +0100 Subject: [PATCH 04/10] Now ocaml compiles again --- ocaml/Generic_input_of_rst.ml | 60 ++++++++++++++++++++++++++++++++ ocaml/Makefile | 2 +- ocaml/qptypes_generator.ml | 6 ++-- ocaml/test_basis.ml | 4 +-- ocaml/test_input.ml | 45 +++++++++++++++++------- src/Perturbation/selection.irp.f | 1 - 6 files changed, 99 insertions(+), 19 deletions(-) create mode 100644 ocaml/Generic_input_of_rst.ml diff --git a/ocaml/Generic_input_of_rst.ml b/ocaml/Generic_input_of_rst.ml new file mode 100644 index 00000000..81388824 --- /dev/null +++ b/ocaml/Generic_input_of_rst.ml @@ -0,0 +1,60 @@ +open Core.Std;; +open Qptypes;; + + +let fail_msg str (ex,range) = + let msg = match ex with + | Failure msg -> msg + | _ -> raise ex + in + let range = match range with + | Sexp.Annotated.Atom (range,_) -> range + | Sexp.Annotated.List (range,_,_) -> range + in + let open Sexp.Annotated in + let start_pos = range.start_pos.offset + and end_pos = range.end_pos.offset + in + let pre = String.sub ~pos:0 ~len:start_pos str + and mid = String.sub ~pos:start_pos ~len:(end_pos-start_pos) str + and post = String.sub ~pos:(end_pos) + ~len:((String.length str)-(end_pos)) str + in + let str = Printf.sprintf "%s ## %s ## %s" pre mid post + in + let str = String.tr str ~target:'(' ~replacement:' ' + |> String.split ~on:')' + |> List.map ~f:String.strip + |> List.filter ~f:(fun x -> + match String.substr_index x ~pos:0 ~pattern:"##" with + | None -> false + | Some _ -> true + ) + |> String.concat ~sep:"\n" + in + Printf.eprintf "Error: (%s)\n\n %s\n\n" msg str; +;; + + +let evaluate_sexp t_of_sexp s = + let sexp = ("("^s^")") in + match ( Sexp.of_string_conv sexp t_of_sexp ) with + | `Result r -> Some r + | `Error ex -> ( fail_msg sexp ex; None) +;; + +let of_rst t_of_sexp s = + Rst_string.to_string s + |> String.split ~on:'\n' + |> List.filter ~f:(fun line -> + String.contains line '=') + |> List.map ~f:(fun line -> + "("^( + String.tr line ~target:'=' ~replacement:' ' + )^")" ) + |> String.concat + |> evaluate_sexp t_of_sexp +;; + + + diff --git a/ocaml/Makefile b/ocaml/Makefile index 9e137a64..030fdd38 100644 --- a/ocaml/Makefile +++ b/ocaml/Makefile @@ -11,7 +11,7 @@ endif LIBS= PKGS= OCAMLCFLAGS="-g -warn-error A" -OCAMLBUILD=ocamlbuild -j 0 -syntax camlp4o -cflags $(OCAMLCFLAGS) -lflags $(OCAMLCFLAGS) +OCAMLBUILD=ocamlbuild -j 0 -syntax camlp4o -cflags $(OCAMLCFLAGS) -lflags $(OCAMLCFLAGS) -ocamlopt ocamlc.opt MLFILES=$(wildcard *.ml) ezfio.ml Qptypes.ml MLIFILES=$(wildcard *.mli) ALL_TESTS=$(patsubst %.ml,%.byte,$(wildcard test_*.ml)) diff --git a/ocaml/qptypes_generator.ml b/ocaml/qptypes_generator.ml index 63a53775..14eee88f 100644 --- a/ocaml/qptypes_generator.ml +++ b/ocaml/qptypes_generator.ml @@ -228,9 +228,9 @@ let parse_input_ezfio input= and (min, max) = String.lsplit2_exn ~on:':' c and msg = d in - let name :: typ :: ezfio_func :: min :: max :: msg :: [] = - match (name :: typ :: ezfio_func :: min :: max :: msg :: []) with - | l -> List.map ~f:String.strip l + let (name, typ, ezfio_func, min, max, msg) = + match (List.map [ name ; typ ; ezfio_func ; min ; max ; msg ] ~f:String.strip) with + | [ name ; typ ; ezfio_func ; min ; max ; msg ] -> (name, typ, ezfio_func, min, max, msg) | _ -> assert false in Printf.sprintf ezfio_template diff --git a/ocaml/test_basis.ml b/ocaml/test_basis.ml index 79492101..f58d30db 100644 --- a/ocaml/test_basis.ml +++ b/ocaml/test_basis.ml @@ -9,12 +9,12 @@ let test_module () = In_channel.create (Qpackage.root^"/data/basis/"^(String.lowercase b)) in +(* let molecule = let xyz_file = "F2.xyz" in Molecule.of_xyz_file xyz_file in - - let nuclei = molecule.Molecule.nuclei in +*) let basis = (Basis.read_element basis_channel (Nucl_number.of_int 1) Element.F) @ diff --git a/ocaml/test_input.ml b/ocaml/test_input.ml index 613f3b1a..92469c6e 100644 --- a/ocaml/test_input.ml +++ b/ocaml/test_input.ml @@ -16,7 +16,10 @@ let test_bielec_intergals () = in print_endline output; let rst = Input.Bielec_integrals.to_rst b in - let b2 = Input.Bielec_integrals.of_rst rst in + let b2 = match Input.Bielec_integrals.of_rst rst with + | Some x -> x + | None -> assert false + in if (b = b2) then print_endline "OK" else @@ -43,8 +46,11 @@ let test_dets () = in print_endline (Input.Determinants.to_rst b |> Rst_string.to_string ) ; print_endline (Input.Determinants.sexp_of_t b |> Sexplib.Sexp.to_string ) ; - let r = Input.Determinants.to_rst b in - let b2 = Input.Determinants.of_rst r in + let rst = Input.Determinants.to_rst b in + let b2 = match Input.Determinants.of_rst rst with + | Some x -> x + | None -> assert false + in if (b2 = b) then print_endline "OK" else @@ -57,7 +63,10 @@ let test_cisd_sc2 () = in print_endline (Input.Cisd_sc2.to_string b); let rst = Input.Cisd_sc2.to_rst b in - let b2 = Input.Cisd_sc2.of_rst rst in + let b2 = match Input.Cisd_sc2.of_rst rst with + | Some x -> x + | None -> assert false + in if (b = b2) then print_endline "OK" else @@ -71,8 +80,11 @@ let test_electrons () = in print_endline (Input.Electrons.to_string b); let rst = Input.Electrons.to_rst b in - let new_b = Input.Electrons.of_rst rst in - if (b = new_b) then + let b2 = match Input.Electrons.of_rst rst with + | Some x -> x + | None -> assert false + in + if (b = b2) then print_endline "OK" else print_endline "Failed in rst" @@ -84,9 +96,12 @@ let test_fci () = in print_endline (Input.Full_ci.to_string b); let rst = Input.Full_ci.to_rst b in - let new_b = Input.Full_ci.of_rst rst in + let b2 = match Input.Full_ci.of_rst rst with + | Some x -> x + | None -> assert false + in print_endline (Input.Full_ci.to_string b); - if (b = new_b) then + if (b = b2) then print_endline "OK" else print_endline "Failed in rst" @@ -98,9 +113,12 @@ let test_hf () = in print_endline (Input.Hartree_fock.to_string b); let rst = Input.Hartree_fock.to_rst b in - let new_b = Input.Hartree_fock.of_rst rst in + let b2 = match Input.Hartree_fock.of_rst rst with + | Some x -> x + | None -> assert false + in print_endline (Input.Hartree_fock.to_string b); - if (b = new_b) then + if (b = b2) then print_endline "OK" else print_endline "Failed in rst" @@ -117,9 +135,12 @@ let test_nucl () = Ezfio.set_file "F2.ezfio" ; let b = Input.Nuclei.read () in let rst = Input.Nuclei.to_rst b in - let new_b = Input.Nuclei.of_rst rst in + let b2 = match Input.Nuclei.of_rst rst with + | Some x -> x + | None -> assert false + in print_endline (Input.Nuclei.to_string b); - if (b = new_b) then + if (b = b2) then print_endline "OK" else print_endline "Failed in rst" diff --git a/src/Perturbation/selection.irp.f b/src/Perturbation/selection.irp.f index 8751b818..01d8c0af 100644 --- a/src/Perturbation/selection.irp.f +++ b/src/Perturbation/selection.irp.f @@ -148,7 +148,6 @@ subroutine make_s2_eigenfunction integer, parameter :: bufsze = 1000 logical, external :: is_in_wavefunction - print *, irp_here ! !TODO DEBUG ! do i=1,N_det ! do j=i+1,N_det From 19cf9deeb7a1c868854ff076e5efb7c065b16250 Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Thu, 13 Nov 2014 10:58:23 +0100 Subject: [PATCH 05/10] N_det-1 in bit_tmp --- src/Dets/determinants.irp.f | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Dets/determinants.irp.f b/src/Dets/determinants.irp.f index 117096c3..3a186eac 100644 --- a/src/Dets/determinants.irp.f +++ b/src/Dets/determinants.irp.f @@ -149,7 +149,7 @@ END_PROVIDER duplicate(i) = .False. enddo - do i=1,N_det + do i=1,N_det-1 if (duplicate(i)) then cycle endif From 17b443831364256eaa0f4276e8691248338cc3fa Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Fri, 14 Nov 2014 11:06:31 +0100 Subject: [PATCH 06/10] Corrected Input_determinants.ml --- ocaml/Input_determinants.ml | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/ocaml/Input_determinants.ml b/ocaml/Input_determinants.ml index bc476c12..6c47d966 100644 --- a/ocaml/Input_determinants.ml +++ b/ocaml/Input_determinants.ml @@ -131,9 +131,11 @@ end = struct |> States_number.of_int ;; - let write_n_states_diag n = - States_number.to_int n - |> Ezfio.set_determinants_n_states_diag + let write_n_states_diag ~n_states n = + let n_states = States_number.to_int n_states + and n = States_number.to_int n + in + Ezfio.set_determinants_n_states_diag (max n_states n) ;; @@ -232,20 +234,27 @@ end = struct let read_psi_coef () = if not (Ezfio.has_determinants_psi_coef ()) then - Ezfio.ezfio_array_of_list ~rank:1 ~dim:[| 1 |] ~data:[1.] - |> Ezfio.set_determinants_psi_coef - ; + begin + let n_states = + read_n_states () + |> States_number.to_int + in + Ezfio.ezfio_array_of_list ~rank:2 ~dim:[| 1 ; n_states |] + ~data:(List.init n_states ~f:(fun i -> if (i=0) then 1. else 0. )) + |> Ezfio.set_determinants_psi_coef + end; Ezfio.get_determinants_psi_coef () |> Ezfio.flattened_ezfio |> 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 = States_number.to_int n_states in - Ezfio.ezfio_array_of_list ~rank:1 ~dim:[| n_det |] ~data:c + Ezfio.ezfio_array_of_list ~rank:2 ~dim:[| n_det ; n_states |] ~data:c |> Ezfio.set_determinants_psi_coef ;; @@ -339,14 +348,14 @@ end = struct write_mo_label mo_label; write_n_det n_det; write_n_states n_states; - write_n_states_diag n_states_diag; + write_n_states_diag ~n_states:n_states n_states_diag; write_n_det_max_jacobi n_det_max_jacobi; write_threshold_generators threshold_generators; write_threshold_selectors threshold_selectors; write_read_wf read_wf; write_expected_s2 expected_s2; write_s2_eig s2_eig; - write_psi_coef ~n_det:n_det psi_coef; + write_psi_coef ~n_det:n_det psi_coef ~n_states:n_states; write_psi_det ~n_int:n_int ~n_det:n_det psi_det; ;; From 34cdca5927f384abc4f60197fef27807b030949d Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Sat, 15 Nov 2014 11:01:30 +0100 Subject: [PATCH 07/10] Alternate basis in qp_create_ezfio_from_xyz --- ocaml/qp_create_ezfio_from_xyz.ml | 43 ++++++++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 3 deletions(-) diff --git a/ocaml/qp_create_ezfio_from_xyz.ml b/ocaml/qp_create_ezfio_from_xyz.ml index 441519ea..75dd8f72 100644 --- a/ocaml/qp_create_ezfio_from_xyz.ml +++ b/ocaml/qp_create_ezfio_from_xyz.ml @@ -74,17 +74,54 @@ let run ?o b c m xyz_file = (* Write Basis set *) let basis = + + let alternate_basis_table = Hashtbl.Poly.create () in + let alternate_basis_channel element = + let key = Element.to_string element in + match Hashtbl.find alternate_basis_table key with + | Some in_channel -> + in_channel + | None -> + begin + Printf.printf "%s is not defined in basis %s.\nEnter alternate basis : %!" + (Element.to_long_string element) b ; + let bas = + match In_channel.input_line stdin with + | Some line -> String.strip line |> String.lowercase + | None -> failwith "Aborted" + in + let new_channel = In_channel.create + (Qpackage.root ^ "/data/basis/" ^ bas) + in + Hashtbl.add_exn alternate_basis_table ~key:key ~data:new_channel; + new_channel + end + in + let nmax = Nucl_number.get_max () in let rec do_work (accu:(Atom.t*Nucl_number.t) list) (n:int) = function | [] -> accu - | e::tail -> let new_accu = (e,(Nucl_number.of_int ~max:nmax n))::accu in + | e::tail -> + let new_accu = (e,(Nucl_number.of_int ~max:nmax n))::accu in do_work new_accu (n+1) tail in - do_work [] 1 nuclei + let result = do_work [] 1 nuclei |> List.rev |> List.map ~f:(fun (x,i) -> - Basis.read_element basis_channel i x.Atom.element) + try + Basis.read_element basis_channel i x.Atom.element + with + | End_of_file -> + begin + let alt_channel = alternate_basis_channel x.Atom.element in + Basis.read_element alt_channel i x.Atom.element + end + | _ -> assert false + ) |> List.concat + in + (* close all in_channels *) + result in let long_basis = Long_basis.of_basis basis in let ao_num = List.length long_basis in From 72eddc47ecea1b2f90e8f86f78b3c216cff5c61b Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Sun, 16 Nov 2014 18:05:04 +0100 Subject: [PATCH 08/10] Elaborated definition of basis name --- ocaml/qp_create_ezfio_from_xyz.ml | 112 ++++++++++++++++++++---------- 1 file changed, 75 insertions(+), 37 deletions(-) diff --git a/ocaml/qp_create_ezfio_from_xyz.ml b/ocaml/qp_create_ezfio_from_xyz.ml index 75dd8f72..7016b411 100644 --- a/ocaml/qp_create_ezfio_from_xyz.ml +++ b/ocaml/qp_create_ezfio_from_xyz.ml @@ -6,29 +6,85 @@ let spec = let open Command.Spec in empty +> flag "o" (optional string) - ~doc:"file Name of the created EZFIO file" + ~doc:"file Name of the created EZFIO file." +> flag "b" (required string) - ~doc:"name Basis set." + ~doc:"definition of basis set." +> flag "c" (optional_with_default 0 int) ~doc:"int Total charge of the molecule. Default is 0." +> flag "m" (optional_with_default 1 int) - ~doc:"int Spin multiplicity (2S+1) of the molecule. Default is 1" + ~doc:"int Spin multiplicity (2S+1) of the molecule. Default is 1." +> anon ("xyz_file" %: string) ;; let run ?o b c m xyz_file = - (* Open basis set channel *) - let basis_channel = - In_channel.create - (Qpackage.root ^ "/data/basis/" ^ (String.lowercase b)) - in - (* Read molecule *) let molecule = (Molecule.of_xyz_file xyz_file ~charge:(Charge.of_int c) ~multiplicity:(Multiplicity.of_int m) ) in + let nuclei = molecule.Molecule.nuclei in + + let basis_table = Hashtbl.Poly.create () in + (* Open basis set channels *) + let basis_channel element = + let key = Element.to_string element in + match Hashtbl.find basis_table key with + | Some in_channel -> + in_channel + | None -> + begin + Printf.printf "%s is not defined in basis %s.\nEnter alternate basis : %!" + (Element.to_long_string element) b ; + let bas = + match In_channel.input_line stdin with + | Some line -> String.strip line |> String.lowercase + | None -> failwith "Aborted" + in + let new_channel = In_channel.create + (Qpackage.root ^ "/data/basis/" ^ bas) + in + Hashtbl.add_exn basis_table ~key:key ~data:new_channel; + new_channel + end + in + + let rec build_basis = function + | [] -> () + | elem_and_basis_name :: rest -> + begin + match (String.lsplit2 ~on:':' elem_and_basis_name) with + | None -> (* Principal basis *) + begin + let new_channel = In_channel.create + (Qpackage.root ^ "/data/basis/" ^ elem_and_basis_name) + in + List.iter nuclei ~f:(fun x-> + let key = Element.to_string x.Atom.element + in + match Hashtbl.add basis_table ~key:key ~data:new_channel with + | `Ok -> () + | `Duplicate -> () + ) + end + | Some (key, basis) -> (*Aux basis *) + begin + let elem = Element.of_string key + and basis = String.lowercase basis + in + let new_channel = In_channel.create + (Qpackage.root ^ "/data/basis/" ^ basis) + in + match Hashtbl.add basis_table ~key:key ~data:new_channel with + | `Ok -> () + | `Duplicate -> failwith ("Duplicate definition of basis for "^(Element.to_long_string elem)) + end + end; + build_basis rest + in + String.split ~on:' ' b + |> List.rev_map ~f:String.strip + |> build_basis; (* Build EZFIO File name *) let ezfio_file = @@ -54,7 +110,6 @@ let run ?o b c m xyz_file = molecule.Molecule.elec_beta ) ; (* Write Nuclei *) - let nuclei = molecule.Molecule.nuclei in let labels = List.map ~f:(fun x->Element.to_string x.Atom.element) nuclei and charges = @@ -75,29 +130,6 @@ let run ?o b c m xyz_file = (* Write Basis set *) let basis = - let alternate_basis_table = Hashtbl.Poly.create () in - let alternate_basis_channel element = - let key = Element.to_string element in - match Hashtbl.find alternate_basis_table key with - | Some in_channel -> - in_channel - | None -> - begin - Printf.printf "%s is not defined in basis %s.\nEnter alternate basis : %!" - (Element.to_long_string element) b ; - let bas = - match In_channel.input_line stdin with - | Some line -> String.strip line |> String.lowercase - | None -> failwith "Aborted" - in - let new_channel = In_channel.create - (Qpackage.root ^ "/data/basis/" ^ bas) - in - Hashtbl.add_exn alternate_basis_table ~key:key ~data:new_channel; - new_channel - end - in - let nmax = Nucl_number.get_max () in let rec do_work (accu:(Atom.t*Nucl_number.t) list) (n:int) = function | [] -> accu @@ -109,11 +141,11 @@ let run ?o b c m xyz_file = |> List.rev |> List.map ~f:(fun (x,i) -> try - Basis.read_element basis_channel i x.Atom.element + Basis.read_element (basis_channel x.Atom.element) i x.Atom.element with | End_of_file -> begin - let alt_channel = alternate_basis_channel x.Atom.element in + let alt_channel = basis_channel x.Atom.element in Basis.read_element alt_channel i x.Atom.element end | _ -> assert false @@ -187,8 +219,14 @@ let run ?o b c m xyz_file = let command = Command.basic ~summary: "Quantum Package command" - ~readme:(fun () -> - "Creates an EZFIO directory from a standard xyz file + ~readme:(fun () -> " +Creates an EZFIO directory from a standard xyz file. +The basis set is defined as a single string if all the +atoms are taken from the same basis set, otherwise specific +elements can be defined as follows: + + -b \"cc-pcvdz H:cc-pvdz C:6-31g\" + ") spec (fun o b c m xyz_file () -> From a6fa9b1fb67efb9a10dd97bb1f7a153cf27b0981 Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Sun, 16 Nov 2014 18:24:20 +0100 Subject: [PATCH 09/10] Added AO_basis_name.t --- ocaml/Input_ao_basis.ml | 12 +++++------- ocaml/qptypes_generator.ml | 3 +++ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/ocaml/Input_ao_basis.ml b/ocaml/Input_ao_basis.ml index 0e61dc54..502ab0dc 100644 --- a/ocaml/Input_ao_basis.ml +++ b/ocaml/Input_ao_basis.ml @@ -4,7 +4,7 @@ open Core.Std;; module Ao_basis : sig type t = - { ao_basis : string ; + { ao_basis : AO_basis_name.t; ao_num : AO_number.t ; ao_prim_num : AO_prim_number.t array; ao_prim_num_max : AO_prim_number.t; @@ -20,7 +20,7 @@ module Ao_basis : sig val to_rst : t -> Rst_string.t end = struct type t = - { ao_basis : string ; + { ao_basis : AO_basis_name.t; ao_num : AO_number.t ; ao_prim_num : AO_prim_number.t array; ao_prim_num_max : AO_prim_number.t; @@ -34,10 +34,8 @@ end = struct let get_default = Qpackage.get_ezfio_default "ao_basis";; let read_ao_basis () = - if not (Ezfio.has_ao_basis_ao_basis ()) then - Ezfio.set_ao_basis_ao_basis "" - ; Ezfio.get_ao_basis_ao_basis () + |> AO_basis_name.of_string ;; let read_ao_num () = @@ -171,7 +169,7 @@ Basis set :: %s ======= ========= =========== -" b.ao_basis +" (AO_basis_name.to_string b.ao_basis) (Basis.to_string short_basis |> String.split ~on:'\n' |> List.map ~f:(fun x-> " "^x) @@ -213,7 +211,7 @@ ao_coef = %s ao_expo = %s md5 = %s " - b.ao_basis + (AO_basis_name.to_string b.ao_basis) (AO_number.to_string b.ao_num) (b.ao_prim_num |> Array.to_list |> List.map ~f:(AO_prim_number.to_string) |> String.concat ~sep:", " ) diff --git a/ocaml/qptypes_generator.ml b/ocaml/qptypes_generator.ml index 14eee88f..a625dade 100644 --- a/ocaml/qptypes_generator.ml +++ b/ocaml/qptypes_generator.ml @@ -100,6 +100,9 @@ let input_data = " * Rst_string : string +* AO_basis_name : string + assert (x <> \"\") ; + " ;; From 0b40cf663a13eb105b6a21d4cd24f1e09692f854 Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Thu, 27 Nov 2014 23:05:26 +0100 Subject: [PATCH 10/10] Improved qp_edit --- data/ezfio_defaults | 2 +- ocaml/Input_ao_basis.ml | 24 ++++--- ocaml/Input_bi_integrals.ml | 4 +- ocaml/Input_bitmasks.ml | 16 +++-- ocaml/Input_cis.ml | 3 +- ocaml/Input_cisd_sc2.ml | 3 +- ocaml/Input_determinants.ml | 36 +++++----- ocaml/Input_electrons.ml | 12 ++-- ocaml/Input_full_ci.ml | 9 +-- ocaml/Input_hartree_fock.ml | 3 +- ocaml/Input_mo_basis.ml | 16 +++-- ocaml/Input_nuclei.ml | 16 +++-- ocaml/qp_edit.ml | 136 +++++++++++++++++++++--------------- ocaml/qp_print.ml | 10 ++- ocaml/test_input.ml | 45 +++++++++--- 15 files changed, 206 insertions(+), 129 deletions(-) diff --git a/data/ezfio_defaults b/data/ezfio_defaults index 6aba9e85..9cc29c1b 100644 --- a/data/ezfio_defaults +++ b/data/ezfio_defaults @@ -18,7 +18,7 @@ cis_dressed determinants n_states 1 n_states_diag determinants_n_states - n_det_max_jacobi 5000 + n_det_max_jacobi 1000 threshold_generators 0.99 threshold_selectors 0.999 read_wf False diff --git a/ocaml/Input_ao_basis.ml b/ocaml/Input_ao_basis.ml index 502ab0dc..cd13fc88 100644 --- a/ocaml/Input_ao_basis.ml +++ b/ocaml/Input_ao_basis.ml @@ -14,7 +14,7 @@ module Ao_basis : sig ao_expo : AO_expo.t array; } with sexp ;; - val read : unit -> t + val read : unit -> t option val to_string : t -> string val to_md5 : t -> MD5.t val to_rst : t -> Rst_string.t @@ -93,15 +93,19 @@ end = struct ;; let read () = - { ao_basis = read_ao_basis (); - ao_num = read_ao_num () ; - ao_prim_num = read_ao_prim_num (); - ao_prim_num_max = read_ao_prim_num_max (); - ao_nucl = read_ao_nucl (); - ao_power = read_ao_power (); - ao_coef = read_ao_coef () ; - ao_expo = read_ao_expo () ; - } + if (Ezfio.has_ao_basis_ao_basis ()) then + Some + { ao_basis = read_ao_basis (); + ao_num = read_ao_num () ; + ao_prim_num = read_ao_prim_num (); + ao_prim_num_max = read_ao_prim_num_max (); + ao_nucl = read_ao_nucl (); + ao_power = read_ao_power (); + ao_coef = read_ao_coef () ; + ao_expo = read_ao_expo () ; + } + else + None ;; let to_long_basis b = diff --git a/ocaml/Input_bi_integrals.ml b/ocaml/Input_bi_integrals.ml index 2d864aca..c5fc4fe5 100644 --- a/ocaml/Input_bi_integrals.ml +++ b/ocaml/Input_bi_integrals.ml @@ -13,7 +13,7 @@ module Bielec_integrals : sig direct : bool; } with sexp ;; - val read : unit -> t + val read : unit -> t option val write : t -> unit val to_string : t -> string val to_rst : t -> Rst_string.t @@ -150,7 +150,7 @@ end = struct if (result.read_mo_integrals && result.write_mo_integrals) then failwith "Read and Write MO integrals are both true."; - result + Some result ;; let write b = diff --git a/ocaml/Input_bitmasks.ml b/ocaml/Input_bitmasks.ml index 4b02a735..f374abc8 100644 --- a/ocaml/Input_bitmasks.ml +++ b/ocaml/Input_bitmasks.ml @@ -10,7 +10,7 @@ module Bitmasks : sig generators : int64 array; } with sexp ;; - val read : unit -> t + val read : unit -> t option val to_string : t -> string end = struct type t = @@ -77,11 +77,15 @@ end = struct ;; let read () = - { n_int = read_n_int (); - bit_kind = read_bit_kind (); - n_mask_gen = read_n_mask_gen (); - generators = read_generators (); - } + if (Ezfio.has_mo_basis_mo_tot_num ()) then + Some + { n_int = read_n_int (); + bit_kind = read_bit_kind (); + n_mask_gen = read_n_mask_gen (); + generators = read_generators (); + } + else + None ;; let to_string b = diff --git a/ocaml/Input_cis.ml b/ocaml/Input_cis.ml index d5be2a6a..1094c56b 100644 --- a/ocaml/Input_cis.ml +++ b/ocaml/Input_cis.ml @@ -12,7 +12,7 @@ module Cis_dressed : sig en_2_2 : bool; } with sexp ;; - val read : unit -> t + val read : unit -> t option val to_string : t -> string val to_rst : t -> Rst_string.t val of_rst : Rst_string.t -> t option @@ -86,6 +86,7 @@ end = struct ;; let read () = + Some { n_state_cis = read_n_state_cis (); n_core_cis = read_n_core_cis (); n_act_cis = read_n_act_cis (); diff --git a/ocaml/Input_cisd_sc2.ml b/ocaml/Input_cisd_sc2.ml index 6870e69d..ed046d79 100644 --- a/ocaml/Input_cisd_sc2.ml +++ b/ocaml/Input_cisd_sc2.ml @@ -9,7 +9,7 @@ module Cisd_sc2 : sig do_pt2_end : bool; } with sexp ;; - val read : unit -> t + val read : unit -> t option val write : t -> unit val to_string : t -> string val to_rst : t -> Rst_string.t @@ -71,6 +71,7 @@ end = struct let read () = + Some { n_det_max_cisd_sc2 = read_n_det_max_cisd_sc2 (); pt2_max = read_pt2_max (); do_pt2_end = read_do_pt2_end (); diff --git a/ocaml/Input_determinants.ml b/ocaml/Input_determinants.ml index 6c47d966..bb369ec3 100644 --- a/ocaml/Input_determinants.ml +++ b/ocaml/Input_determinants.ml @@ -19,7 +19,7 @@ module Determinants : sig psi_coef : Det_coef.t array; psi_det : Determinant.t array; } with sexp - val read : unit -> t + val read : unit -> t option val write : t -> unit val to_string : t -> string val to_rst : t -> Rst_string.t @@ -311,21 +311,25 @@ end = struct let read () = - { n_int = read_n_int () ; - bit_kind = read_bit_kind () ; - mo_label = read_mo_label () ; - n_det = read_n_det () ; - n_states = read_n_states () ; - n_states_diag = read_n_states_diag () ; - n_det_max_jacobi = read_n_det_max_jacobi () ; - threshold_generators = read_threshold_generators () ; - threshold_selectors = read_threshold_selectors () ; - read_wf = read_read_wf () ; - expected_s2 = read_expected_s2 () ; - s2_eig = read_s2_eig () ; - psi_coef = read_psi_coef () ; - psi_det = read_psi_det () ; - } + if (Ezfio.has_mo_basis_mo_tot_num ()) then + Some + { n_int = read_n_int () ; + bit_kind = read_bit_kind () ; + mo_label = read_mo_label () ; + n_det = read_n_det () ; + n_states = read_n_states () ; + n_states_diag = read_n_states_diag () ; + n_det_max_jacobi = read_n_det_max_jacobi () ; + threshold_generators = read_threshold_generators () ; + threshold_selectors = read_threshold_selectors () ; + read_wf = read_read_wf () ; + expected_s2 = read_expected_s2 () ; + s2_eig = read_s2_eig () ; + psi_coef = read_psi_coef () ; + psi_det = read_psi_det () ; + } + else + None ;; let write { n_int ; diff --git a/ocaml/Input_electrons.ml b/ocaml/Input_electrons.ml index c3480d04..24d0fe00 100644 --- a/ocaml/Input_electrons.ml +++ b/ocaml/Input_electrons.ml @@ -8,7 +8,7 @@ module Electrons : sig elec_beta_num : Elec_beta_number.t; } with sexp ;; - val read : unit -> t + val read : unit -> t option val write : t -> unit val read_elec_num : unit -> Elec_number.t val to_string : t -> string @@ -53,9 +53,13 @@ end = struct let read () = - { elec_alpha_num = read_elec_alpha_num (); - elec_beta_num = read_elec_beta_num (); - } + if (Ezfio.has_electrons_elec_alpha_num ()) then + Some + { elec_alpha_num = read_elec_alpha_num (); + elec_beta_num = read_elec_beta_num (); + } + else + None ;; let write { elec_alpha_num ; elec_beta_num } = diff --git a/ocaml/Input_full_ci.ml b/ocaml/Input_full_ci.ml index 95c15232..0ee59f53 100644 --- a/ocaml/Input_full_ci.ml +++ b/ocaml/Input_full_ci.ml @@ -9,7 +9,7 @@ module Full_ci : sig do_pt2_end : bool; } with sexp ;; - val read : unit -> t + val read : unit -> t option val write : t-> unit val to_string : t -> string val to_rst : t -> Rst_string.t @@ -69,9 +69,10 @@ end = struct let read () = - { n_det_max_fci = read_n_det_max_fci (); - pt2_max = read_pt2_max (); - do_pt2_end = read_do_pt2_end (); + Some + { n_det_max_fci = read_n_det_max_fci (); + pt2_max = read_pt2_max (); + do_pt2_end = read_do_pt2_end (); } ;; diff --git a/ocaml/Input_hartree_fock.ml b/ocaml/Input_hartree_fock.ml index 27fd9b0e..845fb070 100644 --- a/ocaml/Input_hartree_fock.ml +++ b/ocaml/Input_hartree_fock.ml @@ -8,7 +8,7 @@ module Hartree_fock : sig thresh_scf : Threshold.t; } with sexp ;; - val read : unit -> t + val read : unit -> t option val write : t -> unit val to_string : t -> string val to_rst : t -> Rst_string.t @@ -54,6 +54,7 @@ end = struct let read () = + Some { n_it_scf_max = read_n_it_scf_max (); thresh_scf = read_thresh_scf (); } diff --git a/ocaml/Input_mo_basis.ml b/ocaml/Input_mo_basis.ml index d53e78b7..5ad982ac 100644 --- a/ocaml/Input_mo_basis.ml +++ b/ocaml/Input_mo_basis.ml @@ -10,7 +10,7 @@ module Mo_basis : sig mo_coef : (MO_coef.t array) array; } with sexp ;; - val read : unit -> t + val read : unit -> t option val to_string : t -> string val to_rst : t -> Rst_string.t end = struct @@ -68,11 +68,15 @@ end = struct ;; let read () = - { mo_tot_num = read_mo_tot_num (); - mo_label = read_mo_label () ; - mo_occ = read_mo_occ (); - mo_coef = read_mo_coef (); - } + if (Ezfio.has_mo_basis_mo_tot_num ()) then + Some + { mo_tot_num = read_mo_tot_num (); + mo_label = read_mo_label () ; + mo_occ = read_mo_occ (); + mo_coef = read_mo_coef (); + } + else + None ;; let mo_coef_to_string mo_coef = diff --git a/ocaml/Input_nuclei.ml b/ocaml/Input_nuclei.ml index 3526d721..cbcb9f46 100644 --- a/ocaml/Input_nuclei.ml +++ b/ocaml/Input_nuclei.ml @@ -10,7 +10,7 @@ module Nuclei : sig nucl_coord : Point3d.t array; } with sexp ;; - val read : unit -> t + val read : unit -> t option val write : t -> unit val to_string : t -> string val to_rst : t -> Rst_string.t @@ -111,11 +111,15 @@ end = struct let read () = - { nucl_num = read_nucl_num (); - nucl_label = read_nucl_label () ; - nucl_charge = read_nucl_charge (); - nucl_coord = read_nucl_coord (); - } + if (Ezfio.has_nuclei_nucl_num ()) then + Some + { nucl_num = read_nucl_num (); + nucl_label = read_nucl_label () ; + nucl_charge = read_nucl_charge (); + nucl_coord = read_nucl_coord (); + } + else + None ;; let write { nucl_num ; diff --git a/ocaml/qp_edit.ml b/ocaml/qp_edit.ml index a6241882..0aad8e5c 100644 --- a/ocaml/qp_edit.ml +++ b/ocaml/qp_edit.ml @@ -43,73 +43,93 @@ let make_header kw = ;; let get s = - let header = (make_header s) - and rst = let open Input in - match s with - | Full_ci -> - Full_ci.(to_rst (read ())) - | Hartree_fock -> - Hartree_fock.(to_rst (read ())) - | Mo_basis -> - Mo_basis.(to_rst (read ())) - | Electrons -> - Electrons.(to_rst (read ())) - | Determinants -> - Determinants.(to_rst (read ())) - | Cisd_sc2 -> - Cisd_sc2.(to_rst (read ())) - | Nuclei -> - Nuclei.(to_rst (read ())) - | Ao_basis -> - Ao_basis.(to_rst (read ())) - | Bielec_integrals -> - Bielec_integrals.(to_rst (read ())) - - in header^(Rst_string.to_string rst) + let header = (make_header s) in + let f (read,to_rst) = + match read () with + | Some text -> header ^ (Rst_string.to_string (to_rst text)) + | None -> "" + in + let rst = + try + begin + let open Input in + match s with + | Full_ci -> + f Full_ci.(read, to_rst) + | Hartree_fock -> + f Hartree_fock.(read, to_rst) + | Mo_basis -> + f Mo_basis.(read, to_rst) + | Electrons -> + f Electrons.(read, to_rst) + | Cisd_sc2 -> + f Cisd_sc2.(read, to_rst) + | Nuclei -> + f Nuclei.(read, to_rst) + | Ao_basis -> + f Ao_basis.(read, to_rst) + | Bielec_integrals -> + f Bielec_integrals.(read, to_rst) + | Determinants -> + f Determinants.(read, to_rst) + end + with + | Sys_error msg -> (Printf.eprintf "Info: %s\n%!" msg ; "") + in + rst ;; let set str s = let header = (make_header s) in - let index_begin = String.substr_index_exn ~pos:0 ~pattern:header str in - let index_begin = index_begin + (String.length header) in - let index_end = - match ( String.substr_index ~pos:(index_begin+(String.length header)+1) - ~pattern:"==" str) with - | Some i -> i - | None -> String.length str - in - let l = index_end - index_begin in - let str = String.sub ~pos:index_begin ~len:l str - |> Rst_string.of_string - in - let write (of_rst,w) = - match of_rst str with - | Some data -> w data - | None -> () - in - let open Input in - match s with - | Hartree_fock -> write Hartree_fock.(of_rst, write) - | Full_ci -> write Full_ci.(of_rst, write) - | Electrons -> write Electrons.(of_rst, write) - | Cisd_sc2 -> write Cisd_sc2.(of_rst, write) - | Bielec_integrals -> write Bielec_integrals.(of_rst, write) - | Determinants -> write Determinants.(of_rst, write) - | Nuclei -> write Nuclei.(of_rst, write) - | Ao_basis -> () (* TODO *) - | Mo_basis -> () (* TODO *) - + match String.substr_index ~pos:0 ~pattern:header str with + | None -> () + | Some idx -> + begin + let index_begin = idx + (String.length header) in + let index_end = + match ( String.substr_index ~pos:(index_begin+(String.length header)+1) + ~pattern:"==" str) with + | Some i -> i + | None -> String.length str + in + let l = index_end - index_begin in + let str = String.sub ~pos:index_begin ~len:l str + |> Rst_string.of_string + in + let write (of_rst,w) s = + try + match of_rst str with + | Some data -> w data + | None -> () + with + | _ -> (Printf.eprintf "Info: Read error in %s\n%!" + (keyword_to_string s)) + in + let open Input in + match s with + | Hartree_fock -> write Hartree_fock.(of_rst, write) s + | Full_ci -> write Full_ci.(of_rst, write) s + | Electrons -> write Electrons.(of_rst, write) s + | Cisd_sc2 -> write Cisd_sc2.(of_rst, write) s + | Bielec_integrals -> write Bielec_integrals.(of_rst, write) s + | Determinants -> write Determinants.(of_rst, write) s + | Nuclei -> write Nuclei.(of_rst, write) s + | Ao_basis -> () (* TODO *) + | Mo_basis -> () (* TODO *) + end ;; let create_temp_file ezfio_filename fields = let temp_filename = Filename.temp_file "qp_edit_" ".rst" in - Out_channel.with_file temp_filename ~f:(fun out_channel -> - (file_header ezfio_filename) :: (List.map ~f:get fields) - |> String.concat ~sep:"\n" - |> Out_channel.output_string out_channel - ); - temp_filename + begin + Out_channel.with_file temp_filename ~f:(fun out_channel -> + (file_header ezfio_filename) :: (List.map ~f:get fields) + |> String.concat ~sep:"\n" + |> Out_channel.output_string out_channel + ) + end + ; temp_filename ;; let run ezfio_filename = diff --git a/ocaml/qp_print.ml b/ocaml/qp_print.ml index 6405d0ee..4edb2f8e 100644 --- a/ocaml/qp_print.ml +++ b/ocaml/qp_print.ml @@ -51,7 +51,10 @@ let run_i ~action ezfio_filename = let compute_charge () = - let input = Input.Electrons.read () in + let input = match Input.Electrons.read () with + | Some x -> x + | None -> assert false + in let nucl_charge = Ezfio.get_nuclei_nucl_charge () |> Ezfio.flattened_ezfio |> Array.map ~f:(Float.to_int) and n_alpha = input.Input.Electrons.elec_alpha_num @@ -63,7 +66,10 @@ let run_i ~action ezfio_filename = in let compute_multiplicity () = - let input = Input.Electrons.read () in + let input = match Input.Electrons.read () with + | Some x -> x + | None -> assert false + in let n_alpha = input.Input.Electrons.elec_alpha_num and n_beta = input.Input.Electrons.elec_beta_num in Multiplicity.of_alpha_beta n_alpha n_beta diff --git a/ocaml/test_input.ml b/ocaml/test_input.ml index 92469c6e..a2351321 100644 --- a/ocaml/test_input.ml +++ b/ocaml/test_input.ml @@ -2,7 +2,9 @@ open Qptypes;; let test_ao () = Ezfio.set_file "F2.ezfio" ; - let b = Input.Ao_basis.read () + let b = match Input.Ao_basis.read () with + | Some x -> x + | None -> assert false in print_endline (Input.Ao_basis.to_string b); print_endline (Input.Ao_basis.to_rst b |> Rst_string.to_string); @@ -10,7 +12,9 @@ let test_ao () = let test_bielec_intergals () = Ezfio.set_file "F2.ezfio" ; - let b = Input.Bielec_integrals.read () + let b = match Input.Bielec_integrals.read () with + | Some x -> x + | None -> assert false in let output = Input.Bielec_integrals.to_string b in @@ -28,21 +32,27 @@ let test_bielec_intergals () = let test_bitmasks () = Ezfio.set_file "F2.ezfio" ; - let b = Input.Bitmasks.read () + let b = match Input.Bitmasks.read () with + | Some x -> x + | None -> assert false in print_endline (Input.Bitmasks.to_string b); ;; let test_cis () = Ezfio.set_file "F2.ezfio" ; - let b = Input.Cis_dressed.read () + let b = match Input.Cis_dressed.read () with + | Some x -> x + | None -> assert false in print_endline (Input.Cis_dressed.to_string b); ;; let test_dets () = Ezfio.set_file "F2.ezfio" ; - let b = Input.Determinants.read () + let b = match Input.Determinants.read () with + | Some x -> x + | None -> assert false in print_endline (Input.Determinants.to_rst b |> Rst_string.to_string ) ; print_endline (Input.Determinants.sexp_of_t b |> Sexplib.Sexp.to_string ) ; @@ -59,7 +69,9 @@ let test_dets () = let test_cisd_sc2 () = Ezfio.set_file "F2.ezfio" ; - let b = Input.Cisd_sc2.read () + let b = match Input.Cisd_sc2.read () with + | Some x -> x + | None -> assert false in print_endline (Input.Cisd_sc2.to_string b); let rst = Input.Cisd_sc2.to_rst b in @@ -76,7 +88,9 @@ let test_cisd_sc2 () = let test_electrons () = Ezfio.set_file "F2.ezfio" ; - let b = Input.Electrons.read () + let b = match Input.Electrons.read () with + | Some x -> x + | None -> assert false in print_endline (Input.Electrons.to_string b); let rst = Input.Electrons.to_rst b in @@ -92,7 +106,9 @@ let test_electrons () = let test_fci () = Ezfio.set_file "F2.ezfio" ; - let b = Input.Full_ci.read () + let b = match Input.Full_ci.read () with + | Some x -> x + | None -> assert false in print_endline (Input.Full_ci.to_string b); let rst = Input.Full_ci.to_rst b in @@ -109,7 +125,9 @@ let test_fci () = let test_hf () = Ezfio.set_file "F2.ezfio" ; - let b = Input.Hartree_fock.read () + let b = match Input.Hartree_fock.read () with + | Some x -> x + | None -> assert false in print_endline (Input.Hartree_fock.to_string b); let rst = Input.Hartree_fock.to_rst b in @@ -126,14 +144,19 @@ let test_hf () = let test_mo () = Ezfio.set_file "F2.ezfio" ; - let b = Input.Mo_basis.read () + let b = match Input.Mo_basis.read () with + | Some x -> x + | None -> assert false in print_endline (Input.Mo_basis.to_string b); ;; let test_nucl () = Ezfio.set_file "F2.ezfio" ; - let b = Input.Nuclei.read () in + let b = match Input.Nuclei.read () with + | Some x -> x + | None -> assert false + in let rst = Input.Nuclei.to_rst b in let b2 = match Input.Nuclei.of_rst rst with | Some x -> x