Skip to content

Instantly share code, notes, and snippets.

@ncrubin
Created June 23, 2021 02:40
Show Gist options
  • Save ncrubin/444fe6ea5dcf5526482335542cd50058 to your computer and use it in GitHub Desktop.
Save ncrubin/444fe6ea5dcf5526482335542cd50058 to your computer and use it in GitHub Desktop.
"""
pip install openfermion pyscf openfermionpyscf fqe
"""
import openfermion as of
from openfermionpyscf import run_pyscf
import fqe
from fqe.openfermion_utils import integrals_to_fqe_restricted
def main():
num_atoms = 2
atom_type = 'H'
bond_distance = 2.4
molecule = of.chem.chemical_series.make_atomic_lattice(nx_atoms=1,
ny_atoms=num_atoms,
nz_atoms=1,
basis='sto-3g',
atom_type=atom_type,
spacing=bond_distance
)
print(molecule)
molecule = run_pyscf(molecule, run_scf=True, run_fci=True)
n_electrons = molecule.n_electrons
sz = 0
norbs = molecule.n_orbitals
oei, tei = molecule.get_integrals()
print(oei)
fermion_hamiltonian = of.get_fermion_operator(molecule.get_molecular_hamiltonian())
fqe_ham = integrals_to_fqe_restricted(oei, tei)
print(of.jordan_wigner(fermion_hamiltonian))
# etc, etc, etc,
hf_wf = fqe.Wavefunction([[n_electrons, sz, norbs]])
hf_wf.set_wfn(strategy='hartree-fock')
hf_wf.print_wfn()
print(hf_wf.expectationValue(fqe_ham).real + molecule.nuclear_repulsion,
molecule.hf_energy) # these should be the same
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment