2014-10-24 00:25:15 +02:00
|
|
|
open Qptypes;;
|
|
|
|
open Qputils;;
|
|
|
|
open Core.Std;;
|
|
|
|
|
|
|
|
module Mo_basis : sig
|
|
|
|
type t =
|
|
|
|
{ mo_tot_num : MO_number.t ;
|
2014-10-29 16:56:16 +01:00
|
|
|
mo_label : MO_label.t;
|
|
|
|
mo_occ : MO_occ.t array;
|
|
|
|
mo_coef : (MO_coef.t array) array;
|
2014-10-25 21:24:21 +02:00
|
|
|
} with sexp
|
2014-10-24 00:25:15 +02:00
|
|
|
;;
|
|
|
|
val read : unit -> t
|
|
|
|
val to_string : t -> string
|
2014-10-29 22:13:03 +01:00
|
|
|
val to_rst : t -> Rst_string.t
|
2014-10-24 00:25:15 +02:00
|
|
|
end = struct
|
|
|
|
type t =
|
|
|
|
{ mo_tot_num : MO_number.t ;
|
2014-10-29 16:56:16 +01:00
|
|
|
mo_label : MO_label.t;
|
|
|
|
mo_occ : MO_occ.t array;
|
|
|
|
mo_coef : (MO_coef.t array) array;
|
2014-10-25 21:24:21 +02:00
|
|
|
} with sexp
|
2014-10-24 00:25:15 +02:00
|
|
|
;;
|
|
|
|
|
|
|
|
let get_default = Qpackage.get_ezfio_default "mo_basis";;
|
|
|
|
|
|
|
|
let read_mo_label () =
|
|
|
|
if not (Ezfio.has_mo_basis_mo_label ()) then
|
2014-10-29 16:56:16 +01:00
|
|
|
Ezfio.set_mo_basis_mo_label "None"
|
2014-10-24 00:25:15 +02:00
|
|
|
;
|
|
|
|
Ezfio.get_mo_basis_mo_label ()
|
2014-10-29 16:56:16 +01:00
|
|
|
|> MO_label.of_string
|
2014-10-24 00:25:15 +02:00
|
|
|
;;
|
|
|
|
|
|
|
|
let read_mo_tot_num () =
|
|
|
|
Ezfio.get_mo_basis_mo_tot_num ()
|
|
|
|
|> MO_number.of_int
|
|
|
|
;;
|
|
|
|
|
|
|
|
let read_mo_occ () =
|
|
|
|
if not (Ezfio.has_mo_basis_mo_label ()) then
|
|
|
|
begin
|
|
|
|
let elec_alpha_num = Ezfio.get_electrons_elec_alpha_num ()
|
|
|
|
and elec_beta_num = Ezfio.get_electrons_elec_beta_num ()
|
|
|
|
and mo_tot_num = MO_number.to_int (read_mo_tot_num ()) in
|
|
|
|
let data = Array.init mo_tot_num ~f:(fun i ->
|
|
|
|
if (i<elec_beta_num) then 2.
|
|
|
|
else if (i < elec_alpha_num) then 1.
|
|
|
|
else 0.) |> Array.to_list in
|
|
|
|
Ezfio.ezfio_array_of_list ~rank:1
|
|
|
|
~dim:[| mo_tot_num |] ~data:data
|
|
|
|
|> Ezfio.set_mo_basis_mo_occ
|
|
|
|
end;
|
2014-11-03 17:37:16 +01:00
|
|
|
Ezfio.flattened_ezfio (Ezfio.get_mo_basis_mo_occ () )
|
2014-10-29 16:56:16 +01:00
|
|
|
|> Array.map ~f:MO_occ.of_float
|
2014-10-24 00:25:15 +02:00
|
|
|
;;
|
|
|
|
|
|
|
|
let read_mo_coef () =
|
2014-11-03 17:37:16 +01:00
|
|
|
let a = Ezfio.get_mo_basis_mo_coef ()
|
|
|
|
|> Ezfio.flattened_ezfio
|
2014-10-24 00:25:15 +02:00
|
|
|
|> Array.map ~f:MO_coef.of_float
|
2014-10-29 16:56:16 +01:00
|
|
|
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
|
|
|
|
)
|
2014-10-24 00:25:15 +02:00
|
|
|
;;
|
|
|
|
|
|
|
|
let read () =
|
|
|
|
{ mo_tot_num = read_mo_tot_num ();
|
|
|
|
mo_label = read_mo_label () ;
|
|
|
|
mo_occ = read_mo_occ ();
|
|
|
|
mo_coef = read_mo_coef ();
|
|
|
|
}
|
|
|
|
;;
|
|
|
|
|
2014-10-29 16:56:16 +01:00
|
|
|
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 =
|
2014-10-29 22:13:03 +01:00
|
|
|
if (i+4 < mo_tot_num) then
|
|
|
|
create_list ( (print_five i (i+3) |> String.concat ~sep:"\n")::accu ) (i+4)
|
2014-10-29 16:56:16 +01:00
|
|
|
else
|
|
|
|
(print_five i (mo_tot_num-1) |> String.concat ~sep:"\n")::accu |> List.rev
|
|
|
|
in
|
|
|
|
create_list [] 0 |> String.concat ~sep:"\n\n"
|
|
|
|
;;
|
|
|
|
|
2014-10-29 22:13:03 +01:00
|
|
|
let to_rst b =
|
2014-10-24 00:25:15 +02:00
|
|
|
Printf.sprintf "
|
2014-10-29 00:12:45 +01:00
|
|
|
Label of the molecular orbitals ::
|
|
|
|
|
|
|
|
mo_label = %s
|
|
|
|
|
|
|
|
Total number of MOs ::
|
|
|
|
|
|
|
|
mo_tot_num = %s
|
|
|
|
|
2014-10-29 16:56:16 +01:00
|
|
|
MO coefficients ::
|
|
|
|
|
|
|
|
%s
|
2014-10-28 17:16:51 +01:00
|
|
|
"
|
2014-10-29 16:56:16 +01:00
|
|
|
(MO_label.to_string b.mo_label)
|
2014-10-28 17:16:51 +01:00
|
|
|
(MO_number.to_string b.mo_tot_num)
|
2014-10-29 16:56:16 +01:00
|
|
|
(mo_coef_to_string b.mo_coef)
|
2014-10-29 22:13:03 +01:00
|
|
|
|> Rst_string.of_string
|
2014-10-28 17:16:51 +01:00
|
|
|
|
|
|
|
;;
|
|
|
|
|
2014-10-29 22:13:03 +01:00
|
|
|
let to_string b =
|
2014-10-28 17:16:51 +01:00
|
|
|
Printf.sprintf "
|
|
|
|
mo_label = %s
|
2014-10-24 00:25:15 +02:00
|
|
|
mo_tot_num = \"%s\"
|
|
|
|
mo_occ = %s
|
|
|
|
mo_coef = %s
|
|
|
|
"
|
2014-10-29 16:56:16 +01:00
|
|
|
(MO_label.to_string b.mo_label)
|
2014-10-24 00:25:15 +02:00
|
|
|
(MO_number.to_string b.mo_tot_num)
|
|
|
|
(b.mo_occ |> Array.to_list |> List.map
|
2014-10-29 16:56:16 +01:00
|
|
|
~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" )
|
2014-10-28 17:16:51 +01:00
|
|
|
;;
|
2014-10-24 00:25:15 +02:00
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|