From 28e6fda24235b1d1c8880d12315795ca6ab719fa Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Fri, 1 Jan 2021 12:52:50 +0100 Subject: [PATCH] Added frozen_core --- mo/frozen_core.org | 118 ++++++++++++++++++++++++++++++++++++ mo/lib/frozen_core.ml | 72 ++++++++++++++++++++++ mo/lib/frozen_core.mli | 39 ++++++++++++ top/install_printers.org | 21 +++++-- top/lib/install_printers.ml | 8 ++- 5 files changed, 251 insertions(+), 7 deletions(-) create mode 100644 mo/frozen_core.org create mode 100644 mo/lib/frozen_core.ml create mode 100644 mo/lib/frozen_core.mli diff --git a/mo/frozen_core.org b/mo/frozen_core.org new file mode 100644 index 0000000..2b8471f --- /dev/null +++ b/mo/frozen_core.org @@ -0,0 +1,118 @@ +#+begin_src elisp tangle: no :results none :exports none +(setq pwd (file-name-directory buffer-file-name)) +(setq name (file-name-nondirectory (substring buffer-file-name 0 -4))) +(setq lib (concat pwd "lib/")) +(setq testdir (concat pwd "test/")) +(setq mli (concat lib name ".mli")) +(setq ml (concat lib name ".ml")) +(setq test-ml (concat testdir name ".ml")) +(org-babel-tangle) +#+end_src + +* Frozen core + :PROPERTIES: + :header-args: :noweb yes :comments both + :END: + + Defines how the core electrons are frozen, for each atom. + +** Type + + #+NAME: types + #+begin_src ocaml :tangle (eval mli) +type kind = + | All_electron + | Small + | Large + #+end_src + + #+begin_src ocaml :tangle (eval mli) +type t + #+end_src + + #+begin_src ocaml :tangle (eval ml) :exports none +<> +type t = int array + #+end_src + +** Creation + + #+begin_src ocaml :tangle (eval mli) +val make : kind -> Particles.Nuclei.t -> t + +val of_int_list : int list -> t +val of_int_array : int array -> t + #+end_src + + | ~make~ | Creates a ~Frozen_core.t~ with the same kind for all atoms | + | ~of_int_array~ | Creates a ~Frozen_core.t~ giving the number of frozen electrons per atom | + | ~of_int_list~ | Creates a ~Frozen_core.t~ giving the number of frozen electrons per atom | + + #+begin_example +let f = Frozen_core.(make Small nuclei) ;; +val f : Frozen_core.t = [|0; 2; 2; 0|] + +let f = Frozen_core.(of_int_list [0; 2; 2; 0]) +val f : Frozen_core.t = [|0; 2; 2; 0|] + #+end_example + + #+begin_src ocaml :tangle (eval ml) :exports none +let make_ae nuclei = + Array.map (fun _ -> 0) nuclei + +let make_small nuclei = + Array.map (fun (e,_) -> Particles.Element.small_core e) nuclei + +let make_large nuclei = + Array.map (fun (e,_) -> Particles.Element.large_core e) nuclei + +let make = function + | All_electron -> make_ae + | Small -> make_small + | Large -> make_large + + +external of_int_array : int array -> t = "%identity" + +let of_int_list = Array.of_list + #+end_src + +** Access + + #+begin_src ocaml :tangle (eval mli) +val num_elec : t -> int +val num_mos : t -> int + #+end_src + + | ~num_elec~ | Number of frozen electrons | + | ~num_mos~ | Number of frozen molecular orbitals | + + #+begin_example +Frozen_core.num_elec f ;; +- : int = 4 + +Frozen_core.num_mos f ;; +- : int = 2 + #+end_example + + #+begin_src ocaml :tangle (eval ml) :exports none +let num_elec t = + Array.fold_left ( + ) 0 t + +let num_mos t = + (num_elec t) / 2 + #+end_src + +** Printers + + #+begin_src ocaml :tangle (eval mli) +val pp : Format.formatter -> t -> unit + #+end_src + + #+begin_src ocaml :tangle (eval ml) :exports none +let pp ppf t = + Format.fprintf ppf "@[[|"; + Array.iter (fun x -> Format.fprintf ppf "@,@[%d@]" x) t; + Format.fprintf ppf "|]@]"; + #+end_src + diff --git a/mo/lib/frozen_core.ml b/mo/lib/frozen_core.ml new file mode 100644 index 0000000..65333d0 --- /dev/null +++ b/mo/lib/frozen_core.ml @@ -0,0 +1,72 @@ +(* [[file:../frozen_core.org::*Type][Type:3]] *) +type kind = + | All_electron + | Small + | Large +type t = int array +(* Type:3 ends here *) + + + +(* | ~make~ | Creates a ~Frozen_core.t~ with the same kind for all atoms | + * | ~of_int_array~ | Creates a ~Frozen_core.t~ giving the number of frozen electrons per atom | + * | ~of_int_list~ | Creates a ~Frozen_core.t~ giving the number of frozen electrons per atom | + * + * #+begin_example + * let f = Frozen_core.(make Small nuclei) ;; + * val f : Frozen_core.t = [|0; 2; 2; 0|] + * + * let f = Frozen_core.(of_int_list [0; 2; 2; 0]) + * val f : Frozen_core.t = [|0; 2; 2; 0|] + * #+end_example *) + + +(* [[file:../frozen_core.org::*Creation][Creation:2]] *) +let make_ae nuclei = + Array.map (fun _ -> 0) nuclei + +let make_small nuclei = + Array.map (fun (e,_) -> Particles.Element.small_core e) nuclei + +let make_large nuclei = + Array.map (fun (e,_) -> Particles.Element.large_core e) nuclei + +let make = function + | All_electron -> make_ae + | Small -> make_small + | Large -> make_large + + +external of_int_array : int array -> t = "%identity" + +let of_int_list = Array.of_list +(* Creation:2 ends here *) + + + +(* | ~num_elec~ | Number of frozen electrons | + * | ~num_mos~ | Number of frozen molecular orbitals | + * + * #+begin_example + * Frozen_core.num_elec f ;; + * - : int = 4 + * + * Frozen_core.num_mos f ;; + * - : int = 2 + * #+end_example *) + + +(* [[file:../frozen_core.org::*Access][Access:2]] *) +let num_elec t = + Array.fold_left ( + ) 0 t + +let num_mos t = + (num_elec t) / 2 +(* Access:2 ends here *) + +(* [[file:../frozen_core.org::*Printers][Printers:2]] *) +let pp ppf t = + Format.fprintf ppf "@[[|"; + Array.iter (fun x -> Format.fprintf ppf "@,@[%d@]" x) t; + Format.fprintf ppf "|]@]"; +(* Printers:2 ends here *) diff --git a/mo/lib/frozen_core.mli b/mo/lib/frozen_core.mli new file mode 100644 index 0000000..8b4499f --- /dev/null +++ b/mo/lib/frozen_core.mli @@ -0,0 +1,39 @@ +(* Type + * + * #+NAME: types *) + +(* [[file:../frozen_core.org::types][types]] *) +type kind = + | All_electron + | Small + | Large +(* types ends here *) + +(* [[file:../frozen_core.org::*Type][Type:2]] *) +type t +(* Type:2 ends here *) + +(* Creation *) + + +(* [[file:../frozen_core.org::*Creation][Creation:1]] *) +val make : kind -> Particles.Nuclei.t -> t + +val of_int_list : int list -> t +val of_int_array : int array -> t +(* Creation:1 ends here *) + +(* Access *) + + +(* [[file:../frozen_core.org::*Access][Access:1]] *) +val num_elec : t -> int +val num_mos : t -> int +(* Access:1 ends here *) + +(* Printers *) + + +(* [[file:../frozen_core.org::*Printers][Printers:1]] *) +val pp : Format.formatter -> t -> unit +(* Printers:1 ends here *) diff --git a/top/install_printers.org b/top/install_printers.org index 002ba96..a23b252 100644 --- a/top/install_printers.org +++ b/top/install_printers.org @@ -18,18 +18,31 @@ All printers are fetched automatically using the following script: - #+NAME: printers + #+NAME: raw_printers #+begin_src sh :results output raw grep "val pp " ../*/*.org \ | grep -v docs \ | cut -d ":" -f 1 \ | sed 's|^../||' \ - | sed 's|.org|.pp" ;|' \ + | sed 's|.org||' \ | sed 's|/| |' \ | sed 's/[^ ]*/\u&/g' \ | sed 's| |.|' \ - | sed 's|^|"|' \ - | grep -v Top.Install_printers.pp + | grep -v Top.Install_printers + #+end_src + + #+NAME: printers + #+begin_src python :results output raw :var p=raw_printers +result = [] +for l in p.split(): + dir, module = l.split('.') + if dir == module: + e = f'"{module}.pp" ;' + else: + e = f'"{dir}.{module}.pp" ;' + result.append(e) +result = '\n'.join(result) +print(result) #+end_src diff --git a/top/lib/install_printers.ml b/top/lib/install_printers.ml index 894ee15..ca039ca 100644 --- a/top/lib/install_printers.ml +++ b/top/lib/install_printers.ml @@ -1,4 +1,4 @@ -(* [[file:../install_printers.org::*Intall printers][Intall printers:2]] *) +(* [[file:../install_printers.org::*Intall printers][Intall printers:3]] *) let printers = [ "Common.Angular_momentum.pp" ; @@ -9,11 +9,13 @@ let printers = "Common.Range.pp" ; "Common.Spin.pp" ; "Common.Zkey.pp" ; + "Mo.Frozen_core.pp" ; "Particles.Electrons.pp" ; "Particles.Element.pp" ; "Particles.Nuclei.pp" ; "Particles.Zmatrix.pp" ; - "Simulation.Simulation.pp" ; + "Perturbation.Mp2.pp" ; + "Simulation.pp" ; ] @@ -32,4 +34,4 @@ let rec install_printers = function let () = if not (install_printers printers) then Format.eprintf "Problem installing QCaml-printers@." -(* Intall printers:2 ends here *) +(* Intall printers:3 ends here *)