10
1
mirror of https://gitlab.com/scemama/QCaml.git synced 2024-11-09 07:33:40 +01:00
QCaml/Basis/AOBasis.ml

188 lines
4.6 KiB
OCaml
Raw Normal View History

2018-06-13 17:49:58 +02:00
open Lacaml.D
2018-07-05 00:39:17 +02:00
open Util
2018-06-13 17:49:58 +02:00
type t =
{
2020-03-26 16:24:41 +01:00
basis : Basis.t ;
overlap : Overlap.t lazy_t;
2020-04-16 19:49:23 +02:00
multipole : Multipole.t lazy_t;
2020-03-26 16:24:41 +01:00
ortho : Orthonormalization.t lazy_t;
eN_ints : NucInt.t lazy_t;
kin_ints : KinInt.t lazy_t;
ee_ints : ERI.t lazy_t;
ee_lr_ints : ERI_lr.t lazy_t;
f12_ints : F12.t lazy_t;
f12_over_r12_ints : ScreenedERI.t lazy_t;
cartesian : bool ;
2018-06-13 17:49:58 +02:00
}
2020-03-26 16:24:41 +01:00
let basis t = t.basis
let overlap t = Lazy.force t.overlap
2020-04-16 19:49:23 +02:00
let multipole t = Lazy.force t.multipole
2020-03-26 16:24:41 +01:00
let ortho t = Lazy.force t.ortho
let eN_ints t = Lazy.force t.eN_ints
let kin_ints t = Lazy.force t.kin_ints
let ee_ints t = Lazy.force t.ee_ints
let ee_lr_ints t = Lazy.force t.ee_lr_ints
let f12_ints t = Lazy.force t.f12_ints
2020-02-17 19:45:53 +01:00
let f12_over_r12_ints t = Lazy.force t.f12_over_r12_ints
2020-03-26 16:24:41 +01:00
let cartesian t = t.cartesian
2019-02-20 18:24:44 +01:00
2020-04-19 16:54:26 +02:00
module Cs = ContractedShell
let values t point =
2020-05-05 00:29:00 +02:00
let result = Vec.create (Basis.size t.basis) in
Array.iter (fun shell ->
Cs.values shell point
|> Array.iteri
2020-04-19 16:54:26 +02:00
(fun i_c value ->
2020-05-05 00:29:00 +02:00
let i = Cs.index shell + i_c + 1 in
result.{i} <- value)
) (Basis.contracted_shells t.basis);
result
2019-02-20 18:24:44 +01:00
2020-05-05 00:29:00 +02:00
2019-03-26 10:38:50 +01:00
let make ~cartesian ~basis ?f12 nuclei =
2020-05-05 00:29:00 +02:00
let overlap =
lazy (
Overlap.of_basis basis
) in
let ortho =
lazy (
Orthonormalization.make ~cartesian ~basis (Lazy.force overlap)
) in
let eN_ints =
lazy (
NucInt.of_basis_nuclei ~basis nuclei
) in
let kin_ints =
lazy (
KinInt.of_basis basis
) in
let ee_ints =
lazy (
ERI.of_basis basis
) in
let ee_lr_ints =
lazy (
ERI_lr.of_basis basis
) in
let f12_ints =
lazy (
F12.of_basis basis
) in
let f12_over_r12_ints =
lazy (
ScreenedERI.of_basis basis
) in
let multipole =
lazy (
Multipole.of_basis basis
) in
2020-04-16 19:49:23 +02:00
{ basis ; overlap ; multipole ; ortho ; eN_ints ; kin_ints ; ee_ints ;
2020-03-26 16:24:41 +01:00
ee_lr_ints ; f12_ints ; f12_over_r12_ints ; cartesian ;
2018-06-13 17:49:58 +02:00
}
2020-03-26 16:24:41 +01:00
let test_case name t =
2018-07-05 00:39:17 +02:00
let check_matrix title a r =
let a = Mat.to_array a in
2020-04-19 16:54:26 +02:00
Mat.to_array r
2020-03-26 17:43:11 +01:00
|> Array.iteri (fun i x ->
let message =
Printf.sprintf "%s line %d" title i
in
Alcotest.(check (array (float 1.e-10))) message a.(i) x
2020-04-19 16:54:26 +02:00
)
2018-07-05 00:39:17 +02:00
in
2020-05-05 00:29:00 +02:00
let check_eri a r =
2018-07-05 00:39:17 +02:00
let f { ERI.i_r1 ; j_r2 ; k_r1 ; l_r2 ; value } =
2020-03-26 16:24:41 +01:00
(i_r1, (j_r2, (k_r1, (l_r2, value))))
2018-07-05 00:39:17 +02:00
in
2020-03-26 17:43:11 +01:00
let a = ERI.to_list a |> List.rev_map f |> List.rev in
let r = ERI.to_list r |> List.rev_map f |> List.rev in
2020-03-27 15:54:03 +01:00
Alcotest.(check (list (pair int (pair int (pair int (pair int (float 1.e-10))))))) "ERI" a r
2018-07-05 00:39:17 +02:00
in
2020-05-05 00:29:00 +02:00
let check_eri_lr a r =
2020-03-26 17:43:11 +01:00
let f { ERI_lr.i_r1 ; j_r2 ; k_r1 ; l_r2 ; value } =
(i_r1, (j_r2, (k_r1, (l_r2, value))))
in
let a = ERI_lr.to_list a |> List.rev_map f |> List.rev in
let r = ERI_lr.to_list r |> List.rev_map f |> List.rev in
2020-03-27 15:54:03 +01:00
Alcotest.(check (list (pair int (pair int (pair int (pair int (float 1.e-10))))))) "ERI_lr" a r
2020-03-26 17:43:11 +01:00
in
2018-07-05 00:39:17 +02:00
let test_overlap () =
let reference =
2020-03-26 16:24:41 +01:00
sym_matrix_of_file ("test_files/"^name^"_overlap.ref")
2018-07-05 00:39:17 +02:00
in
let overlap =
Lazy.force t.overlap |> Overlap.matrix
in
check_matrix "Overlap" overlap reference
in
let test_eN_ints () =
let reference =
2020-03-26 16:24:41 +01:00
sym_matrix_of_file ("test_files/"^name^"_nuc.ref")
2018-07-05 00:39:17 +02:00
in
let eN_ints =
Lazy.force t.eN_ints |> NucInt.matrix
in
check_matrix "eN_ints" eN_ints reference
in
let test_kin_ints () =
let reference =
2020-03-26 16:24:41 +01:00
sym_matrix_of_file ("test_files/"^name^"_kin.ref")
2018-07-05 00:39:17 +02:00
in
let kin_ints =
Lazy.force t.kin_ints |> KinInt.matrix
in
check_matrix "kin_ints" kin_ints reference
in
let test_ee_ints () =
let reference =
2020-03-26 16:24:41 +01:00
ERI.of_file ("test_files/"^name^"_eri.ref") ~sparsity:`Dense ~size:(Basis.size t.basis)
2018-07-05 00:39:17 +02:00
in
let ee_ints =
2020-03-26 16:24:41 +01:00
Lazy.force t.ee_ints
2018-07-05 00:39:17 +02:00
in
2020-05-05 00:29:00 +02:00
check_eri ee_ints reference
2020-03-26 16:24:41 +01:00
;
in
let test_ee_lr_ints () =
let reference =
2020-03-26 17:43:11 +01:00
ERI_lr.of_file ("test_files/"^name^"_eri_lr.ref") ~sparsity:`Dense
2020-03-26 16:24:41 +01:00
~size:(Basis.size t.basis)
in
2020-03-26 17:43:11 +01:00
let ee_lr_ints =
Lazy.force t.ee_lr_ints
2020-03-26 16:24:41 +01:00
in
2020-05-05 00:29:00 +02:00
check_eri_lr ee_lr_ints reference
2018-07-05 00:39:17 +02:00
in
[
2020-03-26 16:24:41 +01:00
"Overlap", `Quick, test_overlap;
"eN_ints", `Quick, test_eN_ints;
"kin_ints", `Quick, test_kin_ints;
"ee_ints", `Quick, test_ee_ints;
"ee_lr_ints", `Quick, test_ee_lr_ints;
2018-07-05 00:39:17 +02:00
]