Skip to content

Commit

Permalink
Add implemention of CalcJobImporter for pw.x calculations
Browse files Browse the repository at this point in the history
  • Loading branch information
sphuber committed Sep 20, 2023
1 parent fc1a940 commit 1ae4b68
Show file tree
Hide file tree
Showing 9 changed files with 1,777 additions and 0 deletions.
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
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.
: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
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

0 comments on commit 1ae4b68

Please sign in to comment.