Skip to content

Commit

Permalink
Program no longer assumes where integrals start in fcidump (#63)
Browse files Browse the repository at this point in the history
* only master loads wave function and integrals

* added # because it was missing

* Program no longer assumes where integrals start in fcidump

* Program no longer assumes where integrals start in fcidump: updated
  • Loading branch information
nathanjohnsongithub authored Jun 29, 2023
1 parent 6093765 commit 145299d
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions qe/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from collections import defaultdict
from qe.integral_indexing_utils import compound_idx4
import math
from itertools import takewhile

# _____ _ _ _ _ _ _ _
# |_ _| (_) | (_) | (_) | | (_)
Expand All @@ -18,6 +19,12 @@
# \___/_| |_|_|\__|_|\__,_|_|_/___\__,_|\__|_|\___/|_| |_|


# Takes in the raw lines and manipulates them if needed based on using zip or not.
def manipulate_line(raw_line, used_zip):
line = raw_line.decode("utf-8") if used_zip else raw_line
return line.strip()


# ~
# Integrals of the Hamiltonian over molecular orbitals
# ~
Expand All @@ -41,6 +48,9 @@ def load_integrals(
for i in glob.glob(fcidump_path):
print(i)

# Add used_zip boolean so we know if we need to decode the lines.
used_zip = True

# Use an iterator to avoid storing everything in memory twice.
if fcidump_path.split(".")[-1] == "gz":
import gzip
Expand All @@ -52,13 +62,15 @@ def load_integrals(
f = bz2.open(fcidump_path)
else:
f = open(fcidump_path)
used_zip = False

# Only non-zero integrals are stored in the fci_dump.
# Hence we use a defaultdict to handle the sparsity
n_orb = int(next(f).split()[2])

for _ in range(3):
next(f)
# Using takewhile we 'take lines from the file' while '/' has not been found
# Needed so we can start reading data on the integrals.
lines = list(takewhile(lambda line: "/" not in manipulate_line(line, used_zip), f))

d_one_e_integral = defaultdict(int)
d_two_e_integral = defaultdict(int)
Expand Down

0 comments on commit 145299d

Please sign in to comment.