コード例 #1
0
ファイル: test_topology.py プロジェクト: djay0529/mdanalysis
 def test_right_type_bonds(self):
     assert_equal(self.bgroup.bonds(),
                  calc_bonds(self.bgroup.atom1.positions,
                             self.bgroup.atom2.positions))
     assert_equal(self.bgroup.bonds(pbc=True),
                  calc_bonds(self.bgroup.atom1.positions,
                             self.bgroup.atom2.positions,
                             box=self.u.dimensions))
コード例 #2
0
ファイル: test_topology.py プロジェクト: ivirshup/mdanalysis
 def test_right_type_bonds(self):
     assert_equal(
         self.bgroup.bonds(),
         calc_bonds(self.bgroup.atom1.positions,
                    self.bgroup.atom2.positions))
     assert_equal(
         self.bgroup.bonds(pbc=True),
         calc_bonds(self.bgroup.atom1.positions,
                    self.bgroup.atom2.positions,
                    box=self.u.dimensions))
コード例 #3
0
def main():
	u = Universe(conf,traj)	
	nmol = len(list(u.residues))
	Nlen = len(u.residues[0].atoms)
	Nhalf = Nlen/2
	R = np.zeros((2,Nhalf))

	for ts in u.trajectory:
		print " frame ", ts.frame
		for n in xrange(0,Nhalf):
			npair = Nlen - n -1

			R[1,n] = npair - n

			#get the pairs of atoms with indices n-npair for all residues 
			ag1 = [myres.atoms[n].pos for myres in u.residues]
			ag1 = np.array(ag1)
			ag2 = [myres.atoms[npair].pos for myres in u.residues]
			ag2 = np.array(ag2)
			#calculate distance
			distance_array = calc_bonds(ag1,ag2)
			#average it
			r2_loc = np.mean(distance_array*distance_array)
			#divide <R(n)**2> by the n
			R[0,n] = r2_loc/R[1,n]
			print "n = ", n , " n* " , npair , " the n ", R[1,n] ," r2 = ", R[0,n], " r2_loc = ", r2_loc
		plot(R[1,:], R[0,:], 'r--', lw=2)
		xlabel("n")
		ylabel(r" <R^2>/n")
		plt.savefig(name + '.pdf')
コード例 #4
0
    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
コード例 #5
0
    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