-
Notifications
You must be signed in to change notification settings - Fork 823
Fix reading of lammpsdump ATOM card. #3360
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
Changes from all commits
b7526cb
d45a8f1
aefbaf5
d6e904d
26f5645
b8d42d4
06f109b
417ac61
23b3a50
580b8ae
c59758c
cfccb1a
482dd9b
6b3abbe
f91d55b
c09b1a2
3704dfe
bf85a49
b9497b6
7e8d429
d48e499
268ffa6
df7db87
755daa3
a0256f4
fd5ef5c
4eaf954
fb50a4a
aa9694b
85f39f4
19752e3
f18f0d2
ff58b09
5d8ea3f
ea05796
7ec8a62
238ed90
07eb8fa
0a9e81c
ace0b75
fb0e307
e963e5d
e059410
f3ee49b
fd10657
9450727
893fe04
a78527a
283d0b6
c418caf
bcf3c6e
226dbfc
61886f8
1582d36
1ae6f27
efaa80d
36b1a35
15c073a
6b5cf61
b95fa58
159220f
11376c1
6ba4992
0aa046d
c464b68
1d7497f
11d8518
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -36,7 +36,8 @@ | |
| RefLAMMPSData, RefLAMMPSDataMini, RefLAMMPSDataDCD, | ||
| ) | ||
| from MDAnalysisTests.datafiles import ( | ||
| LAMMPScnt, LAMMPShyd, LAMMPSdata, LAMMPSdata_mini, LAMMPSDUMP | ||
| LAMMPScnt, LAMMPShyd, LAMMPSdata, LAMMPSdata_mini, LAMMPSDUMP, | ||
| LAMMPSDUMP_allcoords, LAMMPSDUMP_nocoords | ||
| ) | ||
|
|
||
|
|
||
|
|
@@ -119,7 +120,7 @@ def test_Writer_dimensions(self, LAMMPSDATAWriter): | |
| assert_almost_equal(u_ref.dimensions, u_new.dimensions, | ||
| err_msg="attributes different after writing", | ||
| decimal=6) | ||
|
|
||
| def test_Writer_atoms_types(self, LAMMPSDATAWriter): | ||
| u_ref, u_new = LAMMPSDATAWriter | ||
| assert_equal(u_ref.atoms.types, u_new.atoms.types, | ||
|
|
@@ -434,7 +435,8 @@ def u(self, tmpdir, request): | |
| with gzip.GzipFile(f, 'wb') as fout: | ||
| fout.write(data) | ||
|
|
||
| yield mda.Universe(f, format='LAMMPSDUMP') | ||
| yield mda.Universe(f, format='LAMMPSDUMP', | ||
| lammps_coordinate_convention="auto") | ||
|
|
||
| @pytest.fixture() | ||
| def reference_positions(self): | ||
|
|
@@ -507,3 +509,119 @@ def test_atom_reordering(self, u, reference_positions): | |
| reference_positions['atom13_pos']): | ||
| assert_almost_equal(atom1.position, atom1_pos, decimal=5) | ||
| assert_almost_equal(atom13.position, atom13_pos, decimal=5) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("convention", | ||
| ["unscaled", "unwrapped", "scaled_unwrapped"]) | ||
| def test_open_absent_convention_fails(convention): | ||
| with pytest.raises(ValueError, match="No coordinates following"): | ||
| mda.Universe(LAMMPSDUMP, format='LAMMPSDUMP', | ||
| lammps_coordinate_convention=convention) | ||
|
|
||
|
|
||
| def test_open_incorrect_convention_fails(): | ||
| with pytest.raises(ValueError, | ||
| match="is not a valid option"): | ||
| mda.Universe(LAMMPSDUMP, format='LAMMPSDUMP', | ||
| lammps_coordinate_convention="42") | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("convention,result", | ||
| [("auto", "unscaled"), ("unscaled", "unscaled"), | ||
| ("scaled", "scaled"), ("unwrapped", "unwrapped"), | ||
| ("scaled_unwrapped", "scaled_unwrapped")]) | ||
| def test_open_all_convention(convention, result): | ||
| u = mda.Universe(LAMMPSDUMP_allcoords, format='LAMMPSDUMP', | ||
| lammps_coordinate_convention=convention) | ||
| assert(u.trajectory.lammps_coordinate_convention == result) | ||
|
|
||
hmacdope marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| def test_no_coordinate_info(): | ||
| with pytest.raises(ValueError, match="No coordinate information detected"): | ||
| u = mda.Universe(LAMMPSDUMP_nocoords, format='LAMMPSDUMP', | ||
| lammps_coordinate_convention="auto") | ||
|
|
||
|
|
||
| class TestCoordinateMatches(object): | ||
| @pytest.fixture() | ||
| def universes(self): | ||
| coordinate_conventions = ["auto", "unscaled", "scaled", "unwrapped", | ||
| "scaled_unwrapped"] | ||
| universes = {i: mda.Universe(LAMMPSDUMP_allcoords, format='LAMMPSDUMP', | ||
| lammps_coordinate_convention=i) | ||
| for i in coordinate_conventions} | ||
| return universes | ||
|
|
||
| @pytest.fixture() | ||
| def reference_unscaled_positions(self): | ||
| # copied from trajectory file | ||
| # atom 340 is the first one in the trajectory so we use that | ||
| atom340_pos1_unscaled = [4.48355, 0.331422, 1.59231] | ||
| atom340_pos2_unscaled = [4.41947, 35.4403, 2.25115] | ||
| atom340_pos3_unscaled = [4.48989, 0.360633, 2.63623] | ||
| return np.asarray([atom340_pos1_unscaled, atom340_pos2_unscaled, | ||
| atom340_pos3_unscaled]) | ||
|
|
||
| def test_unscaled_reference(self, universes, reference_unscaled_positions): | ||
| atom_340 = universes["unscaled"].atoms[339] | ||
| for i, ts_u in enumerate(universes["unscaled"].trajectory[0:3]): | ||
| assert_almost_equal(atom_340.position, | ||
| reference_unscaled_positions[i, :], decimal=5) | ||
|
|
||
| def test_scaled_reference(self, universes, reference_unscaled_positions): | ||
|
Member
Author
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. @richardjgowers @IAlibay question surrounding the accuracy of the
Member
Author
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. Now a separate issue #3361
Member
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. 1 d.p. sounds problematic, you kinda have to try to get that bad a float match 😕
Member
Author
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. Yeah no changes made to |
||
| # NOTE use of unscaled positions here due to S->R transform | ||
| atom_340 = universes["scaled"].atoms[339] | ||
| for i, ts_u in enumerate(universes["scaled"].trajectory[0:3]): | ||
| assert_almost_equal(atom_340.position, | ||
| reference_unscaled_positions[i, :], decimal=1) | ||
| # NOTE this seems a bit inaccurate? | ||
|
|
||
| @pytest.fixture() | ||
| def reference_unwrapped_positions(self): | ||
| # copied from trajectory file | ||
| # atom 340 is the first one in the trajectory so we use that | ||
| atom340_pos1_unwrapped = [4.48355, 35.8378, 1.59231] | ||
| atom340_pos2_unwrapped = [4.41947, 35.4403, 2.25115] | ||
| atom340_pos3_unwrapped = [4.48989, 35.867, 2.63623] | ||
| return np.asarray([atom340_pos1_unwrapped, atom340_pos2_unwrapped, | ||
| atom340_pos3_unwrapped]) | ||
|
|
||
| def test_unwrapped_scaled_reference(self, universes, | ||
| reference_unwrapped_positions): | ||
| atom_340 = universes["unwrapped"].atoms[339] | ||
| for i, ts_u in enumerate(universes["unwrapped"].trajectory[0:3]): | ||
| assert_almost_equal(atom_340.position, | ||
| reference_unwrapped_positions[i, :], decimal=5) | ||
|
|
||
| def test_unwrapped_scaled_reference(self, universes, | ||
| reference_unwrapped_positions): | ||
| # NOTE use of unscaled positions here due to S->R transform | ||
| atom_340 = universes["scaled_unwrapped"].atoms[339] | ||
| for i, ts_u in enumerate( | ||
| universes["scaled_unwrapped"].trajectory[0:3]): | ||
| assert_almost_equal(atom_340.position, | ||
| reference_unwrapped_positions[i, :], decimal=1) | ||
| # NOTE this seems a bit inaccurate? | ||
|
|
||
| def test_scaled_unscaled_match(self, universes): | ||
| assert(len(universes["unscaled"].trajectory) | ||
| == len(universes["scaled"].trajectory)) | ||
| for ts_u, ts_s in zip(universes["unscaled"].trajectory, | ||
| universes["scaled"].trajectory): | ||
| assert_almost_equal(ts_u.positions, ts_s.positions, decimal=1) | ||
| # NOTE this seems a bit inaccurate? | ||
|
|
||
| def test_unwrapped_scaled_unwrapped_match(self, universes): | ||
| assert(len(universes["unwrapped"].trajectory) == | ||
| len(universes["scaled_unwrapped"].trajectory)) | ||
| for ts_u, ts_s in zip(universes["unwrapped"].trajectory, | ||
| universes["scaled_unwrapped"].trajectory): | ||
| assert_almost_equal(ts_u.positions, ts_s.positions, decimal=1) | ||
| # NOTE this seems a bit inaccurate? | ||
|
|
||
| def test_auto_is_unscaled_match(self, universes): | ||
| assert(len(universes["auto"].trajectory) == | ||
| len(universes["unscaled"].trajectory)) | ||
| for ts_a, ts_s in zip(universes["auto"].trajectory, | ||
| universes["unscaled"].trajectory): | ||
| assert_almost_equal(ts_a.positions, ts_s.positions, decimal=5) | ||
Uh oh!
There was an error while loading. Please reload this page.