Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 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
18 changes: 18 additions & 0 deletions express/parsers/apps/espresso/formats/txt.py
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,24 @@ def potential_profile(self, text):
data = self._general_output_parser(text, **settings.REGEX["potential_profile"])
return [[e[i] for e in data] for i in range(4)]

def wavefunction_amplitude(self, text):
"""
Extracts wavefunction amplitude along z coordinate.

Example input:
#z (A) Amplitude
-4.89 0.0012
-4.78 0.0034
-4.67 0.0067
-4.56 0.0123
-4.44 0.0234

Returns:
list[list[float]]
"""
data = self._general_output_parser(text, **settings.REGEX["wavefunction_amplitude"])
return [[e[i] for e in data] for i in range(2)]

def charge_density_profile(self, text):
"""
Extracts total charge density along z.
Expand Down
6 changes: 6 additions & 0 deletions express/parsers/apps/espresso/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,9 +274,15 @@ def reaction_energies(self):
def _get_esm_file(self):
return find_file(".esm1", self.work_dir)

def _get_wavefunction_file(self):
return find_file(settings.WAVEFUNCTION_FILE, self.work_dir)

def potential_profile(self):
return self.txt_parser.potential_profile(self._get_file_content(self._get_esm_file()))

def wavefunction_amplitude(self):
return self.txt_parser.wavefunction_amplitude(self._get_file_content(self._get_wavefunction_file()))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to multiply by alat_to_angstrom


def charge_density_profile(self):
return self.txt_parser.charge_density_profile(self._get_file_content(self._get_esm_file()))

Expand Down
7 changes: 7 additions & 0 deletions express/parsers/apps/espresso/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
AVERAGE_FILE = "avg.dat"
HP_FILE = "__prefix__.Hubbard_parameters.dat" # contains Hubbard U and V parameters
HP_NN_FILE = "HUBBARD.dat" # contains Hubbard V parameters for 6 nearest neighbors
WAVEFUNCTION_FILE = "wf_r.dat"

COMMON_REGEX = r"{0}\s+[=:<>]\s*([-+]?\d*\.?\d*([Ee][+-]?\d+)?)"
DOUBLE_REGEX = GENERAL_REGEX.double_number
Expand Down Expand Up @@ -121,6 +122,12 @@
"output_type": "float",
"match_groups": [1, 2, 3, 4],
},
"wavefunction_amplitude": {
"regex": r"^\s+({0})\s+({0})".format(DOUBLE_REGEX),
"occurrences": 0,
"output_type": "float",
"match_groups": [1, 2],
},
"charge_density_profile": {
"regex": r"^\s+({0})\s+({0})\s+{0}\s+{0}\s+{0}".format(DOUBLE_REGEX),
"occurrences": 0,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from express.properties.non_scalar.two_dimensional_plot import TwoDimensionalPlotProperty


class WavefunctionAmplitude(TwoDimensionalPlotProperty):
"""
Wavefunction amplitude.
"""

def __init__(self, name, parser, *args, **kwargs):
super(WavefunctionAmplitude, self).__init__(name, parser, *args, **kwargs)
wavefunction_amplitude = self.parser.wavefunction_amplitude()
self.xDataArray = wavefunction_amplitude[0]
self.yDataSeries = [wavefunction_amplitude[1]]

3 changes: 3 additions & 0 deletions express/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@
"potential_profile": {
"reference": "express.properties.non_scalar.two_dimensional_plot.potential_profile.PotentialProfile"
},
"wavefunction_amplitude": {
"reference": "express.properties.non_scalar.two_dimensional_plot.wavefunction_amplitude.WavefunctionAmplitude"
},
"charge_density_profile": {
"reference": "express.properties.non_scalar.two_dimensional_plot.charge_density_profile.ChargeDensityProfile"
},
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ dependencies = [
"munch==2.5.0",
"pymatgen>=2023.8.10",
"ase>=3.17.0",
"mat3ra-esse>=2024.1.25.post7",
"mat3ra-esse @ git+https://github.com/Exabyte-io/esse.git@6cff939259da4f358e7295c66b5a37a84d764e98",
"jarvis-tools>=2023.12.12",
# To avoid module 'numpy.linalg._umath_linalg' has no attribute '_ilp64' in Colab
"numpy>=1.24.4,<2",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from tests.unit import UnitTestBase
from express.properties.non_scalar.two_dimensional_plot.wavefunction_amplitude import WavefunctionAmplitude


WAVEFUNCTION_AMPLITUDE_RAW_DATA = [
[0.0, 0.0050251256, 0.0100502513, 0.0150753769, 0.0201005025],
[0.0000322091, 0.0000072134, -0.0000218274, -0.0000540398, -0.0000883573]
]

WAVEFUNCTION_AMPLITUDE = {
"name": "wavefunction_amplitude",
"xDataArray": [0.0, 0.0050251256, 0.0100502513, 0.0150753769, 0.0201005025],
"yDataSeries": [[0.0000322091, 0.0000072134, -0.0000218274, -0.0000540398, -0.0000883573]],
"xAxis": {"label": "coordinate", "units": "angstrom"},
"yAxis": {"label": "amplitude", "units": "a.u."},
}


class WavefunctionAmplitudeTest(UnitTestBase):
def setUp(self):
super().setUp()

def tearDown(self):
super().tearDown()

def test_wavefunction_amplitude(self):
parser = self.get_mocked_parser("wavefunction_amplitude", WAVEFUNCTION_AMPLITUDE_RAW_DATA)
property_ = WavefunctionAmplitude("wavefunction_amplitude", parser)
self.assertDeepAlmostEqual(property_.serialize_and_validate(), WAVEFUNCTION_AMPLITUDE)

Loading