in Chemistry/src/DataModel/Serialization/LegacyFormats/FciDump.cs [111:158]
public static void Serialize(TextWriter writer, IEnumerable<ElectronicStructureProblem> problems)
{
var problem = problems.Single();
// Start by writing the header.
writer.WriteLine($"&FCI NORB={problem.NOrbitals},NELEC={problem.NElectrons},");
// Assume global phase symmetry for now.
writer.WriteLine($" ORBSYM={String.Join("", Enumerable.Range(0, problem.NOrbitals).Select(idx => "1,"))}");
writer.WriteLine($" ISYM=1,");
writer.WriteLine("&END");
(string, double) FormatTerm(KeyValuePair<OrbitalIntegral, DoubleCoeff> term) =>
(
String.Join(" ",
ConvertIndices(
term.Key.OrbitalIndices,
OrbitalIntegral.Convention.Dirac,
OrbitalIntegral.Convention.Mulliken
)
.ToOneBasedIndices()
),
term.Value
);
foreach (var (indices, value) in problem
.OrbitalIntegralHamiltonian
.Terms[TermType.OrbitalIntegral.TwoBody]
.Select(FormatTerm))
{
writer.WriteLine($"{value} {indices}");
}
// Next write out all one-body terms, using trailing zeros to indicate one-body.
foreach (var (indices, value) in problem
.OrbitalIntegralHamiltonian
.Terms[TermType.OrbitalIntegral.OneBody]
.Select(FormatTerm))
{
writer.WriteLine($"{value} {indices} 0 0");
}
// Finish by writing out the identity term.
var identityTerm = problem
.OrbitalIntegralHamiltonian
.Terms.GetValueOrDefault(TermType.OrbitalIntegral.Identity, null)
?.Select(term => term.Value.Value)
?.SingleOrDefault() ?? 0.0
+ problem.EnergyOffset.Value;
writer.WriteLine($"{identityTerm} 0 0 0 0");
}