diff --git a/ocaml/Input_hartree_fock.ml b/ocaml/Input_hartree_fock.ml index 2444f0a0..bd92e69b 100644 --- a/ocaml/Input_hartree_fock.ml +++ b/ocaml/Input_hartree_fock.ml @@ -11,6 +11,7 @@ module Hartree_fock : 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_it_scf_max : Strictly_positive_int.t; @@ -71,6 +72,22 @@ SCF convergence criterion (on energy) :: |> 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 40c8a0a7..30b1ed9c 100644 --- a/ocaml/test_input.ml +++ b/ocaml/test_input.ml @@ -83,6 +83,13 @@ let test_hf () = let b = Input.Hartree_fock.read () in print_endline (Input.Hartree_fock.to_string b); + let rst = Input.Hartree_fock.to_rst b in + let new_b = Input.Hartree_fock.of_rst rst in + print_endline (Input.Hartree_fock.to_string b); + if (b = new_b) then + print_endline "OK" + else + print_endline "Failed in rst" ;; let test_mo () = @@ -117,4 +124,4 @@ test_bielec_intergals ();; test_electrons(); *) -test_electrons(); +test_hf();