QCaml/CI/CI.ml

79 lines
1.8 KiB
OCaml
Raw Normal View History

2019-02-22 00:18:32 +01:00
open Lacaml.D
2019-02-22 19:19:11 +01:00
module Ds = Determinant_space
2019-02-22 00:18:32 +01:00
type t =
{
2019-02-22 19:19:11 +01:00
det_space : Ds.t ;
2019-02-22 00:18:32 +01:00
h_matrix : Mat.t lazy_t ;
2019-02-22 19:19:11 +01:00
s2_matrix : Mat.t lazy_t ;
2019-02-22 00:18:32 +01:00
eigensystem : (Mat.t * Vec.t) lazy_t;
}
let det_space t = t.det_space
let h_matrix t = Lazy.force t.h_matrix
2019-02-22 19:19:11 +01:00
let s2_matrix t = Lazy.force t.s2_matrix
2019-02-22 00:18:32 +01:00
let eigensystem t = Lazy.force t.eigensystem
let eigenvectors t =
let (x,_) = eigensystem t in x
let eigenvalues t =
let (_,x) = eigensystem t in x
2019-02-22 19:19:11 +01:00
let h_integrals mo_basis =
2019-02-22 00:18:32 +01:00
let one_e_ints = MOBasis.one_e_ints mo_basis
and two_e_ints = MOBasis.two_e_ints mo_basis
in
2019-02-22 19:19:11 +01:00
( (fun i j _ -> one_e_ints.{i,j}),
(fun i j k l s s' ->
if s' = Spin.other s then
ERI.get_phys two_e_ints i j k l
else
(ERI.get_phys two_e_ints i j k l) -.
(ERI.get_phys two_e_ints i j l k)
) )
let h_ij mo_basis ki kj =
let integrals =
List.map (fun f -> f mo_basis)
[ h_integrals ]
in
CIMatrixElement.make integrals ki kj
|> List.hd
2019-02-22 00:18:32 +01:00
let make det_space =
2019-02-22 19:19:11 +01:00
let ndet = Ds.size det_space in
let det = Ds.determinants det_space in
let mo_basis = Ds.mo_basis det_space in
2019-02-22 00:18:32 +01:00
let h_matrix = lazy (
2019-02-22 19:19:11 +01:00
Array.init ndet (fun i -> let ki = det.(i) in
Array.init ndet (fun j -> let kj = det.(j) in
h_ij mo_basis ki kj
))
|> Mat.of_array
)
in
let s2_matrix = lazy (
Array.init ndet (fun i -> let ki = det.(i) in
Array.init ndet (fun j -> let kj = det.(j) in
CIMatrixElement.make_s2 ki kj
))
|> Mat.of_array
2019-02-22 00:18:32 +01:00
)
in
let eigensystem = lazy (
Lazy.force h_matrix
|> Util.diagonalize_symm
)
in
2019-02-22 19:19:11 +01:00
{ det_space ; h_matrix ; s2_matrix ; eigensystem }
2019-02-22 00:18:32 +01:00