4
1
mirror of https://github.com/pfloos/quack synced 2024-06-22 21:22:20 +02:00
quack/qcaml-tools/quack_input.ml

109 lines
3.0 KiB
OCaml
Raw Normal View History

2020-10-11 21:54:30 +02:00
let quack_dir =
try Sys.getenv "QUACK_DIR" with
Not_found -> "."
let quack_basis_filename = quack_dir ^ "/input/basis"
let quack_molecule_filename = quack_dir ^ "/input/molecule"
2020-10-08 11:52:49 +02:00
let basis_file : string option ref = ref None
let nuclei_file : string option ref = ref None
let charge : int option ref = ref None
let multiplicity : int option ref = ref None
let speclist = [
( "-b" , Arg.String (fun x -> basis_file := Some x),
"File containing the atomic basis set") ;
( "-c" , Arg.Int (fun x -> charge := Some x),
"Total charge of the system") ;
( "-m" , Arg.Int (fun x -> multiplicity := Some x),
"Multiplicity of the system") ;
( "-x" , Arg.String (fun x -> nuclei_file := Some x),
"File containing the nuclear coordinates") ;
]
2020-10-10 11:30:40 +02:00
let print_basis nuclei basis =
2020-10-11 21:54:30 +02:00
let oc = open_out quack_basis_filename in
let ocf = Format.formatter_of_out_channel oc in
2020-10-10 11:30:40 +02:00
let g_basis = Qcaml.Gaussian.Basis.general_basis basis in
let dict =
Array.to_list nuclei
|> List.mapi (fun i (e, _) ->
(i+1), List.assoc e g_basis
)
in
List.iter (fun (i,b) ->
2020-10-11 21:54:30 +02:00
Format.fprintf ocf "%d %d\n" i (Array.length b);
2020-10-10 11:30:40 +02:00
Array.iter (fun x ->
2020-10-11 21:54:30 +02:00
Format.fprintf ocf "%a" Qcaml.Gaussian.General_basis.pp_gcs x) b
) dict;
close_out oc
2020-10-10 11:30:40 +02:00
2020-10-11 21:54:30 +02:00
let print_molecule nuclei electrons =
let oc = open_out quack_molecule_filename in
let nat = Array.length nuclei in
let nela = Qcaml.Particles.Electrons.n_alfa electrons in
let nelb = Qcaml.Particles.Electrons.n_beta electrons in
let ncore = Qcaml.Particles.Nuclei.small_core nuclei in
let nryd = 0 in
Printf.fprintf oc "# nAt nEla nElb nCore nRyd\n";
Printf.fprintf oc " %4d %4d %4d %5d %4d\n" nat nela nelb ncore nryd;
Printf.fprintf oc "# Znuc x y z\n";
let open Qcaml.Common.Coordinate in
Array.iter (fun (element, coord) ->
Printf.fprintf oc "%3s %16.10f %16.10f %16.10f\n"
(Qcaml.Particles.Element.to_string element)
coord.x coord.y coord.z
) nuclei;
close_out oc
2020-10-10 11:30:40 +02:00
2020-10-08 11:52:49 +02:00
let run () =
let basis_file =
match !basis_file with
| None -> raise (Invalid_argument "Basis set file should be specified with -b")
| Some x -> x
and nuclei_file =
match !nuclei_file with
| None -> raise (Invalid_argument "Coordinate file should be specified with -x")
| Some x -> x
2020-10-11 21:54:30 +02:00
and charge =
match !charge with
| None -> 0
| Some c -> c
and multiplicity =
match !multiplicity with
| None -> 1
| Some m -> m
2020-10-08 11:52:49 +02:00
in
let nuclei =
2020-10-10 11:30:40 +02:00
Qcaml.Particles.Nuclei.of_xyz_file nuclei_file
2020-10-08 11:52:49 +02:00
in
2020-10-11 21:54:30 +02:00
let electrons =
Qcaml.Particles.Electrons.of_atoms ~multiplicity ~charge nuclei
in
2020-10-08 11:52:49 +02:00
let basis =
2020-10-10 11:30:40 +02:00
Qcaml.Gaussian.Basis.of_nuclei_and_basis_filename ~nuclei basis_file
2020-10-08 11:52:49 +02:00
in
(* Print basis *)
2020-10-11 21:54:30 +02:00
print_molecule nuclei electrons;
2020-10-10 11:30:40 +02:00
print_basis nuclei basis;
2020-10-08 11:52:49 +02:00
()
let () =
let usage_msg = "Available options:" in
Arg.parse speclist (fun _ -> ()) usage_msg;
run ()