From c1433be7f8bc5503451b42d2699adc55c917bf6f Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Thu, 8 Oct 2020 11:42:33 +0200 Subject: [PATCH] Pretty printers for basis --- common/lib/dune | 1 + dune-project | 1 + gaussian_basis/lib/general_basis.ml | 22 ++++++++++++++++++++++ gaussian_basis/lib/general_basis.mli | 8 ++++++++ particles/lib/element.ml | 5 +++++ particles/lib/element.mli | 8 +++++++- 6 files changed, 44 insertions(+), 1 deletion(-) diff --git a/common/lib/dune b/common/lib/dune index 777cb5b..fa52323 100644 --- a/common/lib/dune +++ b/common/lib/dune @@ -4,6 +4,7 @@ (name qcaml_common) (public_name qcaml.common) (libraries + str zarith getopt ) diff --git a/dune-project b/dune-project index 74b9906..3d7638a 100644 --- a/dune-project +++ b/dune-project @@ -27,6 +27,7 @@ in quantum chemistry.") (depends (ocaml (>= 4.10)) (dune (>= 1.10)) + str lacaml getopt zarith diff --git a/gaussian_basis/lib/general_basis.ml b/gaussian_basis/lib/general_basis.ml index 23ec71b..fc6a819 100644 --- a/gaussian_basis/lib/general_basis.ml +++ b/gaussian_basis/lib/general_basis.ml @@ -143,3 +143,25 @@ let of_string input_string = |> Stream.of_list |> read_stream + +let pp_primitive ppf prim = + Format.fprintf ppf "@[%17.10e %17.10e@]" prim.exponent prim.coefficient + + +let pp_gcs ppf gcs = + let (angular_momentum, prim_array) = gcs in + Format.fprintf ppf "@[%a %d@]@." + Angular_momentum.pp_string angular_momentum + (Array.length prim_array); + + Array.iteri (fun i prim -> Format.fprintf ppf "@[%3d %a@]@." + (i+1) pp_primitive prim) prim_array + + +let pp_element_basis ppf eb = + let (element, basis) = eb in + Format.fprintf ppf "@[%s@]@." (String.uppercase_ascii @@ Element.to_long_string element); + Array.iter (fun b -> Format.fprintf ppf "@[%a@]" pp_gcs b) basis + +let pp ppf t = + List.iter (fun x -> Format.fprintf ppf "@[%a@]@." pp_element_basis x) t diff --git a/gaussian_basis/lib/general_basis.mli b/gaussian_basis/lib/general_basis.mli index 04a4e1d..b2f4376 100644 --- a/gaussian_basis/lib/general_basis.mli +++ b/gaussian_basis/lib/general_basis.mli @@ -129,3 +129,11 @@ val to_string : string * (general_contracted_shell array) -> string val of_string : string -> t (** Reads a GAMESS-formatted string. *) + +(** Pretty printers *) + +val pp_primitive : Format.formatter -> primitive -> unit +val pp_gcs : Format.formatter -> general_contracted_shell -> unit +val pp_element_basis : Format.formatter -> element_basis -> unit + +val pp : Format.formatter -> t -> unit diff --git a/particles/lib/element.ml b/particles/lib/element.ml index ca5cd05..c85b2ad 100644 --- a/particles/lib/element.ml +++ b/particles/lib/element.ml @@ -205,3 +205,8 @@ let small_core = function | Te -> 28 | I -> 28 | Xe -> 28 | Pt -> 60 +let pp ppf t = + Format.fprintf ppf "@[%s@]" (to_string t) + +let pp_long ppf t = + Format.fprintf ppf "@[%s@]" (to_long_string t) diff --git a/particles/lib/element.mli b/particles/lib/element.mli index eda983a..3463903 100644 --- a/particles/lib/element.mli +++ b/particles/lib/element.mli @@ -68,7 +68,13 @@ val mass : t -> Mass.t val small_core : t -> int (** Number of electrons in the small core model (all except the outermost two shells). *) -(* TODO +(* val large_core : t -> int (** Number of electrons in the large core model (all except the outermost shell). *) *) + + +(** Pretty printers *) +val pp : Format.formatter -> t -> unit +val pp_long : Format.formatter -> t -> unit +