Skip to content

How to Maintain the Integrity of a System Containing Multiple Independent Chains Across PBC in MDAnalysis #4455

Answered by yuxuanzhuang
erwusht asked this question in Q&A
Discussion options

You must be logged in to vote

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 i…

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
2 replies
@IAlibay
Comment options

@erwusht
Comment options

Comment options

You must be logged in to vote
1 reply
@erwusht
Comment options

Answer selected by erwusht
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants
Converted from issue

This discussion was converted from issue #4449 on February 11, 2024 09:55.