ProDy icon indicating copy to clipboard operation
ProDy copied to clipboard

added trajectory wrap method

Open jamesmkrieger opened this issue 4 years ago • 30 comments

Previously there was only a function to wrapAtoms for individual frames. This extends that to the whole trajectory.

jamesmkrieger avatar Mar 11 '21 09:03 jamesmkrieger

This should probably have more testing

jamesmkrieger avatar Dec 20 '21 17:12 jamesmkrieger

I generated a trajectory of Na and Cl in a small water box where wrapping occurs. I visualized it and have quantitative support. I'll test the function on this. image

AnthonyBogetti avatar May 07 '24 20:05 AnthonyBogetti

@jamesmkrieger, I have a dcd file with wrapping and am trying to run the following code with it:

from prody import *
f = DCDFile("nacl_namd.dcd")
f.hasUnitcell
f.wrap()

The f.hasUnitcell is True, but when I try to wrap I get the following error:

In [5]: f.wrap()
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
File ~/apps/miniforge3/envs/prody-wrap_traj/lib/python3.8/site-packages/ProDy-2.0.2-py3.8-linux-x86_64.egg/prody/measure/transform.py:530, in wrapAtoms(frame, unitcell, center)
    529 try:
--> 530     unitcell = frame.getUnitcell()[:3]
    531 except AttributeError:

AttributeError: 'numpy.ndarray' object has no attribute 'getUnitcell'

During handling of the above exception, another exception occurred:

TypeError                                 Traceback (most recent call last)
Cell In[5], line 1
----> 1 f.wrap()

File ~/apps/miniforge3/envs/prody-wrap_traj/lib/python3.8/site-packages/ProDy-2.0.2-py3.8-linux-x86_64.egg/prody/trajectory/trajbase.py:397, in TrajBase.wrap(self, unitcell, center)
    395 LOGGER.progress('Wrapping trajectory ...', len(coordsets))
    396 for i, coordset in enumerate(coordsets):
--> 397     wrapped.addCoordset(wrapAtoms(coordset), unitcell=unitcell, center=center)
    398     LOGGER.update(i)
    400 LOGGER.finish()

File ~/apps/miniforge3/envs/prody-wrap_traj/lib/python3.8/site-packages/ProDy-2.0.2-py3.8-linux-x86_64.egg/prody/measure/transform.py:532, in wrapAtoms(frame, unitcell, center)
    530         unitcell = frame.getUnitcell()[:3]
    531     except AttributeError:
--> 532         raise TypeError('unitcell information must be provided')
    534 half = unitcell / 2
    535 ucmin = center - half

TypeError: unitcell information must be provided

Am I doing something wrong?

AnthonyBogetti avatar May 08 '24 18:05 AnthonyBogetti

I don’t really remember these functions so I don’t know. Did you actually set a unit cell or anything like that?

jamesmkrieger avatar May 08 '24 18:05 jamesmkrieger

The frames do have a unitcell:

In [17]: f.getFrame(1).getUnitcell()                                                                                                                                         
Out[17]:                                                                                                                                                                     
array([29.05412292, 29.05412292, 29.05412292, 93.09894122, 93.09894122,                                                                                                      
       93.09894122])

AnthonyBogetti avatar May 08 '24 19:05 AnthonyBogetti

I wonder where we are ending up with a numpy array. Maybe DCDFile isn’t the right object?

jamesmkrieger avatar May 08 '24 19:05 jamesmkrieger

I'll look into this a bit more.

AnthonyBogetti avatar May 08 '24 19:05 AnthonyBogetti

Thanks

jamesmkrieger avatar May 08 '24 20:05 jamesmkrieger