Skip to content

Commit f374de1

Browse files
committed
DCDwriter now has a option to set istart
Programs who use DCD have different conventions for istart, the starting frame of the trajectory. Because of this we now allow it to be set by the user.
1 parent d082cea commit f374de1

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

package/MDAnalysis/coordinates/DCD.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,7 @@ def __init__(self,
358358
dt=1,
359359
remarks='',
360360
nsavc=1,
361+
istart=0,
361362
**kwargs):
362363
"""Parameters
363364
----------
@@ -380,6 +381,8 @@ def __init__(self,
380381
how many MD steps is a frame saved to the DCD). By default, this
381382
number is just set to one and this should be sufficient for almost
382383
all cases but if required, nsavc can be changed.
384+
istart : int (optional)
385+
starting frame number. CHARMM defaults to 1.
383386
**kwargs : dict
384387
General writer arguments
385388
@@ -400,7 +403,7 @@ def __init__(self,
400403
nsavc=nsavc,
401404
delta=delta,
402405
is_periodic=1,
403-
istart=0)
406+
istart=istart)
404407

405408
def write_next_timestep(self, ts):
406409
"""Write timestep object into trajectory.

testsuite/MDAnalysisTests/coordinates/test_dcd.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,16 @@ def test_writer_trajectory_no_natoms(tmpdir, universe_dcd):
284284
universe_dcd.trajectory.Writer("foo.dcd")
285285

286286

287+
@pytest.mark.parametrize('istart', (0, 1, 2, 3))
288+
def test_write_istart(universe_dcd, tmpdir, istart):
289+
u = universe_dcd
290+
outfile = str(tmpdir.join('test.dcd'))
291+
with mda.Writer(outfile, u.atoms.n_atoms, istart=istart) as w:
292+
w.write(u.atoms)
293+
u = mda.Universe(PSF, outfile)
294+
assert u.trajectory._file.header['istart'] == istart
295+
296+
287297
class RefCHARMMtriclinicDCD(object):
288298
topology = PSF_TRICLINIC
289299
trajectory = DCD_TRICLINIC

0 commit comments

Comments
 (0)