From f9fe342c58d5368b302e40c1bf8800659b7b37eb Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Mon, 3 Nov 2014 22:24:40 +0100 Subject: [PATCH] Input_nuclei is written by qp_edit --- ocaml/Gto.ml | 7 -- ocaml/Input_ao_basis.ml | 33 ++++++--- ocaml/Input_nuclei.ml | 158 ++++++++++++++++++++++++++++------------ ocaml/qp_edit.ml | 4 +- 4 files changed, 137 insertions(+), 65 deletions(-) diff --git a/ocaml/Gto.ml b/ocaml/Gto.ml index b7d5d1cd..de9de237 100644 --- a/ocaml/Gto.ml +++ b/ocaml/Gto.ml @@ -67,13 +67,6 @@ let read_one in_channel = (** Transform the gto to a string *) -let to_string { sym = sym ; lc = lc } = - let f (p,c) = Printf.sprintf "( %s, %f )" (Primitive.to_string p) (AO_coef.to_float c) - in - Printf.sprintf "( %s, %s )" (Symmetry.to_string sym) - (String.concat (List.map ~f:f lc) ~sep:", ") -;; - let to_string { sym = sym ; lc = lc } = let result = Printf.sprintf "%s %3d" (Symmetry.to_string sym) (List.length lc) diff --git a/ocaml/Input_ao_basis.ml b/ocaml/Input_ao_basis.ml index 2d7e91b3..0e61dc54 100644 --- a/ocaml/Input_ao_basis.ml +++ b/ocaml/Input_ao_basis.ml @@ -145,16 +145,12 @@ end = struct let print_sym = let l = List.init (Array.length b.ao_power) ~f:( fun i -> ( (i+1),b.ao_nucl.(i),b.ao_power.(i) ) ) in - let rec do_work count = function + let rec do_work = function | [] -> [] | (i,n,x)::tail -> - if (count < 2) then - (Printf.sprintf " (%4d) %d:%-8s" i (Nucl_number.to_int n) (Symmetry.Xyz.to_string x)):: - (do_work (count+1) tail) - else - (Printf.sprintf " (%4d) %d:%-8s\n" i (Nucl_number.to_int n) (Symmetry.Xyz.to_string x)):: - (do_work 0 tail) - in do_work 0 l + (Printf.sprintf " %5d %6d %-8s\n" i (Nucl_number.to_int n) (Symmetry.Xyz.to_string x)):: + (do_work tail) + in do_work l |> String.concat in @@ -168,9 +164,12 @@ Basis set :: %s -Symmetries :: +======= ========= =========== + Basis Nucleus Symmetries +======= ========= =========== %s +======= ========= =========== " b.ao_basis (Basis.to_string short_basis @@ -181,6 +180,22 @@ Symmetries :: |> Rst_string.of_string ;; + let read_rst s = + let s = Rst_string.to_string s + |> String.split ~on:'\n' + in + let rec extract_basis = function + | [] -> failwith "Error in basis set" + | line :: tail -> + let line = String.strip line in + if line = "Basis set ::" then + String.concat tail ~sep:"\n" + else + extract_basis tail + in + extract_basis s + ;; + let to_md5 b = let short_basis = to_basis b in Basis.to_md5 short_basis diff --git a/ocaml/Input_nuclei.ml b/ocaml/Input_nuclei.ml index 5202c785..11eeb7d4 100644 --- a/ocaml/Input_nuclei.ml +++ b/ocaml/Input_nuclei.ml @@ -10,7 +10,8 @@ module Nuclei : sig nucl_coord : Point3d.t array; } with sexp ;; - val read : unit -> t + 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 @@ -30,18 +31,52 @@ end = struct Nucl_number.of_int ~max:nmax nmax ;; + let write_nucl_num n = + Nucl_number.to_int n + |> Ezfio.set_nuclei_nucl_num + ;; + + let read_nucl_label () = Ezfio.get_nuclei_nucl_label () |> Ezfio.flattened_ezfio |> Array.map ~f:Element.of_string ;; + let write_nucl_label ~nucl_num labels = + let nucl_num = + Nucl_number.to_int nucl_num + in + let labels = + Array.to_list labels + |> List.map ~f:Element.to_string + in + Ezfio.ezfio_array_of_list ~rank:1 + ~dim:[| nucl_num |] ~data:labels + |> Ezfio.set_nuclei_nucl_label + ;; + + let read_nucl_charge () = Ezfio.get_nuclei_nucl_charge () |> Ezfio.flattened_ezfio |> Array.map ~f:Charge.of_float ;; + let write_nucl_charge ~nucl_num charges = + let nucl_num = + Nucl_number.to_int nucl_num + in + let charges = + Array.to_list charges + |> List.map ~f:Charge.to_float + in + Ezfio.ezfio_array_of_list ~rank:1 + ~dim:[| nucl_num |] ~data:charges + |> Ezfio.set_nuclei_nucl_charge + ;; + + let read_nucl_coord () = let nucl_num = Nucl_number.to_int (read_nucl_num ()) in let raw_data = @@ -59,6 +94,81 @@ end = struct result ;; + let write_nucl_coord ~nucl_num coord = + let nucl_num = + Nucl_number.to_int nucl_num + in + let coord = Array.to_list coord in + let coord = + (List.map ~f:(fun x-> x.Point3d.x) coord) @ + (List.map ~f:(fun x-> x.Point3d.y) coord) @ + (List.map ~f:(fun x-> x.Point3d.z) coord) + in + Ezfio.ezfio_array_of_list ~rank:2 + ~dim:[| nucl_num ; 3 |] ~data:coord + |> Ezfio.set_nuclei_nucl_coord + ;; + + + let read () = + { nucl_num = read_nucl_num (); + nucl_label = read_nucl_label () ; + nucl_charge = read_nucl_charge (); + nucl_coord = read_nucl_coord (); + } + ;; + + let write { nucl_num ; + nucl_label ; + nucl_charge ; + nucl_coord ; + } = + write_nucl_num nucl_num ; + write_nucl_label ~nucl_num:nucl_num nucl_label; + write_nucl_charge ~nucl_num:nucl_num nucl_charge; + write_nucl_coord ~nucl_num:nucl_num nucl_coord; + ;; + + + let to_string b = + Printf.sprintf " +nucl_num = %s +nucl_label = %s +nucl_charge = %s +nucl_coord = %s +" + (Nucl_number.to_string b.nucl_num) + (b.nucl_label |> Array.to_list |> List.map + ~f:(Element.to_string) |> String.concat ~sep:", " ) + (b.nucl_charge |> Array.to_list |> List.map + ~f:(Charge.to_string) |> String.concat ~sep:", " ) + (b.nucl_coord |> Array.to_list |> List.map + ~f:(Point3d.to_string Units.Bohr) |> String.concat ~sep:"\n" ) + ;; + + + let to_rst b = + let nucl_num = Nucl_number.to_int b.nucl_num in + let text = + ( Printf.sprintf " %d\n " + nucl_num + ) :: ( + List.init nucl_num ~f:(fun i-> + Printf.sprintf " %-3s %d %s" + (b.nucl_label.(i) |> Element.to_string) + (b.nucl_charge.(i) |> Charge.to_int ) + (b.nucl_coord.(i) |> Point3d.to_string Units.Angstrom) ) + ) |> String.concat ~sep:"\n" + in + Printf.sprintf " +Nuclear coordinates in xyz format (Angstroms) :: + +%s + +" text + |> Rst_string.of_string + ;; + let of_rst s = let l = Rst_string.to_string s |> String.split ~on:'\n' @@ -104,52 +214,6 @@ end = struct } ;; - let read () = - { nucl_num = read_nucl_num (); - nucl_label = read_nucl_label () ; - nucl_charge = read_nucl_charge (); - nucl_coord = read_nucl_coord (); - } - ;; - - let to_string b = - Printf.sprintf " -nucl_num = %s -nucl_label = %s -nucl_charge = %s -nucl_coord = %s -" - (Nucl_number.to_string b.nucl_num) - (b.nucl_label |> Array.to_list |> List.map - ~f:(Element.to_string) |> String.concat ~sep:", " ) - (b.nucl_charge |> Array.to_list |> List.map - ~f:(Charge.to_string) |> String.concat ~sep:", " ) - (b.nucl_coord |> Array.to_list |> List.map - ~f:(Point3d.to_string Units.Bohr) |> String.concat ~sep:"\n" ) - ;; - - let to_rst b = - let nucl_num = Nucl_number.to_int b.nucl_num in - let text = - ( Printf.sprintf " %d\n " - nucl_num - ) :: ( - List.init nucl_num ~f:(fun i-> - Printf.sprintf " %-3s %d %s" - (b.nucl_label.(i) |> Element.to_string) - (b.nucl_charge.(i) |> Charge.to_int ) - (b.nucl_coord.(i) |> Point3d.to_string Units.Angstrom) ) - ) |> String.concat ~sep:"\n" - in - Printf.sprintf " -Nuclear coordinates in xyz format (Angstroms) :: - -%s - -" text - |> Rst_string.of_string -;; - end diff --git a/ocaml/qp_edit.ml b/ocaml/qp_edit.ml index 79e80a16..58724215 100644 --- a/ocaml/qp_edit.ml +++ b/ocaml/qp_edit.ml @@ -91,8 +91,8 @@ let set str s = | Cisd_sc2 -> *) | Nuclei -> - let b = Input.Nuclei.of_rst str in - print_string (Input.Nuclei.to_string b); + Input.Nuclei.of_rst str + |> Input.Nuclei.write; | Bielec_integrals -> let b = Input.Bielec_integrals.of_rst str in print_string (Input.Bielec_integrals.to_string b);