本文整理汇总了Python中htmd.molecule.molecule.Molecule.appendFrames方法的典型用法代码示例。如果您正苦于以下问题:Python Molecule.appendFrames方法的具体用法?Python Molecule.appendFrames怎么用?Python Molecule.appendFrames使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类htmd.molecule.molecule.Molecule
的用法示例。
在下文中一共展示了Molecule.appendFrames方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: sampleRegion
# 需要导入模块: from htmd.molecule.molecule import Molecule [as 别名]
# 或者: from htmd.molecule.molecule.Molecule import appendFrames [as 别名]
def sampleRegion(self, point=None, radius=None, limits=None, nsamples=20, singlemol=False):
""" Samples conformations from a region in the projected space.
Parameters
----------
point : list or np.ndarray
A point in the projected space. Undefined dimensions should have None value.
radius : float
The radius in around the point in which to sample conformations.
limits : np.ndarray
A (2, ndim) dimensional array containing the min (1st row) and max (2nd row) limits for each dimension.
None values will be interpreted as no limit in that dimension, or min/max value.
nsamples : int
The number of conformations to sample.
singlemol : bool
If True it will return all samples within a single Molecule instead of a list of Molecules.
Returns
-------
absFrames : list
A list of the absolute frame indexes sampled
relFrames : list of tuples
A list of (trajNum, frameNum) tuples sampled
mols : Molecule or list of Molecules
The conformations stored in a Molecule or a list of Molecules
Examples
--------
>>> # Working with 4 dimensional data for example
>>> abs, rel, mols = data.sampleRegion(point=(0.5, 3, None, None), radius=0.1) # Point undefined in dim 3, 4
>>> minlims = [-1, None, None, 4] # No min limit for 2, 3 dim
>>> maxlims = [2, 3, None, 7] # No max limit for 3 dim
>>> abs, rel, mols = data.sampleRegion(limits=np.array([minlims, maxlims]))
"""
from scipy.spatial.distance import cdist
datconcat = np.concatenate(self.dat)
numdim = datconcat.shape[1]
if point is not None:
if radius is None:
raise RuntimeError('You must define a radius with a point.')
point = np.array(point)
if len(point) != numdim:
raise RuntimeError(
'Argument `point` should be same dimensionality as your data ({} dimensions)'.format(numdim))
keepdim = np.array([p is not None for p in point])
dists = cdist(datconcat[:, keepdim], [point[keepdim]])
confs = np.where(dists < radius)[0]
elif limits is not None:
if limits.shape != (2, numdim):
raise RuntimeError('Argument `limits` should be of shape (2, {})'.format(numdim))
mask = np.ones(datconcat.shape[0], dtype=bool)
for i in range(numdim):
if limits[0, i] is not None:
mask &= datconcat[:, i] > limits[0, i]
if limits[1, i] is not None:
mask &= datconcat[:, i] < limits[1, i]
confs = np.where(mask)[0]
if len(confs) > nsamples:
confs = np.random.choice(confs, nsamples, replace=False)
sims = self.abs2sim(confs)
from htmd.molecule.molecule import Molecule
if singlemol:
mol = Molecule(sims[0])
for i in range(1, len(sims)):
m = Molecule(sims[i])
mol.appendFrames(m)
else:
mol = []
for s in sims:
mol.append(Molecule(s))
return confs, self.abs2rel(confs), mol