mirror of
https://gitlab.com/scemama/eplf
synced 2024-12-13 07:53:46 +01:00
Improved input
This commit is contained in:
parent
919c59a86f
commit
b92517db0b
153
scripts/eplf_edit.py
Executable file
153
scripts/eplf_edit.py
Executable file
@ -0,0 +1,153 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
from math import *
|
||||
|
||||
import input_wrapper
|
||||
InputFile = input_wrapper.InputFile
|
||||
rw_data = list(input_wrapper.rw_data)
|
||||
rw_data.sort()
|
||||
ro_data = list(input_wrapper.rw_data)
|
||||
ro_data.sort()
|
||||
|
||||
import sys, os
|
||||
import tempfile
|
||||
|
||||
editor = os.getenv("EDITOR",default="vi")
|
||||
|
||||
## Data editing
|
||||
###############
|
||||
|
||||
class Editor(object):
|
||||
def __init__(self,inp,name):
|
||||
self.dir = inp.name
|
||||
self.name = name
|
||||
self.inp = inp
|
||||
def action(self):
|
||||
raise TypeError
|
||||
def edit(self):
|
||||
print "Editing "+self.name
|
||||
self.action()
|
||||
|
||||
class GeometryEditor(Editor):
|
||||
def action(self):
|
||||
self.charge = self.inp.nucl_charge
|
||||
self.coord = self.inp.nucl_coord
|
||||
edit_temp_file(self.inp,self.write_geom_file,self.read_geom_file)
|
||||
|
||||
def write_geom_file(self,file,inp):
|
||||
print >>file, "###########################"
|
||||
print >>file, "# Geometry : %s"%(inp.name)
|
||||
print >>file, "###########################"
|
||||
print >>file, ""
|
||||
has_fitcusp = False
|
||||
has_label = False
|
||||
fields = "Charge X Y Z"
|
||||
format = "%10.1f "+"%10.6f "*3
|
||||
fields = fields.split()
|
||||
print >>file, " ".join(["#"]+map(lambda x: x.center(10),fields))
|
||||
print >>file, "# "+"-"*11*len(fields)+"\n"
|
||||
charge = self.charge
|
||||
coord = self.coord
|
||||
for i in xrange(len(charge)):
|
||||
buffer = [ charge[i], coord[0][i], coord[1][i], coord[2][i] ]
|
||||
print >>file, " "+format%tuple(buffer)
|
||||
|
||||
def read_geom_file(self,file,inp):
|
||||
lines = file.readlines()
|
||||
lines = filter(lambda x: len(x.strip())>0,lines)
|
||||
lines = filter(lambda x: not x.startswith("#"),lines)
|
||||
lines = map(lambda x: x.split(),lines)
|
||||
coord = [ [], [], [] ]
|
||||
charge = []
|
||||
for line in lines:
|
||||
charge.append(float(line[-4]))
|
||||
coord[0].append(float(line[-3]))
|
||||
coord[1].append(float(line[-2]))
|
||||
coord[2].append(float(line[-1]))
|
||||
inp.coord = coord
|
||||
|
||||
|
||||
def edit(x,inp):
|
||||
d = { "geometry": GeometryEditor,
|
||||
}
|
||||
d[x](inp,x.replace("_"," ")).edit()
|
||||
|
||||
## Write temporary input file
|
||||
#############################
|
||||
|
||||
def write_main_file(file,inp):
|
||||
print >>file, "####################"
|
||||
print >>file, "# %s"%(inp.name)
|
||||
print >>file, "####################"
|
||||
print >>file, ""
|
||||
print >>file, "# Edit"
|
||||
print >>file, "# --------------------\n"
|
||||
print >>file, '# edit(geometry)'
|
||||
print >>file, '# edit(grid_parameters)'
|
||||
print >>file, ""
|
||||
print >>file, "# Computation"
|
||||
print >>file, "# --------------------\n"
|
||||
compute = filter(lambda x: x.startswith("compute"),rw_data)
|
||||
compute = filter(lambda x: not x.endswith("_grad"),compute)
|
||||
compute = filter(lambda x: not x.endswith("_lapl"),compute)
|
||||
for p in compute:
|
||||
x = ' '
|
||||
exec "if inp.%s: x = 'X'"%(p)
|
||||
print >>file, "(%s) %s"%(x,p[8:])
|
||||
print >>file, ""
|
||||
|
||||
## Execute temporary input file
|
||||
###############################
|
||||
|
||||
def read_main_file(file,inp):
|
||||
|
||||
lines = file.readlines()
|
||||
for line in lines:
|
||||
line = line.lstrip()
|
||||
if line == "":
|
||||
pass
|
||||
elif line[0] == "(":
|
||||
line = line.replace("( ) ","=False inp.compute_")
|
||||
line = line.replace("(X) ","=True inp.compute_")
|
||||
line = line.replace("(x) ","=True inp.compute_")
|
||||
buffer = line.split()
|
||||
line = ' '.join([buffer[1].lower(),buffer[0]])
|
||||
elif line.startswith("edit"):
|
||||
line = line.replace("(","('").replace(")","',inp)").lower()
|
||||
exec line
|
||||
|
||||
|
||||
def edit_temp_file(input_file,write_file,read_file,saved_file=None):
|
||||
if saved_file is None:
|
||||
file,filename = tempfile.mkstemp()
|
||||
file = open(filename,"w")
|
||||
write_file(file,input_file)
|
||||
file.close()
|
||||
os.system("%s %s"%(editor,filename))
|
||||
else:
|
||||
file = open(saved_file,'r')
|
||||
buffer = file.read()
|
||||
file.close()
|
||||
|
||||
file,filename = tempfile.mkstemp()
|
||||
file = open(filename,"w")
|
||||
file.write(buffer)
|
||||
file.close()
|
||||
file = open(filename,"r")
|
||||
read_file(file,input_file)
|
||||
file.close()
|
||||
|
||||
os.remove(filename)
|
||||
|
||||
def main():
|
||||
if len(sys.argv) not in [2,3]:
|
||||
print "Syntax : %s <EZFIO_File> [input_file]"%(sys.argv[0])
|
||||
sys.exit(1)
|
||||
inp = InputFile(sys.argv[1])
|
||||
if len(sys.argv) == 3:
|
||||
saved_file = sys.argv[2]
|
||||
else:
|
||||
saved_file = None
|
||||
edit_temp_file(inp,write_main_file,read_main_file,saved_file)
|
||||
|
||||
main()
|
@ -10,22 +10,22 @@ ro_data = """det_num nucl_num mo_num ao_num
|
||||
""".split()
|
||||
rw_data = """
|
||||
point_num step_size origin opposite
|
||||
compute_ELF compute_EPLF compute_RHO
|
||||
compute_ELF_grad compute_EPLF_grad compute_RHO_grad
|
||||
compute_ELF_lapl compute_EPLF_lapl compute_RHO_lapl
|
||||
compute_elf compute_eplf compute_density
|
||||
compute_elf_grad compute_eplf_grad compute_density_grad
|
||||
compute_elf_lapl compute_eplf_lapl compute_density_lapl
|
||||
""".split()
|
||||
rw_data_full = rw_data + geom_data
|
||||
|
||||
######################################################################
|
||||
DEFAULT_COMPUTE_EPLF = True
|
||||
DEFAULT_COMPUTE_ELF = False
|
||||
DEFAULT_COMPUTE_RHO = False
|
||||
DEFAULT_COMPUTE_DENSITY = False
|
||||
DEFAULT_COMPUTE_EPLF_GRAD = False
|
||||
DEFAULT_COMPUTE_ELF_GRAD = False
|
||||
DEFAULT_COMPUTE_RHO_GRAD = False
|
||||
DEFAULT_COMPUTE_DENSITY_GRAD = False
|
||||
DEFAULT_COMPUTE_EPLF_LAPL = False
|
||||
DEFAULT_COMPUTE_ELF_LAPL = False
|
||||
DEFAULT_COMPUTE_RHO_LAPL = False
|
||||
DEFAULT_COMPUTE_DENSITY_LAPL = False
|
||||
DEFAULT_POINT_NUM = [80,80,80]
|
||||
|
||||
######################################################################
|
||||
@ -201,106 +201,106 @@ class InputFile(object):
|
||||
raise InputFileExn("Wrong type")
|
||||
ezfio.set_grid_opposite(value)
|
||||
|
||||
def get_compute_ELF(self):
|
||||
def get_compute_elf(self):
|
||||
if ezfio.has_compute_elf():
|
||||
return ezfio.get_compute_elf()
|
||||
else:
|
||||
return DEFAULT_COMPUTE_ELF
|
||||
|
||||
def set_compute_ELF(self,value):
|
||||
def set_compute_elf(self,value):
|
||||
if not isinstance(value,bool):
|
||||
raise InputFileExn("Wrong type")
|
||||
ezfio.set_compute_elf(value)
|
||||
|
||||
def get_compute_EPLF(self):
|
||||
def get_compute_eplf(self):
|
||||
if ezfio.has_compute_eplf():
|
||||
return ezfio.get_compute_eplf()
|
||||
else:
|
||||
return DEFAULT_COMPUTE_EPLF
|
||||
|
||||
def set_compute_EPLF(self,value):
|
||||
def set_compute_eplf(self,value):
|
||||
if not isinstance(value,bool):
|
||||
raise InputFileExn("Wrong type")
|
||||
ezfio.set_compute_eplf(value)
|
||||
|
||||
def get_compute_RHO(self):
|
||||
if ezfio.has_compute_rho():
|
||||
return ezfio.get_compute_rho()
|
||||
def get_compute_density(self):
|
||||
if ezfio.has_compute_density():
|
||||
return ezfio.get_compute_density()
|
||||
else:
|
||||
return DEFAULT_COMPUTE_RHO
|
||||
return DEFAULT_COMPUTE_DENSITY
|
||||
|
||||
def set_compute_RHO(self,value):
|
||||
def set_compute_density(self,value):
|
||||
if not isinstance(value,bool):
|
||||
raise InputFileExn("Wrong type")
|
||||
ezfio.set_compute_rho(value)
|
||||
ezfio.set_compute_density(value)
|
||||
|
||||
|
||||
def get_compute_ELF_grad(self):
|
||||
def get_compute_elf_grad(self):
|
||||
if ezfio.has_compute_elf_grad():
|
||||
return ezfio.get_compute_elf_grad()
|
||||
else:
|
||||
return DEFAULT_COMPUTE_ELF_GRAD
|
||||
|
||||
def set_compute_ELF_grad(self,value):
|
||||
def set_compute_elf_grad(self,value):
|
||||
if not isinstance(value,bool):
|
||||
raise InputFileExn("Wrong type")
|
||||
ezfio.set_compute_elf_grad(value)
|
||||
|
||||
def get_compute_EPLF_grad(self):
|
||||
def get_compute_eplf_grad(self):
|
||||
if ezfio.has_compute_eplf_grad():
|
||||
return ezfio.get_compute_eplf_grad()
|
||||
else:
|
||||
return DEFAULT_COMPUTE_EPLF_GRAD
|
||||
|
||||
def set_compute_EPLF_grad(self,value):
|
||||
def set_compute_eplf_grad(self,value):
|
||||
if not isinstance(value,bool):
|
||||
raise InputFileExn("Wrong type")
|
||||
ezfio.set_compute_eplf_grad(value)
|
||||
|
||||
def get_compute_RHO_grad(self):
|
||||
if ezfio.has_compute_rho_grad():
|
||||
return ezfio.get_compute_rho_grad()
|
||||
def get_compute_density_grad(self):
|
||||
if ezfio.has_compute_density_grad():
|
||||
return ezfio.get_compute_density_grad()
|
||||
else:
|
||||
return DEFAULT_COMPUTE_RHO_GRAD
|
||||
return DEFAULT_COMPUTE_DENSITY_GRAD
|
||||
|
||||
def set_compute_RHO_grad(self,value):
|
||||
def set_compute_density_grad(self,value):
|
||||
if not isinstance(value,bool):
|
||||
raise InputFileExn("Wrong type")
|
||||
ezfio.set_compute_rho_grad(value)
|
||||
ezfio.set_compute_density_grad(value)
|
||||
|
||||
|
||||
def get_compute_ELF_lapl(self):
|
||||
def get_compute_elf_lapl(self):
|
||||
if ezfio.has_compute_elf_lapl():
|
||||
return ezfio.get_compute_elf_lapl()
|
||||
else:
|
||||
return DEFAULT_COMPUTE_ELF_LAPL
|
||||
|
||||
def set_compute_ELF_lapl(self,value):
|
||||
def set_compute_elf_lapl(self,value):
|
||||
if not isinstance(value,bool):
|
||||
raise InputFileExn("Wrong type")
|
||||
ezfio.set_compute_elf_lapl(value)
|
||||
|
||||
def get_compute_EPLF_lapl(self):
|
||||
def get_compute_eplf_lapl(self):
|
||||
if ezfio.has_compute_eplf_lapl():
|
||||
return ezfio.get_compute_eplf_lapl()
|
||||
else:
|
||||
return DEFAULT_COMPUTE_EPLF_LAPL
|
||||
|
||||
def set_compute_EPLF_lapl(self,value):
|
||||
def set_compute_eplf_lapl(self,value):
|
||||
if not isinstance(value,bool):
|
||||
raise InputFileExn("Wrong type")
|
||||
ezfio.set_compute_eplf_lapl(value)
|
||||
|
||||
def get_compute_RHO_lapl(self):
|
||||
if ezfio.has_compute_rho_lapl():
|
||||
return ezfio.get_compute_rho_lapl()
|
||||
def get_compute_density_lapl(self):
|
||||
if ezfio.has_compute_density_lapl():
|
||||
return ezfio.get_compute_density_lapl()
|
||||
else:
|
||||
return DEFAULT_COMPUTE_RHO_LAPL
|
||||
return DEFAULT_COMPUTE_DENSITY_LAPL
|
||||
|
||||
def set_compute_RHO_lapl(self,value):
|
||||
def set_compute_density_lapl(self,value):
|
||||
if not isinstance(value,bool):
|
||||
raise InputFileExn("Wrong type")
|
||||
ezfio.set_compute_rho_lapl(value)
|
||||
ezfio.set_compute_density_lapl(value)
|
||||
|
||||
# Build the corresponding properties
|
||||
for i in ro_data:
|
||||
|
Loading…
Reference in New Issue
Block a user