0

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

universe.select_atoms("name OW and around 4 (resid 20 and name O2)")

但是,来自 PBC 框的原子坐标位于框的另一侧。换句话说,我必须手动平移原子以确保它们实际上在 4 埃的距离内。

是否有使用 select_atoms 函数的选择功能来实现这一点?

4

1 回答 1

2

如果我很好理解,您希望在最接近该选择的图像中获取给定选择周围的原子。

universe.select_atoms不修改坐标,我不知道有什么功能可以满足您的需求。以下函数适用于像您这样的正交框:

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 才能运行以下代码:

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')
于 2017-01-17T18:36:00.800 回答