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

Implemented read MOs from trexio

This commit is contained in:
Anthony Scemama 2024-09-13 18:22:45 +02:00
parent c0754499a3
commit 52db618c2b
4 changed files with 97 additions and 3 deletions

View File

@ -43,7 +43,7 @@ val general_basis : t -> General_basis.t
(** Returns the [!GeneralBasis] that was used to build the current basis. *) (** Returns the [!GeneralBasis] that was used to build the current basis. *)
(** {TREXIO} *) (** {1 TREXIO} *)
val of_trexio : Trexio.trexio_file -> t val of_trexio : Trexio.trexio_file -> t
val to_trexio : Trexio.trexio_file -> t -> unit val to_trexio : Trexio.trexio_file -> t -> unit

View File

@ -25,7 +25,7 @@ val reshape_inplace : int -> int -> ('a,'b) t -> ('c,'d) t
(** Changes the dimensions of the matrix *) (** Changes the dimensions of the matrix *)
val reshape_vec_inplace : int -> int -> ('a*'b) Vector.t -> ('a,'b) t val reshape_vec_inplace : int -> int -> ('a*'b) Vector.t -> ('a,'b) t
(** Reshapres a vector into a matrix *) (** Reshapes a vector into a matrix *)
val init_cols : int -> int -> (int -> int -> float) -> ('a,'b) t val init_cols : int -> int -> (int -> int -> float) -> ('a,'b) t
(** Creates an uninitialized matrix. *) (** Creates an uninitialized matrix. *)

View File

@ -12,6 +12,7 @@ type mo_type =
| RHF | ROHF | UHF | CASSCF | Projected | RHF | ROHF | UHF | CASSCF | Projected
| Natural of string | Natural of string
| Localized of string | Localized of string
| From_trexio
type t = type t =
{ {
@ -162,7 +163,87 @@ let of_mo_basis simulation other =
(** TREXIO *)
let of_trexio ?mo_occupation ~simulation f =
let mo_type = From_trexio in
let mo_num = Trexio.read_mo_num f in
let ao_basis = Si.ao_basis simulation in
let mo_occupation = match mo_occupation with
| Some x -> x
| None ->
try
Trexio.read_mo_occupation f
|> Linear_algebra.Vector.of_array
with
| Failure _ ->
let electrons = Si.electrons simulation in
let n_alfa = Particles.Electrons.n_alfa electrons in
let n_beta = Particles.Electrons.n_beta electrons in
Array.init mo_num (fun i ->
if i < n_beta then 2. else
if i < n_alfa then 1. else
0.)
|> Linear_algebra.Vector.of_array
in
let ao_num =
Trexio.read_ao_num f
in
let mo_coef =
Trexio.read_mo_coefficient f
|> Linear_algebra.Vector.of_array
|> Linear_algebra.Matrix.reshape_vec_inplace ao_num mo_num
in
let eN_ints =
try
let result =
Trexio.read_mo_1e_int_potential_n_e f
|> Linear_algebra.Vector.of_array
|> Linear_algebra.Matrix.reshape_vec_inplace mo_num mo_num
in lazy result
with
| Failure _ -> lazy (
Ao.Basis.eN_ints ao_basis
|> mo_matrix_of_ao_matrix ~mo_coef
)
and kin_ints =
try
let result =
Trexio.read_mo_1e_int_kinetic f
|> Linear_algebra.Vector.of_array
|> Linear_algebra.Matrix.reshape_vec_inplace mo_num mo_num
in lazy result
with
| Failure _ -> lazy (
Ao.Basis.kin_ints ao_basis
|> mo_matrix_of_ao_matrix ~mo_coef
)
and ee_ints =
(* TODO *)
lazy (failwith "Not implemented")
in
let one_e_ints =
try
let result =
Trexio.read_mo_1e_int_core_hamiltonian f
|> Linear_algebra.Vector.of_array
|> Linear_algebra.Matrix.reshape_vec_inplace mo_num mo_num
in lazy result
with
| Failure _ -> lazy (
Matrix.add (Lazy.force eN_ints) (Lazy.force kin_ints)
)
in
{ simulation ; mo_type ; mo_occupation ; mo_coef ;
eN_ints ; ee_ints ; kin_ints ; one_e_ints ;
}
let to_trexio _t =
failwith "Not implemented"
(** Printers *)
let pp_range ?(start=1) ?(finish=0) ppf t = let pp_range ?(start=1) ?(finish=0) ppf t =
let rows = Matrix.dim1 t.mo_coef let rows = Matrix.dim1 t.mo_coef

View File

@ -11,6 +11,7 @@ type mo_type =
| RHF | ROHF | UHF | CASSCF | Projected | RHF | ROHF | UHF | CASSCF | Projected
| Natural of string | Natural of string
| Localized of string | Localized of string
| From_trexio
type t type t
type mo = Mo_dim.t type mo = Mo_dim.t
@ -90,7 +91,19 @@ val ao_matrix_of_mo_matrix :
(mo,mo) Matrix.t -> (ao,ao) Matrix.t (mo,mo) Matrix.t -> (ao,ao) Matrix.t
(** Build a matrix in AO basis from a matrix in MO basis. *) (** Build a matrix in AO basis from a matrix in MO basis. *)
(** {1 Printers} *)
(** {1 TREXIO} *)
val of_trexio :
?mo_occupation:mo Linear_algebra.Vector.t ->
simulation:Simulation.t ->
Trexio.trexio_file ->
t
val to_trexio : Trexio.trexio_file -> t -> unit
(** {2 Printers} *)
val pp_range : ?start:int -> ?finish:int -> Format.formatter -> t -> unit val pp_range : ?start:int -> ?finish:int -> Format.formatter -> t -> unit
val pp : Format.formatter -> t -> unit val pp : Format.formatter -> t -> unit