Re: [AMBER] How do I apply cpptraj.timecorr to the output dataset of cpptraj.dihedral?

From: Jose Borreguero <>
Date: Thu, 17 Jul 2014 14:36:54 -0400

It seems that cpptraj cannot do the following first and second time
autocorrelation functions:
<(3*cos^2(phi(t)-phi(t+t0)) - 1)/2>_t0
using phi(t) from the output of dihedral command.
Thus I wrote a python script to do that, reading as input the output file
from dihedral command. Maybe someone else can profit from this.
#!/usr/bin/env python
import numpy
if __name__=='__main__':
  import argparse
  parser = argparse.ArgumentParser(description='calculate first and second
order correlations')
  parser.add_argument('--infile',help='input file with dihedral angles')
  parser.add_argument('--outfile',help='output file')
  args = parser.parse_args()

  phis=(numpy.pi/180.)*numpy.loadtxt(args.infile, comments='#',

  # First order Legendre Polynomial autocorrelation
  # We use cos(a-b)=cos(a)cos(b)+sin(a)sin(b)


  # Second order Legendre Polynomial autocorrelation
  # We use the relation cos^2(x)=(1+cos(2x))/2 and
  cos_2phis=numpy.cos(2*phis) # cos(2*phi)
  sin_2phis=numpy.cos(2*phis) # sin(2*phi)

  c2=(1+c2)/2 # <cos^2(phi(t)-phi(t+t0)>_t0

  dt=1.0 #picoseconds
  buf='# time c1 c2\n'
  for i in range(nh,n):
    buf+='{0:4.0f} {1:7.4f} {2:7.4f}\n'.format( dt*(i-nh), c1[i], c2[i] )


On Wed, Jul 16, 2014 at 7:40 PM, Jose Borreguero <>

> Dear Amber users,
> I want to calculate the time autocorrelation function of a dihedral angle.
> I've used dihedral command from cpptraj to get the angle. For instance:
> dihedral theta .Si6 .C18 .C20 .C24 out theta.dat
> Command timecorr requires a vector as input, so I guess my question is
> how do I translate dataset theta into vector set (cos(theta), sin(theta),
> 0) so that I can feed it to timecorr.
> Related question: with output file theta.dat I can create file vector.dat
> with columns cos(theta), sin(theta), and 0. Then is it possible to read
> file vector.dat into a vector set that I can pass to timecorr?
> Best regards,
> -Jose Borreguero
AMBER mailing list
Received on Thu Jul 17 2014 - 12:00:02 PDT
Custom Search