10
1
mirror of https://gitlab.com/scemama/QCaml.git synced 2024-11-06 22:23:42 +01:00

Hartree-Fock OK

This commit is contained in:
Anthony Scemama 2018-02-22 18:20:45 +01:00
parent 2ae07e13df
commit 23389acfc8
4 changed files with 134 additions and 124 deletions

View File

@ -329,7 +329,6 @@ let hvrr_two_e_vector (angMom_a, angMom_b, angMom_c, angMom_d)
result result
(*
and trr_v angMom_a angMom_c = and trr_v angMom_a angMom_c =
match (angMom_a.tot, angMom_c.tot) with match (angMom_a.tot, angMom_c.tot) with
@ -340,123 +339,120 @@ let hvrr_two_e_vector (angMom_a, angMom_b, angMom_c, angMom_d)
try Zmap.find map_2d.(0) key with try Zmap.find map_2d.(0) key with
| Not_found -> | Not_found ->
let result = let xyz = get_xyz angMom_c in
let xyz = get_xyz angMom_c in let axyz = Powers.get xyz angMom_a in
let axyz = Powers.get xyz angMom_a in let cm = Powers.decr xyz angMom_c in
let cm = Powers.decr xyz angMom_c in let cmxyz = Powers.get xyz cm in
let cmxyz = Powers.get xyz cm in let expo_inv_q_over_p =
let expo_inv_q_over_p = Array.mapi (fun l expo_inv_p_l ->
Array.mapi (fun l expo_inv_p_l -> let expo_p_l = 1./.expo_inv_p_l in
let expo_p_l = 1./.expo_inv_p_l in Array.mapi (fun k expo_inv_q_k ->
Array.mapi (fun k expo_inv_q_k -> expo_inv_q_k *. expo_p_l) expo_inv_q ) expo_inv_p
expo_inv_q_k *. expo_p_l) expo_inv_q ) expo_inv_p in
in let result = None in
let result = None in
let result = let result =
if cmxyz < 1 then result else if cmxyz < 1 then result else
let f = 0.5 *. (float_of_int cmxyz) in begin
if abs_float f < cutoff then result else let f = 0.5 *. (float_of_int cmxyz) in
begin let cmm = Powers.decr xyz cm in
let cmm = Powers.decr xyz cm in match result, trr_v angMom_a cmm with
match result, trr_v angMom_a cmm with
| None, None -> None
| Some result, None -> Some result
| None, Some v3 ->
Some (Array.init np (fun l ->
let v3_l = v3.(l) in
Array.mapi (fun k v3_lk ->
expo_inv_q.(k) *. f *. v3_lk) v3_l
) )
| Some result, Some v3 ->
(Array.iteri (fun l v3_l ->
let result_l = result.(l) in
Array.iteri (fun k v3_lk ->
result_l.(k) <- result_l.(k) +.
expo_inv_q.(k) *. f *. v3_lk) v3_l
) v3 ; Some result)
end
in
let result =
match result, trr_v angMom_a cm with
| None, None -> None | None, None -> None
| None, Some v3 ->
Some (Array.init np (fun l ->
let v3_l = v3.(l) in
Array.mapi (fun k v3_lk ->
expo_inv_q.(k) *. f *. v3_lk) v3_l
) )
| Some result, None -> Some result | Some result, None -> Some result
| None, Some v1 -> | Some result, Some v3 ->
Some (Array.init np (fun l -> (Array.iteri (fun l v3_l ->
let v1_l = v1.(l) let result_l = result.(l) in
and cpa = (center_pa xyz).(l) Array.iteri (fun k v3_lk ->
and expo_inv_q_over_p_l = expo_inv_q_over_p.(l) result_l.(k) <- result_l.(k) +.
in expo_inv_q.(k) *. f *. v3_lk) v3_l
Array.mapi (fun k v1_lk -> ) v3 ; Some result)
let cqc = (center_qc xyz).(k) in end
(cqc +. expo_inv_q_over_p_l.(k) *. cpa) *. v1_lk in
) v1_l let result =
) ) begin
| Some result, Some v1 -> match result, trr_v angMom_a cm with
(Array.iteri (fun l v1_l -> | Some result, None -> Some result
let cpa = (center_pa xyz).(l) | Some result, Some v1 ->
and result_l = result.(l) (Array.iteri (fun l v1_l ->
and expo_inv_q_over_p_l = expo_inv_q_over_p.(l) let cpa = (center_pa xyz).(l)
in and result_l = result.(l)
Array.iteri (fun k v1_lk -> and expo_inv_q_over_p_l = expo_inv_q_over_p.(l)
let cqc = (center_qc xyz).(k) in in
result_l.(k) <- result_l.(k) +. Array.iteri (fun k v1_lk ->
(cqc +. expo_inv_q_over_p_l.(k) *. cpa) *. v1_lk let cqc = (center_qc xyz).(k) in
) v1_l result_l.(k) <- result_l.(k) +.
) v1 ; Some result) (cqc +. expo_inv_q_over_p_l.(k) *. cpa) *. v1_lk
in ) v1_l
let result = ) v1 ; Some result)
if cmxyz < 0 then result else | None, None -> None
begin | None, Some v1 ->
let ap = Powers.incr xyz angMom_a in Some (Array.init np (fun l ->
match result, trr_v ap cm with let v1_l = v1.(l)
| None, None -> None and cpa = (center_pa xyz).(l)
| Some result, None -> Some result and expo_inv_q_over_p_l = expo_inv_q_over_p.(l)
| None, Some v4 -> in
Some (Array.init np (fun l -> Array.mapi (fun k v1_lk ->
let v4_l = v4.(l) in let cqc = (center_qc xyz).(k) in
let expo_inv_q_over_p_l = expo_inv_q_over_p.(l) in (cqc +. expo_inv_q_over_p_l.(k) *. cpa) *. v1_lk
Array.mapi (fun k v4_lk -> ) v1_l
-. expo_inv_q_over_p_l.(k) *. v4_lk) v4_l ) )
) ) end
| Some result, Some v4 -> in
(Array.iteri (fun l v4_l -> let result =
let result_l = result.(l) in if cmxyz < 0 then result else
Array.iteri (fun k v4_lk -> begin
let expo_inv_q_over_p_l = expo_inv_q_over_p.(l) in let ap = Powers.incr xyz angMom_a in
result_l.(k) <- result_l.(k) match result, trr_v ap cm with
-. expo_inv_q_over_p_l.(k) *. v4_lk) v4_l | Some result, None -> Some result
) v4 ; Some result) | Some result, Some v4 ->
end (Array.iteri (fun l v4_l ->
in let result_l = result.(l) in
let result = Array.iteri (fun k v4_lk ->
if axyz < 1 then result else let expo_inv_q_over_p_l = expo_inv_q_over_p.(l) in
let f = 0.5 *. (float_of_int axyz) in result_l.(k) <- result_l.(k)
if abs_float f < cutoff then result else -. expo_inv_q_over_p_l.(k) *. v4_lk) v4_l
begin ) v4 ; Some result)
let am = Powers.decr xyz angMom_a in | None, None -> None
match result, trr_v am cm with | None, Some v4 ->
| None, None -> None Some (Array.init np (fun l ->
| Some result, None -> Some result let v4_l = v4.(l) in
| None, Some v2 -> let expo_inv_q_over_p_l = expo_inv_q_over_p.(l) in
Some (Array.init np (fun l -> Array.mapi (fun k v4_lk ->
let v2_l = v2.(l) in -. expo_inv_q_over_p_l.(k) *. v4_lk) v4_l
Array.mapi (fun k v2_lk -> ) )
expo_inv_q.(k) *. f *. v2_lk) v2_l end
) ) in
| Some result, Some v2 -> let result =
(Array.iteri (fun l v2_l -> if axyz < 1 then result else
let result_l = result.(l) in begin
Array.iteri (fun k v2_lk -> let f = 0.5 *. (float_of_int axyz) in
result_l.(k) <- result_l.(k) +. let am = Powers.decr xyz angMom_a in
expo_inv_q.(k) *. f *. v2_lk) v2_l match result, trr_v am cm with
) v2; Some result) | Some result, None -> Some result
end | Some result, Some v2 ->
in result (Array.iteri (fun l v2_l ->
in let result_l = result.(l) in
Zmap.add map_2d.(0) key result; Array.iteri (fun k v2_lk ->
result result_l.(k) <- result_l.(k) +.
*) expo_inv_q.(k) *. f *. v2_lk) v2_l
) v2; Some result)
| None, None -> None
| None, Some v2 ->
Some (Array.init np (fun l ->
let v2_l = v2.(l) in
Array.mapi (fun k v2_lk ->
expo_inv_q.(k) *. f *. v2_lk) v2_l
) )
end
in
Zmap.add map_2d.(0) key result;
result
in in
let sum matrix = let sum matrix =
@ -465,11 +461,8 @@ let hvrr_two_e_vector (angMom_a, angMom_b, angMom_c, angMom_d)
let vrr_v a b = let vrr_v a b =
let v = let v =
vrr_v 0 a b if Array.length zero_m_array < 6 then vrr_v 0 a b
(*
if Array.length zero_m_array < 10 then vrr_v 0 a b
else trr_v a b else trr_v a b
*)
in in
match v with match v with
| None -> 0. | None -> 0.

View File

@ -1,4 +1,6 @@
type t = { type t = {
charge : Charge.t;
electrons : Electrons.t ;
basis : Basis.t; basis : Basis.t;
nuclei : Nuclei.t; nuclei : Nuclei.t;
overlap : Overlap.t lazy_t; overlap : Overlap.t lazy_t;
@ -9,12 +11,21 @@ type t = {
nuclear_repulsion : float; nuclear_repulsion : float;
} }
let make ~nuclei ~basis = let make ?multiplicity:(multiplicity=1) ?charge:(charge=0) ~nuclei basis =
let electrons =
Electrons.make ~multiplicity ~charge nuclei
in
let charge =
Array.fold_left (fun accu (e, _) -> accu + Charge.to_int (Element.to_charge e) )
0 nuclei - Electrons.(electrons.n_alpha + electrons.n_beta)
|> Charge.of_int
in
let overlap = let overlap =
lazy (Overlap.of_basis basis) lazy (Overlap.of_basis basis)
in in
{ {
basis ; nuclei ; overlap ; charge ;
basis ; nuclei ; electrons ; overlap ;
overlap_ortho = lazy (Orthonormalization.make (Lazy.force overlap)); overlap_ortho = lazy (Orthonormalization.make (Lazy.force overlap));
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);
@ -23,12 +34,12 @@ let make ~nuclei ~basis =
} }
let of_filenames ~basis ~nuclei = let of_filenames ?multiplicity:(multiplicity=1) ?charge:(charge=0) ~nuclei basis =
let nuclei = let nuclei =
Nuclei.of_filename ~filename:nuclei Nuclei.of_filename ~filename:nuclei
in in
let basis = let basis =
Basis.of_nuclei_and_basis_filename ~nuclei ~filename:basis Basis.of_nuclei_and_basis_filename ~nuclei ~filename:basis
in in
make ~nuclei ~basis make ~charge ~multiplicity ~nuclei basis

View File

@ -161,3 +161,9 @@ let diagonalize_symm h =
syevd ~vectors:true ~w v syevd ~vectors:true ~w v
in in
v, result v, result
let xt_o_x o x =
gemm o x
|> gemm ~transa:`T x

View File

@ -30,7 +30,7 @@ let run ~out =
in in
let s = let s =
Simulation.of_filenames ~nuclei:nuclei_file ~basis:basis_file Simulation.of_filenames ~nuclei:nuclei_file basis_file
in in
print_endline @@ Nuclei.to_string s.Simulation.nuclei; print_endline @@ Nuclei.to_string s.Simulation.nuclei;