-
Notifications
You must be signed in to change notification settings - Fork 661
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
Pathlib object handling for Universe, SingleFrameReaderBase and Toplogy parsers (Issue #3937) #4535
Open
talagayev
wants to merge
18
commits into
MDAnalysis:develop
Choose a base branch
from
talagayev:singleframereader_pathlib
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
0dbca13
addition of tests for str and pathlib handling of SingleFrameReaderBa…
talagayev c2c7c2c
renamed tests to specify GRO input as testcase
talagayev 05ea8de
Added testcase of LAMMPS str and pathlib handling in class SingleFram…
talagayev 5c0383c
Update AUTHORS list
talagayev 9a4932b
Update CHANGELOG
talagayev ff2a832
Adjusting blank lines for PEP8
talagayev d85defc
adjsuting blank lines for PEP8
talagayev 87f7a95
removed singleframereader test in test_gro.py
talagayev 27e9685
removed singleframe_reader test in test_lammps.py
talagayev 567e6ef
added test for str and path input for singleframereader in base.py
talagayev 5558dda
Added Baseframe test for singleframes str and path input in base.py
talagayev 2953310
Merge pull request #2 from talagayev/talagayev-patch-1_singleframe
talagayev c181021
Merge branch 'develop' into singleframereader_pathlib
talagayev e06ae55
add pathlib checking to topology and universe
hmacdope 0aa40cc
add test for topology Pathlib and fix changelog
hmacdope 5dafd01
fix spacing chaneg in AUTHORS
hmacdope 33d6b4e
Merge branch 'develop' into singleframereader_pathlib
orbeckst f785eea
Merge branch 'develop' into singleframereader_pathlib
orbeckst File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,12 +25,14 @@ | |
|
||
import numpy as np | ||
import pytest | ||
from pathlib import Path | ||
from unittest import TestCase | ||
from numpy.testing import (assert_equal, assert_almost_equal, | ||
assert_array_almost_equal, assert_allclose) | ||
|
||
import MDAnalysis as mda | ||
from MDAnalysis.coordinates.timestep import Timestep | ||
from MDAnalysis.coordinates.memory import MemoryReader | ||
from MDAnalysis.transformations import translate | ||
|
||
|
||
|
@@ -134,6 +136,12 @@ def test_pickle_singleframe_reader(self): | |
assert_equal(reader.ts, reader_p.ts, | ||
"Modification of ts not preserved after serialization") | ||
|
||
def test_pathlib_input_single(self): | ||
path = Path(self.filename) | ||
u_str = mda.Universe(self.filename) | ||
u_path = mda.Universe(path) | ||
assert u_str.atoms.n_atoms == u_path.atoms.n_atoms | ||
|
||
|
||
class BaseReference(object): | ||
def __init__(self): | ||
|
@@ -537,6 +545,16 @@ def test_timeseries_atomgroup_asel_mutex(self, reader): | |
atoms = mda.Universe(reader.filename, to_guess=()).select_atoms("index 1") | ||
with pytest.raises(ValueError, match="Cannot provide both"): | ||
timeseries = reader.timeseries(atomgroup=atoms, asel=atoms, order='fac') | ||
|
||
def test_pathlib_input_base(self, reader): | ||
if isinstance(reader, MemoryReader): | ||
if isinstance(reader, MemoryReader): | ||
skip_reason = "MemoryReader" | ||
pytest.skip(f"Skipping test for Pathlib input with reason: {skip_reason}") | ||
path = Path(reader.filename) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here adding an additional Line: Fixes the following Failed Pytest in 4 cases: |
||
u_str = mda.Universe(reader.filename) | ||
u_path = mda.Universe(path) | ||
assert u_str.atoms.n_atoms == u_path.atoms.n_atoms | ||
|
||
|
||
class MultiframeReaderTest(BaseReaderTest): | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,7 +46,6 @@ | |
assert_equal, | ||
) | ||
import pytest | ||
from io import StringIO | ||
|
||
|
||
class TestGROReaderOld(RefAdK): | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Here errors if we use
self.filename = str(filename)
in thetest_mmtf.py
The lead to errors similar to this one:
FileNotFoundError: [Errno 2] No such file or directory: '<mmtf.api.mmtf_reader.MMTFDecoder object at 0x135416780>'
I managed to fix the error by adding:
else:
self.filename = str(filename)
if "MMTF" in self.filename:
self.filename = filename
basically putting a specific condition for MMTF cases, not the cleanest approach, but maybe this helps @hmacdope fixing the error in a better way :)
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.
I tried to look more into it now, the
"MMTF"
is a specific case, the other errors appear mainly because of the parmed parser which has both problems with thebase.py
in thecoordinates
andtopology
. It is possible to use in thebase.py
in thecoordinates
:elif hasattr(filename, 'topology'):
self.filename = filename
This helps to fix the errors, although it is quite similar as to just directly using
self.filename = filename
without anyif/elif/else
conditions. For thebase.py
intopology
I will try to figure out if there is any option to fix it, since again having there onlyself.filename = filename
also fixes the errors with theparmed
parserThere 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.
@talagayev I think the
FileNotFoundError
for mmtf above is because instead of a filename, sometimes a MMTFDecoder object is encountered. I think what you've got is fixing it, but it might be clearer to have a block like:Where you've enumerated all the special cases explicitly in each
elif
branch, rather than hiding some special cases inside other branchesThere 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.
Ah I see, yes the option that I got worked, but was definitely not the best option, but yes was connected with mmtf and yes
elif 'mmtf' in str(filename.__class__):
looks much better :)