[gmx-developers] how to write a xtc file in c

Yang Ye leafyoung81-group at yahoo.com
Thu Aug 10 11:39:13 CEST 2006


Mark Abraham wrote:
> Dongsheng Zhang wrote:
>> Dear GMX developers,
>>
>> I want to write a xtc file to do rerun to get a special potential
>> energy. Could you please tell me how to write a xtc file in c from a gro
>> file (with multiple frames got from a xtc file, without velocity)? Thank
>> you for your help!
>
> Read the source code - to find the right functions to call look how 
> trjconv or something does it, then grep the src/*/*.c files for the 
> function definition.
>
> Also http://www.gromacs.org/documentation/reference/online/xtc.html
This document shall help you.

Here is basic workflow:

1. Open XTC
int xfile = -1;
char *xfilename = "out.xtc";

xfile = open_xtc(xfilename, "w");

2. Close
if (xfile!=-1) {
   close_xtc(xfile);
   xfile = -1;
   //OK
} else {
   //Error
}

3. Write XTC
long step = -1;
double sim_time = 0.0;

matrix mat;
int i;
rvec *x_data;
double ppos[3];
int img[3];
int pnode;

int n_total_particles;

Particle p_data;

if (xfile==-1) {
  //Error
}

if (n_total_particles <1) {
  //Error
}

mat[0][0] = CONV_UNIT_L(box_l[0]);
mat[0][1] = 0.0;
mat[0][2] = 0.0;
mat[1][0] = 0.0;
mat[1][1] = CONV_UNIT_L(box_l[1]);
mat[1][2] = 0.0;
mat[2][0] = 0.0;
mat[2][1] = 0.0;
mat[2][2] = CONV_UNIT_L(box_l[2]);

x_data = (rvec *)malloc(sizeof(rvec)*(n_total_particles+1));

for (i = 0; i < n_total_particles; i++) {
   x_data[i][0] = X;
   x_data[i][1] = Y;
   x_data[i][2] = Z;
}

write_xtc(xfile, n_total_particles, step, sim_time, mat, x_data, 1000);
step++;

free(x_data);

return OK;

> Mark
> _______________________________________________
> gmx-developers mailing list
> gmx-developers at gromacs.org
> http://www.gromacs.org/mailman/listinfo/gmx-developers
> Please don't post (un)subscribe requests to the list. Use the www 
> interface or send it to gmx-developers-request at gromacs.org.
>






More information about the gromacs.org_gmx-developers mailing list