Skip to content
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

Merged
merged 4 commits into from
Jun 29, 2023

Conversation

nathanjohnsongithub
Copy link
Contributor

  • 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.

@nathanjohnsongithub nathanjohnsongithub changed the title Nathans branch Program no longer assumes where integrals start in fcidump Jun 21, 2023
@TApplencourt
Copy link
Collaborator

Didn't i Have already merged this?

@seanr7
Copy link
Contributor

seanr7 commented Jun 23, 2023

Didn't i Have already merged this?

This has some new changes in the io.py file, I think

@nathanjohnsongithub
Copy link
Contributor Author

Yes, I added things to the io.py file

qe/io.py Outdated
Comment on lines 64 to 74
# 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
Copy link
Collaborator

@TApplencourt TApplencourt Jun 23, 2023

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))
Copy link
Contributor Author

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.

Copy link
Collaborator

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.

@TApplencourt TApplencourt merged commit 145299d into Exa-sCI:clean Jun 29, 2023
@TApplencourt
Copy link
Collaborator

Well done :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants