def dump_fcidump(filename, data):
    """Write one- and two-electron integrals in the Molpro 2012 FCIDUMP format.

    Works only for restricted wavefunctions.

    Keep in mind that the FCIDUMP format changed in Molpro 2012, so files
    written with this function cannot be used with older versions of Molpro

    Parmeters
    ---------
    filename : str
        The filename of the FCIDUMP file. This is usually "FCIDUMP".

    data : IOData
        Must contain ``one_mo``, ``two_mo``. May contain ``core_energy``, ``nelec`` and
        ``ms``.
    """
    with open(filename, 'w') as f:
        one_mo = data.one_mo
        two_mo = data.two_mo
        nactive = one_mo.shape[0]
        core_energy = getattr(data, 'core_energy', 0.0)
        nelec = getattr(data, 'nelec', 0)
        ms2 = getattr(data, 'ms2', 0)
        print(' &FCI NORB=%i,NELEC=%i,MS2=%i,' % (nactive, nelec, ms2), file=f)
        print('  ORBSYM= ' + ','.join(str(1) for v in range(nactive)) + ',',
            file=f)
        print('  ISYM=1', file=f)
        print(' &END', file=f)
        for i in range(nactive):
            for j in range(i + 1):
                for k in range(nactive):
                    for l in range(k + 1):
                        if i * (i + 1) / 2 + j >= k * (k + 1) / 2 + l:
                            value = two_mo[i, k, j, l]
                            if value != 0.0:
                                print('%23.16e %4i %4i %4i %4i' % (value, i +
                                    1, j + 1, k + 1, l + 1), file=f)
        for i in range(nactive):
            for j in range(i + 1):
                value = one_mo[i, j]
                if value != 0.0:
                    print('%23.16e %4i %4i %4i %4i' % (value, i + 1, j + 1,
                        0, 0), file=f)
        if core_energy != 0.0:
            print('%23.16e %4i %4i %4i %4i' % (core_energy, 0, 0, 0, 0), file=f
                )
