[gmx-users] for help about reading xtc file
Xu, Yechuan
y.xu at neu.edu
Fri Aug 16 19:02:54 CEST 2013
If the xdrfile library can't do what I want, writing out
the frames is an alternative. I know that the MDAnalysis
has modified the xdrfile library to do seeking xtc file.
But it seems that they do a python wrapper.
Thanks,
YC
On Aug 16, 2013, at 12:35 PM, Mark Abraham wrote:
> That's only worth bothering with if you'll do that re-read several
> times. Is writing out the frame(s) of interest a better solution?
>
> Mark
>
> On Fri, Aug 16, 2013 at 6:25 PM, Xu, Yechuan <y.xu at neu.edu> wrote:
>> Yes, I realized that it is a opaque structure.
>> I just want to read a certain frame from the
>> xtc file. For example, last time I read the xtc
>> file to a certain frame, I want to recorde the
>> position and next time I can read the xtc file
>> from there, not from beginning.
>>
>> Did anybody do that?
>>
>> Thanks,
>> YC
>>
>> On Aug 16, 2013, at 4:39 AM, Mark Abraham wrote:
>>
>>> On Thu, Aug 15, 2013 at 11:33 PM, Xu, Yechuan <y.xu at neu.edu> wrote:
>>>> Thank you for your reply. after I read the xdrfile.c,
>>>>
>>>> I changed the sentence as
>>>> pos=xdr_getpos((XDR*) (xtc->xdr));
>>>>
>>>> like that in the file of xdrfile.c. I also copy the definition
>>>> for XDR and xdr_op to my own code.
>>>
>>> You can see those functions, but the fact that there's an opaque
>>> struct is a clue you're not supposed to want to use them. Your code
>>> has already read the frame using the public interface in
>>> xdrfile_xtc.h. What else are you trying to achieve?
>>>
>>> Mark
>>>
>>>> But I still got the errors:
>>>> seekxtc.c:61:33: error: dereferencing pointer to incomplete type
>>>> pos=xdr_getpos((XDR *)(xtc->xdr));
>>>> ^
>>>>
>>>> here are my code:
>>>> #include <stdio.h>
>>>> #include <stdlib.h>
>>>> #include <math.h>
>>>> #include <xdrfile_xtc.h>
>>>>
>>>> enum xdr_op
>>>> {
>>>> XDR_ENCODE = 0,
>>>> XDR_DECODE = 1,
>>>> XDR_FREE = 2
>>>> };
>>>>
>>>> typedef struct XDR XDR;
>>>>
>>>> struct XDR
>>>> {
>>>> enum xdr_op x_op;
>>>> struct xdr_ops
>>>> {
>>>> int (*x_getlong) (XDR *__xdrs, int32_t *__lp);
>>>> int (*x_putlong) (XDR *__xdrs, int32_t *__lp);
>>>> int (*x_getbytes) (XDR *__xdrs, char *__addr, unsigned int __len);
>>>> int (*x_putbytes) (XDR *__xdrs, char *__addr, unsigned int __len);
>>>> /* two next routines are not 64-bit IO safe - don't use! */
>>>> unsigned int (*x_getpostn) (XDR *__xdrs);
>>>> int (*x_setpostn) (XDR *__xdrs, unsigned int __pos);
>>>> void (*x_destroy) (XDR *__xdrs);
>>>> }
>>>> *x_ops;
>>>> char *x_private;
>>>> };
>>>>
>>>>
>>>> int main(int argc, char *argv[])
>>>> {
>>>> int i;
>>>> int step, read_return, result;
>>>> int natoms;
>>>> float time,prec=1000.;
>>>> matrix box;
>>>> rvec *x;
>>>> XDRFILE *xtc;
>>>> char *fname;
>>>> unsigned int pos;
>>>>
>>>> printf("begin, argc=%d\n",argc);
>>>> if(argc==2){
>>>> fname=argv[1];
>>>> }
>>>>
>>>> xtc=xdrfile_open (fname,"r");
>>>> read_xtc_natoms (fname,&natoms);
>>>> printf("number of atoms: %d\n",natoms);
>>>>
>>>> x = calloc(natoms, sizeof (x[0]));
>>>>
>>>> while(1){
>>>> read_return=read_xtc(xtc,natoms,&step,&time,box,x,&prec);
>>>> if (read_return!=0) break;
>>>>
>>>> pos=xdr_getpos((XDR *)(xtc->xdr));
>>>> printf("%d\n",pos);
>>>>
>>>> }
>>>>
>>>> xdrfile_close (xtc);
>>>> }
>>>> Thanks,
>>>> YC
>>>>
>>>>
>>>> On Aug 15, 2013, at 3:09 PM, Mark Abraham wrote:
>>>>
>>>>> Right, because a pointer to an XDRFILE is neither a struct nor a union
>>>>> :-) Look at how these routines are used, and consult the header files
>>>>> for the right types to give them.
>>>>>
>>>>> Mark
>>>>>
>>>>> On Thu, Aug 15, 2013 at 7:29 PM, Xu, Yechuan <y.xu at neu.edu> wrote:
>>>>>> Hi Everyone,
>>>>>>
>>>>>> I want to read a certain frame in a xtc file. How can I do that?
>>>>>> I see there are xdr_getpos() and xdr_setpos(). How should I use
>>>>>> these functions?
>>>>>>
>>>>>> I tried:
>>>>>>
>>>>>> XDRFILE *xtc;
>>>>>> unsigned int pos;
>>>>>>
>>>>>> pos=xdr_getpos(xtc.xdr);
>>>>>>
>>>>>> but I got:
>>>>>> error: request for member ‘xdr’ in something not a structure or union
>>>>>>
>>>>>> Thanks in advance.
>>>>>> YC--
>>>>>> gmx-users mailing list gmx-users at gromacs.org
>>>>>> http://lists.gromacs.org/mailman/listinfo/gmx-users
>>>>>> * Please search the archive at http://www.gromacs.org/Support/Mailing_Lists/Search before posting!
>>>>>> * Please don't post (un)subscribe requests to the list. Use the
>>>>>> www interface or send it to gmx-users-request at gromacs.org.
>>>>>> * Can't post? Read http://www.gromacs.org/Support/Mailing_Lists
>>>>> --
>>>>> gmx-users mailing list gmx-users at gromacs.org
>>>>> http://lists.gromacs.org/mailman/listinfo/gmx-users
>>>>> * Please search the archive at http://www.gromacs.org/Support/Mailing_Lists/Search before posting!
>>>>> * Please don't post (un)subscribe requests to the list. Use the
>>>>> www interface or send it to gmx-users-request at gromacs.org.
>>>>> * Can't post? Read http://www.gromacs.org/Support/Mailing_Lists
>>>>
>>>> --
>>>> gmx-users mailing list gmx-users at gromacs.org
>>>> http://lists.gromacs.org/mailman/listinfo/gmx-users
>>>> * Please search the archive at http://www.gromacs.org/Support/Mailing_Lists/Search before posting!
>>>> * Please don't post (un)subscribe requests to the list. Use the
>>>> www interface or send it to gmx-users-request at gromacs.org.
>>>> * Can't post? Read http://www.gromacs.org/Support/Mailing_Lists
>>> --
>>> gmx-users mailing list gmx-users at gromacs.org
>>> http://lists.gromacs.org/mailman/listinfo/gmx-users
>>> * Please search the archive at http://www.gromacs.org/Support/Mailing_Lists/Search before posting!
>>> * Please don't post (un)subscribe requests to the list. Use the
>>> www interface or send it to gmx-users-request at gromacs.org.
>>> * Can't post? Read http://www.gromacs.org/Support/Mailing_Lists
>>
>> --
>> gmx-users mailing list gmx-users at gromacs.org
>> http://lists.gromacs.org/mailman/listinfo/gmx-users
>> * Please search the archive at http://www.gromacs.org/Support/Mailing_Lists/Search before posting!
>> * Please don't post (un)subscribe requests to the list. Use the
>> www interface or send it to gmx-users-request at gromacs.org.
>> * Can't post? Read http://www.gromacs.org/Support/Mailing_Lists
> --
> gmx-users mailing list gmx-users at gromacs.org
> http://lists.gromacs.org/mailman/listinfo/gmx-users
> * Please search the archive at http://www.gromacs.org/Support/Mailing_Lists/Search before posting!
> * Please don't post (un)subscribe requests to the list. Use the
> www interface or send it to gmx-users-request at gromacs.org.
> * Can't post? Read http://www.gromacs.org/Support/Mailing_Lists
More information about the gromacs.org_gmx-users
mailing list