def datafile(filename, mode="rb", format=None):
    """Initialize the appropriate
    :py:class:`~chemlab.io.iohandler.IOHandler` for a given file
    extension or file format.

    The *datafile* function can be conveniently used to quickly read
    or write data in a certain format::

        >>> handler = datafile("molecule.pdb")
        >>> mol = handler.read("molecule")
        # You can also use this shortcut
        >>> mol = datafile("molecule.pdb").read("molecule")

    **Parameters**

    filename: str
          Path of the file to open.
    format: str or None
          When different from *None*, can be used to specify a
          format identifier for that file. It should be used when
          the extension is ambiguous or when there isn't a specified
          filename. See below for a list of the formats supported by chemlab.

    """

    filename = os.path.expanduser(filename)
    base, ext = os.path.splitext(filename)

    if format is None:
        hc = get_handler_class(ext)
    else:
        hc = _handler_map.get(format)
        if hc is None:
            raise ValueError('Format {} not supported.'.format(format))

    fd = open(filename, mode)

    handler = hc(fd)
    return handler
Initialize the appropriate
    :py:class:`~chemlab.io.iohandler.IOHandler` for a given file
    extension or file format.

    The *datafile* function can be conveniently used to quickly read
    or write data in a certain format::

        >>> handler = datafile("molecule.pdb")
        >>> mol = handler.read("molecule")
        # You can also use this shortcut
        >>> mol = datafile("molecule.pdb").read("molecule")

    **Parameters**

    filename: str
          Path of the file to open.
    format: str or None
          When different from *None*, can be used to specify a
          format identifier for that file. It should be used when
          the extension is ambiguous or when there isn't a specified
          filename. See below for a list of the formats supported by chemlab.