Skip to content

Commit

Permalink
Fix Boltzmann KeyError
Browse files Browse the repository at this point in the history
* use try except and update with mda 2.6.0 release
  • Loading branch information
xhgchen committed Aug 9, 2023
1 parent 06539e7 commit 760bf9d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
14 changes: 7 additions & 7 deletions transport_analysis/tests/test_viscosity.py
Expand Up @@ -88,6 +88,12 @@ def characteristic_poly_helfand(
):
result = np.zeros(total_frames)

# update when mda 2.6.0 releases with typo fix
try:
boltzmann = constants["Boltzmann_constant"]
except KeyError:
boltzmann = constants["Boltzman_constant"]

for lag in range(total_frames):
sum = 0
sum = np.float64(sum)
Expand All @@ -102,13 +108,7 @@ def characteristic_poly_helfand(
vis_helf = (
sum
* n_dim
/ (
(total_frames - lag)
* 2
* constants["Boltzman_constant"]
* vol_avg
* temp_avg
)
/ ((total_frames - lag) * 2 * boltzmann * vol_avg * temp_avg)
)

result[lag] = vis_helf
Expand Down
10 changes: 8 additions & 2 deletions transport_analysis/viscosity.py
Expand Up @@ -112,6 +112,12 @@ def _prepare(self):
)
# self.results.timeseries not set here

# update when mda 2.6.0 releases with typo fix
try:
self.boltzmann = constants["Boltzmann_constant"]
except KeyError:
self.boltzmann = constants["Boltzman_constant"]

@staticmethod
def _parse_dim_type(dim_str):
r"""Sets up the desired dimensionality of the calculation."""
Expand Down Expand Up @@ -194,9 +200,9 @@ def _conclude(self):
# update viscosity by particle array
self.results.visc_by_particle[lag, :] = np.mean(sq_diff, axis=0)

# divide by 2, boltzman constant, vol_avg, and temp_avg
# divide by 2, boltzmann constant, vol_avg, and temp_avg
self.results.visc_by_particle = self.results.visc_by_particle / (
2 * constants["Boltzman_constant"] * self._vol_avg * self.temp_avg
2 * self.boltzmann * self._vol_avg * self.temp_avg
)
# average over # particles and update results array
self.results.timeseries = self.results.visc_by_particle.mean(axis=1)

0 comments on commit 760bf9d

Please sign in to comment.