10
0
mirror of https://github.com/LCPQ/quantum_package synced 2024-06-19 19:52:15 +02:00
quantum_package/ocaml/Atom.ml

39 lines
914 B
OCaml
Raw Normal View History

2014-08-23 17:07:47 +02:00
open Core.Std;;
exception AtomError of string
type t =
{ element : Element.t ;
charge : Charge.t ;
coord : Point3d.t ;
2014-10-25 21:24:21 +02:00
} with sexp
2014-08-23 17:07:47 +02: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 ;
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 ;
charge = Element.to_charge e;
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)
;;
let to_string ~units a =
2014-08-23 17:07:47 +02:00
[ Element.to_string a.element ;
Charge.to_string a.charge ;
Point3d.to_string ~units a.coord ]
2014-10-29 22:13:03 +01:00
|> String.concat ~sep:" "
2014-08-23 17:07:47 +02:00
;;