def name_sep_val(mm, name, sep='=', dtype=float, ipos=1):
  """Read key-value pair such as "name = value"

  Args:
    mm (mmap): memory map
    name (str): name of variable; used to find value line
    sep (str, optional): separator, default '='
    dtype (type, optional): variable data type, default float
    ipos (int, optiona): position of value in line, default 1 (after sep)
  Return:
    dtype: value of requested variable
  Examples:
    >>> name_sep_val(mm, 'a')  # 'a = 2.4'
    >>> name_sep_val(mm, 'volume', ipos=-2) # 'volume = 100.0 bohr^3'
    >>> name_sep_val(mm, 'key', sep=':')  # 'key:val'
    >>> name_sep_val(mm, 'new', sep=':')  # 'new:name'
    >>> name_sep_val(mm, 'natom', dtype=int)  # 'new:name'
  """
  idx = mm.find(name.encode())
  if idx == -1:
    raise RuntimeError('"%s" not found' % name)
  mm.seek(idx)
  line = mm.readline().decode()
  tokens = line.split(sep)
  val_text = tokens[ipos].split()[0]
  val = dtype(val_text)
  return val