mirror of
https://github.com/LCPQ/quantum_package
synced 2025-01-10 21:18:29 +01:00
PEP 8 in ezfio_with_default and typo
This commit is contained in:
parent
246cc66936
commit
22bae15794
@ -1,7 +1,7 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
|
||||||
__author__ = "Anthony Scemama"
|
__author__ = "Anthony Scemama and Applencourt for the amazing PEP8"
|
||||||
__date__ = "Tue Jul 29 12:20:00 CEST 2014"
|
__date__ = "jeudi 26 mars 2015, 12:49:35 (UTC+0100)"
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Creates the provider of a variable that has to be
|
Creates the provider of a variable that has to be
|
||||||
@ -14,7 +14,7 @@ import os
|
|||||||
|
|
||||||
class EZFIO_Provider(object):
|
class EZFIO_Provider(object):
|
||||||
|
|
||||||
data = """BEGIN_PROVIDER [ %(type)s, %(name)s ]
|
data = """BEGIN_PROVIDER [ %(type)s, %(name)s ]
|
||||||
implicit none
|
implicit none
|
||||||
BEGIN_DOC
|
BEGIN_DOC
|
||||||
! %(doc)s
|
! %(doc)s
|
||||||
@ -33,109 +33,109 @@ class EZFIO_Provider(object):
|
|||||||
END_PROVIDER
|
END_PROVIDER
|
||||||
"""
|
"""
|
||||||
|
|
||||||
write_correspondance = {
|
write_correspondance = {"integer": "write_int",
|
||||||
"integer" : "write_int",
|
"logical": "write_bool",
|
||||||
"logical" : "write_bool",
|
"double precision": "write_double"}
|
||||||
"double precision" : "write_double" }
|
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.values = "type doc default name ezfio_dir ezfio_name write output".split()
|
self.values = "type doc default name ezfio_dir ezfio_name write output".split()
|
||||||
for v in self.values:
|
|
||||||
exec "self.%s = None"%(v) in locals()
|
|
||||||
|
|
||||||
def __repr__(self):
|
|
||||||
self.get_default()
|
|
||||||
self.set_write()
|
|
||||||
for v in self.values:
|
|
||||||
exec "test = self.%s is None"%(v) in locals()
|
|
||||||
if test:
|
|
||||||
print >>sys.stderr, "Error : %s is not set in ezfio_with_default.py"%(v)
|
|
||||||
for v in self.values:
|
for v in self.values:
|
||||||
exec "x = str(self.%s)"%(v) in locals()
|
exec "self.%s = None" % (v) in locals()
|
||||||
print >>sys.stderr, "%s : %s"%(v, x)
|
|
||||||
sys.exit(1)
|
|
||||||
return self.data%self.__dict__
|
|
||||||
|
|
||||||
def set_write(self):
|
def __repr__(self):
|
||||||
self.write = ""
|
self.get_default()
|
||||||
if self.type in self.write_correspondance:
|
self.set_write()
|
||||||
write = self.write_correspondance[self.type]
|
for v in self.values:
|
||||||
output = self.output
|
exec "test = self.%s is None" % (v) in locals()
|
||||||
name = self.name
|
if test:
|
||||||
self.write = """
|
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__
|
||||||
|
|
||||||
|
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
|
||||||
|
self.write = """
|
||||||
call write_time(%(output)s)
|
call write_time(%(output)s)
|
||||||
call %(write)s(%(output)s, %(name)s, &
|
call %(write)s(%(output)s, %(name)s, &
|
||||||
'%(name)s')
|
'%(name)s')""" % locals()
|
||||||
"""%locals()
|
|
||||||
|
|
||||||
def set_type(self,t):
|
def set_type(self, t):
|
||||||
self.type = t.lower()
|
self.type = t.lower()
|
||||||
|
|
||||||
def set_doc(self,t):
|
def set_doc(self, t):
|
||||||
self.doc = t.replace('\n', '\n! ')
|
self.doc = t.replace('\n', '\n! ')
|
||||||
|
|
||||||
def set_name(self,t):
|
def set_name(self, t):
|
||||||
self.name = t
|
self.name = t
|
||||||
|
|
||||||
def set_ezfio_dir(self,t):
|
def set_ezfio_dir(self, t):
|
||||||
self.ezfio_dir = t.lower()
|
self.ezfio_dir = t.lower()
|
||||||
|
|
||||||
def set_ezfio_name(self,t):
|
def set_ezfio_name(self, t):
|
||||||
self.ezfio_name = t.lower()
|
self.ezfio_name = t.lower()
|
||||||
|
|
||||||
def set_output(self,t):
|
def set_output(self, t):
|
||||||
self.output = t
|
self.output = t
|
||||||
|
|
||||||
def set_default(self,t):
|
def set_default(self, t):
|
||||||
self.default = t
|
self.default = t
|
||||||
|
|
||||||
def get_default(self):
|
def get_default(self):
|
||||||
filename = '/'.join( [os.environ['QPACKAGE_ROOT'], 'data', 'ezfio_defaults'] )
|
filename = '/'.join([os.environ['QPACKAGE_ROOT'],
|
||||||
file = open(filename,'r')
|
'data',
|
||||||
lines = file.readlines()
|
'ezfio_defaults'])
|
||||||
file.close()
|
|
||||||
# Search directory
|
with open(filename, 'r') as f:
|
||||||
for k,line in enumerate(lines):
|
lines = f.readlines()
|
||||||
if line[0] != ' ':
|
|
||||||
if line.strip().lower() == self.ezfio_dir:
|
# Search directory
|
||||||
break
|
for k, line in enumerate(lines):
|
||||||
if k+1 == len(lines):
|
if line[0] != ' ':
|
||||||
return
|
if line.strip().lower() == self.ezfio_dir:
|
||||||
# Search name
|
break
|
||||||
while k < len(lines):
|
if k + 1 == len(lines):
|
||||||
k+=1
|
return
|
||||||
buffer = lines[k].split()
|
# Search name
|
||||||
if len(buffer) == 0:
|
while k < len(lines):
|
||||||
return
|
k += 1
|
||||||
if buffer[0].lower() == self.ezfio_name:
|
buffer = lines[k].split()
|
||||||
break
|
if len(buffer) == 0:
|
||||||
v = buffer[1]
|
return
|
||||||
name = self.name
|
if buffer[0].lower() == self.ezfio_name:
|
||||||
try:
|
break
|
||||||
v_eval = eval(v)
|
v = buffer[1]
|
||||||
if type(v_eval) == bool:
|
name = self.name
|
||||||
v = '.%s.'%(v)
|
try:
|
||||||
elif type(v_eval) == float:
|
v_eval = eval(v)
|
||||||
v = v.replace('e','d')
|
if isinstance(v_eval, bool):
|
||||||
v = v.replace('E','D')
|
v = '.%s.' % (v)
|
||||||
v = "%(name)s = %(v)s"%locals()
|
elif isinstance(v_eval, float):
|
||||||
except:
|
v = v.replace('e', 'd')
|
||||||
v = "call ezfio_get_%(v)s(%(name)s)"%locals()
|
v = v.replace('E', 'D')
|
||||||
self.default = v
|
v = "%(name)s = %(v)s" % locals()
|
||||||
|
except:
|
||||||
|
v = "call ezfio_get_%(v)s(%(name)s)" % locals()
|
||||||
|
self.default = v
|
||||||
|
|
||||||
|
|
||||||
def test_module():
|
def test_module():
|
||||||
T = EZFIO_Provider()
|
T = EZFIO_Provider()
|
||||||
T.set_type ( "double precision" )
|
T.set_type("double precision")
|
||||||
T.set_name ( "thresh_SCF" )
|
T.set_name("thresh_SCF")
|
||||||
T.set_doc ( "Threshold on the convergence of the Hartree Fock energy" )
|
T.set_doc("Threshold on the convergence of the Hartree Fock energy")
|
||||||
T.set_ezfio_dir ( "Hartree_Fock" )
|
T.set_ezfio_dir("Hartree_Fock")
|
||||||
T.set_ezfio_name( "thresh_SCF" )
|
T.set_ezfio_name("thresh_SCF")
|
||||||
T.set_output ( "output_Hartree_Fock" )
|
T.set_output("output_Hartree_Fock")
|
||||||
print T
|
print T
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
test_module()
|
test_module()
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user