mirror of
https://github.com/LCPQ/quantum_package
synced 2024-08-25 05:51:46 +02:00
commit
98da6c7a3e
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
|
||||
|
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
|
||||
|
0
data/ezfio_defaults/.empty
Normal file
0
data/ezfio_defaults/.empty
Normal file
9
data/ezfio_defaults/bi_integrals.ezfio_default
Normal file
9
data/ezfio_defaults/bi_integrals.ezfio_default
Normal file
@ -0,0 +1,9 @@
|
||||
bielec_integrals
|
||||
read_ao_integrals False
|
||||
read_mo_integrals False
|
||||
write_ao_integrals False
|
||||
write_mo_integrals False
|
||||
threshold_ao 1.e-15
|
||||
threshold_mo 1.e-15
|
||||
direct False
|
||||
|
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
|
||||
|
5
data/ezfio_defaults/cisd_sc2.ezfio_default
Normal file
5
data/ezfio_defaults/cisd_sc2.ezfio_default
Normal file
@ -0,0 +1,5 @@
|
||||
cisd_sc2_selected
|
||||
n_det_max_cisd_sc2 10000
|
||||
pt2_max 1.e-4
|
||||
do_pt2_end True
|
||||
|
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
|
@ -7,6 +7,7 @@ include Input_ao_basis;;
|
||||
include Input_bi_integrals;;
|
||||
include Input_bitmasks;;
|
||||
include Input_cisd_sc2;;
|
||||
include Input_cisd_sc2_selected;;
|
||||
include Input_determinants;;
|
||||
include Input_electrons;;
|
||||
include Input_full_ci;;
|
||||
@ -14,4 +15,3 @@ include Input_hartree_fock;;
|
||||
include Input_mo_basis;;
|
||||
include Input_nuclei;;
|
||||
|
||||
|
||||
|
@ -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.lowercase (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
|
||||
;;
|
||||
|
||||
|
@ -13,6 +13,7 @@ type keyword =
|
||||
| Ao_basis
|
||||
| Bielec_integrals
|
||||
| Cisd_sc2
|
||||
| Cisd_sc2_selected
|
||||
| Determinants
|
||||
| Electrons
|
||||
| Full_ci
|
||||
@ -26,6 +27,7 @@ let keyword_to_string = function
|
||||
| Ao_basis -> "AO basis"
|
||||
| Bielec_integrals -> "Two electron integrals"
|
||||
| Cisd_sc2 -> "CISD (SC)^2"
|
||||
| Cisd_sc2_selected -> "CISD (SC)^2 selected"
|
||||
| Determinants -> "Determinants"
|
||||
| Electrons -> "Electrons"
|
||||
| Full_ci -> "Selected Full-CI"
|
||||
@ -80,6 +82,8 @@ let get s =
|
||||
f Electrons.(read, to_rst)
|
||||
| Cisd_sc2 ->
|
||||
f Cisd_sc2.(read, to_rst)
|
||||
| Cisd_sc2_selected ->
|
||||
f Cisd_sc2_selected.(read, to_rst)
|
||||
| Nuclei ->
|
||||
f Nuclei.(read, to_rst)
|
||||
| Ao_basis ->
|
||||
@ -129,6 +133,7 @@ let set str s =
|
||||
| Full_ci -> write Full_ci.(of_rst, write) s
|
||||
| Electrons -> write Electrons.(of_rst, write) s
|
||||
| Cisd_sc2 -> write Cisd_sc2.(of_rst, write) s
|
||||
| Cisd_sc2_selected -> write Cisd_sc2_selected.(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
|
||||
@ -179,6 +184,7 @@ let run check_only ezfio_filename =
|
||||
Bielec_integrals ;
|
||||
Hartree_fock ;
|
||||
Cisd_sc2 ;
|
||||
Cisd_sc2_selected ;
|
||||
Full_ci ;
|
||||
Mo_basis;
|
||||
Determinants ;
|
||||
|
@ -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"] == "output":
|
||||
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 += 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()
|
5
scripts/ezfio_interface/convert_ezfio.sh
Normal file
5
scripts/ezfio_interface/convert_ezfio.sh
Normal file
@ -0,0 +1,5 @@
|
||||
#!/bin/bash
|
||||
# Convert a old ezfio file (with option.irp.f ezfio_default)
|
||||
# into a new EZFIO.cfg type
|
||||
mv $1/Hartree_Fock $1/hartree_fock
|
||||
mv $1/hartree_Fock/thresh_SCF $1/hartree_fock/thresh_scf
|
640
scripts/ezfio_interface/ei_handler.py
Executable file
640
scripts/ezfio_interface/ei_handler.py
Executable file
@ -0,0 +1,640 @@
|
||||
#!/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
|
||||
Ezfio_dir : is equal to MODULE.lower!
|
||||
|
||||
|
||||
Format specification :
|
||||
[provider_name] : the name of the provider in irp.f90
|
||||
- doc : Is the doc
|
||||
- Type : Is a fancy_type support by the ocaml
|
||||
- ezfio_name : Will be the name of the file for the ezfio
|
||||
(optional by default is the name of the provider)
|
||||
- interface : The provider is a imput or a output
|
||||
- default : The default value if interface == input:
|
||||
- size : Is the string read in ezfio.cgf who containt the size information
|
||||
(like 1 or =sum(ao_num) or (ao_num,3) )
|
||||
|
||||
Example 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
|
||||
```
|
||||
|
||||
"""
|
||||
|
||||
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 convert into
|
||||
fortran and ocaml one.
|
||||
"""
|
||||
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 Ocam 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['MO_guess'] = Type("MO_guess", "string", "character*(32)")
|
||||
|
||||
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
|
||||
src = qpackage_root + "/ocaml/qptypes_generator.ml"
|
||||
with open(src, "r") as f:
|
||||
l = [i for i in f.read().splitlines() if i.strip().startswith("*")]
|
||||
|
||||
# Read the fancy_type, the ocaml. and convert the ocam to the fortran
|
||||
for i in l:
|
||||
str_fancy_type = i.split()[1].strip()
|
||||
str_ocaml_type = i.split()[3]
|
||||
str_fortran_type = ocaml_to_fortran[str_ocaml_type]
|
||||
|
||||
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)
|
||||
|
||||
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_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_provider = []
|
||||
l_type = []
|
||||
l_doc = []
|
||||
|
||||
for k, v in dict_ezfio_cfg.iteritems():
|
||||
if v['interface'] == "input":
|
||||
l_provider.append(k)
|
||||
l_type.append(v["type"])
|
||||
l_doc.append(v["doc"])
|
||||
|
||||
e_glob = EZFIO_ocaml(l_provider=l_provider,
|
||||
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 "full_ci";;',
|
||||
'']
|
||||
|
||||
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 main():
|
||||
"""
|
||||
Two condition:
|
||||
-Take the EZFIO.cfg path in arg
|
||||
or
|
||||
-Look if EZFIO.cfg is present in the pwd
|
||||
|
||||
Return : - ezfio_interface.irp.f
|
||||
- folder_ezfio_inteface_config
|
||||
"""
|
||||
|
||||
# ~#~#~#~# #
|
||||
# I n i t #
|
||||
# ~#~#~#~# #
|
||||
|
||||
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)
|
||||
|
||||
# ~#~#~#~#~#~#~#~#~#~#~#~#~#~# #
|
||||
# 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 c a m l #
|
||||
# ~#~#~#~#~#~#
|
||||
|
||||
str_ocaml_input = create_ocaml_input(dict_ezfio_cfg, module_lower)
|
||||
save_ocaml_input(module_lower, str_ocaml_input)
|
||||
|
||||
# ~#~#~#~#~#~#~#~#
|
||||
# I R P . f 9 0 #
|
||||
# ~#~#~#~#~#~#~#~#
|
||||
|
||||
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 #
|
||||
# ~#~#~#~#~#~#~#~#~#~#~#~# #
|
||||
|
||||
str_ezfio_config = create_ezfio_config(dict_ezfio_cfg)
|
||||
save_ezfio_config(module_lower, str_ezfio_config)
|
||||
|
||||
# ~#~#~#~#~#~#~#~#~#~#~#~#~#~ #
|
||||
# e z f i o _ d e f a u l t #
|
||||
# ~#~#~#~#~#~#~#~#~#~#~#~#~#~ #
|
||||
|
||||
str_ezfio_default = create_ezfio_default(dict_ezfio_cfg)
|
||||
save_ezfio_default(module_lower, str_ezfio_default)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
326
scripts/ezfio_interface/ezfio_generate_ocaml.py
Executable file
326
scripts/ezfio_interface/ezfio_generate_ocaml.py
Executable file
@ -0,0 +1,326 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import sys
|
||||
|
||||
# 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_provider = [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_provider", "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_provider, 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_provider = [provider_name, ...]
|
||||
|
||||
Return the read_global template
|
||||
'''
|
||||
# ~#~#~#~#~#~#~#~ #
|
||||
# C h e c k i n g #
|
||||
# ~#~#~#~#~#~#~#~ #
|
||||
|
||||
self.check_if_init(["l_provider"],
|
||||
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_provider]
|
||||
|
||||
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_provider = [provider_name, ...]
|
||||
|
||||
Return the type template
|
||||
'''
|
||||
# ~#~#~#~#~#~#~#~ #
|
||||
# C h e c k i n g #
|
||||
# ~#~#~#~#~#~#~#~ #
|
||||
|
||||
self.check_if_init(["l_provider"],
|
||||
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_provider]
|
||||
l_template += [" } ="]
|
||||
l_template += [" write_{0:<30} {0};".format(p) for p in self.l_provider]
|
||||
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_provider = [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_provider", "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_provider]
|
||||
l_template += ['"']
|
||||
|
||||
for p, t in zip(self.l_provider, 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_provider = [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_provider", "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_provider, self.l_doc):
|
||||
|
||||
l_template += ["{0} ::".format(d),
|
||||
"",
|
||||
" {0} = %s".format(p),
|
||||
""]
|
||||
l_template += ['"']
|
||||
|
||||
for p, t in zip(self.l_provider, 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)
|
96
scripts/ezfio_interface/ezfio_generate_provider.py
Executable file
96
scripts/ezfio_interface/ezfio_generate_provider.py
Executable file
@ -0,0 +1,96 @@
|
||||
#!/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.
|
||||
"""
|
||||
|
||||
|
||||
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()
|
@ -90,10 +90,19 @@ END_PROVIDER
|
||||
self.default = t
|
||||
|
||||
def get_default(self):
|
||||
filename = '/'.join( [os.environ['QPACKAGE_ROOT'], 'data', 'ezfio_defaults'] )
|
||||
file = open(filename,'r')
|
||||
lines = file.readlines()
|
||||
file.close()
|
||||
|
||||
from os import listdir
|
||||
from os.path import isfile, join
|
||||
|
||||
mypath = '/'.join( [os.environ['QPACKAGE_ROOT'], 'data', 'ezfio_defaults','/'])
|
||||
onlyfiles = [ f for f in listdir(mypath) if isfile(join(mypath,f)) ]
|
||||
|
||||
lines= []
|
||||
for filename in onlyfiles:
|
||||
file = open(mypath+filename,'r')
|
||||
lines.extend(file.readlines()[:])
|
||||
file.close()
|
||||
|
||||
# Search directory
|
||||
for k,line in enumerate(lines):
|
||||
if line[0] != ' ':
|
||||
|
@ -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
|
||||
|
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: Get n_det_max_cisd_sc2 from EZFIO file
|
||||
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 state) is lower
|
||||
than pt2_max in absolute value
|
||||
interface: input
|
||||
default: 0.0001
|
||||
|
||||
[energy]
|
||||
type: double precision
|
||||
doc: "Calculated Full CI energy"
|
||||
interface: output
|
||||
|
||||
[energy_pt2]
|
||||
type: double precision
|
||||
doc: "Calculated Full CI energy"
|
||||
interface: output
|
||||
|
@ -1,4 +0,0 @@
|
||||
cisd_sc2_selected
|
||||
n_det_max_cisd_sc2 integer
|
||||
pt2_max double precision
|
||||
do_pt2_end logical
|
@ -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,42 +1,42 @@
|
||||
[N_det_max_fci]
|
||||
type: Det_number_max
|
||||
doc: Max number of determinants in the wave function
|
||||
interface: output
|
||||
interface: input
|
||||
default: 10000
|
||||
|
||||
[N_det_max_fci_property]
|
||||
type: Det_number_max
|
||||
doc: Max number of determinants in the wave function when you select for a given property
|
||||
interface: output
|
||||
interface: input
|
||||
default: 10000
|
||||
|
||||
[do_pt2_end]
|
||||
type: logical
|
||||
doc: If true, compute the PT2 at the end of the selection
|
||||
interface: output
|
||||
interface: input
|
||||
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: output
|
||||
interface: input
|
||||
default: 0.0001
|
||||
|
||||
[var_pt2_ratio]
|
||||
type: Normalized_float
|
||||
doc: The selection process stops when the energy ratio variational/(variational+PT2)
|
||||
is equal to var_pt2_ratio
|
||||
interface: output
|
||||
interface: input
|
||||
default: 0.75
|
||||
|
||||
[energy]
|
||||
type: double precision
|
||||
doc: "Calculated Full CI energy"
|
||||
interface: input
|
||||
interface: output
|
||||
|
||||
[energy_pt2]
|
||||
type: double precision
|
||||
doc: "Calculated Full CI energy"
|
||||
interface: input
|
||||
interface: output
|
||||
|
||||
|
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,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
|
||||
|
||||
|
||||
|
||||
|
181
tests/unit_test/unit_test.py
Executable file
181
tests/unit_test/unit_test.py
Executable file
@ -0,0 +1,181 @@
|
||||
#!/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 = 1.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
|
||||
|
||||
def init_folder(geo, basis, mult=1):
|
||||
'''
|
||||
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)
|
||||
|
||||
cmd = "qp_create_ezfio_from_xyz -b {0} -m {1} {2}.xyz".format(basis,
|
||||
mult,
|
||||
geo)
|
||||
subprocess.check_call([cmd], shell=True)
|
||||
|
||||
|
||||
def get_error_message(l_exepected, l_cur):
|
||||
l_msg = ["Need {0} get {1}".format(i,j) for i,j in zip(l_exepected,l_cur)]
|
||||
return "\n".join(l_msg)
|
||||
|
||||
|
||||
def run_hf(geo, basis):
|
||||
"""
|
||||
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)
|
||||
ezfio.set_file("{0}.ezfio".format(geo))
|
||||
|
||||
# ~#~#~#~#~#~#~#~#~#~#~#~#~ #
|
||||
# S e t _ p a r a m e t e r #
|
||||
# ~#~#~#~#~#~#~#~#~#~#~#~#~ #
|
||||
|
||||
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 run_big_test(geo, basis):
|
||||
if not has_hf_alredy:
|
||||
run_hf(geo, basis)
|
||||
|
||||
run_full_ci_10k_pt2_end(geo, basis)
|
||||
return True
|
||||
|
||||
|
||||
class SimplisticTest(unittest.TestCase):
|
||||
|
||||
def test_full_ci_10k_pt2_end(self):
|
||||
self.assertTrue(run_big_test("methane", "sto-3g"))
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
Loading…
Reference in New Issue
Block a user