10
0
mirror of https://github.com/LCPQ/quantum_package synced 2024-11-08 15:13:52 +01:00
quantum_package/ocaml/Basis.ml

44 lines
1011 B
OCaml
Raw Normal View History

2014-08-27 16:38:13 +02:00
open Core.Std;;
2014-09-17 23:47:13 +02:00
open Qptypes;;
2014-08-27 16:38:13 +02:00
2014-09-17 23:47:13 +02:00
type t = (Gto.t * Atom_number.t) list;;
2014-08-27 16:38:13 +02:00
(** Read all the basis functions of an element *)
2014-09-17 23:47:13 +02:00
let read in_channel at_number =
2014-08-27 16:38:13 +02:00
let rec read result =
try
let gto = Gto.read_one in_channel in
2014-09-17 23:47:13 +02:00
read ( (gto,at_number)::result)
2014-08-27 16:38:13 +02:00
with
| Gto.End_Of_Basis -> List.rev result
in read []
;;
(** Find an element in the basis set file *)
let find in_channel element =
2014-09-17 14:57:12 +02:00
In_channel.seek in_channel 0L;
2014-08-27 16:38:13 +02:00
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
;;
2014-09-17 23:47:13 +02:00
(** Read an element from the file *)
let read_element in_channel at_number element =
2014-08-27 16:38:13 +02:00
ignore (find in_channel element) ;
2014-09-17 23:47:13 +02:00
read in_channel at_number ;
2014-08-27 16:38:13 +02:00
;;
2014-09-17 14:57:12 +02:00
let to_string b =
2014-09-17 23:47:13 +02:00
List.map ~f:(fun (g,n) ->
let n = Atom_number.to_int n in
(Int.to_string n)^":"^(Gto.to_string g)) b
2014-09-17 14:57:12 +02:00
|> String.concat ~sep:"\n"
;;