Skip to content
This repository has been archived by the owner on Sep 11, 2023. It is now read-only.

Commit

Permalink
[thermo] amend util unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
cwehmeyer committed Feb 19, 2017
1 parent 5d0aeef commit c2ee821
Showing 1 changed file with 50 additions and 25 deletions.
75 changes: 50 additions & 25 deletions pyemma/thermo/tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,8 +317,9 @@ def test_umbrella_sampling_bias_sequences_1x0(self):
force_constants = np.array([
util._ensure_force_constant(1.0, 1),
util._ensure_force_constant(2.0, 1)], dtype=np.float64)
width = np.zeros(shape=(umbrella_centers.shape[1],), dtype=np.float64)
self._assert_bias_sequences(
util._get_umbrella_bias_sequences(trajs, umbrella_centers, force_constants),
util._get_umbrella_bias_sequences(trajs, umbrella_centers, force_constants, width),
[np.array([[0.0, 1.0], [0.125, 0.25], [0.5, 0.0]])])

def test_umbrella_sampling_bias_sequences_1x1(self):
Expand All @@ -329,48 +330,72 @@ def test_umbrella_sampling_bias_sequences_1x1(self):
force_constants = np.array([
util._ensure_force_constant(1.0, 1),
util._ensure_force_constant(2.0, 1)], dtype=np.float64)
width = np.zeros(shape=(umbrella_centers.shape[1],), dtype=np.float64)
self._assert_bias_sequences(
util._get_umbrella_bias_sequences(trajs, umbrella_centers, force_constants),
util._get_umbrella_bias_sequences(trajs, umbrella_centers, force_constants, width),
[np.array([[0.0, 1.0], [0.125, 0.25], [0.5, 0.0]])])

def test_umbrella_sampling_bias_sequences_catches_unmatching_dimension(self):
# wrong centers + constants
with self.assertRaises(TypeError):
util._get_umbrella_bias_sequences([np.array([[0.0, 0.0], [0.5, 0.1], [1.0, 0.2]])],
np.array([[1.0, 1.0]]), [[[1.0, 0.0], [1.0, 0.0]]])
util._get_umbrella_bias_sequences(
[np.array([[0.0, 0.0], [0.5, 0.1], [1.0, 0.2]])],
np.array([[1.0, 1.0]]), [[[1.0, 0.0], [1.0, 0.0]]],
np.array([0.0, 0.0]))
with self.assertRaises(TypeError):
util._get_umbrella_bias_sequences([np.array([[0.0, 0.0], [0.5, 0.1], [1.0, 0.2]])],
[[1.0, 1.0]], np.array([[[1.0, 0.0], [1.0, 0.0]]]))
util._get_umbrella_bias_sequences(
[np.array([[0.0, 0.0], [0.5, 0.1], [1.0, 0.2]])],
[[1.0, 1.0]], np.array([[[1.0, 0.0], [1.0, 0.0]]]),
np.array([0.0, 0.0]))
with self.assertRaises(ValueError):
util._get_umbrella_bias_sequences([np.array([[0.0, 0.0], [0.5, 0.1], [1.0, 0.2]])],
np.array([1.0, 1.0]), np.array([[[1.0, 0.0], [1.0, 0.0]]]))
util._get_umbrella_bias_sequences(
[np.array([[0.0, 0.0], [0.5, 0.1], [1.0, 0.2]])],
np.array([1.0, 1.0]), np.array([[[1.0, 0.0], [1.0, 0.0]]]),
np.array([0.0, 0.0]))
with self.assertRaises(ValueError):
util._get_umbrella_bias_sequences([np.array([[0.0, 0.0], [0.5, 0.1], [1.0, 0.2]])],
np.array([[1.0, 1.0]]), np.array([[1.0, 0.0], [1.0, 0.0]]))
util._get_umbrella_bias_sequences(
[np.array([[0.0, 0.0], [0.5, 0.1], [1.0, 0.2]])],
np.array([[1.0, 1.0]]), np.array([[1.0, 0.0], [1.0, 0.0]]),
np.array([0.0, 0.0]))
with self.assertRaises(ValueError):
util._get_umbrella_bias_sequences([np.array([[0.0, 0.0], [0.5, 0.1], [1.0, 0.2]])],
np.array([[[1.0, 1.0]]]), np.array([[[1.0, 0.0], [1.0, 0.0]]]))
util._get_umbrella_bias_sequences(
[np.array([[0.0, 0.0], [0.5, 0.1], [1.0, 0.2]])],
np.array([[[1.0, 1.0]]]), np.array([[[1.0, 0.0], [1.0, 0.0]]]),
np.array([0.0, 0.0]))
with self.assertRaises(ValueError):
util._get_umbrella_bias_sequences([np.array([[0.0, 0.0], [0.5, 0.1], [1.0, 0.2]])],
np.array([[1.0, 1.0]]), np.array([[[[1.0, 0.0], [1.0, 0.0]]]]))
util._get_umbrella_bias_sequences(
[np.array([[0.0, 0.0], [0.5, 0.1], [1.0, 0.2]])],
np.array([[1.0, 1.0]]), np.array([[[[1.0, 0.0], [1.0, 0.0]]]]),
np.array([0.0, 0.0]))
# conflicting centers + constants
with self.assertRaises(ValueError):
util._get_umbrella_bias_sequences([np.array([[0.0, 0.0], [0.5, 0.1], [1.0, 0.2]])],
np.array([[1.0, 1.0, 1.0]]), np.array([[[1.0, 0.0], [1.0, 0.0]]]))
util._get_umbrella_bias_sequences(
[np.array([[0.0, 0.0], [0.5, 0.1], [1.0, 0.2]])],
np.array([[1.0, 1.0, 1.0]]), np.array([[[1.0, 0.0], [1.0, 0.0]]]),
np.array([0.0, 0.0]))
with self.assertRaises(ValueError):
util._get_umbrella_bias_sequences([np.array([[0.0, 0.0], [0.5, 0.1], [1.0, 0.2]])],
np.array([[1.0]]), np.array([[[1.0, 0.0], [1.0, 0.0]]]))
util._get_umbrella_bias_sequences(
[np.array([[0.0, 0.0], [0.5, 0.1], [1.0, 0.2]])],
np.array([[1.0]]), np.array([[[1.0, 0.0], [1.0, 0.0]]]),
np.array([0.0, 0.0]))
with self.assertRaises(ValueError):
util._get_umbrella_bias_sequences([np.array([[0.0, 0.0], [0.5, 0.1], [1.0, 0.2]])],
np.array([[1.0, 1.0], [2.0, 2.0]]), np.array([[[1.0, 0.0], [1.0, 0.0]]]))
util._get_umbrella_bias_sequences(
[np.array([[0.0, 0.0], [0.5, 0.1], [1.0, 0.2]])],
np.array([[1.0, 1.0], [2.0, 2.0]]), np.array([[[1.0, 0.0], [1.0, 0.0]]]),
np.array([0.0, 0.0]))
# traj does not match valid centers + constants
with self.assertRaises(TypeError):
util._get_umbrella_bias_sequences([[[0.0, 0.0], [0.5, 0.1], [1.0, 0.2]]],
np.array([[1.0, 1.0]]), np.array([[[1.0, 0.0], [1.0, 0.0]]]))
util._get_umbrella_bias_sequences(
[[[0.0, 0.0], [0.5, 0.1], [1.0, 0.2]]],
np.array([[1.0, 1.0]]), np.array([[[1.0, 0.0], [1.0, 0.0]]]),
np.array([0.0, 0.0]))
with self.assertRaises(ValueError):
util._get_umbrella_bias_sequences([np.array([0.0, 0.5, 1.0])],
np.array([[1.0, 1.0]]), np.array([[[1.0, 0.0], [1.0, 0.0]]]))
util._get_umbrella_bias_sequences(
[np.array([0.0, 0.5, 1.0])],
np.array([[1.0, 1.0]]), np.array([[[1.0, 0.0], [1.0, 0.0]]]),
np.array([0.0, 0.0]))
with self.assertRaises(ValueError):
util._get_umbrella_bias_sequences(
[np.array([[0.0, 1.0, 2.0], [0.5, 1.0, 2.0], [1.0, 1.0, 2.0]])],
np.array([[1.0, 1.0]]), np.array([[[1.0, 0.0], [1.0, 0.0]]]))
np.array([[1.0, 1.0]]), np.array([[[1.0, 0.0], [1.0, 0.0]]]),
np.array([0.0, 0.0]))

0 comments on commit c2ee821

Please sign in to comment.