Beispiel #1
0
 def test_ensure_umbrella_center_from_ndarray(self):
     # dimension=1
     us_center = util._ensure_umbrella_center(np.array([1.0]), 1)
     self._assert_us_center(us_center, 1)
     np.testing.assert_array_equal(us_center,
                                   np.array([1.0], dtype=np.float64))
     # dimension=3, uniform
     us_center = util._ensure_umbrella_center(np.array([1.0, 1.0, 1.0]), 3)
     self._assert_us_center(us_center, 3)
     np.testing.assert_array_equal(
         us_center, np.array([1.0, 1.0, 1.0], dtype=np.float64))
     # dimension=4, not uniform
     us_center = util._ensure_umbrella_center(
         np.array([1.0, 2.0, 3.0, 4.0]), 4)
     self._assert_us_center(us_center, 4)
     np.testing.assert_array_equal(
         us_center, np.array([1.0, 2.0, 3.0, 4.0], dtype=np.float64))
     # dimension=4x1, not uniform
     us_center = util._ensure_umbrella_center(
         np.array([
             [1.0, 2.0, 3.0, 4.0],
         ]), 4)
     self._assert_us_center(us_center, 4)
     np.testing.assert_array_equal(
         us_center, np.array([1.0, 2.0, 3.0, 4.0], dtype=np.float64))
Beispiel #2
0
 def test_ensure_umbrella_center_from_scalar(self):
     # dimension=1
     us_center = util._ensure_umbrella_center(1.0, 1)
     self._assert_us_center(us_center, 1)
     np.testing.assert_array_equal(us_center,
                                   np.array([1.0], dtype=np.float64))
     # dimension=3
     us_center = util._ensure_umbrella_center(1.0, 3)
     self._assert_us_center(us_center, 3)
     np.testing.assert_array_equal(
         us_center, np.array([1.0, 1.0, 1.0], dtype=np.float64))
Beispiel #3
0
 def test_umbrella_sampling_bias_sequences_1x1(self):
     trajs = [np.array([[0.0], [0.5], [1.0]])]
     umbrella_centers = np.array([
         util._ensure_umbrella_center(0.0, 1),
         util._ensure_umbrella_center(1.0, 1)
     ],
                                 dtype=np.float64)
     force_constants = np.array([
         util._ensure_force_constant(1.0, 1),
         util._ensure_force_constant(2.0, 1)
     ],
                                dtype=np.float64)
     self._assert_bias_sequences(
         util._get_umbrella_bias_sequences(trajs, umbrella_centers,
                                           force_constants),
         [np.array([[0.0, 1.0], [0.125, 0.25], [0.5, 0.0]])])
Beispiel #4
0
 def test_umbrella_sampling_bias_sequences_1x0(self):
     trajs = [np.array([0.0, 0.5, 1.0])]
     umbrella_centers = np.array([
         util._ensure_umbrella_center(0.0, 1),
         util._ensure_umbrella_center(1.0, 1)
     ],
                                 dtype=np.float64)
     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, width),
         [np.array([[0.0, 1.0], [0.125, 0.25], [0.5, 0.0]])])
Beispiel #5
0
 def test_ensure_umbrella_center_catches_unmatching_dimension(self):
     with self.assertRaises(ValueError):
         util._ensure_umbrella_center([1.0, 1.0], 1)
     with self.assertRaises(ValueError):
         util._ensure_umbrella_center([1.0, 1.0, 1.0], 2)
     with self.assertRaises(ValueError):
         util._ensure_umbrella_center([1.0, 1.0], 3)
     with self.assertRaises(ValueError):
         util._ensure_umbrella_center([[1.0], [1.0]], 1)
     with self.assertRaises(ValueError):
         util._ensure_umbrella_center([[1.0], [1.0]], 3)
     with self.assertRaises(ValueError):
         util._ensure_umbrella_center([[1.0, 1.0], [1.0]], 3)