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

Added MatrixOnBasis

This commit is contained in:
Anthony Scemama 2018-06-13 19:03:42 +02:00
parent 9e5933f0d0
commit c1a53f40e8
13 changed files with 61 additions and 27 deletions

View File

@ -12,6 +12,7 @@ module Ps = PrimitiveShell
module Psp = PrimitiveShellPair module Psp = PrimitiveShellPair
type t = Mat.t type t = Mat.t
external matrix : t -> Mat.t = "%identity"
let cutoff = integrals_cutoff let cutoff = integrals_cutoff

View File

@ -1,4 +1,4 @@
(** Electronic kinetic energy integrals, expressed as a matrix in a {Basis.t}. (** Electronic kinetic energy integrals, expressed as a matrix in a {!Basis.t}.
{% {%
$$ $$
@ -7,11 +7,6 @@ $$
%} %}
*) *)
type t = Lacaml.D.Mat.t include module type of MatrixOnBasis
val of_basis : Basis.t -> t
(** Build from a {Basis.t}. *)
val to_file : filename:string -> t -> unit
(** Write the integrals in a file. *)

14
Basis/MatrixOnBasis.mli Normal file
View File

@ -0,0 +1,14 @@
(** Signature for matrices built on the {!Basis.t} *)
open Lacaml.D
type t
val of_basis : Basis.t -> t
(** Build from a {!Basis.t}. *)
val to_file : filename:string -> t -> unit
(** Write the integrals in a file. *)
val matrix : t -> Mat.t
(** Returns the matrix suitable for Lacaml *)

View File

@ -5,6 +5,7 @@ open Constants
open Lacaml.D open Lacaml.D
type t = Mat.t type t = Mat.t
external matrix : t -> Mat.t = "%identity"
module Am = AngularMomentum module Am = AngularMomentum
module Bs = Basis module Bs = Basis
@ -108,3 +109,7 @@ let to_file ~filename eni_array =
done; done;
close_out oc close_out oc
let of_basis basis =
invalid_arg "of_basis_nuclei should be called for NucInt"

View File

@ -1,4 +1,4 @@
(** Electron-Nucleus attractive potential integrals, expressed as a matrix in a {Basis.t}. (** Electron-Nucleus attractive potential integrals, expressed as a matrix in a {!Basis.t}.
{% $$ {% $$
V_{ij} = \left \langle \chi_i \left| \sum_A \frac{-Z_A}{ | \mathbf{r} - \mathbf{R}_A |} \right| \chi_j \right \rangle V_{ij} = \left \langle \chi_i \left| \sum_A \frac{-Z_A}{ | \mathbf{r} - \mathbf{R}_A |} \right| \chi_j \right \rangle
@ -6,10 +6,9 @@ $$ %}
*) *)
type t = Lacaml.D.Mat.t include module type of MatrixOnBasis
val of_basis_nuclei : basis:Basis.t -> Nuclei.t -> t val of_basis_nuclei : basis:Basis.t -> Nuclei.t -> t
(** Build from a {Basis.t} and the nuclei (coordinates and charges). *) (** Build from a {Basis.t} and the nuclei (coordinates and charges). *)
val to_file : filename:string -> t -> unit
(** Write the integrals in a file. *)

View File

@ -6,11 +6,14 @@ type t = Mat.t
module Am = AngularMomentum module Am = AngularMomentum
module Bs = Basis module Bs = Basis
module Cs = ContractedShell module Cs = ContractedShell
module Ov = Overlap
let make_canonical ~thresh ~basis ~cartesian ~overlap = let make_canonical ~thresh ~basis ~cartesian ~overlap =
let overlap_matrix = Ov.matrix overlap in
let make_canonical_spherical basis = let make_canonical_spherical basis =
let ao_num = Bs.size basis in let ao_num = Bs.size basis in
let cart_sphe = Mat.make ao_num ao_num 0. let cart_sphe = Mat.make ao_num ao_num 0.
@ -24,14 +27,14 @@ let make_canonical ~thresh ~basis ~cartesian ~overlap =
i := !i + Mat.dim1 submatrix; i := !i + Mat.dim1 submatrix;
n := !n + Mat.dim2 submatrix; n := !n + Mat.dim2 submatrix;
) (Bs.contracted_shells basis); ) (Bs.contracted_shells basis);
let s = gemm ~transa:`T ~m:!n cart_sphe overlap in let s = gemm ~transa:`T ~m:!n cart_sphe overlap_matrix in
let overlap = gemm s ~n:!n cart_sphe in let overlap_matrix = gemm s ~n:!n cart_sphe in
let s = canonical_ortho ~thresh ~overlap (Mat.identity !n) in let s = canonical_ortho ~thresh ~overlap:overlap_matrix (Mat.identity !n) in
gemm cart_sphe ~k:!n s gemm cart_sphe ~k:!n s
in in
if cartesian then if cartesian then
canonical_ortho ~thresh ~overlap (Mat.identity @@ Mat.dim1 overlap) canonical_ortho ~thresh ~overlap:overlap_matrix (Mat.identity @@ Mat.dim1 overlap_matrix)
else else
match basis with match basis with
| None -> invalid_arg | None -> invalid_arg
@ -42,7 +45,8 @@ let make_canonical ~thresh ~basis ~cartesian ~overlap =
let make_lowdin ~thresh ~overlap = let make_lowdin ~thresh ~overlap =
let u_vec, u_val = diagonalize_symm overlap in let overlap_matrix = Ov.matrix overlap in
let u_vec, u_val = diagonalize_symm overlap_matrix in
Vec.iter (fun x -> if x < thresh then Vec.iter (fun x -> if x < thresh then
invalid_arg (__FILE__^": make_lowdin") ) u_val; invalid_arg (__FILE__^": make_lowdin") ) u_val;
@ -61,3 +65,4 @@ let make ?(thresh=1.e-12) ?basis ~cartesian overlap =
make_lowdin ~thresh ~overlap make_lowdin ~thresh ~overlap
*) *)
make_canonical ~thresh ~basis ~cartesian ~overlap make_canonical ~thresh ~basis ~cartesian ~overlap

View File

@ -1,6 +1,8 @@
(** Orthonormalization of the basis. *) (** Orthonormalization of the basis. *)
type t = Lacaml.D.Mat.t open Lacaml.D
type t = Mat.t
val make: ?thresh:float -> ?basis:Basis.t -> cartesian:bool -> Overlap.t -> t val make: ?thresh:float -> ?basis:Basis.t -> cartesian:bool -> Overlap.t -> t
(** Returns a matrix or orthonormal vectors in the basis. The vectors are (** Returns a matrix or orthonormal vectors in the basis. The vectors are

View File

@ -3,6 +3,8 @@ open Constants
open Lacaml.D open Lacaml.D
type t = Mat.t type t = Mat.t
external matrix : t -> Mat.t = "%identity"
module Am = AngularMomentum module Am = AngularMomentum
module Bs = Basis module Bs = Basis
@ -12,6 +14,7 @@ module Csp = ContractedShellPair
module Po = Powers module Po = Powers
module Psp = PrimitiveShellPair module Psp = PrimitiveShellPair
let cutoff = integrals_cutoff let cutoff = integrals_cutoff
let to_powers x = let to_powers x =

6
Basis/Overlap.mli Normal file
View File

@ -0,0 +1,6 @@
(** Overlap matrix of the atomic orbitals.
{% $$ \langle \chi_i | \chi_j \rangle $$ %}
*)
include module type of MatrixOnBasis

View File

@ -15,9 +15,9 @@ module Ao = AOBasis
let make ~density ao_basis = let make ~density ao_basis =
let m_P = density let m_P = density
and m_T = Lazy.force ao_basis.Ao.kin_ints and m_T = Lazy.force ao_basis.Ao.kin_ints |> KinInt.matrix
and m_V = Lazy.force ao_basis.Ao.eN_ints and m_V = Lazy.force ao_basis.Ao.eN_ints |> NucInt.matrix
and m_G = Lazy.force ao_basis.Ao.ee_ints and m_G = Lazy.force ao_basis.Ao.ee_ints
in in
let nBas = Mat.dim1 m_T let nBas = Mat.dim1 m_T
in in

View File

@ -9,10 +9,11 @@ type t = guess
module Ao = AOBasis module Ao = AOBasis
module El = Electrons module El = Electrons
module Ov = Overlap
let hcore_guess ao_basis = let hcore_guess ao_basis =
let eN_ints = Lazy.force ao_basis.Ao.eN_ints let eN_ints = Lazy.force ao_basis.Ao.eN_ints |> NucInt.matrix
and kin_ints = Lazy.force ao_basis.Ao.kin_ints and kin_ints = Lazy.force ao_basis.Ao.kin_ints |> KinInt.matrix
in in
Mat.add eN_ints kin_ints Mat.add eN_ints kin_ints
@ -20,9 +21,9 @@ let hcore_guess ao_basis =
let huckel_guess ao_basis = let huckel_guess ao_basis =
let c = 0.5 *. 1.75 in let c = 0.5 *. 1.75 in
let ao_num = Basis.size ao_basis.Ao.basis in let ao_num = Basis.size ao_basis.Ao.basis in
let eN_ints = Lazy.force ao_basis.Ao.eN_ints let eN_ints = Lazy.force ao_basis.Ao.eN_ints |> NucInt.matrix
and kin_ints = Lazy.force ao_basis.Ao.kin_ints and kin_ints = Lazy.force ao_basis.Ao.kin_ints |> KinInt.matrix
and overlap = Lazy.force ao_basis.Ao.overlap and overlap = Lazy.force ao_basis.Ao.overlap |> Ov.matrix
and m_X = Lazy.force ao_basis.Ao.ortho and m_X = Lazy.force ao_basis.Ao.ortho
in in
let diag = Array.init (ao_num+1) (fun i -> if i=0 then 0. else let diag = Array.init (ao_num+1) (fun i -> if i=0 then 0. else

View File

@ -4,6 +4,7 @@ open Lacaml.D
module Si = Simulation module Si = Simulation
module El = Electrons module El = Electrons
module Ao = AOBasis module Ao = AOBasis
module Ov = Overlap
let make ?guess:(guess=`Huckel) ?max_scf:(max_scf=64) ?level_shift:(level_shift=0.1) let make ?guess:(guess=`Huckel) ?max_scf:(max_scf=64) ?level_shift:(level_shift=0.1)
?threshold_SCF:(threshold_SCF=1.e-5) simulation = ?threshold_SCF:(threshold_SCF=1.e-5) simulation =
@ -35,10 +36,11 @@ let make ?guess:(guess=`Huckel) ?max_scf:(max_scf=64) ?level_shift:(level_shift=
(* Overlap matrix *) (* Overlap matrix *)
let m_S = let m_S =
Lazy.force ao_basis.Ao.overlap Lazy.force ao_basis.Ao.overlap
|> Ov.matrix
in in
let m_T = Lazy.force ao_basis.Ao.kin_ints let m_T = Lazy.force ao_basis.Ao.kin_ints |> KinInt.matrix
and m_V = Lazy.force ao_basis.Ao.eN_ints and m_V = Lazy.force ao_basis.Ao.eN_ints |> NucInt.matrix
in in
(* Level shift in MO basis *) (* Level shift in MO basis *)

View File

@ -1,6 +1,7 @@
(** Floats >= 0. *) (** Floats >= 0. *)
type t = private float type t = private float
val of_float : float -> t val of_float : float -> t
val unsafe_of_float : float -> t
val to_float : t -> float val to_float : t -> float
val to_string : t -> string val to_string : t -> string
val of_string : string -> t val of_string : string -> t