diff --git a/ocaml/Bitlist.ml b/ocaml/Bitlist.ml index 3e69487e..20c2a17a 100644 --- a/ocaml/Bitlist.ml +++ b/ocaml/Bitlist.ml @@ -106,14 +106,14 @@ let of_mo_number_list n_int l = let to_mo_number_list l = let a = Array.of_list l in - let mo_tot_num = MO_number.get_mo_tot_num () in + let mo_tot_num = MO_number.get_max () in let rec do_work accu = function | 0 -> accu | i -> begin let new_accu = match a.(i-1) with - | Bit.One -> (MO_number.of_int ~mo_tot_num:mo_tot_num i)::accu + | Bit.One -> (MO_number.of_int ~max:mo_tot_num i)::accu | Bit.Zero -> accu in do_work new_accu (i-1) diff --git a/ocaml/Input_ao_basis.ml b/ocaml/Input_ao_basis.ml index a094abd1..c0c20224 100644 --- a/ocaml/Input_ao_basis.ml +++ b/ocaml/Input_ao_basis.ml @@ -59,9 +59,10 @@ end = struct ;; let read_ao_nucl () = + let nmax = Nucl_number.get_max () in (Ezfio.get_ao_basis_ao_nucl () ).Ezfio.data |> Ezfio.flattened_ezfio_data - |> Array.map ~f:Nucl_number.of_int + |> Array.map ~f:(fun x-> Nucl_number.of_int ~max:nmax x) ;; let read_ao_power () = diff --git a/ocaml/Input_determinants.ml b/ocaml/Input_determinants.ml index 2f55527e..8b308807 100644 --- a/ocaml/Input_determinants.ml +++ b/ocaml/Input_determinants.ml @@ -177,10 +177,10 @@ end = struct let n_int = read_n_int () in if not (Ezfio.has_determinants_psi_det ()) then begin - let mo_tot_num = MO_number.get_mo_tot_num () in + let mo_tot_num = MO_number.get_max () in let rec build_data accu = function | 0 -> accu - | n -> build_data ((MO_number.of_int ~mo_tot_num:mo_tot_num n)::accu) (n-1) + | n -> build_data ((MO_number.of_int ~max:mo_tot_num n)::accu) (n-1) in let det_a = build_data [] (Ezfio.get_electrons_elec_alpha_num ()) |> Bitlist.of_mo_number_list n_int @@ -248,7 +248,7 @@ end = struct let to_rst b = let mo_tot_num = Ezfio.get_mo_basis_mo_tot_num () in - let mo_tot_num = MO_number.of_int mo_tot_num ~mo_tot_num:mo_tot_num in + let mo_tot_num = MO_number.of_int mo_tot_num ~max:mo_tot_num in let det_text = List.map2_exn ~f:(fun coef det -> Printf.sprintf " %f\n%s\n" @@ -315,7 +315,7 @@ Determinants :: let to_string b = let mo_tot_num = Ezfio.get_mo_basis_mo_tot_num () in - let mo_tot_num = MO_number.of_int mo_tot_num ~mo_tot_num:mo_tot_num in + let mo_tot_num = MO_number.of_int mo_tot_num ~max:mo_tot_num in Printf.sprintf " n_int = %s bit_kind = %s diff --git a/ocaml/Input_nuclei.ml b/ocaml/Input_nuclei.ml index 969a78b4..1aaa2236 100644 --- a/ocaml/Input_nuclei.ml +++ b/ocaml/Input_nuclei.ml @@ -26,8 +26,8 @@ end = struct let get_default = Qpackage.get_ezfio_default "nuclei";; let read_nucl_num () = - Ezfio.get_nuclei_nucl_num () - |> Nucl_number.of_int + let nmax = Nucl_number.get_max () in + Nucl_number.of_int ~max:nmax nmax ;; let read_nucl_label () = @@ -75,15 +75,8 @@ end = struct else extract_begin tail in - (* Read the xyz data *) - let rec read_line = function - | [] -> [] - | line::tail -> - if (String.strip line = "") then [] - else - (read_line tail) - in (* Create a list of Atom.t *) + let nmax = Nucl_number.get_max () in let atom_list = match (extract_begin l) with | _ :: nucl_num :: title :: lines -> @@ -91,7 +84,7 @@ end = struct let nucl_num = nucl_num |> String.strip |> Int.of_string - |> Nucl_number.of_int + |> Nucl_number.of_int ~max:nmax and lines = Array.of_list lines in List.init (Nucl_number.to_int nucl_num) ~f:(fun i -> @@ -101,7 +94,7 @@ end = struct in (* Create the Nuclei.t data structure *) { nucl_num = List.length atom_list - |> Nucl_number.of_int; + |> 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 -> diff --git a/ocaml/Molecule.ml b/ocaml/Molecule.ml index 48c28997..f295420b 100644 --- a/ocaml/Molecule.ml +++ b/ocaml/Molecule.ml @@ -25,7 +25,8 @@ let get_multiplicity m = ;; let get_nucl_num m = - Nucl_number.of_int (List.length m.nuclei) + let nmax = (List.length m.nuclei) in + Nucl_number.of_int nmax ~max:nmax ;; let name m = diff --git a/ocaml/qp_create_ezfio_from_xyz.ml b/ocaml/qp_create_ezfio_from_xyz.ml index e4110268..441519ea 100644 --- a/ocaml/qp_create_ezfio_from_xyz.ml +++ b/ocaml/qp_create_ezfio_from_xyz.ml @@ -74,9 +74,10 @@ let run ?o b c m xyz_file = (* Write Basis set *) let basis = + 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 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 diff --git a/ocaml/qptypes_generator.ml b/ocaml/qptypes_generator.ml index ffab3bf2..b1c33d85 100644 --- a/ocaml/qptypes_generator.ml +++ b/ocaml/qptypes_generator.ml @@ -37,34 +37,6 @@ let input_data = " assert (x <> \"\") ; -* AO_number : int - assert (x > 0) ; - if (x > 1000) then - warning \"More than 1000 AOs\"; - if (Ezfio.has_ao_basis_ao_num ()) then - assert (x <= (Ezfio.get_ao_basis_ao_num ())); - -* Nucl_number : int - assert (x > 0) ; - if (x > 1000) then - warning \"More than 1000 atoms\"; - if (Ezfio.has_nuclei_nucl_num ()) then - assert (x <= (Ezfio.get_nuclei_nucl_num ())); - -* N_int_number : int - assert (x > 0) ; - if (x > 100) then - warning \"N_int > 100\"; - if (Ezfio.has_determinants_n_int ()) then - assert (x = (Ezfio.get_determinants_n_int ())); - -* Det_number : int - assert (x > 0) ; - if (x > 100000000) then - warning \"More than 100 million determinants\"; - if (Ezfio.has_determinants_n_det ()) then - assert (x <= (Ezfio.get_determinants_n_det ())); - * Det_number_max : int assert (x > 0) ; if (x > 100000000) then @@ -131,38 +103,36 @@ let input_data = " " ;; +let input_ezfio = " +* MO_number : int + mo_basis_mo_tot_num + 1 : 10000 + More than 10000 MOs + +* AO_number : int + ao_basis_ao_num + 1 : 10000 + More than 10000 AOs + +* Nucl_number : int + nuclei_nucl_num + 1 : 10000 + More than 10000 nuclei + +* N_int_number : int + determinants_n_int + 1 : 30 + N_int > 30 + +* Det_number : int + determinants_n_det + 1 : 100000000 + More than 100 million determinants + +" +;; + let untouched = " -module MO_number : sig - type t with sexp - val to_int : t -> int - val get_mo_tot_num : unit -> int - val of_int : ?mo_tot_num:int -> int -> t - val to_string : t -> string -end = struct - type t = int with sexp - let get_mo_tot_num () = - if (Ezfio.has_mo_basis_mo_tot_num ()) then - Ezfio.get_mo_basis_mo_tot_num () - else - 0 - let to_int x = x - let of_int ?mo_tot_num x = ( assert (x > 0) ; - if (x > 1000) then - warning \"More than 1000 MOs\"; - let mo_tot_num = match mo_tot_num with - | Some i -> i - | None -> get_mo_tot_num () - in - begin - match mo_tot_num with - | 0 -> () - | i -> assert ( x <= i ) - end - ; x ) - - let to_string x = Int.to_string x -end - " let template = format_of_string " @@ -209,9 +179,75 @@ let parse_input input= |> print_string ;; -let () = - parse_input input_data ; - print_endline untouched + +let ezfio_template = format_of_string " +module %s : sig + type t with sexp + val to_%s : t -> %s + val get_max : unit -> %s + val of_%s : ?min:%s -> ?max:%s -> %s -> t + val to_string : t -> string +end = struct + type t = %s with sexp + let to_string x = %s.to_string x + let get_max () = + if (Ezfio.has_%s ()) then + Ezfio.get_%s () + else + %s + let get_min () = + %s + let to_%s x = x + let of_%s ?(min=get_min ()) ?(max=get_max ()) x = + begin + assert (x >= min) ; + if (x > %s) then + warning \"%s\"; + begin + match max with + | %s -> () + | i -> assert ( x <= i ) + end ; + x + end +end +" ;; +let parse_input_ezfio input= + let parse s = + match ( + String.split s ~on:'\n' + |> List.filter ~f:(fun x -> (String.strip x) <> "") + ) with + | [] -> "" + | a :: b :: c :: d :: [] -> + begin + let (name,typ) = String.lsplit2_exn ~on:':' a + and ezfio_func = b + and (min, max) = String.lsplit2_exn ~on:':' c + and msg = d + in + let name :: typ :: ezfio_func :: min :: max :: msg :: [] = + name :: typ :: ezfio_func :: min :: max :: msg :: [] + |> List.map ~f:String.strip + in + Printf.sprintf ezfio_template + name typ typ typ typ typ typ typ typ (String.capitalize typ) + ezfio_func ezfio_func max min typ typ max msg min + end + | _ -> failwith "Error in input_ezfio" + in + String.split ~on:'*' input + |> List.map ~f:parse + |> String.concat + |> print_string +;; + +let () = + parse_input input_data ; + parse_input_ezfio input_ezfio; + print_endline untouched; + +