2017-08-18 18:28:33 +02:00
|
|
|
open Core
|
2014-08-23 17:07:47 +02:00
|
|
|
|
|
|
|
exception AtomError of string
|
|
|
|
|
|
|
|
type t =
|
|
|
|
{ element : Element.t ;
|
|
|
|
charge : Charge.t ;
|
|
|
|
coord : Point3d.t ;
|
2017-08-18 18:28:33 +02:00
|
|
|
} [@@deriving sexp]
|
2014-08-23 17:07:47 +02:00
|
|
|
|
2015-11-17 22:25:26 +01:00
|
|
|
(** Read xyz coordinates of the atom *)
|
|
|
|
let of_string ~units s =
|
2014-08-23 17:07:47 +02:00
|
|
|
let buffer = s
|
|
|
|
|> String.split ~on:' '
|
|
|
|
|> List.filter ~f:(fun x -> x <> "")
|
|
|
|
in
|
|
|
|
match buffer with
|
|
|
|
| [ name; charge; x; y; z ] ->
|
|
|
|
{ element = Element.of_string name ;
|
|
|
|
charge = Charge.of_string charge ;
|
2015-11-17 22:25:26 +01:00
|
|
|
coord = Point3d.of_string ~units (String.concat [x; y; z] ~sep:" ")
|
2014-08-23 17:07:47 +02:00
|
|
|
}
|
2014-08-24 20:00:26 +02:00
|
|
|
| [ name; x; y; z ] ->
|
|
|
|
let e = Element.of_string name in
|
|
|
|
{ element = e ;
|
2014-10-26 17:29:11 +01:00
|
|
|
charge = Element.to_charge e;
|
2015-11-17 22:25:26 +01:00
|
|
|
coord = Point3d.of_string ~units (String.concat [x; y; z] ~sep:" ")
|
2014-08-24 20:00:26 +02:00
|
|
|
}
|
2014-08-23 17:07:47 +02:00
|
|
|
| _ -> raise (AtomError s)
|
2016-03-22 13:28:03 +01:00
|
|
|
|
2014-08-23 17:07:47 +02:00
|
|
|
|
2015-11-17 22:25:26 +01:00
|
|
|
let to_string ~units a =
|
2014-08-23 17:07:47 +02:00
|
|
|
[ Element.to_string a.element ;
|
|
|
|
Charge.to_string a.charge ;
|
2015-11-17 22:25:26 +01:00
|
|
|
Point3d.to_string ~units a.coord ]
|
2014-10-29 22:13:03 +01:00
|
|
|
|> String.concat ~sep:" "
|
2016-03-22 13:28:03 +01:00
|
|
|
|
|
|
|
|
|
|
|
let to_xyz a =
|
|
|
|
Printf.sprintf "%-3s %s"
|
|
|
|
(Element.to_string a.element)
|
|
|
|
(Point3d.to_string ~units:Units.Angstrom a.coord)
|
|
|
|
|
2014-08-23 17:07:47 +02:00
|
|
|
|