Improved GAMESS/US parser

This commit is contained in:
Anthony Scemama 2020-02-05 12:15:47 +01:00
parent a2859ad69c
commit 13fcc8e6fa
2 changed files with 6166 additions and 74 deletions

View File

@ -22,7 +22,9 @@ let read_shell ic =
let shell, n = let shell, n =
try try
Scanf.sscanf (input_line ic) " %c %d " (fun shell n -> shell, n) let line = input_line ic in
if String.trim line = "$END" then raise End_of_file;
Scanf.sscanf line "%c %d " (fun shell n -> shell, n)
with with
| End_of_file -> raise No_shell | End_of_file -> raise No_shell
| Scanf.Scan_failure m -> raise (Malformed_shell m) | Scanf.Scan_failure m -> raise (Malformed_shell m)
@ -32,7 +34,7 @@ let read_shell ic =
| 0 -> [] | 0 -> []
| i -> let contraction = | i -> let contraction =
let line = (input_line ic) in let line = (input_line ic) in
try Scanf.sscanf line " %_d %f %f " try Scanf.sscanf line "%_d %f %f "
(fun exponent coefficient -> { exponent ; coefficient }) (fun exponent coefficient -> { exponent ; coefficient })
with _ -> raise (Malformed_shell (Printf.sprintf with _ -> raise (Malformed_shell (Printf.sprintf
"Expected %d %c contractions, error at contraction %d:\n%s" "Expected %d %c contractions, error at contraction %d:\n%s"
@ -63,19 +65,21 @@ let read_element ic =
Some (element, Array.of_list (loop ()) ) Some (element, Array.of_list (loop ()) )
with with
| Element.ElementError _ -> None
| End_of_file -> None | End_of_file -> None
let read filename = let read filename =
let ic = open_in filename in let ic = open_in filename in
let rec loop () = let rec loop accu =
match read_element ic with try
| Some e -> e :: loop () match read_element ic with
| None -> [] | Some e -> loop (e :: accu)
| None -> accu
with
Element.ElementError _ -> loop accu
in in
loop () loop []
let combine basis_list = let combine basis_list =

File diff suppressed because one or more lines are too long