10
1
mirror of https://gitlab.com/scemama/QCaml.git synced 2024-11-07 06:33:39 +01:00
QCaml/gaussian_integrals/lib/multipole.ml

242 lines
8.1 KiB
OCaml
Raw Normal View History

2020-10-09 09:47:57 +02:00
open Common
open Linear_algebra
2020-10-10 10:59:09 +02:00
open Gaussian
2020-04-16 19:49:23 +02:00
open Constants
2020-10-02 18:55:19 +02:00
type t = (Basis.t, Basis.t) Matrix.t array
2020-04-16 19:49:23 +02:00
(*
[| "x"; "y"; "z"; "x2"; "y2"; "z2" |]
*)
2020-09-26 12:02:53 +02:00
module Am = Angular_momentum
2020-04-16 19:49:23 +02:00
module Bs = Basis
module Co = Coordinate
2020-09-26 12:02:53 +02:00
module Cs = Contracted_shell
module Csp = Contracted_shell_pair
2020-04-16 19:49:23 +02:00
module Po = Powers
2020-09-26 12:02:53 +02:00
module Psp = Primitive_shell_pair
2020-04-16 19:49:23 +02:00
2020-10-19 18:33:02 +02:00
let matrix t = function
| "x" -> t.(0)
| "y" -> t.(1)
| "z" -> t.(2)
| "x2" -> t.(3)
| "y2" -> t.(4)
| "z2" -> t.(5)
| "xy" -> t.(6)
| "xz" -> t.(8)
| "yz" -> t.(7)
| "x3" -> t.(9)
| "y3" -> t.(10)
| "z3" -> t.(11)
| "x4" -> t.(12)
| "y4" -> t.(13)
| "z4" -> t.(14)
2021-01-01 16:39:33 +01:00
| _ -> Util.not_implemented "Multipole"
2020-07-08 11:37:43 +02:00
2020-04-16 19:49:23 +02:00
let cutoff = integrals_cutoff
let to_powers x =
let open Zkey in
match to_powers x with
| Six x -> x
| _ -> assert false
(** Computes all the integrals of the contracted shell pair *)
let contracted_class shell_a shell_b : float Zmap.t array =
match Csp.make shell_a shell_b with
2020-07-08 11:37:43 +02:00
| None -> Array.init 15 (fun _ -> Zmap.create 0)
2020-04-16 19:49:23 +02:00
| Some shell_p ->
begin
(* Pre-computation of integral class indices *)
let class_indices = Csp.zkey_array shell_p in
let contracted_class =
2020-07-08 11:37:43 +02:00
Array.init 15 (fun _ -> Array.make (Array.length class_indices) 0.)
2020-04-16 19:49:23 +02:00
in
let a_minus_b =
Csp.a_minus_b shell_p
in
let norm_coef_scales =
Csp.norm_scales shell_p
in
(* Compute all integrals in the shell for each pair of significant shell pairs *)
let xyz_of_int k =
match k with
| 0 -> Co.X
| 1 -> Co.Y
| _ -> Co.Z
in
List.iter (fun (coef_prod, psp) ->
2020-09-26 12:02:53 +02:00
(* Screening on the product of coefficients *)
2020-04-16 19:49:23 +02:00
if (abs_float coef_prod) > 1.e-6*.cutoff then
begin
let expo_inv = Psp.exponent_inv psp
and center_pa = Psp.center_minus_a psp
2020-04-19 23:24:52 +02:00
and xa = Co.(get X) @@ Cs.center shell_a
and ya = Co.(get Y) @@ Cs.center shell_a
and za = Co.(get Z) @@ Cs.center shell_a
2020-04-16 19:49:23 +02:00
in
Array.iteri (fun i key ->
let (angMomA, angMomB) = to_powers key in
(* 1D Overlap <i|j> *)
let f k =
let xyz = xyz_of_int k in
Overlap_primitives.hvrr (Po.get xyz angMomA, Po.get xyz angMomB)
expo_inv
(Co.get xyz a_minus_b, Co.get xyz center_pa)
in
(* 1D <i|x-Xa|j> *)
let g k =
let xyz = xyz_of_int k in
Overlap_primitives.hvrr (Po.get xyz angMomA + 1, Po.get xyz angMomB)
expo_inv
(Co.get xyz a_minus_b, Co.get xyz center_pa)
in
(* 1D <i|(x-Xa)^2|j> *)
let h k =
let xyz = xyz_of_int k in
Overlap_primitives.hvrr (Po.get xyz angMomA + 2, Po.get xyz angMomB)
expo_inv
(Co.get xyz a_minus_b, Co.get xyz center_pa)
2020-07-08 11:37:43 +02:00
in
(* 1D <i|(x-Xa)^3|j> *)
let j k =
let xyz = xyz_of_int k in
Overlap_primitives.hvrr (Po.get xyz angMomA + 3, Po.get xyz angMomB)
expo_inv
(Co.get xyz a_minus_b, Co.get xyz center_pa)
in
(* 1D <i|(x-Xa)^4|j> *)
let l k =
let xyz = xyz_of_int k in
Overlap_primitives.hvrr (Po.get xyz angMomA + 4, Po.get xyz angMomB)
expo_inv
(Co.get xyz a_minus_b, Co.get xyz center_pa)
2020-04-16 19:49:23 +02:00
in
let norm = norm_coef_scales.(i) in
2020-07-08 11:37:43 +02:00
let f0, f1, f2, g0, g1, g2, h0, h1, h2, j0, j1, j2 , l0, l1, l2 =
f 0, f 1, f 2, g 0, g 1, g 2, h 0, h 1, h 2, j 0, j 1, j 2, l 0, l 1, l 2
2020-04-16 19:49:23 +02:00
in
let x = g0 +. f0 *. xa in
let y = g1 +. f1 *. ya in
let z = g2 +. f2 *. za in
let x2 = h0 +. xa *. (2. *. x -. xa *. f0) in
let y2 = h1 +. ya *. (2. *. y -. ya *. f1) in
let z2 = h2 +. za *. (2. *. z -. za *. f2) in
2020-09-26 12:02:53 +02:00
let x3 = j0 +. xa *. f0 *. (3. *. x2 -. 3. *. x *. xa +. xa *. xa) in
let y3 = j1 +. ya *. f1 *. (3. *. y2 -. 3. *. y *. ya +. ya *. ya) in
let z3 = j2 +. za *. f2 *. (3. *. z2 -. 3. *. z *. za +. za *. za) in
let x4 = l0 +. xa *. f0 *. ( 4. *. x3 -. 6. *. x2 *. xa +. 4. *. x *. xa *. xa -. xa *. xa *. xa) in
let y4 = l1 +. ya *. f1 *. ( 4. *. y3 -. 6. *. y2 *. ya +. 4. *. y *. ya *. ya -. ya *. ya *. ya) in
let z4 = l2 +. za *. f2 *. ( 4. *. z3 -. 6. *. z2 *. za +. 4. *. z *. za *. za -. za *. za *. za) in
2020-07-08 11:37:43 +02:00
2020-04-16 19:49:23 +02:00
let c = contracted_class in
let d = coef_prod *. norm in
2020-09-26 12:02:53 +02:00
c.(0).(i) <- c.(0).(i) +. d *. x *. f1 *. f2;
c.(1).(i) <- c.(1).(i) +. d *. f0 *. y *. f2;
c.(2).(i) <- c.(2).(i) +. d *. f0 *. f1 *. z;
c.(3).(i) <- c.(3).(i) +. d *. x2 *. f1 *. f2;
c.(4).(i) <- c.(4).(i) +. d *. f0 *. y2 *. f2;
c.(5).(i) <- c.(5).(i) +. d *. f0 *. f1 *. z2;
c.(6).(i) <- c.(6).(i) +. d *. x *. y *. f2;
c.(7).(i) <- c.(7).(i) +. d *. f0 *. y *. z;
c.(8).(i) <- c.(8).(i) +. d *. x *. f1 *. z;
c.(9).(i) <- c.(9).(i) +. d *. x3 *. f1 *. f2;
2020-07-08 11:37:43 +02:00
c.(10).(i) <- c.(10).(i) +. d *. f0 *. y3 *. f2;
c.(11).(i) <- c.(11).(i) +. d *. f0 *. f1 *. z3;
c.(12).(i) <- c.(12).(i) +. d *. x4 *. f1 *. f2;
c.(13).(i) <- c.(13).(i) +. d *. f0 *. y4 *. f2;
c.(14).(i) <- c.(14).(i) +. d *. f0 *. f1 *. z4;
2020-04-16 19:49:23 +02:00
) class_indices
end
) (Csp.coefs_and_shell_pairs shell_p);
let result =
Array.map (fun c -> Zmap.create (Array.length c) ) contracted_class
in
2020-04-19 18:38:14 +02:00
for j=0 to Array.length result -1 do
2020-04-16 19:49:23 +02:00
let rj = result.(j) in
let cj = contracted_class.(j) in
Array.iteri (fun i key -> Zmap.add rj key cj.(i)) class_indices
done;
result
end
(** Create multipole matrices *)
let of_basis basis =
let to_powers x =
let open Zkey in
match to_powers x with
| Three x -> x
| _ -> assert false
in
let n = Bs.size basis
and shell = Bs.contracted_shells basis
in
2020-09-26 12:02:53 +02:00
let result = Array.init 15 (fun _ -> Matrix.create n n |> Matrix.to_bigarray_inplace) in
2020-04-16 19:49:23 +02:00
for j=0 to (Array.length shell) - 1 do
for i=0 to j do
(* Compute all the integrals of the class *)
let cls =
contracted_class shell.(i) shell.(j)
in
2020-07-08 11:37:43 +02:00
for k=0 to 14 do
2020-04-16 19:49:23 +02:00
Array.iteri (fun j_c powers_j ->
let j_c = Cs.index shell.(j) + j_c + 1 in
let xj = to_powers powers_j in
Array.iteri (fun i_c powers_i ->
let i_c = Cs.index shell.(i) + i_c + 1 in
let xi = to_powers powers_i in
let key =
Zkey.of_powers_six xi xj
in
let value =
try Zmap.find cls.(k) key
with Not_found -> 0.
in
result.(k).{i_c,j_c} <- value;
result.(k).{j_c,i_c} <- value;
) (Am.zkey_array (Singlet (Cs.ang_mom shell.(i))))
) (Am.zkey_array (Singlet (Cs.ang_mom shell.(j))))
done;
done;
done;
2020-09-26 12:02:53 +02:00
let result =
Array.map Matrix.of_bigarray_inplace result
in
Array.iter Matrix.detri_inplace result;
2020-04-16 19:49:23 +02:00
result
2020-10-12 08:57:00 +02:00
let to_file ~filename eni_array =
let n = Matrix.dim1 eni_array in
let eni_array = Matrix.to_bigarray_inplace eni_array in
let oc = open_out filename in
for j=1 to n do
for i=1 to j do
let value = eni_array.{i,j} in
if (value <> 0.) then
Printf.fprintf oc " %5d %5d %20.15f\n" i j value;
done;
done;
close_out oc