From 61d54ffbfc6d8fc498e66c4a3c7485e052aa26df Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Wed, 17 Sep 2014 14:57:12 +0200 Subject: [PATCH] Added Long_basis in ocaml --- ocaml/Basis.ml | 5 +++++ ocaml/Long_basis.ml | 27 +++++++++++++++++++++++++++ ocaml/{symmetry.ml => Symmetry.ml} | 10 +++++++++- ocaml/qp_create_ezfio_from_xyz.ml | 1 + ocaml/test_basis.ml | 26 ++++++++++++++++++++++++++ 5 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 ocaml/Long_basis.ml rename ocaml/{symmetry.ml => Symmetry.ml} (92%) create mode 100644 ocaml/test_basis.ml diff --git a/ocaml/Basis.ml b/ocaml/Basis.ml index cfce7a52..7fb4736d 100644 --- a/ocaml/Basis.ml +++ b/ocaml/Basis.ml @@ -15,6 +15,7 @@ let read in_channel = (** Find an element in the basis set file *) let find in_channel element = + In_channel.seek in_channel 0L; let element_read = ref Element.X in while !element_read <> element do @@ -32,3 +33,7 @@ let read_element in_channel element = read in_channel ; ;; +let to_string b = + List.map ~f:Gto.to_string b + |> String.concat ~sep:"\n" +;; diff --git a/ocaml/Long_basis.ml b/ocaml/Long_basis.ml new file mode 100644 index 00000000..b602a630 --- /dev/null +++ b/ocaml/Long_basis.ml @@ -0,0 +1,27 @@ +open Core.Std;; + +type t = (Symmetry.Xyz.t * Gto.t) list;; + +let of_basis b = + let rec do_work accu = function + | [] -> accu + | g::tail -> + begin + let new_accu = + Symmetry.Xyz.of_symmetry g.Gto.sym + |> List.map ~f:(fun x-> (x,g)) + in + do_work (new_accu@accu) tail + end + in + do_work [] b + |> List.rev +;; + + +let to_string b = + List.map ~f:(fun (x,y) -> + (Symmetry.Xyz.to_string x)^" "^(Gto.to_string y) + ) b + |> String.concat ~sep:"\n" +;; diff --git a/ocaml/symmetry.ml b/ocaml/Symmetry.ml similarity index 92% rename from ocaml/symmetry.ml rename to ocaml/Symmetry.ml index bf9b09b2..aac3ed18 100644 --- a/ocaml/symmetry.ml +++ b/ocaml/Symmetry.ml @@ -54,19 +54,24 @@ let to_l = function | K -> Positive_int.of_int 8 | L -> Positive_int.of_int 9 +type st = t +;; + module Xyz : sig type t val of_string : string -> t val to_string : t -> string val get_l : t -> Positive_int.t + val of_symmetry : st -> t list end = struct type t = { x: Positive_int.t ; y: Positive_int.t ; z: Positive_int.t } type state_type = Null | X | Y | Z - (* Input string is like "x2z3" *) + (** Builds an XYZ triplet from a string. + * The input string is like "x2z3" *) let of_string s = let flush state accu number = let n = @@ -106,6 +111,7 @@ end = struct z=Positive_int.of_int 0 } "" ;; + (** Transforms an XYZ triplet to a string *) let to_string t = let x = match (Positive_int.to_int t.x) with | 0 -> "" @@ -123,6 +129,7 @@ end = struct x^y^z ;; + (** Returns the l quantum number from a XYZ powers triplet *) let get_l t = let x = Positive_int.to_int t.x and y = Positive_int.to_int t.y @@ -130,6 +137,7 @@ end = struct in Positive_int.of_int (x+y+z) ;; + (** Returns a list of XYZ powers for a given symmetry *) let of_symmetry sym = let l = Positive_int.to_int (to_l sym) in let create_z xyz = diff --git a/ocaml/qp_create_ezfio_from_xyz.ml b/ocaml/qp_create_ezfio_from_xyz.ml index 4a8bca24..8a40155b 100644 --- a/ocaml/qp_create_ezfio_from_xyz.ml +++ b/ocaml/qp_create_ezfio_from_xyz.ml @@ -81,6 +81,7 @@ File : %s\n" c m b xyz_file; ~rank:2 ~dim:[| nucl_num ; 3 |] ~data:coords); (* Write Basis set *) + ;; let command = diff --git a/ocaml/test_basis.ml b/ocaml/test_basis.ml new file mode 100644 index 00000000..278821f4 --- /dev/null +++ b/ocaml/test_basis.ml @@ -0,0 +1,26 @@ +open Core.Std;; +open Qputils;; + +let test_module () = + + let basis_channel = + let b = "cc-pvdz" in + In_channel.create (Qpackage.root / "data/basis" / (String.lowercase b)) + in + + let molecule = + let xyz_file = "F2.xyz" in + Molecule.of_xyz_file xyz_file + in + + let basis = + (Basis.read_element basis_channel Element.F) @ + (Basis.read_element basis_channel Element.F) + in + + Long_basis.of_basis basis + |> Long_basis.to_string + |> print_endline +;; + +test_module ();