Skip to content

Commit

Permalink
Merge pull request #291 from choderalab/no_string_raises
Browse files Browse the repository at this point in the history
No string raises
  • Loading branch information
mrshirts committed Feb 24, 2018
2 parents 9582976 + 4900df8 commit 24fc03f
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 13 deletions.
6 changes: 3 additions & 3 deletions pymbar/confidenceintervals.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ def generateConfidenceIntervals(replicates, K):
print(replicate['error'])
print("destimated")
print(replicate['destimated'])
raise "isnan"
raise ArithmaticError("Encountered isnan in computation")
else:
if abs(replicate['error']) <= alpha * replicate['destimated']:
a += 1.0
Expand All @@ -238,7 +238,7 @@ def generateConfidenceIntervals(replicates, K):
print(replicate['error'])
print("destimated")
print(replicate['destimated'])
raise "isnan"
raise ArithmaticError("Encountered isnan in computation")
else:
if abs(replicate['error'][i]) <= alpha * replicate['destimated'][i]:
a += 1.0
Expand All @@ -254,7 +254,7 @@ def generateConfidenceIntervals(replicates, K):
print(replicate['error'])
print("ij_estimated")
print(replicate['destimated'])
raise "isnan"
raise ArithmaticError("Encountered isnan in computation")
else:
if abs(replicate['error'][i, j]) <= alpha * replicate['destimated'][i, j]:
a += 1.0
Expand Down
8 changes: 4 additions & 4 deletions pymbar/mbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
import numpy as np
import numpy.linalg as linalg
from pymbar import mbar_solvers
from pymbar.utils import kln_to_kn, kn_to_n, ParameterError, logsumexp, check_w_normalized
from pymbar.utils import kln_to_kn, kn_to_n, ParameterError, DataError, logsumexp, check_w_normalized

DEFAULT_SOLVER_PROTOCOL = mbar_solvers.DEFAULT_SOLVER_PROTOCOL
DEFAULT_SUBSAMPLING_PROTOCOL = mbar_solvers.DEFAULT_SUBSAMPLING_PROTOCOL
Expand Down Expand Up @@ -1129,7 +1129,7 @@ def computePerturbedFreeEnergies(self, u_ln, compute_uncertainty=True, uncertain

# Check dimensions.
if (N < self.N):
raise "There seems to be too few samples in u_kn. You must evaluate at the new potential with all of the samples used originally."
raise DataError("There seems to be too few samples in u_kn. You must evaluate at the new potential with all of the samples used originally.")

state_list = np.arange(L) # need to get it into the correct shape
A_in = np.array([0])
Expand Down Expand Up @@ -1357,7 +1357,7 @@ def computePMF(self, u_n, bin_n, nbins, uncertainties='from-lowest', pmf_referen

# Sanity check.
if (len(indices) == 0):
raise "WARNING: bin %d has no samples -- all bins must have at least one sample." % i
raise DataError("WARNING: bin %d has no samples -- all bins must have at least one sample." % i)

# Compute dimensionless free energy of occupying state i.
f_i[i] = - logsumexp(log_w_n[indices])
Expand Down Expand Up @@ -1441,7 +1441,7 @@ def computePMF(self, u_n, bin_n, nbins, uncertainties='from-lowest', pmf_referen
return (f_i, df_i)

else:
raise "Uncertainty method '%s' not recognized." % uncertainties
raise ParameterError("Uncertainty method '%s' not recognized." % uncertainties)


#=========================================================================
Expand Down
12 changes: 6 additions & 6 deletions pymbar/old_mbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
import math
import numpy as np
import numpy.linalg as linalg
from pymbar.utils import _logsum, kln_to_kn, kn_to_n, ParameterError
from pymbar.utils import _logsum, kln_to_kn, kn_to_n, ParameterError, DataError

#=========================================================================
# MBAR class definition
Expand Down Expand Up @@ -1147,7 +1147,7 @@ def computePerturbedFreeEnergies(self, u_ln, compute_uncertainty=True, uncertain

# Check dimensions.
if (N < self.N):
raise "There seems to be too few samples in u_kn. You must evaluate at the new potential with all of the samples used originally."
raise DataError("There seems to be too few samples in u_kn. You must evaluate at the new potential with all of the samples used originally.")

# Retrieve N and K for convenience.
N = self.N
Expand Down Expand Up @@ -1543,7 +1543,7 @@ def computePMF(self, u_n, bin_n, nbins, uncertainties='from-lowest', pmf_referen
return (f_i, df_i)

else:
raise "Uncertainty method '%s' not recognized." % uncertainties
raise ParameterError("Uncertainty method '%s' not recognized." % uncertainties)

return

Expand Down Expand Up @@ -1604,7 +1604,7 @@ def computePMF_states(self, u_n, bin_n, nbins):

# Sanity check.
if (len(indices) == 0):
raise "WARNING: bin %d has no samples -- all bins must have at least one sample." % i
raise DataError("WARNING: bin %d has no samples -- all bins must have at least one sample." % i)

# Compute dimensionless free energy of occupying state i.
f_i[i] = - _logsum(log_w_n[indices])
Expand Down Expand Up @@ -1754,8 +1754,8 @@ def _pseudoinverse(self, A, tol=1.0e-10):
# Get size
[M, N] = A.shape
if N != M:
raise "pseudoinverse can only be computed for square matrices: dimensions were %d x %d" % (
M, N)
raise DataError("pseudoinverse can only be computed for square matrices: dimensions were %d x %d" % (
M, N))

# Make sure A contains no nan.
if(np.any(np.isnan(A))):
Expand Down
9 changes: 9 additions & 0 deletions pymbar/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,3 +400,12 @@ class BoundsError(Exception):
"""
pass


class DataError(Exception):

"""
Data is inconsistent.
"""
pass

0 comments on commit 24fc03f

Please sign in to comment.