From ff30a9d50136daa83f9d4da1db3fe11ff49ce5d1 Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Mon, 27 Oct 2014 01:14:18 +0100 Subject: [PATCH] Cleaning --- ocaml/Gto.ml | 7 +++---- ocaml/Makefile | 9 +++++---- ocaml/Point3d.ml | 4 +++- ocaml/Primitive.ml | 3 +++ ocaml/Primitive.mli | 11 +++++++++++ ocaml/Range.mli | 10 ++++++++++ ocaml/Symmetry.ml | 18 +++++------------- ocaml/Symmetry.mli | 36 ++++++++++++++++++++++++++++++++++++ ocaml/Units.mli | 7 +++++++ 9 files changed, 83 insertions(+), 22 deletions(-) create mode 100644 ocaml/Primitive.mli create mode 100644 ocaml/Range.mli create mode 100644 ocaml/Symmetry.mli create mode 100644 ocaml/Units.mli diff --git a/ocaml/Gto.ml b/ocaml/Gto.ml index 370da2ad..b7d5d1cd 100644 --- a/ocaml/Gto.ml +++ b/ocaml/Gto.ml @@ -52,10 +52,9 @@ let read_one in_channel = match buffer with | [ j ; expo ; coef ] -> begin - let p = { Primitive.sym = sym ; - Primitive.expo = AO_expo.of_float - (Float.of_string expo) - } + let p = + Primitive.of_sym_expo sym + (AO_expo.of_float (Float.of_string expo) ) and c = AO_coef.of_float (Float.of_string coef) in read_lines ( (p,c)::result) (i-1) end diff --git a/ocaml/Makefile b/ocaml/Makefile index c477fce6..f2ef83a7 100644 --- a/ocaml/Makefile +++ b/ocaml/Makefile @@ -1,5 +1,3 @@ -#TODO : Opam auto-installer in makefile - # Check if QPACKAGE_ROOT is defined ifndef QPACKAGE_ROOT @@ -12,8 +10,8 @@ endif LIBS= PKGS= -OCAMLCFLAGS=-g -OCAMLBUILD=ocamlbuild -j 0 -syntax camlp4o -cflags $(OCAMLCFLAGS) -lflags -g +OCAMLCFLAGS=-g +OCAMLBUILD=ocamlbuild -j 0 -syntax camlp4o -cflags $(OCAMLCFLAGS) -lflags -g MLFILES=$(wildcard *.ml) ezfio.ml Qptypes.ml MLIFILES=$(wildcard *.mli) ALL_TESTS=$(patsubst %.ml,%.byte,$(wildcard test_*.ml)) @@ -26,6 +24,9 @@ default: $(ALL_TESTS) $(ALL_EXE) executables: $(MAKE) -C $(QPACKAGE_ROOT)/data executables +%.odoc: $(MLFILES) + $(OCAMLBUILD) $*.odoc -use-ocamlfind $(PKGS) + %.inferred.mli: $(MLFILES) $(OCAMLBUILD) $*.inferred.mli -use-ocamlfind $(PKGS) mv _build/$*.inferred.mli . diff --git a/ocaml/Point3d.ml b/ocaml/Point3d.ml index 8dce49b7..39f28fff 100644 --- a/ocaml/Point3d.ml +++ b/ocaml/Point3d.ml @@ -1,4 +1,5 @@ open Core.Std;; +open Qptypes;; type t = { x : float ; @@ -28,9 +29,10 @@ let distance2 p1 p2 = let { x=x1 ; y=y1 ; z=z1 } = p1 and { x=x2 ; y=y2 ; z=z2 } = p2 in (x2-.x1)*.(x2-.x1) +. (y2-.y1)*.(y2-.y1) +. (z2-.z1)*.(z2-.z1) + |> Positive_float.of_float ;; -let distance p1 p2 = sqrt (distance2 p1 p2) +let distance p1 p2 = sqrt (Positive_float.to_float (distance2 p1 p2)) ;; let to_string u p = diff --git a/ocaml/Primitive.ml b/ocaml/Primitive.ml index 3d9a36d5..a6377d6f 100644 --- a/ocaml/Primitive.ml +++ b/ocaml/Primitive.ml @@ -13,3 +13,6 @@ let to_string p = (AO_expo.to_float e) ;; +let of_sym_expo s e = + { sym=s ; expo=e} +;; diff --git a/ocaml/Primitive.mli b/ocaml/Primitive.mli new file mode 100644 index 00000000..77cb633a --- /dev/null +++ b/ocaml/Primitive.mli @@ -0,0 +1,11 @@ +type t = +{ sym : Symmetry.t; + expo : Qptypes.AO_expo.t; +} with sexp + +(** Conversion to string for printing *) +val to_string : t -> string + +(** Creation *) +val of_sym_expo : Symmetry.t -> Qptypes.AO_expo.t -> t + diff --git a/ocaml/Range.mli b/ocaml/Range.mli new file mode 100644 index 00000000..2d56a0fa --- /dev/null +++ b/ocaml/Range.mli @@ -0,0 +1,10 @@ +type t = int list with sexp + +(** A range is a sorted list of ints in an interval. + It is created using a string : + "[a-b]" : range between a and b (included) + "[a]" : the list with only one integer a + "a" : equivalent to "[a]" + *) +val of_string : string -> t +val to_string : t -> string diff --git a/ocaml/Symmetry.ml b/ocaml/Symmetry.ml index 43358116..9e130606 100644 --- a/ocaml/Symmetry.ml +++ b/ocaml/Symmetry.ml @@ -74,16 +74,7 @@ let of_l i = type st = t ;; -module Xyz : sig - type t = { x: Positive_int.t ; - y: Positive_int.t ; - z: Positive_int.t } with sexp - val of_string : string -> t - val to_string : t -> string - val get_l : t -> Positive_int.t - val of_symmetry : st -> t list - val to_symmetry : t -> st -end = struct +module Xyz = struct type t = { x: Positive_int.t ; y: Positive_int.t ; z: Positive_int.t } with sexp @@ -187,9 +178,10 @@ end = struct in create_x [] { x=(to_l sym) ; y=Positive_int.of_int 0 ; z=Positive_int.of_int 0 } - ;; + ;; - let to_symmetry sym = of_l (get_l sym) - ;; + (** Returns the symmetry corresponding to the XYZ triplet *) + let to_symmetry sym = of_l (get_l sym) + ;; end diff --git a/ocaml/Symmetry.mli b/ocaml/Symmetry.mli new file mode 100644 index 00000000..baffeb2e --- /dev/null +++ b/ocaml/Symmetry.mli @@ -0,0 +1,36 @@ +type t = S | P | D | F | G | H | I | J | K | L with sexp + +(** Creatio from strings *) +val to_string : t -> string +val of_string : string -> t +val of_char : char -> t + +(** Connexion with l quantum number *) +val to_l : t -> Qptypes.Positive_int.t +val of_l : Qptypes.Positive_int.t -> t + +type st = t +module Xyz : + sig + type t = { + x : Qptypes.Positive_int.t; + y : Qptypes.Positive_int.t; + z : Qptypes.Positive_int.t; + } with sexp + + (** The string format contains the powers of x,y and z in a + format like "x2z3" *) + + val of_string : string -> t + val to_string : t -> string + + (** Returns the quantum number l *) + val get_l : t -> Qptypes.Positive_int.t + + (** Returns a list of XYZ powers for a given symmetry *) + val of_symmetry : st -> t list + + (** Returns the symmetry corresponding to the XYZ powers *) + val to_symmetry : t -> st + + end diff --git a/ocaml/Units.mli b/ocaml/Units.mli new file mode 100644 index 00000000..eff3fb23 --- /dev/null +++ b/ocaml/Units.mli @@ -0,0 +1,7 @@ +type units = Bohr | Angstrom + +(** Conversion functions *) +val angstrom_to_bohr : float +val bohr_to_angstrom : float + +