2019-03-03 01:43:04 +01:00
|
|
|
(** Data structures for storing the determinant space.
|
|
|
|
|
|
|
|
If the space is built as the outer product of all {% $\alpha$ %} and {%
|
|
|
|
$\beta$ %} determinants, the storage is of type [Spin]. It is sufficient
|
|
|
|
to have the arrays of {% $\alpha$ %} and {% $\beta$ %} spindeterminants.
|
|
|
|
|
|
|
|
Otherwise, the space is of type [Arbitrary].
|
|
|
|
|
|
|
|
*)
|
|
|
|
|
|
|
|
type arbitrary_space =
|
|
|
|
{
|
|
|
|
det : int array array ;
|
|
|
|
det_alfa : Spindeterminant.t array ;
|
|
|
|
det_beta : Spindeterminant.t array ;
|
|
|
|
index_start : int array;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-02-28 14:25:57 +01:00
|
|
|
type determinant_storage =
|
2019-03-03 01:43:04 +01:00
|
|
|
| Arbitrary of arbitrary_space
|
|
|
|
| Spin of (Spindeterminant.t array * Spindeterminant.t array)
|
|
|
|
|
2019-02-28 14:25:57 +01:00
|
|
|
|
2019-02-20 19:43:16 +01:00
|
|
|
type t =
|
2019-03-03 01:43:04 +01:00
|
|
|
{
|
|
|
|
n_alfa : int ;
|
|
|
|
n_beta : int ;
|
|
|
|
mo_class : MOClass.t ;
|
|
|
|
mo_basis : MOBasis.t ;
|
|
|
|
determinants : determinant_storage;
|
|
|
|
}
|
2019-02-20 19:43:16 +01:00
|
|
|
|
2019-02-28 14:25:57 +01:00
|
|
|
|
2019-03-04 22:56:03 +01:00
|
|
|
module Ss = SpindeterminantSpace
|
2019-02-20 19:43:16 +01:00
|
|
|
|
2019-03-03 01:43:04 +01:00
|
|
|
let n_alfa t = t.n_alfa
|
|
|
|
let n_beta t = t.n_beta
|
2019-02-20 19:43:16 +01:00
|
|
|
let mo_class t = t.mo_class
|
|
|
|
let mo_basis t = t.mo_basis
|
2019-02-28 14:25:57 +01:00
|
|
|
|
|
|
|
|
|
|
|
let size t =
|
|
|
|
match t.determinants with
|
|
|
|
| Spin (a,b) -> (Array.length a) * (Array.length b)
|
2019-03-03 01:43:04 +01:00
|
|
|
| Arbitrary a ->
|
2019-03-04 22:56:03 +01:00
|
|
|
let ndet_a = Array.length a.det_alfa in
|
|
|
|
a.index_start.(ndet_a)
|
2019-02-28 14:25:57 +01:00
|
|
|
|
|
|
|
|
|
|
|
let determinant_stream t =
|
|
|
|
match t.determinants with
|
|
|
|
| Arbitrary a ->
|
2019-03-03 01:43:04 +01:00
|
|
|
let det_beta = a.det_beta
|
|
|
|
and det_alfa = a.det_alfa
|
|
|
|
and det = a.det in
|
|
|
|
let n_alfa = Array.length det_alfa in
|
|
|
|
let alfa = ref det_alfa.(0)
|
|
|
|
and det_i_alfa = ref det.(0) in
|
|
|
|
let i_alfa = ref 0
|
|
|
|
and k_beta = ref 0
|
|
|
|
in
|
|
|
|
Stream.from (fun _ ->
|
|
|
|
if !i_alfa = n_alfa then None else
|
|
|
|
begin
|
|
|
|
let i_beta = (!det_i_alfa).(!k_beta) in
|
|
|
|
let beta = det_beta.(i_beta) in
|
|
|
|
let result =
|
|
|
|
Some (Determinant.of_spindeterminants (!alfa) beta)
|
|
|
|
in
|
|
|
|
incr k_beta;
|
|
|
|
if !k_beta = Array.length !det_i_alfa then
|
|
|
|
begin
|
|
|
|
k_beta := 0;
|
|
|
|
incr i_alfa;
|
|
|
|
if !i_alfa < n_alfa then
|
|
|
|
begin
|
|
|
|
alfa := det_alfa.(!i_alfa);
|
|
|
|
det_i_alfa := det.(!i_alfa)
|
|
|
|
end
|
|
|
|
end;
|
|
|
|
result
|
|
|
|
end
|
|
|
|
)
|
|
|
|
|
2019-02-28 14:25:57 +01:00
|
|
|
| Spin (a,b) ->
|
|
|
|
let na = Array.length a
|
|
|
|
and nb = Array.length b in
|
|
|
|
let i = ref 0
|
|
|
|
and j = ref 0 in
|
|
|
|
Stream.from (fun k ->
|
|
|
|
if !j < nb then
|
|
|
|
let result =
|
|
|
|
Determinant.of_spindeterminants a.(!i) b.(!j)
|
|
|
|
in
|
|
|
|
incr i;
|
|
|
|
if !i = na then (i := 0 ; incr j);
|
|
|
|
Some result
|
|
|
|
else
|
|
|
|
None)
|
|
|
|
|
|
|
|
|
2019-02-28 16:55:50 +01:00
|
|
|
let determinants t = t.determinants
|
|
|
|
|
|
|
|
|
|
|
|
let determinants_array t =
|
2019-03-03 01:43:04 +01:00
|
|
|
let s = determinant_stream t in
|
|
|
|
Array.init (size t) (fun _ -> Stream.next s)
|
2019-02-28 14:25:57 +01:00
|
|
|
|
|
|
|
|
|
|
|
let determinant t i =
|
2019-03-03 01:43:04 +01:00
|
|
|
let alfa, beta =
|
|
|
|
match t.determinants with
|
|
|
|
| Arbitrary a ->
|
|
|
|
let i_alfa =
|
|
|
|
let index_start = a.index_start in
|
|
|
|
let rec loop i_alfa =
|
|
|
|
if index_start.(i_alfa) <= i then
|
|
|
|
loop (i_alfa+1)
|
|
|
|
else i_alfa
|
|
|
|
in loop 0
|
|
|
|
in
|
|
|
|
let i_beta = i - a.index_start.(i_alfa) in
|
|
|
|
let alfa = a.det_alfa.(i_alfa) in
|
|
|
|
let beta = a.det_beta.(i_beta) in
|
|
|
|
alfa, beta
|
|
|
|
|
|
|
|
| Spin (a,b) ->
|
|
|
|
let nb = Array.length b in
|
|
|
|
let k = i / nb in
|
|
|
|
let j = i - k * nb in
|
|
|
|
a.(j), b.(k)
|
|
|
|
|
|
|
|
in
|
|
|
|
Determinant.of_spindeterminants alfa beta
|
2019-02-28 14:25:57 +01:00
|
|
|
|
2019-02-20 19:43:16 +01:00
|
|
|
|
|
|
|
let fci_of_mo_basis ?(frozen_core=true) mo_basis =
|
|
|
|
let s = MOBasis.simulation mo_basis in
|
|
|
|
let e = Simulation.electrons s in
|
|
|
|
let n_alfa = Electrons.n_alfa e
|
|
|
|
and n_beta = Electrons.n_beta e in
|
|
|
|
let det_a =
|
|
|
|
Ss.fci_of_mo_basis ~frozen_core mo_basis n_alfa
|
|
|
|
and det_b =
|
|
|
|
Ss.fci_of_mo_basis ~frozen_core mo_basis n_beta
|
|
|
|
in
|
|
|
|
let mo_class = Ss.mo_class det_a in
|
|
|
|
let determinants =
|
2019-03-03 01:43:04 +01:00
|
|
|
let det_alfa = Ss.spin_determinants det_a
|
|
|
|
and det_beta = Ss.spin_determinants det_b
|
|
|
|
in
|
|
|
|
let n_det_beta = Array.length det_beta in
|
2019-03-04 22:56:03 +01:00
|
|
|
let n_det_alfa = Array.length det_alfa in
|
|
|
|
|
|
|
|
let ndet = n_det_alfa * n_det_beta in
|
|
|
|
Format.printf "Number of determinants : %d %d %d\n%!"
|
|
|
|
n_det_alfa n_det_beta ndet;
|
|
|
|
Spin (det_alfa, det_beta)
|
|
|
|
|
2019-03-05 00:39:23 +01:00
|
|
|
(*
|
2019-03-04 22:56:03 +01:00
|
|
|
let det = Array.make n_det_alfa
|
|
|
|
(Array.init n_det_beta (fun i -> i))
|
|
|
|
in
|
|
|
|
let index_start = Array.init (n_det_alfa+1) (fun i -> i*n_det_beta) in
|
|
|
|
let ndet = (index_start.(n_det_alfa)) in
|
|
|
|
|
|
|
|
Format.printf "Number of determinants : %d %d %d\n%!"
|
|
|
|
n_det_alfa n_det_beta ndet;
|
2019-03-03 01:43:04 +01:00
|
|
|
Arbitrary {
|
2019-03-04 22:56:03 +01:00
|
|
|
det_alfa ; det_beta ; det ; index_start
|
2019-03-03 01:43:04 +01:00
|
|
|
}
|
2019-03-05 00:39:23 +01:00
|
|
|
*)
|
2019-02-20 19:43:16 +01:00
|
|
|
in
|
|
|
|
{ n_alfa ; n_beta ; mo_class ; mo_basis ; determinants }
|
|
|
|
|
|
|
|
|
|
|
|
let pp_det_space ppf t =
|
|
|
|
Format.fprintf ppf "@[<v 2>[ ";
|
2019-02-28 14:25:57 +01:00
|
|
|
let i = ref 0 in
|
|
|
|
determinant_stream t
|
|
|
|
|> Stream.iter (fun d -> Format.fprintf ppf "@[<v>@[%8d@]@;@[%a@]@]@;" !i
|
|
|
|
(Determinant.pp_det (MOBasis.size (mo_basis t))) d; incr i) ;
|
2019-02-20 19:43:16 +01:00
|
|
|
Format.fprintf ppf "]@]"
|
|
|
|
|