10
0
mirror of https://github.com/LCPQ/quantum_package synced 2024-11-09 07:33:53 +01:00
quantum_package/ocaml/Basis.ml

78 lines
1.8 KiB
OCaml
Raw Normal View History

2017-08-18 19:43:52 +02:00
open Sexplib.Std
2016-01-14 17:03:55 +01:00
open Qptypes
2014-08-27 16:38:13 +02:00
2017-08-18 18:28:33 +02:00
type t = (Gto.t * Nucl_number.t) list [@@deriving sexp]
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 []
2016-01-14 17:03:55 +01:00
2014-08-27 16:38:13 +02:00
(** Find an element in the basis set file *)
let find in_channel element =
2017-08-18 19:43:52 +02:00
seek_in in_channel 0;
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
2016-01-14 17:03:55 +01:00
2014-08-27 16:38:13 +02:00
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) ;
2016-01-14 17:03:55 +01:00
read in_channel at_number
2014-08-27 16:38:13 +02:00
2016-12-19 13:27:16 +01:00
let to_string_general ~fmt ~atom_sep ?ele_array b =
2014-10-26 12:46:17 +01:00
let new_nucleus n =
2016-12-19 13:27:16 +01:00
match ele_array with
| None -> Printf.sprintf "Atom %d" n
| Some x -> Printf.sprintf "%s" (Element.to_string x.(n-1))
2014-10-26 12:46:17 +01:00
in
let rec do_work accu current_nucleus = function
| [] -> List.rev accu
| (g,n)::tail ->
let n = Nucl_number.to_int n
in
let accu =
if (n <> current_nucleus) then
(new_nucleus n)::atom_sep::accu
2014-10-26 12:46:17 +01:00
else
accu
in
do_work ((Gto.to_string ~fmt g)::accu) n tail
2014-10-26 12:46:17 +01:00
in
do_work [new_nucleus 1] 1 b
2017-08-18 19:43:52 +02:00
|> String.concat "\n"
2016-12-19 13:27:16 +01:00
let to_string_gamess ?ele_array =
to_string_general ?ele_array ~fmt:Gto.Gamess ~atom_sep:""
2016-12-19 13:27:16 +01:00
let to_string_gaussian ?ele_array b =
2017-08-18 19:43:52 +02:00
String.concat "\n"
2016-12-19 13:27:16 +01:00
[ to_string_general ?ele_array ~fmt:Gto.Gaussian ~atom_sep:"****" b ; "****" ]
let to_string ?(fmt=Gto.Gamess) =
match fmt with
| Gto.Gamess -> to_string_gamess
| Gto.Gaussian -> to_string_gaussian
2016-01-14 17:03:55 +01:00
include To_md5
let to_md5 = to_md5 sexp_of_t
2016-01-14 17:03:55 +01:00
2014-10-26 12:46:17 +01:00