10
0
mirror of https://github.com/LCPQ/quantum_package synced 2024-06-22 05:02:15 +02:00
quantum_package/ocaml/Input_mo_basis.ml

89 lines
2.3 KiB
OCaml
Raw Normal View History

2014-10-24 00:25:15 +02:00
open Qptypes;;
open Qputils;;
open Core.Std;;
module Mo_basis : sig
type t =
{ mo_tot_num : MO_number.t ;
mo_label : Non_empty_string.t;
mo_occ : Positive_float.t array;
mo_coef : MO_coef.t array;
2014-10-25 21:24:21 +02:00
} with sexp
2014-10-24 00:25:15 +02:00
;;
val read : unit -> t
val to_string : t -> string
end = struct
type t =
{ mo_tot_num : MO_number.t ;
mo_label : Non_empty_string.t;
mo_occ : Positive_float.t array;
mo_coef : MO_coef.t array;
2014-10-25 21:24:21 +02:00
} with sexp
2014-10-24 00:25:15 +02:00
;;
let get_default = Qpackage.get_ezfio_default "mo_basis";;
let read_mo_label () =
if not (Ezfio.has_mo_basis_mo_label ()) then
Ezfio.set_mo_basis_mo_label "Unknown"
;
Ezfio.get_mo_basis_mo_label ()
|> Non_empty_string.of_string
;;
let read_mo_tot_num () =
Ezfio.get_mo_basis_mo_tot_num ()
|> MO_number.of_int
;;
let read_mo_occ () =
if not (Ezfio.has_mo_basis_mo_label ()) then
begin
let elec_alpha_num = Ezfio.get_electrons_elec_alpha_num ()
and elec_beta_num = Ezfio.get_electrons_elec_beta_num ()
and mo_tot_num = MO_number.to_int (read_mo_tot_num ()) in
let data = Array.init mo_tot_num ~f:(fun i ->
if (i<elec_beta_num) then 2.
else if (i < elec_alpha_num) then 1.
else 0.) |> Array.to_list in
Ezfio.ezfio_array_of_list ~rank:1
~dim:[| mo_tot_num |] ~data:data
|> Ezfio.set_mo_basis_mo_occ
end;
(Ezfio.get_mo_basis_mo_occ () ).Ezfio.data
|> Ezfio.flattened_ezfio_data
|> Array.map ~f:Positive_float.of_float
;;
let read_mo_coef () =
(Ezfio.get_mo_basis_mo_coef () ).Ezfio.data
|> Ezfio.flattened_ezfio_data
|> Array.map ~f:MO_coef.of_float
;;
let read () =
{ mo_tot_num = read_mo_tot_num ();
mo_label = read_mo_label () ;
mo_occ = read_mo_occ ();
mo_coef = read_mo_coef ();
}
;;
let to_string b =
Printf.sprintf "
mo_label = %s
mo_tot_num = \"%s\"
mo_occ = %s
mo_coef = %s
"
(Non_empty_string.to_string b.mo_label)
(MO_number.to_string b.mo_tot_num)
(b.mo_occ |> Array.to_list |> List.map
~f:(Positive_float.to_string) |> String.concat ~sep:", " )
(b.mo_coef |> Array.to_list |> List.map
~f:(MO_coef.to_string) |> String.concat ~sep:", " )
end