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

Fix PDBWriter with StringIO for invalid coordinates #2518

Merged
merged 35 commits into from
Feb 11, 2020

Conversation

RMeli
Copy link
Member

@RMeli RMeli commented Feb 9, 2020

Fixes #2512

Changes made in this Pull Request:

  • Ignore TypeError when PDBWriter is trying to remove a StringIO object with invalid coordinates, so that the correct exception can be raised instead.

PR Checklist

  • Tests?
  • CHANGELOG updated?
  • Issue raised/referenced?

RMeli and others added 30 commits August 7, 2019 18:41
@codecov
Copy link

codecov bot commented Feb 9, 2020

Codecov Report

Merging #2518 into develop will not change coverage by %.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff            @@
##           develop    #2518   +/-   ##
========================================
  Coverage    90.41%   90.41%           
========================================
  Files          170      170           
  Lines        23150    23150           
  Branches      2990     2990           
========================================
  Hits         20930    20930           
  Misses        1621     1621           
  Partials       599      599           
Impacted Files Coverage Δ
package/MDAnalysis/analysis/base.py 97.24% <0.00%> (ø) ⬆️
package/MDAnalysis/coordinates/TRZ.py 83.64% <0.00%> (ø) ⬆️
package/MDAnalysis/analysis/lineardensity.py 83.11% <0.00%> (ø) ⬆️
package/MDAnalysis/lib/util.py 88.26% <0.00%> (ø) ⬆️
package/MDAnalysis/analysis/gnm.py 96.06% <0.00%> (ø) ⬆️
package/MDAnalysis/lib/formats/libdcd.pyx 78.96% <0.00%> (ø) ⬆️
package/MDAnalysis/core/topologyobjects.py 97.87% <0.00%> (ø) ⬆️
package/MDAnalysis/analysis/waterdynamics.py 82.72% <0.00%> (ø) ⬆️
package/MDAnalysis/core/groups.py 98.24% <0.00%> (ø) ⬆️
...age/MDAnalysis/analysis/hbonds/hbond_autocorrel.py 87.50% <0.00%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6efe65a...6efe65a. Read the comment docs.

@@ -678,6 +682,10 @@ def _check_pdb_coordinates(self):
except OSError as err:
if err.errno == errno.ENOENT:
pass
except TypeError:
if isinstance(self.filename, StringIO):
pass
Copy link
Contributor

Choose a reason for hiding this comment

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

This is equivalent to

except TypeError:
    pass

Shouldn't it be the following?

except TypeError:
    if isinstance(self.filename, StringIO):
        pass
    else:
        raise

Copy link
Member Author

Choose a reason for hiding this comment

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

Definitely! Thanks for spotting this problem!

Copy link
Member Author

@RMeli RMeli Feb 9, 2020

Choose a reason for hiding this comment

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

The same logic should apply to the previous exception as well, which is suffering from the same problem.

However, this rises a question: should we ignore all the exceptions that can occur while trying os.remove so that the correct exception ValueError (which is the problem triggering os.remove) is thrown instead?

Copy link
Contributor

Choose a reason for hiding this comment

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

We can at least wonder what would be the equivalent of an os.remove on a StringIO. Now, we have an odd discrepancy in behaviour between files and StringIO. Maybe it should be a different issue?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think the equivalent of os.remove for StringIO is just getting out of scope. However, it looks like that calling close() already frees the memory buffer:

StringIO.close()
Free the memory buffer. Attempting to do further operations with a closed StringIO object will raise a ValueError.

Copy link
Contributor

Choose a reason for hiding this comment

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

I guess, then, that the handling is appropriate.

@jbarnoud jbarnoud merged commit abc9049 into MDAnalysis:develop Feb 11, 2020
@RMeli RMeli deleted the issues/#2512-stringio branch February 11, 2020 17:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

PDBWriter incompatible with StringIO if atom coordinates go out of range
4 participants