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

Add implemention of CalcJobImporter for pw.x calculations #847

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ aiida-quantumespresso = 'aiida_quantumespresso.cli:cmd_root'
'quantumespresso.xspectra' = 'aiida_quantumespresso.calculations.xspectra:XspectraCalculation'
'quantumespresso.open_grid' = 'aiida_quantumespresso.calculations.open_grid:OpenGridCalculation'

[project.entry-points.'aiida.calculations.importers']
'quantumespresso.pw' = 'aiida_quantumespresso.calculations.importers.pw:PwCalculationImporter'

[project.entry-points.'aiida.data']
'quantumespresso.force_constants' = 'aiida_quantumespresso.data.force_constants:ForceConstantsData'
'quantumespresso.hubbard_structure' = 'aiida_quantumespresso.data.hubbard_structure:HubbardStructureData'
Expand Down Expand Up @@ -171,6 +174,7 @@ disable = [
'locally-disabled',
'logging-format-interpolation',
'no-else-raise',
'too-few-public-methods',
'too-many-arguments',
'too-many-ancestors',
'too-many-branches',
Expand Down
3 changes: 2 additions & 1 deletion src/aiida_quantumespresso/calculations/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,8 @@ def prepare_for_submission(self, folder):
codeinfo = datastructures.CodeInfo()
codeinfo.cmdline_params = (list(cmdline_params) + ['-in', self.metadata.options.input_filename])
codeinfo.stdout_name = self.metadata.options.output_filename
codeinfo.code_uuid = self.inputs.code.uuid
if 'code' in self.inputs:
codeinfo.code_uuid = self.inputs.code.uuid
calcinfo.codes_info = [codeinfo]

calcinfo.local_copy_list = local_copy_list
Expand Down
Empty file.
50 changes: 50 additions & 0 deletions src/aiida_quantumespresso/calculations/importers/pw.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# -*- coding: utf-8 -*-
""":class:`aiida.engine.processes.calcjobs.importer.CalcJobImporter` implementation for ``PwCalculation``."""
from __future__ import annotations

import pathlib
import tempfile

from aiida.engine import CalcJobImporter
from aiida.orm import AbstractCode, Node, RemoteData


class PwCalculationImporter(CalcJobImporter):
""":class:`aiida.engine.processes.calcjobs.importer.CalcJobImporter` implementation for ``PwCalculation``.

This class allows to import a completed ``pw.x`` calculation that was executed without AiiDA, into an AiiDA profile.
"""

@staticmethod
def parse_remote_data( # pylint: disable=arguments-differ
remote_data: RemoteData,
input_file_name: str,
code: AbstractCode | None = None,
metadata: dict | None = None,
pseudo_folder_path: str | None = None,
) -> dict[str, Node | dict]:
"""Parse the input nodes from the files in the provided ``RemoteData``.

:param remote_data: the remote data node containing the raw input files.
:param input_file_name: the filename of the main Quantum ESPRESSO input file.
sphuber marked this conversation as resolved.
Show resolved Hide resolved
:param code: Optional ``AbstractCode`` node to attach to the imported node, as if it would have been run with
the ``code`` input in a real run.
:param metadata: Optional ``metadata`` inputs to set on the imported node, as if it would have been run with
the ``metadata`` input in a real run.
:returns: a dictionary with the parsed inputs nodes that match the input spec of the associated ``CalcJob``.
"""
from aiida_quantumespresso.tools.pwinputparser import create_builder_from_file

with tempfile.TemporaryDirectory() as tmppath:
dirpath = pathlib.Path(tmppath) / 'folder'
with remote_data.get_authinfo().get_transport() as transport:
transport.copytree(remote_data.get_remote_path(), dirpath)

builder = create_builder_from_file(
str(dirpath), input_file_name, code, metadata or {}, pseudo_folder_path=pseudo_folder_path
)

inputs = dict(builder)
inputs['remote_folder'] = remote_data

return inputs
4 changes: 3 additions & 1 deletion src/aiida_quantumespresso/tools/pwinputparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ def create_builder_from_file(input_folder, input_file_name, code, metadata, pseu

if isinstance(code, str):
code = load_code(code)
builder.code = code

if code is not None:
builder.code = code

# read input_file
if isinstance(input_folder, str):
Expand Down
26 changes: 26 additions & 0 deletions tests/calculations/importers/test_pw.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# -*- coding: utf-8 -*-
"""Tests for the :class:`aiida_quantumespresso.calculations.importers.pw.PwCalculationImporter` class."""
from pathlib import Path

from aiida.engine import run
from aiida.orm import RemoteData

from aiida_quantumespresso.calculations.importers.pw import PwCalculationImporter
from aiida_quantumespresso.calculations.pw import PwCalculation


def test_default(filepath_tests, fixture_code, aiida_localhost):
"""Test importing a typical completed ``pw.x`` calculation."""
aiida_localhost.configure()
filepath_remote = Path(filepath_tests) / 'calculations' / 'importers' / 'test_pw' / 'test_default'
remote_data = RemoteData(str(filepath_remote), computer=aiida_localhost)
input_file_name = 'aiida.in'
code = fixture_code('quantumespresso.pw')
pseudo_folder_path = filepath_remote / 'pseudo'
inputs = PwCalculationImporter().parse_remote_data(
remote_data, input_file_name, code, pseudo_folder_path=str(pseudo_folder_path)
)
results, node = run.get_node(PwCalculation, **inputs)
assert node.is_finished_ok
assert node.is_imported
assert set(results.keys()) == {'output_band', 'output_trajectory', 'output_parameters', 'retrieved'}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash
exec > _scheduler-stdout.txt
exec 2> _scheduler-stderr.txt




'/home/sph/code/qe/qe-6.6/bin/pw.x' '-in' 'aiida.in' > 'aiida.out'
27 changes: 27 additions & 0 deletions tests/calculations/importers/test_pw/test_default/aiida.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
&CONTROL
calculation = 'scf'
outdir = './out/'
prefix = 'aiida'
pseudo_dir = './pseudo/'
verbosity = 'high'
/
&SYSTEM
ecutrho = 2.4000000000d+02
ecutwfc = 3.0000000000d+01
ibrav = 0
nat = 2
ntyp = 1
/
&ELECTRONS
/
ATOMIC_SPECIES
Si 28.085 Si.UPF
ATOMIC_POSITIONS angstrom
Si 0.0000000000 0.0000000000 0.0000000000
Si 1.3575000000 1.3575000000 1.3575000000
K_POINTS automatic
2 2 2 0 0 0
CELL_PARAMETERS angstrom
0.0000000000 2.7150000000 2.7150000000
2.7150000000 0.0000000000 2.7150000000
2.7150000000 2.7150000000 0.0000000000
Loading
Loading