10
0
mirror of https://github.com/LCPQ/quantum_package synced 2024-11-03 20:54:00 +01:00
quantum_package/ocaml/Input_electrons.ml

104 lines
2.3 KiB
OCaml
Raw Normal View History

2014-10-21 23:23:37 +02:00
open Qptypes;;
open Qputils;;
2017-08-18 18:28:33 +02:00
open Core;;
2014-10-21 23:23:37 +02:00
module Electrons : sig
type t =
2014-10-22 00:12:23 +02:00
{ elec_alpha_num : Elec_alpha_number.t;
elec_beta_num : Elec_beta_number.t;
2017-08-18 18:28:33 +02:00
} [@@deriving sexp]
2014-10-21 23:23:37 +02:00
;;
2014-11-27 23:05:26 +01:00
val read : unit -> t option
2014-11-04 00:39:10 +01:00
val write : t -> unit
2014-10-31 19:33:29 +01:00
val read_elec_num : unit -> Elec_number.t
2014-10-21 23:23:37 +02:00
val to_string : t -> string
2014-10-29 22:13:03 +01:00
val to_rst : t -> Rst_string.t
2014-11-12 17:17:44 +01:00
val of_rst : Rst_string.t -> t option
2014-10-21 23:23:37 +02:00
end = struct
type t =
2014-10-22 00:12:23 +02:00
{ elec_alpha_num : Elec_alpha_number.t;
elec_beta_num : Elec_beta_number.t;
2017-08-18 18:28:33 +02:00
} [@@deriving sexp]
2014-10-21 23:23:37 +02:00
;;
let get_default = Qpackage.get_ezfio_default "electrons";;
let read_elec_alpha_num() =
Ezfio.get_electrons_elec_alpha_num ()
2014-10-22 00:12:23 +02:00
|> Elec_alpha_number.of_int
2014-10-21 23:23:37 +02:00
;;
2014-11-04 00:39:10 +01:00
let write_elec_alpha_num n =
Elec_alpha_number.to_int n
|> Ezfio.set_electrons_elec_alpha_num
;;
2014-10-21 23:23:37 +02:00
let read_elec_beta_num() =
Ezfio.get_electrons_elec_beta_num ()
2014-10-22 00:12:23 +02:00
|> Elec_beta_number.of_int
2014-10-21 23:23:37 +02:00
;;
2014-11-04 00:39:10 +01:00
let write_elec_beta_num n =
Elec_beta_number.to_int n
|> Ezfio.set_electrons_elec_beta_num
;;
2014-10-21 23:23:37 +02:00
let read_elec_num () =
let na = Ezfio.get_electrons_elec_alpha_num ()
and nb = Ezfio.get_electrons_elec_beta_num ()
in assert (na >= nb);
2014-10-22 00:12:23 +02:00
Elec_number.of_int (na + nb)
2014-10-21 23:23:37 +02:00
;;
let read () =
2014-11-27 23:05:26 +01:00
if (Ezfio.has_electrons_elec_alpha_num ()) then
Some
{ elec_alpha_num = read_elec_alpha_num ();
elec_beta_num = read_elec_beta_num ();
}
else
None
2014-10-21 23:23:37 +02:00
;;
2014-11-04 00:39:10 +01:00
let write { elec_alpha_num ; elec_beta_num } =
write_elec_alpha_num elec_alpha_num;
write_elec_beta_num elec_beta_num;
;;
2014-10-29 22:13:03 +01:00
let to_rst b =
2014-10-29 00:12:45 +01:00
Printf.sprintf "
Spin multiplicity is %s.
Number of alpha and beta electrons ::
elec_alpha_num = %s
elec_beta_num = %s
2014-10-28 17:16:51 +01:00
"
2014-10-29 00:12:45 +01:00
(Multiplicity.of_alpha_beta b.elec_alpha_num b.elec_beta_num
|> Multiplicity.to_string)
2014-10-28 17:16:51 +01:00
(Elec_alpha_number.to_string b.elec_alpha_num)
(Elec_beta_number.to_string b.elec_beta_num)
2014-10-29 22:13:03 +01:00
|> Rst_string.of_string
2014-10-28 17:16:51 +01:00
;;
2014-10-29 22:13:03 +01:00
let to_string b =
2014-10-28 17:16:51 +01:00
Printf.sprintf "elec_alpha_num = %s
2014-10-21 23:23:37 +02:00
elec_beta_num = %s
elec_num = %s
"
2014-10-22 00:12:23 +02:00
(Elec_alpha_number.to_string b.elec_alpha_num)
(Elec_beta_number.to_string b.elec_beta_num)
2014-10-31 19:33:29 +01:00
(Elec_number.to_string (read_elec_num ()))
2014-10-28 17:16:51 +01:00
;;
2014-10-31 19:33:29 +01:00
2014-11-12 17:17:44 +01:00
include Generic_input_of_rst;;
let of_rst = of_rst t_of_sexp;;
2014-10-31 19:33:29 +01:00
2014-10-21 23:23:37 +02:00
end