Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parser for waves.sxb files from SPHInX #1224

Merged
merged 38 commits into from
Jan 25, 2024
Merged
Changes from 26 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
9464eea
Parser for waves.sxb files from Sphimnx
skatnagallu Nov 29, 2023
e755fb6
Format black
pyiron-runner Nov 29, 2023
c41a869
added missing modules
skatnagallu Nov 29, 2023
ceb0c2f
Update pyiron_atomistics/sphinx/output_parser.py
skatnagallu Nov 29, 2023
d439265
Changes according to sam's suggestions. Created properties
skatnagallu Nov 29, 2023
59f544e
SphinxWavesParser now uses a file name, and removed the _check_loaded…
skatnagallu Nov 29, 2023
71fac6c
added mesh as property
skatnagallu Nov 29, 2023
27cf39c
removed if cwd=none:
skatnagallu Nov 29, 2023
752ccdd
If the file_name is absolute path, cwd is ignored
skatnagallu Nov 29, 2023
293aa10
small syntax changes
skatnagallu Nov 29, 2023
4d075a7
Update pyiron_atomistics/sphinx/output_parser.py
skatnagallu Nov 29, 2023
a61eabf
Removed load function. Defined all variables in __init__()
skatnagallu Nov 29, 2023
cdb9a20
bug fix for _n_gk and implemented numpy version for _fillin()
skatnagallu Nov 29, 2023
a849b98
removed the _fillin static method.
skatnagallu Nov 29, 2023
c981207
removed numba import
skatnagallu Nov 29, 2023
0f62517
Format black
pyiron-runner Nov 29, 2023
9ecb56f
make a file for sphinx parsers
samwaseda Nov 30, 2023
bb32971
update path
samwaseda Nov 30, 2023
2355069
update path
samwaseda Nov 30, 2023
d6129dd
removed _fft_idx property and changed get_psi_rec() function
skatnagallu Nov 30, 2023
c98d101
Merge branch 'spx_output_parser_wavefunction' of https://github.com/p…
skatnagallu Nov 30, 2023
251b066
Merge branch 'main' into spx_output_parser_wavefunction
samwaseda Nov 30, 2023
63bbdef
Changed back to _fft_idx, and made it cached_property
skatnagallu Dec 1, 2023
4df58f0
Merge pull request #1236 from pyiron/main
jan-janssen Dec 2, 2023
c526ddf
Changed some properties to cached properties. removed _eps variable. …
skatnagallu Dec 6, 2023
6e0d5cf
Update pyiron_atomistics/sphinx/output_parser.py
samwaseda Dec 6, 2023
1090aff
Restore a line that I deleted accidentally.
samwaseda Dec 6, 2023
73894b1
add the doc string
skatnagallu Dec 6, 2023
48dd3ad
Translate indices to pythonic way.
skatnagallu Dec 6, 2023
a2e2b13
Modiefied get_psi_rec() to have an option to get compact wavefunctions
skatnagallu Dec 6, 2023
2303421
Update pyiron_atomistics/sphinx/output_parser.py
skatnagallu Dec 7, 2023
e73c0e9
Merge pull request #1250 from pyiron/spx_add_tests
skatnagallu Dec 8, 2023
f60648c
added waves.sxb for sphinx_test_waves
skatnagallu Dec 11, 2023
9963e4f
added a test for SphinxWavesReader
skatnagallu Dec 15, 2023
82e4198
added a proper waves.sxb file for test
skatnagallu Dec 18, 2023
d7ac87a
Format black
pyiron-runner Jan 23, 2024
adc140a
take absolute value before taking the mean for test_waves()
skatnagallu Jan 23, 2024
f0c59e7
Update tests/sphinx/test_parsers.py
samwaseda Jan 24, 2024
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
105 changes: 105 additions & 0 deletions pyiron_atomistics/sphinx/output_parser.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from functools import cached_property
import numpy as np
import re
import scipy.constants
from pathlib import Path
import h5py
import warnings


Expand Down Expand Up @@ -417,3 +419,106 @@ def results(self):
if len(value) > 0:
results["dft"][key] = value
return results


class SphinxWavesReader:
"""Class to read SPHInX waves.sxb files (HDF5 format)

Initialize with waves.sxb filename, or use load ()

"""

def __init__(self, file_name="waves.sxb", cwd="."):
"""
Args:
file_name (str): file name
cwd (str): directory path
"""
if Path(file_name).is_absolute():
self.wfile = h5py.File(Path(file_name))
else:
path = Path(cwd) / Path(file_name)
self.wfile = h5py.File(path)

@property
def _n_gk(self):
return self.wfile['nGk'][:]

@cached_property
def mesh(self):
return self.wfile["meshDim"][:]

@property
def Nx(self):
return self.mesh[0]

@property
def Ny(self):
return self.mesh[1]

@property
def Nz(self):
return self.mesh[2]

@cached_property
def n_states(self):
return self.wfile["nPerK"][0]

@cached_property
def n_spin(self):
return self.wfile["nSpin"].shape[0]

@cached_property
def k_weights(self):
return self.wfile["kWeights"][:]

@cached_property
def k_vec(self):
return self.wfile["kVec"][:]

@cached_property
def eps(self):
"""All eigenvalues (in Hartree) as (nk,n_states) block"""
return (self.wfile['eps'][:].reshape(-1, self.n_spin, self.n_states)).T

@cached_property
def _fft_idx(self):
fft_idx = []
off = 0
for ngk in self._n_gk:
fft_idx.append(self.wfile["fftIdx"][off : off + ngk])
off += ngk
return fft_idx

def get_psi_rec(self, i, ispin, ik, compact=False):
"""
Loads a single wavefunction on full FFT mesh of shape mesh.

params: i: state index (int)
ispin: spin index (int)
ik: k index (int)
compact: (bool)
returns:
res: complex valued wavefunction indexed by (i,ispin,ik) loaded on to the FFT mesh.
compact_wave: compact wavefunctions, without loading on FFT mesh.
"""
#translate indices to pythonic style.
i = np.arange(self.n_states)[i]
ik = np.arange(self.nk)[ik]
ispin = np.arange(self.n_spin)[ispin]

res = np.zeros(shape=self.mesh, dtype=np.complex128)
off = self._n_gk[ik] * (i + ispin * self.n_states)
psire = self.wfile[f"psi-{ik+1}.re"][off : off + self._n_gk[ik]]
psiim = self.wfile[f"psi-{ik+1}.im"][off : off + self._n_gk[ik]]
samwaseda marked this conversation as resolved.
Show resolved Hide resolved
res.flat[self._fft_idx[ik]] = psire + 1j * psiim
samwaseda marked this conversation as resolved.
Show resolved Hide resolved
if compact:
compact_wave = psire + 1j * psiim
return compact_wave
skatnagallu marked this conversation as resolved.
Show resolved Hide resolved
return res

@property
def nk(self):
"""Number of k-points"""
return self.k_weights.shape[0]

Loading