Skip to content

Commit

Permalink
LAMMPS support for chainreader (#4170)
Browse files Browse the repository at this point in the history
* Generalize continuous check

* Bug fix parent method and chain implementation

* Update changelog and docs

* Update error output string

* Bug fix parenthesis

* Bug fix parent method and chain implementation

* Update changelog and docs

* simplify fix

* Address small reviewer comments

* Add test for consistent, expected time between frames

* Add check for timesteps
  • Loading branch information
jaclark5 authored Jun 26, 2023
1 parent c87a3cd commit b943ca0
Show file tree
Hide file tree
Showing 8 changed files with 477 additions and 3 deletions.
3 changes: 3 additions & 0 deletions package/CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@ Fixes
(PR #4163, Issue #4159)

Enhancements
* LAMMPSDump Reader use of `continuous` option to stitch trajectories
(Issue #3546)

Changes
* Add definition of ts.data['time'] in LAMMPSDump Reader (Issue #3546)
* As per NEP29 the minimum supported version has been raised to 1.22. We
have opted to pin to a minimum of 1.22.3 to avoid known issues on some
platforms.
Expand Down
1 change: 1 addition & 0 deletions package/MDAnalysis/coordinates/LAMMPS.py
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,7 @@ def _read_next_timestep(self):
f.readline() # ITEM TIMESTEP
step_num = int(f.readline())
ts.data['step'] = step_num
ts.data['time'] = step_num * ts.dt

f.readline() # ITEM NUMBER OF ATOMS
n_atoms = int(f.readline())
Expand Down
4 changes: 2 additions & 2 deletions package/MDAnalysis/coordinates/chain.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ class ChainReader(base.ReaderBase):
what frames are used with the continuous option.
The default chainreader will read all frames. The continuous option is
currently only supported for XTC and TRR files.
currently only supported for XTC, TRR, and LAMMPSDUMP files.
Notes
-----
Expand Down Expand Up @@ -299,7 +299,7 @@ def __init__(self, filenames, skip=1, dt=None, continuous=False,

# calculate new start_frames to have a time continuous trajectory.
if continuous:
check_allowed_filetypes(self.readers, ['XTC', 'TRR'])
check_allowed_filetypes(self.readers, ['XTC', 'TRR', "LAMMPSDUMP"])
if np.any(np.array(n_frames) == 1):
raise RuntimeError("ChainReader: Need at least two frames in "
"every trajectory with continuous=True")
Expand Down
16 changes: 15 additions & 1 deletion testsuite/MDAnalysisTests/coordinates/test_chainreader.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@
import MDAnalysis as mda
from MDAnalysis.transformations import translate
from MDAnalysisTests.datafiles import (PDB, PSF, CRD, DCD,
GRO, XTC, TRR, PDB_small, PDB_closed)
GRO, XTC, TRR, PDB_small, PDB_closed,
LAMMPS_chain, LAMMPSDUMP_chain1,
LAMMPSDUMP_chain2,)
from MDAnalysisTests.util import no_warning


Expand Down Expand Up @@ -206,6 +208,18 @@ def test_set_all_format_tuples(self):
assert universe.trajectory.n_frames == 21
assert_equal(universe.trajectory.filenames, [PDB, XTC, TRR])

def test_set_all_format_lammps(self):
universe = mda.Universe(
LAMMPS_chain, [LAMMPSDUMP_chain1, LAMMPSDUMP_chain2],
format="LAMMPSDUMP", continuous=True)
assert universe.trajectory.n_frames == 11

# Test whether the amount of time between frames is consistently = 1
time_values = np.array([ts.time for ts in universe.trajectory])
dt_array = time_values[1:]-time_values[:-1]
assert np.unique(dt_array) == 1
assert_equal(time_values, np.arange(11))

def test_set_format_tuples_and_format(self):
universe = mda.Universe(GRO, [(PDB, 'pdb'), GRO, GRO, (XTC, 'xtc'),
(TRR, 'trr')], format='gro')
Expand Down
186 changes: 186 additions & 0 deletions testsuite/MDAnalysisTests/data/lammps/chain_dump_1.lammpstrj
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
ITEM: TIMESTEP
0
ITEM: NUMBER OF ATOMS
22
ITEM: BOX BOUNDS pp pp pp
0.0000000000000000e+00 1.0000000000000000e+01
0.0000000000000000e+00 1.0000000000000000e+01
0.0000000000000000e+00 1.0000000000000000e+01
ITEM: ATOMS id mol type q xu yu zu
4 0 2 0 5.88374 3.41791 0.249243
10 0 2 0 5.19702 4.14267 2.35373
13 0 2 0 3.42556 5.80345 1.03172
16 0 2 0 0.0624761 8.72482 0.313035
22 0 2 0 1.59082 3.31475 4.97774
11 0 2 0 3.42477 4.70658 3.66179
1 0 1 0 5.19899 5.00015 5.48947
2 0 1 0 4.97794 4.97944 4.51567
14 0 2 0 6.62547 4.95874 6.02809
19 0 2 0 7.08926 4.30542 5.23948
20 0 2 0 7.0361 5.90606 5.4861
15 0 2 0 4.22366 9.62949 5.40626
21 0 2 0 4.17191 8.57808 5.01616
6 0 2 0 8.27587 8.45465 4.67567
18 0 2 0 1.26168 1.6929 8.0355
3 0 2 0 3.45325 5.51395 8.67997
9 0 2 0 5.19513 5.29517 8.55806
5 0 2 0 6.55796 3.99289 9.54127
7 0 2 0 7.62242 6.3979 9.73197
8 0 2 0 6.88523 4.51143 6.98553
17 0 2 0 9.17665 6.50396 7.07893
12 0 2 0 7.07863 9.62566 7.36101
ITEM: TIMESTEP
1
ITEM: NUMBER OF ATOMS
22
ITEM: BOX BOUNDS pp pp pp
0.0000000000000000e+00 1.0000000000000000e+01
0.0000000000000000e+00 1.0000000000000000e+01
0.0000000000000000e+00 1.0000000000000000e+01
ITEM: ATOMS id mol type q xu yu zu
4 0 2 0 5.87099 3.41767 0.251237
10 0 2 0 5.17103 4.14373 2.36815
13 0 2 0 3.43361 5.81743 1.05571
16 0 2 0 0.0513171 8.713 0.28804
22 0 2 0 1.5998 3.31559 4.97326
11 0 2 0 3.42282 4.70176 3.65073
1 0 1 0 5.20676 4.99743 5.47086
2 0 1 0 4.9757 4.97824 4.51385
14 0 2 0 6.6219 4.99337 6.05337
19 0 2 0 7.12985 4.31467 5.24475
20 0 2 0 7.03647 5.90326 5.48498
15 0 2 0 4.22247 9.64286 5.3867
21 0 2 0 4.17371 8.58414 5.00718
6 0 2 0 8.25895 8.45456 4.65529
18 0 2 0 1.24399 1.69158 8.02878
3 0 2 0 3.44983 5.48966 8.7051
9 0 2 0 5.18181 5.2815 8.56656
5 0 2 0 6.56395 3.97275 9.5395
7 0 2 0 7.61969 6.40413 9.72323
8 0 2 0 6.88059 4.52138 6.98398
17 0 2 0 9.19784 6.49329 7.08897
12 0 2 0 7.1015 9.62409 7.37619
ITEM: TIMESTEP
2
ITEM: NUMBER OF ATOMS
22
ITEM: BOX BOUNDS pp pp pp
0.0000000000000000e+00 1.0000000000000000e+01
0.0000000000000000e+00 1.0000000000000000e+01
0.0000000000000000e+00 1.0000000000000000e+01
ITEM: ATOMS id mol type q xu yu zu
4 0 2 0 5.85828 3.41747 0.253186
10 0 2 0 5.14503 4.14478 2.38259
13 0 2 0 3.44167 5.83141 1.07969
16 0 2 0 0.0401567 8.70118 0.263043
22 0 2 0 1.60879 3.31643 4.96878
11 0 2 0 3.4209 4.69695 3.63969
1 0 1 0 5.21537 4.99476 5.45525
2 0 1 0 4.97272 4.97698 4.50903
14 0 2 0 6.61824 5.02819 6.07806
19 0 2 0 7.17033 4.32411 5.2502
20 0 2 0 7.03677 5.90027 5.48392
15 0 2 0 4.22129 9.65621 5.36713
21 0 2 0 4.17552 8.59021 4.9982
6 0 2 0 8.24203 8.45447 4.63492
18 0 2 0 1.2263 1.69026 8.02205
3 0 2 0 3.44645 5.46536 8.73023
9 0 2 0 5.16846 5.26782 8.57506
5 0 2 0 6.56988 3.95258 9.53777
7 0 2 0 7.61696 6.41036 9.71449
8 0 2 0 6.87604 4.53115 6.98274
17 0 2 0 9.21902 6.48262 7.09901
12 0 2 0 7.12436 9.62251 7.39137
ITEM: TIMESTEP
3
ITEM: NUMBER OF ATOMS
22
ITEM: BOX BOUNDS pp pp pp
0.0000000000000000e+00 1.0000000000000000e+01
0.0000000000000000e+00 1.0000000000000000e+01
0.0000000000000000e+00 1.0000000000000000e+01
ITEM: ATOMS id mol type q xu yu zu
4 0 2 0 5.84563 3.41731 0.255081
10 0 2 0 5.11902 4.14585 2.39703
13 0 2 0 3.44973 5.8454 1.10368
16 0 2 0 0.0289914 8.68935 0.238036
22 0 2 0 1.61778 3.31727 4.9643
11 0 2 0 3.41903 4.69215 3.62866
1 0 1 0 5.22524 4.99218 5.44415
2 0 1 0 4.96857 4.97562 4.49975
14 0 2 0 6.61446 5.06321 6.10201
19 0 2 0 7.21069 4.33378 5.25586
20 0 2 0 7.03704 5.89714 5.48289
15 0 2 0 4.2201 9.66953 5.34754
21 0 2 0 4.17732 8.59631 4.98923
6 0 2 0 8.2251 8.45438 4.61454
18 0 2 0 1.2086 1.68893 8.01533
3 0 2 0 3.44311 5.44105 8.75537
9 0 2 0 5.15508 5.25413 8.58357
5 0 2 0 6.57575 3.93237 9.53609
7 0 2 0 7.61422 6.41659 9.70575
8 0 2 0 6.87164 4.54066 6.98195
17 0 2 0 9.24021 6.47194 7.10905
12 0 2 0 7.14724 9.62094 7.40656
ITEM: TIMESTEP
4
ITEM: NUMBER OF ATOMS
22
ITEM: BOX BOUNDS pp pp pp
0.0000000000000000e+00 1.0000000000000000e+01
0.0000000000000000e+00 1.0000000000000000e+01
0.0000000000000000e+00 1.0000000000000000e+01
ITEM: ATOMS id mol type q xu yu zu
4 0 2 0 5.83303 3.41722 0.256909
10 0 2 0 5.09298 4.14692 2.4115
13 0 2 0 3.4578 5.85939 1.12768
16 0 2 0 0.0178158 8.67751 0.213006
22 0 2 0 1.62678 3.31812 4.95981
11 0 2 0 3.4172 4.68734 3.61764
1 0 1 0 5.23636 4.98968 5.43716
2 0 1 0 4.9633 4.97418 4.48634
14 0 2 0 6.61052 5.09848 6.12517
19 0 2 0 7.25094 4.34369 5.26174
20 0 2 0 7.0373 5.89391 5.48185
15 0 2 0 4.21891 9.68281 5.32792
21 0 2 0 4.17913 8.60247 4.98027
6 0 2 0 8.20816 8.45428 4.59414
18 0 2 0 1.19088 1.68761 8.0086
3 0 2 0 3.43982 5.41671 8.78054
9 0 2 0 5.14164 5.24043 8.59209
5 0 2 0 6.58155 3.9121 9.53447
7 0 2 0 7.61148 6.42282 9.69699
8 0 2 0 6.86741 4.54983 6.98173
17 0 2 0 9.26141 6.46124 7.1191
12 0 2 0 7.17014 9.61936 7.42176
ITEM: TIMESTEP
5
ITEM: NUMBER OF ATOMS
22
ITEM: BOX BOUNDS pp pp pp
0.0000000000000000e+00 1.0000000000000000e+01
0.0000000000000000e+00 1.0000000000000000e+01
0.0000000000000000e+00 1.0000000000000000e+01
ITEM: ATOMS id mol type q xu yu zu
4 0 2 0 5.82049 3.41718 0.258662
10 0 2 0 5.06689 4.148 2.42599
13 0 2 0 3.46588 5.87339 1.15172
16 0 2 0 0.00662379 8.66565 0.187939
22 0 2 0 1.63579 3.31896 4.95531
11 0 2 0 3.41541 4.68252 3.60661
1 0 1 0 5.2482 4.98721 5.43226
2 0 1 0 4.9574 4.9727 4.47085
14 0 2 0 6.60634 5.13405 6.14753
19 0 2 0 7.29111 4.35383 5.26782
20 0 2 0 7.03759 5.89064 5.48076
15 0 2 0 4.21772 9.69606 5.30825
21 0 2 0 4.18095 8.6087 4.97131
6 0 2 0 8.19119 8.45419 4.57372
18 0 2 0 1.17314 1.68628 8.00186
3 0 2 0 3.43657 5.39233 8.80574
9 0 2 0 5.12815 5.2267 8.60064
5 0 2 0 6.58727 3.89175 9.53293
7 0 2 0 7.60873 6.42905 9.68822
8 0 2 0 6.86339 4.55856 6.98215
17 0 2 0 9.28264 6.45054 7.12917
12 0 2 0 7.19307 9.61778 7.43698
Loading

0 comments on commit b943ca0

Please sign in to comment.