Amber-MD / pytraj

Python interface of cpptraj
https://amber-md.github.io/pytraj
168 stars 38 forks source link

mindist stops working when called multiple times #1572

Closed hherce closed 3 years ago

hherce commented 3 years ago

I am using a for loop to analyze a the minimum distance of a series of individual atoms to a group. I am doing it in the following manner:

alldist = []
for j in range(40):
    dist = []
    frame_indices = [j]
    traj0 = pt.load('tmp.trr', 'tmp.pdb', frame_indices=frame_indices)
    for i in resatoms:
        dist.append(pt.mindist(traj0,':RES&@'+i+' @1-242')[0])
    alldist.append(dist)

It runs fine until the loop reaches 21 frames (j=21) and gets stuck there. The problem is specifically with pt.mindist. I could stop the calculation and try to run again the distances for j=1 and it wont do it, I need to restart python for mindist to work again. I also run j=21 just to be sure that there is nothing wrong with the trajectory itself. Is it possible that mindist contains a variable that keeps increasing with each iteration of the function and this ends up saturating my computer memory? I would also appreciate if you could let me know a way around it while you fix the code. Thanks! Henry

hherce commented 3 years ago

I am almost sure that it is a memory issue, if I reduce the number of atoms in resatoms by half, the loop hangs now in frame 35.

hainm commented 3 years ago

thanks @hherce for your report. I can reproduce the issue with below code (to use pytraj's data):

import pytraj as pt

alldist = []
resatoms = range(10) # works fine with range(8)

for j in range(40):
    dist = []
    frame_indices = [j]
    traj0 = pt.load('tz2.nc', 'tz2.parm7', frame_indices=frame_indices)
    for i in resatoms:
        dist.append(pt.mindist(traj0,':2 :3')[0])
    alldist.append(dist)

print(alldist)
hainm commented 3 years ago

I am investigating now.

hherce commented 3 years ago

Awesome! just let me know if you have any questions. Thanks! Henry

From: Hai Nguyen notifications@github.com Sent: Tuesday, February 9, 2021 11:40 PM To: Amber-MD/pytraj pytraj@noreply.github.com Cc: Herce, Henry D. Henry_Herce@DFCI.HARVARD.EDU; Mention mention@noreply.github.com Subject: Re: [Amber-MD/pytraj] mindist stops working when called multiple times (#1572)

    External Email - Use Caution

I am investigating now.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://secure-web.cisco.com/17Hj8F_wjLN7wJivnraFuCW04JZzOBcNtalLWTTekvK5XAhAp6THXf6NcuZS2xD1orw0_iVA6fvHvIslFY9v7LZBdr6gSUK0J0g6KuFxX-l7BeXk_t3jMzwdqHYeUPdw-KRT9X7fcAfvRSpboM4bMtRDRBvuAYXN7na_EYty6Cz6VS4trU75XmUX1oF0jiqdZ0W33VKx2tAsc1aZ5wGwrUxdFsJkYVB7m_vFPV9UWmJ9kZ_KuctauB_tUi-MCcZq6qb6F3uRdr1Ap0txCocGyXQ/https%3A%2F%2Fgithub.com%2FAmber-MD%2Fpytraj%2Fissues%2F1572%23issuecomment-776434503, or unsubscribehttps://secure-web.cisco.com/10XBMKc0fK_V3Qo8CRmzYuHC7fYAr24vAU_PDFktbKlCnQS1fpjOhFk5vnWSU9eD2gEcrLl_qp0fUeBkTCg9CH2P1G3c9lEXLTeF9u8rSHk7OVbA9GImsskF22UR2F2UoE-pCn8Z-3cJl7iBCscyr4MkM6L5HiWzLRg5AmNKBSTDMa0AWGaT7fMjqhX6-KjbWIu2sdqIvylUv7GHO_DpZHcdHQIPHBQOibjEkAk2j2kbiC03ax3alWa4eICbDD5tjeWeVKitkM7v3Sv9k3E_DQw/https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FASB3XLHTPMPY46C4TM566NTS6IE3NANCNFSM4XMGYCNA. The information in this e-mail is intended only for the person to whom it is addressed. If you believe this e-mail was sent to you in error and the e-mail contains patient information, please contact the Mass General Brigham Compliance HelpLine at http://www.massgeneralbrigham.org/complianceline . If the e-mail was sent to you in error but does not contain patient information, please contact the sender and properly dispose of the e-mail.

hainm commented 3 years ago

@hherce Please turn off the capture_stdout, which is problematic:

import pytraj as pt
from contextlib import contextmanager

class Dummy:
    def __enter__(self):
        return self

    def __exit__(self):
        return

    def read(self):
        return ""

@contextmanager
def mock_capture():
    yield Dummy(), ""

pt.analysis.c_action.capture_stdout = mock_capture

alldist = []
resatoms = range(40)

for j in range(40):
    dist = []
    frame_indices = [j]
    traj0 = pt.load('tz2.nc', 'tz2.parm7', frame_indices=frame_indices)
    for i in resatoms:
        dist.append(pt.mindist(traj0,':2 :3')[0])
    alldist.append(dist)

print(alldist)

Related issues:

  1. https://github.com/Amber-MD/pytraj/issues/1498#issuecomment-558360392
  2. https://github.com/Amber-MD/pytraj/issues/1569
hherce commented 3 years ago

Great! Thanks so much! It seems that is working now and I would have never figured out a way around this. Thanks again and best regards, Henry

From: Hai Nguyen notifications@github.com Sent: Tuesday, February 9, 2021 11:55 PM To: Amber-MD/pytraj pytraj@noreply.github.com Cc: Herce, Henry D. Henry_Herce@DFCI.HARVARD.EDU; Mention mention@noreply.github.com Subject: Re: [Amber-MD/pytraj] mindist stops working when called multiple times (#1572)

    External Email - Use Caution

@hhercehttps://secure-web.cisco.com/1d39ahEo-ykQCNMwK8HwjWmfYEwGI2yVQq8jAFPqlb888SfSHIqlvomi8c3RXd1j8CcLgx7Vr867pfDfxkQzrgBxoBTyfyjlL74H_y-NqTDB_4f-7Bn34T3pCbHvDEP-eRuNJCijyUT-z7L3uDQOBzrzqFcXEEgmccWSICBupl-QvAXnxzmDec1jWQM2cmZqZwC1bkcYsBmIBI9ECvewjRNacWZGsFcsG8-Z8yQ6Nb1wKCzXOTF_Pk7VxyPvkKctf/https%3A%2F%2Fgithub.com%2Fhherce Please turn off the capture_stdout, which is problematic:

import pytraj as pt

from contextlib import contextmanager

class Dummy:

def __enter__(self):

    return self

def __exit__(self):

    return

def read(self):

    return ""

@contextmanager

def mock_capture():

yield Dummy(), ""

pt.analysis.c_action.capture_stdout = mock_capture

alldist = []

resatoms = range(40)

for j in range(40):

dist = []

frame_indices = [j]

traj0 = pt.load('tz2.nc', 'tz2.parm7', frame_indices=frame_indices)

for i in resatoms:

    dist.append(pt.mindist(traj0,':2 :3')[0])

alldist.append(dist)

print(alldist)

Related issues:

  1. 1498 (comment)https://secure-web.cisco.com/1DEVWSHsqnonSx4nm9YJFSP42B4hIzcNVPl8Mcu4FbrQ5WCnf9ouOvva_kVN4LzW_e8H1joFOEkjxCclMdEXwTlLmMXF7kN0gN84P2MVgJKVb-ypdxr26ACAMWyVDHokT9ye7oUYT140qb-kDwRPxQ9JdUEuue146mOnpWOE42H43uReGef3h66BO4bWW0aBLFIZMnKaIPQF7iY45GHLJZrtQmEY-jvEivc9batVWNR94YISG8DZFwv7VibvRJzJW/https%3A%2F%2Fgithub.com%2FAmber-MD%2Fpytraj%2Fissues%2F1498%23issuecomment-558360392

  2. 1569https://secure-web.cisco.com/1E97pQ0ngdFa_HJkxaO3osuejGpVJKenSNoWa16-AcL0NJn-FECiF0hCsrghwW-MNItzp7p_YZ5oA_hPnwZMsSweTekFJ_i43L_5et4QopxkL0UNszJpDzojKl2Zych1DS6YntYD9ozDmpk2fajifocXq_u4C_WDiq0PieOLreAXPIi2X6DIy8z3iHKYexhoTh7p0F9oJA_0LWZJtcwTWAWhzqvUOFTZ35dm7WQ8vOFJdYtWKG_1Y3e0xsNPY6ytN/https%3A%2F%2Fgithub.com%2FAmber-MD%2Fpytraj%2Fissues%2F1569

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://secure-web.cisco.com/1G0GwLN6PQ6PGSI1_SPDwNX7HXHRHe3a6HBodToyQOC57iLlaKkJK58GKoCn5PXq5WXXttJ5EB2kromz4wk3htYdS6oZQEbQCMWdwkTCz1fOO4r2n1jwdLLMYzI4qq4EZrem8lwfMl3IxQJeyDQ0NWzEeLcNWcb5eTZykk5FVCSNTo7-tHSaQ6G26tg51bhUPNoUPb2y2l56D0pP4eXQSvOY2Hh74kKc9IZ05P_5A_iR_r8voVu17rDOZWiEQTNvR/https%3A%2F%2Fgithub.com%2FAmber-MD%2Fpytraj%2Fissues%2F1572%23issuecomment-776441432, or unsubscribehttps://secure-web.cisco.com/1a37Ha-qT00oOM9H9GEKXUwDWPrstPqyxZMksBRkJhv1QABklSqxG-pQ_oGazXzflmyMPI7H9cMPiWTGevELyQSc_7Io6IaXYHcu5vQyvbKu05NSRt_Srr1Q3uTJF_5NE-KXyivL3SmmIpleiqXisTxOl9e1IxzWaDtappr1fevQn1xBFllG3rMCC3IhWsjwpdg9GrfPiQD-ix8ixQqewvJ5x221CAzxhPevMDaN9qDQv37HV0JtVfcK7qC4Ll1yx/https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FASB3XLD63MQ4BK54VFZTK2LS6IGTNANCNFSM4XMGYCNA. The information in this e-mail is intended only for the person to whom it is addressed. If you believe this e-mail was sent to you in error and the e-mail contains patient information, please contact the Mass General Brigham Compliance HelpLine at http://www.massgeneralbrigham.org/complianceline . If the e-mail was sent to you in error but does not contain patient information, please contact the sender and properly dispose of the e-mail.