From e3e16bd5bdf27365b9e58ad9bcf7082448b0ec69 Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Thu, 18 Jan 2018 17:39:10 +0100 Subject: [PATCH] Pretty printing --- Basis/Basis.ml | 25 ++++++++++++++++++++++--- Basis/Contracted_shell.ml | 12 +++++++----- Nuclei/Nuclei.ml | 26 ++++++++++++++++++++++++++ Nuclei/Nuclei_lexer.mll | 12 +++++++----- Nuclei/Xyz_parser.mly | 10 +++++----- Utils/Coordinate.mli | 2 ++ run_integrals.ml | 6 ++++-- 7 files changed, 73 insertions(+), 20 deletions(-) diff --git a/Basis/Basis.ml b/Basis/Basis.ml index e7e8eaf..bc3730c 100644 --- a/Basis/Basis.ml +++ b/Basis/Basis.ml @@ -1,5 +1,6 @@ type t +(** Returns an array of the basis set per atom *) let of_nuclei_and_general_basis n b = Array.map (fun (e, center) -> List.assoc e b @@ -14,7 +15,25 @@ let of_nuclei_and_general_basis n b = let to_string b = - Array.map (fun i -> Contracted_shell.to_string i) b - |> Array.to_list - |> String.concat "\n" + let line =" +----------------------------------------------------------------------- +" in + " + Atomic Basis set + ---------------- + +----------------------------------------------------------------------- +Angular Coordinates (Bohr) Exponents Coefficients +Momentum X Y Z +----------------------------------------------------------------------- +" + ^( Array.mapi (fun atom_id basis -> + Array.map (fun i -> + Contracted_shell.to_string i) basis + |> Array.to_list + |> String.concat line + ) b + |> Array.to_list + |> String.concat line) + ^ line diff --git a/Basis/Contracted_shell.ml b/Basis/Contracted_shell.ml index 2c4e195..02d8558 100644 --- a/Basis/Contracted_shell.ml +++ b/Basis/Contracted_shell.ml @@ -18,12 +18,14 @@ let norm_coef a i = a.norm_coef.(i) let to_string s = + let coord = + Coordinate.to_Bohr s.center + in let open Printf in - [ sprintf "center: %s" (Coordinate.to_string s.center) ; - sprintf "angular momentum: %s" (Angular_momentum.to_string s.totAngMom) ] - @ (Array.map2 (fun e c -> sprintf "expo: %e coeff: %e" e c) s.expo s.coef - |> Array.to_list) @ ["\n"] - |> String.concat "\n" + ( sprintf "%2s %10.6f %10.6f %10.6f " (Angular_momentum.to_string s.totAngMom) + (Coordinate.x coord) (Coordinate.y coord) (Coordinate.z coord) ) ^ + (Array.map2 (fun e c -> sprintf "%16.8e %16.8e" e c) s.expo s.coef + |> Array.to_list |> String.concat (sprintf "\n%36s" " ") ) (** Normalization coefficient of contracted function i, which depends on the exponent and the angular momentum. Two conventions can be chosen : a single diff --git a/Nuclei/Nuclei.ml b/Nuclei/Nuclei.ml index f0834c1..a683900 100644 --- a/Nuclei/Nuclei.ml +++ b/Nuclei/Nuclei.ml @@ -23,3 +23,29 @@ let of_zmt_file ~filename = |> Zmatrix.to_xyz |> Array.map (fun (e,x,y,z) -> (e, Coordinate.of_3_floats x y z )) +let to_string atoms = + " + Nuclear Coordinates (Angstrom) + ------------------------------ + +----------------------------------------------------------------------- + Center Atomic Element Coordinates (Angstroms) + Number X Y Z +----------------------------------------------------------------------- +" ^ + (Array.mapi (fun i (e, coord) -> + let coord = + Coordinate.to_Angstrom coord + in + Printf.sprintf " %5d %5d %5s %12.6f %12.6f %12.6f" + (i+1) (Element.to_int e) (Element.to_string e) + (Coordinate.x coord) (Coordinate.y coord) (Coordinate.z coord) + ) atoms + |> Array.to_list + |> String.concat "\n" ) ^ +" +----------------------------------------------------------------------- + +" + + diff --git a/Nuclei/Nuclei_lexer.mll b/Nuclei/Nuclei_lexer.mll index 33b68bb..f02d4f5 100644 --- a/Nuclei/Nuclei_lexer.mll +++ b/Nuclei/Nuclei_lexer.mll @@ -7,7 +7,7 @@ let white = [' ' '\t']+ let word = [^' ' '\t' '\n']+ let letter = ['A'-'Z' 'a'-'z'] let integer = ['0'-'9']+ -let real = '-'? integer '.' integer (['e' 'E'] ('+'|'-')? integer)? +let real = '-'? (integer '.' integer | integer '.' | '.' integer) (['e' 'E'] ('+'|'-')? integer)? rule read_all = parse @@ -20,11 +20,12 @@ rule read_all = parse { - let debug () = - let ic = open_in "caffeine.xyz" in +(* DEBUG + let () = + let ic = open_in "h2o.xyz" in let lexbuf = Lexing.from_channel ic in while true do - let s = + let s = match read_all lexbuf with | EOL -> "EOL" | SPACE w -> "SPACE("^w^")" @@ -34,5 +35,6 @@ rule read_all = parse | EOF -> "EOF" in print_endline s - done; + done; +*) } diff --git a/Nuclei/Xyz_parser.mly b/Nuclei/Xyz_parser.mly index 4d5c4c7..8451bc0 100644 --- a/Nuclei/Xyz_parser.mly +++ b/Nuclei/Xyz_parser.mly @@ -34,14 +34,14 @@ title: | title_list EOL { $1 } text: - | WORD {$1 } - | SPACE {$1 } - | FLOAT {(string_of_float $1)} - | INTEGER {(string_of_int $1)} + | WORD { $1 } + | SPACE { $1 } + | FLOAT { (string_of_float $1)} + | INTEGER { (string_of_int $1)} title_list: | { "" } - | title_list text { $1 ^ $2 } + | title_list text { ($1 ^ $2) } atoms_xyz: | atoms_list EOL { List.rev $1 } diff --git a/Utils/Coordinate.mli b/Utils/Coordinate.mli index 91a5985..6fbae0f 100644 --- a/Utils/Coordinate.mli +++ b/Utils/Coordinate.mli @@ -12,5 +12,7 @@ val (|-) : t -> t -> t val (|+) : t -> t -> t val (|.) : float -> t -> t val dot : t -> t -> float +val to_Angstrom : t -> t +val to_Bohr : t -> t val norm : t -> float diff --git a/run_integrals.ml b/run_integrals.ml index d0ee6e2..50f9d8d 100644 --- a/run_integrals.ml +++ b/run_integrals.ml @@ -24,11 +24,13 @@ let run ~coord ~basis = and general_basis = Gamess_reader.read ~filename:basis_file in + print_endline @@ Nuclei.to_string nuclei; + let basis = Basis.of_nuclei_and_general_basis nuclei general_basis in - Array.map Basis.to_string basis - |> Array.iter print_endline + Basis.to_string basis + |> print_endline let () =