首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >MDAnalysis从PBC框中选择原子,但不改变坐标。

MDAnalysis从PBC框中选择原子,但不改变坐标。
EN

Stack Overflow用户
提问于 2017-01-16 11:23:08
回答 1查看 352关注 0票数 0

MDAnalysis的距离选择命令,如“box”和“sphzere”,从周期图像中选择原子(我使用的是矩形框)。

代码语言:javascript
复制
universe.select_atoms("name OW and around 4 (resid 20 and name O2)")

然而,来自PBC盒的原子坐标位于盒子的另一边。换句话说,我必须手动翻译原子,以确保它们实际上是与4安格斯特龙距离。

是否有使用select_atoms函数实现这一目标的选择特性?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-01-17 18:36:00

如果我能理解的话,你会想让原子围绕一个给定的选择在图像中,是最接近该选择的。

universe.select_atoms不修改坐标,我也不知道有一个函数能满足您的需要。以下功能可以用于像您这样的正交盒:

代码语言:javascript
复制
def pack_around(atom_group, center):
    """
    Translate atoms to their periodic image the closest to a given point.

    The function assumes that the center is in the main periodic image.
    """
    # Get the box for the current frame
    box = atom_group.universe.dimensions
    # The next steps assume that all the atoms are in the same
    # periodic image, so let's make sure it is the case
    atom_group.pack_into_box()
    # AtomGroup.positions is a property rather than a simple attribute.
    # It does not always propagate changes very well so let's work with
    # a copy of the coordinates for now.
    positions = atom_group.positions.copy()
    # Identify the *coordinates* to translate.
    sub = positions - center
    culprits = numpy.where(numpy.sqrt(sub**2) > box[:3] / 2)
    # Actually translate the coordinates.
    positions[culprits] -= (u.dimensions[culprits[1]]
                            * numpy.sign(sub[culprits]))
    # Propagate the new coordinates.
    atom_group.positions = positions

使用该函数,我在一个MDAnalysis测试文件上得到了预期的行为。需要安装MDAnalysisTests才能运行以下代码:

代码语言:javascript
复制
import numpy
import MDAnalysis as mda
from MDAnalysisTests.datafiles import PDB_sub_sol

u = mda.Universe(PDB_sub_sol)
selection = u.select_atoms('around 15 resid 32')
center = u.select_atoms('resid 32').center_of_mass()

# Save the initial file for latter comparison
u.atoms.write('original.pdb')
selection.write('selection_original.pdb')

# Translate the coordinates
pack_around(selection, center)

# Save the new coordinates
u.atoms.write('modified.pdb')
selection.write('selection_modified.pdb')
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41675253

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档