10
1
mirror of https://gitlab.com/scemama/QCaml.git synced 2024-12-22 04:13:33 +01:00

Added tests for AOBasis

This commit is contained in:
Anthony Scemama 2018-07-05 00:39:17 +02:00
parent 381a22d499
commit 955f9d014b
14 changed files with 27822 additions and 13 deletions

View File

@ -1,4 +1,5 @@
open Lacaml.D
open Util
type t =
{
@ -39,5 +40,75 @@ let make ~cartesian ~basis nuclei =
let test_case t =
let check_matrix title a r =
let a = Mat.to_array a in
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
) (Mat.to_array r)
in
let check_eri title a r =
let f { ERI.i_r1 ; j_r2 ; k_r1 ; l_r2 ; value } =
(i_r1, (j_r2, (k_r1, (l_r2, value))))
in
let a = ERI.to_list a |> List.map f
and r = ERI.to_list r |> List.map f
in
Alcotest.(check (list (pair int (pair int (pair int (pair int (float 1.e-12))))))) "ERI" a r
in
let test_overlap () =
let reference =
sym_matrix_of_file "test_files/ao_overlap.ref"
in
let overlap =
Lazy.force t.overlap |> Overlap.matrix
in
check_matrix "Overlap" overlap reference
in
let test_eN_ints () =
let reference =
sym_matrix_of_file "test_files/ao_nuc.ref"
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 =
sym_matrix_of_file "test_files/ao_kin.ref"
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 =
ERI.of_file "test_files/ao_eri.ref" ~sparsity:`Dense ~size:(Basis.size t.basis)
in
let ee_ints =
Lazy.force t.ee_ints
in
check_eri "ee_ints" ee_ints reference
in
[
"Overlap", `Quick, test_overlap;
"eN_ints", `Quick, test_eN_ints;
"kin_ints", `Quick, test_kin_ints;
"ee_ints", `Quick, test_ee_ints;
]

View File

@ -17,3 +17,5 @@ val make : cartesian:bool -> basis:Basis.t -> Nuclei.t -> t
molecular geometry {Nuclei.t} *)
(** {2 Tests} *)
val test_case : t -> unit Alcotest.test_case list

View File

@ -34,3 +34,5 @@ val contracted_shells : t -> ContractedShell.t array
val to_string : t -> string
(** Pretty prints the basis set in a string. TODO *)

View File

@ -67,7 +67,10 @@ let test_case ao_basis =
|> Lacaml.D.Mat.to_array
in
Array.iteri (fun i x ->
Alcotest.(check (array (float 1.e-15))) "same guess" a.(i) x) reference
let message =
Printf.sprintf "Guess line %d" (i)
in
Alcotest.(check (array (float 1.e-15))) message a.(i) x) reference
| _ -> assert false
in

View File

@ -10,4 +10,6 @@ type t = guess
val make : ?nocc:int -> guess:[ `Hcore | `Huckel ] -> AOBasis.t -> t
(** {2 Tests} *)
val test_case : AOBasis.t -> unit Alcotest.test_case list

View File

@ -181,7 +181,7 @@ let to_stream d =
if !j > !l then begin
j := 1;
k := !k + 1;
if !k > d.size then begin
if !k > !l then begin
k := 1;
l := !l + 1;
end;
@ -209,3 +209,37 @@ let to_file ?(cutoff=Constants.epsilon) ~filename data =
let of_file ~size ~sparsity filename =
let result = create ~size sparsity in
let ic = Scanf.Scanning.open_in filename in
let rec read_line () =
let result =
try
Some (Scanf.bscanf ic " %d %d %d %d %f" (fun i j k l v ->
set_phys result i j k l v))
with End_of_file -> None
in
match result with
| Some () -> read_line ()
| None -> ()
in
read_line ();
Scanf.Scanning.close_in ic;
result
let to_list data =
let s =
to_stream data
in
let rec append accu =
let d =
try Some (Stream.next s) with
| Stream.Failure -> None
in
match d with
| None -> List.rev accu
| Some d -> append (d :: accu)
in
append []

View File

@ -37,10 +37,18 @@ val set_phys : t -> int -> int -> int -> int -> float -> unit
(** Set an integral using the Physicist's convention {% $\langle ij|kl \rangle$ %}. *)
val to_stream : t -> element Stream.t
(** Fetch all integrals from a stream. *)
(** Retrun the data structure as a stream. *)
val to_list : t -> element list
(** Retrun the data structure as a list. *)
(** {2 I/O} *)
val to_file : ?cutoff:float -> filename:string -> t -> unit
(** Write the data to file, using the physicist's ordering. *)
val of_file : size:int -> sparsity:[< `Dense | `Sparse ]
-> Scanf.Scanning.file_name -> t
(** Read from a text file with format ["%d %d %d %d %f"]. *)

View File

@ -273,3 +273,40 @@ let debug_matrix name a =
Format.printf "@[%s =\n@[%a@]@]@ " name pp_matrix a
let matrix_of_file filename =
let ic = Scanf.Scanning.open_in filename in
let rec read_line accu =
let result =
try
Some (Scanf.bscanf ic " %d %d %f" (fun i j v ->
(i,j,v) :: accu))
with End_of_file -> None
in
match result with
| Some accu -> read_line accu
| None -> List.rev accu
in
let data = read_line [] in
Scanf.Scanning.close_in ic;
let isize, jsize =
List.fold_left (fun (accu_i,accu_j) (i,j,v) ->
(max i accu_i, max j accu_j)) (0,0) data
in
let result =
Lacaml.D.Mat.of_array
(Array.make_matrix isize jsize 0.)
in
List.iter (fun (i,j,v) -> result.{i,j} <- v) data;
result
let sym_matrix_of_file filename =
let result =
matrix_of_file filename
in
for j=1 to Mat.dim1 result do
for i=1 to j do
result.{j,i} <- result.{i,j}
done;
done;
result

View File

@ -90,6 +90,14 @@ $$
val debug_matrix: string -> Lacaml.D.mat -> unit
(** Prints a matrix in stdout for debug *)
val matrix_of_file : string -> Lacaml.D.mat
(** Reads a matrix from a file with format "%d %d %f" corresponding to
[i, j, A.{i,j}]. *)
val sym_matrix_of_file : string -> Lacaml.D.mat
(** Reads a symmetric matrix from a file with format "%d %d %f" corresponding to
[i, j, A.{i,j}]. *)
(** {2 Printers} *)
val pp_float_array_size : Format.formatter -> float array -> unit
(** Example:

View File

@ -1,12 +1,22 @@
let test_water_dz () =
let basis_file = "test_files/cc-pvdz"
let nuclei_file = "test_files/h2o.xyz"
and nuclei_file = "test_files/h2o.xyz"
in
let simulation_closed_shell =
Simulation.of_filenames ~charge:0 ~multiplicity:1 ~nuclei:nuclei_file basis_file
in
let ao_basis =
simulation_closed_shell.Simulation.ao_basis
in
Alcotest.run "Water, cc-pVDZ" [
"AO_Basis", AOBasis.test_case ao_basis;
"Guess", Guess.test_case ao_basis;
]
let () =
Alcotest.run "SCF test" [
"Guess", Guess.test_case simulation_closed_shell.Simulation.ao_basis;
]
test_water_dz ()

27144
test_files/ao_eri.ref Normal file

File diff suppressed because it is too large Load Diff

152
test_files/ao_kin.ref Normal file
View File

@ -0,0 +1,152 @@
1 1 2.921577233608e+01
1 2 -8.119801866963e+00
2 2 2.682631425310e+00
1 3 1.678795169747e-01
2 3 2.397955546354e-01
3 3 4.534500000000e-01
4 4 2.037148464379e+00
5 5 2.037148464379e+00
6 6 2.037148464379e+00
4 7 3.830827872764e-01
7 7 6.882500000000e-01
5 8 3.830827872764e-01
8 8 6.882500000000e-01
6 9 3.830827872764e-01
9 9 6.882500000000e-01
1 10 -7.454414939129e-01
2 10 5.142431587554e-01
3 10 3.983585189562e-01
10 10 2.567500000000e+00
11 11 4.147500000000e+00
12 12 4.147500000000e+00
1 13 -7.454414939129e-01
2 13 5.142431587554e-01
3 13 3.983585189562e-01
10 13 -1.975000000000e-01
13 13 2.567500000000e+00
14 14 4.147500000000e+00
1 15 -7.454414939129e-01
2 15 5.142431587554e-01
3 15 3.983585189562e-01
10 15 -1.975000000000e-01
13 15 -1.975000000000e-01
15 15 2.567500000000e+00
1 16 -1.625245710154e-03
2 16 1.883414871004e-02
3 16 9.609863471787e-02
4 16 -7.043955417211e-02
6 16 -5.452046836450e-02
7 16 -1.987883398142e-01
9 16 -1.538628902391e-01
10 16 1.176562813393e-01
12 16 1.777802503510e-01
13 16 -1.495482754154e-02
15 16 6.449004371052e-02
16 16 3.347671997727e-01
1 17 1.846585301041e-02
2 17 4.084053838595e-02
3 17 1.369515771765e-01
4 17 -2.715030181110e-02
6 17 -2.101443128618e-02
7 17 -1.164399853683e-01
9 17 -9.012496761581e-02
10 17 8.455611116740e-02
12 17 1.403241892240e-02
13 17 7.408894943315e-02
15 17 8.035963311395e-02
16 17 1.182520739417e-01
17 17 1.830000000000e-01
1 18 3.951372266567e-02
2 18 1.695591769735e-01
3 18 2.382528843220e-01
4 18 -3.239997736207e-01
6 18 -3.449160943226e-01
7 18 -7.502046695243e-02
9 18 -2.816860634455e-01
10 18 2.881592031694e-01
12 18 6.240799325682e-01
13 18 8.803539819411e-02
15 18 5.259115937610e-01
18 18 1.817500000000e+00
5 19 1.216261837434e-01
8 19 2.889133238019e-01
11 19 -4.596764763563e-01
14 19 -3.557912465751e-01
19 19 1.817500000000e+00
1 20 3.058376351011e-02
2 20 1.312394130364e-01
3 20 1.844085896781e-01
4 20 -3.449160943226e-01
6 20 -1.453401142399e-01
7 20 -2.816860634455e-01
9 20 7.088729721359e-02
10 20 6.338686039953e-01
12 20 2.987473417905e-01
13 20 6.813971494582e-02
15 20 -3.774878216471e-03
20 20 1.817500000000e+00
1 21 -1.625245710154e-03
2 21 1.883414871004e-02
3 21 9.609863471787e-02
4 21 7.043955417211e-02
6 21 -5.452046836450e-02
7 21 1.987883398142e-01
9 21 -1.538628902391e-01
10 21 1.176562813393e-01
12 21 -1.777802503510e-01
13 21 -1.495482754154e-02
15 21 6.449004371052e-02
16 21 -1.048847055322e-02
17 21 2.463983558179e-02
18 21 9.415566467729e-04
21 21 3.347671997727e-01
1 22 1.846585301041e-02
2 22 4.084053838595e-02
3 22 1.369515771765e-01
4 22 2.715030181110e-02
6 22 -2.101443128618e-02
7 22 1.164399853683e-01
9 22 -9.012496761581e-02
10 22 8.455611116740e-02
12 22 -1.403241892240e-02
13 22 7.408894943315e-02
15 22 8.035963311395e-02
16 22 2.463983558179e-02
17 22 7.410708495360e-02
18 22 6.021333451474e-02
21 22 1.182520739417e-01
22 22 1.830000000000e-01
1 23 -3.951372266567e-02
2 23 -1.695591769735e-01
3 23 -2.382528843220e-01
4 23 -3.239997736207e-01
6 23 3.449160943226e-01
7 23 -7.502046695243e-02
9 23 2.816860634455e-01
10 23 -2.881592031694e-01
12 23 6.240799325682e-01
13 23 -8.803539819411e-02
15 23 -5.259115937610e-01
16 23 -9.415566467729e-04
17 23 -6.021333451474e-02
18 23 -1.335361388732e-01
23 23 1.817500000000e+00
5 24 1.216261837434e-01
8 24 2.889133238019e-01
11 24 4.596764763563e-01
14 24 -3.557912465751e-01
19 24 -1.762927240490e-02
24 24 1.817500000000e+00
1 25 3.058376351011e-02
2 25 1.312394130364e-01
3 25 1.844085896781e-01
4 25 3.449160943226e-01
6 25 -1.453401142399e-01
7 25 2.816860634455e-01
9 25 7.088729721359e-02
10 25 6.338686039953e-01
12 25 -2.987473417905e-01
13 25 6.813971494582e-02
15 25 -3.774878216471e-03
20 25 -1.762927240490e-02
25 25 1.817500000000e+00

184
test_files/ao_nuc.ref Normal file
View File

@ -0,0 +1,184 @@
1 1 -62.275538570011626
1 2 12.125766386472707
2 2 -5.343929717466414
1 3 -6.100269746982712
2 3 -2.806625238561235
3 3 -8.073112495140448
4 4 -6.070483981972077
5 5 -6.020376245163298
1 6 0.021047824795628
2 6 0.059542698627091
3 6 0.122128952648285
6 6 -6.050394866778804
4 7 -3.024512985962175
7 7 -5.520724858265616
5 8 -2.957829307189493
8 8 -5.294960875803310
1 9 0.005735454188750
2 9 0.058986375084516
3 9 0.242182169825154
6 9 -2.997778270134004
9 9 -5.430211916771475
1 10 -1.268812623301953
2 10 -3.022019170332814
3 10 -5.664435751167721
6 10 0.083812871378967
9 10 0.127380222267056
10 10 -8.628204685058252
11 11 -8.479382644014068
4 12 0.145168151556606
7 12 0.220629016845957
12 12 -8.638057540209802
1 13 -1.264930391412323
2 13 -2.973934120559030
3 13 -5.534631816432880
6 13 0.048930954133317
9 13 0.060238608721114
10 13 -2.826460881338021
13 13 -8.388581378260625
5 14 0.084750898621728
8 14 0.104336330882231
14 14 -8.442978743068055
1 15 -1.267256164986236
2 15 -3.002740987650844
3 15 -5.612394961391496
6 15 0.167689976133437
9 15 0.220939129390582
10 15 -2.879352513403266
13 15 -2.814326247689351
15 15 -8.518199690267490
1 16 -0.952782331128032
2 16 -0.659697257447191
3 16 -2.133380584676123
4 16 0.781678807320804
6 16 0.621904009887217
7 16 1.683543836881078
9 16 1.335016133706429
10 16 -1.667756769813941
12 16 -0.892129017039093
13 16 -1.002036072838890
15 16 -1.417221214109857
16 16 -2.107649553933351
1 17 -2.125569862292254
2 17 -1.283697589114871
3 17 -4.356847439238844
4 17 0.475989916364254
6 17 0.422920264606057
7 17 1.457001429268338
9 17 1.281208833804038
10 17 -2.714649250270574
12 17 -0.177568399270841
13 17 -2.534034955544656
15 17 -2.657802917740243
16 17 -2.216667723612138
17 17 -4.400950633759910
1 18 -2.722272718137221
2 18 -1.342430040285649
3 18 -3.134245891244376
4 18 1.207502416332363
6 18 1.859803173331492
7 18 0.154338245034725
9 18 1.875416611517870
10 18 -2.122324389752063
12 18 -1.399421827416947
13 18 -2.110282781750609
15 18 -3.412988363382125
16 18 -0.725572895656271
17 18 -1.058526698205781
18 18 -6.039011282703799
5 19 -1.143153779160152
8 19 -2.197963104716381
11 19 1.795742318003083
14 19 1.414000635111198
19 19 -5.201581003294230
1 20 -2.105375144535297
2 20 -1.024185792572825
3 20 -2.373112850525145
4 20 1.813239423354615
6 20 0.279098841704008
7 20 1.795210877899557
9 20 -0.795441044877890
10 20 -3.226105544921671
12 20 -0.373373026048553
13 20 -1.619458317062542
15 20 -0.975233500904051
16 20 -0.526642074592188
17 20 -0.763663320985964
18 20 -0.614080030530267
20 20 -5.676881156330306
1 21 -0.952782331128032
2 21 -0.659697257447191
3 21 -2.133380584676123
4 21 -0.781678807320804
6 21 0.621904009887217
7 21 -1.683543836881078
9 21 1.335016133706429
10 21 -1.667756769813941
12 21 0.892129017039093
13 21 -1.002036072838890
15 21 -1.417221214109857
16 21 -0.314984996351282
17 21 -1.134126995835193
18 21 -0.762024763333394
20 21 -0.126622780128378
21 21 -2.107649553933350
1 22 -2.125569862292254
2 22 -1.283697589114871
3 22 -4.356847439238845
4 22 -0.475989916364254
6 22 0.422920264606057
7 22 -1.457001429268338
9 22 1.281208833804038
10 22 -2.714649250270574
12 22 0.177568399270841
13 22 -2.534034955544656
15 22 -2.657802917740243
16 22 -1.134126995835193
17 22 -3.038370745562461
18 22 -1.548585213033768
20 22 -0.470482164033214
21 22 -2.216667723612139
22 22 -4.400950633759910
1 23 2.722272718137221
2 23 1.342430040285649
3 23 3.134245891244376
4 23 1.207502416332363
6 23 -1.859803173331492
7 23 0.154338245034725
9 23 -1.875416611517870
10 23 2.122324389752063
12 23 -1.399421827416947
13 23 2.110282781750609
15 23 3.412988363382125
16 23 0.762024763333394
17 23 1.548585213033768
18 23 2.123053594706917
20 23 0.327619011507388
21 23 0.725572895656271
22 23 1.058526698205781
23 23 -6.039011282703799
5 24 -1.143153779160152
8 24 -2.197963104716381
11 24 -1.795742318003083
14 24 1.414000635111198
19 24 -0.335614222402832
24 24 -5.201581003294229
1 25 -2.105375144535297
2 25 -1.024185792572825
3 25 -2.373112850525145
4 25 -1.813239423354615
6 25 0.279098841704008
7 25 -1.795210877899557
9 25 -0.795441044877890
10 25 -3.226105544921671
12 25 0.373373026048553
13 25 -1.619458317062542
15 25 -0.975233500904051
16 25 -0.126622780128378
17 25 -0.470482164033214
18 25 -0.327619011507388
20 25 -0.455545660034585
21 25 -0.526642074592188
22 25 -0.763663320985964
23 25 0.614080030530267
25 25 -5.676881156330306

152
test_files/ao_overlap.ref Normal file
View File

@ -0,0 +1,152 @@
1 1 1.000998080253e+00
1 2 -1.089770396863e-01
2 2 2.589136611840e-01
1 3 1.944811333519e-01
2 3 3.605646305751e-01
3 3 1.000000000000e+00
4 4 4.710359000708e-01
5 5 4.710359000708e-01
6 6 4.710359000708e-01
4 7 3.440329210735e-01
7 7 1.000000000000e+00
5 8 3.440329210735e-01
8 8 1.000000000000e+00
6 9 3.440329210735e-01
9 9 1.000000000000e+00
1 10 7.062162317220e-02
2 10 3.205188022439e-01
3 10 6.642837680050e-01
10 10 1.000000000000e+00
11 11 1.000000000000e+00
12 12 1.000000000000e+00
1 13 7.062162317220e-02
2 13 3.205188022439e-01
3 13 6.642837680050e-01
10 13 3.333333333333e-01
13 13 1.000000000000e+00
14 14 1.000000000000e+00
1 15 7.062162317220e-02
2 15 3.205188022439e-01
3 15 6.642837680050e-01
10 15 3.333333333333e-01
13 15 3.333333333333e-01
15 15 1.000000000000e+00
1 16 3.171319480222e-02
2 16 8.268963186213e-02
3 16 2.921899212170e-01
4 16 -8.998501474641e-02
6 16 -6.964872517185e-02
7 16 -2.892387585156e-01
9 16 -2.238718397465e-01
10 16 2.071461679848e-01
12 16 1.137023134320e-01
13 16 1.223325295927e-01
15 16 1.731428172024e-01
16 16 3.453140483256e-01
1 17 6.976572432971e-02
2 17 1.656227325961e-01
3 17 6.480686780259e-01
4 17 -5.761190681911e-02
6 17 -4.459182316054e-02
7 17 -3.097468249184e-01
9 17 -2.397451569285e-01
10 17 3.386153785280e-01
12 17 2.021320317353e-02
13 17 3.235378022416e-01
15 17 3.325705003087e-01
16 17 4.024473615409e-01
17 17 1.000000000000e+00
1 18 8.785967280055e-02
2 18 1.625995182322e-01
3 18 3.097200982275e-01
4 18 -1.126177340593e-01
6 18 -1.912976723480e-01
7 18 7.162906290324e-02
9 18 -2.477755283293e-01
10 18 2.142693129905e-01
12 18 1.644679231103e-01
13 18 2.369695468836e-01
15 18 3.975607902238e-01
18 18 1.000000000000e+00
5 19 1.345357324933e-01
8 19 3.917509964418e-01
11 19 -2.518078274267e-01
14 19 -1.949001644106e-01
19 19 1.000000000000e+00
1 20 6.800370285896e-02
2 20 1.258526121304e-01
3 20 2.397244703736e-01
4 20 -1.912976723480e-01
6 20 -1.352935417619e-02
7 20 -2.477755283293e-01
9 20 1.999718460405e-01
10 20 3.908965439518e-01
12 20 2.634436528908e-02
13 20 1.834152818834e-01
15 20 8.266215724669e-02
20 20 1.000000000000e+00
1 21 3.171319480222e-02
2 21 8.268963186213e-02
3 21 2.921899212170e-01
4 21 8.998501474641e-02
6 21 -6.964872517185e-02
7 21 2.892387585156e-01
9 21 -2.238718397465e-01
10 21 2.071461679848e-01
12 21 -1.137023134320e-01
13 21 1.223325295927e-01
15 21 1.731428172024e-01
16 21 4.183516455622e-02
17 21 1.807587458354e-01
18 21 9.394699365630e-02
21 21 3.453140483256e-01
1 22 6.976572432971e-02
2 22 1.656227325961e-01
3 22 6.480686780259e-01
4 22 5.761190681911e-02
6 22 -4.459182316054e-02
7 22 3.097468249184e-01
9 22 -2.397451569285e-01
10 22 3.386153785280e-01
12 22 -2.021320317353e-02
13 22 3.235378022416e-01
15 22 3.325705003087e-01
16 22 1.807587458354e-01
17 22 6.069828068976e-01
18 22 1.751930664878e-01
21 22 4.024473615409e-01
22 22 1.000000000000e+00
1 23 -8.785967280055e-02
2 23 -1.625995182322e-01
3 23 -3.097200982275e-01
4 23 -1.126177340593e-01
6 23 1.912976723480e-01
7 23 7.162906290324e-02
9 23 2.477755283293e-01
10 23 -2.142693129905e-01
12 23 1.644679231103e-01
13 23 -2.369695468836e-01
15 23 -3.975607902238e-01
16 23 -9.394699365630e-02
17 23 -1.751930664878e-01
18 23 -2.526746162319e-01
23 23 1.000000000000e+00
5 24 1.345357324933e-01
8 24 3.917509964418e-01
11 24 2.518078274267e-01
14 24 -1.949001644106e-01
19 24 5.104398252778e-02
24 24 1.000000000000e+00
1 25 6.800370285896e-02
2 25 1.258526121304e-01
3 25 2.397244703736e-01
4 25 1.912976723480e-01
6 25 -1.352935417619e-02
7 25 2.477755283293e-01
9 25 1.999718460405e-01
10 25 3.908965439518e-01
12 25 -2.634436528908e-02
13 25 1.834152818834e-01
15 25 8.266215724669e-02
20 25 5.104398252778e-02
25 25 1.000000000000e+00