10
0
mirror of https://github.com/LCPQ/quantum_package synced 2024-12-23 04:43:50 +01:00

Input_electrons.ml reads rst

This commit is contained in:
Anthony Scemama 2014-10-31 19:33:29 +01:00
parent dc29b0144c
commit e476d845f5
2 changed files with 27 additions and 5 deletions

View File

@ -6,17 +6,17 @@ module Electrons : sig
type t = type t =
{ elec_alpha_num : Elec_alpha_number.t; { elec_alpha_num : Elec_alpha_number.t;
elec_beta_num : Elec_beta_number.t; elec_beta_num : Elec_beta_number.t;
elec_num : Elec_number.t;
} with sexp } with sexp
;; ;;
val read : unit -> t val read : unit -> t
val read_elec_num : unit -> Elec_number.t
val to_string : t -> string val to_string : t -> string
val to_rst : t -> Rst_string.t val to_rst : t -> Rst_string.t
val of_rst : Rst_string.t -> t
end = struct end = struct
type t = type t =
{ elec_alpha_num : Elec_alpha_number.t; { elec_alpha_num : Elec_alpha_number.t;
elec_beta_num : Elec_beta_number.t; elec_beta_num : Elec_beta_number.t;
elec_num : Elec_number.t;
} with sexp } with sexp
;; ;;
@ -43,7 +43,6 @@ end = struct
let read () = let read () =
{ elec_alpha_num = read_elec_alpha_num (); { elec_alpha_num = read_elec_alpha_num ();
elec_beta_num = read_elec_beta_num (); elec_beta_num = read_elec_beta_num ();
elec_num = read_elec_num ();
} }
;; ;;
@ -71,8 +70,24 @@ elec_num = %s
" "
(Elec_alpha_number.to_string b.elec_alpha_num) (Elec_alpha_number.to_string b.elec_alpha_num)
(Elec_beta_number.to_string b.elec_beta_num) (Elec_beta_number.to_string b.elec_beta_num)
(Elec_number.to_string b.elec_num) (Elec_number.to_string (read_elec_num ()))
;; ;;
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 end

View File

@ -63,6 +63,12 @@ let test_electrons () =
let b = Input.Electrons.read () let b = Input.Electrons.read ()
in in
print_endline (Input.Electrons.to_string b); print_endline (Input.Electrons.to_string b);
let rst = Input.Electrons.to_rst b in
let new_b = Input.Electrons.of_rst rst in
if (b = new_b) then
print_endline "OK"
else
print_endline "Failed in rst"
;; ;;
let test_fci () = let test_fci () =
@ -108,6 +114,7 @@ test_hf ();;
test_mo ();; test_mo ();;
test_nucl (); test_nucl ();
test_bielec_intergals ();; test_bielec_intergals ();;
test_electrons();
*) *)
test_cisd_sc2 (); test_electrons();