"""Opens a file and parses it using the YAML sintax
:param fileName: name of the file
:type fileName: ``string``
:return: parsed data
:rtype: ``dict``
"""
data={}
try:
withopen(fileName,'r')asstream:
try:
data=yaml.load(stream,Loader=yaml.SafeLoader)
except:
print("Cannot parse file")
except:
print("Cannot open file : ",fileName)
#
returndata
##############
# CHECK DICT #
##############
defcheck_dict(parsed_data={},default_data={}):
"""Check data: returns a dictionary with the same keys of default_data. If keys are matching, values of default_data are replaced with those of parsed_data.
:param parsed_data: parsed data
:type parsed_data: ``dict``
:param default_data: default data
:type default_data: ``dict``
:return: checked data
:rtype: ``dict``
"""
#
data={}
#
forkeyindefault_data.keys():
ifkeyinparsed_data.keys():
data[key]=parsed_data[key]
else:
data[key]=default_data[key]
#
returndata
###########
# SUPPORT #
###########
defprint_bar(prefix="",nmarks=92):
"""Prints bar.
:param prefix: prefix
:type prefix: ``string``
:param nmarks: number of marks
:type nmarks: ``int``
"""
#
s=prefix
foriinrange(nmarks):
s+="-"
print(s)
#########
# PRINT #
#########
defprint_dict(title="input_west",data={}):
"""Prints data.
:param title: title
:type title: ``string``
:param data: data to print
:type default_data: ``dict``
"""
#
nmarks=92
nspaces=5
s=""
foriinrange(nspaces):
s+=" "
#
print_bar(s,nmarks)
print(s+"I/O Summary : "+str(title))
print_bar(s,nmarks)
forkeyindata.keys():
print(s+key,"=",data[key])
print_bar(s,nmarks)
sys.stdout.flush()
#############
# INTERFACE #
#############
defread_keyword_from_file(*args,**kwargs):
"""Read keyword from file
:return: read data
:rtype: ``dict``
"""
#
fileName=args[0]
keyword=args[1]
verbose=args[2]
#
# Assign static & dynamical defaults
#
default_data=default[keyword]
update_default_values(keyword,kwargs)
#
# Read input file
#
input_data=open_and_parse_file(fileName)
ifkeywordininput_data.keys():
parsed_data=input_data[keyword]
else:
parsed_data={}
#
# Compare defaults and input variables
#
data=check_dict(parsed_data,default_data)
#
# Print
#
if(verbose):
print_dict(keyword,data)
#
returndata
########
# TEST #
########
deftest():
#
fileName="west.in"
#
withopen(fileName,"w")asfile:
file.write("""
input_west :
qe_prefix : molecule
west_prefix : molecule
outdir : "./"
wstat_control :
wstat_calculation : R # this is a comment
unknown_key : value # this line will be read but not passed
@@ -15,7 +15,7 @@ The complete **WEST** reference for input parameters.
**WESTpy** is a Python package, designed to assist users of the WEST code in pre- and post-process massively parallel calculations. Click `here <http://www.west-code.org/doc/westpy/latest/>`_ to know more.
.. seealso::
The input file is given according to the JavaScript Object Notation (`www.json.org <http://www.json.org/>`_).
The input file is given according to the YAML Notation (`https://yaml.org/ <https://yaml.org//>`_).
|
...
...
@@ -56,6 +56,7 @@ wstat_control
- "S" : Start from scratch
- "R" : Restart from an interrupted run. You should restart with the same number of cores, and images.
- "E" : Calculation is outsourced to a server
.. data:: n_pdep_eigen
...
...
@@ -108,20 +109,20 @@ wstat_control
.. data:: l_minimize_exx_if_active
:type: boolean
:default: false
:description: If (true), then the exact-exchange term in the Hamiltonian is computed with the cutoff of the wavefunction.
:default: False
:description: If (True), then the exact-exchange term in the Hamiltonian is computed with the cutoff of the wavefunction.
.. data:: l_kinetic_only
:type: boolean
:default: false
:description: If (true), then only the kinetic term in the Hamiltonian is kept.
:default: False
:description: If (True), then only the kinetic term in the Hamiltonian is kept.
.. data:: l_use_ecutrho
:type: boolean
:default: false
:description: If (true), then the eigenpotentials are represented with ecutrho instead of ecutwfc.
:default: False
:description: If (True), then the eigenpotentials are represented with ecutrho instead of ecutwfc.
.. data:: qlist
...
...
@@ -221,13 +222,13 @@ wfreq_control
.. data:: l_enable_lanczos
:type: boolean
:default: true
:description: If (false), then Lanczos solvers are turned off.
:default: True
:description: If (False), then Lanczos solvers are turned off.
.. data:: l_enable_gwetot
:type: boolean
:default: false
:default: False
:description: Deprecated parameter.
.. data:: o_restart_time
...
...
@@ -290,8 +291,8 @@ westpp_control
.. data:: westpp_sign
:type: boolean
:default: false
:description: If (true), then the sign of the wavefunction/eigenpotential is kept in the output file.
:default: False
:description: If (True), then the sign of the wavefunction/eigenpotential is kept in the output file.