mirror of
https://github.com/LCPQ/quantum_package
synced 2025-01-03 18:16:12 +01:00
Cleaning of ezfio_generate_provider.py
This commit is contained in:
parent
3c368023e9
commit
9d27774df1
@ -8,16 +8,14 @@ Creates the provider of a variable that has to be
|
||||
fetched from the EZFIO file.
|
||||
"""
|
||||
|
||||
import sys
|
||||
import os
|
||||
|
||||
|
||||
class EZFIO_Provider(object):
|
||||
|
||||
data = """BEGIN_PROVIDER [ %(type)s, %(name)s ]
|
||||
data = """
|
||||
BEGIN_PROVIDER [ %(type)s, %(name)s ]
|
||||
implicit none
|
||||
BEGIN_DOC
|
||||
! %(doc)s
|
||||
! %(doc)s
|
||||
END_DOC
|
||||
|
||||
logical :: has
|
||||
@ -26,34 +24,30 @@ class EZFIO_Provider(object):
|
||||
if (has) then
|
||||
call ezfio_get_%(ezfio_dir)s_%(ezfio_name)s(%(name)s)
|
||||
else
|
||||
%(default)s
|
||||
print *, '%(ezfio_dir)s/%(ezfio_name)s not found in EZFIO file'
|
||||
stop 1
|
||||
endif
|
||||
%(write)s
|
||||
|
||||
%(write)s
|
||||
|
||||
END_PROVIDER
|
||||
"""
|
||||
""".strip()
|
||||
|
||||
write_correspondance = {"integer": "write_int",
|
||||
"logical": "write_bool",
|
||||
"double precision": "write_double"}
|
||||
|
||||
def __init__(self):
|
||||
self.values = "type doc default name ezfio_dir ezfio_name write output".split()
|
||||
self.values = "type doc name ezfio_dir ezfio_name write output".split()
|
||||
for v in self.values:
|
||||
exec "self.%s = None" % (v) in locals()
|
||||
exec "self.{0} = None".format(v)
|
||||
|
||||
def __repr__(self):
|
||||
if not self.default:
|
||||
self.get_default()
|
||||
self.set_write()
|
||||
for v in self.values:
|
||||
exec "test = self.%s is None" % (v) in locals()
|
||||
if test:
|
||||
if not v:
|
||||
msg = "Error : %s is not set in ezfio_with_default.py" % (v)
|
||||
print >>sys.stderr, msg
|
||||
for v in self.values:
|
||||
exec "x = str(self.%s)" % (v) in locals()
|
||||
print >>sys.stderr, "%s : %s" % (v, x)
|
||||
sys.exit(1)
|
||||
return self.data % self.__dict__
|
||||
|
||||
@ -63,16 +57,17 @@ END_PROVIDER
|
||||
write = self.write_correspondance[self.type]
|
||||
output = self.output
|
||||
name = self.name
|
||||
self.write = """
|
||||
call write_time(%(output)s)
|
||||
call %(write)s(%(output)s, %(name)s, &
|
||||
'%(name)s')""" % locals()
|
||||
|
||||
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.replace('\n', '\n! ')
|
||||
self.doc = t.strip().replace('\n', '\n! ')
|
||||
|
||||
def set_name(self, t):
|
||||
self.name = t
|
||||
@ -86,46 +81,6 @@ END_PROVIDER
|
||||
def set_output(self, t):
|
||||
self.output = t
|
||||
|
||||
def set_default(self, t):
|
||||
self.default = t
|
||||
|
||||
def get_default(self):
|
||||
filename = '/'.join([os.environ['QPACKAGE_ROOT'],
|
||||
'data',
|
||||
'ezfio_defaults'])
|
||||
|
||||
with open(filename, 'r') as f:
|
||||
lines = f.readlines()
|
||||
|
||||
# Search directory
|
||||
for k, line in enumerate(lines):
|
||||
if line[0] != ' ':
|
||||
if line.strip().lower() == self.ezfio_dir:
|
||||
break
|
||||
if k + 1 == len(lines):
|
||||
return
|
||||
# Search name
|
||||
while k < len(lines):
|
||||
k += 1
|
||||
buffer = lines[k].split()
|
||||
if len(buffer) == 0:
|
||||
return
|
||||
if buffer[0].lower() == self.ezfio_name:
|
||||
break
|
||||
v = buffer[1]
|
||||
name = self.name
|
||||
try:
|
||||
v_eval = eval(v)
|
||||
if isinstance(v_eval, bool):
|
||||
v = '.%s.' % (v)
|
||||
elif isinstance(v_eval, float):
|
||||
v = v.replace('e', 'd')
|
||||
v = v.replace('E', 'D')
|
||||
v = "%(name)s = %(v)s" % locals()
|
||||
except:
|
||||
v = "call ezfio_get_%(v)s(%(name)s)" % locals()
|
||||
self.default = v
|
||||
|
||||
|
||||
def test_module():
|
||||
T = EZFIO_Provider()
|
||||
@ -137,6 +92,5 @@ def test_module():
|
||||
T.set_output("output_Hartree_Fock")
|
||||
print T
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
test_module()
|
||||
|
@ -272,16 +272,8 @@ def create_ezfio_provider(dict_ezfio_cfg):
|
||||
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'])
|
||||
|
||||
str_ = "\n".join([" print *, '{0}/{1} not found in EZFIO file'",
|
||||
" stop 1"])
|
||||
|
||||
str_ = str_.format(dict_info['ezfio_dir'],
|
||||
dict_info['ezfio_name'])
|
||||
|
||||
ez_p.set_default(str_)
|
||||
|
||||
ez_p.set_output("output_%s" % dict_info['ezfio_dir'])
|
||||
|
||||
dict_code_provider[provider_name] = str(ez_p)
|
||||
|
||||
return dict_code_provider
|
||||
|
@ -19,7 +19,7 @@ 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
|
||||
than pt2_max in absolute value)
|
||||
interface: output
|
||||
default: 0.0001
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user