From dc29b0144c1d4f5f3d95271b34e7f86c908ab0f7 Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Fri, 31 Oct 2014 19:26:27 +0100 Subject: [PATCH] Input_cisd_sc2 reads rst --- ocaml/Input_cisd_sc2.ml | 19 +++++++++++++++++++ ocaml/test_input.ml | 9 ++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/ocaml/Input_cisd_sc2.ml b/ocaml/Input_cisd_sc2.ml index b87dcc91..48d99559 100644 --- a/ocaml/Input_cisd_sc2.ml +++ b/ocaml/Input_cisd_sc2.ml @@ -12,6 +12,7 @@ module Cisd_sc2 : 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 = { n_det_max_cisd_sc2 : Det_number_max.t; @@ -91,6 +92,24 @@ Compute E(PT2) at the end :: (PT2_energy.to_string b.pt2_max) (Bool.to_string b.do_pt2_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 + ;; + + end diff --git a/ocaml/test_input.ml b/ocaml/test_input.ml index a415e79f..dbee17d7 100644 --- a/ocaml/test_input.ml +++ b/ocaml/test_input.ml @@ -49,6 +49,13 @@ let test_cisd_sc2 () = let b = Input.Cisd_sc2.read () 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 + if (b = b2) then + print_endline "OK" + else + print_endline "rst failed"; + ;; let test_electrons () = @@ -102,5 +109,5 @@ test_mo ();; test_nucl (); test_bielec_intergals ();; *) -test_bielec_intergals ();; +test_cisd_sc2 ();