Skip to content

Commit

Permalink
Update docstrings for units.py for the case of entropy values
Browse files Browse the repository at this point in the history
  • Loading branch information
jaclark5 committed Nov 13, 2024
1 parent eb2fa34 commit f312b6d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
2 changes: 0 additions & 2 deletions src/alchemlyb/estimators/mbar_.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,6 @@ def fit(self, u_nk, compute_entropy_enthalpy=False):
self._d_delta_h_.attrs = u_nk.attrs
self._delta_s_.attrs = u_nk.attrs
self._d_delta_s_.attrs = u_nk.attrs
self._delta_s_.attrs["energy_unit"] = "k"
self._d_delta_s_.attrs["energy_unit"] = "k"

return self

Expand Down
5 changes: 5 additions & 0 deletions src/alchemlyb/parsing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,13 @@ def wrapper(outfile, T, *args, **kwargs):
dict_with_df = func(outfile, T, *args, **kwargs)
for k in dict_with_df.keys():
if dict_with_df[k] is not None:

if T < 273:
raise ValueError("Temperature must be in Kelvin.")

Check warning on line 36 in src/alchemlyb/parsing/__init__.py

View check run for this annotation

Codecov / codecov/patch

src/alchemlyb/parsing/__init__.py#L36

Added line #L36 was not covered by tests

dict_with_df[k].attrs["temperature"] = T
dict_with_df[k].attrs["energy_unit"] = "kT"

return dict_with_df

return wrapper
13 changes: 12 additions & 1 deletion src/alchemlyb/postprocessors/units.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
def to_kT(df, T=None):
"""Convert the unit of a DataFrame to `kT`.
Note that if entropy values are passed it is assumed that they are
multiplied by the temperature, S * T.
If temperature `T` is not provided, the DataFrame need to have attribute
`temperature` and `energy_unit`. Otherwise, the temperature of the output
dateframe will be set accordingly.
Expand All @@ -25,7 +28,7 @@ def to_kT(df, T=None):
df : DataFrame
DataFrame to convert unit.
T : float
Temperature (default: None).
Temperature (default: None) in Kelvin.
Returns
-------
Expand All @@ -34,6 +37,8 @@ def to_kT(df, T=None):
"""
new_df = df.copy()
if T is not None:
if T < 273:
raise ValueError("Temperature must be in Kelvin.")

Check warning on line 41 in src/alchemlyb/postprocessors/units.py

View check run for this annotation

Codecov / codecov/patch

src/alchemlyb/postprocessors/units.py#L41

Added line #L41 was not covered by tests
new_df.attrs["temperature"] = T
elif "temperature" not in df.attrs:
raise TypeError("Attribute temperature not found in the input " "Dataframe.")
Expand Down Expand Up @@ -61,6 +66,9 @@ def to_kT(df, T=None):
def to_kcalmol(df, T=None):
"""Convert the unit of a DataFrame to kcal/mol.
Note that if entropy values are passed, the result is S * T in units
of kcal/mol.
If temperature `T` is not provided, the DataFrame need to have attribute
`temperature` and `energy_unit`. Otherwise, the temperature of the output
dateframe will be set accordingly.
Expand All @@ -86,6 +94,9 @@ def to_kcalmol(df, T=None):
def to_kJmol(df, T=None):
"""Convert the unit of a DataFrame to kJ/mol.
Note that if entropy values are passed, the result is S * T in units
of kJ/mol.
If temperature `T` is not provided, the DataFrame need to have attribute
`temperature` and `energy_unit`. Otherwise, the temperature of the output
dateframe will be set accordingly.
Expand Down

0 comments on commit f312b6d

Please sign in to comment.