How to Maintain the Integrity of a System Containing Multiple Independent Chains Across PBC in MDAnalysis #4455
-
Hi, I'm currently working on a molecular dynamics simulation project that involves multiple protein chains within the same system. These chains are structurally independent (i.e., no covalent bonds between them) and occasionally span across the periodic boundary conditions (PBC), which complicates the analysis of their interactions and overall structure. Is there a recommended approach within MDAnalysis to maintain the integrity of independent protein chains that may span PBCs? Thank you in advance for your time and help! Best regards, |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
@erwusht since this is more about usability than a bug, I am transferring this to our discussion forum in the hopes that someone may have a solution for you there. |
Beta Was this translation helpful? Give feedback.
-
Here is the code snippet I normally use: # From https://groups.google.com/g/mdnalysis-discussion/c/umDpvbCmQiE/m/FKtNClazAwAJ
# Author: Richard Gowers
from MDAnalysis.transformations.base import TransformationBase
import numpy as np
class GroupHug(TransformationBase):
def __init__(self, center, *others):
super().__init__(max_threads=1, parallelizable=True)
self.c = center
self.o = others
@staticmethod
def calc_restoring_vec(ag1, ag2):
box = ag1.dimensions[:3]
dist = ag1.center_of_mass() - ag2.center_of_mass()
return box * np.rint(dist / box)
def _transform(self, ts):
# loop over other atomgroups and shunt them into nearest image to
# center
for i in self.o:
rvec = self.calc_restoring_vec(self.c, i)
i.translate(+rvec)
return ts
then you can group the protein chains together with e.g. prot_chain_list = []
# group all the protein chains
for chain in u_prot.segments:
prot_chain_list.append(chain.atoms)
prot_group = GroupHug(*prot_chain_list)
u.trajectory.add_transformations(
*[prot_group]
) |
Beta Was this translation helpful? Give feedback.
Here is the code snippet I normally use: