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

Fixed bug on parsing coordinates of WFs when there is no space #21

Merged
merged 2 commits into from
Feb 5, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 20 additions & 7 deletions aiida_wannier90/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,14 +208,27 @@ def raw_wout_parser(wann_out_file):
wf_out_i['wannier_function'] = int(
line.split('(')[0].split()[-1]
)
wf_out_i['spread'] = float(line.split('(')[1].split()[-1])
wf_out_i['spread'] = float(line.split(')')[1].strip())
#wf_out_i['spread'] = float(line.split()[-1])
#x = float(line.split()[-5].strip(','))
#y = float(line.split()[-4].strip(','))
#z = float(line.split()[-3].strip(','))
x = float(line.split('(')[1].split()[0].strip(','))
y = float(line.split('(')[1].split()[1].strip(','))
z = float(line.split('(')[1].split()[2].strip(','))
try:
x = float(
line.split('(')[1].split(')')[0].split(',')[0].strip()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the final .strip() actually necessary? I think the float constructor is happy to accept string with leading or trailing whitespace.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are probably right, I wanted to be sure :-)

)
except (ValueError, IndexError):
# To avoid that the crasher completely fails, we set None as a fallback
x = None
try:
y = float(
line.split('(')[1].split(')')[0].split(',')[1].strip()
)
except (ValueError, IndexError):
y = None
try:
z = float(
line.split('(')[1].split(')')[0].split(',')[2].strip()
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we could de-duplicate the line.split('(')[1].split(')')[0].split(',') part:

Maybe something like the following?

x, y, z = (
    float(val) for val in 
    line.split('(')[1].split(')')[0].split(',')
)

Or is there a case where one of the coordinates could fail, but not the others?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is unfortunately, when ******* is printed. We will need anyway at some point to change Wannier90 to print what we need in a csv file or similar as discussed in #1

except (ValueError, IndexError):
z = None
coord = (x, y, z)
wf_out_i['coordinates'] = coord
wf_out.append(wf_out_i)
Expand Down