Re: [AMBER] Cpptraj: Move origin to specific coordinates

From: Daniel Roe <>
Date: Tue, 21 Oct 2014 09:06:58 -0600


Very interesting problem! It's a bit involved, but I think you can do
it with cpptraj (make sure you have the most up-to-date version,
14.09). Basically there are two phases. In the first phase you center,
calculate the vector, then scale the vector. In the second you need to
script a loop to take advantage of the 'center reference'
functionality. At the end the center of mass of the whole protein will
be centered on the end of the scaled vector (which I think is what you
want). Here is an example where I am using residues 5 and 6 of a

# Load trajectory, center, calculate vector from origin to c.o.m. of
residues 5 and 6.
parm myparm.parm7
center origin
vector center :5,6 trajout trajfmt netcdf parmout vec.parm7
# Scale the vector by 1.1x
clear trajin
parm vec.parm7
trajin parm vec.parm7
scale x 1.1 y 1.1 z 1.1
trajout parm vec.parm7

The 'vector' command here will generate a pseudo trajectory/topology
for the vector, which you can then read back in and use the 'scale'
command on. The vector pseudo-topology has two atoms: the origin and
the vector itself. The scaled vector is output to another
pseudo-trajectory. Notice the 'clear trajin' which ensures you don't
process the original trajectory the second time around, and the 'parm'
keyword in the 'trajout' command to let it know you will be writing a
trajectory associated with the vector pseudo parm. Looking at the
cpptraj output here for Warnings/Errors will be crucial.

Next you would script a loop to use each frame of the scaled vector
trajectory as the reference to center each frame of the original
trajectory on (here I will use bash). Remember in the vector pseudo
trajectory the origin is the first atom, the vector is the second atom
(which is why I'm using the reference mask '.2' in the 'center'
command). Note I'm also using the '-tl' command-line functionality of
cpptraj to get the number of frames in the trajectory:

MAXFRAMES=`cpptraj -p myparm.parm7 -y -tl | awk '{print $2}'`
for ((FRAME=1; FRAME <= $MAXFRAMES; FRAME++)) ; do
  cpptraj <<EOF
    parm myparm.parm7
    trajin $FRAME $FRAME 1
    parm vec.parm7
    reference $FRAME $FRAME parm vec.parm7
    center reference * .2
    trajout append

You may want to redirect/append the cpptraj output here to make it
easier to check for problems. Hopefully this is what you want to do.
Let me know if you have any questions.


On Tue, Oct 21, 2014 at 7:09 AM, Waldner, Birgit
<> wrote:
> Dear Amber users,
> I would like to achieve the following task using cpptraj, but can't find a straightforward way to do all of it directly in cpptraj:
> 1. Calculate a vector from the center of mass of the whole protein (centered at 0 0 0) to the center of mass of the residues specified in a second mask.
> 2. Elongate the vector by 10-20%.
> 3. Set the origin to the coordinates stored in the elongated vector.
> And all this for each frame of the trajectory.
> Basically I want to move the origin 10-20% away from the residues specified in the second mask, but in the direction of the vector from the center of mass of the protein to the center of mass of the atoms in the second mask.
> I can calculate the vector in step 1, but then I can't find in the manual how to perform the actions of step 2 and step 3 in cpptraj.
> Does anyone know how or if this can all be done in cpptraj? Could the "scale" command help? Is there an option to multiply a vector with a matrix or scalar in cpptraj?
> Thank you very much for your help, best regards,
> Birgit Waldner
> _______________________________________________
> AMBER mailing list

Daniel R. Roe, PhD
Department of Medicinal Chemistry
University of Utah
30 South 2000 East, Room 307
Salt Lake City, UT 84112-5820
(801) 587-9652
(801) 585-6208 (Fax)
AMBER mailing list
Received on Tue Oct 21 2014 - 08:30:02 PDT
Custom Search