10
0
mirror of https://github.com/LCPQ/quantum_package synced 2024-12-23 04:43:50 +01:00

Added Long_basis in ocaml

This commit is contained in:
Anthony Scemama 2014-09-17 14:57:12 +02:00
parent caa59e03c7
commit 61d54ffbfc
5 changed files with 68 additions and 1 deletions

View File

@ -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"
;;

27
ocaml/Long_basis.ml Normal file
View File

@ -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"
;;

View File

@ -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 =

View File

@ -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 =

26
ocaml/test_basis.ml Normal file
View File

@ -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 ();