Pretty printing

This commit is contained in:
Anthony Scemama 2018-01-18 17:39:10 +01:00
parent 72eb1ce5c3
commit e3e16bd5bd
7 changed files with 73 additions and 20 deletions

View File

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

View File

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

View File

@ -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" ) ^
"
-----------------------------------------------------------------------
"

View File

@ -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;
*)
}

View File

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

View File

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

View File

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