def test_right_type_angles(self): assert_equal(self.agroup.angles(), calc_angles(self.agroup.atom1.positions, self.agroup.atom2.positions, self.agroup.atom3.positions)) assert_equal(self.agroup.angles(pbc=True), calc_angles(self.agroup.atom1.positions, self.agroup.atom2.positions, self.agroup.atom3.positions, box=self.u.dimensions))
def test_right_type_angles(self): assert_equal( self.agroup.angles(), calc_angles(self.agroup.atom1.positions, self.agroup.atom2.positions, self.agroup.atom3.positions)) assert_equal( self.agroup.angles(pbc=True), calc_angles(self.agroup.atom1.positions, self.agroup.atom2.positions, self.agroup.atom3.positions, box=self.u.dimensions))
def test_angles(self): from MDAnalysis.core.distances import calc_angles # Shift atom coordinates a few box lengths in random directions and see if we still get same results a2 = (self.a + self.box * (-1, 0, 0)).astype(np.float32) # seem to get converted to float64 otherwise b2 = (self.b + self.box * (1, 0, 1)).astype(np.float32) c2 = (self.c + self.box * (-2, 5, -7)).astype(np.float32) ref = calc_angles(self.a, self.b, self.c) test1 = calc_angles(a2, self.b, self.c, box=self.box) test2 = calc_angles(self.a, b2, self.c, box=self.box) test3 = calc_angles(self.a, self.b, c2, box=self.box) test4 = calc_angles(a2, b2, c2, box=self.box) for val in [test1, test2, test3, test4]: assert_almost_equal(ref, val, self.prec, err_msg="Min image in angle calculation failed")
def _single_run(self, start, stop): """Perform a single pass of the trajectory""" self.u.trajectory[start] # Calculate partners at t=0 box = self.u.dimensions if self.pbc else None # 2d array of all distances d = distance_array(self.h.positions, self.a.positions, box=box) if self.exclusions: # set to above dist crit to exclude d[self.exclusions] = self.d_crit + 1.0 # find which partners satisfy distance criteria hidx, aidx = numpy.where(d < self.d_crit) a = calc_angles(self.d.positions[hidx], self.h.positions[hidx], self.a.positions[aidx], box=box) # from amongst those, who also satisfiess angle crit idx2 = numpy.where(a > self.a_crit) hidx = hidx[idx2] aidx = aidx[idx2] nbonds = len(hidx) # number of hbonds at t=0 results = numpy.zeros_like(numpy.arange(start, stop, self._skip), dtype=numpy.float32) if self.time_cut: # counter for time criteria count = numpy.zeros(nbonds, dtype=numpy.float64) for i, ts in enumerate(self.u.trajectory[start:stop:self._skip]): box = self.u.dimensions if self.pbc else None d = calc_bonds(self.h.positions[hidx], self.a.positions[aidx], box=box) a = calc_angles(self.d.positions[hidx], self.h.positions[hidx], self.a.positions[aidx], box=box) winners = (d < self.d_crit) & (a > self.a_crit) results[i] = winners.sum() if self.bond_type is 'continuous': # Remove losers for continuous definition hidx = hidx[numpy.where(winners)] aidx = aidx[numpy.where(winners)] elif self.bond_type is 'intermittent': if self.time_cut: # Add to counter of where losers are count[~winners] += self._skip * self.u.trajectory.dt count[winners] = 0 # Reset timer for winners # Remove if you've lost too many times # New arrays contain everything but removals hidx = hidx[count < self.time_cut] aidx = aidx[count < self.time_cut] count = count[count < self.time_cut] else: pass if len(hidx) == 0: # Once everyone has lost, the fun stops break results /= nbonds return results
def _single_run(self, start, stop): """Perform a single pass of the trajectory""" self.u.trajectory[start] # Calculate partners at t=0 box = self.u.dimensions if self.pbc else None # 2d array of all distances d = distance_array(self.h.positions, self.a.positions, box=box) if self.exclusions: # set to above dist crit to exclude d[self.exclusions] = self.d_crit + 1.0 # find which partners satisfy distance criteria hidx, aidx = numpy.where(d < self.d_crit) a = calc_angles(self.d.positions[hidx], self.h.positions[hidx], self.a.positions[aidx], box=box) # from amongst those, who also satisfiess angle crit idx2 = numpy.where(a > self.a_crit) hidx = hidx[idx2] aidx = aidx[idx2] nbonds = len(hidx) # number of hbonds at t=0 results = numpy.zeros_like(numpy.arange(start, stop, self._skip), dtype=numpy.float32) if self.time_cut: # counter for time criteria count = numpy.zeros(nbonds, dtype=numpy.float64) for i, ts in enumerate(self.u.trajectory[start : stop : self._skip]): box = self.u.dimensions if self.pbc else None d = calc_bonds(self.h.positions[hidx], self.a.positions[aidx], box=box) a = calc_angles(self.d.positions[hidx], self.h.positions[hidx], self.a.positions[aidx], box=box) winners = (d < self.d_crit) & (a > self.a_crit) results[i] = winners.sum() if self.bond_type is "continuous": # Remove losers for continuous definition hidx = hidx[numpy.where(winners)] aidx = aidx[numpy.where(winners)] elif self.bond_type is "intermittent": if self.time_cut: # Add to counter of where losers are count[~winners] += self._skip * self.u.trajectory.dt count[winners] = 0 # Reset timer for winners # Remove if you've lost too many times # New arrays contain everything but removals hidx = hidx[count < self.time_cut] aidx = aidx[count < self.time_cut] count = count[count < self.time_cut] else: pass if len(hidx) == 0: # Once everyone has lost, the fun stops break results /= nbonds return results