mirror of
https://github.com/LCPQ/quantum_package
synced 2025-01-09 20:48:47 +01:00
Using streams in determinants
This commit is contained in:
parent
e4043cda0d
commit
32208d35f9
@ -340,7 +340,7 @@ psi_det = %s
|
|||||||
let idx = String.substr_index_exn r ~pos:0 ~pattern:"\nDeterminants"
|
let idx = String.substr_index_exn r ~pos:0 ~pattern:"\nDeterminants"
|
||||||
in
|
in
|
||||||
let (header, dets) =
|
let (header, dets) =
|
||||||
(String.prefix r idx, String.suffix r ((String.length r)-idx) )
|
(String.prefix r idx, String.suffix r ((String.length r)-idx-1) )
|
||||||
in
|
in
|
||||||
|
|
||||||
(* Handle header *)
|
(* Handle header *)
|
||||||
@ -360,95 +360,120 @@ psi_det = %s
|
|||||||
|> String.concat
|
|> String.concat
|
||||||
in
|
in
|
||||||
|
|
||||||
(* Handle determinant coefs *)
|
(* Handle determinants and coefs *)
|
||||||
let dets = match ( dets
|
let dets_stream =
|
||||||
|> String.split ~on:'\n'
|
|
||||||
|> List.map ~f:(String.strip)
|
|
||||||
) with
|
|
||||||
| _::lines -> lines
|
|
||||||
| _ -> failwith "Error in determinants"
|
|
||||||
in
|
|
||||||
|
|
||||||
let psi_coef =
|
let ipos, jmax =
|
||||||
let rec read_coefs accu = function
|
ref (-1), String.length dets
|
||||||
| [] -> List.rev accu
|
|
||||||
| "" :: "" :: tail -> read_coefs accu tail
|
|
||||||
| "" :: c :: tail ->
|
|
||||||
let c =
|
|
||||||
String.split ~on:'\t' c
|
|
||||||
|> List.map ~f:(fun x -> Det_coef.of_float (Float.of_string x))
|
|
||||||
|> Array.of_list
|
|
||||||
in
|
|
||||||
read_coefs (c :: accu) tail
|
|
||||||
| _ :: tail -> read_coefs accu tail
|
|
||||||
in
|
in
|
||||||
let a =
|
let next_line =
|
||||||
let buffer =
|
Stream.from (fun _ ->
|
||||||
read_coefs [] dets
|
let rec loop line =
|
||||||
in
|
let j =
|
||||||
let nstates =
|
!ipos + 1
|
||||||
List.hd_exn buffer
|
|
||||||
|> Array.length
|
|
||||||
in
|
|
||||||
let extract_state i =
|
|
||||||
let i =
|
|
||||||
i-1
|
|
||||||
in
|
|
||||||
List.map ~f:(fun x -> x.(i)) buffer
|
|
||||||
in
|
|
||||||
let rec build_result accu = function
|
|
||||||
| 0 -> accu
|
|
||||||
| i ->
|
|
||||||
let new_accu =
|
|
||||||
(extract_state i) :: accu
|
|
||||||
in
|
in
|
||||||
build_result new_accu (i-1)
|
ipos := j;
|
||||||
in
|
if (j < jmax) then
|
||||||
build_result [] nstates
|
match dets.[j] with
|
||||||
|
| '\n' -> Some (String.of_char_list @@ List.rev line )
|
||||||
|
| ' ' -> loop line
|
||||||
|
| c -> loop (c :: line)
|
||||||
|
else
|
||||||
|
None
|
||||||
|
in loop []
|
||||||
|
)
|
||||||
in
|
in
|
||||||
List.concat a
|
ignore @@ Stream.next next_line; (* Determinants :: *)
|
||||||
|> Array.of_list
|
ignore @@ Stream.next next_line; (* *)
|
||||||
|
Stream.from (fun _ ->
|
||||||
|
try
|
||||||
|
begin
|
||||||
|
let result =
|
||||||
|
let coefs =
|
||||||
|
let line =
|
||||||
|
Stream.next next_line
|
||||||
|
in
|
||||||
|
String.split ~on:'\t' line
|
||||||
|
|> Array.of_list
|
||||||
|
|> Array.map ~f:(fun x -> Det_coef.of_float @@ Float.of_string x)
|
||||||
|
in
|
||||||
|
Some (coefs,
|
||||||
|
Stream.next next_line |> String.rev,
|
||||||
|
Stream.next next_line |> String.rev )
|
||||||
|
in
|
||||||
|
ignore @@ Stream.next next_line;
|
||||||
|
result
|
||||||
|
end
|
||||||
|
with
|
||||||
|
| Stream.Failure -> None
|
||||||
|
)
|
||||||
in
|
in
|
||||||
|
|
||||||
(*
|
|
||||||
let dets = match ( dets
|
|
||||||
|> String.split ~on:'\n'
|
|
||||||
|> List.map ~f:(String.strip)
|
|
||||||
) with
|
|
||||||
| _::lines -> lines
|
|
||||||
| _ -> failwith "Error in determinants"
|
|
||||||
in
|
|
||||||
*)
|
|
||||||
|
|
||||||
(* Handle determinants *)
|
|
||||||
let psi_det =
|
let psi_coef, psi_det =
|
||||||
let alpha = Ezfio.get_electrons_elec_alpha_num ()
|
|
||||||
|
let alpha =
|
||||||
|
Ezfio.get_electrons_elec_alpha_num ()
|
||||||
|> Elec_alpha_number.of_int
|
|> Elec_alpha_number.of_int
|
||||||
and beta = Ezfio.get_electrons_elec_beta_num ()
|
and beta =
|
||||||
|
Ezfio.get_electrons_elec_beta_num ()
|
||||||
|> Elec_beta_number.of_int
|
|> Elec_beta_number.of_int
|
||||||
and n_int =
|
and n_int =
|
||||||
N_int_number.get_max ()
|
N_int_number.get_max ()
|
||||||
|> N_int_number.of_int
|
|> N_int_number.of_int
|
||||||
in
|
in
|
||||||
let rec read_dets accu = function
|
|
||||||
| [] -> List.rev accu
|
let rec read coefs dets_bit = function
|
||||||
| ""::_::alpha_str::beta_str::tail ->
|
| None -> (List.rev coefs), (List.rev dets_bit)
|
||||||
begin
|
| Some (c, alpha_str, beta_str) ->
|
||||||
let newdet =
|
begin
|
||||||
(Bitlist.of_string_mp alpha_str, Bitlist.of_string_mp beta_str)
|
ignore @@ Stream.next dets_stream;
|
||||||
|> Determinant.of_bitlist_couple ~n_int ~alpha ~beta
|
let new_coefs =
|
||||||
|
c :: coefs
|
||||||
|
and new_dets =
|
||||||
|
let newdet =
|
||||||
|
(Bitlist.of_string_mp alpha_str, Bitlist.of_string_mp beta_str)
|
||||||
|
|> Determinant.of_bitlist_couple ~n_int ~alpha ~beta
|
||||||
|
in
|
||||||
|
newdet :: dets_bit
|
||||||
|
in
|
||||||
|
read new_coefs new_dets (Stream.peek dets_stream)
|
||||||
|
end
|
||||||
|
in
|
||||||
|
|
||||||
|
let coefs, dets_bit =
|
||||||
|
read [] [] (Stream.peek dets_stream)
|
||||||
|
in
|
||||||
|
let nstates =
|
||||||
|
List.hd_exn coefs |> Array.length
|
||||||
|
in
|
||||||
|
let a =
|
||||||
|
let extract_state i =
|
||||||
|
let i =
|
||||||
|
i-1
|
||||||
in
|
in
|
||||||
read_dets (newdet::accu) tail
|
List.map ~f:(fun x -> x.(i)) coefs
|
||||||
end
|
in
|
||||||
| _::tail -> read_dets accu tail
|
let rec build_result accu = function
|
||||||
|
| 0 -> accu
|
||||||
|
| i ->
|
||||||
|
let new_accu =
|
||||||
|
(extract_state i) :: accu
|
||||||
|
in
|
||||||
|
build_result new_accu (i-1)
|
||||||
|
in
|
||||||
|
build_result [] nstates
|
||||||
in
|
in
|
||||||
let dets =
|
let new_coefs =
|
||||||
List.map ~f:String.rev dets
|
List.concat a |> Array.of_list
|
||||||
|
and new_dets =
|
||||||
|
Array.of_list dets_bit
|
||||||
in
|
in
|
||||||
read_dets [] dets
|
new_coefs, new_dets
|
||||||
|> Array.of_list
|
|
||||||
in
|
in
|
||||||
|
|
||||||
|
|
||||||
let bitkind =
|
let bitkind =
|
||||||
Printf.sprintf "(bit_kind %d)" (Lazy.force Qpackage.bit_kind
|
Printf.sprintf "(bit_kind %d)" (Lazy.force Qpackage.bit_kind
|
||||||
|> Bit_kind.to_int)
|
|> Bit_kind.to_int)
|
||||||
|
Loading…
Reference in New Issue
Block a user