Skip to content

Commit 86f3413

Browse files
committed
update FE for mtrexee
1 parent 228d211 commit 86f3413

File tree

1 file changed

+33
-2
lines changed

1 file changed

+33
-2
lines changed

ensemble_md/analysis/analyze_free_energy.py

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,36 @@ def _combine_df_adjacent(df_adjacent, state_ranges, df_err_adjacent=None, err_ty
249249
return df, df_err, overlap_bool
250250

251251

252+
def _calculate_df(estimators):
253+
"""
254+
An internal function used in :func:`calculate_free_energy` to calculate a list of free energies between adjacent
255+
states for all replicas.
256+
257+
Parameters
258+
----------
259+
estimators : list
260+
A list of estimators fitting the input data for all replicas. With this, the user
261+
can access all the free energies and their associated uncertainties for all states and replicas.
262+
In our code, these estimators come from the function :func:`_apply_estimators`.
263+
264+
Returns
265+
-------
266+
df : float
267+
Free energy differences between for specified replica.
268+
df_err : float
269+
Uncertainties corresponding to the values in :code:`df`.
270+
271+
See also
272+
--------
273+
:func:`calculate_free_energy`
274+
"""
275+
l = np.linspace(0, 1, num=len(estimators[0].index))
276+
estimators[0].index = l
277+
estimators[0].columns = l
278+
est = estimators[0].loc[0, 1]
279+
return est
280+
281+
252282
def calculate_free_energy(data, state_ranges, df_method="MBAR", err_method="propagate", n_bootstrap=None, seed=None, MTREXEE=False): # noqa: E501
253283
"""
254284
Caculates the averaged free energy profile with the chosen method given :math:`u_{nk}` or :math:`dH/dλ` data
@@ -308,11 +338,12 @@ def calculate_free_energy(data, state_ranges, df_method="MBAR", err_method="prop
308338
else:
309339
n_tot = state_ranges[-1] + 1
310340
estimators = _apply_estimators(data, df_method)
341+
print(estimators)
311342
if MTREXEE is False:
312343
df_adjacent, df_err_adjacent = _calculate_df_adjacent(estimators)
313344
df, df_err, overlap_bool = _combine_df_adjacent(df_adjacent, state_ranges, df_err_adjacent, err_type='propagate') # noqa: E501
314345
else:
315-
df, df_err = _calculate_df_adjacent(estimators)
346+
df, df_err = _calculate_df(estimators)
316347

317348
if err_method == 'bootstrap':
318349
if seed is not None:
@@ -328,7 +359,7 @@ def calculate_free_energy(data, state_ranges, df_method="MBAR", err_method="prop
328359
df_adjacent, df_err_adjacent = _calculate_df_adjacent(bootstrap_estimators)
329360
df_sampled, _, overlap_bool = _combine_df_adjacent(df_adjacent, state_ranges, df_err_adjacent, err_type='propagate') # doesn't matter what value err_type here is # noqa: E501
330361
else:
331-
df_sampled, _ = _calculate_df_adjacent(bootstrap_estimators)
362+
df_sampled, _ = _calculate_df(bootstrap_estimators)
332363
df_bootstrap.append(df_sampled)
333364
error_bootstrap = np.std(df_bootstrap, axis=0, ddof=1)
334365

0 commit comments

Comments
 (0)