Skip to content

Conversation

@orbeckst
Copy link
Member

@orbeckst orbeckst commented Mar 15, 2018

Fixes #1819

Changes made in this Pull Request:

  • add native NAMD 2.10 test DCD trajectory with PSF
  • add tests
  • add fix

PR Checklist

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

@orbeckst
Copy link
Member Author

I added tests and the fix; some of the other tests are failing now: need to look at them in more detail and check if the reference needs to be changed or code logic somewhere.

Help welcome.

"""convert a dcd-frame to a :class:`TimeStep`"""
ts.frame = self._frame
ts.time = (ts.frame + self._file.header['istart']) * self.ts.dt
ts.time = (ts.frame + self._file.header['istart']/self._file.header['nsavc']) * self.ts.dt
Copy link
Member

Choose a reason for hiding this comment

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

I thought there where more places where we need changes. I'm pretty sure the writer needs to be updated too.

Copy link
Member Author

Choose a reason for hiding this comment

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

I am pretty sure that you're right... I just committed what I had before falling asleep.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think I fixed all occurences of istart/nsavc in the reader and writer. I also added a test for the writer to check the defaults that we are setting. Namely, istart=0 is not what CHARMM would do: it would set it to nsavc which is what MDAnalysis now does for istart=None. However, I kept the MDAnalysis value (which we had for a while) as the default.

@orbeckst
Copy link
Member Author

#1830 needs to be fixed before the tests will be useful

@kain88-de
Copy link
Member

you can rebase. We already applied a band aid. The fix for #1830 needs some more time

@orbeckst
Copy link
Member Author

ok

@orbeckst orbeckst force-pushed the issue-1819-dcd-istart branch 2 times, most recently from 9fd0736 to 29f89f5 Compare March 18, 2018 07:13
@pytest.fixture()
def correct_values(self):
return [[0, 1000, 0], [49, 1049, 4.68953]]
return [[0, 1, 0], [49, 50, 4.68953]]
Copy link
Member

Choose a reason for hiding this comment

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

@orbeckst this makes the tests pass. I'm unsure why we have to adjust the step by 1 position now.

Copy link
Member Author

Choose a reason for hiding this comment

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

Do you mean, adjusting the step by 1 position instead of 1000? The reason for this is that istart is measured in integrator time steps. 1 frame contains nsavc integrator time steps. If a DCD wants to state that the trajectory starts "at frame 1" then it has to set istart = nsavc. In 0.17.0 we wrongly interpreted istart as frames instead of integrator time steps.

If your question is "why do our test DCDs now have a starting time "at frame 1", e.g.

>>> import MDAnalysis as mda
... from MDAnalysisTests.datafiles import PSF, DCD, DCD_NAMD_GBIS, PSF_NAMD_GBIS, TPR, XTC
...
>>> # DCD time starts at 1*dt
>>> u = mda.Universe(PSF, DCD)
>>> print(u.trajectory.frame, u.trajectory.time, u.trajectory.n_frames, u.trajectory.totaltime)
0 0.9999999119200186 98 96.9999914562418
>>> u = mda.Universe(PSF_NAMD_GBIS, DCD_NAMD_GBIS)
>>> print(u.trajectory.frame, u.trajectory.time, u.trajectory.n_frames, u.trajectory.totaltime)
0 0.010000000029814058 100 0.9900000029515917
>>> # XTC starts at 0*dt
>>> u = mda.Universe(TPR, XTC)
>>> print(u.trajectory.frame, u.trajectory.time, u.trajectory.n_frames, u.trajectory.totaltime)
0 0.0 10 900.0000686645508

then the answer is because this is how we interpret the meaning of istart at the moment: as an offset of istart/nsavc frames from 0 (based on the docs that I cited in #1819). I am admittedly not 100% sure if this is the best way to do this; it seems to imply that the starting frame is not saved in a trajectory and the first frame that was saved would be the one istart integrator time steps after the begin of the simulation. The CHARMM docs (Example under TRAJECTORY command) imply that the DYNAmics command does indeed start saving after the coordinates with the initial conditions:

Example. Assume that the three files traj1.trj, traj2.trj and traj3.trj were created using the following dyanmics commands:
dyna start nstep 1000 nsavc 100 ! saves 10 frames (100, 200, ...1000)
dyna restart nstep 10000 nsavc 100 ! saves 100 frames (1100, 1200, ...10100)
dyna restart nstep 10000 nsavc 100 ! saves 100 frames (10200, 10300, ...20100)

I might have to play around with the CHARMM TRAJectory command to get a better idea of what CHARMM really thinks of a trajectory.

However, I'd like to fix istart first (which is clearly wrong) and then discuss what is more of a discussion about how to interpret quirks in the DCD format and how to make it work seamlessly in MDAnalysis.

Copy link
Member

@kain88-de kain88-de Mar 18, 2018

Choose a reason for hiding this comment

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

The change of 1000 to 1 is OK. We made this change in the current development cycle. I'm curious why we needed to change from step 49 to 50. My first try to fix the istart behavior was in #1767. The change in the iteration introduced by your changes is new to this pr. Because such a change would break user code I'm hesitant to merge this.

There are some NAMD experts in my group. I will ask them what behavior is best for them.

Copy link
Member Author

Choose a reason for hiding this comment

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

Can you explain with a simple example what the change "from 49 to 50" means?

Copy link
Member Author

Choose a reason for hiding this comment

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

I quickly browsed through the discussion in #1767. The choice istart=1 is now istart=None or manually setting istart=nsavc. Setting istart=0 as the default for the writer is retained.

If we wanted to make clearer that we want the user to be able to set frame offsets then we should introduce something like frame_offset. We already have offset for the Timestep.

I haven't understood yet where changes in frames come from. It might well be that something needs to be fixed but I'd like to have a test case for this in the dcd tests (and not primarily in the rms code).

Copy link
Member

Choose a reason for hiding this comment

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

I will have some time during the week to have a closer look at this.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm curious why we needed to change from step 49 to 50.

I think the same reason: before we had 1049, which was calculated as istart + frames = 1000 + 49. Now we have istart/nsavc + frames = 1000/1000 + 49 = 1 + 49 = 50.

Copy link
Member

Choose a reason for hiding this comment

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

Sorry I didn't have time yet to look at this. But your guess is likely right. This means from now on all reported time will start from 1? except when istart is 0.

Copy link
Member

Choose a reason for hiding this comment

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

I'm cool with that. This will affect users by showing later times now. I would change the CHANGELOG message to say that we used to report to early timestamps and now read times correctly and users should expect that times are shifted to later values. I like to be a bit more exact then just we did it wrong

Otherwise looks good to me. It can be merged.

@orbeckst
Copy link
Member Author

Last commit harmonizes use of decimal and should make the lone failure on travis pass now.

@orbeckst
Copy link
Member Author

@kain88-de I am travelling for most of the day and will be busy over the next few days. Please move forward with this PR as you see fit.

@pytest.mark.parametrize("variable, default", (("istart", 0), ("nsavc", 1)))
def test_DCDWriter_default(tmpdir, variable, default):
outfile = str(tmpdir.join("test.dcd"))
with mda.Writer(outfile, n_atoms=10) as W:
Copy link
Member Author

Choose a reason for hiding this comment

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

In principle, writing the empty DCD and returning the header could be made a module-level fixture. I am out of time to do this right now.

ts_dcd.positions,
3)

@pytest.fixture(params=[(PSF, DCD),
Copy link
Member Author

Choose a reason for hiding this comment

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

Should this be declared with scope="module"?

Copy link
Member Author

@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.

comments inline – don't have time to address them

orbeckst and others added 6 commits March 18, 2018 19:10
- 100 steps of TMD in GBIS implicit solvent from closed AdK
  to open AdK; dt = 1fs; output frequency 10, first step 10
- NAMD version 2.10
- created by @sseyler
- see
  #1819 (comment)
  for details
- fixes #1819
- add tests for the istart and nsavc defaults in DCDWriter
- update docs for nsavc and istart
- adjust test_writer_dt() so that we get the same times for dcd and xtc
  (which is a bit tricky)
- update CHANGELOG
@orbeckst orbeckst force-pushed the issue-1819-dcd-istart branch from ea153c9 to 4e7d4aa Compare March 19, 2018 00:11
@orbeckst
Copy link
Member Author

For some reason, the minimal tests failed with something related to duecredit (https://travis-ci.org/MDAnalysis/mdanalysis/jobs/355076569). I rebased this branch against develop to make sure that everything is in here and force-pushed.

Apologies @kain88-de, you will have to make sure that your branch pulls properly.

@kain88-de
Copy link
Member

Apologies @kain88-de, you will have to make sure that your branch pulls properly.

git reset --hard upstream/branch-name works like a charm everytime ;-)

@orbeckst
Copy link
Member Author

@kain88-de any more comments?

@tylerjereddy
Copy link
Member

I tried resolving the merge conflict in the github GUI since it was a pretty simple thing in the changelog.

@orbeckst
Copy link
Member Author

still need to modify CHANGELOG following #1832 (comment)

@orbeckst orbeckst self-assigned this Mar 23, 2018
@orbeckst orbeckst merged commit 5a232a3 into develop Mar 23, 2018
@orbeckst orbeckst deleted the issue-1819-dcd-istart branch March 23, 2018 06:04
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.

DCDReader calculates wrong time (istart is in integrator steps not frames)

4 participants