On Tue, May 8, 2018 at 11:18 PM, Hai Nguyen <nhai.qn.gmail.com> wrote:
> Hi,
>
> You can give pytraj (python interface of cpptraj) a try. Please see below
> example (with ipython)
>
> In [36]: import numpy as np
>
>
> In [37]: import pytraj as pt
>
>
> In [38]: traj = pt.load('data/tz2.nc', 'data/tz2.parm7', frame_indices=[0,])
> # take 1st frame.
>
>
> In [39]: v = np.random.rand(traj.n_frames, traj.top.n_atoms, 3) # or any
> 3d array you want.
>
>
> In [40]: traj.velocities = v
>
>
> In [41]: traj.save('test.rst7', crdinfo={'has_velocity': True})
>
>
> In [42]: !ls test.rst7.1
>
> test.rst7.1
>
>
> In [43]: traj2 = pt.load('test.rst7.1', top=traj.top)
>
>
> In [44]: traj2.velocities
>
> Out[44]:
>
> array([[[ 0.0679721, 0.9868183, 0.0208989],
>
> [ 0.9172472, 0.421962 , 0.1716633],
>
> [ 0.4589834, 0.9581008, 0.6106007],
>
> ...,
>
> [ 0.4099388, 0.7560913, 0.4540014],
>
> [ 0.8590423, 0.0519312, 0.96421 ],
>
> [ 0.5929765, 0.5500232, 0.5587808]]])
>
>
>
>
> Let us know if that's what you want.
> I hope you can find (richful) information here: http://amber-md.github.
> io/pytraj/latest/index.html
>
>
ah, if you're familiar with numpy array, you can assign the velocity for a
specific atom via
In [61]: traj.velocities[0, 0] = [1., 2., 3.] # [0, 0] means 1st frame, 1st
atom; and so on.
In [62]: traj.velocities[0, 0]
Out[62]: array([ 1., 2., 3.])
Hai
_______________________________________________
AMBER mailing list
AMBER.ambermd.org
http://lists.ambermd.org/mailman/listinfo/amber
Received on Tue May 08 2018 - 20:30:04 PDT