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

Nuclear repulsion

This commit is contained in:
Anthony Scemama 2018-02-20 23:54:48 +01:00
parent 34edda6317
commit 0455da3b46
9 changed files with 143 additions and 176 deletions

7
.merlin Normal file
View File

@ -0,0 +1,7 @@
PKG str unix bigarray lacaml
S .
S Nuclei
S Utils
S Basis
S HartreeFock
B _build/**

View File

@ -41,30 +41,9 @@ let rec hvrr_two_e (angMom_a, angMom_b, angMom_c, angMom_d)
| _ -> Z | _ -> Z
in in
(*
if debug then begin
Printf.printf "\n---- %d %d %d %d ----\n" totAngMom_a totAngMom_b totAngMom_c totAngMom_d;
let (x,y,z) = angMom_a in Printf.printf "%d %d %d\n" x y z;
let (x,y,z) = angMom_b in Printf.printf "%d %d %d\n" x y z;
let (x,y,z) = angMom_c in Printf.printf "%d %d %d\n" x y z;
let (x,y,z) = angMom_d in Printf.printf "%d %d %d\n" x y z;
Printf.printf "%f %f %f %f\n%f %f %f\n%f %f %f\n%f %f %f\n" expo_b expo_d
expo_inv_p expo_inv_q
(get X center_ab) (get Y center_ab) (get Z center_ab)
(get X center_cd) (get Y center_cd) (get Z center_cd)
(get X center_pq) (get Y center_pq) (get Z center_pq)
end;
*)
(** Vertical recurrence relations *) (** Vertical recurrence relations *)
let rec vrr0 angMom_a = let rec vrr0 angMom_a =
(*
if debug then
begin
let (x,y,z) = angMom_a in
Printf.printf "vrr0: %d : %d %d %d\n" angMom_a.tot x y z
end;
*)
match angMom_a.tot with match angMom_a.tot with
| 0 -> zero_m_array | 0 -> zero_m_array
@ -78,59 +57,45 @@ let rec hvrr_two_e (angMom_a, angMom_b, angMom_c, angMom_d)
let am = Powers.decr xyz angMom_a in let am = Powers.decr xyz angMom_a in
let amxyz = Powers.get xyz am in let amxyz = Powers.get xyz am in
if amxyz < 0 then empty else if amxyz >= 0 then
let f1 = expo_inv_p *. (Coordinate.get xyz center_pq) let f1 = expo_inv_p *. (Coordinate.get xyz center_pq)
and f2 = expo_b *. expo_inv_p *. (Coordinate.get xyz center_ab) and f2 = expo_b *. expo_inv_p *. (Coordinate.get xyz center_ab)
in in
let result = Array.create_float maxsze in let result = Array.create_float maxsze in
if amxyz < 1 then if amxyz < 1 then
begin begin
let v1 = let v1 =
vrr0 am vrr0 am
in in
for m=0 to maxm-1 do for m=0 to maxm-1 do
result.(m) <- f1 *. v1.(m+1) -. f2 *. v1.(m) result.(m) <- f1 *. v1.(m+1) -. f2 *. v1.(m)
done; done;
result.(maxm) <- -. f2 *. v1.(maxm) result.(maxm) <- -. f2 *. v1.(maxm)
end end
else else
begin begin
let amm = Powers.decr xyz am in let amm = Powers.decr xyz am in
let v3 = vrr0 amm in let v3 = vrr0 amm in
let v1 = vrr0 am in let v1 = vrr0 am in
let f3 = (float_of_int amxyz) *. expo_inv_p *. 0.5 in let f3 = (float_of_int amxyz) *. expo_inv_p *. 0.5 in
for m=0 to maxm-1 do for m=0 to maxm-1 do
result.(m) <- f1 *. v1.(m+1) -. f2 *. v1.(m) result.(m) <- f1 *. v1.(m+1) -. f2 *. v1.(m)
+. f3 *. (v3.(m) +. expo_inv_p *. v3.(m+1)) +. f3 *. (v3.(m) +. expo_inv_p *. v3.(m+1))
done; done;
result.(maxm) <- f3 *. v3.(maxm) result.(maxm) <- f3 *. v3.(maxm)
end; end;
result result
else
empty
in Zmap.add map_1d key result; in Zmap.add map_1d key result;
result result
and vrr angMom_a angMom_c = and vrr angMom_a angMom_c =
(*
if debug then
begin
let angMom_ax, angMom_ay, angMom_az = angMom_a in
let angMom_cx, angMom_cy, angMom_cz = angMom_c in
Printf.printf "vrr : %d %d : %d %d %d %d %d %d\n" angMom_a.tot angMom_c.tot
angMom_ax angMom_ay angMom_az angMom_cx angMom_cy angMom_cz
end;
*)
match (angMom_a.tot, angMom_c.tot) with match (angMom_a.tot, angMom_c.tot) with
| (i,0) -> if (i>0) then | (i,0) -> if (i>0) then vrr0 angMom_a
vrr0 angMom_a else zero_m_array
(*
OneElectronRR.hvrr_one_e (angMom_a, angMom_b) (angMom_a.tot, angMom_b.tot)
(maxm, zero_m_array) (expo_b) (expo_inv_p) (center_ab, center_pq, center_ab)
map_1d
*)
else zero_m_array
| (_,_) -> | (_,_) ->
let key = Zkey.of_powers (Zkey.Six (angMom_a, angMom_c)) in let key = Zkey.of_powers (Zkey.Six (angMom_a, angMom_c)) in
@ -142,58 +107,59 @@ let rec hvrr_two_e (angMom_a, angMom_b, angMom_c, angMom_d)
let cmxyz = Powers.get xyz cm in let cmxyz = Powers.get xyz cm in
let axyz = Powers.get xyz angMom_a in let axyz = Powers.get xyz angMom_a in
if cmxyz < 0 then empty if cmxyz >= 0 then
else let f1 =
let f1 = -. expo_d *. expo_inv_q *. (Coordinate.get xyz center_cd)
-. expo_d *. expo_inv_q *. (Coordinate.get xyz center_cd) and f2 =
and f2 = expo_inv_q *. (Coordinate.get xyz center_pq)
expo_inv_q *. (Coordinate.get xyz center_pq) in
in let result = Array.make maxsze 0. in
let result = Array.make maxsze 0. in if ( (abs_float f1 > cutoff) || (abs_float f2 > cutoff) ) then
if ( (abs_float f1 > cutoff) || (abs_float f2 > cutoff) ) then
begin
let v1 =
vrr angMom_a cm
in
for m=0 to maxm-1 do
result.(m) <- f1 *. v1.(m) -. f2 *. v1.(m+1) ;
done;
result.(maxm) <- f1 *. v1.(maxm) ;
end;
if cmxyz > 0 then
begin
let f3 =
(float_of_int cmxyz) *. expo_inv_q *. 0.5
in
if (abs_float f3 > cutoff) ||
(abs_float (f3 *. expo_inv_q) > cutoff) then
begin begin
let v3 = let v1 =
let cmm = Powers.decr xyz cm in vrr angMom_a cm
vrr angMom_a cmm
in in
for m=0 to maxm-1 do for m=0 to maxm-1 do
result.(m) <- result.(m) +. result.(m) <- f1 *. v1.(m) -. f2 *. v1.(m+1) ;
f3 *. (v3.(m) +. expo_inv_q *. v3.(m+1))
done; done;
result.(maxm) <- result.(maxm) +. f3 *. v3.(maxm) result.(maxm) <- f1 *. v1.(maxm) ;
end end;
end; if cmxyz > 0 then
if (axyz > 0) && (cmxyz >= 0) then begin
begin let f3 =
let am = Powers.decr xyz angMom_a in (float_of_int cmxyz) *. expo_inv_q *. 0.5
let f5 = in
(float_of_int axyz) *. expo_inv_p *. expo_inv_q *. 0.5 if (abs_float f3 > cutoff) ||
in (abs_float (f3 *. expo_inv_q) > cutoff) then
if (abs_float f5 > cutoff) then begin
let v5 = let v3 =
vrr am cm let cmm = Powers.decr xyz cm in
in vrr angMom_a cmm
for m=0 to maxm-1 do in
result.(m) <- result.(m) -. f5 *. v5.(m+1) for m=0 to maxm-1 do
done result.(m) <- result.(m) +.
end; f3 *. (v3.(m) +. expo_inv_q *. v3.(m+1))
result done;
result.(maxm) <- result.(maxm) +. f3 *. v3.(maxm)
end
end;
if axyz > 0 && cmxyz >= 0 then
begin
let am = Powers.decr xyz angMom_a in
let f5 =
(float_of_int axyz) *. expo_inv_p *. expo_inv_q *. 0.5
in
if (abs_float f5 > cutoff) then
let v5 =
vrr am cm
in
for m=0 to maxm-1 do
result.(m) <- result.(m) -. f5 *. v5.(m+1)
done
end;
result
else
empty
in Zmap.add map_2d key result; in Zmap.add map_2d key result;
result result
@ -204,74 +170,47 @@ let rec hvrr_two_e (angMom_a, angMom_b, angMom_c, angMom_d)
(** Horizontal recurrence relations *) (** Horizontal recurrence relations *)
and hrr0 angMom_a angMom_b angMom_c = and hrr0 angMom_a angMom_b angMom_c =
(*
if debug then
begin
let angMom_ax, angMom_ay, angMom_az = angMom_a
and angMom_bx, angMom_by, angMom_bz = angMom_b
and angMom_cx, angMom_cy, angMom_cz = angMom_c in
Printf.printf "hrr0: %d %d %d : %d %d %d %d %d %d %d %d %d\n"
angMom_ax angMom_ay angMom_az
angMom_bx angMom_by angMom_bz
angMom_cx angMom_cy angMom_cz
end;
*)
match angMom_b.tot with match angMom_b.tot with
| 0 -> (vrr angMom_a angMom_c).(0) | 0 -> (vrr angMom_a angMom_c).(0)
| 1 -> | 1 ->
let xyz = get_xyz angMom_b in let xyz = get_xyz angMom_b in
let ap = Powers.incr xyz angMom_a in let ap = Powers.incr xyz angMom_a in
let v1 = let v1 = vrr ap angMom_c in
vrr ap angMom_c let f2 = Coordinate.get xyz center_ab in
in
let f2 =
(Coordinate.get xyz center_ab)
in
if (abs_float f2 < cutoff) then v1.(0) else if (abs_float f2 < cutoff) then v1.(0) else
let v2 = let v2 = vrr angMom_a angMom_c in
vrr angMom_a angMom_c v1.(0) +. f2 *. v2.(0)
in
v1.(0) +. f2 *. v2.(0)
| _ -> | _ ->
let xyz = get_xyz angMom_b in let xyz = get_xyz angMom_b in
let bxyz = Powers.get xyz angMom_b in let bxyz = Powers.get xyz angMom_b in
if (bxyz < 1) then 0. else if bxyz > 0 then
let ap = Powers.incr xyz angMom_a in let ap = Powers.incr xyz angMom_a in
let bm = Powers.decr xyz angMom_b in let bm = Powers.decr xyz angMom_b in
let h1 = let h1 = hrr0 ap bm angMom_c in
hrr0 ap bm angMom_c let f2 = Coordinate.get xyz center_ab in
in if abs_float f2 < cutoff then h1 else
let f2 = let h2 = hrr0 angMom_a bm angMom_c in
(Coordinate.get xyz center_ab) h1 +. f2 *. h2
in else 0.
if (abs_float f2 < cutoff) then h1 else
let h2 =
hrr0 angMom_a bm angMom_c
in
h1 +. f2 *. h2
and hrr angMom_a angMom_b angMom_c angMom_d = and hrr angMom_a angMom_b angMom_c angMom_d =
match (angMom_b.tot, angMom_d.tot) with match (angMom_b.tot, angMom_d.tot) with
| (_,0) -> if (angMom_b.tot = 0) then | (_,0) ->
(vrr angMom_a angMom_c).(0) if (angMom_b.tot = 0) then
(vrr angMom_a angMom_c).(0)
else else
hrr0 angMom_a angMom_b angMom_c hrr0 angMom_a angMom_b angMom_c
| (_,_) -> | (_,_) ->
let xyz = get_xyz angMom_d in let xyz = get_xyz angMom_d in
let cp = Powers.incr xyz angMom_c in let cp = Powers.incr xyz angMom_c in
let dm = Powers.decr xyz angMom_d in let dm = Powers.decr xyz angMom_d in
let h1 = let h1 = hrr angMom_a angMom_b cp dm in
hrr angMom_a angMom_b cp dm
in
let f2 = Coordinate.get xyz center_cd in let f2 = Coordinate.get xyz center_cd in
if (abs_float f2 < cutoff) then h1 else if abs_float f2 < cutoff then h1 else
let h2 = let h2 = hrr angMom_a angMom_b angMom_c dm in
hrr angMom_a angMom_b angMom_c dm h1 +. f2 *. h2
in
h1 +. f2 *. h2
in in
hrr angMom_a angMom_b angMom_c angMom_d hrr angMom_a angMom_b angMom_c angMom_d

View File

@ -159,17 +159,10 @@ let hvrr_two_e_vector (angMom_a, angMom_b, angMom_c, angMom_d)
| None -> None | None -> None
| Some v1 -> | Some v1 ->
begin begin
let result = Array.make_matrix np nq 0. in Some (Array.init np (fun l ->
for l=0 to np-1 do let v1_l = v1.(l) in
for k=0 to nq-1 do Array.mapi (fun k f1k -> v1_l.(k) *. f1k) f1
result.(l).(k) <- v1.(l).(k) *. f1.(k) ) )
done
done;
Some (
Array.init np (fun l ->
let v1_l = v1.(l) in
Array.init nq (fun k -> v1_l.(k) *. f1.(k))
))
end end
else None else None
in in

View File

@ -1,6 +1,6 @@
.NOPARALLEL: .NOPARALLEL:
INCLUDE_DIRS=Nuclei,Utils,Basis INCLUDE_DIRS=Nuclei,Utils,Basis,HartreeFock
LIBS= LIBS=
PKGS= PKGS=
OCAMLCFLAGS="-g -warn-error A" OCAMLCFLAGS="-g -warn-error A"

View File

@ -1,4 +1,4 @@
type t = float type t = private float
(** Float conversion functions *) (** Float conversion functions *)
val to_float : t -> float val to_float : t -> float

View File

@ -1,3 +1,4 @@
open Util
open Xyz_ast open Xyz_ast
type t = (Element.t * Coordinate.t) array type t = (Element.t * Coordinate.t) array
@ -70,3 +71,18 @@ let of_filename ~filename =
of_xyz_file filename of_xyz_file filename
let repulsion ~nuclei =
let get_charge e =
Element.to_charge e
|> Charge.to_float
in
Array.fold_left ( fun accu (e1, coord1) ->
accu +.
Array.fold_left (fun accu (e2, coord2) ->
let r = Coordinate.(norm (coord1 |- coord2)) in
if r > 0. then
accu +. 0.5 *. (get_charge e2) *. (get_charge e1) /. r
else accu
) 0. nuclei
) 0. nuclei

View File

@ -5,6 +5,7 @@ type t = {
eN_ints : NucInt.t lazy_t; eN_ints : NucInt.t lazy_t;
kin_ints : KinInt.t lazy_t; kin_ints : KinInt.t lazy_t;
ee_ints : ERI.t lazy_t; ee_ints : ERI.t lazy_t;
nuclear_repulsion : float;
} }
let make ~nuclei ~basis = let make ~nuclei ~basis =
@ -14,6 +15,7 @@ let make ~nuclei ~basis =
eN_ints = lazy (NucInt.of_basis_nuclei basis nuclei); eN_ints = lazy (NucInt.of_basis_nuclei basis nuclei);
kin_ints = lazy (KinInt.of_basis basis); kin_ints = lazy (KinInt.of_basis basis);
ee_ints = lazy (ERI.of_basis basis); ee_ints = lazy (ERI.of_basis basis);
nuclear_repulsion = Nuclei.repulsion nuclei;
} }

View File

@ -144,3 +144,11 @@ let boys_function ~maxm t =
result result
end end
let array_sum a =
Array.fold_left ( +. ) 0. a
let array_product a =
Array.fold_left ( *. ) 0. a

View File

@ -36,6 +36,8 @@ let run ~out =
in in
print_endline @@ Nuclei.to_string s.Simulation.nuclei; print_endline @@ Nuclei.to_string s.Simulation.nuclei;
print_endline "Nuclear repulsion : ";
print_float s.Simulation.nuclear_repulsion; print_newline ();
print_endline @@ Basis.to_string s.Simulation.basis; print_endline @@ Basis.to_string s.Simulation.basis;
let overlap = Lazy.force s.Simulation.overlap in let overlap = Lazy.force s.Simulation.overlap in