[gmx-developers] Getting the last frame in an xtc file

Mark Abraham Mark.Abraham at anu.edu.au
Thu Apr 10 13:48:05 CEST 2008


Ran Friedman wrote:
> Dear developers,
> 
> I bothered you with this question two weeks ago but received no replies.
> To make this simple: is there a way to get the time or frame number for
> the last frame of an xtc file? Did any of you use
> xtc_get_last_frame_time or xtc_get_last_frame_number successfully, or
> managed to do it in any other way that doesn't include reading all
> frames one-by-one?

Roughly speaking, xtc_at_header_start expects to be at the start of a 
frame to read its header, or to fail. The 3.3.1 version of 
xtc_get_frame_number does the test-for-header with explicit code, 
whereas 3.3.3 does it with the call to xtc_at_header_start. When the 
test fails, and xtc_at_header_start fails, the 3.3.3 version should 
probably have

	if(gmx_fseek(xdrfiles[fp+1],off-sizeof(int)*2,SEEK_SET)){

as line 1328, not

	if(gmx_fseek(xdrfiles[fp+1],off,SEEK_SET)){

so that it seeks backwards in the same way as the 3.3.1 code does. Ran 
can probably test this to see if it works :-)

Mark

> Ran Friedman wrote:
>> Dear developers,
>>
>> I was unsuccessful in using xtc_get_last_frame_time from libxdrf.c on
>> different XTC files. This function isn't used by any other function in
>> GMX AFAIK.
>>
>> The function always exits with return value -1 after the following line:
>>
>> line 1639:
>> time = xtc_get_current_frame_time(fp, natoms, bOK);
>> xtc_get_current_frame_time, in its turn, returns -1 after calling
>> xtc_at_header_start:
>>
>> line 1281:
>> ret = xtc_at_header_start(fp,natoms,&step,&time);
>>
>> And xtc_at_header_start returns -1 at:
>>
>> lines 1159-1165:
>>   /* read magic natoms and timestep */
>>   for(i = 0;i<3;i++){
>>     if(!xdr_int(xdridptr[fp+1], &(i_inp[i]))){
>>       gmx_fseek(xdrfiles[fp+1],off+sizeof(int),SEEK_SET);
>>       return -1;
>>     }
>>   }
>>
>> It returns -1 when i=1 (i.e. for the number of atoms), but the magic
>> number is also not right (and it's not the same number for different
>> trajectories).
>>
>> Coming back to the high level function which I use
>> (xtc_get_last_frame_time), I noticed that it puts the stream pointer to
>> the EOF - 4 fields:
>>
>> lines 1634-1639
>>     if( (res = gmx_fseek(xdrfiles[fp+1],-4,SEEK_END)) != 0){
>>       *bOK = 0;
>>       return -1;
>>     }
>>
>>     time = xtc_get_current_frame_time(fp, natoms, bOK);
>>
>> My questions are:
>> 1. Will this location point me to the header? If the header is at the
>> beginning of each frame then I guess that the answer is no.
>> 2. Suppose that it doesn't point me to the header of the last frame, how
>> can I get there without passing through all other frames?
>>
>> I'm using GMX 3.3.3.
>>
>> Thanks,
>> Ran.
>>
>>   
> 
> 
> _______________________________________________
> 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