mirror of
https://github.com/LCPQ/quantum_package
synced 2024-08-24 21:41:46 +02:00
pretty printing of MOs
This commit is contained in:
parent
b45b950717
commit
23695b4edb
4
Makefile
4
Makefile
@ -53,7 +53,9 @@ bin/m4:
|
||||
QPACKAGE_ROOT=$$PWD ./scripts/install_m4.sh | tee install_m4.log
|
||||
|
||||
|
||||
ocaml: ocaml/Qptypes.ml curl m4
|
||||
ocaml: curl m4
|
||||
rm ocaml/Qptypes.ml
|
||||
$(MAKE) ocaml/Qptypes.ml
|
||||
|
||||
ocaml/Qptypes.ml:
|
||||
$(info $(BLUE)===== Installing ocaml =====$(BLACK))
|
||||
|
@ -5,19 +5,20 @@ open Core.Std;;
|
||||
module Mo_basis : sig
|
||||
type t =
|
||||
{ mo_tot_num : MO_number.t ;
|
||||
mo_label : Non_empty_string.t;
|
||||
mo_occ : Positive_float.t array;
|
||||
mo_coef : MO_coef.t array;
|
||||
mo_label : MO_label.t;
|
||||
mo_occ : MO_occ.t array;
|
||||
mo_coef : (MO_coef.t array) array;
|
||||
} with sexp
|
||||
;;
|
||||
val read : unit -> t
|
||||
val to_string : t -> string
|
||||
val debug : t -> string
|
||||
end = struct
|
||||
type t =
|
||||
{ mo_tot_num : MO_number.t ;
|
||||
mo_label : Non_empty_string.t;
|
||||
mo_occ : Positive_float.t array;
|
||||
mo_coef : MO_coef.t array;
|
||||
mo_label : MO_label.t;
|
||||
mo_occ : MO_occ.t array;
|
||||
mo_coef : (MO_coef.t array) array;
|
||||
} with sexp
|
||||
;;
|
||||
|
||||
@ -25,10 +26,10 @@ end = struct
|
||||
|
||||
let read_mo_label () =
|
||||
if not (Ezfio.has_mo_basis_mo_label ()) then
|
||||
Ezfio.set_mo_basis_mo_label "Unknown"
|
||||
Ezfio.set_mo_basis_mo_label "None"
|
||||
;
|
||||
Ezfio.get_mo_basis_mo_label ()
|
||||
|> Non_empty_string.of_string
|
||||
|> MO_label.of_string
|
||||
;;
|
||||
|
||||
let read_mo_tot_num () =
|
||||
@ -52,13 +53,19 @@ end = struct
|
||||
end;
|
||||
(Ezfio.get_mo_basis_mo_occ () ).Ezfio.data
|
||||
|> Ezfio.flattened_ezfio_data
|
||||
|> Array.map ~f:Positive_float.of_float
|
||||
|> Array.map ~f:MO_occ.of_float
|
||||
;;
|
||||
|
||||
let read_mo_coef () =
|
||||
(Ezfio.get_mo_basis_mo_coef () ).Ezfio.data
|
||||
let a = (Ezfio.get_mo_basis_mo_coef () ).Ezfio.data
|
||||
|> Ezfio.flattened_ezfio_data
|
||||
|> Array.map ~f:MO_coef.of_float
|
||||
in
|
||||
let mo_tot_num = read_mo_tot_num () |> MO_number.to_int in
|
||||
let ao_num = (Array.length a)/mo_tot_num in
|
||||
Array.init mo_tot_num ~f:(fun j ->
|
||||
Array.sub ~pos:(j*ao_num) ~len:(ao_num) a
|
||||
)
|
||||
;;
|
||||
|
||||
let read () =
|
||||
@ -69,6 +76,70 @@ end = struct
|
||||
}
|
||||
;;
|
||||
|
||||
let mo_coef_to_string mo_coef =
|
||||
let ao_num = Array.length mo_coef.(0)
|
||||
and mo_tot_num = Array.length mo_coef in
|
||||
let rec print_five imin imax =
|
||||
match (imax-imin+1) with
|
||||
| 1 ->
|
||||
let header = [ Printf.sprintf " #%15d" (imin+1) ; ] in
|
||||
let new_lines =
|
||||
List.init ao_num ~f:(fun i ->
|
||||
Printf.sprintf " %3d %15.10f " (i+1)
|
||||
(MO_coef.to_float mo_coef.(imin ).(i)) )
|
||||
in header @ new_lines
|
||||
| 2 ->
|
||||
let header = [ Printf.sprintf " #%15d %15d" (imin+1) (imin+2) ; ] in
|
||||
let new_lines =
|
||||
List.init ao_num ~f:(fun i ->
|
||||
Printf.sprintf " %3d %15.10f %15.10f" (i+1)
|
||||
(MO_coef.to_float mo_coef.(imin ).(i))
|
||||
(MO_coef.to_float mo_coef.(imin+1).(i)) )
|
||||
in header @ new_lines
|
||||
| 3 ->
|
||||
let header = [ Printf.sprintf " #%15d %15d %15d"
|
||||
(imin+1) (imin+2) (imin+3); ] in
|
||||
let new_lines =
|
||||
List.init ao_num ~f:(fun i ->
|
||||
Printf.sprintf " %3d %15.10f %15.10f %15.10f" (i+1)
|
||||
(MO_coef.to_float mo_coef.(imin ).(i))
|
||||
(MO_coef.to_float mo_coef.(imin+1).(i))
|
||||
(MO_coef.to_float mo_coef.(imin+2).(i)) )
|
||||
in header @ new_lines
|
||||
| 4 ->
|
||||
let header = [ Printf.sprintf " #%15d %15d %15d %15d"
|
||||
(imin+1) (imin+2) (imin+3) (imin+4) ; ] in
|
||||
let new_lines =
|
||||
List.init ao_num ~f:(fun i ->
|
||||
Printf.sprintf " %3d %15.10f %15.10f %15.10f %15.10f" (i+1)
|
||||
(MO_coef.to_float mo_coef.(imin ).(i))
|
||||
(MO_coef.to_float mo_coef.(imin+1).(i))
|
||||
(MO_coef.to_float mo_coef.(imin+2).(i))
|
||||
(MO_coef.to_float mo_coef.(imin+3).(i)) )
|
||||
in header @ new_lines
|
||||
| 5 ->
|
||||
let header = [ Printf.sprintf " #%15d %15d %15d %15d %15d"
|
||||
(imin+1) (imin+2) (imin+3) (imin+4) (imin+5) ; ] in
|
||||
let new_lines =
|
||||
List.init ao_num ~f:(fun i ->
|
||||
Printf.sprintf " %3d %15.10f %15.10f %15.10f %15.10f %15.10f" (i+1)
|
||||
(MO_coef.to_float mo_coef.(imin ).(i))
|
||||
(MO_coef.to_float mo_coef.(imin+1).(i))
|
||||
(MO_coef.to_float mo_coef.(imin+2).(i))
|
||||
(MO_coef.to_float mo_coef.(imin+3).(i))
|
||||
(MO_coef.to_float mo_coef.(imin+4).(i)) )
|
||||
in header @ new_lines
|
||||
| _ -> assert false
|
||||
in
|
||||
let rec create_list accu i =
|
||||
if (i+5 < mo_tot_num) then
|
||||
create_list ( (print_five i (i+4) |> String.concat ~sep:"\n")::accu ) (i+5)
|
||||
else
|
||||
(print_five i (mo_tot_num-1) |> String.concat ~sep:"\n")::accu |> List.rev
|
||||
in
|
||||
create_list [] 0 |> String.concat ~sep:"\n\n"
|
||||
;;
|
||||
|
||||
let to_string b =
|
||||
Printf.sprintf "
|
||||
Label of the molecular orbitals ::
|
||||
@ -79,9 +150,13 @@ Total number of MOs ::
|
||||
|
||||
mo_tot_num = %s
|
||||
|
||||
MO coefficients ::
|
||||
|
||||
%s
|
||||
"
|
||||
(Non_empty_string.to_string b.mo_label)
|
||||
(MO_label.to_string b.mo_label)
|
||||
(MO_number.to_string b.mo_tot_num)
|
||||
(mo_coef_to_string b.mo_coef)
|
||||
|
||||
;;
|
||||
|
||||
@ -92,12 +167,14 @@ mo_tot_num = \"%s\"
|
||||
mo_occ = %s
|
||||
mo_coef = %s
|
||||
"
|
||||
(Non_empty_string.to_string b.mo_label)
|
||||
(MO_label.to_string b.mo_label)
|
||||
(MO_number.to_string b.mo_tot_num)
|
||||
(b.mo_occ |> Array.to_list |> List.map
|
||||
~f:(Positive_float.to_string) |> String.concat ~sep:", " )
|
||||
(b.mo_coef |> Array.to_list |> List.map
|
||||
~f:(MO_coef.to_string) |> String.concat ~sep:", " )
|
||||
~f:(MO_occ.to_string) |> String.concat ~sep:", " )
|
||||
(b.mo_coef |> Array.map
|
||||
~f:(fun x-> Array.map ~f:MO_coef.to_string x |> String.concat_array
|
||||
~sep:"," ) |>
|
||||
String.concat_array ~sep:"\n" )
|
||||
;;
|
||||
|
||||
end
|
||||
|
29
ocaml/MO_label.ml
Normal file
29
ocaml/MO_label.ml
Normal file
@ -0,0 +1,29 @@
|
||||
open Core.Std;;
|
||||
|
||||
type t =
|
||||
| Guess
|
||||
| Canonical
|
||||
| Natural
|
||||
| Localized
|
||||
| None
|
||||
with sexp
|
||||
;;
|
||||
|
||||
let to_string = function
|
||||
| Guess -> "Guess"
|
||||
| Canonical -> "Canonical"
|
||||
| Natural -> "Natural"
|
||||
| Localized -> "Localized"
|
||||
| None -> "None"
|
||||
;;
|
||||
|
||||
let of_string s =
|
||||
match String.lowercase s with
|
||||
| "guess" -> Guess
|
||||
| "canonical" -> Canonical
|
||||
| "natural" -> Natural
|
||||
| "localized" -> Localized
|
||||
| "none" -> None
|
||||
| _ -> failwith "MO_label should be one of:
|
||||
Guess | Canonical | Natural | Localized | None."
|
||||
;;
|
14
ocaml/MO_label.mli
Normal file
14
ocaml/MO_label.mli
Normal file
@ -0,0 +1,14 @@
|
||||
type t =
|
||||
| Guess
|
||||
| Canonical
|
||||
| Natural
|
||||
| Localized
|
||||
| None
|
||||
with sexp
|
||||
|
||||
(** String representation *)
|
||||
val to_string : t -> string
|
||||
|
||||
(** Build from string representation *)
|
||||
val of_string : string -> t
|
||||
|
@ -102,6 +102,9 @@ let input_data = "
|
||||
|
||||
* MO_coef : float
|
||||
|
||||
* MO_occ : float
|
||||
assert (x >= 0.);
|
||||
|
||||
* AO_coef : float
|
||||
|
||||
* AO_expo : float
|
||||
|
12
ocaml/test_determinants.ml
Normal file
12
ocaml/test_determinants.ml
Normal file
@ -0,0 +1,12 @@
|
||||
open Qptypes;;
|
||||
|
||||
let test_module () =
|
||||
let mo_tot_num = MO_number.of_int 10 in
|
||||
let det =
|
||||
[| 15L ; 7L |]
|
||||
|> Determinant.of_int64_array (N_int_number.of_int 1)
|
||||
in
|
||||
Printf.printf "%s\n" (Determinant.to_string (~mo_tot_num:mo_tot_num) det)
|
||||
;;
|
||||
|
||||
test_module ();;
|
@ -75,7 +75,7 @@ let test_mo () =
|
||||
Ezfio.set_file "F2.ezfio" ;
|
||||
let b = Input.Mo_basis.read ()
|
||||
in
|
||||
print_endline (Input.Mo_basis.to_string b);
|
||||
print_endline (Input.Mo_basis.debug b);
|
||||
;;
|
||||
|
||||
let test_nucl () =
|
||||
@ -96,5 +96,5 @@ test_hf ();;
|
||||
test_mo ();;
|
||||
test_nucl ();
|
||||
*)
|
||||
test_dets();;
|
||||
test_mo();;
|
||||
|
||||
|
5
ocaml/test_mo_label.ml
Normal file
5
ocaml/test_mo_label.ml
Normal file
@ -0,0 +1,5 @@
|
||||
let () =
|
||||
let m = MO_label.of_string "canonical" in
|
||||
let s = MO_label.to_string m in
|
||||
print_string s
|
||||
;;
|
Loading…
Reference in New Issue
Block a user