10
1
mirror of https://gitlab.com/scemama/QCaml.git synced 2024-11-07 14:43:41 +01:00
QCaml/particles/lib/electrons.ml

63 lines
1.8 KiB
OCaml
Raw Normal View History

2020-12-28 23:27:33 +01:00
(* [[file:~/QCaml/particles/electrons.org::*Type][Type:2]] *)
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
(* Type:2 ends here *)
2018-02-23 18:44:31 +01:00
2020-12-28 12:43:32 +01:00
(* | ~make~ | ~make n_alfa n_beta~ |
* | ~of_atoms~ | Creates the data relative to electrons for a molecular system described by ~Nuclei.t~ for a given total charge and spin multiplicity. | *)
2020-12-28 23:27:33 +01:00
(* [[file:~/QCaml/particles/electrons.org::*Creation][Creation:2]] *)
2020-12-28 12:43:32 +01:00
open Common
2020-09-26 12:02:53 +02:00
let make n_alfa n_beta =
{ 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
(* Creation:2 ends here *)
2018-02-23 18:44:31 +01:00
2020-09-26 12:02:53 +02:00
2020-12-28 12:43:32 +01:00
(* | ~charge~ | Sum of the charges of the electrons |
* | ~n_elec~ | Number of electrons |
* | ~n_alfa~ | Number of alpha electrons |
* | ~n_beta~ | Number of beta electrons |
* | ~multiplicity~ | Spin multiplicity: $2S+1$ | *)
2020-12-28 23:27:33 +01:00
(* [[file:~/QCaml/particles/electrons.org::*Access][Access:2]] *)
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
(* Access:2 ends here *)
2020-12-28 23:27:33 +01:00
(* [[file:~/QCaml/particles/electrons.org::*Printers][Printers:2]] *)
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
(* Printers:2 ends here *)