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

different atom number error message #2219

Merged
merged 4 commits into from
Apr 6, 2019
Merged

different atom number error message #2219

merged 4 commits into from
Apr 6, 2019

Conversation

Yibo-Zhang
Copy link
Contributor

@Yibo-Zhang Yibo-Zhang commented Mar 16, 2019

Fixes #1998

Changes made in this Pull Request:

  • move the 'check if atom number changed' above conversion part. It will give the clear error message when atom numbers are different.

PR Checklist

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

@richardjgowers
Copy link
Member

Not sure why appveyor failed, ignore that. Can you check that there’s a test for a pdb file with varying atoms per frame? Should be in one of the test_pdb.py files

@Yibo-Zhang
Copy link
Contributor Author

Hi @richardjgowers , pytest test_pdb.py, it did not show errors related to the varing atoms per frame.

Copy link
Member

@zemanj zemanj left a comment

Choose a reason for hiding this comment

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

Error message needs to be improved and, as @richardjgowers already mentioned, tests are needed as well.

@@ -393,15 +393,16 @@ def _read_frame(self, frame):
line[24:33], line[33:40],
line[40:47], line[47:54]]

# doing the conversion from list to array at the end is faster
self.ts.positions = tmp_buf

# check if atom number changed
if pos != self.n_atoms:
raise ValueError("Read an incorrect number of atoms\n"
Copy link
Member

@zemanj zemanj Mar 18, 2019

Choose a reason for hiding this comment

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

The error message is still somewhat misleading. In fact, the number of atoms read is correct, and reading has nothing to do with the error. Also, the number of atoms read from the trajectory frame reported in the error message seems to be wrong (pos+1 instead of pos). I'd suggest changing the error to

...
        if pos != self.n_atoms:
            raise ValueError("Inconsistency in file '{}': The number of atoms "
                             "({}) in trajectory frame {} differs from the "
                             "number of atoms ({}) in the corresponding "
                             "topology.\nTrajectories with varying numbers of "
                             "atoms are currently not supported."
                             "".format(self.filename, pos, frame, self.n_atoms)

@codecov
Copy link

codecov bot commented Mar 18, 2019

Codecov Report

Merging #2219 into develop will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #2219      +/-   ##
===========================================
+ Coverage    89.57%   89.58%   +<.01%     
===========================================
  Files          158      158              
  Lines        19724    19687      -37     
  Branches      2780     2769      -11     
===========================================
- Hits         17668    17636      -32     
+ Misses        1460     1457       -3     
+ Partials       596      594       -2
Impacted Files Coverage Δ
package/MDAnalysis/coordinates/PDB.py 90.54% <100%> (+0.6%) ⬆️
package/MDAnalysis/topology/PSFParser.py 85.21% <0%> (-2.61%) ⬇️
package/MDAnalysis/analysis/waterdynamics.py 81.13% <0%> (-1.56%) ⬇️
util.py 88.14% <0%> (-0.02%) ⬇️
package/MDAnalysis/core/groups.py 98.26% <0%> (ø) ⬆️
package/MDAnalysis/lib/util.py 88.46% <0%> (+0.13%) ⬆️
package/MDAnalysis/core/universe.py 94.98% <0%> (+0.55%) ⬆️
package/MDAnalysis/analysis/nuclinfo.py 92.25% <0%> (+2.11%) ⬆️

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 668e183...3d554a9. Read the comment docs.

@Yibo-Zhang
Copy link
Contributor Author

Hi @zemanj . Thanks for your suggestion. I looked through the test_PDB file and not find the test I need. So I try to write one like

    def test_atom_not_match(self):
        from MDAnalysis.coordinates.PDB import PDBReader
        reader = PDBReader(PDB_singleframe)
        with pytest.raises(ValueError) as excinfo:
            reader._read_frame(0)
        assert 'Inconsistency in file' in str(excinfo.value)

However, I do not know how to make the ValueError happen. Also when I try to give PDBReader a n_atoms parameter, it report indexerror, is there a test file that contain different atom number, that I can use to test it. Or maybe I'm totally wrong about this thing.

@richardjgowers
Copy link
Member

Hey @Yibo-Zhang , the problem here is you need to trigger the error with the file you use in the test. The file you're currently using has nothing wrong with it, so you never check the piece of code you've modified. Instead, if you give it a pdb file where the number of atoms changes between frames, you can test that you get the expected behaviour (ie a ValueError with a useful error message).

Inside test_pdb there's some examples of using StringIO to create special pdb files that trigger certain conditions, you should be able to make a varying-atom pdb file with the same method.

@Yibo-Zhang
Copy link
Contributor Author

Hey @richardjgowers , I added the test for the changed part, and it works. Can you have a quick review. Thanks

Copy link
Member

@orbeckst orbeckst left a comment

Choose a reason for hiding this comment

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

Looks good to me.

@richardjgowers and @zemanj do you want to have a quick look?

@orbeckst
Copy link
Member

orbeckst commented Apr 2, 2019

@Yibo-Zhang please also

  • add your name to AUTHORS
  • add an entry to CHANGELOG (under Fixes)

@orbeckst
Copy link
Member

orbeckst commented Apr 5, 2019

@Yibo-Zhang if you want this to get merged soon please add yourself to AUTHORS and add an entry to CHANGELOG #2219 (comment)

@zemanj please check if your comments have been addressed, your approval is missing. Thanks.

@Yibo-Zhang
Copy link
Contributor Author

hey @orbeckst I added that two parts, thanks. I'm so happy that I can add my name at authors list.

@zemanj
Copy link
Member

zemanj commented Apr 6, 2019

Conflicts need to be resolved, otherwise this looks really good!

@orbeckst orbeckst self-assigned this Apr 6, 2019
@orbeckst orbeckst merged commit 3f7f633 into MDAnalysis:develop Apr 6, 2019
@orbeckst
Copy link
Member

orbeckst commented Apr 6, 2019

Congratulations @Yibo-Zhang , your first PR has been merged, thank you for your contribution. I hope more will follow!

IAlibay added a commit that referenced this pull request Dec 18, 2023
orbeckst added a commit that referenced this pull request Dec 21, 2023
Update of AUTHORS and CHANGELOG with inferred author contributions.

*  Removed duplicate mattwthompson in 0.20.0 changelog entry.: mattwthompson was placed twice by accident, this removes this duplication.

* Addition of missing authors.

   An retrospective analysis of the authors found via `git shortlog -s -n --email --branches="develop"` found several commits by authors which were not present in the `AUTHORS.md` file.

    - Zhenbo Li: commited via PR: Started tests for gnm. #803 and Make Travis run tests on OSX. #771,
    - Jenna M. Swarthout via PR Update CoC according to suggestions from current CoC committee #4289 and Point to new reporting form link (owned by [email protected]) #4298,
    - Bradley Dice via PR   Fix GSD Windows compatibility #2384 ,
    - David Minh via PR #2668

   There seemed to be no indications in the above mentioned PRs that the author did not want to be in the authors file, it looks like it was just forgotten.

* Addition of missing entries from the changelog

   Continued cross referencing of the git shortlog output but also accounting for the changelog identified several individuals that had not been included in the changelog entries for the release they contributed under. They were added to the relevant entry of the changelog based on the merge commit date.

   Please note that for Tone Bengsten, we a) had no github handle (so they were assigned @tbengtsen), and b) no specific commit. Given we know that this individual was including alongside the encore merge, they were assigned to the 0.16.0 release.

* Update CHANGELOG
* PR #1218
* PR #1284 and #1408
* PR #4109
* based on git history
* PRs #803 and #771 (author addition, changelog addition)
* PR #2255 and #2221
* PR #1225
* PR #4289 and #4298
* PR #4031
* PR #4085
* PR #3635
* PR #2356
* PR #2559
* No GH handle - Encore author addition @tbengtsen
* PR #4184
* PR #2614
* PR #2219
* PR #2384
* PR #2668
* Add missing entry for Jenna

Thanks to @fiona-naughton for helping out with digging into this data :)

Co-authored-by: Fiona Naughton <[email protected]>
Co-authored-by: Oliver Beckstein <[email protected]>
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.

4 participants