Skip to content

Commit

Permalink
Add error handling for missing parameters. Update version to match PyPI.
Browse files Browse the repository at this point in the history
  • Loading branch information
anotherjoshsmith committed Mar 1, 2018
1 parent b9df6f5 commit 2bb524f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
16 changes: 14 additions & 2 deletions plumitas/plumitas.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,15 @@ def read_hills(filename='HILLS'):
return read_colvar(filename)


def get_frame_weights(df, temp, bias):
def get_frame_weights(df, temp, static_bias=None):
if not static_bias:
raise ValueError('You must supply a static bias column with the'
'"static_bias" arg to get frame weights.')

# calculate normalized weight
k = 8.314e-3
beta = 1 / (temp * k)
w = np.exp(beta * df.loc[:, bias])
w = np.exp(beta * df.loc[:, static_bias])
df['weight'] = w / w.sum()
return

Expand Down Expand Up @@ -117,6 +121,10 @@ def make_2d_free_energy_surface(df, x, y, temp, weight=None, bins=20,
-------
axes: matplotlib.AxesSubplot
"""
if not weight:
raise ValueError('You must supply frame weights to generate the FES.'
'Try using plumitas.get_frame_weights first.')

k = 8.314e-3
beta = 1 / (temp * k)

Expand Down Expand Up @@ -192,6 +200,10 @@ def potential_of_mean_force(df, collective_variables,
-------
axes: matplotlib.AxesSubplot
"""
if not weight:
raise ValueError('You must supply frame weights to generate the FES.'
'Try using plumitas.get_frame_weights first.')

k = 8.314e-3
beta = 1 / (temp * k)

Expand Down
6 changes: 4 additions & 2 deletions plumitas/tests/test_plumitas.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ def test_make_2d_free_energy_surface():
multi=number_of_replicas,
unbiased=True)
# overwrite weight column above with real, normalized weights
plm.get_frame_weights(multi_colvar_df, bias='pb.bias', temp=300)
plm.get_frame_weights(multi_colvar_df,
static_bias='pb.bias', temp=300)

# send over to 2D FES method
axis = plm.make_2d_free_energy_surface(multi_colvar_df,
Expand All @@ -59,7 +60,8 @@ def test_potential_of_mean_force():
colvar_file = op.join(data_path, "COLVAR")
colvar_df = plm.read_colvar(colvar_file)
# get normalized frame weights
plm.get_frame_weights(colvar_df, bias='pb.bias', temp=300)
plm.get_frame_weights(colvar_df,
static_bias='pb.bias', temp=300)
axis = plm.potential_of_mean_force(colvar_df,
colvar_df.columns,
weight='weight',
Expand Down
2 changes: 1 addition & 1 deletion plumitas/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
_version_major = 0
_version_minor = 0
_version_micro = 1 # use '' for first of series, number for 1 and above
_version_extra = 'dev1'
_version_extra = 'dev2'
# _version_extra = '' # Uncomment this for full releases

# Construct full version string from these.
Expand Down

0 comments on commit 2bb524f

Please sign in to comment.