Skip to content

Commit

Permalink
First round of review
Browse files Browse the repository at this point in the history
  • Loading branch information
mbercx committed Dec 15, 2023
1 parent aa6eb9d commit b21fc70
Showing 1 changed file with 14 additions and 17 deletions.
31 changes: 14 additions & 17 deletions src/aiida_quantumespresso/workflows/pw/relax.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@ def define(cls, spec):
"""Define the process specification."""
# yapf: disable
super().define(spec)
spec.expose_inputs(PwBaseWorkChain, namespace='base_relax',
exclude=('clean_workdir', 'pw.structure', 'pw.parent_folder'),
namespace_options={'help': 'Inputs for the `PwBaseWorkChain` for the main relax loop.'})
spec.expose_inputs(PwBaseWorkChain, namespace='base_init_relax',
exclude=('clean_workdir', 'pw.structure', 'pw.parent_folder'),
namespace_options={'required': False, 'populate_defaults': False,
'help': (
'Inputs for the `PwBaseWorkChain` that runs an initial geometry optimization, typically with looser'
'precision settings to find a geometry that is already closer to the final one quickly.'
)})
spec.expose_inputs(PwBaseWorkChain, namespace='base_relax',
exclude=('clean_workdir', 'pw.structure', 'pw.parent_folder'),
namespace_options={'help': 'Inputs for the `PwBaseWorkChain` for the main relax loop.'})
spec.input('structure', valid_type=orm.StructureData, help='The inputs structure.')
spec.input('meta_convergence', valid_type=orm.Bool, default=lambda: orm.Bool(True),
help='If `True` the workchain will perform a meta-convergence on the cell volume.')
Expand All @@ -55,10 +55,13 @@ def define(cls, spec):
),
cls.results,
)
spec.exit_code(400, 'ERROR_MAX_ITERATIONS_EXCEEDED',
message='The maximum number of meta convergence iterations was exceeded.')
spec.exit_code(401, 'ERROR_SUB_PROCESS_FAILED_RELAX',
message='the relax `PwBaseWorkChain` sub process failed')
spec.exit_code(402, 'ERROR_SUB_PROCESS_FAILED_FINAL_SCF',
message='this exit code has been deprecated since the final SCF has been removed.')
message='the final scf PwBaseWorkChain sub process failed '
'(deprecated since the final SCF has been removed)')
spec.exit_code(403, 'ERROR_SUB_PROCESS_FAILED_INIT_RELAX',
message='the initial relaxation `PwBaseWorkChain` sub process failed')
spec.expose_outputs(PwBaseWorkChain, exclude=('output_structure',))
Expand Down Expand Up @@ -254,7 +257,7 @@ def should_run_relax(self):
# Stop if the maximum number of meta iterations has been reached
if self.ctx.iteration == self.inputs.max_meta_convergence_iterations.value:
self.report('Maximum number of meta convergence iterations reached.')
return False
return self.exit_codes.ERROR_MAX_ITERATIONS_EXCEEDED

base_relax_workchain = self.ctx.base_relax_workchains[-1]

Expand All @@ -278,10 +281,11 @@ def should_run_relax(self):
}
}
new_kpts_mesh, _ = create_kpoints_from_distance(**inputs_create_kpoints).get_kpoints_mesh()
if tuple(input_kpts_mesh) != tuple(new_kpts_mesh):

if not all(k1 <= k2 for k1, k2 in zip(new_kpts_mesh, input_kpts_mesh)):
self.report(
'k-points mesh changed for specified `kpoints_distance` due to a change in the unit cell. '
'Running another geometry optimization with new mesh.'
'Density of k-points mesh has increased for the specified `kpoints_distance` due to a change in the'
' unit cell. Running another geometry optimization with new mesh.'
)
return True

Expand All @@ -292,11 +296,7 @@ def run_relax(self):
"""Run the `PwBaseWorkChain` to run a relax `PwCalculation`."""
self.ctx.iteration += 1
inputs = self.ctx.relax_inputs

if 'base_init_relax_workchain' in self.ctx:
inputs.pw.structure = self.ctx.base_init_relax_workchain.outputs.output_structure
else:
inputs.pw.structure = self.ctx.current_structure
inputs.pw.structure = self.ctx.current_structure

# If one of the nested `PwBaseWorkChain`s changed the number of bands, apply it here
if self.ctx.current_number_of_bands is not None:
Expand Down Expand Up @@ -352,10 +352,7 @@ def results(self):
if self.ctx.relax_inputs.pw.parameters['CONTROL']['calculation'] != 'scf':
self.out('output_structure', final_relax_workchain.outputs.output_structure)

try:
self.out_many(self.exposed_outputs(self.ctx.workchain_scf, PwBaseWorkChain))
except AttributeError:
self.out_many(self.exposed_outputs(final_relax_workchain, PwBaseWorkChain))
self.out_many(self.exposed_outputs(final_relax_workchain, PwBaseWorkChain))

def on_terminated(self):
"""Clean the working directories of all child calculations if `clean_workdir=True` in the inputs."""
Expand Down

0 comments on commit b21fc70

Please sign in to comment.