10
1
mirror of https://gitlab.com/scemama/QCaml.git synced 2024-11-09 07:33:40 +01:00
QCaml/Utils/Coordinate.ml

93 lines
1.6 KiB
OCaml
Raw Normal View History

2018-02-13 17:36:25 +01:00
type bohr = Bohr.t
type angstrom = Angstrom.t
2018-02-02 01:25:10 +01:00
2018-02-13 17:36:25 +01:00
type t = bohr
2018-01-17 18:19:38 +01:00
2018-02-13 17:36:25 +01:00
type axis = X | Y | Z
2018-01-17 18:19:38 +01:00
2018-02-14 18:08:43 +01:00
2018-02-13 17:36:25 +01:00
let a_to_b a = Constants.a0_inv *. a
let b_to_a b = Constants.a0 *. b
2018-01-17 18:19:38 +01:00
2018-02-13 17:36:25 +01:00
let bohr_to_angstrom { Bohr.x ; y ; z } =
Angstrom.make
{
Point.
x = b_to_a x ;
y = b_to_a y ;
z = b_to_a z ;
}
2018-01-17 18:19:38 +01:00
2018-02-13 17:36:25 +01:00
let angstrom_to_bohr { Angstrom.x ; y ; z } =
Bohr.make
{
Point.
x = a_to_b x ;
y = a_to_b y ;
z = a_to_b z ;
}
2018-01-17 18:19:38 +01:00
2018-02-13 17:36:25 +01:00
let zero =
Bohr.make { Point.x = 0. ; y = 0. ; z = 0. }
2018-01-17 18:19:38 +01:00
2018-01-18 14:56:08 +01:00
(** Linear algebra *)
2018-02-13 17:36:25 +01:00
let ( |. ) s { Bohr.x ; y ; z } =
Bohr.make {
Point.
x = s *. x ;
y = s *. y ;
z = s *. z ;
}
let ( |+ ) { Bohr.x = x1 ; y = y1 ; z = z1 } { Bohr.x = x2 ; y = y2 ; z = z2 } =
Bohr.make {
Point.
x = x1 +. x2 ;
y = y1 +. y2 ;
z = z1 +. z2 ;
}
let ( |- ) { Bohr.x = x1 ; y = y1 ; z = z1 } { Bohr.x = x2 ; y = y2 ; z = z2 } =
Bohr.make {
Point.
x = x1 -. x2 ;
y = y1 -. y2 ;
z = z1 -. z2 ;
}
2018-01-18 14:56:08 +01:00
2018-02-09 10:49:27 +01:00
let neg a = -1. |. a
2018-01-17 18:19:38 +01:00
2018-02-13 17:36:25 +01:00
let dot { Bohr.x = x1 ; y = y1 ; z = z1 } { Bohr.x = x2 ; y = y2 ; z = z2 } =
x1 *. x2 +. y1 *. y2 +. z1 *. z2
2018-01-17 18:19:38 +01:00
2018-02-13 17:36:25 +01:00
let norm u =
sqrt ( dot u u )
2018-01-19 17:42:12 +01:00
2018-02-13 17:36:25 +01:00
let get axis { Bohr.x ; y ; z } =
match axis with
| X -> x
| Y -> y
| Z -> z
2018-03-15 15:25:49 +01:00
2018-03-16 00:23:47 +01:00
open Format
let pp ppf c =
let open Bohr in
fprintf ppf "@[@[%8.4f@] @[%8.4f@] @[%8.4f@]@]" c.x c.y c.z
2018-03-15 15:25:49 +01:00
let pp_bohr ppf c =
let open Bohr in
2018-03-16 00:23:47 +01:00
fprintf ppf "@[(@[%10f@], @[%10f@], @[%10f@] Bohr)@]" c.x c.y c.z
2018-03-15 15:25:49 +01:00
let pp_angstrom ppf c =
let c = bohr_to_angstrom c in
let open Angstrom in
2018-03-16 00:23:47 +01:00
fprintf ppf "@[(@[%10f@], @[%10f@], @[%10f@] Angs)@]" c.x c.y c.z