@@ -256,7 +256,7 @@ cdef class DCDFile:
256256 self .wrote_header = False
257257 # Has to come last since it checks the reached_eof flag
258258 if self .mode == 'r' :
259- self .remarks = self . _read_header ()
259+ self ._read_header ()
260260
261261 def close (self ):
262262 """Close the open DCD file
@@ -278,7 +278,8 @@ cdef class DCDFile:
278278 "ErrorCode: {}" .format (self .fname , ok ))
279279
280280
281- def _read_header (self ):
281+ cdef void _read_header (self ):
282+ """read header and populate internal fields"""
282283 if not self .is_open :
283284 raise IOError ("No file open" )
284285
@@ -321,9 +322,9 @@ cdef class DCDFile:
321322
322323 py_remarks = "" .join (s for s in py_remarks if s in string .printable )
323324
324- return py_remarks
325+ self . remarks = py_remarks
325326
326- def _estimate_n_frames (self ):
327+ cdef int _estimate_n_frames (self ):
327328 extrablocksize = 48 + 8 if self .charmm & DCD_HAS_EXTRA_BLOCK else 0
328329 self ._firstframesize = (self .natoms + 2 ) * self .ndims * sizeof (float ) + extrablocksize
329330 self ._framesize = ((self .natoms - self .nfixed + 2 ) * self .ndims * sizeof (float ) +
@@ -337,8 +338,13 @@ cdef class DCDFile:
337338
338339 @property
339340 def is_periodic (self ):
340- return bool ((self .charmm & DCD_IS_CHARMM ) and
341- (self .charmm & DCD_HAS_EXTRA_BLOCK ))
341+ """
342+ Returns
343+ -------
344+ bool if periodic unitcell is available
345+ """
346+ return bool ((self .charmm & DCD_IS_CHARMM ) and
347+ (self .charmm & DCD_HAS_EXTRA_BLOCK ))
342348
343349 def seek (self , frame ):
344350 """Seek to Frame.
@@ -375,17 +381,21 @@ cdef class DCDFile:
375381
376382 @property
377383 def header (self ):
384+ """
385+ Returns
386+ -------
387+ dict of header values needed to write new dcd
388+ """
378389 return {'natoms' : self .natoms ,
379390 'istart' : self .istart ,
380391 'nsavc' : self .nsavc ,
381392 'delta' : self .delta ,
382393 'charmm' : self .charmm ,
383394 'remarks' : self .remarks }
384395
385- def write_header (self , remarks , natoms , istart ,
386- nsavc , delta ,
387- charmm ):
388- """write DCD header
396+ def write_header (self , remarks , natoms , istart , nsavc , delta , charmm ):
397+ """write DCD header. This function needs to be called before a frame can be
398+ written.
389399
390400 Parameters
391401 ----------
@@ -394,9 +404,14 @@ cdef class DCDFile:
394404 natoms : int
395405 number of atoms to write
396406 istart : int
407+ starting frame
397408 nsavc : int
409+ number of frames between saves
398410 delta : float
411+ timepstep
399412 charmm : int
413+ is charmm dcd
414+
400415 """
401416 if not self .is_open :
402417 raise IOError ("No file open" )
@@ -433,12 +448,6 @@ cdef class DCDFile:
433448 cartesion coordinates
434449 box : array_like, shape=(6)
435450 Box vectors for this frame
436- step : int
437- current step number, 1 indexed
438- time : float
439- current time
440- natoms : int
441- number of atoms in frame
442451
443452 Raises
444453 ------
@@ -467,10 +476,26 @@ cdef class DCDFile:
467476 self .natoms , < FLOAT_T * > & x [0 ],
468477 < FLOAT_T * > & y [0 ], < FLOAT_T * > & z [0 ],
469478 < DOUBLE_T * > & c_box [0 ], self .charmm )
479+ if ok != 0 :
480+ raise IOError ("Couldn't write DCD frame" )
470481
471482 self .current_frame += 1
472483
473484 def read (self ):
485+ """
486+ Read next dcd frame
487+
488+ Returns
489+ -------
490+ DCDFrame : namedtuple
491+ positions are in ``x`` and unitcell in ``unitcell`` attribute of DCDFrame
492+
493+ Notes
494+ -----
495+ unitcell is read as it from DCD. Post processing depending the program this
496+ DCD file was written with is necessary. Have a look at the MDAnalysis DCD reader
497+ for possible post processing into a common unitcell data structure.
498+ """
474499 if self .reached_eof :
475500 raise IOError ('Reached last frame in DCD, seek to 0' )
476501 if not self .is_open :
@@ -501,6 +526,30 @@ cdef class DCDFile:
501526
502527
503528 def readframes (self , start = None , stop = None , step = None , order = 'fac' , indices = None ):
529+ """
530+ read multiple frames at once
531+
532+ Parameters
533+ ----------
534+ start, stop, step : int
535+ range of frames
536+ order : str (optional)
537+ give order of returned array with `f`:frames, `a`:atoms, `c`:coordinates
538+ indices : array_like (optional)
539+ only read selected atoms. In ``None`` read all.
540+
541+ Returns
542+ -------
543+ DCDFrame : namedtuple
544+ positions are in ``x`` and unitcell in ``unitcell`` attribute of DCDFrame.
545+ Here the attributes contain the positions for all frames in the given order
546+
547+ Notes
548+ -----
549+ unitcell is read as it from DCD. Post processing depending the program this
550+ DCD file was written with is necessary. Have a look at the MDAnalysis DCD reader
551+ for possible post processing into a common unitcell data structure.
552+ """
504553 if self .reached_eof :
505554 raise IOError ('Reached last frame in DCD, seek to 0' )
506555 if not self .is_open :
0 commit comments