Skip to content

Commit

Permalink
chore: rename averaged -> average (#123)
Browse files Browse the repository at this point in the history
* chore: rename averaged -> average

* chore: add setuptools to requirements.txt

* chore: update requirements.txt and revert addition of setuptools
  • Loading branch information
azech-hqs committed Nov 15, 2022
1 parent 04ed9ea commit 3f124d3
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 18 deletions.
4 changes: 2 additions & 2 deletions express/parsers/apps/espresso/formats/txt.py
Original file line number Diff line number Diff line change
Expand Up @@ -810,7 +810,7 @@ def final_lattice_vectors(self, text):
if cell_parameters_last_index < 0: return self.initial_lattice_vectors(text)
return self._extract_lattice(text[cell_parameters_last_index:])

def averaged_quantity(self, stdout_file: str) -> np.ndarray:
def average_quantity(self, stdout_file: str) -> np.ndarray:
"""
Extract planar and macroscopic averages of a quantity from the output of average.x (output file or avg.dat)
The format is as follows:
Expand All @@ -835,5 +835,5 @@ def averaged_quantity(self, stdout_file: str) -> np.ndarray:
average_file = find_file(stdout_file, self.work_dir)
if type(average_file) == str and os.path.isfile(average_file):
dtype = np.dtype([("x", float), ("planar_average", float), ("macroscopic_average", float)])
data = np.fromregex(average_file, settings.REGEX["averaged_quantity"]["regex"], dtype)
data = np.fromregex(average_file, settings.REGEX["average_quantity"]["regex"], dtype)
return data
4 changes: 2 additions & 2 deletions express/parsers/apps/espresso/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,8 +333,8 @@ def final_structure_strings(self):
pass
return structures

def averaged_potential(self):
data = self.txt_parser.averaged_quantity(self.stdout_file)
def average_potential(self):
data = self.txt_parser.average_quantity(self.stdout_file)
data["x"] *= Constant.BOHR # convert to angstrom
data["planar_average"] *= Constant.RYDBERG # convert to eV
data["macroscopic_average"] *= Constant.RYDBERG # convert to eV
Expand Down
2 changes: 1 addition & 1 deletion express/parsers/apps/espresso/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@
"occurrences": 0,
"output_type": "str",
},
"averaged_quantity": {
"average_quantity": {
"regex": r"\s*({0})\s+({0})\s+({0})".format(DOUBLE_REGEX),
},
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
from express.properties.non_scalar.two_dimensional_plot import TwoDimensionalPlotProperty


class AveragedPotentialProfile(TwoDimensionalPlotProperty):
class AveragePotentialProfile(TwoDimensionalPlotProperty):
"""
Averaged potential profile plot.
Average potential profile plot.
"""

def __init__(self, name: str, parser, *args, **kwargs):
super().__init__(name, parser, *args, **kwargs)

self.data = self.safely_invoke_parser_method("averaged_potential")
self.data = self.safely_invoke_parser_method("average_potential")
self.xDataArray = self.data["x"].tolist()
self.yDataSeries = [self.data["planar_average"].tolist(), self.data["macroscopic_average"].tolist()]
4 changes: 2 additions & 2 deletions express/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@
'file_content': {
'reference': 'express.properties.non_scalar.file_content.FileContent'
},
'averaged_potential_profile': {
'reference': 'express.properties.non_scalar.two_dimensional_plot.averaged_potential_profile.AveragedPotentialProfile'
'average_potential_profile': {
'reference': 'express.properties.non_scalar.two_dimensional_plot.average_potential_profile.AveragePotentialProfile'
},
}

Expand Down
2 changes: 1 addition & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ click==7.0
coverage==5.3
cycler==0.10.0
decorator==4.4.2
esse==2022.11.10.post0
esse==2022.11.15.post0
exabyte-json-include==2021.05.06
flask==1.0.2
idna==2.7
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from mock import MagicMock
import numpy as np
from tests.unit import UnitTestBase
from express.properties.non_scalar.two_dimensional_plot.averaged_potential_profile import AveragedPotentialProfile
from express.properties.non_scalar.two_dimensional_plot.average_potential_profile import AveragePotentialProfile


AVG_POTENTIAL = {
"name": "averaged_potential_profile",
"name": "average_potential_profile",
"xDataArray": [0, 2.0943951, 4.1887902, 6.28318531],
"yDataSeries": [[0, 0, 0, 0], [1.0, -0.5, -0.5, 1.0]],
"yAxis": {
Expand All @@ -19,7 +19,7 @@
}


class AveragedPotentialProfileTest(UnitTestBase):
class AveragePotentialProfileTest(UnitTestBase):
def setUp(self):
super().setUp()

Expand All @@ -39,9 +39,9 @@ def create_mock_data(self, n_points: int = 300):
dtype = np.dtype([("x", float), ("planar_average", float), ("macroscopic_average", float)])
return np.array(list(zip(x, p_x, m_x)), dtype=dtype)

def test_averaged_potential(self):
averaged_potential_data = self.create_mock_data(n_points=4)
def test_average_potential(self):
average_potential_data = self.create_mock_data(n_points=4)
parser = MagicMock()
parser.attach_mock(MagicMock(return_value=averaged_potential_data), "averaged_potential")
property_ = AveragedPotentialProfile("averaged_potential_profile", parser)
parser.attach_mock(MagicMock(return_value=average_potential_data), "average_potential")
property_ = AveragePotentialProfile("average_potential_profile", parser)
self.assertDeepAlmostEqual(property_.serialize_and_validate(), AVG_POTENTIAL, places=6)

0 comments on commit 3f124d3

Please sign in to comment.