mirror of
https://github.com/LCPQ/quantum_package
synced 2024-10-02 14:30:59 +02:00
ezfio_interface
This commit is contained in:
parent
c9f7d3eb92
commit
d824b013bb
@ -4,105 +4,133 @@
|
|||||||
import ConfigParser
|
import ConfigParser
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
|
|
||||||
|
def create_dic_fancy_type():
|
||||||
|
fancy_type = defaultdict(dict)
|
||||||
|
|
||||||
def create_ezfio_config(config_file, save, root):
|
ocaml_to_fortran = {"int": "integer",
|
||||||
|
"float": "double precision",
|
||||||
|
"logical": "logical",
|
||||||
|
"string": "character*60"}
|
||||||
|
|
||||||
|
fancy_type['integer'] = {
|
||||||
|
"ocaml": "int",
|
||||||
|
"fortran": "integer"}
|
||||||
|
|
||||||
|
fancy_type['double precision'] = {
|
||||||
|
"ocaml": "float",
|
||||||
|
"fortran": "double precision"}
|
||||||
|
fancy_type['logical'] = {
|
||||||
|
"ocaml": "logical",
|
||||||
|
"fortran": "logical"}
|
||||||
|
|
||||||
|
src = os.environ.get('QPACKAGE_ROOT') + "/ocaml/qptypes_generator.ml"
|
||||||
|
|
||||||
|
with open(src, "r") as f:
|
||||||
|
l = f.read().splitlines()
|
||||||
|
|
||||||
|
l = [i for i in l 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] = {"ocaml": ocaml_type,
|
||||||
|
"fortran": fortran_type}
|
||||||
|
|
||||||
|
return dict(fancy_type)
|
||||||
|
|
||||||
|
import sys
|
||||||
|
|
||||||
|
|
||||||
|
def dict_config_file(config_file, dic_type):
|
||||||
|
d = defaultdict(dict)
|
||||||
|
list_key = ["doc", "ezfio_name", "ezfio_dir", "ezfio_default_value"]
|
||||||
|
|
||||||
|
provider_names = config_file.sections()
|
||||||
|
for provider_name in provider_names:
|
||||||
|
|
||||||
|
if config_file.get(provider_name, "type") not in dic_type:
|
||||||
|
print config_file.get(provider_name, "type"), "not avalaible"
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
for k in list_key:
|
||||||
|
d[provider_name][k] = config_file.get(provider_name, k)
|
||||||
|
|
||||||
|
type_raw = config_file.get(provider_name, "type")
|
||||||
|
d[provider_name]["ezfio_type"] = dic_type[type_raw]["fortran"]
|
||||||
|
d[provider_name]["ocaml_type"] = dic_type[type_raw]["ocaml"]
|
||||||
|
|
||||||
|
return dict(d)
|
||||||
|
|
||||||
|
|
||||||
|
def create_ezfio_string(dict_all, t):
|
||||||
|
a = {"config": "ezfio_type",
|
||||||
|
"default": "ezfio_default_value"}
|
||||||
|
|
||||||
|
info = a[t]
|
||||||
d = defaultdict(list)
|
d = defaultdict(list)
|
||||||
|
|
||||||
ls = config_file.sections()
|
for provider_name, dict_info in dict_all.items():
|
||||||
for i in ls:
|
l_to_join = [" ", dict_info['ezfio_name'], dict_info[info], "\n"]
|
||||||
l_to_join = [" ",
|
d[dict_info['ezfio_dir']].append(l_to_join)
|
||||||
config_file.get(i, 'ezfio_name'),
|
|
||||||
config_file.get(i, 'ezfio_type'),
|
|
||||||
"\n"]
|
|
||||||
|
|
||||||
d[config_file.get(i, 'ezfio_dir')].append(l_to_join)
|
# Only for fun,sry reader...
|
||||||
|
return [" ".join([k, "\n"] + [j for i in v for j in i])
|
||||||
s = ""
|
for k, v in d.items()]
|
||||||
for k, v in d.items():
|
|
||||||
s += k + "\n"
|
|
||||||
for i in v:
|
|
||||||
s += " ".join(i)
|
|
||||||
|
|
||||||
if (save):
|
|
||||||
for k, v in d.items():
|
|
||||||
f = open(root + "/" + k + ".ezfio_config", "w")
|
|
||||||
f.write(k + "\n")
|
|
||||||
for i in v:
|
|
||||||
f.write(" ".join(i))
|
|
||||||
f.close()
|
|
||||||
|
|
||||||
return s
|
|
||||||
|
|
||||||
|
|
||||||
def create_ezfio_default(config_file):
|
def create_ezfio_provider(dict_all):
|
||||||
|
|
||||||
d = defaultdict(list)
|
|
||||||
|
|
||||||
ls = config_file.sections()
|
|
||||||
for i in ls:
|
|
||||||
l_to_join = [" ",
|
|
||||||
config_file.get(i, 'ezfio_name'),
|
|
||||||
config_file.get(i, 'ezfio_default_value'),
|
|
||||||
"\n"]
|
|
||||||
|
|
||||||
d[config_file.get(i, 'ezfio_dir')].append(l_to_join)
|
|
||||||
|
|
||||||
f = ""
|
|
||||||
for k, v in d.items():
|
|
||||||
f += k + "\n"
|
|
||||||
for i in v:
|
|
||||||
f += " ".join(i)
|
|
||||||
|
|
||||||
return f
|
|
||||||
|
|
||||||
|
|
||||||
def create_ezfio_provider(config_file):
|
|
||||||
from ezfio_with_default import EZFIO_Provider
|
from ezfio_with_default import EZFIO_Provider
|
||||||
lp = []
|
lp = []
|
||||||
|
|
||||||
T = EZFIO_Provider()
|
T = EZFIO_Provider()
|
||||||
|
for provider_name, dict_info in dict_all.items():
|
||||||
|
T.set_type(dict_info['ezfio_type'])
|
||||||
|
T.set_name(provider_name)
|
||||||
|
T.set_doc(dict_info['doc'])
|
||||||
|
T.set_ezfio_dir(dict_info['ezfio_dir'])
|
||||||
|
T.set_ezfio_name(dict_info['ezfio_name'])
|
||||||
|
T.set_default(dict_info['ezfio_default_value'])
|
||||||
|
|
||||||
ls = config_file.sections()
|
T.set_output("output_%s" % dict_info['ezfio_dir'])
|
||||||
for i in ls:
|
lp.append(str(T))
|
||||||
T.set_type(config_file.get(i, 'ezfio_type'))
|
|
||||||
T.set_name(i)
|
|
||||||
T.set_doc(config_file.get(i, 'doc'))
|
|
||||||
T.set_ezfio_dir(config_file.get(i, 'ezfio_dir'))
|
|
||||||
T.set_ezfio_name(config_file.get(i, 'ezfio_name'))
|
|
||||||
T.set_default(config_file.get(i, 'ezfio_default_value'))
|
|
||||||
|
|
||||||
T.set_output("output_%s" % config_file.get(i, 'ezfio_dir'))
|
|
||||||
lp.append(T.get_string())
|
|
||||||
|
|
||||||
return lp
|
return lp
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
if __name__ == "__main__":
|
def get_dict_cgf():
|
||||||
|
|
||||||
|
dict_cfg = {}
|
||||||
|
fancy_type = create_dic_fancy_type()
|
||||||
|
|
||||||
|
src = os.environ.get('QPACKAGE_ROOT') + "/src/"
|
||||||
|
|
||||||
src = "/home/razoa/quantum_package/src/"
|
|
||||||
for root, dirs, files in os.walk(src, topdown=False):
|
for root, dirs, files in os.walk(src, topdown=False):
|
||||||
|
|
||||||
for name in dirs:
|
for name in dirs:
|
||||||
|
|
||||||
path_config_folder = src + name
|
path_config_folder = src + name
|
||||||
config = ConfigParser.ConfigParser()
|
config = ConfigParser.ConfigParser()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
config.readfp(open(path_config_folder + '/EZFIO.cfg'))
|
config.readfp(open(path_config_folder + '/EZFIO.cfg'))
|
||||||
except Exception as inst:
|
except Exception as inst:
|
||||||
# print inst
|
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
|
dict_cfg.update(dict_config_file(config, fancy_type))
|
||||||
|
|
||||||
print path_config_folder
|
return dict_cfg
|
||||||
print create_ezfio_config(config, True, path_config_folder)
|
|
||||||
|
|
||||||
for i in create_ezfio_provider(config):
|
if __name__ == "__main__":
|
||||||
|
src = os.environ.get('QPACKAGE_ROOT') + "/src/"
|
||||||
|
|
||||||
|
roger = get_dict_cgf()
|
||||||
|
print roger
|
||||||
|
|
||||||
|
for i in create_ezfio_string(roger, "config"):
|
||||||
print i
|
print i
|
||||||
|
|
||||||
path = "{root}/options.irp.f".format(
|
for i in create_ezfio_string(roger, "default"):
|
||||||
root=path_config_folder)
|
print i
|
||||||
with open(path, "w") as f:
|
|
||||||
for i in create_ezfio_provider(config):
|
|
||||||
f.write(i+"\n")
|
|
||||||
|
|
||||||
|
@ -1,20 +1,20 @@
|
|||||||
[n_det_max_fci]
|
[n_det_max_fci]
|
||||||
doc : Max number of determinants in the wave function
|
doc: Max number of determinants in the wave function
|
||||||
ezfio_name : n_det_max_fci
|
type: Det_number_max
|
||||||
ezfio_type : integer
|
ezfio_name: n_det_max_fci
|
||||||
ezfio_dir : full_ci
|
ezfio_dir: full_ci
|
||||||
ezfio_default_value : 10000
|
ezfio_default_value: 10000
|
||||||
|
|
||||||
[pt2_max]
|
[pt2_max]
|
||||||
doc : The selection process stops when the largest PT2 (for all the states) is lower than pt2_max in absolute value
|
doc: The selection process stops when the largest PT2 (for all the states) is lower than pt2_max in absolute value
|
||||||
ezfio_name : pt2_max
|
type: double precision
|
||||||
ezfio_type : double precision
|
ezfio_name: pt2_max
|
||||||
ezfio_dir : full_ci
|
ezfio_dir: full_ci
|
||||||
ezfio_default_value : 1.e-4
|
ezfio_default_value: 1.e-4
|
||||||
|
|
||||||
[do_pt2_end]
|
[do_pt2_end]
|
||||||
doc : If true, compute the PT2 at the end of the selection
|
doc: If true, compute the PT2 at the end of the selection
|
||||||
ezfio_name : do_pt2_end
|
type: logical
|
||||||
ezfio_type : logical
|
ezfio_name: do_pt2_end
|
||||||
ezfio_dir : full_ci
|
ezfio_dir: full_ci
|
||||||
ezfio_default_value : False
|
ezfio_default_value: False
|
@ -82,6 +82,7 @@ $(error )
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Check if ASSUMPTIONS.rst exists
|
# Check if ASSUMPTIONS.rst exists
|
||||||
|
|
||||||
ASSUMPTIONS_RST_OK=$(shell ls ASSUMPTIONS.rst || echo False)
|
ASSUMPTIONS_RST_OK=$(shell ls ASSUMPTIONS.rst || echo False)
|
||||||
@ -113,13 +114,18 @@ endif
|
|||||||
|
|
||||||
# Define the EZFIO rules
|
# Define the EZFIO rules
|
||||||
|
|
||||||
$(EZFIO): $(wildcard $(QPACKAGE_ROOT)/src/*.ezfio_config) $(wildcard $(QPACKAGE_ROOT)/src/*/*.ezfio_config)
|
$(EZFIO): $(wildcard $(QPACKAGE_ROOT)/src/*/EZFIO.cfg) $(wildcard $(QPACKAGE_ROOT)/src/*/options.irp.f) options.irp.f
|
||||||
@echo Building EZFIO library
|
@echo Building EZFIO library
|
||||||
@cp $(wildcard $(QPACKAGE_ROOT)/src/*.ezfio_config) $(wildcard $(QPACKAGE_ROOT)/src/*/*.ezfio_config) $(EZFIO_DIR)/config
|
@cp $(wildcard $(QPACKAGE_ROOT)/src/*.ezfio_config) $(wildcard $(QPACKAGE_ROOT)/src/*/*.ezfio_config) $(EZFIO_DIR)/config
|
||||||
@cd $(EZFIO_DIR) ; export FC="$(FC)" ; export FCFLAGS="$(FCFLAGS)" ; export IRPF90="$(IRPF90)" ; $(MAKE) ; $(MAKE) Python
|
@cd $(EZFIO_DIR) ; export FC="$(FC)" ; export FCFLAGS="$(FCFLAGS)" ; export IRPF90="$(IRPF90)" ; $(MAKE) ; $(MAKE) Python
|
||||||
|
|
||||||
ezfio: $(EZFIO)
|
ezfio: $(EZFIO)
|
||||||
|
|
||||||
|
|
||||||
|
options.irp.f: EZFIO.cfg
|
||||||
|
$(QPACKAGE_ROOT)/scripts/ezfio_interface.py
|
||||||
|
touch options.irp.f
|
||||||
|
|
||||||
# Create symbolic links of other modules
|
# Create symbolic links of other modules
|
||||||
|
|
||||||
ifneq ($(PWD),$(QPACKAGE_ROOT)/src)
|
ifneq ($(PWD),$(QPACKAGE_ROOT)/src)
|
||||||
|
Loading…
Reference in New Issue
Block a user