10
1
mirror of https://gitlab.com/scemama/QCaml.git synced 2024-12-22 04:13:33 +01:00

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 type t
(** Returns an array of the basis set per atom *)
let of_nuclei_and_general_basis n b = let of_nuclei_and_general_basis n b =
Array.map (fun (e, center) -> Array.map (fun (e, center) ->
List.assoc e b List.assoc e b
@ -14,7 +15,25 @@ let of_nuclei_and_general_basis n b =
let to_string b = let to_string b =
Array.map (fun i -> Contracted_shell.to_string i) b let line ="
|> Array.to_list -----------------------------------------------------------------------
|> String.concat "\n" " 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 to_string s =
let coord =
Coordinate.to_Bohr s.center
in
let open Printf in let open Printf in
[ sprintf "center: %s" (Coordinate.to_string s.center) ; ( sprintf "%2s %10.6f %10.6f %10.6f " (Angular_momentum.to_string s.totAngMom)
sprintf "angular momentum: %s" (Angular_momentum.to_string s.totAngMom) ] (Coordinate.x coord) (Coordinate.y coord) (Coordinate.z coord) ) ^
@ (Array.map2 (fun e c -> sprintf "expo: %e coeff: %e" e c) s.expo s.coef (Array.map2 (fun e c -> sprintf "%16.8e %16.8e" e c) s.expo s.coef
|> Array.to_list) @ ["\n"] |> Array.to_list |> String.concat (sprintf "\n%36s" " ") )
|> String.concat "\n"
(** Normalization coefficient of contracted function i, which depends on the (** Normalization coefficient of contracted function i, which depends on the
exponent and the angular momentum. Two conventions can be chosen : a single 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 |> Zmatrix.to_xyz
|> Array.map (fun (e,x,y,z) -> (e, Coordinate.of_3_floats x y z )) |> 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 word = [^' ' '\t' '\n']+
let letter = ['A'-'Z' 'a'-'z'] let letter = ['A'-'Z' 'a'-'z']
let integer = ['0'-'9']+ let integer = ['0'-'9']+
let real = '-'? integer '.' integer (['e' 'E'] ('+'|'-')? integer)? let real = '-'? (integer '.' integer | integer '.' | '.' integer) (['e' 'E'] ('+'|'-')? integer)?
rule read_all = parse rule read_all = parse
@ -20,11 +20,12 @@ rule read_all = parse
{ {
let debug () = (* DEBUG
let ic = open_in "caffeine.xyz" in let () =
let ic = open_in "h2o.xyz" in
let lexbuf = Lexing.from_channel ic in let lexbuf = Lexing.from_channel ic in
while true do while true do
let s = let s =
match read_all lexbuf with match read_all lexbuf with
| EOL -> "EOL" | EOL -> "EOL"
| SPACE w -> "SPACE("^w^")" | SPACE w -> "SPACE("^w^")"
@ -34,5 +35,6 @@ rule read_all = parse
| EOF -> "EOF" | EOF -> "EOF"
in in
print_endline s print_endline s
done; done;
*)
} }

View File

@ -34,14 +34,14 @@ title:
| title_list EOL { $1 } | title_list EOL { $1 }
text: text:
| WORD {$1 } | WORD { $1 }
| SPACE {$1 } | SPACE { $1 }
| FLOAT {(string_of_float $1)} | FLOAT { (string_of_float $1)}
| INTEGER {(string_of_int $1)} | INTEGER { (string_of_int $1)}
title_list: title_list:
| { "" } | { "" }
| title_list text { $1 ^ $2 } | title_list text { ($1 ^ $2) }
atoms_xyz: atoms_xyz:
| atoms_list EOL { List.rev $1 } | atoms_list EOL { List.rev $1 }

View File

@ -12,5 +12,7 @@ val (|-) : t -> t -> t
val (|+) : t -> t -> t val (|+) : t -> t -> t
val (|.) : float -> t -> t val (|.) : float -> t -> t
val dot : t -> t -> float val dot : t -> t -> float
val to_Angstrom : t -> t
val to_Bohr : t -> t
val norm : t -> float val norm : t -> float

View File

@ -24,11 +24,13 @@ let run ~coord ~basis =
and general_basis = and general_basis =
Gamess_reader.read ~filename:basis_file Gamess_reader.read ~filename:basis_file
in in
print_endline @@ Nuclei.to_string nuclei;
let basis = let basis =
Basis.of_nuclei_and_general_basis nuclei general_basis Basis.of_nuclei_and_general_basis nuclei general_basis
in in
Array.map Basis.to_string basis Basis.to_string basis
|> Array.iter print_endline |> print_endline
let () = let () =