Skip to content

Commit

Permalink
Same for generic outputs
Browse files Browse the repository at this point in the history
  • Loading branch information
pmrv committed Jun 9, 2024
1 parent 18420ce commit dbe84d8
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 26 deletions.
69 changes: 46 additions & 23 deletions pyiron_atomistics/atomistics/job/atomistic.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
from typing import Callable, Union, Tuple
from ase.io import write as ase_write
import posixpath
from functools import wraps

from pyiron_atomistics.atomistics.structure.atoms import Atoms
from pyiron_atomistics.atomistics.structure.neighbors import NeighborsTrajectory
from pyiron_atomistics.atomistics.structure.has_structure import HasStructure
Expand Down Expand Up @@ -1003,26 +1005,38 @@ def load_default(self):
"""
self.load_string(file_content)

def _suppress_notfound(meth):
@wraps(meth)
def f(*args, **kwargs):
try:
return meth(*args, **kwargs)
except ValueError:
return None
return f

class GenericOutput(object):
def __init__(self, job):
self._job = job

@property
@_suppress_notfound
def cells(self):
return self._job["output/generic/cells"]
return self._job.project_hdf5["output/generic/cells"]

@property
@_suppress_notfound
def energy_pot(self):
return self._job["output/generic/energy_pot"]
return self._job.project_hdf5["output/generic/energy_pot"]

@property
@_suppress_notfound
def energy_tot(self):
return self._job["output/generic/energy_tot"]
return self._job.project_hdf5["output/generic/energy_tot"]

@property
@_suppress_notfound
def forces(self):
return self._job["output/generic/forces"]
return self._job.project_hdf5["output/generic/forces"]

@property
def force_max(self):
Expand All @@ -1033,40 +1047,47 @@ def force_max(self):
return np.linalg.norm(self.forces, axis=-1).max(axis=-1)

@property
@_suppress_notfound
def positions(self):
return self._job["output/generic/positions"]
return self._job.project_hdf5["output/generic/positions"]

@property
@_suppress_notfound
def pressures(self):
return self._job["output/generic/pressures"]
return self._job.project_hdf5["output/generic/pressures"]

@property
@_suppress_notfound
def steps(self):
return self._job["output/generic/steps"]
return self._job.project_hdf5["output/generic/steps"]

@property
@_suppress_notfound
def temperature(self):
return self._job["output/generic/temperature"]
return self._job.project_hdf5["output/generic/temperature"]

@property
@_suppress_notfound
def computation_time(self):
return self._job["output/generic/computation_time"]
return self._job.project_hdf5["output/generic/computation_time"]

@property
def unwrapped_positions(self):
unwrapped_positions = self._job["output/generic/unwrapped_positions"]
if unwrapped_positions is not None:
try:
unwrapped_positions = self._job.project_hdf5["output/generic/unwrapped_positions"]
return unwrapped_positions
else:
except ValueError:
return self._job.structure.positions + self.total_displacements

@property
@_suppress_notfound
def volume(self):
return self._job["output/generic/volume"]
return self._job.project_hdf5["output/generic/volume"]

@property
@_suppress_notfound
def indices(self):
return self._job["output/generic/indices"]
return self._job.project_hdf5["output/generic/indices"]

@property
def displacements(self):
Expand All @@ -1078,13 +1099,14 @@ def displacements(self):
- there are atoms which move by more than half a box length in any direction within
two snapshots (due to periodic boundary conditions)
"""
unwrapped_positions = self._job["output/generic/unwrapped_positions"]
if unwrapped_positions is not None:
try:
unwrapped_positions = self._job.project_hdf5["output/generic/unwrapped_positions"]
return np.diff(
np.append([self._job.structure.positions], unwrapped_positions, axis=0),
axis=0,
)
return self.get_displacements(self._job.structure, self.positions, self.cells)
except ValueError:
return self.get_displacements(self._job.structure, self.positions, self.cells)

@staticmethod
def get_displacements(structure, positions, cells):
Expand Down Expand Up @@ -1129,14 +1151,15 @@ def total_displacements(self):
- there are atoms which move by more than half a box length in any direction within
two snapshots (due to periodic boundary conditions)
"""
unwrapped_positions = self._job["output/generic/unwrapped_positions"]
if unwrapped_positions is not None:
try:
unwrapped_positions = self._job.project_hdf5["output/generic/unwrapped_positions"]
return unwrapped_positions - self._job.structure.positions
return np.cumsum(self.displacements, axis=0)
except ValueError:
return np.cumsum(self.displacements, axis=0)

def __dir__(self):
hdf5_path = self._job["output/generic"]
if hdf5_path is not None:
try:
hdf5_path = self._job.project_hdf5["output/generic"]
return hdf5_path.list_nodes()
else:
except ValueError:
return []
7 changes: 4 additions & 3 deletions pyiron_atomistics/sphinx/interactive.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,14 +375,15 @@ def check_band_occupancy(self, plot=True):
"""
import matplotlib.pylab as plt

elec_dict = self._job["output/generic/dft"]["n_valence"]
if elec_dict is None:
try:
elec_dict = self._job.project_hdf5["output/generic/dft"]["n_valence"]
except ValueError:
raise AssertionError("Number of electrons not parsed")
n_elec = np.sum(
[elec_dict[k] for k in self._job.structure.get_chemical_symbols()]
)
n_elec = int(np.ceil(n_elec / 2))
bands = self._job["output/generic/dft/bands_occ"][-1]
bands = self._job.project_hdf5["output/generic/dft/bands_occ"][-1]
bands = bands.reshape(-1, bands.shape[-1])
max_occ = np.sum(~np.isclose(bands, 0), axis=-1).max()
n_bands = bands.shape[-1]
Expand Down

0 comments on commit dbe84d8

Please sign in to comment.