本文整理汇总了Python中msmbuilder.Trajectory.read_frame方法的典型用法代码示例。如果您正苦于以下问题:Python Trajectory.read_frame方法的具体用法?Python Trajectory.read_frame怎么用?Python Trajectory.read_frame使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类msmbuilder.Trajectory
的用法示例。
在下文中一共展示了Trajectory.read_frame方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: load_frame
# 需要导入模块: from msmbuilder import Trajectory [as 别名]
# 或者: from msmbuilder.Trajectory import read_frame [as 别名]
def load_frame(self, traj_index, frame_index):
"""Load one or more specified frames.
Example
-------
>>> project = Project.load_from('ProjectInfo.yaml')
>>> foo = project.load_frame(1,10)
>>> bar = Trajectory.read_frame(TrajFilename=project.traj_filename(1),
WhichFrame=10)
>>> np.all(foo['XYZList'] == bar)
True
Parameters
----------
traj_index : int, [int]
Index or indices of the trajectories to pull from
frame_index : int, [int]
Index or indices of the frames to pull from
Returns
-------
traj : msmbuilder.Trajectory
A trajectory object containing the requested frame(s).
"""
if np.isscalar(traj_index) and np.isscalar(frame_index):
xyz = Trajectory.read_frame(TrajFilename=self.traj_filename(traj_index),
WhichFrame=frame_index)
xyzlist = np.array([xyz])
else:
traj_index = np.array(traj_index)
frame_index = np.array(frame_index)
if not (traj_index.ndim == 1 and np.all(traj_index.shape == frame_index.shape)):
raise ValueError('traj_index and frame_index must be 1D and have the same length')
xyzlist = []
for i,j in zip(traj_index, frame_index):
if j >= self.traj_lengths[i]:
raise ValueError('traj %d too short (%d) to contain a frame %d' % (i, self.traj_lengths[i], j))
xyz = Trajectory.read_frame(TrajFilename=self.traj_filename(i),
WhichFrame=j)
xyzlist.append(xyz)
xyzlist = np.array(xyzlist)
conf = self.load_conf()
conf['XYZList'] = xyzlist
return conf
示例2: run
# 需要导入模块: from msmbuilder import Trajectory [as 别名]
# 或者: from msmbuilder.Trajectory import read_frame [as 别名]
def run(project, assignments, num_confs_per_state, random_source=None):
"""
Pull random confs from each state in an MSM
Parameters
----------
project : msmbuilder.Project
Used to load up the trajectories, get topology
assignments : np.ndarray, dtype=int
State membership for each frame
num_confs_per_state : int
number of conformations to pull from each state
random_source : numpy.random.RandomState, optional
If supplied, random numbers will be pulled from this random source,
instead of the default, which is np.random. This argument is used
for testing, to ensure that the random number generator always
gives the same stream.
Notes
-----
A new random_source can be initialized by calling numpy.random.RandomState(seed)
with whatever seed you like. See http://stackoverflow.com/questions/5836335/consistenly-create-same-random-numpy-array
for some discussion.
"""
if random_source is None:
random_source = np.random
n_states = max(assignments.flatten()) + 1
logger.info("Pulling %s confs for each of %s confs", num_confs_per_state, n_states)
inv = MSMLib.invert_assignments(assignments)
xyzlist = []
for s in xrange(n_states):
trj, frame = inv[s]
# trj and frame are a list of indices, such that
# project.load_traj(trj[i])[frame[i]] is a frame assigned to state s
for j in xrange(num_confs_per_state):
r = random_source.randint(len(trj))
xyz = Trajectory.read_frame(project.traj_filename(trj[r]), frame[r])
xyzlist.append(xyz)
# xyzlist is now a list of (n_atoms, 3) arrays, and we're going
# to stack it along the third dimension
xyzlist = np.dstack(xyzlist)
# load up the conf to get the topology, put then pop in the new coordinates
output = project.load_conf()
output['XYZList'] = xyzlist
return output