Skip to content
Merged
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
324 changes: 323 additions & 1 deletion jobflow_to_pyiron_base_qe.ipynb

Large diffs are not rendered by default.

334 changes: 333 additions & 1 deletion pyiron_base_to_jobflow_qe.ipynb

Large diffs are not rendered by default.

48 changes: 43 additions & 5 deletions quantum_espresso_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from ase.io import write
from adis_tools.parsers import parse_pw
import matplotlib.pyplot as plt
import numpy as np


def write_input(input_dict, working_directory="."):
Expand Down Expand Up @@ -57,7 +58,7 @@ def generate_structures(structure, strain_lst):
structure_strain.cell * strain ** (1 / 3), scale_atoms=True
)
structure_lst.append(structure_strain)
return {str(i): s.todict() for i, s in enumerate(structure_lst)}
return {str(i): atoms_to_json_dict(atoms=s) for i, s in enumerate(structure_lst)}


def plot_energy_volume_curve(volume_lst, energy_lst):
Expand All @@ -67,9 +68,46 @@ def plot_energy_volume_curve(volume_lst, energy_lst):
plt.savefig("evcurve.png")


def get_bulk_structure(name, a, cubic):
return bulk(
name=name,
def get_bulk_structure(element, a, cubic):
ase_atoms = bulk(
name=element,
a=a,
cubic=cubic,
).todict()
)
return atoms_to_json_dict(atoms=ase_atoms)


def atoms_to_json_dict(atoms):
"""
Convert an ASE Atoms object to a fully JSON-serializable dictionary
that uses only Python base data types.

Parameters:
-----------
atoms : ase.Atoms
The Atoms object to convert

Returns:
--------
dict
A dictionary representation using only Python base types
"""
# Get the dictionary representation from ASE
atoms_dict = atoms.todict()

# Create a new dictionary with JSON-serializable values
json_dict = {}

# Convert numpy arrays to lists
for key, value in atoms_dict.items():
if isinstance(value, np.ndarray):
# Convert numpy boolean values to Python booleans
if value.dtype == np.bool_ or value.dtype == bool:
json_dict[key] = value.tolist()
# Convert numpy arrays of numbers to Python lists
else:
json_dict[key] = value.tolist()
else:
json_dict[key] = value

return json_dict
2 changes: 1 addition & 1 deletion workflow_qe.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"31": "python_workflow_definition.pyiron_base.get_list"
},
"edges": [
{"target": 0, "targetHandle": "name", "source": 9, "sourceHandle": null},
{"target": 0, "targetHandle": "element", "source": 9, "sourceHandle": null},
{"target": 0, "targetHandle": "a", "source": 10, "sourceHandle": null},
{"target": 0, "targetHandle": "cubic", "source": 11, "sourceHandle": null},
{"target": 1, "targetHandle": "working_directory", "source": 12, "sourceHandle": null},
Expand Down
Loading