10
1
mirror of https://gitlab.com/scemama/QCaml.git synced 2024-12-22 20:33:36 +01:00
QCaml/common/lib/coordinate.mli
2024-01-17 10:30:24 +01:00

108 lines
2.0 KiB
OCaml

(** Coordinates
*
* Coordinates in 3D space.
*
* All operations on points are done in atomic units.
* Therefore, all coordinates are given in bohr and
* manipulated with this module.
*)
(** Types *)
type bohr
type angstrom
type xyz = {
x : float ;
y : float ;
z : float ;
}
type 'a point = xyz
type t = bohr point
type axis = X | Y | Z
(** Creation *)
val make : 'a point -> t
(** Creates a point in atomic units *)
val make_angstrom : 'a point -> angstrom point
(** Creates a point in angstrom *)
val zero : bohr point
(** (0., 0., 0.) *)
(** Conversion *)
val bohr_to_angstrom : bohr point -> angstrom point
(** Converts a point in bohr to angstrom *)
val angstrom_to_bohr : angstrom point -> bohr point
(** Converts a point in angstrom to bohr *)
(* Vector operations *)
(** Vector operations *)
val neg : t -> t
(** Negative of a point *)
val get : axis -> bohr point -> float
(** Extracts the projection of the coordinate on an axis *)
val dot : t -> t -> float
(** Dot product *)
val norm : t -> float
(** $\ell{^2}$ norm of the vector *)
val ( |. ) : float -> t -> t
(** Scales the vector by a constant *)
val ( |+ ) : t -> t -> t
(** Adds two vectors *)
val ( |- ) : t -> t -> t
(** Subtracts two vectors *)
(** Example
* Coordinate.neg { x=1. ; y=2. ; z=3. } ;;
* - : Coordinate.t = -1.0000 -2.0000 -3.0000
*
* Coordinate.(get Y { x=1. ; y=2. ; z=3. }) ;;
* - : float = 2.
*
* Coordinate.(
* 2. |. { x=1. ; y=2. ; z=3. }
* ) ;;
* - : Coordinate.t = 2.0000 4.0000 6.0000
*
* Coordinate.(
* { x=1. ; y=2. ; z=3. } |+ { x=2. ; y=3. ; z=1. }
* );;
* - : Coordinate.t = 3.0000 5.0000 4.0000
*
* Coordinate.(
* { x=1. ; y=2. ; z=3. } |- { x=2. ; y=3. ; z=1. }
* );;
* - : Coordinate.t = -1.0000 -1.0000 2.0000
*)
(** Printers *)
(* Coordinates can be printed in bohr or angstrom. *)
val pp : Format.formatter -> t -> unit
val pp_bohr: Format.formatter -> t -> unit
val pp_angstrom : Format.formatter -> t -> unit