mirror of
https://github.com/LCPQ/quantum_package
synced 2025-01-10 21:18:29 +01:00
Merge pull request #52 from scemama/master
Accept cause Sooner is beter. Will fix the test bug on monday.
This commit is contained in:
commit
4d44c1b46d
5
.gitattributes
vendored
Normal file
5
.gitattributes
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
*.irp.f linguist-language=IRPF90
|
||||
*.f linguist-language=Fortran
|
||||
*.ml linguist-language=Ocaml
|
||||
*.sh linguist-language=Bash
|
||||
*.py linguist-language=Python
|
2
.gitignore
vendored
2
.gitignore
vendored
@ -7,3 +7,5 @@ bin/
|
||||
quantum_package_static.tar.gz
|
||||
resultsFile
|
||||
opam_installer.sh
|
||||
*.mod
|
||||
*.p
|
@ -1,5 +1,9 @@
|
||||
sudo: true
|
||||
|
||||
language: python
|
||||
python:
|
||||
- "2.6"
|
||||
|
||||
before_script:
|
||||
- sudo apt-get update
|
||||
- sudo apt-get install gfortran liblapack-dev
|
||||
@ -9,4 +13,4 @@ script:
|
||||
- source ./quantum_package.rc
|
||||
- cp ./src/Makefile.config.gfortran ./src/Makefile.config
|
||||
- make build
|
||||
|
||||
- ./tests/unit_test/unit_test.py
|
||||
|
@ -6,8 +6,9 @@
|
||||
* m4
|
||||
* GNU make
|
||||
* Fortran compiler (ifort or gfortran are tested)
|
||||
* Python >= 2.7
|
||||
* Python >= 2.6
|
||||
* Bash
|
||||
* Patch (for opam)
|
||||
|
||||
|
||||
## Standard installation
|
||||
|
2
Makefile
2
Makefile
@ -44,6 +44,6 @@ ocaml:
|
||||
$(MAKE) ocaml/Qptypes.ml
|
||||
|
||||
veryclean:
|
||||
rm -f EZFIO
|
||||
rm -rf EZFIO
|
||||
$(MAKE) EZFIO
|
||||
$(MAKE) -C src veryclean
|
||||
|
1
data/ezfio_defaults/.gitignore
vendored
Normal file
1
data/ezfio_defaults/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
*ezfio_interface_default
|
@ -43,11 +43,6 @@ all_singles
|
||||
pt2_max 1.e-8
|
||||
do_pt2_end False
|
||||
|
||||
cassd
|
||||
n_det_max_cassd 10000
|
||||
pt2_max 1.e-4
|
||||
do_pt2_end True
|
||||
|
||||
hartree_fock
|
||||
n_it_scf_max 200
|
||||
thresh_scf 1.e-10
|
4
data/ezfio_defaults/cisd.ezfio_default
Normal file
4
data/ezfio_defaults/cisd.ezfio_default
Normal file
@ -0,0 +1,4 @@
|
||||
cisd_selected
|
||||
n_det_max_cisd 10000
|
||||
pt2_max 1.e-4
|
||||
|
9
data/ezfio_defaults/determinants.ezfio_default
Normal file
9
data/ezfio_defaults/determinants.ezfio_default
Normal file
@ -0,0 +1,9 @@
|
||||
determinants
|
||||
n_states 1
|
||||
n_states_diag determinants_n_states
|
||||
n_det_max_jacobi 1000
|
||||
threshold_generators 0.99
|
||||
threshold_selectors 0.999
|
||||
read_wf false
|
||||
s2_eig false
|
||||
only_single_double_dm false
|
2
data/ezfio_defaults/properties.ezfio_default
Normal file
2
data/ezfio_defaults/properties.ezfio_default
Normal file
@ -0,0 +1,2 @@
|
||||
properties
|
||||
z_one_point 3.9
|
@ -2,16 +2,10 @@ open Qputils;;
|
||||
open Qptypes;;
|
||||
open Core.Std;;
|
||||
|
||||
|
||||
include Input_ao_basis;;
|
||||
include Input_bi_integrals;;
|
||||
include Input_bitmasks;;
|
||||
include Input_cisd_sc2;;
|
||||
include Input_determinants;;
|
||||
include Input_electrons;;
|
||||
include Input_full_ci;;
|
||||
include Input_hartree_fock;;
|
||||
include Input_mo_basis;;
|
||||
include Input_nuclei;;
|
||||
|
||||
|
||||
include Input_auto_generated;;
|
@ -1,127 +0,0 @@
|
||||
open Qptypes;;
|
||||
open Qputils;;
|
||||
open Core.Std;;
|
||||
|
||||
module Cisd_sc2 : sig
|
||||
type t =
|
||||
{ n_det_max_cisd_sc2 : Det_number_max.t;
|
||||
pt2_max : PT2_energy.t;
|
||||
do_pt2_end : bool;
|
||||
} with sexp
|
||||
;;
|
||||
val read : unit -> t option
|
||||
val write : t -> unit
|
||||
val to_string : t -> string
|
||||
val to_rst : t -> Rst_string.t
|
||||
val of_rst : Rst_string.t -> t option
|
||||
end = struct
|
||||
type t =
|
||||
{ n_det_max_cisd_sc2 : Det_number_max.t;
|
||||
pt2_max : PT2_energy.t;
|
||||
do_pt2_end : bool;
|
||||
} with sexp
|
||||
;;
|
||||
|
||||
let get_default = Qpackage.get_ezfio_default "cisd_sc2_selected";;
|
||||
|
||||
let read_n_det_max_cisd_sc2 () =
|
||||
if not (Ezfio.has_cisd_sc2_selected_n_det_max_cisd_sc2 ()) then
|
||||
get_default "n_det_max_cisd_sc2"
|
||||
|> Int.of_string
|
||||
|> Ezfio.set_cisd_sc2_selected_n_det_max_cisd_sc2
|
||||
;
|
||||
Ezfio.get_cisd_sc2_selected_n_det_max_cisd_sc2 ()
|
||||
|> Det_number_max.of_int
|
||||
;;
|
||||
|
||||
let write_n_det_max_cisd_sc2 n =
|
||||
Det_number_max.to_int n
|
||||
|> Ezfio.set_cisd_sc2_selected_n_det_max_cisd_sc2
|
||||
;;
|
||||
|
||||
|
||||
let read_pt2_max () =
|
||||
if not (Ezfio.has_cisd_sc2_selected_pt2_max ()) then
|
||||
get_default "pt2_max"
|
||||
|> Float.of_string
|
||||
|> Ezfio.set_cisd_sc2_selected_pt2_max
|
||||
;
|
||||
Ezfio.get_cisd_sc2_selected_pt2_max ()
|
||||
|> PT2_energy.of_float
|
||||
;;
|
||||
|
||||
let write_pt2_max p =
|
||||
PT2_energy.to_float p
|
||||
|> Ezfio.set_cisd_sc2_selected_pt2_max
|
||||
;;
|
||||
|
||||
|
||||
let read_do_pt2_end () =
|
||||
if not (Ezfio.has_cisd_sc2_selected_do_pt2_end ()) then
|
||||
get_default "do_pt2_end"
|
||||
|> Bool.of_string
|
||||
|> Ezfio.set_cisd_sc2_selected_do_pt2_end
|
||||
;
|
||||
Ezfio.get_cisd_sc2_selected_do_pt2_end ()
|
||||
;;
|
||||
|
||||
let write_do_pt2_end =
|
||||
Ezfio.set_cisd_sc2_selected_do_pt2_end
|
||||
;;
|
||||
|
||||
|
||||
let read () =
|
||||
Some
|
||||
{ n_det_max_cisd_sc2 = read_n_det_max_cisd_sc2 ();
|
||||
pt2_max = read_pt2_max ();
|
||||
do_pt2_end = read_do_pt2_end ();
|
||||
}
|
||||
;;
|
||||
|
||||
let write { n_det_max_cisd_sc2 ;
|
||||
pt2_max ;
|
||||
do_pt2_end ;
|
||||
} =
|
||||
write_n_det_max_cisd_sc2 n_det_max_cisd_sc2;
|
||||
write_pt2_max pt2_max;
|
||||
write_do_pt2_end do_pt2_end;
|
||||
;;
|
||||
|
||||
let to_string b =
|
||||
Printf.sprintf "
|
||||
n_det_max_cisd_sc2 = %s
|
||||
pt2_max = %s
|
||||
do_pt2_end = %s
|
||||
"
|
||||
(Det_number_max.to_string b.n_det_max_cisd_sc2)
|
||||
(PT2_energy.to_string b.pt2_max)
|
||||
(Bool.to_string b.do_pt2_end)
|
||||
;;
|
||||
|
||||
let to_rst b =
|
||||
Printf.sprintf "
|
||||
Stop when the `n_det` > `n_det_max_cisd_sc2` ::
|
||||
|
||||
n_det_max_cisd_sc2 = %s
|
||||
|
||||
Stop when -E(PT2) < `pt2_max` ::
|
||||
|
||||
pt2_max = %s
|
||||
|
||||
Compute E(PT2) at the end ::
|
||||
|
||||
do_pt2_end = %s
|
||||
|
||||
"
|
||||
(Det_number_max.to_string b.n_det_max_cisd_sc2)
|
||||
(PT2_energy.to_string b.pt2_max)
|
||||
(Bool.to_string b.do_pt2_end)
|
||||
|> Rst_string.of_string
|
||||
;;
|
||||
|
||||
include Generic_input_of_rst;;
|
||||
let of_rst = of_rst t_of_sexp;;
|
||||
|
||||
end
|
||||
|
||||
|
@ -1,153 +0,0 @@
|
||||
open Qptypes;;
|
||||
open Qputils;;
|
||||
open Core.Std;;
|
||||
|
||||
module Full_ci : sig
|
||||
type t =
|
||||
{ n_det_max_fci : Det_number_max.t;
|
||||
pt2_max : PT2_energy.t;
|
||||
do_pt2_end : bool;
|
||||
var_pt2_ratio : Normalized_float.t;
|
||||
} with sexp
|
||||
;;
|
||||
val read : unit -> t option
|
||||
val write : t-> unit
|
||||
val to_string : t -> string
|
||||
val to_rst : t -> Rst_string.t
|
||||
val of_rst : Rst_string.t -> t option
|
||||
end = struct
|
||||
type t =
|
||||
{ n_det_max_fci : Det_number_max.t;
|
||||
pt2_max : PT2_energy.t;
|
||||
do_pt2_end : bool;
|
||||
var_pt2_ratio : Normalized_float.t;
|
||||
} with sexp
|
||||
;;
|
||||
|
||||
let get_default = Qpackage.get_ezfio_default "full_ci";;
|
||||
|
||||
let read_n_det_max_fci () =
|
||||
if not (Ezfio.has_full_ci_n_det_max_fci ()) then
|
||||
get_default "n_det_max_fci"
|
||||
|> Int.of_string
|
||||
|> Ezfio.set_full_ci_n_det_max_fci
|
||||
;
|
||||
Ezfio.get_full_ci_n_det_max_fci ()
|
||||
|> Det_number_max.of_int
|
||||
;;
|
||||
|
||||
let write_n_det_max_fci ndet =
|
||||
Det_number_max.to_int ndet
|
||||
|> Ezfio.set_full_ci_n_det_max_fci
|
||||
;;
|
||||
|
||||
let read_var_pt2_ratio () =
|
||||
if not (Ezfio.has_full_ci_var_pt2_ratio ()) then
|
||||
get_default "var_pt2_ratio"
|
||||
|> Float.of_string
|
||||
|> Ezfio.set_full_ci_var_pt2_ratio
|
||||
;
|
||||
Ezfio.get_full_ci_var_pt2_ratio ()
|
||||
|> Normalized_float.of_float
|
||||
;;
|
||||
|
||||
let write_var_pt2_ratio ratio =
|
||||
Normalized_float.to_float ratio
|
||||
|> Ezfio.set_full_ci_var_pt2_ratio
|
||||
;;
|
||||
|
||||
let read_pt2_max () =
|
||||
if not (Ezfio.has_full_ci_pt2_max ()) then
|
||||
get_default "pt2_max"
|
||||
|> Float.of_string
|
||||
|> Ezfio.set_full_ci_pt2_max
|
||||
;
|
||||
Ezfio.get_full_ci_pt2_max ()
|
||||
|> PT2_energy.of_float
|
||||
;;
|
||||
|
||||
let write_pt2_max pt2_max =
|
||||
PT2_energy.to_float pt2_max
|
||||
|> Ezfio.set_full_ci_pt2_max
|
||||
;;
|
||||
|
||||
let read_do_pt2_end () =
|
||||
if not (Ezfio.has_full_ci_do_pt2_end ()) then
|
||||
get_default "do_pt2_end"
|
||||
|> Bool.of_string
|
||||
|> Ezfio.set_full_ci_do_pt2_end
|
||||
;
|
||||
Ezfio.get_full_ci_do_pt2_end ()
|
||||
;;
|
||||
|
||||
let write_do_pt2_end =
|
||||
Ezfio.set_full_ci_do_pt2_end
|
||||
;;
|
||||
|
||||
|
||||
let read () =
|
||||
Some
|
||||
{ n_det_max_fci = read_n_det_max_fci ();
|
||||
pt2_max = read_pt2_max ();
|
||||
do_pt2_end = read_do_pt2_end ();
|
||||
var_pt2_ratio = read_var_pt2_ratio ();
|
||||
}
|
||||
;;
|
||||
|
||||
|
||||
let write { n_det_max_fci ;
|
||||
pt2_max ;
|
||||
do_pt2_end ;
|
||||
var_pt2_ratio ;
|
||||
} =
|
||||
write_n_det_max_fci n_det_max_fci;
|
||||
write_pt2_max pt2_max;
|
||||
write_do_pt2_end do_pt2_end;
|
||||
write_var_pt2_ratio var_pt2_ratio;
|
||||
;;
|
||||
|
||||
let to_string b =
|
||||
Printf.sprintf "
|
||||
n_det_max_fci = %s
|
||||
pt2_max = %s
|
||||
do_pt2_end = %s
|
||||
var_pt2_ratio = %s
|
||||
"
|
||||
(Det_number_max.to_string b.n_det_max_fci)
|
||||
(PT2_energy.to_string b.pt2_max)
|
||||
(Bool.to_string b.do_pt2_end)
|
||||
(Normalized_float.to_string b.var_pt2_ratio)
|
||||
;;
|
||||
|
||||
let to_rst b =
|
||||
Printf.sprintf "
|
||||
Stop when the `n_det` > `n_det_max_fci` ::
|
||||
|
||||
n_det_max_fci = %s
|
||||
|
||||
Stop when -E(PT2) < `pt2_max` ::
|
||||
|
||||
pt2_max = %s
|
||||
|
||||
Compute E(PT2) at the end ::
|
||||
|
||||
do_pt2_end = %s
|
||||
|
||||
Target energy ratio variational/(variational+PT2) ::
|
||||
|
||||
var_pt2_ratio = %s
|
||||
"
|
||||
(Det_number_max.to_string b.n_det_max_fci)
|
||||
(PT2_energy.to_string b.pt2_max)
|
||||
(Bool.to_string b.do_pt2_end)
|
||||
(Normalized_float.to_string b.var_pt2_ratio)
|
||||
|> Rst_string.of_string
|
||||
;;
|
||||
|
||||
include Generic_input_of_rst;;
|
||||
let of_rst = of_rst t_of_sexp;;
|
||||
|
||||
|
||||
end
|
||||
|
||||
|
@ -1,128 +0,0 @@
|
||||
open Qptypes;;
|
||||
open Qputils;;
|
||||
open Core.Std;;
|
||||
|
||||
module Hartree_fock : sig
|
||||
type t =
|
||||
{ n_it_scf_max : Strictly_positive_int.t;
|
||||
thresh_scf : Threshold.t;
|
||||
guess : MO_guess.t;
|
||||
} with sexp
|
||||
;;
|
||||
val read : unit -> t option
|
||||
val write : t -> unit
|
||||
val to_string : t -> string
|
||||
val to_rst : t -> Rst_string.t
|
||||
val of_rst : Rst_string.t -> t option
|
||||
end = struct
|
||||
type t =
|
||||
{ n_it_scf_max : Strictly_positive_int.t;
|
||||
thresh_scf : Threshold.t;
|
||||
guess : MO_guess.t;
|
||||
} with sexp
|
||||
;;
|
||||
|
||||
let get_default = Qpackage.get_ezfio_default "hartree_fock";;
|
||||
|
||||
let read_n_it_scf_max () =
|
||||
if not (Ezfio.has_hartree_fock_n_it_scf_max ()) then
|
||||
get_default "n_it_scf_max"
|
||||
|> Int.of_string
|
||||
|> Ezfio.set_hartree_fock_n_it_scf_max
|
||||
;
|
||||
Ezfio.get_hartree_fock_n_it_scf_max ()
|
||||
|> Strictly_positive_int.of_int
|
||||
;;
|
||||
|
||||
let write_n_it_scf_max n_it_scf_max =
|
||||
Strictly_positive_int.to_int n_it_scf_max
|
||||
|> Ezfio.set_hartree_fock_n_it_scf_max
|
||||
;;
|
||||
|
||||
let read_thresh_scf () =
|
||||
if not (Ezfio.has_hartree_fock_thresh_scf()) then
|
||||
get_default "thresh_scf"
|
||||
|> Float.of_string
|
||||
|> Ezfio.set_hartree_fock_thresh_scf
|
||||
;
|
||||
Ezfio.get_hartree_fock_thresh_scf ()
|
||||
|> Threshold.of_float
|
||||
;;
|
||||
|
||||
let write_thresh_scf thresh_scf =
|
||||
Threshold.to_float thresh_scf
|
||||
|> Ezfio.set_hartree_fock_thresh_scf
|
||||
;;
|
||||
|
||||
let read_guess () =
|
||||
if not (Ezfio.has_hartree_fock_guess ()) then
|
||||
get_default "guess"
|
||||
|> String.strip ~drop:(fun x -> x = '"')
|
||||
|> Ezfio.set_hartree_fock_guess
|
||||
;
|
||||
Ezfio.get_hartree_fock_guess ()
|
||||
|> MO_guess.of_string
|
||||
;;
|
||||
|
||||
let write_guess guess =
|
||||
MO_guess.to_string guess
|
||||
|> Ezfio.set_hartree_fock_guess
|
||||
;;
|
||||
|
||||
let read () =
|
||||
Some
|
||||
{ n_it_scf_max = read_n_it_scf_max ();
|
||||
thresh_scf = read_thresh_scf ();
|
||||
guess = read_guess ();
|
||||
}
|
||||
;;
|
||||
|
||||
|
||||
let write { n_it_scf_max ;
|
||||
thresh_scf ;
|
||||
guess ;
|
||||
} =
|
||||
write_n_it_scf_max n_it_scf_max;
|
||||
write_thresh_scf thresh_scf;
|
||||
write_guess guess
|
||||
;;
|
||||
|
||||
|
||||
let to_string b =
|
||||
Printf.sprintf "
|
||||
n_it_scf_max = %s
|
||||
thresh_scf = %s
|
||||
guess = %s
|
||||
"
|
||||
(Strictly_positive_int.to_string b.n_it_scf_max)
|
||||
(Threshold.to_string b.thresh_scf)
|
||||
(MO_guess.to_string b.guess)
|
||||
;;
|
||||
|
||||
let to_rst b =
|
||||
Printf.sprintf "
|
||||
Type of MO guess [ Huckel | HCore ] ::
|
||||
|
||||
guess = %s
|
||||
|
||||
Max number of SCF iterations ::
|
||||
|
||||
n_it_scf_max = %s
|
||||
|
||||
SCF convergence criterion (on energy) ::
|
||||
|
||||
thresh_scf = %s
|
||||
|
||||
"
|
||||
(MO_guess.to_string b.guess)
|
||||
(Strictly_positive_int.to_string b.n_it_scf_max)
|
||||
(Threshold.to_string b.thresh_scf)
|
||||
|> Rst_string.of_string
|
||||
;;
|
||||
|
||||
include Generic_input_of_rst;;
|
||||
let of_rst = of_rst t_of_sexp;;
|
||||
|
||||
end
|
||||
|
||||
|
@ -2,27 +2,21 @@ open Qptypes;;
|
||||
open Qputils;;
|
||||
open Core.Std;;
|
||||
|
||||
type t_mo =
|
||||
{ mo_tot_num : MO_number.t ;
|
||||
mo_label : MO_label.t;
|
||||
mo_occ : MO_occ.t array;
|
||||
mo_coef : (MO_coef.t array) array;
|
||||
ao_md5 : MD5.t;
|
||||
} with sexp
|
||||
|
||||
module Mo_basis : sig
|
||||
type t =
|
||||
{ mo_tot_num : MO_number.t ;
|
||||
mo_label : MO_label.t;
|
||||
mo_occ : MO_occ.t array;
|
||||
mo_coef : (MO_coef.t array) array;
|
||||
ao_md5 : MD5.t;
|
||||
} with sexp
|
||||
;;
|
||||
type t = t_mo
|
||||
val read : unit -> t option
|
||||
val to_string : t -> string
|
||||
val to_rst : t -> Rst_string.t
|
||||
end = struct
|
||||
type t =
|
||||
{ mo_tot_num : MO_number.t ;
|
||||
mo_label : MO_label.t;
|
||||
mo_occ : MO_occ.t array;
|
||||
mo_coef : (MO_coef.t array) array;
|
||||
ao_md5 : MD5.t;
|
||||
} with sexp
|
||||
;;
|
||||
type t = t_mo
|
||||
|
||||
let get_default = Qpackage.get_ezfio_default "mo_basis";;
|
||||
|
||||
|
@ -71,8 +71,8 @@ let executables = lazy (
|
||||
)
|
||||
|
||||
|
||||
let get_ezfio_default directory data =
|
||||
let filename = root^"/data/ezfio_defaults" in
|
||||
|
||||
let get_ezfio_default_in_file ~directory ~data ~filename =
|
||||
let lines = In_channel.with_file filename ~f:(fun in_channel ->
|
||||
In_channel.input_lines in_channel) in
|
||||
let rec find_dir = function
|
||||
@ -93,8 +93,10 @@ let get_ezfio_default directory data =
|
||||
begin
|
||||
match (String.lsplit2 ~on:' ' (String.strip line)) with
|
||||
| Some (l,r) ->
|
||||
if (l = data) then (String.lowercase (String.strip r))
|
||||
else find_data rest
|
||||
if (l = data) then
|
||||
String.strip r
|
||||
else
|
||||
find_data rest
|
||||
| None -> raise Not_found
|
||||
end
|
||||
| [] -> raise Not_found
|
||||
@ -102,3 +104,23 @@ let get_ezfio_default directory data =
|
||||
find_dir lines
|
||||
|> find_data ;
|
||||
;;
|
||||
|
||||
let get_ezfio_default directory data =
|
||||
let dirname = root^"/data/ezfio_defaults/" in
|
||||
|
||||
let rec aux = function
|
||||
| [] -> raise Not_found
|
||||
| filename :: tail ->
|
||||
let filename =
|
||||
dirname^filename
|
||||
in
|
||||
try
|
||||
get_ezfio_default_in_file ~directory ~data ~filename
|
||||
with
|
||||
| Not_found -> aux tail
|
||||
in
|
||||
Sys.readdir dirname
|
||||
|> Array.to_list
|
||||
|> aux
|
||||
;;
|
||||
|
||||
|
@ -20,6 +20,10 @@ let run exe ezfio_file =
|
||||
Printf.printf "===============\nQuantum Package\n===============\n\n";
|
||||
Printf.printf "Date : %s\n\n%!" (Time.to_string time_start);
|
||||
|
||||
match (Sys.command ("qp_edit -c "^ezfio_file)) with
|
||||
| 0 -> ()
|
||||
| i -> failwith "Error: Input inconsistent\n";
|
||||
;
|
||||
let exe =
|
||||
match (List.find ~f:(fun (x,_) -> x = exe) executables) with
|
||||
| None -> assert false
|
||||
|
@ -150,19 +150,41 @@ end = struct
|
||||
|
||||
let to_string = function
|
||||
| Huckel -> \"Huckel\"
|
||||
| HCore -> \"HCore\"
|
||||
| HCore -> \"Hcore\"
|
||||
|
||||
let of_string s =
|
||||
let s =
|
||||
String.lowercase s
|
||||
in
|
||||
match s with
|
||||
| \"huckel\" -> Huckel
|
||||
| \"hcore\" -> HCore
|
||||
| \"Huckel\" -> Huckel
|
||||
| \"Hcore\" -> HCore
|
||||
| _ -> failwith (\"Wrong Guess type : \"^s)
|
||||
|
||||
end
|
||||
|
||||
module Disk_access : sig
|
||||
type t with sexp
|
||||
val to_string : t -> string
|
||||
val of_string : string -> t
|
||||
end = struct
|
||||
type t =
|
||||
| Read
|
||||
| Write
|
||||
| None
|
||||
with sexp
|
||||
|
||||
let to_string = function
|
||||
| Read -> \"Read\"
|
||||
| Write -> \"Write\"
|
||||
| None -> \"None\"
|
||||
let of_string s =
|
||||
match s with
|
||||
| \"Read\" -> Read
|
||||
| \"Write\" -> Write
|
||||
| \"None\" -> None
|
||||
| _ -> failwith (\"Wrong IO type : \"^s)
|
||||
|
||||
end
|
||||
"
|
||||
|
||||
;;
|
||||
|
||||
let template = format_of_string "
|
||||
|
@ -1,177 +0,0 @@
|
||||
open Qptypes;;
|
||||
|
||||
let test_ao () =
|
||||
Ezfio.set_file "F2.ezfio" ;
|
||||
let b = match Input.Ao_basis.read () with
|
||||
| Some x -> x
|
||||
| None -> assert false
|
||||
in
|
||||
print_endline (Input.Ao_basis.to_string b);
|
||||
print_endline (Input.Ao_basis.to_rst b |> Rst_string.to_string);
|
||||
;;
|
||||
|
||||
let test_bielec_intergals () =
|
||||
Ezfio.set_file "F2.ezfio" ;
|
||||
let b = match Input.Bielec_integrals.read () with
|
||||
| Some x -> x
|
||||
| None -> assert false
|
||||
in
|
||||
let output = Input.Bielec_integrals.to_string b
|
||||
in
|
||||
print_endline output;
|
||||
let rst = Input.Bielec_integrals.to_rst b in
|
||||
let b2 = match Input.Bielec_integrals.of_rst rst with
|
||||
| Some x -> x
|
||||
| None -> assert false
|
||||
in
|
||||
if (b = b2) then
|
||||
print_endline "OK"
|
||||
else
|
||||
print_endline "rst failed";
|
||||
;;
|
||||
|
||||
let test_bitmasks () =
|
||||
Ezfio.set_file "F2.ezfio" ;
|
||||
let b = match Input.Bitmasks.read () with
|
||||
| Some x -> x
|
||||
| None -> assert false
|
||||
in
|
||||
print_endline (Input.Bitmasks.to_string b);
|
||||
;;
|
||||
|
||||
|
||||
let test_dets () =
|
||||
Ezfio.set_file "F2.ezfio" ;
|
||||
let b = match Input.Determinants.read () with
|
||||
| Some x -> x
|
||||
| None -> assert false
|
||||
in
|
||||
print_endline (Input.Determinants.to_rst b |> Rst_string.to_string ) ;
|
||||
print_endline (Input.Determinants.sexp_of_t b |> Sexplib.Sexp.to_string ) ;
|
||||
let rst = Input.Determinants.to_rst b in
|
||||
let b2 = match Input.Determinants.of_rst rst with
|
||||
| Some x -> x
|
||||
| None -> assert false
|
||||
in
|
||||
if (b2 = b) then
|
||||
print_endline "OK"
|
||||
else
|
||||
print_endline "Failed"
|
||||
;;
|
||||
|
||||
let test_cisd_sc2 () =
|
||||
Ezfio.set_file "F2.ezfio" ;
|
||||
let b = match Input.Cisd_sc2.read () with
|
||||
| Some x -> x
|
||||
| None -> assert false
|
||||
in
|
||||
print_endline (Input.Cisd_sc2.to_string b);
|
||||
let rst = Input.Cisd_sc2.to_rst b in
|
||||
let b2 = match Input.Cisd_sc2.of_rst rst with
|
||||
| Some x -> x
|
||||
| None -> assert false
|
||||
in
|
||||
if (b = b2) then
|
||||
print_endline "OK"
|
||||
else
|
||||
print_endline "rst failed";
|
||||
|
||||
;;
|
||||
|
||||
let test_electrons () =
|
||||
Ezfio.set_file "F2.ezfio" ;
|
||||
let b = match Input.Electrons.read () with
|
||||
| Some x -> x
|
||||
| None -> assert false
|
||||
in
|
||||
print_endline (Input.Electrons.to_string b);
|
||||
let rst = Input.Electrons.to_rst b in
|
||||
let b2 = match Input.Electrons.of_rst rst with
|
||||
| Some x -> x
|
||||
| None -> assert false
|
||||
in
|
||||
if (b = b2) then
|
||||
print_endline "OK"
|
||||
else
|
||||
print_endline "Failed in rst"
|
||||
;;
|
||||
|
||||
let test_fci () =
|
||||
Ezfio.set_file "F2.ezfio" ;
|
||||
let b = match Input.Full_ci.read () with
|
||||
| Some x -> x
|
||||
| None -> assert false
|
||||
in
|
||||
print_endline (Input.Full_ci.to_string b);
|
||||
let rst = Input.Full_ci.to_rst b in
|
||||
let b2 = match Input.Full_ci.of_rst rst with
|
||||
| Some x -> x
|
||||
| None -> assert false
|
||||
in
|
||||
print_endline (Input.Full_ci.to_string b);
|
||||
if (b = b2) then
|
||||
print_endline "OK"
|
||||
else
|
||||
print_endline "Failed in rst"
|
||||
;;
|
||||
|
||||
let test_hf () =
|
||||
Ezfio.set_file "F2.ezfio" ;
|
||||
let b = match Input.Hartree_fock.read () with
|
||||
| Some x -> x
|
||||
| None -> assert false
|
||||
in
|
||||
print_endline (Input.Hartree_fock.to_string b);
|
||||
let rst = Input.Hartree_fock.to_rst b in
|
||||
let b2 = match Input.Hartree_fock.of_rst rst with
|
||||
| Some x -> x
|
||||
| None -> assert false
|
||||
in
|
||||
print_endline (Input.Hartree_fock.to_string b);
|
||||
if (b = b2) then
|
||||
print_endline "OK"
|
||||
else
|
||||
print_endline "Failed in rst"
|
||||
;;
|
||||
|
||||
let test_mo () =
|
||||
Ezfio.set_file "F2.ezfio" ;
|
||||
let b = match Input.Mo_basis.read () with
|
||||
| Some x -> x
|
||||
| None -> assert false
|
||||
in
|
||||
print_endline (Input.Mo_basis.to_string b);
|
||||
;;
|
||||
|
||||
let test_nucl () =
|
||||
Ezfio.set_file "F2.ezfio" ;
|
||||
let b = match Input.Nuclei.read () with
|
||||
| Some x -> x
|
||||
| None -> assert false
|
||||
in
|
||||
let rst = Input.Nuclei.to_rst b in
|
||||
let b2 = match Input.Nuclei.of_rst rst with
|
||||
| Some x -> x
|
||||
| None -> assert false
|
||||
in
|
||||
print_endline (Input.Nuclei.to_string b);
|
||||
if (b = b2) then
|
||||
print_endline "OK"
|
||||
else
|
||||
print_endline "Failed in rst"
|
||||
;;
|
||||
|
||||
(*
|
||||
test_ao ();;
|
||||
test_bitmasks ();
|
||||
test_cis ();
|
||||
test_cisd_sc2 ();
|
||||
test_dets ();
|
||||
test_hf ();;
|
||||
test_mo ();;
|
||||
test_nucl ();
|
||||
test_bielec_intergals ();;
|
||||
test_electrons();
|
||||
*)
|
||||
test_dets ();
|
||||
|
@ -12,6 +12,8 @@ fi
|
||||
source ${QPACKAGE_ROOT}/scripts/qp_include.sh
|
||||
|
||||
check_current_dir_is_module
|
||||
MODULE=$(basename $PWD)
|
||||
|
||||
|
||||
README="True"
|
||||
if [[ -f README.rst ]]
|
||||
|
590
scripts/docopt.py
Executable file
590
scripts/docopt.py
Executable file
@ -0,0 +1,590 @@
|
||||
"""Pythonic command-line interface parser that will make you smile.
|
||||
|
||||
* http://docopt.org
|
||||
* Repository and issue-tracker: https://github.com/docopt/docopt
|
||||
* Licensed under terms of MIT license (see LICENSE-MIT)
|
||||
* Copyright (c) 2013 Vladimir Keleshev, vladimir@keleshev.com
|
||||
|
||||
"""
|
||||
import sys
|
||||
import re
|
||||
|
||||
|
||||
__all__ = ['docopt']
|
||||
__version__ = '0.6.1'
|
||||
|
||||
|
||||
class DocoptLanguageError(Exception):
|
||||
|
||||
"""Error in construction of usage-message by developer."""
|
||||
|
||||
|
||||
class DocoptExit(SystemExit):
|
||||
|
||||
"""Exit in case user invoked program with incorrect arguments."""
|
||||
|
||||
usage = ''
|
||||
|
||||
def __init__(self, message=''):
|
||||
SystemExit.__init__(self, (message + '\n' + self.usage).strip())
|
||||
|
||||
|
||||
class Pattern(object):
|
||||
|
||||
def __eq__(self, other):
|
||||
return repr(self) == repr(other)
|
||||
|
||||
def __hash__(self):
|
||||
return hash(repr(self))
|
||||
|
||||
def fix(self):
|
||||
self.fix_identities()
|
||||
self.fix_repeating_arguments()
|
||||
return self
|
||||
|
||||
def fix_identities(self, uniq=None):
|
||||
"""Make pattern-tree tips point to same object if they are equal."""
|
||||
if not hasattr(self, 'children'):
|
||||
return self
|
||||
uniq = list(set(self.flat())) if uniq is None else uniq
|
||||
for i, child in enumerate(self.children):
|
||||
if not hasattr(child, 'children'):
|
||||
assert child in uniq
|
||||
self.children[i] = uniq[uniq.index(child)]
|
||||
else:
|
||||
child.fix_identities(uniq)
|
||||
|
||||
def fix_repeating_arguments(self):
|
||||
"""Fix elements that should accumulate/increment values."""
|
||||
either = [list(child.children) for child in transform(self).children]
|
||||
for case in either:
|
||||
for e in [child for child in case if case.count(child) > 1]:
|
||||
if isinstance(
|
||||
e,
|
||||
Argument) or isinstance(
|
||||
e,
|
||||
Option) and e.argcount:
|
||||
if e.value is None:
|
||||
e.value = []
|
||||
elif not isinstance(e.value, list):
|
||||
e.value = e.value.split()
|
||||
if isinstance(
|
||||
e,
|
||||
Command) or isinstance(
|
||||
e,
|
||||
Option) and e.argcount == 0:
|
||||
e.value = 0
|
||||
return self
|
||||
|
||||
|
||||
def transform(pattern):
|
||||
"""Expand pattern into an (almost) equivalent one, but with single Either.
|
||||
|
||||
Example: ((-a | -b) (-c | -d)) => (-a -c | -a -d | -b -c | -b -d)
|
||||
Quirks: [-a] => (-a), (-a...) => (-a -a)
|
||||
|
||||
"""
|
||||
result = []
|
||||
groups = [[pattern]]
|
||||
while groups:
|
||||
children = groups.pop(0)
|
||||
parents = [Required, Optional, OptionsShortcut, Either, OneOrMore]
|
||||
if any(t in map(type, children) for t in parents):
|
||||
child = [c for c in children if type(c) in parents][0]
|
||||
children.remove(child)
|
||||
if isinstance(child, Either):
|
||||
for c in child.children:
|
||||
groups.append([c] + children)
|
||||
elif isinstance(child, OneOrMore):
|
||||
groups.append(child.children * 2 + children)
|
||||
else:
|
||||
groups.append(child.children + children)
|
||||
else:
|
||||
result.append(children)
|
||||
return Either(*[Required(*e) for e in result])
|
||||
|
||||
|
||||
class LeafPattern(Pattern):
|
||||
|
||||
"""Leaf/terminal node of a pattern tree."""
|
||||
|
||||
def __init__(self, name, value=None):
|
||||
self.name, self.value = name, value
|
||||
|
||||
def __repr__(self):
|
||||
return '%s(%r, %r)' % (self.__class__.__name__, self.name, self.value)
|
||||
|
||||
def flat(self, *types):
|
||||
return [self] if not types or type(self) in types else []
|
||||
|
||||
def match(self, left, collected=None):
|
||||
collected = [] if collected is None else collected
|
||||
pos, match = self.single_match(left)
|
||||
if match is None:
|
||||
return False, left, collected
|
||||
left_ = left[:pos] + left[pos + 1:]
|
||||
same_name = [a for a in collected if a.name == self.name]
|
||||
if type(self.value) in (int, list):
|
||||
if isinstance(self.value, int):
|
||||
increment = 1
|
||||
else:
|
||||
increment = ([match.value] if isinstance(match.value, str)
|
||||
else match.value)
|
||||
if not same_name:
|
||||
match.value = increment
|
||||
return True, left_, collected + [match]
|
||||
same_name[0].value += increment
|
||||
return True, left_, collected
|
||||
return True, left_, collected + [match]
|
||||
|
||||
|
||||
class BranchPattern(Pattern):
|
||||
|
||||
"""Branch/inner node of a pattern tree."""
|
||||
|
||||
def __init__(self, *children):
|
||||
self.children = list(children)
|
||||
|
||||
def __repr__(self):
|
||||
return '%s(%s)' % (self.__class__.__name__,
|
||||
', '.join(repr(a) for a in self.children))
|
||||
|
||||
def flat(self, *types):
|
||||
if type(self) in types:
|
||||
return [self]
|
||||
return sum([child.flat(*types) for child in self.children], [])
|
||||
|
||||
|
||||
class Argument(LeafPattern):
|
||||
|
||||
def single_match(self, left):
|
||||
for n, pattern in enumerate(left):
|
||||
if isinstance(pattern, Argument):
|
||||
return n, Argument(self.name, pattern.value)
|
||||
return None, None
|
||||
|
||||
@classmethod
|
||||
def parse(class_, source):
|
||||
name = re.findall('(<\S*?>)', source)[0]
|
||||
value = re.findall('\[default: (.*)\]', source, flags=re.I)
|
||||
return class_(name, value[0] if value else None)
|
||||
|
||||
|
||||
class Command(Argument):
|
||||
|
||||
def __init__(self, name, value=False):
|
||||
self.name, self.value = name, value
|
||||
|
||||
def single_match(self, left):
|
||||
for n, pattern in enumerate(left):
|
||||
if isinstance(pattern, Argument):
|
||||
if pattern.value == self.name:
|
||||
return n, Command(self.name, True)
|
||||
else:
|
||||
break
|
||||
return None, None
|
||||
|
||||
|
||||
class Option(LeafPattern):
|
||||
|
||||
def __init__(self, short=None, long=None, argcount=0, value=False):
|
||||
assert argcount in (0, 1)
|
||||
self.short, self.long, self.argcount = short, long, argcount
|
||||
self.value = None if value is False and argcount else value
|
||||
|
||||
@classmethod
|
||||
def parse(class_, option_description):
|
||||
short, long, argcount, value = None, None, 0, False
|
||||
options, _, description = option_description.strip().partition(' ')
|
||||
options = options.replace(',', ' ').replace('=', ' ')
|
||||
for s in options.split():
|
||||
if s.startswith('--'):
|
||||
long = s
|
||||
elif s.startswith('-'):
|
||||
short = s
|
||||
else:
|
||||
argcount = 1
|
||||
if argcount:
|
||||
matched = re.findall('\[default: (.*)\]', description, flags=re.I)
|
||||
value = matched[0] if matched else None
|
||||
return class_(short, long, argcount, value)
|
||||
|
||||
def single_match(self, left):
|
||||
for n, pattern in enumerate(left):
|
||||
if self.name == pattern.name:
|
||||
return n, pattern
|
||||
return None, None
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
return self.long or self.short
|
||||
|
||||
def __repr__(self):
|
||||
return 'Option(%r, %r, %r, %r)' % (self.short, self.long,
|
||||
self.argcount, self.value)
|
||||
|
||||
|
||||
class Required(BranchPattern):
|
||||
|
||||
def match(self, left, collected=None):
|
||||
collected = [] if collected is None else collected
|
||||
l = left
|
||||
c = collected
|
||||
for pattern in self.children:
|
||||
matched, l, c = pattern.match(l, c)
|
||||
if not matched:
|
||||
return False, left, collected
|
||||
return True, l, c
|
||||
|
||||
|
||||
class Optional(BranchPattern):
|
||||
|
||||
def match(self, left, collected=None):
|
||||
collected = [] if collected is None else collected
|
||||
for pattern in self.children:
|
||||
m, left, collected = pattern.match(left, collected)
|
||||
return True, left, collected
|
||||
|
||||
|
||||
class OptionsShortcut(Optional):
|
||||
|
||||
"""Marker/placeholder for [options] shortcut."""
|
||||
|
||||
|
||||
class OneOrMore(BranchPattern):
|
||||
|
||||
def match(self, left, collected=None):
|
||||
assert len(self.children) == 1
|
||||
collected = [] if collected is None else collected
|
||||
l = left
|
||||
c = collected
|
||||
l_ = None
|
||||
matched = True
|
||||
times = 0
|
||||
while matched:
|
||||
# could it be that something didn't match but changed l or c?
|
||||
matched, l, c = self.children[0].match(l, c)
|
||||
times += 1 if matched else 0
|
||||
if l_ == l:
|
||||
break
|
||||
l_ = l
|
||||
if times >= 1:
|
||||
return True, l, c
|
||||
return False, left, collected
|
||||
|
||||
|
||||
class Either(BranchPattern):
|
||||
|
||||
def match(self, left, collected=None):
|
||||
collected = [] if collected is None else collected
|
||||
outcomes = []
|
||||
for pattern in self.children:
|
||||
matched, _, _ = outcome = pattern.match(left, collected)
|
||||
if matched:
|
||||
outcomes.append(outcome)
|
||||
if outcomes:
|
||||
return min(outcomes, key=lambda outcome: len(outcome[1]))
|
||||
return False, left, collected
|
||||
|
||||
|
||||
class Tokens(list):
|
||||
|
||||
def __init__(self, source, error=DocoptExit):
|
||||
self += source.split() if hasattr(source, 'split') else source
|
||||
self.error = error
|
||||
|
||||
@staticmethod
|
||||
def from_pattern(source):
|
||||
source = re.sub(r'([\[\]\(\)\|]|\.\.\.)', r' \1 ', source)
|
||||
source = [s for s in re.split('\s+|(\S*<.*?>)', source) if s]
|
||||
return Tokens(source, error=DocoptLanguageError)
|
||||
|
||||
def move(self):
|
||||
return self.pop(0) if len(self) else None
|
||||
|
||||
def current(self):
|
||||
return self[0] if len(self) else None
|
||||
|
||||
|
||||
def parse_long(tokens, options):
|
||||
"""long ::= '--' chars [ ( ' ' | '=' ) chars ] ;"""
|
||||
long, eq, value = tokens.move().partition('=')
|
||||
assert long.startswith('--')
|
||||
value = None if eq == value == '' else value
|
||||
similar = [o for o in options if o.long == long]
|
||||
if tokens.error is DocoptExit and similar == []: # if no exact match
|
||||
similar = [o for o in options if o.long and o.long.startswith(long)]
|
||||
if len(similar) > 1: # might be simply specified ambiguously 2+ times?
|
||||
raise tokens.error('%s is not a unique prefix: %s?' %
|
||||
(long, ', '.join(o.long for o in similar)))
|
||||
elif len(similar) < 1:
|
||||
argcount = 1 if eq == '=' else 0
|
||||
o = Option(None, long, argcount)
|
||||
options.append(o)
|
||||
if tokens.error is DocoptExit:
|
||||
o = Option(None, long, argcount, value if argcount else True)
|
||||
else:
|
||||
o = Option(similar[0].short, similar[0].long,
|
||||
similar[0].argcount, similar[0].value)
|
||||
if o.argcount == 0:
|
||||
if value is not None:
|
||||
raise tokens.error('%s must not have an argument' % o.long)
|
||||
else:
|
||||
if value is None:
|
||||
if tokens.current() in [None, '--']:
|
||||
raise tokens.error('%s requires argument' % o.long)
|
||||
value = tokens.move()
|
||||
if tokens.error is DocoptExit:
|
||||
o.value = value if value is not None else True
|
||||
return [o]
|
||||
|
||||
|
||||
def parse_shorts(tokens, options):
|
||||
"""shorts ::= '-' ( chars )* [ [ ' ' ] chars ] ;"""
|
||||
token = tokens.move()
|
||||
assert token.startswith('-') and not token.startswith('--')
|
||||
left = token.lstrip('-')
|
||||
parsed = []
|
||||
while left != '':
|
||||
short, left = '-' + left[0], left[1:]
|
||||
similar = [o for o in options if o.short == short]
|
||||
if len(similar) > 1:
|
||||
raise tokens.error('%s is specified ambiguously %d times' %
|
||||
(short, len(similar)))
|
||||
elif len(similar) < 1:
|
||||
o = Option(short, None, 0)
|
||||
options.append(o)
|
||||
if tokens.error is DocoptExit:
|
||||
o = Option(short, None, 0, True)
|
||||
else: # why copying is necessary here?
|
||||
o = Option(short, similar[0].long,
|
||||
similar[0].argcount, similar[0].value)
|
||||
value = None
|
||||
if o.argcount != 0:
|
||||
if left == '':
|
||||
if tokens.current() in [None, '--']:
|
||||
raise tokens.error('%s requires argument' % short)
|
||||
value = tokens.move()
|
||||
else:
|
||||
value = left
|
||||
left = ''
|
||||
if tokens.error is DocoptExit:
|
||||
o.value = value if value is not None else True
|
||||
parsed.append(o)
|
||||
return parsed
|
||||
|
||||
|
||||
def parse_pattern(source, options):
|
||||
tokens = Tokens.from_pattern(source)
|
||||
result = parse_expr(tokens, options)
|
||||
if tokens.current() is not None:
|
||||
raise tokens.error('unexpected ending: %r' % ' '.join(tokens))
|
||||
return Required(*result)
|
||||
|
||||
|
||||
def parse_expr(tokens, options):
|
||||
"""expr ::= seq ( '|' seq )* ;"""
|
||||
seq = parse_seq(tokens, options)
|
||||
if tokens.current() != '|':
|
||||
return seq
|
||||
result = [Required(*seq)] if len(seq) > 1 else seq
|
||||
while tokens.current() == '|':
|
||||
tokens.move()
|
||||
seq = parse_seq(tokens, options)
|
||||
result += [Required(*seq)] if len(seq) > 1 else seq
|
||||
return [Either(*result)] if len(result) > 1 else result
|
||||
|
||||
|
||||
def parse_seq(tokens, options):
|
||||
"""seq ::= ( atom [ '...' ] )* ;"""
|
||||
result = []
|
||||
while tokens.current() not in [None, ']', ')', '|']:
|
||||
atom = parse_atom(tokens, options)
|
||||
if tokens.current() == '...':
|
||||
atom = [OneOrMore(*atom)]
|
||||
tokens.move()
|
||||
result += atom
|
||||
return result
|
||||
|
||||
|
||||
def parse_atom(tokens, options):
|
||||
"""atom ::= '(' expr ')' | '[' expr ']' | 'options'
|
||||
| long | shorts | argument | command ;
|
||||
"""
|
||||
token = tokens.current()
|
||||
result = []
|
||||
if token in '([':
|
||||
tokens.move()
|
||||
matching, pattern = {'(': [')', Required], '[': [']', Optional]}[token]
|
||||
result = pattern(*parse_expr(tokens, options))
|
||||
if tokens.move() != matching:
|
||||
raise tokens.error("unmatched '%s'" % token)
|
||||
return [result]
|
||||
elif token == 'options':
|
||||
tokens.move()
|
||||
return [OptionsShortcut()]
|
||||
elif token.startswith('--') and token != '--':
|
||||
return parse_long(tokens, options)
|
||||
elif token.startswith('-') and token not in ('-', '--'):
|
||||
return parse_shorts(tokens, options)
|
||||
elif token.startswith('<') and token.endswith('>') or token.isupper():
|
||||
return [Argument(tokens.move())]
|
||||
else:
|
||||
return [Command(tokens.move())]
|
||||
|
||||
|
||||
def parse_argv(tokens, options, options_first=False):
|
||||
"""Parse command-line argument vector.
|
||||
|
||||
If options_first:
|
||||
argv ::= [ long | shorts ]* [ argument ]* [ '--' [ argument ]* ] ;
|
||||
else:
|
||||
argv ::= [ long | shorts | argument ]* [ '--' [ argument ]* ] ;
|
||||
|
||||
"""
|
||||
parsed = []
|
||||
while tokens.current() is not None:
|
||||
if tokens.current() == '--':
|
||||
return parsed + [Argument(None, v) for v in tokens]
|
||||
elif tokens.current().startswith('--'):
|
||||
parsed += parse_long(tokens, options)
|
||||
elif tokens.current().startswith('-') and tokens.current() != '-':
|
||||
parsed += parse_shorts(tokens, options)
|
||||
elif options_first:
|
||||
return parsed + [Argument(None, v) for v in tokens]
|
||||
else:
|
||||
parsed.append(Argument(None, tokens.move()))
|
||||
return parsed
|
||||
|
||||
|
||||
def parse_defaults(doc):
|
||||
defaults = []
|
||||
for s in parse_section('options:', doc):
|
||||
# FIXME corner case "bla: options: --foo"
|
||||
_, _, s = s.partition(':') # get rid of "options:"
|
||||
split = re.split('\n[ \t]*(-\S+?)', '\n' + s)[1:]
|
||||
split = [s1 + s2 for s1, s2 in zip(split[::2], split[1::2])]
|
||||
options = [Option.parse(s) for s in split if s.startswith('-')]
|
||||
defaults += options
|
||||
return defaults
|
||||
|
||||
|
||||
def parse_section(name, source):
|
||||
pattern = re.compile('^([^\n]*' + name + '[^\n]*\n?(?:[ \t].*?(?:\n|$))*)',
|
||||
re.IGNORECASE | re.MULTILINE)
|
||||
return [s.strip() for s in pattern.findall(source)]
|
||||
|
||||
|
||||
def formal_usage(section):
|
||||
_, _, section = section.partition(':') # drop "usage:"
|
||||
pu = section.split()
|
||||
return '( ' + ' '.join(') | (' if s == pu[0] else s for s in pu[1:]) + ' )'
|
||||
|
||||
|
||||
def extras(help, version, options, doc):
|
||||
if help and any((o.name in ('-h', '--help')) and o.value for o in options):
|
||||
print(doc.strip("\n"))
|
||||
sys.exit()
|
||||
if version and any(o.name == '--version' and o.value for o in options):
|
||||
print(version)
|
||||
sys.exit()
|
||||
|
||||
|
||||
class Dict(dict):
|
||||
|
||||
def __repr__(self):
|
||||
return '{%s}' % ',\n '.join('%r: %r' % i for i in sorted(self.items()))
|
||||
|
||||
|
||||
def docopt(doc, argv=None, help=True, version=None, options_first=False):
|
||||
"""Parse `argv` based on command-line interface described in `doc`.
|
||||
|
||||
`docopt` creates your command-line interface based on its
|
||||
description that you pass as `doc`. Such description can contain
|
||||
--options, <positional-argument>, commands, which could be
|
||||
[optional], (required), (mutually | exclusive) or repeated...
|
||||
|
||||
Parameters
|
||||
----------
|
||||
doc : str
|
||||
Description of your command-line interface.
|
||||
argv : list of str, optional
|
||||
Argument vector to be parsed. sys.argv[1:] is used if not
|
||||
provided.
|
||||
help : bool (default: True)
|
||||
Set to False to disable automatic help on -h or --help
|
||||
options.
|
||||
version : any object
|
||||
If passed, the object will be printed if --version is in
|
||||
`argv`.
|
||||
options_first : bool (default: False)
|
||||
Set to True to require options precede positional arguments,
|
||||
i.e. to forbid options and positional arguments intermix.
|
||||
|
||||
Returns
|
||||
-------
|
||||
args : dict
|
||||
A dictionary, where keys are names of command-line elements
|
||||
such as e.g. "--verbose" and "<path>", and values are the
|
||||
parsed values of those elements.
|
||||
|
||||
Example
|
||||
-------
|
||||
>>> from docopt import docopt
|
||||
>>> doc = '''
|
||||
... Usage:
|
||||
... my_program tcp <host> <port> [--timeout=<seconds>]
|
||||
... my_program serial <port> [--baud=<n>] [--timeout=<seconds>]
|
||||
... my_program (-h | --help | --version)
|
||||
...
|
||||
... Options:
|
||||
... -h, --help Show this screen and exit.
|
||||
... --baud=<n> Baudrate [default: 9600]
|
||||
... '''
|
||||
>>> argv = ['tcp', '127.0.0.1', '80', '--timeout', '30']
|
||||
>>> docopt(doc, argv)
|
||||
{'--baud': '9600',
|
||||
'--help': False,
|
||||
'--timeout': '30',
|
||||
'--version': False,
|
||||
'<host>': '127.0.0.1',
|
||||
'<port>': '80',
|
||||
'serial': False,
|
||||
'tcp': True}
|
||||
|
||||
See also
|
||||
--------
|
||||
* For video introduction see http://docopt.org
|
||||
* Full documentation is available in README.rst as well as online
|
||||
at https://github.com/docopt/docopt#readme
|
||||
|
||||
"""
|
||||
argv = sys.argv[1:] if argv is None else argv
|
||||
|
||||
usage_sections = parse_section('usage:', doc)
|
||||
if len(usage_sections) == 0:
|
||||
raise DocoptLanguageError('"usage:" (case-insensitive) not found.')
|
||||
if len(usage_sections) > 1:
|
||||
raise DocoptLanguageError('More than one "usage:" (case-insensitive).')
|
||||
DocoptExit.usage = usage_sections[0]
|
||||
|
||||
options = parse_defaults(doc)
|
||||
pattern = parse_pattern(formal_usage(DocoptExit.usage), options)
|
||||
# [default] syntax for argument is disabled
|
||||
# for a in pattern.flat(Argument):
|
||||
# same_name = [d for d in arguments if d.name == a.name]
|
||||
# if same_name:
|
||||
# a.value = same_name[0].value
|
||||
argv = parse_argv(Tokens(argv), list(options), options_first)
|
||||
pattern_options = set(pattern.flat(Option))
|
||||
for options_shortcut in pattern.flat(OptionsShortcut):
|
||||
doc_options = parse_defaults(doc)
|
||||
options_shortcut.children = list(set(doc_options) - pattern_options)
|
||||
# if any_options:
|
||||
# options_shortcut.children += [Option(o.short, o.long, o.argcount)
|
||||
# for o in argv if type(o) is Option]
|
||||
extras(help, version, argv, doc)
|
||||
matched, left, collected = pattern.fix().match(argv)
|
||||
if matched and left == []: # better error message if left?
|
||||
return Dict((a.name, a.value) for a in (pattern.flat() + collected))
|
||||
raise DocoptExit()
|
@ -1,333 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Take a path in argv
|
||||
Check if EZFIO.cfg exists.
|
||||
EZFIO.cfg are in MODULE directories.
|
||||
create : ezfio_interface.irp.f
|
||||
folder_ezfio_inteface_config
|
||||
|
||||
Example EZFIO.cfg:
|
||||
```
|
||||
[thresh_SCF]
|
||||
doc: Threshold on the convergence of the Hartree Fock energy
|
||||
type: Threshold
|
||||
default: 1.e-10
|
||||
|
||||
[do_pt2_end]
|
||||
type: logical
|
||||
doc: If true, compute the PT2 at the end of the selection
|
||||
default: true
|
||||
```
|
||||
|
||||
"""
|
||||
|
||||
import sys
|
||||
import os
|
||||
import os.path
|
||||
|
||||
import ConfigParser
|
||||
|
||||
from collections import defaultdict
|
||||
from collections import namedtuple
|
||||
|
||||
Type = namedtuple('Type', 'ocaml fortran')
|
||||
def bool_convertor(b):
|
||||
return ( b.lower() in [ "true", ".true." ] )
|
||||
|
||||
|
||||
def get_type_dict():
|
||||
"""
|
||||
This function makes the correspondance between the type of value read in
|
||||
ezfio.cfg into the f90 and Ocam Type
|
||||
return fancy_type[fancy_type] = namedtuple('Type', 'ocaml fortran')
|
||||
For example fancy_type['Ndet'].fortran = interger
|
||||
.ocaml = int
|
||||
"""
|
||||
|
||||
# ~#~#~#~ #
|
||||
# I n i t #
|
||||
# ~#~#~#~ #
|
||||
|
||||
# Dict to change ocaml LowLevel type into FortranLowLevel type
|
||||
ocaml_to_fortran = {"int": "integer",
|
||||
"float": "double precision",
|
||||
"logical": "logical",
|
||||
"string": "character*60"}
|
||||
|
||||
fancy_type = defaultdict(dict)
|
||||
|
||||
# ~#~#~#~#~#~#~#~ #
|
||||
# R a w _ t y p e #
|
||||
# ~#~#~#~#~#~#~#~ #
|
||||
|
||||
fancy_type['integer'] = Type("int", "integer")
|
||||
fancy_type['int'] = Type("int", "integer")
|
||||
|
||||
fancy_type['float'] = Type("float", "double precision")
|
||||
fancy_type['double precision'] = Type("float", "double precision")
|
||||
|
||||
fancy_type['logical'] = Type("bool", "logical")
|
||||
fancy_type['bool'] = Type("bool", "logical")
|
||||
|
||||
# ~#~#~#~#~#~#~#~ #
|
||||
# q p _ t y p e s #
|
||||
# ~#~#~#~#~#~#~#~ #
|
||||
|
||||
src = os.environ['QPACKAGE_ROOT'] + "/ocaml/qptypes_generator.ml"
|
||||
|
||||
with open(src, "r") as f:
|
||||
l = [i for i in f.read().splitlines() if i.strip().startswith("*")]
|
||||
|
||||
for i in l:
|
||||
ocaml_fancy_type = i.split()[1].strip()
|
||||
ocaml_type = i.split()[3]
|
||||
fortran_type = ocaml_to_fortran[ocaml_type]
|
||||
|
||||
fancy_type[ocaml_fancy_type] = Type(ocaml_type, fortran_type)
|
||||
|
||||
return dict(fancy_type)
|
||||
|
||||
|
||||
type_dict = get_type_dict()
|
||||
|
||||
|
||||
def get_dict_config_file(config_file_path, module_lower):
|
||||
"""
|
||||
Input:
|
||||
config_file_path is the config file path
|
||||
(for example FULL_PATH/EZFIO.cfg)
|
||||
module_lower is the MODULE name lowered
|
||||
(Ex fullci)
|
||||
|
||||
Return a dict d[provider_name] = {type,
|
||||
doc,
|
||||
ezfio_name,
|
||||
ezfio_dir,
|
||||
interface,
|
||||
default}
|
||||
|
||||
Type : Is a fancy_type named typle who containt fortran and ocaml type
|
||||
doc : Is the doc
|
||||
ezfio_name : Will be the name of the file
|
||||
ezfio_dir : Will be the folder who containt the ezfio_name
|
||||
* /ezfio_dir/ezfio_name
|
||||
* equal to MODULE_lower name for the moment.
|
||||
interface : The provider is a imput or a output
|
||||
if is a output:
|
||||
default : The default value
|
||||
|
||||
"""
|
||||
# ~#~#~#~ #
|
||||
# I n i t #
|
||||
# ~#~#~#~ #
|
||||
|
||||
d = defaultdict(dict)
|
||||
l_info_required = ["doc", "interface"]
|
||||
l_info_optional = ["ezfio_name"]
|
||||
|
||||
# ~#~#~#~#~#~#~#~#~#~#~ #
|
||||
# L o a d _ C o n f i g #
|
||||
# ~#~#~#~#~#~#~#~#~#~#~ #
|
||||
|
||||
config_file = ConfigParser.ConfigParser()
|
||||
config_file.readfp(open(config_file_path))
|
||||
|
||||
# ~#~#~#~#~#~#~#~#~ #
|
||||
# F i l l _ d i c t #
|
||||
# ~#~#~#~#~#~#~#~#~ #
|
||||
|
||||
def error(o, p, c):
|
||||
"o option ; p provider_name ;c config_file_path"
|
||||
print "You need a {0} for {1} in {2}".format(o, p, c)
|
||||
|
||||
for section in config_file.sections():
|
||||
# pvd = provider
|
||||
pvd = section.lower()
|
||||
|
||||
# Create the dictionary who containt the value per default
|
||||
d_default = {"ezfio_name": pvd}
|
||||
|
||||
# Set the ezfio_dir
|
||||
d[pvd]["ezfio_dir"] = module_lower
|
||||
|
||||
# Check if type if avalaible
|
||||
type_ = config_file.get(section, "type")
|
||||
if type_ not in type_dict:
|
||||
print "{0} not avalaible. Choose in:".format(type_)
|
||||
print ", ".join([i for i in type_dict])
|
||||
sys.exit(1)
|
||||
else:
|
||||
d[pvd]["type"] = type_dict[type_]
|
||||
|
||||
# Fill the dict with REQUIRED information
|
||||
for option in l_info_required:
|
||||
try:
|
||||
d[pvd][option] = config_file.get(section, option)
|
||||
except ConfigParser.NoOptionError:
|
||||
error(option, pvd, config_file_path)
|
||||
sys.exit(1)
|
||||
|
||||
# Fill the dict with OPTIONAL information
|
||||
for option in l_info_optional:
|
||||
try:
|
||||
d[pvd][option] = config_file.get(section, option).lower()
|
||||
except ConfigParser.NoOptionError:
|
||||
d[pvd][option] = d_default[option]
|
||||
|
||||
# If interface is output we need a default value information
|
||||
if d[pvd]["interface"] == "input":
|
||||
try:
|
||||
d[pvd]["default"] = config_file.get(section, "default")
|
||||
except ConfigParser.NoOptionError:
|
||||
error("default", pvd, config_file_path)
|
||||
sys.exit(1)
|
||||
|
||||
return dict(d)
|
||||
|
||||
|
||||
def create_ezfio_provider(dict_ezfio_cfg):
|
||||
"""
|
||||
From dict d[provider_name] = {type,
|
||||
doc,
|
||||
ezfio_name,
|
||||
ezfio_dir,
|
||||
interface,
|
||||
default}
|
||||
create the a list who containt all the code for the provider
|
||||
return [code, ...]
|
||||
"""
|
||||
from ezfio_with_default import EZFIO_Provider
|
||||
|
||||
dict_code_provider = dict()
|
||||
|
||||
ez_p = EZFIO_Provider()
|
||||
for provider_name, dict_info in dict_ezfio_cfg.iteritems():
|
||||
if "default" in dict_info:
|
||||
ez_p.set_type(dict_info['type'].fortran)
|
||||
ez_p.set_name(provider_name)
|
||||
ez_p.set_doc(dict_info['doc'])
|
||||
ez_p.set_ezfio_dir(dict_info['ezfio_dir'])
|
||||
ez_p.set_ezfio_name(dict_info['ezfio_name'])
|
||||
ez_p.set_default(dict_info['default'])
|
||||
ez_p.set_output("output_%s" % dict_info['ezfio_dir'])
|
||||
|
||||
dict_code_provider[provider_name] = str(ez_p)
|
||||
|
||||
return dict_code_provider
|
||||
|
||||
|
||||
def save_ezfio_provider(path_head, dict_code_provider):
|
||||
"""
|
||||
Write in path_head/"ezfio_interface.irp.f" the value of dict_code_provider
|
||||
"""
|
||||
|
||||
path = "{0}/ezfio_interface.irp.f".format(path_head)
|
||||
|
||||
# print "Path = {}".format(path)
|
||||
|
||||
try:
|
||||
f = open(path, "r")
|
||||
except IOError:
|
||||
old_output = ""
|
||||
else:
|
||||
old_output = f.read()
|
||||
f.close()
|
||||
|
||||
output = "! DO NOT MODIFY BY HAND\n" + \
|
||||
"! Created by $QPACKAGE_ROOT/scripts/ezfio_interface.py\n" + \
|
||||
"! from file {0}/EZFIO.cfg\n".format(path_head) + \
|
||||
"\n"
|
||||
for provider_name, code in dict_code_provider.iteritems():
|
||||
output += str(code) + "\n"
|
||||
|
||||
if output != old_output:
|
||||
with open(path, "w") as f:
|
||||
f.write(output)
|
||||
|
||||
|
||||
def create_ezfio_config(dict_ezfio_cfg, opt, module_lower):
|
||||
"""
|
||||
From dict_ezfio_cfg[provider_name] = {type, default, ezfio_name,ezfio_dir,doc}
|
||||
Return the string ezfio_interface_config
|
||||
"""
|
||||
|
||||
result = [module_lower]
|
||||
lenmax = max([len(i) for i in dict_ezfio_cfg]) + 2
|
||||
l = sorted(dict_ezfio_cfg.keys())
|
||||
for provider_name in l:
|
||||
provider_info = dict_ezfio_cfg[provider_name]
|
||||
s = " {0} {1}".format(
|
||||
provider_name.lower().ljust(lenmax),
|
||||
provider_info["type"].fortran)
|
||||
result.append(s)
|
||||
return "\n".join(result)
|
||||
|
||||
|
||||
def save_ezfio_config(module_lower, str_ezfio_config):
|
||||
"""
|
||||
Write the str_ezfio_config in
|
||||
$QPACKAGE_ROOT/EZFIO/{0}.ezfio_interface_config".format(module_lower)
|
||||
"""
|
||||
|
||||
ezfio_dir = "{0}/EZFIO".format(os.environ['QPACKAGE_ROOT'])
|
||||
path = "{0}/config/{1}.ezfio_interface_config".format(ezfio_dir,
|
||||
module_lower)
|
||||
|
||||
# print "Path = {}".format(path)
|
||||
|
||||
try:
|
||||
f = open(path, "r")
|
||||
except IOError:
|
||||
old_output = ""
|
||||
else:
|
||||
old_output = f.read()
|
||||
f.close()
|
||||
|
||||
if str_ezfio_config != old_output:
|
||||
with open(path, "w") as f:
|
||||
f.write(str_ezfio_config)
|
||||
|
||||
|
||||
def main():
|
||||
"""
|
||||
Two condition:
|
||||
-Take the EZFIO.cfg path in arg
|
||||
or
|
||||
-Look if EZFIO.cfg is present in the pwd
|
||||
"""
|
||||
|
||||
try:
|
||||
config_file_path = sys.argv[1]
|
||||
except:
|
||||
config_file_path = "EZFIO.cfg"
|
||||
if "EZFIO.cfg" not in os.listdir(os.getcwd()):
|
||||
sys.exit(0)
|
||||
|
||||
config_file_path = os.path.expanduser(config_file_path)
|
||||
config_file_path = os.path.expandvars(config_file_path)
|
||||
config_file_path = os.path.abspath(config_file_path)
|
||||
# print config_file_path
|
||||
|
||||
path_dirname = os.path.dirname(config_file_path)
|
||||
module = [i for i in path_dirname.split("/") if i][-1]
|
||||
module_lower = module.lower()
|
||||
|
||||
# print "Read {0}".format(config_file_path)
|
||||
dict_info_provider = get_dict_config_file(config_file_path, module_lower)
|
||||
|
||||
# print "Generating the ezfio_interface.irp.f: \n"
|
||||
d_config = create_ezfio_provider(dict_info_provider)
|
||||
|
||||
# print "Saving the ezfio_interface.irp.f"
|
||||
save_ezfio_provider(path_dirname, d_config)
|
||||
|
||||
# print "Generating the ezfio_config"
|
||||
config_ezfio = create_ezfio_config(dict_info_provider, "config", module_lower)
|
||||
|
||||
# print "Saving ezfio_config"
|
||||
save_ezfio_config(module_lower, config_ezfio)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
27
scripts/ezfio_interface/convert_ezfio.sh
Executable file
27
scripts/ezfio_interface/convert_ezfio.sh
Executable file
@ -0,0 +1,27 @@
|
||||
#!/bin/bash
|
||||
# Convert a old ezfio file (with option.irp.f ezfio_default)
|
||||
# into a new EZFIO.cfg type
|
||||
|
||||
# Hartree Fock
|
||||
# Changin the case, don't know if is needed or not
|
||||
mv $1/Hartree_Fock $1/hartree_fock 2> /dev/null
|
||||
|
||||
mv $1/hartree_Fock/thresh_SCF $1/hartree_fock/thresh_scf 2> /dev/null
|
||||
|
||||
# BiInts
|
||||
mv $1/bi_integrals $1/bielect_integrals 2> /dev/null
|
||||
|
||||
if [ -f $1/bielect_integrals/read_ao_integrals ]; then
|
||||
if [ `cat $1/bielect_integrals/read_ao_integrals` -eq "True" ]
|
||||
then
|
||||
echo "Read" > $1/bielect_integrals/disk_access_ao_integrals
|
||||
|
||||
elif [ `cat bielect_integrals/write_ao_integrals` -eq "True" ]
|
||||
then
|
||||
echo "Write" > $1/bielect_integrals/disk_access_ao_integrals
|
||||
|
||||
else
|
||||
echo "None" > $1/bielect_integrals/disk_access_ao_integrals
|
||||
|
||||
fi
|
||||
fi
|
823
scripts/ezfio_interface/ei_handler.py
Executable file
823
scripts/ezfio_interface/ei_handler.py
Executable file
@ -0,0 +1,823 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Welcom the ei_handler.
|
||||
We will create all the ezfio related stuff from a EZFIO.cfg file.
|
||||
|
||||
Usage:
|
||||
ei_handler.py [--path] [--irpf90] [--ezfio_config] [--ocaml] [--ezfio_default] [--global]
|
||||
|
||||
By default all the option are executed.
|
||||
|
||||
Options:
|
||||
-h --help
|
||||
--path The path of the `EZFIO.cfg`, by default will look in the ${pwd}
|
||||
--irpf90 Create the `ezfio_interface.irpf90`
|
||||
which contains all the providers needed
|
||||
(aka all with the `interface: input` parameter)
|
||||
in `${pwd}`
|
||||
--ezfio_config Create the `${module_lower}_ezfio_interface_config` in
|
||||
`${QPACKAGE_ROOT}/EZFIO/config/`
|
||||
This file is needed by *EZFIO* to create the `libezfio.so`
|
||||
--ocaml Create the `Input_module.lower.ml` for the *qp_edit*
|
||||
--ezfio_default Create the `${module_lower}_ezfio_interface_default` in
|
||||
`${QPACKAGE_ROOT}/data/ezfio_defaults` needed by
|
||||
the ocaml
|
||||
--global Create all the stuff who need all the EZFIO.cfg
|
||||
|
||||
Format specification :
|
||||
[provider_name] | the name of the provider in irp.f90
|
||||
doc:{str} | Is the doc
|
||||
Type:{str} | Is a fancy_type supported by the ocaml
|
||||
ezfio_name:{str} | Will be the name of the file for the ezfio
|
||||
(optional by default is the name of the provider)
|
||||
interface:{str} | The provider is a imput or a output
|
||||
default:{str} | The default value if interface == input:
|
||||
size:{str} | the size information
|
||||
(like 1 or =sum(ao_num) or (ao_num,3) )
|
||||
|
||||
Example of EZFIO.cfg:
|
||||
```
|
||||
[thresh_SCF]
|
||||
doc: Threshold on the convergence of the Hartree Fock energy
|
||||
type: Threshold
|
||||
default: 1.e-10
|
||||
interface: input
|
||||
size: 1
|
||||
|
||||
[energy]
|
||||
type: double precision
|
||||
doc: Calculated HF energy
|
||||
interface: output
|
||||
```
|
||||
"""
|
||||
from docopt import docopt
|
||||
|
||||
import sys
|
||||
import os
|
||||
import os.path
|
||||
|
||||
import ConfigParser
|
||||
|
||||
from collections import defaultdict
|
||||
from collections import namedtuple
|
||||
|
||||
Type = namedtuple('Type', 'fancy ocaml fortran')
|
||||
|
||||
|
||||
def is_bool(str_):
|
||||
"""
|
||||
Take a string, if is a bool return the conversion into
|
||||
fortran and ocaml.
|
||||
"""
|
||||
if str_.lower() in ['true', '.true.']:
|
||||
return Type(None, "true", ".True.")
|
||||
elif str_.lower() in ['false', '.false.']:
|
||||
return Type(None, "false", ".False")
|
||||
else:
|
||||
raise TypeError
|
||||
|
||||
|
||||
def get_type_dict():
|
||||
"""
|
||||
This function makes the correspondance between the type of value read in
|
||||
ezfio.cfg into the f90 and Ocaml Type
|
||||
return fancy_type[fancy_type] = namedtuple('Type', 'ocaml fortran')
|
||||
For example fancy_type['Ndet'].fortran = interger
|
||||
.ocaml = int
|
||||
"""
|
||||
# ~#~#~#~#~ #
|
||||
# P i c l e #
|
||||
# ~#~#~#~#~ #
|
||||
|
||||
import cPickle as pickle
|
||||
|
||||
from os import listdir
|
||||
|
||||
qpackage_root = os.environ['QPACKAGE_ROOT']
|
||||
fancy_type_pickle = qpackage_root + "/scripts/ezfio_interface/fancy_type.p"
|
||||
|
||||
if fancy_type_pickle in listdir(os.getcwd()):
|
||||
fancy_type = pickle.load(open(fancy_type_pickle, "rb"))
|
||||
return fancy_type
|
||||
|
||||
# ~#~#~#~ #
|
||||
# I n i t #
|
||||
# ~#~#~#~ #
|
||||
|
||||
fancy_type = defaultdict(dict)
|
||||
|
||||
# ~#~#~#~#~#~#~#~ #
|
||||
# R a w _ t y p e #
|
||||
# ~#~#~#~#~#~#~#~ #
|
||||
|
||||
fancy_type['integer'] = Type(None, "int", "integer")
|
||||
fancy_type['int'] = Type(None, "int", "integer")
|
||||
|
||||
fancy_type['float'] = Type(None, "float", "double precision")
|
||||
fancy_type['double precision'] = Type(None, "float", "double precision")
|
||||
|
||||
fancy_type['logical'] = Type(None, "bool", "logical")
|
||||
fancy_type['bool'] = Type(None, "bool", "logical")
|
||||
|
||||
fancy_type['character*(32)'] = Type(None, "string", "character*(32)")
|
||||
fancy_type['character*(60)'] = Type(None, "string", "character*(60)")
|
||||
fancy_type['character*(256)'] = Type(None, "string", "character*(256)")
|
||||
|
||||
# ~#~#~#~#~#~#~#~ #
|
||||
# q p _ t y p e s #
|
||||
# ~#~#~#~#~#~#~#~ #
|
||||
|
||||
# Dict to change ocaml LowLevel type into FortranLowLevel type
|
||||
ocaml_to_fortran = {"int": "integer",
|
||||
"float": "double precision",
|
||||
"logical": "logical",
|
||||
"string": "character*32"}
|
||||
|
||||
# Read and parse qptype generate
|
||||
src = qpackage_root + "/ocaml/qptypes_generator.ml"
|
||||
with open(src, "r") as f:
|
||||
r = f.read()
|
||||
|
||||
# Generate
|
||||
l_gen = [i for i in r.splitlines() if i.strip().startswith("*")]
|
||||
|
||||
# Untouch
|
||||
b = r.find('let untouched = "')
|
||||
e = r.find(';;', b)
|
||||
|
||||
l_un = [
|
||||
i for i in r[
|
||||
b:e].splitlines() if i.strip().startswith("module")]
|
||||
|
||||
# ~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~ #
|
||||
# q p _ t y p e s _ g e n e r a t e #
|
||||
# ~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~ #
|
||||
|
||||
# Read the fancy_type, the ocaml. and convert the ocaml to the fortran
|
||||
for i in l_gen + l_un:
|
||||
str_fancy_type = i.split()[1].strip()
|
||||
str_ocaml_type = i.split()[3]
|
||||
|
||||
if str_ocaml_type != 'sig':
|
||||
str_fortran_type = ocaml_to_fortran[str_ocaml_type]
|
||||
else:
|
||||
str_fortran_type = 'character*(32)'
|
||||
str_ocaml_type = 'string'
|
||||
|
||||
fancy_type[str_fancy_type] = Type(str_fancy_type,
|
||||
str_ocaml_type,
|
||||
str_fortran_type)
|
||||
|
||||
# ~#~#~#~#~#~#~#~ #
|
||||
# F i n a l i z e #
|
||||
# ~#~#~#~#~#~#~#~ #
|
||||
|
||||
pickle.dump(dict(fancy_type), open(fancy_type_pickle, "wb"))
|
||||
|
||||
return dict(fancy_type)
|
||||
|
||||
|
||||
type_dict = get_type_dict()
|
||||
|
||||
|
||||
def get_dict_config_file(config_file_path, module_lower):
|
||||
"""
|
||||
Input:
|
||||
config_file_path is the config file path
|
||||
(for example FULL_PATH/EZFIO.cfg)
|
||||
module_lower is the MODULE name lowered
|
||||
(Ex fullci)
|
||||
|
||||
Return a dict d[provider_name] = {type,
|
||||
doc,
|
||||
ezfio_name,
|
||||
ezfio_dir,
|
||||
size,
|
||||
interface,
|
||||
default}
|
||||
|
||||
- Type : Is a Type named tuple who containt
|
||||
fortran and ocaml type
|
||||
- doc : Is the doc
|
||||
- ezfio_name : Will be the name of the file
|
||||
- ezfio_dir : Will be the folder who containt the ezfio_name
|
||||
* /ezfio_dir/ezfio_name
|
||||
* equal to MODULE_lower name for the moment.
|
||||
- interface : The provider is a imput or a output
|
||||
- default : The default value /!\ stored in a Type named type!
|
||||
if interface == output
|
||||
- size : Is the string read in ezfio.cgf who containt the size information
|
||||
(like 1 or =sum(ao_num))
|
||||
"""
|
||||
# ~#~#~#~ #
|
||||
# I n i t #
|
||||
# ~#~#~#~ #
|
||||
|
||||
d = defaultdict(dict)
|
||||
l_info_required = ["doc", "interface"]
|
||||
l_info_optional = ["ezfio_name", "size"]
|
||||
|
||||
# ~#~#~#~#~#~#~#~#~#~#~ #
|
||||
# L o a d _ C o n f i g #
|
||||
# ~#~#~#~#~#~#~#~#~#~#~ #
|
||||
|
||||
config_file = ConfigParser.ConfigParser()
|
||||
config_file.readfp(open(config_file_path))
|
||||
|
||||
# ~#~#~#~#~#~#~#~#~ #
|
||||
# F i l l _ d i c t #
|
||||
# ~#~#~#~#~#~#~#~#~ #
|
||||
|
||||
def error(o, p, c):
|
||||
"o option ; p provider_name ;c config_file_path"
|
||||
print "You need a {0} for {1} in {2}".format(o, p, c)
|
||||
|
||||
for section in config_file.sections():
|
||||
# pvd = provider
|
||||
pvd = section.lower()
|
||||
|
||||
# Create the dictionary who containt the value per default
|
||||
d_default = {"ezfio_name": pvd}
|
||||
|
||||
# Set the ezfio_dir
|
||||
d[pvd]["ezfio_dir"] = module_lower
|
||||
|
||||
# Check if type if avalaible
|
||||
type_ = config_file.get(section, "type")
|
||||
if type_ not in type_dict:
|
||||
print "{0} not avalaible. Choose in:".format(type_)
|
||||
print ", ".join(sorted([i for i in type_dict]))
|
||||
sys.exit(1)
|
||||
else:
|
||||
d[pvd]["type"] = type_dict[type_]
|
||||
|
||||
# Fill the dict with REQUIRED information
|
||||
for option in l_info_required:
|
||||
try:
|
||||
d[pvd][option] = config_file.get(section, option)
|
||||
except ConfigParser.NoOptionError:
|
||||
error(option, pvd, config_file_path)
|
||||
sys.exit(1)
|
||||
|
||||
# Fill the dict with OPTIONAL information
|
||||
for option in l_info_optional:
|
||||
try:
|
||||
d[pvd][option] = config_file.get(section, option).lower()
|
||||
except ConfigParser.NoOptionError:
|
||||
if option in d_default:
|
||||
d[pvd][option] = d_default[option]
|
||||
|
||||
# If interface is input we need a default value information
|
||||
if d[pvd]["interface"] == "input":
|
||||
try:
|
||||
default_raw = config_file.get(section, "default")
|
||||
except ConfigParser.NoOptionError:
|
||||
error("default", pvd, config_file_path)
|
||||
sys.exit(1)
|
||||
|
||||
try:
|
||||
d[pvd]["default"] = is_bool(default_raw)
|
||||
except TypeError:
|
||||
d[pvd]["default"] = Type(None, default_raw, default_raw)
|
||||
|
||||
return dict(d)
|
||||
|
||||
|
||||
def create_ezfio_provider(dict_ezfio_cfg):
|
||||
"""
|
||||
From dict d[provider_name] = {type,
|
||||
doc,
|
||||
ezfio_name,
|
||||
ezfio_dir,
|
||||
interface,
|
||||
default
|
||||
size}
|
||||
create the a list who containt all the code for the provider
|
||||
return [code, ...]
|
||||
"""
|
||||
from ezfio_generate_provider import EZFIO_Provider
|
||||
dict_code_provider = dict()
|
||||
|
||||
ez_p = EZFIO_Provider()
|
||||
for provider_name, dict_info in dict_ezfio_cfg.iteritems():
|
||||
if "default" in dict_info:
|
||||
ez_p.set_type(dict_info['type'].fortran)
|
||||
ez_p.set_name(provider_name)
|
||||
ez_p.set_doc(dict_info['doc'])
|
||||
ez_p.set_ezfio_dir(dict_info['ezfio_dir'])
|
||||
ez_p.set_ezfio_name(dict_info['ezfio_name'])
|
||||
ez_p.set_output("output_%s" % dict_info['ezfio_dir'])
|
||||
|
||||
dict_code_provider[provider_name] = str(ez_p) + "\n"
|
||||
|
||||
return dict_code_provider
|
||||
|
||||
|
||||
def save_ezfio_provider(path_head, dict_code_provider):
|
||||
"""
|
||||
Write in path_head/"ezfio_interface.irp.f" the value of dict_code_provider
|
||||
"""
|
||||
|
||||
path = "{0}/ezfio_interface.irp.f".format(path_head)
|
||||
|
||||
try:
|
||||
f = open(path, "r")
|
||||
except IOError:
|
||||
old_output = ""
|
||||
else:
|
||||
old_output = f.read()
|
||||
f.close()
|
||||
|
||||
l_output = ["! DO NOT MODIFY BY HAND",
|
||||
"! Created by $QPACKAGE_ROOT/scripts/ezfio_interface.py",
|
||||
"! from file {0}/EZFIO.cfg".format(path_head),
|
||||
"\n"]
|
||||
|
||||
l_output += [code for code in dict_code_provider.values()]
|
||||
|
||||
output = "\n".join(l_output)
|
||||
|
||||
if output != old_output:
|
||||
with open(path, "w+") as f:
|
||||
f.write(output)
|
||||
|
||||
|
||||
def create_ezfio_stuff(dict_ezfio_cfg, config_or_default="config"):
|
||||
"""
|
||||
From dict_ezfio_cfg[provider_name] = {type, default, ezfio_name,ezfio_dir,doc}
|
||||
Return the string ezfio_interface_config
|
||||
"""
|
||||
|
||||
def size_format_to_ezfio(size_raw):
|
||||
"""
|
||||
If size_raw == "=" is a formula -> do nothing; return
|
||||
If the value are between parenthses -> do nothing; return
|
||||
Else put it in parenthsesis
|
||||
"""
|
||||
|
||||
size_raw = str(size_raw)
|
||||
if any([size_raw.startswith('='),
|
||||
size_raw.startswith("(") and size_raw.endswith(")")]):
|
||||
size_convert = size_raw
|
||||
else:
|
||||
size_convert = "({0})".format(size_raw)
|
||||
return size_convert
|
||||
|
||||
def create_format_string(size):
|
||||
"""
|
||||
Take a size number and
|
||||
return the string format for being right align with this offset
|
||||
"""
|
||||
return "{{0:<{0}}}".format(size).format
|
||||
|
||||
# ~#~#~#~#~#~#~#~#~#~#~# #
|
||||
# F o r m a t _ i n f o #
|
||||
# ~#~#~#~#~#~#~#~#~#~#~# #
|
||||
|
||||
lenmax_name = max([len(i) for i in dict_ezfio_cfg])
|
||||
lenmax_type = max([len(i["type"].fortran)
|
||||
for i in dict_ezfio_cfg.values()])
|
||||
|
||||
str_name_format = create_format_string(lenmax_name + 2)
|
||||
str_type_format = create_format_string(lenmax_type + 2)
|
||||
|
||||
# ~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~# #
|
||||
# C r e a t e _ t h e _ s t r i n g #
|
||||
# ~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~# #
|
||||
|
||||
# Checking is many ezfio_dir provided
|
||||
l_ezfio_dir = [d['ezfio_dir'] for d in dict_ezfio_cfg.values()]
|
||||
|
||||
if not l_ezfio_dir.count(l_ezfio_dir[0]) == len(l_ezfio_dir):
|
||||
print >> sys.stderr, "You have many ezfio_dir. Not supported yet"
|
||||
raise TypeError
|
||||
else:
|
||||
result = [l_ezfio_dir[0]]
|
||||
|
||||
for provider_name, provider_info in sorted(dict_ezfio_cfg.iteritems()):
|
||||
|
||||
# Get the value from dict
|
||||
name_raw = provider_info["ezfio_name"].lower()
|
||||
|
||||
fortran_type_raw = provider_info["type"].fortran
|
||||
|
||||
if "size" in provider_info and not provider_info["size"] == "1":
|
||||
size_raw = provider_info["size"]
|
||||
else:
|
||||
size_raw = None
|
||||
|
||||
# It is the last so we don't need to right align it
|
||||
str_size = size_format_to_ezfio(size_raw) if size_raw else ""
|
||||
|
||||
# Get the string in to good format (left align and co)
|
||||
str_name = str_name_format(name_raw)
|
||||
str_fortran_type = str_type_format(fortran_type_raw)
|
||||
|
||||
# Return the string
|
||||
if config_or_default == "config":
|
||||
s = " {0} {1} {2}".format(str_name, str_fortran_type, str_size)
|
||||
elif config_or_default == "default":
|
||||
try:
|
||||
str_value = provider_info["default"].ocaml
|
||||
except KeyError:
|
||||
continue
|
||||
else:
|
||||
s = " {0} {1}".format(str_name, str_value)
|
||||
else:
|
||||
raise KeyError
|
||||
# Append
|
||||
result.append(s)
|
||||
|
||||
return "\n".join(result)
|
||||
|
||||
|
||||
def create_ezfio_config(dict_ezfio_cfg):
|
||||
return create_ezfio_stuff(dict_ezfio_cfg,
|
||||
config_or_default="config")
|
||||
|
||||
|
||||
def save_ezfio_config(module_lower, str_ezfio_config):
|
||||
"""
|
||||
Write the str_ezfio_config in
|
||||
"$QPACKAGE_ROOT/EZFIO/{0}.ezfio_interface_config".format(module_lower)
|
||||
"""
|
||||
|
||||
root_ezfio = "{0}/EZFIO".format(os.environ['QPACKAGE_ROOT'])
|
||||
path = "{0}/config/{1}.ezfio_interface_config".format(root_ezfio,
|
||||
module_lower)
|
||||
|
||||
try:
|
||||
f = open(path, "r")
|
||||
except IOError:
|
||||
old_output = ""
|
||||
else:
|
||||
old_output = f.read()
|
||||
f.close()
|
||||
|
||||
if str_ezfio_config != old_output:
|
||||
with open(path, "w+") as f:
|
||||
f.write(str_ezfio_config)
|
||||
|
||||
|
||||
def create_ezfio_default(dict_ezfio_cfg):
|
||||
return create_ezfio_stuff(dict_ezfio_cfg,
|
||||
config_or_default="default")
|
||||
|
||||
|
||||
def save_ezfio_default(module_lower, str_ezfio_default):
|
||||
"""
|
||||
Write the str_ezfio_config in
|
||||
"$QPACKAGE_ROOT/data/ezfio_defaults/{0}.ezfio_interface_default".format(module_lower)
|
||||
"""
|
||||
|
||||
root_ezfio_default = "{0}/data/ezfio_defaults/".format(
|
||||
os.environ['QPACKAGE_ROOT'])
|
||||
path = "{0}/{1}.ezfio_interface_default".format(root_ezfio_default,
|
||||
module_lower)
|
||||
|
||||
try:
|
||||
f = open(path, "r")
|
||||
except IOError:
|
||||
old_output = ""
|
||||
else:
|
||||
old_output = f.read()
|
||||
f.close()
|
||||
|
||||
if str_ezfio_default != old_output:
|
||||
with open(path, "w+") as f:
|
||||
f.write(str_ezfio_default)
|
||||
|
||||
|
||||
def create_ocaml_input(dict_ezfio_cfg, module_lower):
|
||||
|
||||
# ~#~#~#~# #
|
||||
# I n i t #
|
||||
# ~#~#~#~# #
|
||||
|
||||
from ezfio_generate_ocaml import EZFIO_ocaml
|
||||
|
||||
l_ezfio_name = []
|
||||
l_type = []
|
||||
l_doc = []
|
||||
|
||||
for k, v in dict_ezfio_cfg.iteritems():
|
||||
if v['interface'] == "input":
|
||||
l_ezfio_name.append(v['ezfio_name'])
|
||||
l_type.append(v["type"])
|
||||
l_doc.append(v["doc"])
|
||||
|
||||
if not l_ezfio_name:
|
||||
raise ValueError
|
||||
|
||||
e_glob = EZFIO_ocaml(l_ezfio_name=l_ezfio_name,
|
||||
l_type=l_type,
|
||||
l_doc=l_doc)
|
||||
|
||||
# ~#~#~#~#~#~#~#~# #
|
||||
# C r e a t i o n #
|
||||
# ~#~#~#~#~#~#~#~# #
|
||||
|
||||
template = ['(* =~=~ *)',
|
||||
'(* Init *)',
|
||||
'(* =~=~ *)',
|
||||
""]
|
||||
|
||||
template += ["open Qptypes;;",
|
||||
"open Qputils;;",
|
||||
"open Core.Std;;",
|
||||
"",
|
||||
"module {0} : sig".format(module_lower.capitalize())]
|
||||
|
||||
template += [e_glob.create_type()]
|
||||
|
||||
template += [" val read : unit -> t option",
|
||||
" val write : t-> unit",
|
||||
" val to_string : t -> string",
|
||||
" val to_rst : t -> Rst_string.t",
|
||||
" val of_rst : Rst_string.t -> t option",
|
||||
"end = struct"]
|
||||
|
||||
template += [e_glob.create_type()]
|
||||
|
||||
template += ['',
|
||||
' let get_default = Qpackage.get_ezfio_default "{0}";;'.format(module_lower),
|
||||
'']
|
||||
|
||||
template += ['(* =~=~=~=~=~=~==~=~=~=~=~=~ *)',
|
||||
'(* Generate Special Function *)',
|
||||
'(* =~=~=~==~=~~=~=~=~=~=~=~=~ *)',
|
||||
""]
|
||||
|
||||
for provider_name, d_val in sorted(dict_ezfio_cfg.iteritems()):
|
||||
|
||||
if 'default' not in d_val:
|
||||
continue
|
||||
|
||||
ezfio_dir = d_val["ezfio_dir"]
|
||||
ezfio_name = d_val["ezfio_name"]
|
||||
|
||||
e = EZFIO_ocaml(ezfio_dir=ezfio_dir,
|
||||
ezfio_name=ezfio_name,
|
||||
type=d_val["type"])
|
||||
|
||||
template += [e.create_read(),
|
||||
e.create_write(),
|
||||
""]
|
||||
|
||||
template += ['(* =~=~=~=~=~=~=~=~=~=~=~=~ *)',
|
||||
'(* Generate Global Function *)',
|
||||
'(* =~=~=~=~=~=~=~=~=~=~=~=~ *)',
|
||||
""]
|
||||
|
||||
template += [e_glob.create_read_global(),
|
||||
e_glob.create_write_global(),
|
||||
e_glob.create_to_string(),
|
||||
e_glob.create_to_rst()]
|
||||
|
||||
template += [" include Generic_input_of_rst;;",
|
||||
" let of_rst = of_rst t_of_sexp;;",
|
||||
"",
|
||||
"end"]
|
||||
|
||||
return "\n".join(template)
|
||||
|
||||
|
||||
def save_ocaml_input(module_lower, str_ocaml_input):
|
||||
"""
|
||||
Write the str_ocaml_input in
|
||||
$QPACKAGE_ROOT/ocaml/Input_{0}.ml".format(module_lower)
|
||||
"""
|
||||
|
||||
path = "{0}/ocaml/Input_{1}.ml".format(os.environ['QPACKAGE_ROOT'],
|
||||
module_lower)
|
||||
|
||||
try:
|
||||
f = open(path, "r")
|
||||
except IOError:
|
||||
old_output = ""
|
||||
else:
|
||||
old_output = f.read()
|
||||
f.close()
|
||||
|
||||
if str_ocaml_input != old_output:
|
||||
with open(path, "w+") as f:
|
||||
f.write(str_ocaml_input)
|
||||
|
||||
|
||||
def get_l_module_lower():
|
||||
"""
|
||||
Get all module who have EZFIO.cfg with input data
|
||||
(NB `search` in all the ligne and `match` only in one)
|
||||
"""
|
||||
|
||||
# ~#~#~#~ #
|
||||
# I n i t #
|
||||
# ~#~#~#~ #
|
||||
|
||||
mypath = "{0}/src".format(os.environ['QPACKAGE_ROOT'])
|
||||
|
||||
# ~#~#~#~#~#~#~#~ #
|
||||
# L _ f o l d e r #
|
||||
# ~#~#~#~#~#~#~#~ #
|
||||
|
||||
from os import listdir
|
||||
from os.path import isdir, join, exists
|
||||
|
||||
l_folder = [f for f in listdir(mypath) if isdir(join(mypath, f))]
|
||||
|
||||
# ~#~#~#~#~#~#~#~#~#~#~#~#~#~ #
|
||||
# L _ m o d u l e _ l o w e r #
|
||||
# ~#~#~#~#~#~#~#~#~#~#~#~#~#~ #
|
||||
|
||||
l_module_lower = []
|
||||
import re
|
||||
p = re.compile(ur'interface:\s+input')
|
||||
|
||||
for f in l_folder:
|
||||
path = "{0}/{1}/EZFIO.cfg".format(mypath, f)
|
||||
if exists(path):
|
||||
with open(path, 'r') as file_:
|
||||
if p.search(file_.read()):
|
||||
l_module_lower.append(f.lower())
|
||||
|
||||
# ~#~#~#~#~#~ #
|
||||
# R e t u r n #
|
||||
# ~#~#~#~#~#~ #
|
||||
|
||||
return l_module_lower
|
||||
|
||||
|
||||
def create_ocaml_input_global():
|
||||
"""
|
||||
Check for all the EZFIO.cfg get the module lower
|
||||
then create incule {module_lower}.ml
|
||||
"""
|
||||
|
||||
# ~#~#~#~# #
|
||||
# I n i t #
|
||||
# ~#~#~#~# #
|
||||
|
||||
l_module_lower = get_l_module_lower()
|
||||
|
||||
# ~#~#~#~#~#~#~#~# #
|
||||
# C r e a t i o n #
|
||||
# ~#~#~#~#~#~#~#~# #
|
||||
|
||||
from ezfio_generate_ocaml import EZFIO_ocaml
|
||||
|
||||
qpackage_root = os.environ['QPACKAGE_ROOT']
|
||||
path = qpackage_root + "/scripts/ezfio_interface/qp_edit_template"
|
||||
|
||||
with open(path, "r") as f:
|
||||
template_raw = f.read()
|
||||
|
||||
e = EZFIO_ocaml(l_module_lower=l_module_lower)
|
||||
|
||||
template = template_raw.format(keywords=e.create_qp_keywords(),
|
||||
keywords_to_string=e.create_qp_keywords_to_string(),
|
||||
section_to_rst=e.create_qp_section_to_rst(),
|
||||
write=e.create_qp_write(),
|
||||
tasks=e.create_qp_tasks())
|
||||
|
||||
input_auto = e.create_input_auto_generated()
|
||||
|
||||
return (template, input_auto)
|
||||
|
||||
|
||||
def save_ocaml_input_auto(str_ocaml_input_global):
|
||||
"""
|
||||
Write the str_ocaml_input in
|
||||
$QPACKAGE_ROOT/ocaml/Input_auto_generated.ml
|
||||
"""
|
||||
|
||||
path = "{0}/ocaml/Input_auto_generated.ml".format(os.environ['QPACKAGE_ROOT'])
|
||||
|
||||
try:
|
||||
f = open(path, "r")
|
||||
except IOError:
|
||||
old_output = ""
|
||||
else:
|
||||
old_output = f.read()
|
||||
f.close()
|
||||
|
||||
if str_ocaml_input_global != old_output:
|
||||
with open(path, "w+") as f:
|
||||
f.write(str_ocaml_input_global)
|
||||
|
||||
|
||||
def save_ocaml_qp_edit(str_ocaml_qp_edit):
|
||||
"""
|
||||
Write the str_ocaml_qp_edit in
|
||||
$QPACKAGE_ROOT/ocaml/qp_edit.ml
|
||||
"""
|
||||
|
||||
path = "{0}/ocaml/qp_edit.ml".format(os.environ['QPACKAGE_ROOT'])
|
||||
|
||||
try:
|
||||
f = open(path, "r")
|
||||
except IOError:
|
||||
old_output = ""
|
||||
else:
|
||||
old_output = f.read()
|
||||
f.close()
|
||||
|
||||
if str_ocaml_qp_edit != old_output:
|
||||
with open(path, "w+") as f:
|
||||
f.write(str_ocaml_qp_edit)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
arguments = docopt(__doc__)
|
||||
|
||||
# ___
|
||||
# | ._ o _|_
|
||||
# _|_ | | | |_
|
||||
#
|
||||
|
||||
if not arguments["--global"]:
|
||||
if not arguments["--path"]:
|
||||
config_file_path = "EZFIO.cfg"
|
||||
if "EZFIO.cfg" not in os.listdir(os.getcwd()):
|
||||
sys.exit(0)
|
||||
else:
|
||||
config_file_path = arguments["path"]
|
||||
|
||||
# Get the full path
|
||||
config_file_path = os.path.expanduser(config_file_path)
|
||||
config_file_path = os.path.expandvars(config_file_path)
|
||||
config_file_path = os.path.abspath(config_file_path)
|
||||
|
||||
# ~#~#~#~#~#~#~#~#~#~#~#~#~#~# #
|
||||
# G e t _ m o d u l e _ d i r #
|
||||
# ~#~#~#~#~#~#~#~#~#~#~#~#~#~# #
|
||||
|
||||
path_dirname = os.path.dirname(config_file_path)
|
||||
module = [i for i in path_dirname.split("/") if i][-1]
|
||||
module_lower = module.lower()
|
||||
|
||||
# Because we only authorise this right now!
|
||||
ezfio_dir = module_lower
|
||||
dict_ezfio_cfg = get_dict_config_file(config_file_path, ezfio_dir)
|
||||
|
||||
# _
|
||||
# / _ _| _ _ _ ._ _ ._ _. _|_ o _ ._
|
||||
# \_ (_) (_| (/_ (_| (/_ | | (/_ | (_| |_ | (_) | |
|
||||
# _|
|
||||
|
||||
# ~#~#~#~#~#~#~#~#~#~ #
|
||||
# W h a t _ t o _ d o #
|
||||
# ~#~#~#~#~#~#~#~#~#~ #
|
||||
if any([arguments[i] for i in ["--irpf90",
|
||||
"--ezfio_config",
|
||||
"--ocaml",
|
||||
"--ezfio_default",
|
||||
"--global"]]):
|
||||
# User changer somme argument, do what he want
|
||||
do_all = False
|
||||
else:
|
||||
# Do all the stuff
|
||||
do_all = True
|
||||
|
||||
# ~#~#~#~#~#~#~ #
|
||||
# I R P . f 9 0 #
|
||||
# ~#~#~#~#~#~#~ #
|
||||
|
||||
if do_all or arguments["--irpf90"]:
|
||||
l_str_code = create_ezfio_provider(dict_ezfio_cfg)
|
||||
save_ezfio_provider(path_dirname, l_str_code)
|
||||
|
||||
# ~#~#~#~#~#~#~#~#~#~#~#~ #
|
||||
# e z f i o _ c o n f i g #
|
||||
# ~#~#~#~#~#~#~#~#~#~#~#~ #
|
||||
|
||||
if do_all or arguments["--ezfio_config"]:
|
||||
str_ezfio_config = create_ezfio_config(dict_ezfio_cfg)
|
||||
save_ezfio_config(module_lower, str_ezfio_config)
|
||||
|
||||
# ~#~#~#~#~#~#
|
||||
# O c a m l #
|
||||
# ~#~#~#~#~#~#
|
||||
if do_all or arguments["--ocaml"]:
|
||||
try:
|
||||
str_ocaml_input = create_ocaml_input(dict_ezfio_cfg, module_lower)
|
||||
except ValueError:
|
||||
pass
|
||||
else:
|
||||
save_ocaml_input(module_lower, str_ocaml_input)
|
||||
|
||||
# ~#~#~#~#~#~#~#~#~#~#~#~#~ #
|
||||
# e z f i o _ d e f a u l t #
|
||||
# ~#~#~#~#~#~#~#~#~#~#~#~#~ #
|
||||
if do_all or arguments["--ezfio_default"]:
|
||||
str_ezfio_default = create_ezfio_default(dict_ezfio_cfg)
|
||||
save_ezfio_default(module_lower, str_ezfio_default)
|
||||
|
||||
# ~#~#~#~#~#~#~#~#~#~#~#~#~ #
|
||||
# e z f i o _ d e f a u l t #
|
||||
# ~#~#~#~#~#~#~#~#~#~#~#~#~ #
|
||||
|
||||
if do_all or arguments["--global"]:
|
||||
str_ocaml_qp_edit, str_ocaml_input_auto = create_ocaml_input_global()
|
||||
save_ocaml_input_auto(str_ocaml_input_auto)
|
||||
save_ocaml_qp_edit(str_ocaml_qp_edit)
|
483
scripts/ezfio_interface/ezfio_generate_ocaml.py
Executable file
483
scripts/ezfio_interface/ezfio_generate_ocaml.py
Executable file
@ -0,0 +1,483 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import sys
|
||||
import os
|
||||
|
||||
# If type in **kwargs
|
||||
from ei_handler import Type
|
||||
|
||||
|
||||
class EZFIO_ocaml(object):
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
|
||||
for k, v in kwargs.iteritems():
|
||||
|
||||
try:
|
||||
exec "self.{0} = {1}".format(k, v)
|
||||
except NameError:
|
||||
exec "self.{0} = '{1}'".format(k, v)
|
||||
|
||||
@property
|
||||
def Ocaml_type(self):
|
||||
return self.type.ocaml.capitalize()
|
||||
|
||||
@property
|
||||
def ocaml_type(self):
|
||||
return self.type.ocaml
|
||||
|
||||
@property
|
||||
def fancy_type(self):
|
||||
return self.type.fancy
|
||||
|
||||
def check_if_init(self, l_arg, name):
|
||||
for i in l_arg:
|
||||
try:
|
||||
exec "self.{0}".format(i)
|
||||
except AttributeError:
|
||||
msg = "You need to provide a '{0}' for creating {1}"
|
||||
raise KeyError(msg.format(i, name))
|
||||
|
||||
def create_read(self):
|
||||
'''
|
||||
You need to instantiate the EZFIO_ocaml with this keyword argument
|
||||
ezfio_dir = str
|
||||
ezfio_name = str
|
||||
type = Named_tuple(fancy_type, ocaml_type, fortrant_type)
|
||||
|
||||
Return the read template
|
||||
'''
|
||||
|
||||
# ~#~#~#~#~#~#~#~ #
|
||||
# C h e c k i n g #
|
||||
# ~#~#~#~#~#~#~#~ #
|
||||
|
||||
self.check_if_init(["ezfio_dir", "ezfio_name", "type"],
|
||||
sys._getframe().f_code.co_name)
|
||||
|
||||
# ~#~#~#~#~#~#~#~#~#~#~#~#~#~# #
|
||||
# C r e a t e _ t e m pl a t e #
|
||||
# ~#~#~#~#~#~#~#~#~#~#~#~#~#~# #
|
||||
|
||||
l_template = [
|
||||
'(* Read snippet for {self.ezfio_name} *)',
|
||||
'let read_{self.ezfio_name} () =',
|
||||
' if not (Ezfio.has_{self.ezfio_dir}_{self.ezfio_name} ()) then',
|
||||
' get_default "{self.ezfio_name}"',
|
||||
' |> {self.Ocaml_type}.of_string',
|
||||
' |> Ezfio.set_{self.ezfio_dir}_{self.ezfio_name}',
|
||||
' ;',
|
||||
' Ezfio.get_{self.ezfio_dir}_{self.ezfio_name} ()']
|
||||
|
||||
if self.fancy_type:
|
||||
l_template += [" |> {self.fancy_type}.of_{self.ocaml_type}"]
|
||||
|
||||
l_template += [";;"]
|
||||
|
||||
template = "\n ".join(l_template)
|
||||
|
||||
# ~#~#~#~#~#~ #
|
||||
# R e n d e r #
|
||||
# ~#~#~#~#~#~ #
|
||||
|
||||
template_rendered = template.format(**locals())
|
||||
|
||||
# ~#~#~#~#~#~ #
|
||||
# R e t u r n #
|
||||
# ~#~#~#~#~#~ #
|
||||
return template_rendered
|
||||
|
||||
def create_write(self):
|
||||
'''
|
||||
You need to instantiate the EZFIO_ocaml with this keyword argument
|
||||
ezfio_dir = str
|
||||
ezfio_name = str
|
||||
type = Named_tuple(fancy_type, ocaml_type, fortrant_type)
|
||||
|
||||
Return the read template
|
||||
'''
|
||||
|
||||
# ~#~#~#~#~#~#~#~ #
|
||||
# C h e c k i n g #
|
||||
# ~#~#~#~#~#~#~#~ #
|
||||
|
||||
self.check_if_init(["ezfio_dir", "ezfio_name", "type"],
|
||||
sys._getframe().f_code.co_name)
|
||||
|
||||
# ~#~#~#~#~#~#~#~#~#~#~#~#~#~# #
|
||||
# C r e a t e _ t e m pl a t e #
|
||||
# ~#~#~#~#~#~#~#~#~#~#~#~#~#~# #
|
||||
|
||||
l_template = ['(* Write snippet for {self.ezfio_name} *)']
|
||||
|
||||
if self.fancy_type:
|
||||
l_template += ['let write_{self.ezfio_name} var = ',
|
||||
' {self.fancy_type}.to_{self.ocaml_type} var',
|
||||
' |> Ezfio.set_{self.ezfio_dir}_{self.ezfio_name}']
|
||||
else:
|
||||
l_template += ['let write_{self.ezfio_name} =',
|
||||
' Ezfio.set_{self.ezfio_dir}_{self.ezfio_name}']
|
||||
|
||||
l_template += [';;']
|
||||
|
||||
template = "\n ".join(l_template)
|
||||
|
||||
# ~#~#~#~#~#~ #
|
||||
# R e n d e r #
|
||||
# ~#~#~#~#~#~ #
|
||||
|
||||
template_rendered = template.format(**locals())
|
||||
|
||||
# ~#~#~#~#~#~ #
|
||||
# R e t u r n #
|
||||
# ~#~#~#~#~#~ #
|
||||
return template_rendered
|
||||
|
||||
def create_type(self):
|
||||
'''
|
||||
You need to instantiate the EZFIO_ocaml with this keyword argument
|
||||
l_ezfio_name = [provider_name, ...]
|
||||
l_type = [Named_tuple(fancy_type, ocaml_type, fortrant_type), ...]
|
||||
|
||||
Return the type template
|
||||
'''
|
||||
|
||||
# ~#~#~#~#~#~#~#~ #
|
||||
# C h e c k i n g #
|
||||
# ~#~#~#~#~#~#~#~ #
|
||||
|
||||
self.check_if_init(["l_ezfio_name", "l_type"],
|
||||
sys._getframe().f_code.co_name)
|
||||
|
||||
# ~#~#~#~#~#~#~#~#~#~#~#~#~#~# #
|
||||
# C r e a t e _ t e m pl a t e #
|
||||
# ~#~#~#~#~#~#~#~#~#~#~#~#~#~# #
|
||||
|
||||
l_template = ["(* Generate type *)",
|
||||
"type t = ",
|
||||
" {"]
|
||||
|
||||
for p, t in zip(self.l_ezfio_name, self.l_type):
|
||||
|
||||
if t.fancy:
|
||||
l_template += [" {0:<30} : {1}.t;".format(p, t.fancy)]
|
||||
else:
|
||||
l_template += [" {0:<30} : {1};".format(p, t.ocaml)]
|
||||
|
||||
l_template += [" } with sexp",
|
||||
";;"]
|
||||
|
||||
# ~#~#~#~#~#~ #
|
||||
# R e t u r n #
|
||||
# ~#~#~#~#~#~ #
|
||||
return "\n ".join(l_template)
|
||||
|
||||
def create_read_global(self):
|
||||
'''
|
||||
You need to instantiate the EZFIO_ocaml with this keyword argument
|
||||
l_ezfio_name = [ezfio_name, ...]
|
||||
|
||||
Return the read_global template
|
||||
'''
|
||||
# ~#~#~#~#~#~#~#~ #
|
||||
# C h e c k i n g #
|
||||
# ~#~#~#~#~#~#~#~ #
|
||||
|
||||
self.check_if_init(["l_ezfio_name"],
|
||||
sys._getframe().f_code.co_name)
|
||||
|
||||
# ~#~#~#~#~#~#~#~#~#~#~#~#~#~# #
|
||||
# C r e a t e _ t e m pl a t e #
|
||||
# ~#~#~#~#~#~#~#~#~#~#~#~#~#~# #
|
||||
|
||||
l_template = ["(* Read all *)",
|
||||
"let read() = ",
|
||||
" Some",
|
||||
" {"]
|
||||
|
||||
l_template += [" {0:<30} = read_{0} ();".format(p)
|
||||
for p in self.l_ezfio_name]
|
||||
|
||||
l_template += [" }",
|
||||
";;"]
|
||||
|
||||
# ~#~#~#~#~#~ #
|
||||
# R e t u r n #
|
||||
# ~#~#~#~#~#~ #
|
||||
return "\n ".join(l_template)
|
||||
|
||||
def create_write_global(self):
|
||||
'''
|
||||
You need to instantiate the EZFIO_ocaml with this keyword argument
|
||||
l_ezfio_name = [provider_name, ...]
|
||||
|
||||
Return the type template
|
||||
'''
|
||||
# ~#~#~#~#~#~#~#~ #
|
||||
# C h e c k i n g #
|
||||
# ~#~#~#~#~#~#~#~ #
|
||||
|
||||
self.check_if_init(["l_ezfio_name"],
|
||||
sys._getframe().f_code.co_name)
|
||||
|
||||
# ~#~#~#~#~#~#~#~#~#~#~#~#~#~# #
|
||||
# C r e a t e _ t e m pl a t e #
|
||||
# ~#~#~#~#~#~#~#~#~#~#~#~#~#~# #
|
||||
|
||||
l_template = ["(* Write all *)",
|
||||
"let write{ "]
|
||||
l_template += [" {0};".format(p) for p in self.l_ezfio_name]
|
||||
l_template += [" } ="]
|
||||
l_template += [" write_{0:<30} {0};".format(p)
|
||||
for p in self.l_ezfio_name]
|
||||
l_template += [";;"]
|
||||
|
||||
# ~#~#~#~#~#~ #
|
||||
# R e t u r n #
|
||||
# ~#~#~#~#~#~ #
|
||||
return "\n ".join(l_template)
|
||||
|
||||
def create_to_string(self):
|
||||
'''
|
||||
You need to instantiate the EZFIO_ocaml with this keyword argument
|
||||
l_ezfio_name = [provider_name, ...]
|
||||
l_type = [Named_tuple(fancy_type, ocaml_type, fortrant_type), ...]
|
||||
|
||||
Return the type template
|
||||
'''
|
||||
# ~#~#~#~#~#~#~#~ #
|
||||
# C h e c k i n g #
|
||||
# ~#~#~#~#~#~#~#~ #
|
||||
|
||||
self.check_if_init(["l_ezfio_name", "l_type"],
|
||||
sys._getframe().f_code.co_name)
|
||||
|
||||
# ~#~#~#~#~#~#~#~#~#~#~#~#~#~# #
|
||||
# C r e a t e _ t e m pl a t e #
|
||||
# ~#~#~#~#~#~#~#~#~#~#~#~#~#~# #
|
||||
|
||||
l_template = ['(* to_string*)',
|
||||
'let to_string b =',
|
||||
' Printf.sprintf "']
|
||||
|
||||
l_template += ["{0} = %s".format(p) for p in self.l_ezfio_name]
|
||||
l_template += ['"']
|
||||
|
||||
for p, t in zip(self.l_ezfio_name, self.l_type):
|
||||
|
||||
if t.fancy:
|
||||
str_ = t.fancy
|
||||
else:
|
||||
str_ = t.ocaml.capitalize()
|
||||
|
||||
l_template += [" ({0}.to_string b.{1})".format(str_, p)]
|
||||
|
||||
l_template += [";;"]
|
||||
|
||||
# ~#~#~#~#~#~ #
|
||||
# R e t u r n #
|
||||
# ~#~#~#~#~#~ #
|
||||
return "\n ".join(l_template)
|
||||
|
||||
def create_to_rst(self):
|
||||
'''
|
||||
You need to instantiate the EZFIO_ocaml with this keyword argument
|
||||
l_ezfio_name = [provider_name, ...]
|
||||
l_type = [Named_tuple(fancy_type, ocaml_type, fortrant_type), ...]
|
||||
|
||||
Return the type template
|
||||
'''
|
||||
# ~#~#~#~#~#~#~#~ #
|
||||
# C h e c k i n g #
|
||||
# ~#~#~#~#~#~#~#~ #
|
||||
|
||||
self.check_if_init(["l_ezfio_name", "l_type", "l_doc"],
|
||||
sys._getframe().f_code.co_name)
|
||||
|
||||
# ~#~#~#~#~#~#~#~#~#~#~#~#~#~# #
|
||||
# C r e a t e _ t e m pl a t e #
|
||||
# ~#~#~#~#~#~#~#~#~#~#~#~#~#~# #
|
||||
|
||||
l_template = ['(* to_rst*)',
|
||||
'let to_rst b =',
|
||||
' Printf.sprintf "']
|
||||
|
||||
for p, d in zip(self.l_ezfio_name, self.l_doc):
|
||||
|
||||
l_template += ["{0} ::".format(d),
|
||||
"",
|
||||
" {0} = %s".format(p),
|
||||
""]
|
||||
l_template += ['"']
|
||||
|
||||
for p, t in zip(self.l_ezfio_name, self.l_type):
|
||||
|
||||
if t.fancy:
|
||||
str_ = t.fancy
|
||||
else:
|
||||
str_ = t.ocaml.capitalize()
|
||||
|
||||
l_template += [" ({0}.to_string b.{1})".format(str_, p)]
|
||||
|
||||
l_template += ["|> Rst_string.of_string",
|
||||
";;"]
|
||||
|
||||
# ~#~#~#~#~#~ #
|
||||
# R e t u r n #
|
||||
# ~#~#~#~#~#~ #
|
||||
return "\n ".join(l_template)
|
||||
|
||||
def create_input_auto_generated(self):
|
||||
"""
|
||||
Generate the include of all the Input_module.lower template
|
||||
"""
|
||||
|
||||
# ~#~#~#~#~#~#~#~ #
|
||||
# C h e c k i n g #
|
||||
# ~#~#~#~#~#~#~#~ #
|
||||
|
||||
self.check_if_init(["l_module_lower"],
|
||||
sys._getframe().f_code.co_name)
|
||||
|
||||
# ~#~#~#~#~#~#~#~#~#~#~#~#~#~# #
|
||||
# C r e a t e _ t e m pl a t e #
|
||||
# ~#~#~#~#~#~#~#~#~#~#~#~#~#~# #
|
||||
|
||||
l_template = ['open Qputils;;',
|
||||
'open Qptypes;;',
|
||||
'open Core.Std;;',
|
||||
'']
|
||||
|
||||
for m in self.l_module_lower:
|
||||
l_template += ["include Input_{0}".format(m)]
|
||||
|
||||
# ~#~#~#~#~#~ #
|
||||
# R e t u r n #
|
||||
# ~#~#~#~#~#~ #
|
||||
|
||||
return "\n".join(l_template)
|
||||
|
||||
def create_qp_keywords(self):
|
||||
"""
|
||||
Generate keywords template
|
||||
"""
|
||||
|
||||
# ~#~#~#~#~#~#~#~ #
|
||||
# C h e c k i n g #
|
||||
# ~#~#~#~#~#~#~#~ #
|
||||
|
||||
self.check_if_init(["l_module_lower"],
|
||||
sys._getframe().f_code.co_name)
|
||||
|
||||
# ~#~#~#~#~#~#~#~#~#~#~#~#~#~# #
|
||||
# C r e a t e _ t e m pl a t e #
|
||||
# ~#~#~#~#~#~#~#~#~#~#~#~#~#~# #
|
||||
|
||||
l_template = ["| {0}".format(m.capitalize())
|
||||
for m in self.l_module_lower]
|
||||
|
||||
# ~#~#~#~#~#~ #
|
||||
# R e t u r n #
|
||||
# ~#~#~#~#~#~ #
|
||||
|
||||
return "\n".join(l_template)
|
||||
|
||||
def create_qp_keywords_to_string(self):
|
||||
"""
|
||||
Generate keywords to string template
|
||||
"""
|
||||
|
||||
# ~#~#~#~#~#~#~#~ #
|
||||
# C h e c k i n g #
|
||||
# ~#~#~#~#~#~#~#~ #
|
||||
|
||||
self.check_if_init(["l_module_lower"],
|
||||
sys._getframe().f_code.co_name)
|
||||
|
||||
# ~#~#~#~#~#~#~#~#~#~#~#~#~#~# #
|
||||
# C r e a t e _ t e m pl a t e #
|
||||
# ~#~#~#~#~#~#~#~#~#~#~#~#~#~# #
|
||||
|
||||
l_template = ['| {0} -> "{0}"'.format(m.capitalize())
|
||||
for m in self.l_module_lower]
|
||||
|
||||
# ~#~#~#~#~#~ #
|
||||
# R e t u r n #
|
||||
# ~#~#~#~#~#~ #
|
||||
|
||||
return "\n".join(l_template)
|
||||
|
||||
def create_qp_section_to_rst(self):
|
||||
"""
|
||||
Generate section to rst
|
||||
"""
|
||||
# ~#~#~#~#~#~#~#~ #
|
||||
# C h e c k i n g #
|
||||
# ~#~#~#~#~#~#~#~ #
|
||||
|
||||
self.check_if_init(["l_module_lower"],
|
||||
sys._getframe().f_code.co_name)
|
||||
|
||||
# ~#~#~#~#~#~#~#~#~#~#~#~#~#~# #
|
||||
# C r e a t e _ t e m pl a t e #
|
||||
# ~#~#~#~#~#~#~#~#~#~#~#~#~#~# #
|
||||
|
||||
l_template = []
|
||||
for m in self.l_module_lower:
|
||||
m_cap = m.capitalize()
|
||||
l_template += [" | {0} ->".format(m_cap),
|
||||
" f {0}.(read, to_rst)".format(m_cap)]
|
||||
|
||||
# ~#~#~#~#~#~ #
|
||||
# R e t u r n #
|
||||
# ~#~#~#~#~#~ #
|
||||
|
||||
return "\n".join(l_template)
|
||||
|
||||
def create_qp_write(self):
|
||||
"""
|
||||
Generate write
|
||||
"""
|
||||
# ~#~#~#~#~#~#~#~ #
|
||||
# C h e c k i n g #
|
||||
# ~#~#~#~#~#~#~#~ #
|
||||
|
||||
self.check_if_init(["l_module_lower"],
|
||||
sys._getframe().f_code.co_name)
|
||||
|
||||
# ~#~#~#~#~#~#~#~#~#~#~#~#~#~# #
|
||||
# C r e a t e _ t e m pl a t e #
|
||||
# ~#~#~#~#~#~#~#~#~#~#~#~#~#~# #
|
||||
|
||||
str_ = " | {0} -> write {0}.(of_rst, write) s"
|
||||
l_template = [str_.format(m.capitalize()) for m in self.l_module_lower]
|
||||
|
||||
# ~#~#~#~#~#~ #
|
||||
# R e t u r n #
|
||||
# ~#~#~#~#~#~ #
|
||||
|
||||
return "\n".join(l_template)
|
||||
|
||||
def create_qp_tasks(self):
|
||||
"""
|
||||
Generate taks
|
||||
"""
|
||||
# ~#~#~#~#~#~#~#~ #
|
||||
# C h e c k i n g #
|
||||
# ~#~#~#~#~#~#~#~ #
|
||||
|
||||
self.check_if_init(["l_module_lower"],
|
||||
sys._getframe().f_code.co_name)
|
||||
|
||||
# ~#~#~#~#~#~#~#~#~#~#~#~#~#~# #
|
||||
# C r e a t e _ t e m pl a t e #
|
||||
# ~#~#~#~#~#~#~#~#~#~#~#~#~#~# #
|
||||
|
||||
l_template = [" {0} ; ".format(m.capitalize())
|
||||
for m in self.l_module_lower]
|
||||
|
||||
# ~#~#~#~#~#~ #
|
||||
# R e t u r n #
|
||||
# ~#~#~#~#~#~ #
|
||||
|
||||
return "\n".join(l_template)
|
98
scripts/ezfio_interface/ezfio_generate_provider.py
Executable file
98
scripts/ezfio_interface/ezfio_generate_provider.py
Executable file
@ -0,0 +1,98 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
__author__ = "Applencourt PEP8"
|
||||
__date__ = "jeudi 26 mars 2015, 12:49:35 (UTC+0100)"
|
||||
|
||||
"""
|
||||
Creates the provider of a variable that has to be
|
||||
fetched from the EZFIO file.
|
||||
"""
|
||||
|
||||
import sys
|
||||
|
||||
class EZFIO_Provider(object):
|
||||
|
||||
data = """
|
||||
BEGIN_PROVIDER [ %(type)s, %(name)s ]
|
||||
implicit none
|
||||
BEGIN_DOC
|
||||
! %(doc)s
|
||||
END_DOC
|
||||
|
||||
logical :: has
|
||||
PROVIDE ezfio_filename
|
||||
call ezfio_has_%(ezfio_dir)s_%(ezfio_name)s(has)
|
||||
if (has) then
|
||||
call ezfio_get_%(ezfio_dir)s_%(ezfio_name)s(%(name)s)
|
||||
else
|
||||
print *, '%(ezfio_dir)s/%(ezfio_name)s not found in EZFIO file'
|
||||
stop 1
|
||||
endif
|
||||
%(write)s
|
||||
END_PROVIDER
|
||||
""".strip()
|
||||
|
||||
write_correspondance = {"integer": "write_int",
|
||||
"logical": "write_bool",
|
||||
"double precision": "write_double"}
|
||||
|
||||
def __init__(self):
|
||||
self.values = "type doc name ezfio_dir ezfio_name write output".split()
|
||||
for v in self.values:
|
||||
exec "self.{0} = None".format(v)
|
||||
|
||||
def __repr__(self):
|
||||
self.set_write()
|
||||
for v in self.values:
|
||||
if not v:
|
||||
msg = "Error : %s is not set in ezfio_with_default.py" % (v)
|
||||
print >>sys.stderr, msg
|
||||
sys.exit(1)
|
||||
return self.data % self.__dict__
|
||||
|
||||
def set_write(self):
|
||||
self.write = ""
|
||||
if self.type in self.write_correspondance:
|
||||
write = self.write_correspondance[self.type]
|
||||
output = self.output
|
||||
name = self.name
|
||||
|
||||
l_write = ["",
|
||||
" call write_time(%(output)s)",
|
||||
" call %(write)s(%(output)s, %(name)s, &",
|
||||
" '%(name)s')",
|
||||
""]
|
||||
|
||||
self.write = "\n".join(l_write) % locals()
|
||||
|
||||
def set_type(self, t):
|
||||
self.type = t.lower()
|
||||
|
||||
def set_doc(self, t):
|
||||
self.doc = t.strip().replace('\n', '\n! ')
|
||||
|
||||
def set_name(self, t):
|
||||
self.name = t
|
||||
|
||||
def set_ezfio_dir(self, t):
|
||||
self.ezfio_dir = t.lower()
|
||||
|
||||
def set_ezfio_name(self, t):
|
||||
self.ezfio_name = t.lower()
|
||||
|
||||
def set_output(self, t):
|
||||
self.output = t
|
||||
|
||||
|
||||
def test_module():
|
||||
T = EZFIO_Provider()
|
||||
T.set_type("double precision")
|
||||
T.set_name("thresh_SCF")
|
||||
T.set_doc("Threshold on the convergence of the Hartree Fock energy")
|
||||
T.set_ezfio_dir("Hartree_Fock")
|
||||
T.set_ezfio_name("thresh_SCF")
|
||||
T.set_output("output_Hartree_Fock")
|
||||
print T
|
||||
|
||||
if __name__ == '__main__':
|
||||
test_module()
|
@ -11,27 +11,21 @@ open Core.Std;;
|
||||
(** Keywords used to define input sections *)
|
||||
type keyword =
|
||||
| Ao_basis
|
||||
| Bielec_integrals
|
||||
| Cisd_sc2
|
||||
| Determinants
|
||||
| Electrons
|
||||
| Full_ci
|
||||
| Hartree_fock
|
||||
| Mo_basis
|
||||
| Nuclei
|
||||
{keywords}
|
||||
;;
|
||||
|
||||
|
||||
let keyword_to_string = function
|
||||
| Ao_basis -> "AO basis"
|
||||
| Bielec_integrals -> "Two electron integrals"
|
||||
| Cisd_sc2 -> "CISD (SC)^2"
|
||||
| Determinants -> "Determinants"
|
||||
| Electrons -> "Electrons"
|
||||
| Full_ci -> "Selected Full-CI"
|
||||
| Hartree_fock -> "Hartree-Fock"
|
||||
| Mo_basis -> "MO basis"
|
||||
| Nuclei -> "Molecule"
|
||||
| Ao_basis -> "AO basis"
|
||||
| Determinants -> "Determinants"
|
||||
| Electrons -> "Electrons"
|
||||
| Mo_basis -> "MO basis"
|
||||
| Nuclei -> "Molecule"
|
||||
{keywords_to_string}
|
||||
;;
|
||||
|
||||
|
||||
@ -70,24 +64,17 @@ let get s =
|
||||
begin
|
||||
let open Input in
|
||||
match s with
|
||||
| Full_ci ->
|
||||
f Full_ci.(read, to_rst)
|
||||
| Hartree_fock ->
|
||||
f Hartree_fock.(read, to_rst)
|
||||
| Mo_basis ->
|
||||
f Mo_basis.(read, to_rst)
|
||||
| Electrons ->
|
||||
f Electrons.(read, to_rst)
|
||||
| Cisd_sc2 ->
|
||||
f Cisd_sc2.(read, to_rst)
|
||||
| Nuclei ->
|
||||
f Nuclei.(read, to_rst)
|
||||
| Ao_basis ->
|
||||
f Ao_basis.(read, to_rst)
|
||||
| Bielec_integrals ->
|
||||
f Bielec_integrals.(read, to_rst)
|
||||
| Determinants ->
|
||||
f Determinants.(read, to_rst)
|
||||
{section_to_rst}
|
||||
end
|
||||
with
|
||||
| Sys_error msg -> (Printf.eprintf "Info: %s\n%!" msg ; "")
|
||||
@ -125,11 +112,8 @@ let set str s =
|
||||
in
|
||||
let open Input in
|
||||
match s with
|
||||
| Hartree_fock -> write Hartree_fock.(of_rst, write) s
|
||||
| Full_ci -> write Full_ci.(of_rst, write) s
|
||||
{write}
|
||||
| Electrons -> write Electrons.(of_rst, write) s
|
||||
| Cisd_sc2 -> write Cisd_sc2.(of_rst, write) s
|
||||
| Bielec_integrals -> write Bielec_integrals.(of_rst, write) s
|
||||
| Determinants -> write Determinants.(of_rst, write) s
|
||||
| Nuclei -> write Nuclei.(of_rst, write) s
|
||||
| Ao_basis -> () (* TODO *)
|
||||
@ -176,10 +160,7 @@ let run check_only ezfio_filename =
|
||||
Nuclei ;
|
||||
Ao_basis;
|
||||
Electrons ;
|
||||
Bielec_integrals ;
|
||||
Hartree_fock ;
|
||||
Cisd_sc2 ;
|
||||
Full_ci ;
|
||||
{tasks}
|
||||
Mo_basis;
|
||||
Determinants ;
|
||||
]
|
@ -90,7 +90,10 @@ END_PROVIDER
|
||||
self.default = t
|
||||
|
||||
def get_default(self):
|
||||
filename = '/'.join( [os.environ['QPACKAGE_ROOT'], 'data', 'ezfio_defaults'] )
|
||||
filename = '/'.join( [os.environ['QPACKAGE_ROOT'], 'data',
|
||||
'ezfio_defaults',
|
||||
'WILL_BE_DELETED.ezfio_default'] )
|
||||
|
||||
file = open(filename,'r')
|
||||
lines = file.readlines()
|
||||
file.close()
|
||||
@ -115,6 +118,8 @@ END_PROVIDER
|
||||
true = True
|
||||
false= False
|
||||
try:
|
||||
true = True
|
||||
false = False
|
||||
v_eval = eval(v)
|
||||
except:
|
||||
v = "call ezfio_get_%(v)s(%(name)s)"%locals()
|
||||
|
@ -9,7 +9,7 @@ echo "=-=-=-=-=-=-=-=-=-=-=-"
|
||||
for dir in ${QPACKAGE_ROOT}/src/*/
|
||||
do
|
||||
cd $dir || exit -1
|
||||
${QPACKAGE_ROOT}/scripts/ezfio_interface.py
|
||||
${QPACKAGE_ROOT}/scripts/ezfio_interface/ei_handler.py
|
||||
done
|
||||
|
||||
# For old-style directories. Will be removed some day...
|
||||
|
@ -65,5 +65,4 @@ fi
|
||||
${QPACKAGE_ROOT}/scripts/create_Makefile_depend.sh
|
||||
|
||||
# Update EZFIO interface
|
||||
${QPACKAGE_ROOT}/scripts/ezfio_interface.py
|
||||
|
||||
${QPACKAGE_ROOT}/scripts/ezfio_interface/ei_handler.py
|
||||
|
@ -17,8 +17,8 @@ export QPACKAGE_ROOT=\$( cd \$(dirname "\${BASH_SOURCE}") ; pwd -P )
|
||||
export LD_LIBRARY_PATH="\${QPACKAGE_ROOT}"/lib:\${LD_LIBRARY_PATH}
|
||||
export LIBRARY_PATH="\${QPACKAGE_ROOT}"/lib:\${LIBRARY_PATH}
|
||||
export C_INCLUDE_PATH="\${QPACKAGE_ROOT}"/include:\${C_INCLUDE_PATH}
|
||||
export PYTHONPATH=\${PYTHONPATH}:"\${QPACKAGE_ROOT}"/scripts
|
||||
export PATH=\${PATH}:"\${QPACKAGE_ROOT}"/scripts
|
||||
export PYTHONPATH=\${PYTHONPATH}:"\${QPACKAGE_ROOT}"/scripts:"\${QPACKAGE_ROOT}"/scripts/ezfio_interface
|
||||
export PATH=\${PATH}:"\${QPACKAGE_ROOT}"/scripts:"\${QPACKAGE_ROOT}"/scripts/ezfio_interface
|
||||
export PATH=\${PATH}:"\${QPACKAGE_ROOT}"/bin
|
||||
export PATH=\${PATH}:"\${QPACKAGE_ROOT}"/ocaml
|
||||
source "\${QPACKAGE_ROOT}"/bin/irpman &> /dev/null
|
||||
@ -48,16 +48,6 @@ then
|
||||
fi
|
||||
|
||||
|
||||
echo "${BLUE}===== Installing EZFIO ===== ${BLACK}"
|
||||
${QPACKAGE_ROOT}/scripts/install_ezfio.sh | tee install_ezfio.log
|
||||
|
||||
if [[ ! -d ${QPACKAGE_ROOT}/EZFIO ]]
|
||||
then
|
||||
echo $RED "Error in EZFIO installation" $BLACK
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
echo "${BLUE}===== Installing Zlib ===== ${BLACK}"
|
||||
${QPACKAGE_ROOT}/scripts/install_zlib.sh | tee install_zlib.log
|
||||
|
||||
|
@ -1,9 +0,0 @@
|
||||
bielec_integrals
|
||||
read_ao_integrals logical
|
||||
read_mo_integrals logical
|
||||
write_ao_integrals logical
|
||||
write_mo_integrals logical
|
||||
threshold_ao double precision
|
||||
threshold_mo double precision
|
||||
direct logical
|
||||
|
@ -1,46 +0,0 @@
|
||||
BEGIN_SHELL [ /usr/bin/python ]
|
||||
from ezfio_with_default import EZFIO_Provider
|
||||
T = EZFIO_Provider()
|
||||
T.set_type ( "logical" )
|
||||
T.set_name ( "do_direct_integrals" )
|
||||
T.set_doc ( "If true, compute integrals on the fly" )
|
||||
T.set_ezfio_dir ( "bielec_integrals" )
|
||||
T.set_ezfio_name( "direct" )
|
||||
T.set_output ( "output_biints" )
|
||||
print T
|
||||
|
||||
T.set_type ( "logical" )
|
||||
T.set_name ( "write_mo_integrals" )
|
||||
T.set_doc ( "If true, write MO integrals in EZFIO" )
|
||||
T.set_ezfio_name( "write_mo_integrals" )
|
||||
print T
|
||||
|
||||
T.set_name ( "write_ao_integrals" )
|
||||
T.set_doc ( "If true, write AO integrals in EZFIO" )
|
||||
T.set_ezfio_name( "write_ao_integrals" )
|
||||
print T
|
||||
|
||||
T.set_name ( "read_mo_integrals" )
|
||||
T.set_doc ( "If true, read MO integrals in EZFIO" )
|
||||
T.set_ezfio_name( "read_mo_integrals" )
|
||||
print T
|
||||
|
||||
T.set_name ( "read_ao_integrals" )
|
||||
T.set_doc ( "If true, read AO integrals in EZFIO" )
|
||||
T.set_ezfio_name( "read_ao_integrals" )
|
||||
print T
|
||||
|
||||
T.set_type ( "double precision" )
|
||||
T.set_name ( "ao_integrals_threshold" )
|
||||
T.set_doc ( "If <pq|rs> < ao_integrals_threshold, <pq|rs> = 0" )
|
||||
T.set_ezfio_name( "threshold_ao" )
|
||||
print T
|
||||
|
||||
T.set_name ( "mo_integrals_threshold" )
|
||||
T.set_doc ( "If <ij|kl> < mo_integrals_threshold, <ij|kl> = 0" )
|
||||
T.set_ezfio_name( "threshold_mo" )
|
||||
print T
|
||||
|
||||
END_SHELL
|
||||
|
||||
|
0
src/Bielec_integrals/ASSUMPTIONS.rst
Normal file
0
src/Bielec_integrals/ASSUMPTIONS.rst
Normal file
32
src/Bielec_integrals/EZFIO.cfg
Normal file
32
src/Bielec_integrals/EZFIO.cfg
Normal file
@ -0,0 +1,32 @@
|
||||
[do_direct_integrals]
|
||||
type: logical
|
||||
doc: Compute integrals on the fly
|
||||
interface: input
|
||||
default: False
|
||||
ezfio_name: direct
|
||||
|
||||
[disk_access_mo_integrals]
|
||||
type: Disk_access
|
||||
doc: Read/Write MO integrals from/to disk [ Write | Read | None ]
|
||||
interface: input
|
||||
default: None
|
||||
|
||||
[disk_access_ao_integrals]
|
||||
type: Disk_access
|
||||
doc: Read/Write AO integrals from/to disk [ Write | Read | None ]
|
||||
interface: input
|
||||
default: None
|
||||
|
||||
[ao_integrals_threshold]
|
||||
type: Threshold
|
||||
doc: If |<pq|rs>| < ao_integrals_threshold then <pq|rs> is zero
|
||||
interface: input
|
||||
default: 1.e-15
|
||||
ezfio_name: threshold_ao
|
||||
|
||||
[mo_integrals_threshold]
|
||||
type: Threshold
|
||||
doc: If |<ij|kl>| < ao_integrals_threshold then <pq|rs> is zero
|
||||
interface: input
|
||||
default: 1.e-15
|
||||
ezfio_name: threshold_mo
|
@ -319,13 +319,6 @@ subroutine compute_ao_bielec_integrals(j,k,l,sze,buffer_value)
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
BEGIN_PROVIDER [ logical, ao_bielec_integrals_in_map ]
|
||||
implicit none
|
||||
use map_module
|
||||
@ -356,7 +349,7 @@ BEGIN_PROVIDER [ logical, ao_bielec_integrals_in_map ]
|
||||
integer :: load_ao_integrals
|
||||
print*,'Reading the AO integrals'
|
||||
if (load_ao_integrals(trim(ezfio_filename)//'/work/ao_integrals.bin') == 0) then
|
||||
write(output_BiInts,*) 'AO integrals provided'
|
||||
write(output_bielec_integrals,*) 'AO integrals provided'
|
||||
ao_bielec_integrals_in_map = .True.
|
||||
return
|
||||
endif
|
||||
@ -374,7 +367,7 @@ BEGIN_PROVIDER [ logical, ao_bielec_integrals_in_map ]
|
||||
PROVIDE progress_bar
|
||||
call omp_init_lock(lock)
|
||||
lmax = ao_num*(ao_num+1)/2
|
||||
write(output_BiInts,*) 'Providing the AO integrals'
|
||||
write(output_bielec_integrals,*) 'Providing the AO integrals'
|
||||
call wall_time(wall_0)
|
||||
call wall_time(wall_1)
|
||||
call cpu_time(cpu_1)
|
||||
@ -385,7 +378,7 @@ BEGIN_PROVIDER [ logical, ao_bielec_integrals_in_map ]
|
||||
!$OMP DEFAULT(NONE) &
|
||||
!$OMP SHARED (ao_num, jl_pairs, ao_integrals_map,thresh, &
|
||||
!$OMP cpu_1,wall_1,lock, lmax,n_centers,ao_nucl, &
|
||||
!$OMP ao_overlap_abs,ao_overlap,output_BiInts,abort_here, &
|
||||
!$OMP ao_overlap_abs,ao_overlap,output_bielec_integrals,abort_here, &
|
||||
!$OMP wall_0,progress_bar,progress_value)
|
||||
|
||||
allocate(buffer_i(size_buffer))
|
||||
@ -452,7 +445,7 @@ IRP_ENDIF
|
||||
if (thread_num == 0) then
|
||||
if (wall_2 - wall_0 > 1.d0) then
|
||||
wall_0 = wall_2
|
||||
write(output_BiInts,*) 100.*float(kk)/float(lmax), '% in ', &
|
||||
write(output_bielec_integrals,*) 100.*float(kk)/float(lmax), '% in ', &
|
||||
wall_2-wall_1, 's', map_mb(ao_integrals_map) ,'MB'
|
||||
progress_value = dble(map_mb(ao_integrals_map))
|
||||
endif
|
||||
@ -469,21 +462,21 @@ IRP_ENDIF
|
||||
stop 'Aborting in AO integrals calculation'
|
||||
endif
|
||||
IRP_IF COARRAY
|
||||
write(output_BiInts,*) 'Communicating the map'
|
||||
write(output_bielec_integrals,*) 'Communicating the map'
|
||||
call communicate_ao_integrals()
|
||||
IRP_ENDIF COARRAY
|
||||
write(output_BiInts,*) 'Sorting the map'
|
||||
write(output_bielec_integrals,*) 'Sorting the map'
|
||||
call map_sort(ao_integrals_map)
|
||||
call cpu_time(cpu_2)
|
||||
call wall_time(wall_2)
|
||||
integer(map_size_kind) :: get_ao_map_size, ao_map_size
|
||||
ao_map_size = get_ao_map_size()
|
||||
|
||||
write(output_BiInts,*) 'AO integrals provided:'
|
||||
write(output_BiInts,*) ' Size of AO map : ', map_mb(ao_integrals_map) ,'MB'
|
||||
write(output_BiInts,*) ' Number of AO integrals :', ao_map_size
|
||||
write(output_BiInts,*) ' cpu time :',cpu_2 - cpu_1, 's'
|
||||
write(output_BiInts,*) ' wall time :',wall_2 - wall_1, 's ( x ', (cpu_2-cpu_1)/(wall_2-wall_1+tiny(1.d0)), ' )'
|
||||
write(output_bielec_integrals,*) 'AO integrals provided:'
|
||||
write(output_bielec_integrals,*) ' Size of AO map : ', map_mb(ao_integrals_map) ,'MB'
|
||||
write(output_bielec_integrals,*) ' Number of AO integrals :', ao_map_size
|
||||
write(output_bielec_integrals,*) ' cpu time :',cpu_2 - cpu_1, 's'
|
||||
write(output_bielec_integrals,*) ' wall time :',wall_2 - wall_1, 's ( x ', (cpu_2-cpu_1)/(wall_2-wall_1+tiny(1.d0)), ' )'
|
||||
|
||||
ao_bielec_integrals_in_map = .True.
|
||||
if (write_ao_integrals) then
|
@ -13,7 +13,7 @@ BEGIN_PROVIDER [ type(map_type), ao_integrals_map ]
|
||||
call bielec_integrals_index(ao_num,ao_num,ao_num,ao_num,key_max)
|
||||
sze = key_max
|
||||
call map_init(ao_integrals_map,sze)
|
||||
write(output_BiInts,*) 'AO map initialized'
|
||||
write(output_bielec_integrals,*) 'AO map initialized'
|
||||
END_PROVIDER
|
||||
|
||||
subroutine bielec_integrals_index(i,j,k,l,i1)
|
||||
@ -244,7 +244,7 @@ BEGIN_PROVIDER [ type(map_type), mo_integrals_map ]
|
||||
call bielec_integrals_index(mo_tot_num,mo_tot_num,mo_tot_num,mo_tot_num,key_max)
|
||||
sze = key_max
|
||||
call map_init(mo_integrals_map,sze)
|
||||
write(output_BiInts,*) 'MO map initialized'
|
||||
write(output_bielec_integrals,*) 'MO map initialized'
|
||||
END_PROVIDER
|
||||
|
||||
subroutine insert_into_ao_integrals_map(n_integrals, &
|
@ -31,7 +31,7 @@ BEGIN_PROVIDER [ logical, mo_bielec_integrals_in_map ]
|
||||
integer :: load_mo_integrals
|
||||
print*,'Reading the MO integrals'
|
||||
if (load_mo_integrals(trim(ezfio_filename)//'/work/mo_integrals.bin') == 0) then
|
||||
write(output_BiInts,*) 'MO integrals provided'
|
||||
write(output_bielec_integrals,*) 'MO integrals provided'
|
||||
return
|
||||
endif
|
||||
endif
|
||||
@ -84,8 +84,8 @@ subroutine add_integrals_to_map(mask_ijkl)
|
||||
call bitstring_to_list( mask_ijkl(1,4), list_ijkl(1,4), n_l, N_int )
|
||||
|
||||
size_buffer = min(ao_num*ao_num*ao_num,16000000)
|
||||
write(output_BiInts,*) 'Providing the molecular integrals '
|
||||
write(output_BiInts,*) 'Buffers : ', 8.*(mo_tot_num_align*(n_j)*(n_k+1) + mo_tot_num_align +&
|
||||
write(output_bielec_integrals,*) 'Providing the molecular integrals '
|
||||
write(output_bielec_integrals,*) 'Buffers : ', 8.*(mo_tot_num_align*(n_j)*(n_k+1) + mo_tot_num_align +&
|
||||
ao_num+ao_num*ao_num+ size_buffer*3)/(1024*1024), 'MB / core'
|
||||
|
||||
call wall_time(wall_1)
|
||||
@ -99,7 +99,7 @@ subroutine add_integrals_to_map(mask_ijkl)
|
||||
!$OMP wall_0,thread_num) &
|
||||
!$OMP DEFAULT(NONE) &
|
||||
!$OMP SHARED(size_buffer,ao_num,mo_tot_num,n_i,n_j,n_k,n_l,mo_tot_num_align,&
|
||||
!$OMP mo_coef_transp,output_BiInts, &
|
||||
!$OMP mo_coef_transp,output_bielec_integrals, &
|
||||
!$OMP mo_coef_transp_is_built, list_ijkl, &
|
||||
!$OMP mo_coef_is_built, wall_1, abort_here, &
|
||||
!$OMP mo_coef,mo_integrals_threshold,ao_integrals_map,mo_integrals_map,progress_bar,progress_value)
|
||||
@ -272,7 +272,7 @@ IRP_ENDIF
|
||||
if (thread_num == 0) then
|
||||
if (wall_2 - wall_0 > 1.d0) then
|
||||
wall_0 = wall_2
|
||||
write(output_BiInts,*) 100.*float(l1)/float(ao_num), '% in ', &
|
||||
write(output_bielec_integrals,*) 100.*float(l1)/float(ao_num), '% in ', &
|
||||
wall_2-wall_1, 's', map_mb(mo_integrals_map) ,'MB'
|
||||
progress_value = dble(map_mb(mo_integrals_map))
|
||||
|
||||
@ -291,7 +291,7 @@ IRP_ENDIF
|
||||
stop 'Aborting in MO integrals calculation'
|
||||
endif
|
||||
IRP_IF COARRAY
|
||||
write(output_BiInts,*) 'Communicating the map'
|
||||
write(output_bielec_integrals,*) 'Communicating the map'
|
||||
call communicate_mo_integrals()
|
||||
IRP_ENDIF
|
||||
call map_unique(mo_integrals_map)
|
||||
@ -304,11 +304,11 @@ IRP_ENDIF
|
||||
deallocate(list_ijkl)
|
||||
|
||||
|
||||
write(output_BiInts,*)'Molecular integrals provided:'
|
||||
write(output_BiInts,*)' Size of MO map ', map_mb(mo_integrals_map) ,'MB'
|
||||
write(output_BiInts,*)' Number of MO integrals: ', mo_map_size
|
||||
write(output_BiInts,*)' cpu time :',cpu_2 - cpu_1, 's'
|
||||
write(output_BiInts,*)' wall time :',wall_2 - wall_1, 's ( x ', (cpu_2-cpu_1)/(wall_2-wall_1), ')'
|
||||
write(output_bielec_integrals,*)'Molecular integrals provided:'
|
||||
write(output_bielec_integrals,*)' Size of MO map ', map_mb(mo_integrals_map) ,'MB'
|
||||
write(output_bielec_integrals,*)' Number of MO integrals: ', mo_map_size
|
||||
write(output_bielec_integrals,*)' cpu time :',cpu_2 - cpu_1, 's'
|
||||
write(output_bielec_integrals,*)' wall time :',wall_2 - wall_1, 's ( x ', (cpu_2-cpu_1)/(wall_2-wall_1), ')'
|
||||
|
||||
if (write_mo_integrals) then
|
||||
call dump_mo_integrals(trim(ezfio_filename)//'/work/mo_integrals.bin')
|
41
src/Bielec_integrals/read_write.irp.f
Normal file
41
src/Bielec_integrals/read_write.irp.f
Normal file
@ -0,0 +1,41 @@
|
||||
BEGIN_PROVIDER [ logical, read_ao_integrals ]
|
||||
&BEGIN_PROVIDER [ logical, read_mo_integrals ]
|
||||
&BEGIN_PROVIDER [ logical, write_ao_integrals ]
|
||||
&BEGIN_PROVIDER [ logical, write_mo_integrals ]
|
||||
|
||||
BEGIN_DOC
|
||||
! One level of abstraction for disk_access_ao_integrals and disk_access_mo_integrals
|
||||
END_DOC
|
||||
implicit none
|
||||
|
||||
if (disk_access_ao_integrals.EQ.'Read') then
|
||||
read_ao_integrals = .True.
|
||||
write_ao_integrals = .False.
|
||||
|
||||
else if (disk_access_ao_integrals.EQ.'Write') then
|
||||
read_ao_integrals = .False.
|
||||
write_ao_integrals = .True.
|
||||
|
||||
else if (disk_access_ao_integrals.EQ.'None') then
|
||||
read_ao_integrals = .False.
|
||||
write_ao_integrals = .False.
|
||||
|
||||
else if (disk_access_mo_integrals.EQ.'Read') then
|
||||
read_mo_integrals = .True.
|
||||
write_mo_integrals = .False.
|
||||
|
||||
else if (disk_access_mo_integrals.EQ.'Write') then
|
||||
read_mo_integrals = .False.
|
||||
write_mo_integrals = .True.
|
||||
|
||||
else if (disk_access_mo_integrals.EQ.'None') then
|
||||
read_mo_integrals = .False.
|
||||
write_mo_integrals = .False.
|
||||
|
||||
else
|
||||
print *, 'bielec_integrals/disk_acces not of a the good type'
|
||||
stop "1"
|
||||
|
||||
endif
|
||||
|
||||
END_PROVIDER
|
@ -1,2 +1,2 @@
|
||||
AOs BiInts Bitmask Dets Electrons Ezfio_files Generators_CAS Hartree_Fock MOGuess MonoInts MOs Nuclei Output Perturbation Properties Selectors_full Utils
|
||||
AOs Bielec_integrals Bitmask Dets Electrons Ezfio_files Generators_CAS Hartree_Fock MOGuess MonoInts MOs Nuclei Output Perturbation Properties Selectors_full Utils
|
||||
|
||||
|
@ -1,3 +1,3 @@
|
||||
AOs BiInts Bitmask Dets Electrons Ezfio_files Hartree_Fock MOGuess MonoInts MOs Nuclei Output Selectors_full SingleRefMethod Utils
|
||||
AOs Bielec_integrals Bitmask Dets Electrons Ezfio_files Hartree_Fock MOGuess MonoInts MOs Nuclei Output Selectors_full SingleRefMethod Utils
|
||||
|
||||
|
||||
|
@ -1,2 +1,2 @@
|
||||
AOs BiInts Bitmask CISD CISD_selected Dets Electrons Ezfio_files Hartree_Fock MOGuess MonoInts MOs Nuclei Output Perturbation Properties Selectors_full SingleRefMethod Utils
|
||||
AOs Bielec_integrals Bitmask CISD CISD_selected Dets Electrons Ezfio_files Hartree_Fock MOGuess MonoInts MOs Nuclei Output Perturbation Properties Selectors_full SingleRefMethod Utils
|
||||
|
||||
|
@ -1,2 +1,2 @@
|
||||
AOs BiInts Bitmask CISD Dets Electrons Ezfio_files Hartree_Fock MOGuess MonoInts MOs Nuclei Output Perturbation Properties Selectors_full SingleRefMethod Utils
|
||||
AOs Bielec_integrals Bitmask CISD Dets Electrons Ezfio_files Hartree_Fock MOGuess MonoInts MOs Nuclei Output Perturbation Properties Selectors_full SingleRefMethod Utils
|
||||
|
||||
|
@ -1,2 +1,2 @@
|
||||
AOs BiInts Bitmask Dets Electrons Ezfio_files Hartree_Fock MOGuess MonoInts MOs Nuclei Output Selectors_full SingleRefMethod Utils
|
||||
AOs Bielec_integrals Bitmask Dets Electrons Ezfio_files Hartree_Fock MOGuess MonoInts MOs Nuclei Output Selectors_full SingleRefMethod Utils
|
||||
|
||||
|
@ -1,2 +1,2 @@
|
||||
AOs BiInts Bitmask Dets Electrons Ezfio_files Hartree_Fock MOGuess MonoInts MOs Nuclei Output Selectors_full SingleRefMethod Utils
|
||||
AOs Bielec_integrals Bitmask Dets Electrons Ezfio_files Hartree_Fock MOGuess MonoInts MOs Nuclei Output Selectors_full SingleRefMethod Utils
|
||||
|
||||
|
29
src/CISD_SC2_selected/EZFIO.cfg
Normal file
29
src/CISD_SC2_selected/EZFIO.cfg
Normal file
@ -0,0 +1,29 @@
|
||||
[N_det_max_cisd_sc2]
|
||||
type: Det_number_max
|
||||
doc: Max number of determinants
|
||||
interface: input
|
||||
default: 10000
|
||||
|
||||
[do_pt2_end]
|
||||
type: logical
|
||||
doc: If true, compute the PT2 at the end of the selection
|
||||
interface: input
|
||||
default: true
|
||||
|
||||
[PT2_max]
|
||||
type: PT2_energy
|
||||
doc: The selection process stops when the largest PT2 (for all the states) is lower
|
||||
than abs(pt2_max)
|
||||
interface: input
|
||||
default: 0.0001
|
||||
|
||||
[energy]
|
||||
type: double precision
|
||||
doc: Calculated CISD_SC2 energy of ground_state
|
||||
interface: output
|
||||
|
||||
[energy_pt2]
|
||||
type: double precision
|
||||
doc: Calculated CISD_SC2 energy+pt2 of ground_state
|
||||
interface: output
|
||||
|
@ -1,2 +1,2 @@
|
||||
AOs BiInts Bitmask CISD CISD_selected Dets Electrons Ezfio_files Hartree_Fock MOGuess MonoInts MOs Nuclei Output Perturbation Properties Selectors_full SingleRefMethod Utils
|
||||
AOs Bielec_integrals Bitmask CISD CISD_selected Dets Electrons Ezfio_files Hartree_Fock MOGuess MonoInts MOs Nuclei Output Perturbation Properties Selectors_full SingleRefMethod Utils
|
||||
|
||||
|
@ -1,4 +0,0 @@
|
||||
cisd_sc2_selected
|
||||
n_det_max_cisd_sc2 integer
|
||||
pt2_max double precision
|
||||
do_pt2_end logical
|
@ -62,12 +62,20 @@ program cisd_sc2_selected
|
||||
if (abort_all) then
|
||||
exit
|
||||
endif
|
||||
|
||||
! =~=~=~=~=~=~=~=~=~=~=~=~=~!
|
||||
! W r i t e _ o n _ d i s k !
|
||||
! =~=~=~=~=~=~=~=~=~=~=~=~=~!
|
||||
|
||||
call ezfio_set_full_ci_energy(CI_SC2_energy(1))
|
||||
|
||||
enddo
|
||||
N_det = min(n_det_max_cisd_sc2,N_det)
|
||||
davidson_threshold = 1.d-10
|
||||
touch N_det psi_det psi_coef davidson_threshold davidson_criterion
|
||||
call diagonalize_CI_SC2
|
||||
pt2 = 0.d0
|
||||
|
||||
if(do_pt2_end)then
|
||||
threshold_selectors = 1.d0
|
||||
call H_apply_PT2(pt2, norm_pert, H_pert_diag, N_st)
|
||||
@ -97,6 +105,12 @@ program cisd_sc2_selected
|
||||
print*,'Degree of excitation of this determinant : ',degree
|
||||
|
||||
enddo
|
||||
|
||||
! =~=~=~=~=~=~=~=~=~=~=~=~=~!
|
||||
! W r i t e _ o n _ d i s k !
|
||||
! =~=~=~=~=~=~=~=~=~=~=~=~=~!
|
||||
|
||||
call ezfio_set_full_ci_energy_pt2(CI_SC2_energy(i)+pt2(i)* (1.d0 + norm_pert) - H_pert_diag(i))
|
||||
endif
|
||||
call save_wavefunction
|
||||
deallocate(pt2,norm_pert,H_pert_diag)
|
||||
|
@ -1,51 +0,0 @@
|
||||
BEGIN_PROVIDER [ integer, n_det_max_cisd_sc2 ]
|
||||
implicit none
|
||||
BEGIN_DOC
|
||||
! Get n_det_max_cisd_sc2 from EZFIO file
|
||||
END_DOC
|
||||
logical :: has_n_det_max_cisd_sc2
|
||||
PROVIDE ezfio_filename
|
||||
call ezfio_has_cisd_sc2_selected_n_det_max_cisd_sc2(has_n_det_max_cisd_sc2)
|
||||
if (has_n_det_max_cisd_sc2) then
|
||||
call ezfio_get_cisd_sc2_selected_n_det_max_cisd_sc2(n_det_max_cisd_sc2)
|
||||
else
|
||||
n_det_max_cisd_sc2 = 1000
|
||||
call ezfio_set_cisd_sc2_selected_n_det_max_cisd_sc2(n_det_max_cisd_sc2)
|
||||
endif
|
||||
print*,'n_det_max_cisd_sc2 = ',n_det_max_cisd_sc2
|
||||
END_PROVIDER
|
||||
|
||||
BEGIN_PROVIDER [ double precision , pt2_max ]
|
||||
implicit none
|
||||
BEGIN_DOC
|
||||
! Get pt2_max from EZFIO file
|
||||
END_DOC
|
||||
logical :: has_pt2_max
|
||||
PROVIDE ezfio_filename
|
||||
call ezfio_has_cisd_sc2_selected_pt2_max(has_pt2_max)
|
||||
if (has_pt2_max) then
|
||||
call ezfio_get_cisd_sc2_selected_pt2_max(pt2_max)
|
||||
else
|
||||
pt2_max = 1.d-3
|
||||
call ezfio_set_cisd_sc2_selected_pt2_max(pt2_max)
|
||||
endif
|
||||
print*,'pt2_max = ',pt2_max
|
||||
END_PROVIDER
|
||||
|
||||
BEGIN_PROVIDER [ logical, do_pt2_end ]
|
||||
implicit none
|
||||
BEGIN_DOC
|
||||
! Get do_pt2_end from EZFIO file
|
||||
END_DOC
|
||||
logical :: has_do_pt2_end
|
||||
PROVIDE ezfio_filename
|
||||
call ezfio_has_cisd_sc2_selected_do_pt2_end(has_do_pt2_end)
|
||||
if (has_do_pt2_end) then
|
||||
call ezfio_get_cisd_sc2_selected_do_pt2_end(do_pt2_end)
|
||||
else
|
||||
do_pt2_end = .True.
|
||||
call ezfio_set_cisd_sc2_selected_do_pt2_end(do_pt2_end)
|
||||
endif
|
||||
print*,'do_pt2_end = ',do_pt2_end
|
||||
END_PROVIDER
|
||||
|
@ -1,2 +1,2 @@
|
||||
AOs BiInts Bitmask CISD Dets Electrons Ezfio_files Hartree_Fock MOGuess MonoInts MOs Nuclei Output Perturbation Properties Selectors_full SingleRefMethod Utils
|
||||
AOs Bielec_integrals Bitmask CISD Dets Electrons Ezfio_files Hartree_Fock MOGuess MonoInts MOs Nuclei Output Perturbation Properties Selectors_full SingleRefMethod Utils
|
||||
|
||||
|
@ -1,2 +1,2 @@
|
||||
AOs BiInts Bitmask Dets Electrons Ezfio_files Generators_CAS Hartree_Fock MOGuess MonoInts MOs Nuclei Output Perturbation Properties Selectors_full Utils
|
||||
AOs Bielec_integrals Bitmask Dets Electrons Ezfio_files Generators_CAS Hartree_Fock MOGuess MonoInts MOs Nuclei Output Perturbation Properties Selectors_full Utils
|
||||
|
||||
|
@ -1 +1 @@
|
||||
AOs BiInts Bitmask Electrons Ezfio_files MonoInts MOs Nuclei Output Utils
|
||||
AOs Bielec_integrals Bitmask Electrons Ezfio_files MonoInts MOs Nuclei Output Utils
|
||||
|
@ -3,7 +3,7 @@ program det_svd
|
||||
BEGIN_DOC
|
||||
! Computes the SVD of the Alpha x Beta determinant coefficient matrix
|
||||
END_DOC
|
||||
integer :: i,j
|
||||
integer :: i,j,k
|
||||
|
||||
read_wf = .True.
|
||||
TOUCH read_wf
|
||||
@ -40,17 +40,22 @@ program det_svd
|
||||
print *, 'N_det_alpha = ', N_det_alpha_unique
|
||||
print *, 'N_det_beta = ', N_det_beta_unique
|
||||
print *, ''
|
||||
|
||||
! do i=1,N_det_alpha_unique
|
||||
! do j=1,N_det_beta_unique
|
||||
! print *, i,j,psi_svd_matrix(i,j,:)
|
||||
! enddo
|
||||
! enddo
|
||||
|
||||
print *, ''
|
||||
call diagonalize_ci
|
||||
print *, 'Energy = ', ci_energy
|
||||
|
||||
do i=1,N_det_alpha_unique
|
||||
do j=1,N_det_beta_unique
|
||||
do k=1,N_states
|
||||
if (dabs(psi_svd_matrix(i,j,k)) < 1.d-15) then
|
||||
psi_svd_matrix(i,j,k) = 0.d0
|
||||
endif
|
||||
enddo
|
||||
enddo
|
||||
enddo
|
||||
|
||||
print *, ''
|
||||
print *, psi_svd_coefs(1:20,1)
|
||||
! call save_wavefunction
|
||||
call save_wavefunction
|
||||
|
||||
end
|
||||
|
@ -42,8 +42,10 @@ subroutine save_dets_qmcchem
|
||||
enddo
|
||||
close(31)
|
||||
call system('gzip -f '//trim(ezfio_filename)//'/mo_basis/mo_classif')
|
||||
|
||||
end
|
||||
|
||||
program save_for_qmc
|
||||
call save_dets_qmcchem
|
||||
call write_spindeterminants
|
||||
end
|
||||
|
@ -7,4 +7,8 @@ spindeterminants
|
||||
psi_det_alpha integer*8 (spindeterminants_n_int*spindeterminants_bit_kind/8,spindeterminants_n_det_alpha)
|
||||
psi_det_beta integer*8 (spindeterminants_n_int*spindeterminants_bit_kind/8,spindeterminants_n_det_beta)
|
||||
psi_coef_matrix double precision (spindeterminants_n_det_alpha,spindeterminants_n_det_beta,spindeterminants_n_states)
|
||||
n_svd_coefs integer
|
||||
psi_svd_alpha double precision (spindeterminants_n_det_alpha,spindeterminants_n_svd_coefs,spindeterminants_n_states)
|
||||
psi_svd_beta double precision (spindeterminants_n_det_beta,spindeterminants_n_svd_coefs,spindeterminants_n_states)
|
||||
psi_svd_coefs double precision (spindeterminants_n_svd_coefs,spindeterminants_n_states)
|
||||
|
||||
|
@ -26,7 +26,7 @@ subroutine write_spindeterminants
|
||||
enddo
|
||||
call ezfio_set_spindeterminants_psi_det_alpha(psi_det_alpha_unique)
|
||||
deallocate(tmpdet)
|
||||
|
||||
|
||||
allocate(tmpdet(N_int2,N_det_beta_unique))
|
||||
do i=1,N_det_beta_unique
|
||||
do k=1,N_int
|
||||
@ -38,7 +38,54 @@ subroutine write_spindeterminants
|
||||
enddo
|
||||
call ezfio_set_spindeterminants_psi_det_beta(psi_det_beta_unique)
|
||||
deallocate(tmpdet)
|
||||
|
||||
|
||||
call ezfio_set_spindeterminants_psi_coef_matrix(psi_svd_matrix)
|
||||
|
||||
integer :: n_svd_coefs
|
||||
double precision :: norm, f
|
||||
f = 1.d0/dble(N_states)
|
||||
norm = 1.d0
|
||||
do n_svd_coefs=1,N_det_alpha_unique
|
||||
do k=1,N_states
|
||||
norm -= psi_svd_coefs(n_svd_coefs,k)*psi_svd_coefs(n_svd_coefs,k)
|
||||
enddo
|
||||
if (norm < 1.d-6) then
|
||||
exit
|
||||
endif
|
||||
enddo
|
||||
n_svd_coefs -= 1
|
||||
call ezfio_set_spindeterminants_n_svd_coefs(n_svd_coefs)
|
||||
|
||||
double precision, allocatable :: dtmp(:,:,:)
|
||||
allocate(dtmp(N_det_alpha_unique,n_svd_coefs,N_states))
|
||||
do k=1,N_states
|
||||
do j=1,n_svd_coefs
|
||||
do i=1,N_det_alpha_unique
|
||||
dtmp(i,j,k) = psi_svd_alpha(i,j,k)
|
||||
enddo
|
||||
enddo
|
||||
enddo
|
||||
call ezfio_set_spindeterminants_psi_svd_alpha(dtmp)
|
||||
deallocate(dtmp)
|
||||
|
||||
allocate(dtmp(N_det_beta_unique,n_svd_coefs,N_states))
|
||||
do k=1,N_states
|
||||
do j=1,n_svd_coefs
|
||||
do i=1,N_det_beta_unique
|
||||
dtmp(i,j,k) = psi_svd_beta(i,j,k)
|
||||
enddo
|
||||
enddo
|
||||
enddo
|
||||
call ezfio_set_spindeterminants_psi_svd_beta(dtmp)
|
||||
deallocate(dtmp)
|
||||
|
||||
allocate(dtmp(n_svd_coefs,N_states,1))
|
||||
do k=1,N_states
|
||||
do j=1,n_svd_coefs
|
||||
dtmp(j,k,1) = psi_svd_coefs(j,k)
|
||||
enddo
|
||||
enddo
|
||||
call ezfio_set_spindeterminants_psi_svd_coefs(dtmp)
|
||||
deallocate(dtmp)
|
||||
|
||||
end
|
||||
|
@ -1 +1 @@
|
||||
AOs BiInts Bitmask Dets Electrons Ezfio_files MonoInts MOs Nuclei Output Utils
|
||||
AOs Bielec_integrals Bitmask Dets Electrons Ezfio_files MonoInts MOs Nuclei Output Utils
|
||||
|
@ -18,7 +18,7 @@ default: true
|
||||
|
||||
[PT2_max]
|
||||
type: PT2_energy
|
||||
doc: The selection process stops when the largest PT2 (for all the state is lower
|
||||
doc: The selection process stops when the largest PT2 (for all the state) is lower
|
||||
than pt2_max in absolute value
|
||||
interface: input
|
||||
default: 0.0001
|
||||
@ -32,11 +32,11 @@ default: 0.75
|
||||
|
||||
[energy]
|
||||
type: double precision
|
||||
doc: "Calculated Full CI energy"
|
||||
doc: Calculated Selected FCI energy
|
||||
interface: output
|
||||
|
||||
[energy_pt2]
|
||||
type: double precision
|
||||
doc: "Calculated Full CI energy"
|
||||
doc: Calculated FCI energy + PT2
|
||||
interface: output
|
||||
|
||||
|
@ -1,2 +1,2 @@
|
||||
AOs BiInts Bitmask Dets Electrons Ezfio_files Generators_full Hartree_Fock MOGuess MonoInts MOs Nuclei Output Perturbation Properties Selectors_full Utils
|
||||
AOs Bielec_integrals Bitmask Dets Electrons Ezfio_files Generators_full Hartree_Fock MOGuess MonoInts MOs Nuclei Output Perturbation Properties Selectors_full Utils
|
||||
|
||||
|
@ -1 +1 @@
|
||||
AOs BiInts Bitmask Dets Electrons Ezfio_files MonoInts MOs Nuclei Output Utils
|
||||
AOs Bielec_integrals Bitmask Dets Electrons Ezfio_files MonoInts MOs Nuclei Output Utils
|
||||
|
@ -1,2 +1,2 @@
|
||||
AOs BiInts Bitmask Dets Electrons Ezfio_files Hartree_Fock MOGuess MonoInts MOs Nuclei Output Utils
|
||||
AOs Bielec_integrals Bitmask Dets Electrons Ezfio_files Hartree_Fock MOGuess MonoInts MOs Nuclei Output Utils
|
||||
|
||||
|
@ -1 +1 @@
|
||||
AOs BiInts Bitmask Dets Electrons Ezfio_files MonoInts MOs Nuclei Output Utils
|
||||
AOs Bielec_integrals Bitmask Dets Electrons Ezfio_files MonoInts MOs Nuclei Output Utils
|
||||
|
22
src/Hartree_Fock/EZFIO.cfg
Normal file
22
src/Hartree_Fock/EZFIO.cfg
Normal file
@ -0,0 +1,22 @@
|
||||
[thresh_scf]
|
||||
type: Threshold
|
||||
doc: Threshold on the convergence of the Hartree Fock energy
|
||||
interface: input
|
||||
default: 1.e-10
|
||||
|
||||
[n_it_scf_max]
|
||||
type: Strictly_positive_int
|
||||
doc: Maximum number of SCF iterations
|
||||
interface: input
|
||||
default: 200
|
||||
|
||||
[mo_guess_type]
|
||||
type: MO_guess
|
||||
doc: Initial MO guess. Can be [ Huckel | HCore ]
|
||||
interface: input
|
||||
default: Huckel
|
||||
|
||||
[energy]
|
||||
type: double precision
|
||||
doc: Calculated HF energy
|
||||
interface: output
|
@ -1 +1 @@
|
||||
AOs BiInts Bitmask Electrons Ezfio_files MonoInts MOGuess MOs Nuclei Output Utils
|
||||
AOs Bielec_integrals Bitmask Electrons Ezfio_files MonoInts MOGuess MOs Nuclei Output Utils
|
||||
|
@ -1,6 +0,0 @@
|
||||
hartree_fock
|
||||
thresh_scf double precision
|
||||
n_it_scf_max integer
|
||||
energy double precision
|
||||
guess character*(32)
|
||||
|
@ -1,35 +0,0 @@
|
||||
BEGIN_SHELL [ /usr/bin/python ]
|
||||
from ezfio_with_default import EZFIO_Provider
|
||||
T = EZFIO_Provider()
|
||||
T.set_type ( "double precision" )
|
||||
T.set_name ( "thresh_SCF" )
|
||||
T.set_doc ( "Threshold on the convergence of the Hartree Fock energy" )
|
||||
T.set_ezfio_dir ( "Hartree_Fock" )
|
||||
T.set_ezfio_name( "thresh_SCF" )
|
||||
T.set_output ( "output_Hartree_Fock" )
|
||||
print T
|
||||
|
||||
T = EZFIO_Provider()
|
||||
T.set_type ( "integer" )
|
||||
T.set_name ( "n_it_scf_max" )
|
||||
T.set_doc ( "Maximum number of SCF iterations" )
|
||||
T.set_ezfio_dir ( "Hartree_Fock" )
|
||||
T.set_ezfio_name( "n_it_scf_max" )
|
||||
T.set_output ( "output_Hartree_Fock" )
|
||||
print T
|
||||
|
||||
T = EZFIO_Provider()
|
||||
T.set_type ( "character*(32)" )
|
||||
T.set_name ( "mo_guess_type" )
|
||||
T.set_doc ( "Initial MO guess. Can be [ Huckel | HCore ]" )
|
||||
T.set_ezfio_dir ( "Hartree_Fock" )
|
||||
T.set_ezfio_name( "guess" )
|
||||
T.set_output ( "output_Hartree_Fock" )
|
||||
print T
|
||||
|
||||
|
||||
END_SHELL
|
||||
|
||||
|
||||
|
||||
|
@ -1,2 +1,2 @@
|
||||
AOs BiInts Bitmask Dets Electrons Ezfio_files Hartree_Fock MOGuess MonoInts MOs Nuclei Output Perturbation Properties Selectors_full SingleRefMethod Utils
|
||||
AOs Bielec_integrals Bitmask Dets Electrons Ezfio_files Hartree_Fock MOGuess MonoInts MOs Nuclei Output Perturbation Properties Selectors_full SingleRefMethod Utils
|
||||
|
||||
|
@ -1,5 +1,4 @@
|
||||
[energy]
|
||||
type: double precision
|
||||
doc: "Calculated MRCC energy"
|
||||
interface: output
|
||||
|
||||
doc: Calculated MRCC energy
|
||||
interface: output
|
@ -1,2 +1,2 @@
|
||||
AOs BiInts Bitmask Dets Electrons Ezfio_files Generators_full Hartree_Fock MOGuess MonoInts MOs Nuclei Output Perturbation Properties Selectors_full Utils
|
||||
AOs Bielec_integrals Bitmask Dets Electrons Ezfio_files Generators_full Hartree_Fock MOGuess MonoInts MOs Nuclei Output Perturbation Properties Selectors_full Utils
|
||||
|
||||
|
@ -1,82 +1,9 @@
|
||||
E(CAS+SD) = -3.93510180989509
|
||||
|
||||
-0.726935163332
|
||||
++++----
|
||||
++++----
|
||||
|
||||
0.685482292841
|
||||
+++-+---
|
||||
+++-+---
|
||||
|
||||
0.0409791961003
|
||||
++-+-+--
|
||||
++-+-+--
|
||||
|
||||
c2*c3/c1 = -0.038642391672
|
||||
|
||||
|
||||
-0.996413146877
|
||||
++++----
|
||||
++++----
|
||||
|
||||
-0.0598366139154
|
||||
++-+-+--
|
||||
+++-+---
|
||||
|
||||
-0.0598366139154
|
||||
+++-+---
|
||||
++-+-+--
|
||||
|
||||
|
||||
=======
|
||||
|
||||
0.706616635698
|
||||
+++-+---
|
||||
+++-+---
|
||||
|
||||
-0.692594178414
|
||||
++++----
|
||||
++++----
|
||||
|
||||
-0.0915716740265
|
||||
++-+-+--
|
||||
+++-+---
|
||||
|
||||
-0.0915716740265
|
||||
+++-+---
|
||||
++-+-+--
|
||||
|
||||
0.0461418323107
|
||||
++-+-+--
|
||||
++-+-+--
|
||||
|
||||
-0.0458957789452
|
||||
++--++--
|
||||
++--++--
|
||||
|
||||
|
||||
----
|
||||
|
||||
0.713102867186
|
||||
++++----
|
||||
++++----
|
||||
|
||||
-0.688067688244
|
||||
+++-+---
|
||||
+++-+---
|
||||
|
||||
0.089262694488
|
||||
+++-+---
|
||||
++-+-+--
|
||||
|
||||
0.089262694488
|
||||
++-+-+--
|
||||
+++-+---
|
||||
|
||||
-0.0459510603899
|
||||
++-+-+--
|
||||
++-+-+--
|
||||
|
||||
|
||||
===========
|
||||
MRCC Module
|
||||
===========
|
||||
|
||||
Needed Modules
|
||||
==============
|
||||
|
||||
Documentation
|
||||
=============
|
||||
|
@ -1 +1 @@
|
||||
AOs BiInts Bitmask CID CID_SC2_selected CID_selected CIS CISD CISD_selected CISD_SC2_selected Dets Electrons Ezfio_files Full_CI Generators_full Hartree_Fock MOGuess MonoInts MOs MP2 Nuclei Output Selectors_full Utils Molden FCIdump Generators_CAS CAS_SD DDCI_selected MRCC
|
||||
AOs Bielec_integrals Bitmask CID CID_SC2_selected CID_selected CIS CISD CISD_selected CISD_SC2_selected Dets Electrons Ezfio_files Full_CI Generators_full Hartree_Fock MOGuess MonoInts MOs MP2 Nuclei Output Selectors_full Utils Molden FCIdump Generators_CAS CAS_SD DDCI_selected MRCC
|
||||
|
@ -1,2 +1,2 @@
|
||||
AOs BiInts Bitmask Dets Electrons Ezfio_files Hartree_Fock MOGuess MonoInts MOs Nuclei Output Properties Utils
|
||||
AOs Bielec_integrals Bitmask Dets Electrons Ezfio_files Hartree_Fock MOGuess MonoInts MOs Nuclei Output Properties Utils
|
||||
|
||||
|
@ -1 +1 @@
|
||||
AOs BiInts Bitmask Dets Electrons Ezfio_files MonoInts MOs Nuclei Output Utils
|
||||
AOs Bielec_integrals Bitmask Dets Electrons Ezfio_files MonoInts MOs Nuclei Output Utils
|
||||
|
@ -1,2 +1,2 @@
|
||||
AOs BiInts Bitmask Dets Electrons Ezfio_files Hartree_Fock MOGuess MonoInts MOs Nuclei Output Utils
|
||||
AOs Bielec_integrals Bitmask Dets Electrons Ezfio_files Hartree_Fock MOGuess MonoInts MOs Nuclei Output Utils
|
||||
|
||||
|
@ -1 +1 @@
|
||||
AOs BiInts Bitmask Dets Electrons Ezfio_files MonoInts MOs Nuclei Output Utils
|
||||
AOs Bielec_integrals Bitmask Dets Electrons Ezfio_files MonoInts MOs Nuclei Output Utils
|
||||
|
309
tests/unit_test/unit_test.py
Executable file
309
tests/unit_test/unit_test.py
Executable file
@ -0,0 +1,309 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
import unittest
|
||||
import subprocess
|
||||
import os
|
||||
import sys
|
||||
|
||||
qpackage_root = os.environ['QPACKAGE_ROOT']
|
||||
|
||||
EZFIO = "{0}/EZFIO".format(qpackage_root)
|
||||
sys.path = [EZFIO + "/Python"] + sys.path
|
||||
|
||||
from ezfio import ezfio
|
||||
from collections import defaultdict
|
||||
|
||||
# ~#~#~ #
|
||||
# O p t #
|
||||
# ~#~#~ #
|
||||
|
||||
precision = 5.e-8
|
||||
|
||||
# A test get a geo file and a basis file.
|
||||
# A global dict containt the result for this test
|
||||
# A test return True or Raise a error !
|
||||
# More ezfio condition you set, beter it is
|
||||
|
||||
|
||||
# You cannot order the test flow.
|
||||
# So if you dont whant to remarque on test (for example the HF), set
|
||||
# a global variable and check for it
|
||||
global has_hf_alredy
|
||||
has_hf_alredy = False
|
||||
|
||||
global filename_check
|
||||
|
||||
|
||||
def init_folder(geo, basis, mult=1, ezfio_name=None):
|
||||
'''
|
||||
Take a geo in arg (aka a existing geo.xyz in test/)
|
||||
And create the geo.ezfio with the adeguate basis and multipliciti
|
||||
DO NOT CHECK IS THE EZFIO FOLDER ALREADY EXIST
|
||||
'''
|
||||
|
||||
cmd = "cp {0}/tests/{1}.xyz .".format(qpackage_root, geo)
|
||||
subprocess.check_call([cmd], shell=True)
|
||||
|
||||
if not ezfio_name:
|
||||
ezfio_name = geo
|
||||
|
||||
cmd = "qp_create_ezfio_from_xyz -b {0} -m {1} {2}.xyz -o {3}.ezfio"
|
||||
subprocess.check_call([cmd.format(basis, mult, geo, ezfio_name)],
|
||||
shell=True)
|
||||
|
||||
|
||||
def get_error_message(l_exepected, l_cur):
|
||||
l_msg = ["Need {0} get {1} error is {2}".format(i, j, abs(i - j))
|
||||
for i, j in zip(l_exepected, l_cur)]
|
||||
return "\n".join(l_msg)
|
||||
|
||||
|
||||
# _
|
||||
# / |_ _ _ | o ._ ._ _|_
|
||||
# \_ | | (/_ (_ |< | | | |_) |_| |_
|
||||
# |
|
||||
|
||||
def check_disk_acess(geo, basis, mult=1):
|
||||
|
||||
import uuid
|
||||
filename = str(uuid.uuid4())
|
||||
|
||||
# ~#~#~#~ #
|
||||
# I n i t #
|
||||
# ~#~#~#~ #
|
||||
|
||||
init_folder(geo, basis, mult, ezfio_name=filename)
|
||||
ezfio.set_file("{0}.ezfio".format(filename))
|
||||
|
||||
# ~#~#~#~#~#~#~#~#~#~#~#~#~ #
|
||||
# S e t _ p a r a m e t e r #
|
||||
# ~#~#~#~#~#~#~#~#~#~#~#~#~ #
|
||||
|
||||
# Test 1
|
||||
ezfio.bielec_integrals_disk_access_ao_integrals = "Write"
|
||||
cmd = "qp_edit -c {0}.ezfio".format(filename)
|
||||
subprocess.check_call([cmd], shell=True)
|
||||
|
||||
# Test 2
|
||||
ezfio.bielec_integrals_disk_access_ao_integrals = "IculeAcess"
|
||||
cmd = "qp_edit -c {0}.ezfio".format(filename)
|
||||
|
||||
try:
|
||||
subprocess.check_call([cmd], shell=True)
|
||||
return_code = False
|
||||
except subprocess.CalledProcessError:
|
||||
return_code = True
|
||||
|
||||
# ~#~#~#~#~#~#~#~ #
|
||||
# F i n a l i z e #
|
||||
# ~#~#~#~#~#~#~#~ #
|
||||
|
||||
if return_code:
|
||||
subprocess.call(["rm -R {0}.ezfio".format(filename)], shell=True)
|
||||
return return_code
|
||||
|
||||
|
||||
def check_mo_guess(geo, basis, mult=1):
|
||||
|
||||
import uuid
|
||||
filename = str(uuid.uuid4())
|
||||
|
||||
# ~#~#~#~ #
|
||||
# I n i t #
|
||||
# ~#~#~#~ #
|
||||
|
||||
init_folder(geo, basis, mult, ezfio_name=filename)
|
||||
ezfio.set_file("{0}.ezfio".format(filename))
|
||||
|
||||
# ~#~#~#~#~#~#~#~#~#~#~#~#~ #
|
||||
# S e t _ p a r a m e t e r #
|
||||
# ~#~#~#~#~#~#~#~#~#~#~#~#~ #
|
||||
|
||||
# Test 1
|
||||
ezfio.hartree_fock_mo_guess_type = "Huckel"
|
||||
cmd = "qp_edit -c {0}.ezfio".format(filename)
|
||||
subprocess.check_call([cmd], shell=True)
|
||||
|
||||
# Test 2
|
||||
ezfio.hartree_fock_mo_guess_type = "IculeGuess"
|
||||
cmd = "qp_edit -c {0}.ezfio".format(filename)
|
||||
|
||||
try:
|
||||
subprocess.check_call([cmd], shell=True)
|
||||
return_code = False
|
||||
except subprocess.CalledProcessError:
|
||||
return_code = True
|
||||
|
||||
# ~#~#~#~#~#~#~#~ #
|
||||
# F i n a l i z e #
|
||||
# ~#~#~#~#~#~#~#~ #
|
||||
|
||||
if return_code:
|
||||
subprocess.call(["rm -R {0}.ezfio".format(filename)], shell=True)
|
||||
return return_code
|
||||
|
||||
|
||||
# _
|
||||
# / |_ _ _ | _. | _ _
|
||||
# \_ | | (/_ (_ |< \/ (_| | |_| (/_ _>
|
||||
#
|
||||
|
||||
|
||||
def run_hf(geo, basis, mult=1):
|
||||
"""
|
||||
Run a simle by default hf
|
||||
EZFIO path = geo.ezfio
|
||||
"""
|
||||
# ~#~#~#~#~#~#~#~#~#~ #
|
||||
# R e f _ e n e r g y #
|
||||
# ~#~#~#~#~#~#~#~#~#~ #
|
||||
|
||||
ref_energy = defaultdict(dict)
|
||||
|
||||
ref_energy["sto-3g"]["methane"] = -39.7267433402
|
||||
|
||||
# ~#~#~#~#~#~#~#~#~#~#~#~#~#~#~ #
|
||||
# G l o b a l _ v a r i a b l e #
|
||||
# ~#~#~#~#~#~#~#~#~#~#~#~#~#~#~ #
|
||||
|
||||
global has_hf_alredy
|
||||
has_hf_alredy = True
|
||||
|
||||
# ~#~#~#~ #
|
||||
# I n i t #
|
||||
# ~#~#~#~ #
|
||||
|
||||
init_folder(geo, basis, mult)
|
||||
ezfio.set_file("{0}.ezfio".format(geo))
|
||||
|
||||
# ~#~#~#~#~#~#~#~#~#~#~#~#~ #
|
||||
# S e t _ p a r a m e t e r #
|
||||
# ~#~#~#~#~#~#~#~#~#~#~#~#~ #
|
||||
ezfio.bielec_integrals_direct = False
|
||||
ezfio.bielec_integrals_threshold_ao = 1.e-15
|
||||
ezfio.bielec_integrals_disk_access_ao_integrals = "None"
|
||||
|
||||
ezfio.bielec_integrals_threshold_mo = 1.e-15
|
||||
ezfio.bielec_integrals_disk_access_mo_integrals = "None"
|
||||
|
||||
ezfio.hartree_fock_mo_guess_type = "Huckel"
|
||||
ezfio.hartree_fock_thresh_scf = 1.e-10
|
||||
ezfio.hartree_fock_n_it_scf_max = 100
|
||||
|
||||
# ~#~#~ #
|
||||
# R u n #
|
||||
# ~#~#~ #
|
||||
|
||||
cmd = "qp_run SCF {0}.ezfio/".format(geo)
|
||||
subprocess.check_call([cmd], shell=True)
|
||||
|
||||
# ~#~#~#~#~ #
|
||||
# C h e c k #
|
||||
# ~#~#~#~#~ #
|
||||
|
||||
cur_e = ezfio.get_hartree_fock_energy()
|
||||
ref_e = ref_energy[basis][geo]
|
||||
|
||||
if abs(cur_e - ref_e) <= precision:
|
||||
return True
|
||||
else:
|
||||
raise ValueError(get_error_message([ref_e], [cur_e]))
|
||||
|
||||
|
||||
def run_full_ci_10k_pt2_end(geo, basis):
|
||||
"""
|
||||
Run a Full_ci with 10k with the TruePT2
|
||||
EZFIO path = geo.ezfio
|
||||
"""
|
||||
|
||||
# ~#~#~#~#~#~#~#~#~#~ #
|
||||
# R e f _ e n e r g y #
|
||||
# ~#~#~#~#~#~#~#~#~#~ #
|
||||
|
||||
ref_energy_var = defaultdict(dict)
|
||||
ref_energy_pt2 = defaultdict(dict)
|
||||
|
||||
ref_energy_var["sto-3g"]["methane"] = -0.398058753535695E+02
|
||||
ref_energy_pt2["sto-3g"]["methane"] = -0.398059182483741E+02
|
||||
|
||||
# ~#~#~#~ #
|
||||
# I n i t #
|
||||
# ~#~#~#~ #
|
||||
|
||||
ezfio.set_file("{0}.ezfio".format(geo))
|
||||
|
||||
# ~#~#~#~#~#~#~#~#~#~#~#~#~ #
|
||||
# S e t _ p a r a m e t e r #
|
||||
# ~#~#~#~#~#~#~#~#~#~#~#~#~ #
|
||||
|
||||
ezfio.full_ci_do_pt2_end = True
|
||||
ezfio.full_ci_n_det_max_fci = 10000
|
||||
ezfio.full_ci_pt2_max = 1.e-8
|
||||
|
||||
# ~#~#~ #
|
||||
# R u n #
|
||||
# ~#~#~ #
|
||||
|
||||
cmd = "qp_run full_ci {0}.ezfio/".format(geo)
|
||||
subprocess.check_call([cmd], shell=True)
|
||||
|
||||
# ~#~#~#~#~ #
|
||||
# C h e c k #
|
||||
# ~#~#~#~#~ #
|
||||
|
||||
cur_var = ezfio.get_full_ci_energy()
|
||||
cur_pt2 = ezfio.get_full_ci_energy_pt2()
|
||||
|
||||
ref_var = ref_energy_var[basis][geo]
|
||||
ref_pt2 = ref_energy_pt2[basis][geo]
|
||||
|
||||
t = [abs(cur_var - ref_var) <= precision,
|
||||
abs(cur_pt2 - ref_pt2) <= precision]
|
||||
|
||||
if all(t):
|
||||
return True
|
||||
else:
|
||||
raise ValueError(get_error_message([ref_var, ref_pt2],
|
||||
[cur_var, cur_pt2]))
|
||||
|
||||
|
||||
def hf_then_10k_test(geo, basis):
|
||||
if not has_hf_alredy:
|
||||
run_hf(geo, basis)
|
||||
|
||||
try:
|
||||
run_full_ci_10k_pt2_end(geo, basis)
|
||||
return_code = True
|
||||
except:
|
||||
return_code = False
|
||||
|
||||
# ~#~#~#~#~#~#~#~ #
|
||||
# F i n a l i z e #
|
||||
# ~#~#~#~#~#~#~#~ #
|
||||
|
||||
if return_code:
|
||||
subprocess.call(["rm -R {0}.ezfio".format(geo)], shell=True)
|
||||
return return_code
|
||||
|
||||
|
||||
# ___
|
||||
# | _ _ _|_
|
||||
# | (/_ _> |_
|
||||
#
|
||||
class ValueTest(unittest.TestCase):
|
||||
|
||||
def test_full_ci_10k_pt2_end(self):
|
||||
self.assertTrue(hf_then_10k_test("methane", "sto-3g"))
|
||||
|
||||
|
||||
class InputTest(unittest.TestCase):
|
||||
|
||||
def test_check_disk_acess(self):
|
||||
self.assertTrue(check_disk_acess("methane", "un-ccemd-ref"))
|
||||
|
||||
def test_check_mo_guess(self):
|
||||
self.assertTrue(check_mo_guess("methane", "maug-cc-pVDZ"))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
Loading…
Reference in New Issue
Block a user