Closed jyosa closed 3 years ago
hi @jyosa
How's about just precaculate the distance array to find the frame_indices
that satisfy your criteria?
dist = pt.distance(...)
print(dist < 5) #
Did not work, but for example for a frame 0
top = traj.top
top.set_reference(traj[0])
selection = traj[':ACE<:5.0|:ACE, NME'][0]
here select all residues less than 5 A and also the solute, but when I used the iteration id doesn't work
ok, so I misunderstood your original idea.
May be trying:
top = traj.top
for frame in traj:
top.set_reference_frame(frame)
atom_indices = top.select(<your mask>)
print(frame.xyz[atom_indices].shape) # You can tell that you will likely get different shape
PS1: What are you trying to solve? To get stripped trajectory from the selection? (that won't work because different frame might have different number of atoms, due to the distance-selection).
Hi thank you for your answer, from the selection it is possible also to select each residue? because with this loop I get index for all atoms in the selection, but I got stuck selecting each residue. I want to compute instantaneous dipole moment for each residue in the selection that's my goal. Again thank you!
hi @jyosa, here is my very naive approach: using the atom indices to get new topology and get the residue information?
In [23]: t = pt.datafiles.load_tz2_ortho()
In [24]: top = t.top
In [25]: top.set_reference(t[1])
In [26]: indices = t.top.select(':1<:5.0')
In [27]: [res.original_resid for res in top[indices].residues]
# `original_resid` is 1-based index and is the "original" resid in the `top` above.
goo thank you is getting better, but when I try to compute center of mass I got this: TypeError: Argument 'atmask' has incorrect type (expected pytraj.core.c_core.AtomMask, got str)
ini = 0 top = traj.top for frame in traj: top.set_reference(traj[ini]) indices = traj.top.select(':ACE<:5.0|:ACE, NME') residues = [res.original_resid for res in top[indices].residues] for l in residues: res_id = "\':" + str(l) + "\'" atom_indices = top.select(':225')
coor = frame.xyz[atom_indices]
#print(com)
ini = ini+1
com = frame.center_of_mass(':225') <---- here ask me for pytraj.core.c_core.AtomMask
It's low level code:
vec = frame.center_of_mass(pt.AtomMask(':225'))
print(vec.values)
Or use the API
pt.center_of_mass(traj, mask= ..., fram_indices=[your_index])
PS: It might be a good idea for pytraj to accept string. Cheers.
Excellent thank you now it is working
Great. Happy to close this issue.
Hi, I'm trying to select by distance in each frame (every frame change the residues to select by distance), but I could not do this task. The system consist of a solute surrounded by solvent (methanol), it is possible do that with pytraj, because I tried with iteraframe but looks that is not possible. The thing is that for each molecule less than, for example 5 A , I want to perform some calculation for each frame.
Thank you in advance