From c84c7c30544e529f1650ce75c25173bbb95b431e Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Fri, 31 Oct 2014 19:23:44 +0100 Subject: [PATCH] Input.Bielec_integrals reads rst --- ocaml/Input_bi_integrals.ml | 16 ++++++++++++++++ ocaml/test_input.ml | 10 ++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/ocaml/Input_bi_integrals.ml b/ocaml/Input_bi_integrals.ml index b06d1d28..fdb859d9 100644 --- a/ocaml/Input_bi_integrals.ml +++ b/ocaml/Input_bi_integrals.ml @@ -16,6 +16,7 @@ module Bielec_integrals : sig val read : unit -> t val to_string : t -> string val to_rst : t -> Rst_string.t + val of_rst : Rst_string.t -> t end = struct type t = { read_ao_integrals : bool; @@ -165,6 +166,21 @@ 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 + ;; + end diff --git a/ocaml/test_input.ml b/ocaml/test_input.ml index f75222e3..a415e79f 100644 --- a/ocaml/test_input.ml +++ b/ocaml/test_input.ml @@ -15,6 +15,12 @@ let test_bielec_intergals () = let output = Input.Bielec_integrals.to_string b in print_endline output; + let rst = Input.Bielec_integrals.to_rst b in + let b2 = Input.Bielec_integrals.of_rst rst in + if (b = b2) then + print_endline "OK" + else + print_endline "rst failed"; ;; let test_bitmasks () = @@ -87,7 +93,6 @@ let test_nucl () = (* test_ao ();; -test_bielec_intergals ();; test_bitmasks (); test_cis (); test_cisd_sc2 (); @@ -95,6 +100,7 @@ test_dets (); test_hf ();; test_mo ();; test_nucl (); +test_bielec_intergals ();; *) -test_nucl();; +test_bielec_intergals ();;