-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Program no longer assumes where integrals start in fcidump #63
Program no longer assumes where integrals start in fcidump #63
Conversation
nathanjohnsongithub
commented
Jun 21, 2023
- Program doesn't assume where integrals start inside fcidump file. The number of 'orbsym' lines would crash the program if there was more than one line. Program now checks for a certain 'key' then starts reading the integrals.
Didn't i Have already merged this? |
This has some new changes in the |
Yes, I added things to the io.py file |
qe/io.py
Outdated
# Key were looking for | ||
key = " /\n" | ||
found = False | ||
# Keep looping until the key is found | ||
while not found: | ||
# Read line | ||
line = f.readline() | ||
# Decode if needed | ||
line = line.decode("utf-8") if used_zip else line | ||
# Check if it equals the key | ||
found = line == key |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use the takewhile I think
https://docs.python.org/3/library/itertools.html#itertools.takewhile
def if_new_line(raw_line) {
line =raw_line.decode("utf-8") if used_zip else raw_line
return line.strip() # Is empty line work as sentinel? if not go back to ` /n`
}
takewhile(if_new_line, f)
takewhile: Arguably a little more read-able / functional
raw_line: not mutating variable, make the code easier to read
stip: no "magic number"
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)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needed to be equal to a list for some reason that I do not know.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's the difference between an iterator
and a list
. Maybe https://stackoverflow.com/questions/25653996/what-is-the-difference-between-list-and-iterator-in-python
can help.
Well done :) |