From 24d2eb7e47b2b67d33a46ba6111db467a485bfa8 Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Sun, 25 Feb 2018 00:53:09 +0100 Subject: [PATCH] Documentation --- Basis/ERI.ml | 4 +-- Basis/KinInt.ml | 2 +- Basis/NucInt.ml | 2 +- Basis/OneElectronRR.ml | 2 +- Basis/Orthonormalization.ml | 2 +- Basis/Overlap.ml | 2 +- Utils/AngularMomentum.ml | 9 +++--- Utils/Electrons.ml | 2 +- Utils/NonNegativeFloat.ml | 2 +- Utils/NonNegativeFloat.mli | 1 + Utils/Powers.ml | 6 +++- Utils/Powers.mli | 62 +++++++++++++++++++++++++++++++++---- 12 files changed, 75 insertions(+), 21 deletions(-) diff --git a/Basis/ERI.ml b/Basis/ERI.ml index fa3385c..a731a74 100644 --- a/Basis/ERI.ml +++ b/Basis/ERI.ml @@ -192,9 +192,9 @@ let of_basis basis = let xl = to_powers powers_l in let key = if swap then - Zkey.of_powers (Zkey.Twelve (xk,xl,xi,xj)) + Zkey.of_powers_twelve xk xl xi xj else - Zkey.of_powers (Zkey.Twelve (xi,xj,xk,xl)) + Zkey.of_powers_twelve xi xj xk xl in let value = Zmap.find cls key diff --git a/Basis/KinInt.ml b/Basis/KinInt.ml index 3e6b02e..76bea22 100644 --- a/Basis/KinInt.ml +++ b/Basis/KinInt.ml @@ -140,7 +140,7 @@ let of_basis basis = let i_c = shell.(i).index + i_c + 1 in let xi = to_powers powers_i in let key = - Zkey.of_powers (Zkey.Six (xi,xj)) + Zkey.of_powers_six xi xj in let value = try Zmap.find cls key diff --git a/Basis/NucInt.ml b/Basis/NucInt.ml index 8428032..16af6ef 100644 --- a/Basis/NucInt.ml +++ b/Basis/NucInt.ml @@ -79,7 +79,7 @@ let of_basis_nuclei basis nuclei = let j_c = shell.(j).index + j_c + 1 in let xj = to_powers powers_j in let key = - Zkey.of_powers (Zkey.Six (xi,xj)) + Zkey.of_powers_six xi xj in let value = Zmap.find cls key diff --git a/Basis/OneElectronRR.ml b/Basis/OneElectronRR.ml index e6b1345..03ac8e7 100644 --- a/Basis/OneElectronRR.ml +++ b/Basis/OneElectronRR.ml @@ -37,7 +37,7 @@ let hvrr_one_e angMom_a angMom_b match angMom_a.Po.tot with | 0 -> zero_m_array | _ -> - let key = Zkey.of_powers (Zkey.Three angMom_a) in + let key = Zkey.of_powers_three angMom_a in try Zmap.find map key with | Not_found -> diff --git a/Basis/Orthonormalization.ml b/Basis/Orthonormalization.ml index 82b2607..9d0df20 100644 --- a/Basis/Orthonormalization.ml +++ b/Basis/Orthonormalization.ml @@ -12,7 +12,7 @@ let make_lowdin ?(thresh=1.e-12) ~overlap = let u_vec, u_val = diagonalize_symm overlap in Vec.iter (fun x -> if x < thresh then - invalid_arg "Orthonormalization.make_lowdin") u_val; + invalid_arg (__FILE__^": make_lowdin") ) u_val; let u_val = Vec.reci (Vec.sqrt u_val) in diff --git a/Basis/Overlap.ml b/Basis/Overlap.ml index c5985e2..e9ea239 100644 --- a/Basis/Overlap.ml +++ b/Basis/Overlap.ml @@ -114,7 +114,7 @@ let of_basis basis = let i_c = shell.(i).index + i_c + 1 in let xi = to_powers powers_i in let key = - Zkey.of_powers (Zkey.Six (xi,xj)) + Zkey.of_powers_six xi xj in let value = try Zmap.find cls key diff --git a/Utils/AngularMomentum.ml b/Utils/AngularMomentum.ml index d7877a2..bea478d 100644 --- a/Utils/AngularMomentum.ml +++ b/Utils/AngularMomentum.ml @@ -96,12 +96,11 @@ let zkey_array a = begin match a with | Singlet l1 -> - List.map (fun x -> Zkey.of_powers (Zkey.Three x)) (keys_1d @@ to_int l1) + List.map (fun x -> Zkey.of_powers_three x) (keys_1d @@ to_int l1) | Doublet (l1, l2) -> List.map (fun a -> - List.map (fun b -> - Zkey.of_powers (Zkey.Six (a,b))) (keys_1d @@ to_int l2) + List.map (fun b -> Zkey.of_powers_six a b) (keys_1d @@ to_int l2) ) (keys_1d @@ to_int l1) |> List.concat @@ -110,7 +109,7 @@ let zkey_array a = List.map (fun a -> List.map (fun b -> List.map (fun c -> - Zkey.of_powers (Zkey.Nine (a,b,c))) (keys_1d @@ to_int l3) + Zkey.of_powers_nine a b c) (keys_1d @@ to_int l3) ) (keys_1d @@ to_int l2) |> List.concat ) (keys_1d @@ to_int l1) @@ -122,7 +121,7 @@ let zkey_array a = List.map (fun b -> List.map (fun c -> List.map (fun d -> - Zkey.of_powers (Zkey.Twelve (a,b,c,d))) (keys_1d @@ to_int l4) + Zkey.of_powers_twelve a b c d) (keys_1d @@ to_int l4) ) (keys_1d @@ to_int l3) |> List.concat ) (keys_1d @@ to_int l2) diff --git a/Utils/Electrons.ml b/Utils/Electrons.ml index b951d91..769fce3 100644 --- a/Utils/Electrons.ml +++ b/Utils/Electrons.ml @@ -18,6 +18,6 @@ let make ?multiplicity:(multiplicity=1) ?charge:(charge=0) nuclei = let n_alpha = n_elec - n_beta in let result = { n_alpha ; n_beta ; multiplicity } in if multiplicity <> (n_alpha - n_beta)+1 then - invalid_arg "Electrons.make"; + invalid_arg (__FILE__^": make"); result diff --git a/Utils/NonNegativeFloat.ml b/Utils/NonNegativeFloat.ml index fe2bc8b..2ee5ecc 100644 --- a/Utils/NonNegativeFloat.ml +++ b/Utils/NonNegativeFloat.ml @@ -1,7 +1,7 @@ type t = float let of_float x = - assert ( x >= 0. ); + if x < 0. then invalid_arg (__FILE__^": of_float"); x external to_float : t -> float = "%identity" diff --git a/Utils/NonNegativeFloat.mli b/Utils/NonNegativeFloat.mli index 2d3d60b..e68fd79 100644 --- a/Utils/NonNegativeFloat.mli +++ b/Utils/NonNegativeFloat.mli @@ -1,3 +1,4 @@ +(** Floats >= 0. *) type t = private float val of_float : float -> t val to_float : t -> float diff --git a/Utils/Powers.ml b/Utils/Powers.ml index 9d726a3..62fc1ee 100644 --- a/Utils/Powers.ml +++ b/Utils/Powers.ml @@ -5,7 +5,11 @@ let of_int_tuple t = match t with | (x,y,z) -> { x ; y ; z ; tot=x+y+z } in - assert (result.tot >= 0); + if result.x < 0 || + result.y < 0 || + result.z < 0 || + result.tot < 0 then + invalid_arg (__FILE__^": of_int_tuple"); result let to_int_tuple { x ; y ; z ; _ } = (x,y,z) diff --git a/Utils/Powers.mli b/Utils/Powers.mli index d4b05d2..bcc9732 100644 --- a/Utils/Powers.mli +++ b/Utils/Powers.mli @@ -1,7 +1,57 @@ -type t = private { x: int ; y : int ; z : int ; tot : int } -val of_int_tuple : int * int * int -> t -val to_int_tuple : t -> int * int * int -val get : Coordinate.axis -> t -> int -val incr : Coordinate.axis -> t -> t -val decr : Coordinate.axis -> t -> t +(** Contains powers of x, y and z describing the polynomials in atomic basis sets. *) + +type t = private { + x : int ; + y : int ; + z : int ; + tot : int ; (* x + y + z *) + } + + +val of_int_tuple : int * int * int -> t +(** Example: + [of_int_tuple (2,3,1) -> { x=2 ; y=3 ; z=1 ; tot=6 }] + @raise Invalid_argument if x, y or z < 0. + *) + + +val to_int_tuple : t -> int * int * int +(** Example: + [to_int_tuple { x=2 ; y=3 ; z=1 ; tot=6 } -> (2,3,1) ] + *) + + +val get : Coordinate.axis -> t -> int +(** Example: + + [Powers.get Coordinate.Y { x=2 ; y=3 ; z=1 ; tot=6 } -> 3] + + *) + + +val incr : Coordinate.axis -> t -> t +(** Returns a new {!Powers.t} with the power on the given axis incremented. + + Example: + + {[ + Powers.incr Coordinate.Y { x=2 ; y=3 ; z=1 ; tot=6 } -> + { x=2 ; y=4 ; z=1 ; tot=7 } + ]} + + *) + + +val decr : Coordinate.axis -> t -> t +(** Returns a new {!Powers.t} with the power on the given axis decremented. + As opposed to {!of_int_tuple}, the values may become negative. + + Example: + + {[ + Powers.incr Coordinate.Y { x=2 ; y=3 ; z=1 ; tot=6 } -> + { x=2 ; y=2 ; z=1 ; tot=5 } + ]} + + *)