Amber-MD / pytraj

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

Converting between trajectories #1458

Closed lacoperon closed 6 years ago

lacoperon commented 6 years ago

Hi there,

I was wondering how one would convert between box types within pytraj.

For example, I loaded in an AMBER trajectory, whose trajectory description is:

pytraj.Trajectory, 1000 frames: 
Size: 0.011064 (GB)
<Topology: 495 atoms, 495 residues, 495 mols, PBC with box type = truncoct>

Whereas when I load in a PDB file, I get a description

pytraj.Trajectory, 1 frames: 
Size: 0.000011 (GB)
<Topology: 495 atoms, 495 residues, 495 mols, non-PBC>

What exactly does the difference between PBC with box type = truncoct and non-PBC correspond to?

Note: I'm trying to concatenate the trajectories so I can project the resulting combined trajectory using eigenvalues and eigenvectors obtained from the PCA function. But, I can't do this unless I can align the PDB structure to the AMBER trajectory, which I can't do in pytraj without them being combined. Any help therein would be greatly appreciated.

Thanks

hainm commented 6 years ago
In [8]: traj = pt.load('tz2.ortho.nc', 'tz2.ortho.parm7')[:1]

In [9]: traj
Out[9]: 
pytraj.Trajectory, 1 frames: 
Size: 0.000118 (GB)
<Topology: 5293 atoms, 1704 residues, 1692 mols, PBC with box type = ortho>

In [10]: traj.save("hey.pdb")

In [12]: pt.load('hey.pdb')
Out[12]: 
pytraj.Trajectory, 1 frames: 
Size: 0.000118 (GB)
<Topology: 5293 atoms, 1704 residues, 1692 mols, PBC with box type = ortho>

Any help therein would be greatly appreciated.

I might help if you let me know your specific question here or a specific example. Cheers.

hainm commented 6 years ago

Another example about unitcell

In [31]: traj
Out[31]: 
pytraj.Trajectory, 1 frames: 
Size: 0.000118 (GB)
<Topology: 5293 atoms, 1704 residues, 1692 mols, non-PBC>

In [32]: traj.top.box = pt.core.Box([39.455974, 46.821517, 40.469541, 90.0, 90.0, 90.0])

In [33]: traj
Out[33]: 
pytraj.Trajectory, 1 frames: 
Size: 0.000118 (GB)
<Topology: 5293 atoms, 1704 residues, 1692 mols, PBC with box type = ortho>
hainm commented 6 years ago

Truncated box

In [35]: top = pt.load_topology('tz2.truncoct.parm7')

In [36]: top.box
Out[36]: <Box: truncoct, (x, y, z, alpha, beta, gamma) = (44.8903851, 44.8903851, 44.8903851, 109.471219, 109.471219, 109.471219)>

# convert to ortho-box
top.box = pt.core.Box([39.455974, 46.821517, 40.469541, 90.0, 90.0, 90.0])
In [40]: top
Out[40]: <Topology: 5827 atoms, 1882 residues, 1870 mols, PBC with box type = ortho>
hainm commented 6 years ago

Note: I'm trying to concatenate the trajectories so I can project the resulting combined trajectory using eigenvalues and eigenvectors obtained from the PCA function.

One of the easy ways is to combine numpy array then reassign the traj.xyz

traj.xyz = xyz # :D 
lacoperon commented 6 years ago

Much appreciated!!! Apologies for the delay in responding.

hainm commented 6 years ago

thanks.