code: def to_hdf5(self, f):
          
  
          if isinstance(f, str):
              import h5py
              f = h5py.File(f)
  
          if self.frame is not None:
              frame_group = f.create_group('frame')
              frame_group.attrs['module'] = self.frame.__module__
              frame_group.attrs['class'] = self.frame.__class__.__name__
  
              units = [str(x).encode('utf8')
                       for x in self.frame.units.to_dict().values()]
              frame_group.create_dataset('units', data=units)
  
              d = frame_group.create_group('parameters')
              for k, par in self.frame.parameters.items():
                  quantity_to_hdf5(d, k, par)
  
          cart = self.represent_as('cartesian')
          quantity_to_hdf5(f, 'pos', cart.xyz)
          quantity_to_hdf5(f, 'vel', cart.v_xyz)
  
          return f
docs: Serialize this object to an HDF5 file.
  
          Requires ``h5py``.
  
          Parameters
          ----------
          f : str, :class:`h5py.File`
              Either the filename or an open HDF5 file.