Skip to content

Commit cabcccd

Browse files
authored
Add quantum espresso eample (#1)
* Add quantum espresso eample * add hatchling
1 parent 5c311c8 commit cabcccd

File tree

11 files changed

+20144
-42
lines changed

11 files changed

+20144
-42
lines changed

.github/workflows/pipeline.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ jobs:
2121
- name: Test
2222
shell: bash -l {0}
2323
run: |
24+
export ESPRESSO_PSEUDO=$(pwd)/espresso/pseudo
25+
pip install --no-deps --no-build-isolation -e qe_xml_parser
2426
verdi presto --profile-name pwd
2527
echo -e 'from aiida import load_profile\nload_profile()\n\nfrom python_workflow_definition.aiida import load_workflow_json\n\n\nif __name__ == "__main__":\n workgraph = load_workflow_json(file_name="workflow.json")\n workgraph.run()' > test_with_aiida.py
2628
python test_with_aiida.py
@@ -40,6 +42,8 @@ jobs:
4042
- name: Test
4143
shell: bash -l {0}
4244
run: |
45+
export ESPRESSO_PSEUDO=$(pwd)/espresso/pseudo
46+
pip install --no-deps --no-build-isolation -e qe_xml_parser
4347
echo -e 'from jobflow.managers.local import run_locally\nfrom python_workflow_definition.jobflow import load_workflow_json\n\n\nif __name__ == "__main__":\n flow = load_workflow_json(file_name="workflow.json")\n print(run_locally(flow))' > test_with_jobflow.py
4448
python test_with_jobflow.py
4549
@@ -58,5 +62,7 @@ jobs:
5862
- name: Test
5963
shell: bash -l {0}
6064
run: |
65+
export ESPRESSO_PSEUDO=$(pwd)/espresso/pseudo
66+
pip install --no-deps --no-build-isolation -e qe_xml_parser
6167
echo -e 'from python_workflow_definition.pyiron_base import load_workflow_json\n\n\nif __name__ == "__main__":\n delayed_object_lst = load_workflow_json(file_name="workflow.json")\n print(delayed_object_lst[-1].pull())' > test_with_pyiron.py
6268
python test_with_pyiron.py

README.md

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,4 @@
1-
# Arithmetic Example Workflow
2-
[![Pipeline](https://github.com/pythonworkflow/example-workflow/actions/workflows/pipeline.yml/badge.svg)](https://github.com/pythonworkflow/example-workflow/actions/workflows/pipeline.yml)
3-
4-
Template repository for publishing an interoperable workflow based on the Python Workflow Definition.
5-
6-
## Content
7-
The minimal workflow consists of three files:
8-
9-
| File | Explanation |
10-
|-------------------|---------------------------------------------------------|
11-
| `environment.yml` | Conda environment for software dependencies |
12-
| `workflow.py` | Python functions representing the nodes of the workflow |
13-
| `workflow.json` | Workflow graph consisting of nodes and edges |
14-
15-
Additional optional files for the publication of the workflow:
16-
17-
| File | Explanation |
18-
|----------------------------------|------------------------------------------|
19-
| `README.md` | Readme file to introduce the workflow |
20-
| `.github/workflows/pipeline.yml` | Github Actions to test the workflow |
21-
22-
## Publish your workflow
23-
You can publish your workflow in five simple steps:
24-
* Fork the repository and clone your fork locally.
25-
* Export your workflow to the Python Workflow Definition using the `python_workflow_definition` Python package, by calling the `write_workflow_json()` function.
26-
* Replace the `environment.yml`, `workflow.py` and `workflow.json` in your local folder with the files for your workflow. In addition, you can add additional files if they are required and update the `README.md` to explain your workflow.
27-
* Commit the files locally using `git add -A` and `git commit -m "add my workflow"`
28-
* Push your workflow to Github `git push`
29-
1+
# Quantum Espresso Bulk Modulus Workflow
2+
[![Pipeline](https://github.com/pythonworkflow/quantum-espresso-bulk-modulus-workflow/actions/workflows/pipeline.yml/badge.svg)](https://github.com/pythonworkflow/quantum-espresso-bulk-modulus-workflow/actions/workflows/pipeline.yml)
303

4+
Workflow to calculate the equilibrium bulk modulus with the [quantum ESPRESSO](https://www.quantum-espresso.org) density functional theory simulation code. This repository demonstrates the use of the [python-workflow-definition](https://github.com/pythonworkflow/python-workflow-definition) Python package and the [example-workflow](https://github.com/pythonworkflow/example-workflow) repository template.

environment.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,12 @@ channels:
22
- conda-forge
33
dependencies:
44
- python =3.12
5+
- ase=3.24.0
6+
- hatchling =1.27.0
7+
- matplotlib=3.10.1
8+
- xmlschema=3.4.3
9+
- optimade=1.2.3
10+
- qe=7.2
11+
- qe-tools=2.0.0
512
- pip:
613
- python-workflow-definition==0.0.1

espresso/pseudo/Al.pbe-n-kjpaw_psl.1.0.0.UPF

Lines changed: 18497 additions & 0 deletions
Large diffs are not rendered by default.

qe_xml_parser/pyproject.toml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[build-system]
2+
requires = ["hatchling"]
3+
build-backend = "hatchling.build"
4+
5+
[project]
6+
name = "qe_xml_parser"
7+
version = "0.0.1"
8+
description = "Quantum Espresso xml output parser"
9+
authors = [
10+
{ name = "Marnik Bercx", email = "marnik.bercx@psi.ch" },
11+
]
12+
license = { text = "MIT" }
13+
dependencies = ["numpy", "xmlschema", "qe_tools", "ase"]

qe_xml_parser/src/qe_xml_parser/__init__.py

Whitespace-only changes.
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import numpy
2+
3+
from xmlschema import XMLSchema
4+
from qe_tools import CONSTANTS
5+
6+
from ase import Atoms
7+
from importlib.resources import files
8+
9+
from . import schemas
10+
11+
12+
def parse_pw(xml_file):
13+
"""Parse a Quantum Espresso XML output file."""
14+
15+
xml_dict = XMLSchema(str(files(schemas) / "qes_230310.xsd")).to_dict(xml_file)
16+
17+
parsed_results = {}
18+
19+
try:
20+
cell = (
21+
numpy.array(
22+
[v for v in xml_dict["output"]["atomic_structure"]["cell"].values()]
23+
)
24+
* CONSTANTS.bohr_to_ang
25+
)
26+
symbols = [
27+
el["@name"]
28+
for el in xml_dict["output"]["atomic_structure"]["atomic_positions"]["atom"]
29+
]
30+
positions = (
31+
numpy.array(
32+
[
33+
el["$"]
34+
for el in xml_dict["output"]["atomic_structure"][
35+
"atomic_positions"
36+
]["atom"]
37+
]
38+
)
39+
* CONSTANTS.bohr_to_ang
40+
)
41+
42+
parsed_results["ase_structure"] = Atoms(
43+
cell=cell,
44+
positions=positions,
45+
symbols=symbols,
46+
pbc=True,
47+
)
48+
except KeyError:
49+
pass
50+
51+
try:
52+
parsed_results["energy"] = (
53+
xml_dict["output"]["total_energy"]["etot"] * CONSTANTS.ry_to_ev
54+
)
55+
except KeyError:
56+
pass
57+
58+
try:
59+
parsed_results["forces"] = (
60+
numpy.array(xml_dict["output"]["forces"]["$"]).reshape(
61+
xml_dict["output"]["forces"]["@dims"]
62+
)
63+
* 2
64+
* CONSTANTS.ry_to_ev
65+
/ CONSTANTS.bohr_to_ang
66+
)
67+
except KeyError:
68+
pass
69+
70+
return parsed_results

qe_xml_parser/src/qe_xml_parser/schemas/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)