mirror of
https://github.com/LCPQ/quantum_package
synced 2025-05-06 07:05:25 +02:00
Added bielec_integrals input in ocaml
This commit is contained in:
parent
fea8dfd891
commit
844553e9e2
115
ocaml/Input.ml
115
ocaml/Input.ml
@ -2,119 +2,8 @@ open Qputils;;
|
||||
open Qptypes;;
|
||||
open Core.Std;;
|
||||
|
||||
module Ao_basis : sig
|
||||
type t
|
||||
val read : unit -> t
|
||||
val to_string : t -> string
|
||||
end = struct
|
||||
type t =
|
||||
{ ao_basis : string ;
|
||||
ao_num : AO_number.t ;
|
||||
ao_prim_num : Strictly_positive_int.t array;
|
||||
ao_prim_num_max : Strictly_positive_int.t;
|
||||
ao_nucl : Nucl_number.t array;
|
||||
ao_power : Symmetry.Xyz.t array;
|
||||
ao_coef : float array;
|
||||
ao_expo : Positive_float.t array;
|
||||
}
|
||||
;;
|
||||
|
||||
let read_ao_basis () =
|
||||
if not (Ezfio.has_ao_basis_ao_basis ()) then
|
||||
Ezfio.set_ao_basis_ao_basis ""
|
||||
;
|
||||
Ezfio.get_ao_basis_ao_basis ()
|
||||
;;
|
||||
|
||||
let read_ao_num () =
|
||||
Ezfio.get_ao_basis_ao_num ()
|
||||
|> AO_number.of_int
|
||||
;;
|
||||
|
||||
let read_ao_prim_num () =
|
||||
(Ezfio.get_ao_basis_ao_prim_num () ).Ezfio.data
|
||||
|> Ezfio.flattened_ezfio_data
|
||||
|> Array.map ~f:Strictly_positive_int.of_int
|
||||
;;
|
||||
|
||||
let read_ao_prim_num_max () =
|
||||
(Ezfio.get_ao_basis_ao_prim_num () ).Ezfio.data
|
||||
|> Ezfio.flattened_ezfio_data
|
||||
|> Array.fold ~f:(fun x y -> if x>y then x else y) ~init:0
|
||||
|> Strictly_positive_int.of_int
|
||||
;;
|
||||
|
||||
let read_ao_nucl () =
|
||||
(Ezfio.get_ao_basis_ao_nucl () ).Ezfio.data
|
||||
|> Ezfio.flattened_ezfio_data
|
||||
|> Array.map ~f:Nucl_number.of_int
|
||||
;;
|
||||
|
||||
let read_ao_power () =
|
||||
let x = Ezfio.get_ao_basis_ao_power () in
|
||||
let dim = x.Ezfio.dim.(0) in
|
||||
let data = Ezfio.flattened_ezfio_data x.Ezfio.data in
|
||||
let result = Array.init dim ~f:(fun x -> "") in
|
||||
for i=1 to dim
|
||||
do
|
||||
if (data.(i-1) > 0) then
|
||||
result.(i-1) <- result.(i-1)^"x"^(Int.to_string data.(i-1));
|
||||
if (data.(dim+i-1) > 0) then
|
||||
result.(i-1) <- result.(i-1)^"y"^(Int.to_string data.(dim+i-1));
|
||||
if (data.(2*dim+i-1) > 0) then
|
||||
result.(i-1) <- result.(i-1)^"z"^(Int.to_string data.(2*dim+i-1));
|
||||
done;
|
||||
Array.map ~f:Symmetry.Xyz.of_string result
|
||||
;;
|
||||
|
||||
let read_ao_coef () =
|
||||
(Ezfio.get_ao_basis_ao_coef () ).Ezfio.data
|
||||
|> Ezfio.flattened_ezfio_data
|
||||
;;
|
||||
|
||||
let read_ao_expo () =
|
||||
(Ezfio.get_ao_basis_ao_expo () ).Ezfio.data
|
||||
|> Ezfio.flattened_ezfio_data
|
||||
|> Array.map ~f:Positive_float.of_float
|
||||
;;
|
||||
|
||||
let read () =
|
||||
{ ao_basis = read_ao_basis ();
|
||||
ao_num = read_ao_num () ;
|
||||
ao_prim_num = read_ao_prim_num ();
|
||||
ao_prim_num_max = read_ao_prim_num_max ();
|
||||
ao_nucl = read_ao_nucl ();
|
||||
ao_power = read_ao_power ();
|
||||
ao_coef = read_ao_coef () ;
|
||||
ao_expo = read_ao_expo () ;
|
||||
}
|
||||
;;
|
||||
|
||||
let to_string b =
|
||||
Printf.sprintf "
|
||||
ao_basis = \"%s\"
|
||||
ao_num = %s
|
||||
ao_prim_num = %s
|
||||
ao_prim_num_max = %s
|
||||
ao_nucl = %s
|
||||
ao_power = %s
|
||||
ao_coef = %s
|
||||
ao_expo = %s
|
||||
"
|
||||
b.ao_basis
|
||||
(AO_number.to_string b.ao_num)
|
||||
(b.ao_prim_num |> Array.to_list |> List.map
|
||||
~f:(Strictly_positive_int.to_string) |> String.concat ~sep:", " )
|
||||
(Strictly_positive_int.to_string b.ao_prim_num_max)
|
||||
(b.ao_nucl |> Array.to_list |> List.map ~f:Nucl_number.to_string |>
|
||||
String.concat ~sep:", ")
|
||||
(b.ao_power |> Array.to_list |> List.map ~f:(fun x->
|
||||
"("^(Symmetry.Xyz.to_string x)^")" )|> String.concat ~sep:", ")
|
||||
(b.ao_coef |> Array.to_list |> List.map ~f:Float.to_string
|
||||
|> String.concat ~sep:", ")
|
||||
(b.ao_expo |> Array.to_list |> List.map ~f:Positive_float.to_string
|
||||
|> String.concat ~sep:", ")
|
||||
|
||||
end
|
||||
include Input_ao_basis;;
|
||||
include Input_bi_integrals;;
|
||||
|
||||
|
||||
|
120
ocaml/Input_ao_basis.ml
Normal file
120
ocaml/Input_ao_basis.ml
Normal file
@ -0,0 +1,120 @@
|
||||
open Qptypes;;
|
||||
open Qputils;;
|
||||
open Core.Std;;
|
||||
|
||||
module Ao_basis : sig
|
||||
type t
|
||||
val read : unit -> t
|
||||
val to_string : t -> string
|
||||
end = struct
|
||||
type t =
|
||||
{ ao_basis : string ;
|
||||
ao_num : AO_number.t ;
|
||||
ao_prim_num : Strictly_positive_int.t array;
|
||||
ao_prim_num_max : Strictly_positive_int.t;
|
||||
ao_nucl : Nucl_number.t array;
|
||||
ao_power : Symmetry.Xyz.t array;
|
||||
ao_coef : float array;
|
||||
ao_expo : Positive_float.t array;
|
||||
}
|
||||
;;
|
||||
|
||||
let read_ao_basis () =
|
||||
if not (Ezfio.has_ao_basis_ao_basis ()) then
|
||||
Ezfio.set_ao_basis_ao_basis ""
|
||||
;
|
||||
Ezfio.get_ao_basis_ao_basis ()
|
||||
;;
|
||||
|
||||
let read_ao_num () =
|
||||
Ezfio.get_ao_basis_ao_num ()
|
||||
|> AO_number.of_int
|
||||
;;
|
||||
|
||||
let read_ao_prim_num () =
|
||||
(Ezfio.get_ao_basis_ao_prim_num () ).Ezfio.data
|
||||
|> Ezfio.flattened_ezfio_data
|
||||
|> Array.map ~f:Strictly_positive_int.of_int
|
||||
;;
|
||||
|
||||
let read_ao_prim_num_max () =
|
||||
(Ezfio.get_ao_basis_ao_prim_num () ).Ezfio.data
|
||||
|> Ezfio.flattened_ezfio_data
|
||||
|> Array.fold ~f:(fun x y -> if x>y then x else y) ~init:0
|
||||
|> Strictly_positive_int.of_int
|
||||
;;
|
||||
|
||||
let read_ao_nucl () =
|
||||
(Ezfio.get_ao_basis_ao_nucl () ).Ezfio.data
|
||||
|> Ezfio.flattened_ezfio_data
|
||||
|> Array.map ~f:Nucl_number.of_int
|
||||
;;
|
||||
|
||||
let read_ao_power () =
|
||||
let x = Ezfio.get_ao_basis_ao_power () in
|
||||
let dim = x.Ezfio.dim.(0) in
|
||||
let data = Ezfio.flattened_ezfio_data x.Ezfio.data in
|
||||
let result = Array.init dim ~f:(fun x -> "") in
|
||||
for i=1 to dim
|
||||
do
|
||||
if (data.(i-1) > 0) then
|
||||
result.(i-1) <- result.(i-1)^"x"^(Int.to_string data.(i-1));
|
||||
if (data.(dim+i-1) > 0) then
|
||||
result.(i-1) <- result.(i-1)^"y"^(Int.to_string data.(dim+i-1));
|
||||
if (data.(2*dim+i-1) > 0) then
|
||||
result.(i-1) <- result.(i-1)^"z"^(Int.to_string data.(2*dim+i-1));
|
||||
done;
|
||||
Array.map ~f:Symmetry.Xyz.of_string result
|
||||
;;
|
||||
|
||||
let read_ao_coef () =
|
||||
(Ezfio.get_ao_basis_ao_coef () ).Ezfio.data
|
||||
|> Ezfio.flattened_ezfio_data
|
||||
;;
|
||||
|
||||
let read_ao_expo () =
|
||||
(Ezfio.get_ao_basis_ao_expo () ).Ezfio.data
|
||||
|> Ezfio.flattened_ezfio_data
|
||||
|> Array.map ~f:Positive_float.of_float
|
||||
;;
|
||||
|
||||
let read () =
|
||||
{ ao_basis = read_ao_basis ();
|
||||
ao_num = read_ao_num () ;
|
||||
ao_prim_num = read_ao_prim_num ();
|
||||
ao_prim_num_max = read_ao_prim_num_max ();
|
||||
ao_nucl = read_ao_nucl ();
|
||||
ao_power = read_ao_power ();
|
||||
ao_coef = read_ao_coef () ;
|
||||
ao_expo = read_ao_expo () ;
|
||||
}
|
||||
;;
|
||||
|
||||
let to_string b =
|
||||
Printf.sprintf "
|
||||
ao_basis = \"%s\"
|
||||
ao_num = %s
|
||||
ao_prim_num = %s
|
||||
ao_prim_num_max = %s
|
||||
ao_nucl = %s
|
||||
ao_power = %s
|
||||
ao_coef = %s
|
||||
ao_expo = %s
|
||||
"
|
||||
b.ao_basis
|
||||
(AO_number.to_string b.ao_num)
|
||||
(b.ao_prim_num |> Array.to_list |> List.map
|
||||
~f:(Strictly_positive_int.to_string) |> String.concat ~sep:", " )
|
||||
(Strictly_positive_int.to_string b.ao_prim_num_max)
|
||||
(b.ao_nucl |> Array.to_list |> List.map ~f:Nucl_number.to_string |>
|
||||
String.concat ~sep:", ")
|
||||
(b.ao_power |> Array.to_list |> List.map ~f:(fun x->
|
||||
"("^(Symmetry.Xyz.to_string x)^")" )|> String.concat ~sep:", ")
|
||||
(b.ao_coef |> Array.to_list |> List.map ~f:Float.to_string
|
||||
|> String.concat ~sep:", ")
|
||||
(b.ao_expo |> Array.to_list |> List.map ~f:Positive_float.to_string
|
||||
|> String.concat ~sep:", ")
|
||||
|
||||
end
|
||||
|
||||
|
126
ocaml/Input_bi_integrals.ml
Normal file
126
ocaml/Input_bi_integrals.ml
Normal file
@ -0,0 +1,126 @@
|
||||
open Qptypes;;
|
||||
open Qputils;;
|
||||
open Core.Std;;
|
||||
|
||||
module Bielec_integrals : sig
|
||||
type t
|
||||
val read : unit -> t
|
||||
val to_string : t -> string
|
||||
end = struct
|
||||
type t =
|
||||
{ read_ao_integrals : bool;
|
||||
read_mo_integrals : bool;
|
||||
write_ao_integrals : bool;
|
||||
write_mo_integrals : bool;
|
||||
threshold_ao : Positive_float.t;
|
||||
threshold_mo : Positive_float.t;
|
||||
direct : bool;
|
||||
}
|
||||
;;
|
||||
|
||||
let get_default = Qpackage.get_ezfio_default "bielec_integrals";;
|
||||
|
||||
let read_read_ao_integrals () =
|
||||
if not (Ezfio.has_bielec_integrals_read_ao_integrals ()) then
|
||||
get_default "read_ao_integrals"
|
||||
|> Bool.of_string
|
||||
|> Ezfio.set_bielec_integrals_read_ao_integrals
|
||||
;
|
||||
Ezfio.get_bielec_integrals_read_ao_integrals ()
|
||||
;;
|
||||
|
||||
let read_read_mo_integrals () =
|
||||
if not (Ezfio.has_bielec_integrals_read_mo_integrals ()) then
|
||||
get_default "read_mo_integrals"
|
||||
|> Bool.of_string
|
||||
|> Ezfio.set_bielec_integrals_read_mo_integrals
|
||||
;
|
||||
Ezfio.get_bielec_integrals_read_mo_integrals ()
|
||||
;;
|
||||
|
||||
let read_write_ao_integrals () =
|
||||
if not (Ezfio.has_bielec_integrals_write_ao_integrals ()) then
|
||||
get_default "write_ao_integrals"
|
||||
|> Bool.of_string
|
||||
|> Ezfio.set_bielec_integrals_write_ao_integrals
|
||||
;
|
||||
Ezfio.get_bielec_integrals_write_ao_integrals ()
|
||||
;;
|
||||
|
||||
let read_write_mo_integrals () =
|
||||
if not (Ezfio.has_bielec_integrals_write_mo_integrals ()) then
|
||||
get_default "write_mo_integrals"
|
||||
|> Bool.of_string
|
||||
|> Ezfio.set_bielec_integrals_write_mo_integrals
|
||||
;
|
||||
Ezfio.get_bielec_integrals_write_mo_integrals ()
|
||||
;;
|
||||
|
||||
let read_direct () =
|
||||
if not (Ezfio.has_bielec_integrals_direct ()) then
|
||||
get_default "direct"
|
||||
|> Bool.of_string
|
||||
|> Ezfio.set_bielec_integrals_direct
|
||||
;
|
||||
Ezfio.get_bielec_integrals_direct ()
|
||||
;;
|
||||
|
||||
let read_threshold_ao () =
|
||||
if not (Ezfio.has_bielec_integrals_threshold_ao ()) then
|
||||
get_default "threshold_ao"
|
||||
|> Float.of_string
|
||||
|> Ezfio.set_bielec_integrals_threshold_ao
|
||||
;
|
||||
Ezfio.get_bielec_integrals_threshold_ao ()
|
||||
|> Positive_float.of_float
|
||||
;;
|
||||
|
||||
let read_threshold_mo () =
|
||||
if not (Ezfio.has_bielec_integrals_threshold_mo ()) then
|
||||
get_default "threshold_mo"
|
||||
|> Float.of_string
|
||||
|> Ezfio.set_bielec_integrals_threshold_mo
|
||||
;
|
||||
Ezfio.get_bielec_integrals_threshold_mo ()
|
||||
|> Positive_float.of_float
|
||||
;;
|
||||
|
||||
let read ()=
|
||||
let result =
|
||||
{ read_ao_integrals = read_read_ao_integrals();
|
||||
read_mo_integrals = read_read_mo_integrals () ;
|
||||
write_ao_integrals = read_write_ao_integrals ();
|
||||
write_mo_integrals = read_write_mo_integrals ();
|
||||
threshold_ao = read_threshold_ao ();
|
||||
threshold_mo = read_threshold_mo ();
|
||||
direct = read_direct () ;
|
||||
} in
|
||||
if (result.read_ao_integrals &&
|
||||
result.write_ao_integrals) then
|
||||
failwith "Read and Write AO integrals are both true.";
|
||||
if (result.read_mo_integrals &&
|
||||
result.write_mo_integrals) then
|
||||
failwith "Read and Write MO integrals are both true.";
|
||||
result
|
||||
;;
|
||||
|
||||
let to_string b =
|
||||
Printf.sprintf "
|
||||
read_ao_integrals = %s
|
||||
read_mo_integrals = %s
|
||||
write_ao_integrals = %s
|
||||
write_mo_integrals = %s
|
||||
threshold_ao = %s
|
||||
threshold_mo = %s
|
||||
direct = %s
|
||||
"
|
||||
(Bool.to_string b.read_ao_integrals)
|
||||
(Bool.to_string b.read_mo_integrals)
|
||||
(Bool.to_string b.write_ao_integrals)
|
||||
(Bool.to_string b.write_mo_integrals)
|
||||
(Positive_float.to_string b.threshold_ao)
|
||||
(Positive_float.to_string b.threshold_mo)
|
||||
(Bool.to_string b.direct)
|
||||
end
|
||||
|
||||
|
@ -63,3 +63,34 @@ let executables = lazy (
|
||||
)
|
||||
|
||||
|
||||
let get_ezfio_default directory data =
|
||||
let filename = root / "data/ezfio_defaults" in
|
||||
let lines = In_channel.with_file filename ~f:(fun in_channel ->
|
||||
In_channel.input_lines in_channel) in
|
||||
let rec find_dir = function
|
||||
| line :: rest ->
|
||||
if ((String.strip line) = directory) then
|
||||
rest
|
||||
else
|
||||
find_dir rest
|
||||
| [] -> raise Not_found
|
||||
in
|
||||
let rec find_data = function
|
||||
| line :: rest ->
|
||||
if (line = "") then
|
||||
raise Not_found
|
||||
else if (line.[0] <> ' ') then
|
||||
raise Not_found
|
||||
else
|
||||
begin
|
||||
match (String.lsplit2 ~on:' ' (String.strip line)) with
|
||||
| Some (l,r) ->
|
||||
if (l = data) then (String.lowercase (String.strip r))
|
||||
else find_data rest
|
||||
| None -> raise Not_found
|
||||
end
|
||||
| [] -> raise Not_found
|
||||
in
|
||||
find_dir lines
|
||||
|> find_data ;
|
||||
;;
|
||||
|
@ -1,8 +1,15 @@
|
||||
let test_module () =
|
||||
let test_ao () =
|
||||
Ezfio.set_file "F2.ezfio" ;
|
||||
let b = Input.Ao_basis.read ()
|
||||
in
|
||||
print_endline (Input.Ao_basis.to_string b);
|
||||
;;
|
||||
|
||||
test_module ();;
|
||||
let test_bielec_intergals () =
|
||||
Ezfio.set_file "F2.ezfio" ;
|
||||
let b = Input.Bielec_integrals.read ()
|
||||
in
|
||||
print_endline (Input.Bielec_integrals.to_string b);
|
||||
;;
|
||||
|
||||
test_bielec_intergals ();;
|
||||
|
Loading…
x
Reference in New Issue
Block a user