Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding ENVIRON namelists #703

Open
wants to merge 28 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
a991ec6
Added boundary and electrostatic namelists for ENVIRON
Jun 5, 2021
d2691b8
Added example environ calculation for testing purposes
Jun 5, 2021
a134570
Merge branch 'aiidateam:develop' into develop
sudarshanv01 Jul 11, 2021
d753459
Added test for generating Environ namelist
Jul 11, 2021
726b355
Added some documentation about how to run Environ and some enabled pa…
Jul 11, 2021
64161bc
Fixed typo in parsing of Environ
Jul 15, 2021
12be851
Merge branch 'develop' into develop
mbercx Jul 22, 2021
9fc3a1a
Added tests to pw parser and calculation and added log to exception o…
Jul 23, 2021
b5d2859
Merge branch 'develop' of git+ssh://github.com/sudarshanv01/aiida-qua…
Jul 23, 2021
29e0574
Merge branch 'develop' of git+ssh://github.com/sudarshanv01/aiida-qua…
Jul 23, 2021
894b95a
Merge branch 'develop' of git+ssh://github.com/sudarshanv01/aiida-qua…
Jul 23, 2021
e38ddf1
Merge branch 'develop' of github.com:sudarshanv01/aiida-quantumespres…
Aug 7, 2021
8f0bb86
Make environ tests work in both calculations and parser
Aug 7, 2021
1f6dd1b
Changes from pre-commit to Environ test
Aug 7, 2021
db7d722
Changes from pre-commit to Environ test
Aug 7, 2021
f657f45
Added parser test, calculation files for Environ
Nov 21, 2021
9ef55c5
Added parser test, calculation files for Environ
Nov 21, 2021
4168fee
Added parser test, calculation files for Environ
Nov 21, 2021
5009842
Run environ calculation parser only if it is an environ calculation.
Nov 22, 2021
3d13abb
Merge environ namelists test into one
Nov 22, 2021
90aae90
Fixed is_environ tag
Nov 22, 2021
acb2d0a
Update docs/source/user_guide/get_started/examples/pw_tutorial.rst
sudarshanv01 Nov 23, 2021
c8016b8
Update tests/conftest.py
sudarshanv01 Nov 23, 2021
fe50cfa
Update tests/conftest.py
sudarshanv01 Nov 23, 2021
5764e4f
Update tests/parsers/test_pw.py
sudarshanv01 Nov 23, 2021
ed7e70c
Update tests/calculations/test_pw.py
sudarshanv01 Nov 23, 2021
94d1e85
Update tests/parsers/test_pw.py
sudarshanv01 Nov 23, 2021
2e5bc1b
Removed Pt structure from conftest
Nov 23, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions aiida_quantumespresso/parsers/parse_raw/pw.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ def detect_important_message(logs, line):
logs.warning.append(message)


def parse_stdout(stdout, input_parameters, parser_options=None, parsed_xml=None):
def parse_stdout(stdout, input_parameters, parser_options=None, parsed_xml=None, settings={}):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that using mutable objects (as a dict is) for function defaults is dangerous. The reason is that the default can actually change if it is mutated. Rather, you should define settings=None and then in the function body you call settings = settings or {} which will assign the empty dict if it is None.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, that makes sense, good to know - thanks!

"""Parses the stdout content of a Quantum ESPRESSO `pw.x` calculation.

:param stdout: the stdout content as a string
Expand Down Expand Up @@ -306,6 +306,9 @@ def parse_stdout(stdout, input_parameters, parser_options=None, parsed_xml=None)
# Determine whether the input switched on an electric field
lelfield = input_parameters.get('CONTROL', {}).get('lelfield', False)

# Determine if an ENVIRON calculation run
is_environ = 'ENVIRON' in setttings

# Find some useful quantities.
if not parsed_xml.get('number_of_bands', None):
try:
Expand Down Expand Up @@ -743,7 +746,7 @@ def parse_stdout(stdout, input_parameters, parser_options=None, parsed_xml=None)
parsed_data['fermi_energy' + units_suffix] = default_energy_units
except Exception:
logs.warning.append('Error while parsing Fermi energy from the output file.')
elif 'Gaussian-smeared nuclei' in line:
elif is_environ and 'Gaussian-smeared nuclei' in line:
try:
value_potential_shift = float(line.split()[-2])
unit_potential_shift = line.split()[-1]
Expand Down
6 changes: 3 additions & 3 deletions aiida_quantumespresso/parsers/pw.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def parse(self, **kwargs):

parameters = self.node.inputs.parameters.get_dict()
parsed_xml, logs_xml = self.parse_xml(dir_with_bands, parser_options)
parsed_stdout, logs_stdout = self.parse_stdout(parameters, parser_options, parsed_xml)
parsed_stdout, logs_stdout = self.parse_stdout(parameters, parser_options, parsed_xml, settings)

parsed_bands = parsed_stdout.pop('bands', {})
parsed_structure = parsed_stdout.pop('structure', {})
Expand Down Expand Up @@ -295,7 +295,7 @@ def parse_xml(self, dir_with_bands=None, parser_options=None):

return parsed_data, logs

def parse_stdout(self, parameters, parser_options=None, parsed_xml=None):
def parse_stdout(self, parameters, parser_options=None, parsed_xml=None, settings={}):
sudarshanv01 marked this conversation as resolved.
Show resolved Hide resolved
"""Parse the stdout output file.

:param parameters: the input parameters dictionary
Expand All @@ -321,7 +321,7 @@ def parse_stdout(self, parameters, parser_options=None, parsed_xml=None):
return parsed_data, logs

try:
parsed_data, logs = parse_stdout(stdout, parameters, parser_options, parsed_xml)
parsed_data, logs = parse_stdout(stdout, parameters, parser_options, parsed_xml, settings)
except Exception:
logs.critical.append(traceback.format_exc())
self.exit_code_stdout = self.exit_codes.ERROR_UNEXPECTED_PARSER_EXCEPTION
Expand Down
37 changes: 5 additions & 32 deletions tests/calculations/test_pw.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def test_pw_ibrav(
calc_info = generate_calc_job(fixture_sandbox, entry_point_name, inputs)

cmdline_params = ['-in', 'aiida.in']
local_copy_list = [(upf.uuid, upf.filename, u'./pseudo/Si.upf')]
local_copy_list = [(upf.uuid, upf.filename, './pseudo/Si.upf')]
retrieve_list = ['aiida.out', './out/aiida.save/data-file-schema.xml', './out/aiida.save/data-file.xml']
retrieve_temporary_list = [['./out/aiida.save/K*[0-9]/eigenval*.xml', '.', 2]]

Expand Down Expand Up @@ -252,7 +252,7 @@ def test_pw_parallelization_duplicate_cmdline_flag(fixture_sandbox, generate_cal
assert 'Conflicting' in str(exc.value)


def test_environ_pw_namelists(fixture_sandbox, generate_calc_job, generate_inputs_pw, file_regression):
def test_environ_namelists(fixture_sandbox, generate_calc_job, generate_inputs_pw, file_regression):
"""Test that Environ does not change the contents of the pw file created."""
entry_point_name = 'quantumespresso.pw'

Expand All @@ -276,38 +276,11 @@ def test_environ_pw_namelists(fixture_sandbox, generate_calc_job, generate_input

with fixture_sandbox.open('aiida.in') as handle:
input_written = handle.read()

# Checks on the files written to the sandbox folder as raw input
assert sorted(fixture_sandbox.get_content_list()) == sorted(['aiida.in', 'pseudo', 'out', 'environ.in'])
# Check the aiida.in files are written correctly
file_regression.check(input_written, encoding='utf-8', extension='.in')

def test_environ_namelists(fixture_sandbox, generate_calc_job, generate_inputs_pw, file_regression):
"""Test that Environ namelists are created."""
entry_point_name = 'quantumespresso.pw'

inputs = generate_inputs_pw()
inputs['settings'] = orm.Dict(
dict={
'ENVIRON': {
'electrolyte_linearized': True,
'environ_type': 'input',
},
'BOUNDARY': {
'solvent_mode': 'electronic',
'electrolyte_mode': 'electronic',
},
'ELECTROSTATIC': {
'pbc_correction': 'parabolic',
}
},
)
generate_calc_job(fixture_sandbox, entry_point_name, inputs)

with fixture_sandbox.open('environ.in') as handle:
environ_written = handle.read()

# Checks on the files written to the sandbox folder as raw input
assert sorted(fixture_sandbox.get_content_list()) == sorted(['aiida.in', 'pseudo', 'out', 'environ.in'])
# Checks on the files written to the sandbox folder as raw input
file_regression.check(environ_written, encoding='utf-8', extension='.in')
# Check the aiida.in files are written correctly
sudarshanv01 marked this conversation as resolved.
Show resolved Hide resolved
file_regression.check(input_written, encoding='utf-8', extension='.aiida.in')
file_regression.check(environ_written, encoding='utf-8', extension='.environ.in')