4 * This source code is part of
8 * GROningen MAchine for Chemical Simulations
12 * Copyright (c) 1991-1999
13 * BIOSON Research Institute, Dept. of Biophysical Chemistry
14 * University of Groningen, The Netherlands
17 * GROMACS: A message-passing parallel molecular dynamics implementation
18 * H.J.C. Berendsen, D. van der Spoel and R. van Drunen
19 * Comp. Phys. Comm. 91, 43-56 (1995)
21 * Also check out our WWW page:
22 * http://md.chem.rug.nl/~gmx
27 * Great Red Oystrich Makes All Chemists Sane
29 static char *SRCID_g_run_rms_c
= "$Id$";
45 real
calc_ener(int natoms
,real w_rms
[],rvec x
[],rvec xp
[])
53 for(j
=0;(j
<natoms
);j
++) {
56 e
+=w_rms
[j
]*(x
[j
][m
]-xp
[j
][m
])*(x
[j
][m
]-xp
[j
][m
]);
62 int main (int argc
,char *argv
[])
64 static char *desc
[] = {
65 "g_run_rms computes the root mean square deviation (RMSD) of a structure",
66 "from a trajectory x(t), with respect to a reference structure from the",
67 "same trajectory, but at a specified time before the current time",
68 "x(t-dt) by LSQ fitting the structures on top of each other[PAR]",
69 "This tells you something about the mobility of structure as a function",
72 static int run_time
= 5;
74 { "-t", FALSE
, etINT
, &run_time
,
75 "Time interval dt between reference and actual structure" }
77 int step
,nre
,natom
,i
,j
,m
,teller
=0;
78 real t
,lambda
,*w_rls
,*w_rms
,tmas
;
84 rvec
**x
,*xp
,*v
,xcm
,*temp
;
93 { efTRX
, "-f", NULL
, ffREAD
},
94 { efTPX
, NULL
, NULL
, ffREAD
},
95 { efNDX
, NULL
, NULL
, ffREAD
},
96 { efXVG
, NULL
, "runrms", ffWRITE
}
98 #define NFILE asize(fnm)
100 CopyRight(stderr
,argv
[0]);
101 parse_common_args(&argc
,argv
,PCA_CAN_VIEW
| PCA_CAN_TIME
,TRUE
,
102 NFILE
,fnm
,asize(pa
),pa
,asize(desc
),desc
,0,NULL
);
105 read_tpxheader(ftp2fn(efTPX
,NFILE
,fnm
),&header
);
106 snew(xp
,header
.natoms
);
107 for(i
=0;(i
<run_time
+1);i
++)
108 snew(x
[i
],header
.natoms
);
109 snew(w_rls
,header
.natoms
);
110 snew(w_rms
,header
.natoms
);
111 snew(v
,header
.natoms
);
113 read_tpx(ftp2fn(efTPX
,NFILE
,fnm
),
114 &step
,&t
,&lambda
,&ir
,
115 box
,&natom
,xp
,NULL
,NULL
,&top
);
120 fprintf(stderr
,"select group for root least squares fit\n");
121 rd_index(ftp2fn(efNDX
,NFILE
,fnm
),1,&isize
[RLS
],&index
[RLS
],&grpnames
[RLS
]);
122 for(i
=0;(i
<isize
[RLS
]);i
++)
123 w_rls
[index
[RLS
][i
]]=top
.atoms
.atom
[index
[RLS
][i
]].m
;
125 fprintf(stderr
,"select group for root mean square calculation\n");
126 rd_index(ftp2fn(efNDX
,NFILE
,fnm
),1,&isize
[RMS
],&index
[RMS
],&grpnames
[RMS
]);
127 for(i
=0;(i
<isize
[RMS
]);i
++)
128 w_rms
[index
[RMS
][i
]]=top
.atoms
.atom
[index
[RMS
][i
]].m
;
130 fp
=xvgropen(ftp2fn(efXVG
,NFILE
,fnm
),"Running RMSD","Time (ps)","RMSD (nm)");
132 rm_pbc(&(top
.idef
),top
.atoms
.nr
,box
,xp
,xp
);
136 for(i
=0;(i
<header
.natoms
);i
++)
139 /*set center of mass to zero for reference coordinates*/
142 natom
=read_first_x(&status
,ftp2fn(efTRX
,NFILE
,fnm
),&t
,&x
[0],box
);
143 for(i
=0; (i
<run_time
); i
++) {
144 read_next_x(status
,&t
,natom
,x
[i
],box
);
145 rm_pbc(&(top
.idef
),top
.atoms
.nr
,box
,x
[i
],x
[i
]);
148 for(j
=0;(j
<header
.natoms
);j
++)
150 xcm
[m
]+=x
[i
][j
][m
]*w_rls
[j
];
154 for(j
=0;(j
<header
.natoms
);j
++) {
160 read_next_x(status
,&t
,natom
,x
[run_time
],box
);
163 rm_pbc(&(top
.idef
),top
.atoms
.nr
,box
,x
[run_time
],x
[run_time
]);
166 for(j
=0;(j
<header
.natoms
);j
++)
168 xcm
[m
]+=x
[run_time
][j
][m
]*w_rls
[j
];
172 for(j
=0;(j
<header
.natoms
);j
++) {
174 x
[run_time
][j
][m
]-=xcm
[m
];
177 /*calculate energy of root_least_squares*/
178 do_fit(header
.natoms
,w_rls
,x
[0],x
[run_time
]);
179 fprintf(fp
,"%8.4f %8.4f\n",
180 t
,calc_ener(header
.natoms
,w_rms
,x
[0],x
[run_time
]));
184 for(i
=0;(i
<run_time
);i
++)
187 } while ((read_next_x(status
,&t
,natom
,x
[run_time
],box
)));
188 fprintf(stderr
,"\n");
193 xvgr_file(ftp2fn(efXVG
,NFILE
,fnm
),NULL
);