10
0
mirror of https://github.com/LCPQ/quantum_package synced 2024-06-22 05:02:15 +02:00

Added possibility to put a basis set in a file

This commit is contained in:
Anthony Scemama 2015-11-24 17:21:38 +01:00
parent 3d7687e3c3
commit e432dc8ea3

View File

@ -91,7 +91,10 @@ let run ?o b c d m p xyz_file =
in in
let basis_table = Hashtbl.Poly.create () in let basis_table =
Hashtbl.Poly.create ()
in
(* Open basis set channels *) (* Open basis set channels *)
let basis_channel element = let basis_channel element =
let key = let key =
@ -115,31 +118,46 @@ let run ?o b c d m p xyz_file =
Sys.remove temp_filename Sys.remove temp_filename
in in
let fetch_channel basis =
let command =
if (p) then
Qpackage.root ^ "/scripts/get_basis.sh \"" ^ temp_filename
^ "." ^ basis ^ "\" \"" ^ basis ^"\" pseudo"
else
Qpackage.root ^ "/scripts/get_basis.sh \"" ^ temp_filename
^ "." ^ basis ^ "\" \"" ^ basis ^"\""
in
match Sys.is_file basis with
| `Yes ->
In_channel.create basis
| _ ->
begin
let filename =
Unix.open_process_in command
|> In_channel.input_all
|> String.strip
in
let new_channel =
In_channel.create filename
in
Unix.unlink filename;
new_channel
end
in
let rec build_basis = function let rec build_basis = function
| [] -> () | [] -> ()
| elem_and_basis_name :: rest -> | elem_and_basis_name :: rest ->
begin begin
match (String.lsplit2 ~on:':' elem_and_basis_name) with match (String.lsplit2 ~on:':' elem_and_basis_name) with
| None -> (* Principal basis *) | None -> (* Principal basis *)
let basis = elem_and_basis_name in
let command =
if (p) then
Qpackage.root ^ "/scripts/get_basis.sh \"" ^ temp_filename
^ "." ^ basis ^ "\" \"" ^ basis ^"\" pseudo"
else
Qpackage.root ^ "/scripts/get_basis.sh \"" ^ temp_filename
^ "." ^ basis ^ "\" \"" ^ basis ^"\""
in
begin begin
let filename = let basis =
Unix.open_process_in command elem_and_basis_name
|> In_channel.input_all
|> String.strip
in in
let new_channel = let new_channel =
In_channel.create filename fetch_channel basis
in in
Unix.unlink filename;
List.iter nuclei ~f:(fun elem-> List.iter nuclei ~f:(fun elem->
let key = let key =
Element.to_string elem.Atom.element Element.to_string elem.Atom.element
@ -151,26 +169,18 @@ let run ?o b c d m p xyz_file =
end end
| Some (key, basis) -> (*Aux basis *) | Some (key, basis) -> (*Aux basis *)
begin begin
let elem = Element.of_string key let elem =
and basis = String.lowercase basis Element.of_string key
and basis =
String.lowercase basis
in in
let key = let key =
Element.to_string elem Element.to_string elem
in in
let command = let new_channel =
Qpackage.root ^ "/scripts/get_basis.sh \"" ^ temp_filename fetch_channel basis
^ "." ^ basis ^ "\" \"" ^ basis ^ "\" "
in in
begin begin
let filename =
Unix.open_process_in command
|> In_channel.input_all
|> String.strip
in
let new_channel =
In_channel.create filename
in
Unix.unlink filename;
match Hashtbl.add basis_table ~key:key ~data:new_channel with match Hashtbl.add basis_table ~key:key ~data:new_channel with
| `Ok -> () | `Ok -> ()
| `Duplicate -> failwith ("Duplicate definition of basis for "^(Element.to_long_string elem)) | `Duplicate -> failwith ("Duplicate definition of basis for "^(Element.to_long_string elem))