Skip to content

Commit 1ae4b68

Browse files
committed
Add implemention of CalcJobImporter for pw.x calculations
1 parent fc1a940 commit 1ae4b68

File tree

9 files changed

+1777
-0
lines changed

9 files changed

+1777
-0
lines changed

pyproject.toml

+4
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ aiida-quantumespresso = 'aiida_quantumespresso.cli:cmd_root'
8787
'quantumespresso.xspectra' = 'aiida_quantumespresso.calculations.xspectra:XspectraCalculation'
8888
'quantumespresso.open_grid' = 'aiida_quantumespresso.calculations.open_grid:OpenGridCalculation'
8989

90+
[project.entry-points.'aiida.calculations.importers']
91+
'quantumespresso.pw' = 'aiida_quantumespresso.calculations.importers.pw:PwCalculationImporter'
92+
9093
[project.entry-points.'aiida.data']
9194
'quantumespresso.force_constants' = 'aiida_quantumespresso.data.force_constants:ForceConstantsData'
9295
'quantumespresso.hubbard_structure' = 'aiida_quantumespresso.data.hubbard_structure:HubbardStructureData'
@@ -171,6 +174,7 @@ disable = [
171174
'locally-disabled',
172175
'logging-format-interpolation',
173176
'no-else-raise',
177+
'too-few-public-methods',
174178
'too-many-arguments',
175179
'too-many-ancestors',
176180
'too-many-branches',

src/aiida_quantumespresso/calculations/importers/__init__.py

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# -*- coding: utf-8 -*-
2+
""":class:`aiida.engine.processes.calcjobs.importer.CalcJobImporter` implementation for ``PwCalculation``."""
3+
from __future__ import annotations
4+
5+
import pathlib
6+
import tempfile
7+
8+
from aiida.engine import CalcJobImporter
9+
from aiida.orm import AbstractCode, Node, RemoteData
10+
11+
12+
class PwCalculationImporter(CalcJobImporter):
13+
""":class:`aiida.engine.processes.calcjobs.importer.CalcJobImporter` implementation for ``PwCalculation``.
14+
15+
This class allows to import a completed ``pw.x`` calculation that was executed without AiiDA, into an AiiDA profile.
16+
"""
17+
18+
@staticmethod
19+
def parse_remote_data( # pylint: disable=arguments-differ
20+
remote_data: RemoteData,
21+
input_file_name: str,
22+
code: AbstractCode | None = None,
23+
metadata: dict | None = None,
24+
pseudo_folder_path: str | None = None,
25+
) -> dict[str, Node | dict]:
26+
"""Parse the input nodes from the files in the provided ``RemoteData``.
27+
28+
:param remote_data: the remote data node containing the raw input files.
29+
:param input_file_name: the filename of the main Quantum ESPRESSO input file.
30+
:param code: Optional ``AbstractCode`` node to attach to the imported node, as if it would have been run with
31+
the ``code`` input in a real run.
32+
:param metadata: Optional ``metadata`` inputs to set on the imported node, as if it would have been run with
33+
the ``metadata`` input in a real run.
34+
:returns: a dictionary with the parsed inputs nodes that match the input spec of the associated ``CalcJob``.
35+
"""
36+
from aiida_quantumespresso.tools.pwinputparser import create_builder_from_file
37+
38+
with tempfile.TemporaryDirectory() as tmppath:
39+
dirpath = pathlib.Path(tmppath) / 'folder'
40+
with remote_data.get_authinfo().get_transport() as transport:
41+
transport.copytree(remote_data.get_remote_path(), dirpath)
42+
43+
builder = create_builder_from_file(
44+
str(dirpath), input_file_name, code, metadata or {}, pseudo_folder_path=pseudo_folder_path
45+
)
46+
47+
inputs = dict(builder)
48+
inputs['remote_folder'] = remote_data
49+
50+
return inputs
+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# -*- coding: utf-8 -*-
2+
"""Tests for the :class:`aiida_quantumespresso.calculations.importers.pw.PwCalculationImporter` class."""
3+
from pathlib import Path
4+
5+
from aiida.engine import run
6+
from aiida.orm import RemoteData
7+
8+
from aiida_quantumespresso.calculations.importers.pw import PwCalculationImporter
9+
from aiida_quantumespresso.calculations.pw import PwCalculation
10+
11+
12+
def test_default(filepath_tests, fixture_code, aiida_localhost):
13+
"""Test importing a typical completed ``pw.x`` calculation."""
14+
aiida_localhost.configure()
15+
filepath_remote = Path(filepath_tests) / 'calculations' / 'importers' / 'test_pw' / 'test_default'
16+
remote_data = RemoteData(str(filepath_remote), computer=aiida_localhost)
17+
input_file_name = 'aiida.in'
18+
code = fixture_code('quantumespresso.pw')
19+
pseudo_folder_path = filepath_remote / 'pseudo'
20+
inputs = PwCalculationImporter().parse_remote_data(
21+
remote_data, input_file_name, code, pseudo_folder_path=str(pseudo_folder_path)
22+
)
23+
results, node = run.get_node(PwCalculation, **inputs)
24+
assert node.is_finished_ok
25+
assert node.is_imported
26+
assert set(results.keys()) == {'output_band', 'output_trajectory', 'output_parameters', 'retrieved'}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/bash
2+
exec > _scheduler-stdout.txt
3+
exec 2> _scheduler-stderr.txt
4+
5+
6+
7+
8+
'/home/sph/code/qe/qe-6.6/bin/pw.x' '-in' 'aiida.in' > 'aiida.out'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
&CONTROL
2+
calculation = 'scf'
3+
outdir = './out/'
4+
prefix = 'aiida'
5+
pseudo_dir = './pseudo/'
6+
verbosity = 'high'
7+
/
8+
&SYSTEM
9+
ecutrho = 2.4000000000d+02
10+
ecutwfc = 3.0000000000d+01
11+
ibrav = 0
12+
nat = 2
13+
ntyp = 1
14+
/
15+
&ELECTRONS
16+
/
17+
ATOMIC_SPECIES
18+
Si 28.085 Si.UPF
19+
ATOMIC_POSITIONS angstrom
20+
Si 0.0000000000 0.0000000000 0.0000000000
21+
Si 1.3575000000 1.3575000000 1.3575000000
22+
K_POINTS automatic
23+
2 2 2 0 0 0
24+
CELL_PARAMETERS angstrom
25+
0.0000000000 2.7150000000 2.7150000000
26+
2.7150000000 0.0000000000 2.7150000000
27+
2.7150000000 2.7150000000 0.0000000000

0 commit comments

Comments
 (0)