10
1
mirror of https://gitlab.com/scemama/QCaml.git synced 2024-12-23 04:43:32 +01:00
QCaml/Basis/OneElectronRR.ml

185 lines
5.2 KiB
OCaml
Raw Normal View History

2018-01-22 15:27:41 +01:00
open Util
2018-02-03 23:26:20 +01:00
open Constants
exception NullPair
2018-01-22 15:27:41 +01:00
2018-02-23 18:41:30 +01:00
module Am = AngularMomentum
2018-02-23 15:49:27 +01:00
module Co = Coordinate
2018-02-23 18:41:30 +01:00
module Cs = ContractedShell
2018-02-23 15:49:27 +01:00
module Csp = ContractedShellPair
module Po = Powers
2018-03-15 16:03:43 +01:00
module Ps = PrimitiveShell
module Psp = PrimitiveShellPair
2018-02-23 15:49:27 +01:00
2018-01-22 15:27:41 +01:00
(** Horizontal and Vertical Recurrence Relations (HVRR) *)
2018-02-23 15:49:27 +01:00
let hvrr_one_e angMom_a angMom_b
zero_m_array expo_b expo_inv_p
center_ab center_pa center_pc
map =
2018-01-22 15:27:41 +01:00
2018-02-23 15:49:27 +01:00
let maxm = angMom_a.Po.tot + angMom_b.Po.tot in
2018-02-03 23:26:20 +01:00
let maxsze = maxm+1 in
2018-01-22 15:27:41 +01:00
2018-02-19 16:01:13 +01:00
let get_xyz angMom =
match angMom with
2018-02-23 15:49:27 +01:00
| { Po.y=0 ; z=0 ; _ } -> Co.X
| { z=0 ; _ } -> Co.Y
| _ -> Co.Z
2018-02-19 16:01:13 +01:00
in
2018-01-22 15:27:41 +01:00
(** Vertical recurrence relations *)
2018-02-19 16:01:13 +01:00
let rec vrr angMom_a =
2018-02-23 15:49:27 +01:00
let { Po.x=ax ; y=ay ; z=az } = angMom_a in
2018-02-19 16:01:13 +01:00
if ax < 0 || ay < 0 || az < 0 then raise Exit
2018-01-22 15:27:41 +01:00
else
2018-02-23 15:49:27 +01:00
match angMom_a.Po.tot with
2018-02-03 23:26:20 +01:00
| 0 -> zero_m_array
2018-01-22 15:27:41 +01:00
| _ ->
2018-02-25 00:53:09 +01:00
let key = Zkey.of_powers_three angMom_a in
2018-02-03 23:26:20 +01:00
try Zmap.find map key with
| Not_found ->
let result =
2018-02-23 15:49:27 +01:00
let xyz = get_xyz angMom_a in
let am = Po.decr xyz angMom_a in
let amxyz = Po.get xyz am in
let f1 = Co.get xyz center_pa in
let f2 = expo_inv_p *. Co.get xyz center_pc in
if amxyz < 1 then
let v1 = vrr am in
Array.init (maxsze - angMom_a.Po.tot)
(fun m -> f1 *. v1.(m) -. f2 *. v1.(m+1))
else
2018-02-03 23:26:20 +01:00
let v3 =
2018-02-23 15:49:27 +01:00
let amm = Po.decr xyz am in
2018-02-19 16:01:13 +01:00
vrr amm
2018-02-03 23:26:20 +01:00
in
2018-02-23 15:49:27 +01:00
let v1 = vrr am in
let f3 = float_of_int amxyz *. expo_inv_p *. 0.5 in
Array.init (maxsze - angMom_a.Po.tot)
(fun m -> f1 *. v1.(m) -. f2 *. v1.(m+1) +.
f3 *. (v3.(m) -. expo_inv_p *. v3.(m+1))
)
2018-02-03 23:26:20 +01:00
in Zmap.add map key result;
result
2018-01-22 15:27:41 +01:00
(** Horizontal recurrence relations *)
2018-02-19 16:01:13 +01:00
and hrr angMom_a angMom_b =
2018-01-22 15:27:41 +01:00
2018-02-23 15:49:27 +01:00
match angMom_b.Po.tot with
| 0 -> (vrr angMom_a).(0)
| _ ->
let xyz = get_xyz angMom_b in
let bxyz = Po.get xyz angMom_b in
if (bxyz < 1) then 0. else
let ap = Po.incr xyz angMom_a in
let bm = Po.decr xyz angMom_b in
let h1 = hrr ap bm in
let f2 = Co.get xyz center_ab in
2018-02-24 23:57:38 +01:00
if abs_float f2 < integrals_cutoff then h1 else
2018-02-23 15:49:27 +01:00
let h2 = hrr angMom_a bm in
h1 +. f2 *. h2
2018-01-22 15:27:41 +01:00
in
2018-02-19 16:01:13 +01:00
hrr angMom_a angMom_b
2018-01-22 15:27:41 +01:00
(** Computes all the one-electron integrals of the contracted shell pair *)
2018-02-05 23:31:46 +01:00
let contracted_class_shell_pair ~zero_m shell_p geometry : float Zmap.t =
2018-01-22 15:27:41 +01:00
2018-03-14 14:39:22 +01:00
let shell_a = Csp.shell_a shell_p
and shell_b = Csp.shell_b shell_p
2018-02-03 23:26:20 +01:00
in
2018-03-21 15:01:39 +01:00
let maxm = Am.to_int (Csp.ang_mom shell_p) in
2018-01-22 15:27:41 +01:00
(* Pre-computation of integral class indices *)
2018-03-21 15:01:39 +01:00
let class_indices = Csp.zkey_array shell_p in
2018-01-22 15:27:41 +01:00
let contracted_class =
Array.make (Array.length class_indices) 0.;
in
(* Compute all integrals in the shell for each pair of significant shell pairs *)
2018-03-20 19:02:58 +01:00
let norm_scales_p = Csp.norm_scales shell_p in
2018-03-21 15:01:39 +01:00
let center_ab = Csp.a_minus_b shell_p in
2018-03-20 19:02:58 +01:00
List.iter (fun (coef_prod, psp) ->
2018-02-03 23:26:20 +01:00
try
begin
(** Screening on the product of coefficients *)
2018-02-24 23:57:38 +01:00
if abs_float coef_prod < 1.e-3 *. integrals_cutoff then
2018-02-03 23:26:20 +01:00
raise NullPair;
2018-01-22 15:27:41 +01:00
2018-03-20 19:02:58 +01:00
let expo_pq_inv = Psp.exponent_inv psp
and expo_b = Ps.exponent (Psp.shell_b psp)
and center_p = Psp.center psp
and center_pa = Psp.center_minus_a psp
2018-03-15 16:03:43 +01:00
in
2018-03-20 19:02:58 +01:00
Array.iter (fun (element, nucl_coord) ->
2018-02-05 23:31:46 +01:00
let charge = Element.to_charge element |> Charge.to_float in
2018-02-03 23:26:20 +01:00
let center_pc =
2018-02-23 15:49:27 +01:00
Co.(center_p |- nucl_coord )
2018-02-03 23:26:20 +01:00
in
let norm_pq_sq =
2018-02-23 15:49:27 +01:00
Co.dot center_pc center_pc
2018-02-03 23:26:20 +01:00
in
let zero_m_array =
zero_m ~maxm ~expo_pq_inv ~norm_pq_sq
in
2018-03-21 15:01:39 +01:00
match Cs.(ang_mom shell_a, ang_mom shell_b) with
2018-02-23 15:49:27 +01:00
| Am.(S,S) ->
let integral = zero_m_array.(0) in
2018-02-05 23:31:46 +01:00
contracted_class.(0) <- contracted_class.(0) -. coef_prod *. integral *. charge
2018-02-03 23:26:20 +01:00
| _ ->
let map = Zmap.create (2*maxm) in
2018-03-20 15:16:24 +01:00
let norm_scales = norm_scales_p in
2018-02-03 23:26:20 +01:00
(* Compute the integral class from the primitive shell quartet *)
class_indices
|> Array.iteri (fun i key ->
let (angMomA,angMomB) =
2018-02-25 01:40:12 +01:00
match Zkey.to_powers key with
2018-02-06 17:13:25 +01:00
| Zkey.Six x -> x
| _ -> assert false
2018-02-03 23:26:20 +01:00
in
2018-03-20 15:16:24 +01:00
let norm = norm_scales.(i) in
2018-02-03 23:26:20 +01:00
let coef_prod = coef_prod *. norm in
let integral =
2018-02-23 15:49:27 +01:00
hvrr_one_e
angMomA angMomB
zero_m_array
2018-03-15 16:03:43 +01:00
expo_b
expo_pq_inv
2018-02-23 15:49:27 +01:00
center_ab center_pa center_pc
2018-02-03 23:26:20 +01:00
map
in
2018-02-05 23:31:46 +01:00
contracted_class.(i) <- contracted_class.(i) -. coef_prod *. integral *. charge
2018-02-03 23:26:20 +01:00
)
2018-03-20 19:02:58 +01:00
) geometry
2018-02-03 23:26:20 +01:00
end
with NullPair -> ()
2018-03-20 19:02:58 +01:00
) (Csp.coefs_and_shell_pairs shell_p);
let result =
Zmap.create (Array.length contracted_class)
in
Array.iteri (fun i key -> Zmap.add result key contracted_class.(i)) class_indices;
result
2018-02-03 23:26:20 +01:00
2018-01-22 15:27:41 +01:00