mirror of
https://github.com/LCPQ/quantum_package
synced 2024-11-12 17:13:54 +01:00
Function to read the basis of an element
This commit is contained in:
parent
256efa75b8
commit
0cdae777d5
33
ocaml/gto.ml
33
ocaml/gto.ml
@ -2,6 +2,7 @@ open Core.Std;;
|
||||
open Qptypes;;
|
||||
|
||||
exception GTO_Read_Failure of string
|
||||
exception End_Of_Basis
|
||||
|
||||
type t =
|
||||
{ sym : Symmetry.t ;
|
||||
@ -32,6 +33,8 @@ let of_prim_coef_list pc =
|
||||
let read_one in_channel =
|
||||
(* Fetch number of lines to read on first line *)
|
||||
let buffer = input_line in_channel in
|
||||
if ( (String.strip buffer) = "" ) then
|
||||
raise End_Of_Basis;
|
||||
let sym_str = String.sub buffer 0 2 in
|
||||
let n_str = String.sub buffer 2 ((String.length buffer)-2) in
|
||||
let sym = Symmetry.of_string (String.strip sym_str) in
|
||||
@ -62,7 +65,37 @@ let read_one in_channel =
|
||||
|> of_prim_coef_list
|
||||
;;
|
||||
|
||||
(** Read all the basis functions of an element *)
|
||||
let read_basis in_channel =
|
||||
let rec read result =
|
||||
try
|
||||
let gto = read_one in_channel in
|
||||
read (gto::result)
|
||||
with
|
||||
| End_Of_Basis -> List.rev result
|
||||
in read []
|
||||
;;
|
||||
|
||||
(** Find an element in the basis set file *)
|
||||
let find in_channel element =
|
||||
let element_read = ref Element.X in
|
||||
while !element_read <> element
|
||||
do
|
||||
let buffer = input_line in_channel in
|
||||
try
|
||||
element_read := Element.of_string buffer
|
||||
with
|
||||
| Element.ElementError _ -> ()
|
||||
done ;
|
||||
!element_read
|
||||
;;
|
||||
|
||||
let read_basis_of_element in_channel element =
|
||||
find in_channel element ;
|
||||
read_basis in_channel ;
|
||||
;;
|
||||
|
||||
(** Transform the gto to a string *)
|
||||
let to_string { sym = sym ; lc = lc } =
|
||||
let f (p,c) = Printf.sprintf "( %s, %f )" (Primitive.to_string p) c
|
||||
in
|
||||
|
@ -9,13 +9,28 @@ let test_prim () =
|
||||
|> print_string
|
||||
;;
|
||||
|
||||
let test_gto () =
|
||||
let test_gto_1 () =
|
||||
let in_channel = open_in "/home/scemama/quantum_package/data/basis/cc-pVDZ" in
|
||||
ignore (input_line in_channel);
|
||||
let gto = Gto.read_one in_channel in
|
||||
print_string (Gto.to_string gto);
|
||||
let gto = Gto.read_one in_channel in
|
||||
print_string (Gto.to_string gto);
|
||||
let gto = Gto.read_one in_channel in
|
||||
print_string (Gto.to_string gto);
|
||||
;;
|
||||
|
||||
let test_gto_2 () =
|
||||
let in_channel = open_in "/home/scemama/quantum_package/data/basis/cc-pVDZ" in
|
||||
ignore (input_line in_channel);
|
||||
let basis = Gto.read_basis in_channel in
|
||||
List.iter basis ~f:(fun x-> Printf.printf "%s\n" (Gto.to_string x))
|
||||
;;
|
||||
|
||||
let test_gto () =
|
||||
let in_channel = open_in "/home/scemama/quantum_package/data/basis/cc-pVDZ" in
|
||||
let basis = Gto.read_basis_of_element in_channel Element.C in
|
||||
List.iter basis ~f:(fun x-> Printf.printf "%s\n" (Gto.to_string x))
|
||||
;;
|
||||
|
||||
let test_module () =
|
||||
|
Loading…
Reference in New Issue
Block a user