Documentation

This commit is contained in:
Anthony Scemama 2018-03-03 22:13:14 +01:00
parent ac3f079330
commit f95d9740b6
11 changed files with 92 additions and 15 deletions

View File

@ -1,4 +1,4 @@
(** Chemical elements. *) (** Chemical elements. *)
exception ElementError of string exception ElementError of string
@ -42,11 +42,25 @@ Example:
[Element.(to_long_string Fe) -> "Iron"] [Element.(to_long_string Fe) -> "Iron"]
*) *)
(** Properties *)
val to_int : t -> int val to_int : t -> int
(** Convert to the atomic charge, with [int] type. *)
val of_int : int -> t val of_int : int -> t
(** Create from the atomic charge, with [int] type. *)
val to_charge : t -> Charge.t val to_charge : t -> Charge.t
(** Convert to the atomic charge, with {!Charge.t} type. *)
val of_charge : Charge.t -> t val of_charge : Charge.t -> t
(** Create from the atomic charge, with {!Charge.t} type. *)
val covalent_radius : t -> NonNegativeFloat.t val covalent_radius : t -> NonNegativeFloat.t
(** Covalent radii of the elements, in atomic units. *)
val vdw_radius : t -> NonNegativeFloat.t val vdw_radius : t -> NonNegativeFloat.t
(** Van der Waals radii of the elements, in atomic units. *)
val mass : t -> Mass.t val mass : t -> Mass.t
(** Atomic mass of the elements, in atomic units. *)

View File

@ -1 +1,3 @@
(** Atomic mass. *)
include NonNegativeFloat include NonNegativeFloat

3
Nuclei/Mass.mli Normal file
View File

@ -0,0 +1,3 @@
(** Atomic mass. *)
include module type of NonNegativeFloat

View File

@ -3,7 +3,7 @@ open Xyz_ast
type t = (Element.t * Coordinate.t) array type t = (Element.t * Coordinate.t) array
let of_xyz_file ~filename = let of_xyz_file filename =
let lexbuf = let lexbuf =
let ic = open_in filename in let ic = open_in filename in
Lexing.from_channel ic Lexing.from_channel ic
@ -25,7 +25,7 @@ let of_xyz_file ~filename =
let of_zmt_file ~filename = let of_zmt_file filename =
let ic = open_in filename in let ic = open_in filename in
let rec aux accu = let rec aux accu =
try try
@ -38,7 +38,7 @@ let of_zmt_file ~filename =
in aux [] in aux []
|> Zmatrix.of_string |> Zmatrix.of_string
|> Zmatrix.to_xyz |> Zmatrix.to_xyz
|> Array.map (fun (e,x,y,z) -> (e, (Angstrom.make {Point.x ; y ; z} ))) |> Array.map (fun (e,x,y,z) -> (e, Coordinate.angstrom_to_bohr (Angstrom.make {Point.x ; y ; z} )))
let to_string atoms = let to_string atoms =
@ -67,11 +67,11 @@ let to_string atoms =
" "
let of_filename ~filename = let of_filename filename =
of_xyz_file filename of_xyz_file filename
let repulsion ~nuclei = let repulsion nuclei =
let get_charge e = let get_charge e =
Element.to_charge e Element.to_charge e
|> Charge.to_float |> Charge.to_float
@ -86,3 +86,9 @@ let repulsion ~nuclei =
) 0. nuclei ) 0. nuclei
) 0. nuclei ) 0. nuclei
let charge nuclei =
Array.fold_left (fun accu (e, _) -> accu + Charge.to_int (Element.to_charge e) )
0 nuclei
|> Charge.of_int

26
Nuclei/Nuclei.mli Normal file
View File

@ -0,0 +1,26 @@
(** Data structure for the molecular geometry, represented as an array
of tuples ({!Element.t}, {!Coordinate.t}).
*)
type t = (Element.t * Bohr.t) array
val of_xyz_file : string -> t
(** Create from a file, in [xyz] format. *)
val of_zmt_file : string -> t
(** Create from a file, in z-matrix format. *)
val to_string : t -> string
(** Transform to a string, for printing. *)
val of_filename : string -> t
(** Detects the type of file ([xyz], z-matrix) and reads the file. *)
val repulsion : t -> float
(** Nuclear repulsion energy, in atomic units. *)
val charge : t -> Charge.t
(** Sum of the charges of the nuclei. *)

View File

@ -1,13 +1,16 @@
(** When an [xyz] file is read by the [Xyz_parser.mly], it is converted into
an {!xyz_file} data structure. *)
type nucleus = type nucleus =
{ {
element: Element.t ; element: Element.t ;
coord: Angstrom.t; coord : Angstrom.t;
} }
type xyz_file = type xyz_file =
{ {
number_of_atoms : int; number_of_atoms : int ;
file_title : string; file_title : string ;
nuclei : nucleus list; nuclei : nucleus list ;
} }

View File

@ -21,9 +21,7 @@ let make ?multiplicity:(multiplicity=1) ?charge:(charge=0) ~nuclei basis =
Electrons.make ~multiplicity ~charge nuclei Electrons.make ~multiplicity ~charge nuclei
in in
let charge = let charge =
Array.fold_left (fun accu (e, _) -> accu + Charge.to_int (Element.to_charge e) ) Charge.(Nuclei.charge nuclei + Electrons.charge electrons)
0 nuclei - Electrons.(electrons.n_alpha + electrons.n_beta)
|> Charge.of_int
in in
let overlap = let overlap =
lazy (Overlap.of_basis basis) lazy (Overlap.of_basis basis)
@ -41,7 +39,7 @@ let make ?multiplicity:(multiplicity=1) ?charge:(charge=0) ~nuclei basis =
let of_filenames ?multiplicity:(multiplicity=1) ?charge:(charge=0) ~nuclei basis = let of_filenames ?multiplicity:(multiplicity=1) ?charge:(charge=0) ~nuclei basis =
let nuclei = let nuclei =
Nuclei.of_filename ~filename:nuclei Nuclei.of_filename nuclei
in in
let basis = let basis =
Basis.of_nuclei_and_basis_filename ~nuclei ~filename:basis Basis.of_nuclei_and_basis_filename ~nuclei ~filename:basis

View File

@ -12,3 +12,14 @@ let to_string x =
else else
Printf.sprintf "%f" x Printf.sprintf "%f" x
let ( + ) a b =
(to_float a) +. (to_float b) |> of_float
let ( - ) a b =
(to_float a) -. (to_float b) |> of_float
let ( * ) a b =
(to_float a) *. b |> of_float
let ( / ) a b =
(to_float a) /. b |> of_float

View File

@ -10,3 +10,9 @@ val of_int : int -> t
val to_string: t -> string val to_string: t -> string
val of_string: string -> t val of_string: string -> t
val ( + ) : t -> t -> t
val ( - ) : t -> t -> t
val ( * ) : t -> float -> t
val ( / ) : t -> float -> t

View File

@ -21,3 +21,7 @@ let make ?multiplicity:(multiplicity=1) ?charge:(charge=0) nuclei =
invalid_arg (__FILE__^": make"); invalid_arg (__FILE__^": make");
result result
let charge e =
- (e.n_alpha + e.n_beta)
|> Charge.of_int

View File

@ -15,3 +15,7 @@ val make : ?multiplicity:int -> ?charge:int -> Nuclei.t -> t
@raise Invalid_argument if the spin multiplicity is not compatible with @raise Invalid_argument if the spin multiplicity is not compatible with
the molecule and the total charge. the molecule and the total charge.
*) *)
val charge : t -> Charge.t
(** Sum of the charges of the electrons. *)