hi Thomas,
On Thu, Jan 17, 2019 at 10:52 AM Thomas Evangelidis <tevang3.gmail.com>
wrote:
> Greetings,
>
> I want to get the total charge of an atom selection using pytraj.
>
> traj = pt.load('complex_postmin.min_GB.rst', 'complex.prmtop',
> > frame_indices=[0])
> > mask = ':LIG<:6.000 & ! :WAT,LIG'
> > print traj[mask].top.charge.sum()
>
>
> pytraj complains 'Error: No reference set, cannot select by distance.' and
> returns a value which is the total charge of ':WAT,LIG'. I understand that
> I must define a reference frame to calculate the distances but I don't know
> how. Could someone please show me how to do it?
Please use "traj.top.set_reference(traj[0])"
In [8]: traj.top.set_reference(traj[0])
In [9]: traj[':3<:6.0'].top.charge.sum()
Out[9]: 1.6463350682727196e-09
> Is there also an option to
> load only the last frame of the trajectory without knowing the total number
> of frames in advance?
>
>
It turns out that pytraj has not supported that yet. But you can use
iterload to create on-disk trajectory (nothing is actually loaded) and then
do slicing to get on-memory traj.
In [22]: traj = pt.iterload('tz2.nc', 'tz2.parm7')
In [23]: traj
Out[23]:
pytraj.TrajectoryIterator, 101 frames:
Size: 0.000503 (GB)
<Topology: 223 atoms, 13 residues, 1 mols, non-PBC>
In [24]: traj[-2:-1] # Python fancy indexing
Out[24]:
pytraj.Trajectory, 1 frames:
Size: 0.000005 (GB)
<Topology: 223 atoms, 13 residues, 1 mols, non-PBC>
I've opened a github issue to remind to implement loading last frame (via
frame_indices option): https://github.com/Amber-MD/pytraj/issues/1465
Let me know if you have further questions.
Hai
_______________________________________________
AMBER mailing list
AMBER.ambermd.org
http://lists.ambermd.org/mailman/listinfo/amber
Received on Fri Jan 18 2019 - 13:00:02 PST