[gmx-users] write velocity and coordinates with template.c

Mark Abraham Mark.Abraham at anu.edu.au
Fri Jul 27 16:01:31 CEST 2012

On 27/07/2012 7:14 PM, prithvi raj pandey wrote:
>> Message: 2
>> Date: Thu, 26 Jul 2012 20:56:00 +1000
>> From: Mark Abraham <Mark.Abraham at anu.edu.au>
>> Subject: Re: [gmx-users] Writing velocity of particles using
>>          template.c
>> To: Discussion list for GROMACS users <gmx-users at gromacs.org>
>> Message-ID: <50112240.5000109 at anu.edu.au>
>> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
>> On 26/07/2012 8:22 PM, prithvi raj pandey wrote:
>>> Dear gmx users,
>>> I am using template.c of gromacs 4.0.7 for writing my own analysis
>>> tool. When I am using the fr.x[i][XX], it writes the coordinates of
>>> the particles (i crosschecked it with the coordinates written by the
>>> trjconv command). But the problem arises when I use fr.v[i][XX] for
>>> writing the velocities of the particles or fr.f[i][XX] for writing the
>>> force. The program compiles fine by using make command. But finally
>>> the template stops showing segmentation fault. The main loop is as
>>> follows -
>>>    do {
>>> fprintf(fp,"BOX  %f %f %f %f
>>> \n",fr.time,fr.box[XX][XX],fr.box[YY][YY],fr.box[ZZ][ZZ]);
>>> for (i=0; i<top.atoms.nr; i++)
>>> {
>>>       fprintf(fp,"Velocity at t=%8.3f : %f  %f
>>> %f\n",fr.time,fr.v[i][XX],fr.v[i][YY],fr.v[i][ZZ]);
>>> }
>>>     } while(read_next_frame(status,&fr));
>>> Am I using the variable used for writing velocity/force wrongly?
>> Did you verify that the trajectory has velocities, and that you read
>> them, and that they're found in fr.v? Look at the code for a tool that
>> reads velocities (g_velacc, I guess).
>> Mark
> Dear Mark,
> I ran the g_velacc command, it works fine and writes the output .xvg
> file. Also i generated a .gro containing both positions and velocity
> using the trjconv command.
> By this time I could wirte the velocity using template.c by changing
> TRX_READ_X toTRX_READ_V and by adding *vtop in rvec in the following
> section of template.c
>   t_topology top;
>    int        ePBC;
>    char       title[STRLEN];
>    t_trxframe fr;
>    rvec       *xtop,*vtop;
>    matrix     box;
>    int        status;
>    int        flags = TRX_READ_V;
> But the problem now is it only writes velocity using the variable
> fr.v[i][XX], but the coordinates are not being written by the variable
> fr.x[i][XX]. I intend to use both coordinates and velocity for my
> program.
> It seems to that the  "flags =" can only take one value. This is
> because I tried to write both TRX_READ_X and TRX_READ_V under the same
> flags variable, but it did not compile.

If you'd looked up the header file where these are defined, or grepped 
the source code for how they are used (if you're in a git tree, git grep 
makes this easy!), you might have seen that they are designed to be 
combined with a bitwise-or.


More information about the gromacs.org_gmx-users mailing list