10
1
mirror of https://gitlab.com/scemama/QCaml.git synced 2024-06-17 02:35:18 +02:00
QCaml/particles/lib/electrons.ml

51 lines
955 B
OCaml
Raw Normal View History

2024-02-28 10:34:39 +01:00
(** Type *)
2018-02-23 18:44:31 +01:00
type t = {
2019-02-20 19:43:16 +01:00
n_alfa : int ;
n_beta : int ;
2018-02-23 18:44:31 +01:00
}
2020-12-28 12:43:32 +01:00
2018-02-23 18:44:31 +01:00
2020-12-28 12:43:32 +01:00
open Common
2024-02-28 10:34:39 +01:00
(** Creation *)
let make n_alfa n_beta =
2020-09-26 12:02:53 +02:00
{ n_alfa ; n_beta }
let of_atoms ?multiplicity:(multiplicity=1) ?charge:(charge=0) nuclei =
2018-02-23 18:44:31 +01:00
let positive_charges =
Array.fold_left (fun accu (e, _) -> accu + Charge.to_int (Element.to_charge e) )
0 nuclei
in
let negative_charges = charge - positive_charges in
let n_elec = - negative_charges in
let n_beta = ((n_elec - multiplicity)+1)/2 in
2019-02-20 19:43:16 +01:00
let n_alfa = n_elec - n_beta in
2020-09-26 12:02:53 +02:00
let result = { n_alfa ; n_beta } in
2019-02-20 19:43:16 +01:00
if multiplicity <> (n_alfa - n_beta)+1 then
2018-02-25 00:53:09 +01:00
invalid_arg (__FILE__^": make");
2018-02-23 18:44:31 +01:00
result
2020-12-28 12:43:32 +01:00
2024-02-28 10:34:39 +01:00
(** Access *)
2018-03-03 22:13:14 +01:00
let charge e =
2019-02-20 19:43:16 +01:00
- (e.n_alfa + e.n_beta)
2018-03-03 22:13:14 +01:00
|> Charge.of_int
2019-02-20 19:43:16 +01:00
let n_alfa t = t.n_alfa
2020-12-28 12:43:32 +01:00
2019-02-20 19:43:16 +01:00
let n_beta t = t.n_beta
2020-12-28 12:43:32 +01:00
2019-12-03 12:25:31 +01:00
let n_elec t = t.n_alfa + t.n_beta
2020-12-28 12:43:32 +01:00
2020-09-26 12:02:53 +02:00
let multiplicity t = t.n_alfa - t.n_beta + 1
2020-12-28 12:43:32 +01:00
2024-02-28 10:34:39 +01:00
(** Printers *)
2020-12-28 12:43:32 +01:00
let pp ppf t =
Format.fprintf ppf "@[n_alfa=%d, n_beta=%d@]" t.n_alfa t.n_beta
2024-02-28 10:34:39 +01:00