10
1
mirror of https://gitlab.com/scemama/QCaml.git synced 2024-11-14 10:03:39 +01:00
QCaml/Utils/Electrons.ml

32 lines
829 B
OCaml
Raw Normal View History

2019-02-20 19:43:16 +01:00
(** Number of {% $\alpha$ %} and {% $\beta$ %} electrons *)
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
multiplicity : int;
}
let make ?multiplicity:(multiplicity=1) ?charge:(charge=0) nuclei =
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
let result = { n_alfa ; n_beta ; multiplicity } in
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
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
let n_beta t = t.n_beta
2019-12-03 12:25:31 +01:00
let n_elec t = t.n_alfa + t.n_beta
2019-02-20 19:43:16 +01:00
let multiplicity t = t.multiplicity