Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
west-public
West
Commits
29e39e89
Commit
29e39e89
authored
Jul 29, 2019
by
Marco Govoni
Browse files
Added fetch_input.py
parent
7af12dc9
Changes
1
Hide whitespace changes
Inline
Side-by-side
Tools/fetch_input.py
0 → 100644
View file @
29e39e89
#!/usr/bin/python
# File: fetch_input.py
from
__future__
import
print_function
import
sys
import
os
import
yaml
import
json
def
open_and_parse_file
(
fileName
)
:
"""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
:
with
open
(
fileName
,
'r'
)
as
stream
:
try
:
data
=
yaml
.
load
(
stream
,
Loader
=
yaml
.
SafeLoader
)
except
:
print
(
"Cannot parse file"
)
except
:
print
(
"Cannot open file : "
,
fileName
)
return
data
def
check_data
(
keyword
,
parsed_data
,
default
)
:
#
data
=
{}
#
if
keyword
in
parsed_data
.
keys
()
:
for
key
in
default
.
keys
()
:
if
key
in
parsed_data
[
keyword
].
keys
()
:
data
[
key
]
=
parsed_data
[
keyword
][
key
]
else
:
data
[
key
]
=
default
[
key
]
else
:
print
(
"Missing keyword in input file : "
,
keyword
)
return
data
def
read_input_west
(
*
args
,
**
kwargs
):
#
fileName
=
args
[
0
]
#
default
=
{}
default
[
"qe_prefix"
]
=
"pwscf"
default
[
"west_prefix"
]
=
"west"
default
[
"outdir"
]
=
"./"
#
parsed_data
=
open_and_parse_file
(
fileName
)
#
checked_data
=
check_data
(
"input_west"
,
parsed_data
,
default
)
print
(
checked_data
)
return
checked_data
def
read_wstat_control
(
*
args
,
**
kwargs
):
#
fileName
=
args
[
0
]
nq
=
args
[
1
]
#
default
=
{}
default
[
"wstat_calculation"
]
=
"S"
default
[
"n_pdep_eigen"
]
=
1
default
[
"n_pdep_times"
]
=
4
default
[
"n_pdep_maxiter"
]
=
100
default
[
"n_dfpt_maxiter"
]
=
250
default
[
"n_pdep_read_from_file"
]
=
0
default
[
"trev_pdep"
]
=
1.e-3
default
[
"trev_pdep_rel"
]
=
1.e-1
default
[
"tr2_dfpt"
]
=
1.e-12
default
[
"l_kinetic_only"
]
=
False
default
[
"l_minimize_exx_if_active"
]
=
False
default
[
"l_use_ecutrho"
]
=
False
default
[
"qlist"
]
=
[
i
+
1
for
i
in
range
(
nq
)
]
#
parsed_data
=
open_and_parse_file
(
fileName
)
#
checked_data
=
check_data
(
"wstat_control"
,
parsed_data
,
default
)
print
(
checked_data
)
return
checked_data
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment