10
0
mirror of https://github.com/LCPQ/quantum_package synced 2024-11-13 09:34:02 +01: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-09-18 17:01:43 +02:00
(** Read xyz coordinates of the atom with unit u *)
let of_string u 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 ;
2014-09-18 17:01:43 +02:00
coord = Point3d.of_string u (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-07 19:33:11 +02:00
charge = Charge.of_int (Element.to_charge e);
2014-09-18 17:01:43 +02:00
coord = Point3d.of_string u (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)
;;
2014-10-07 19:33:11 +02:00
let to_string u a =
2014-08-23 17:07:47 +02:00
[ Element.to_string a.element ;
Charge.to_string a.charge ;
2014-10-07 19:33:11 +02:00
Point3d.to_string u a.coord ]
2014-08-24 20:00:26 +02:00
|> String.concat ?sep:(Some " ")
2014-08-23 17:07:47 +02:00
;;