Skip to content

PLUMED Collective Variables in OPS#910

Merged
dwhswenson merged 2 commits into
openpathsampling:masterfrom
apdealbao:ops_with_plumed
May 3, 2020
Merged

PLUMED Collective Variables in OPS#910
dwhswenson merged 2 commits into
openpathsampling:masterfrom
apdealbao:ops_with_plumed

Conversation

@apdealbao

Copy link
Copy Markdown
Contributor

This adds a PLUMED wrapper to the OPS collective variables, along with tests and examples. The wrapper requires a PLUMED and py-PLUMED (available via conda-forge) and OpenMM (available from conda/omnia). Tests are skipped in these requirements are not met.

Unsure about if/how to change OPS conda-recipe/meta.yaml

@dwhswenson dwhswenson self-assigned this Mar 18, 2020
@dwhswenson dwhswenson added this to the 1.3 milestone Mar 18, 2020

@dwhswenson dwhswenson left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the contribution! I'm excited for this one, and very much looking forward to getting it merged in!

Overall, it looks very good. A number of minor changes recommended, mostly to tests. Things aren't in specific line-by-line comments:

  1. Please add py-plumed to devtools/conda-recipe/meta.yaml, under requirements: run:. This is where we currently have all the extra requirements. I'm planning to change that soon (it's an ugly and outdated place to keep these things), but wanted you to get this in first.

  2. We have a 10-frame "PDB trajectory" of AD in tests/test_data/ala_small_traj.pdb. Load this (using tools from the OpenMM engine) instead of adding the extra AD_trajectory.nc file. This might also work instead of adding the AD_initial_frame.pdb (Does MOLINFO will just take the first model in a multiple model PDB?) For the example, you could require that users copy over the results from https://github.com/openpathsampling/openpathsampling/blob/master/examples/alanine_dipeptide_tps/AD_tps_1_trajectory.ipynb (start from the last step of the resulting file alanine_dipeptide_tps_equil.nc instead of the AD_trajectory.nc -- that's how I made the tutorial AD_trajectory.nc file anyway). We do this for a number of other examples (although we should be more explicit about where the file needs to come from). One heads-up: sometimes you'll get the "increasing" transition instead of the "decreasing" transition (because psi is periodic). See Figs 7 and 8 and related discussion in the OPS 2 paper for details. This could mess with the nice figure you make at the end. (I think giving users a warning about this is all you need.)

Comment thread openpathsampling/tests/test_plumed_wrapper.py Outdated
Comment thread openpathsampling/tests/test_plumed_wrapper.py Outdated
Comment thread openpathsampling/tests/test_plumed_wrapper.py Outdated
Comment thread openpathsampling/tests/test_plumed_wrapper.py Outdated
Comment thread openpathsampling/tests/test_plumed_wrapper.py Outdated
Comment thread openpathsampling/tests/test_plumed_wrapper.py Outdated
Comment thread openpathsampling/collectivevariables/plumed_wrapper.py Outdated
@apdealbao apdealbao requested a review from dwhswenson March 18, 2020 16:17
@apdealbao

Copy link
Copy Markdown
Contributor Author

Thank you for the very clear pointers! All changes are implemented as requested.

subprocess did not work for me to source PLUMED. I opted to add the built-in wrapper to the current PYTHONPATH. Please let me know if this is fine.

@dwhswenson

Copy link
Copy Markdown
Member

@apdealbao : Right now it seems that the PLUMED RMSD and MDTraj's RMSD are not looking at the same trajectory, probably a result of the last set of changes. That's the only error in unit testing. (Once it passes tests without errors, I can check things like test coverage, etc.)

@apdealbao

Copy link
Copy Markdown
Contributor Author

Hi @dwhswenson. I am unable to track the error. In the last commit, I updated the tests/test_data/plumed_wrapper/AD_plumed_rmsd.pdb file to be the same as the first frame of tests/test_data/ala_small_traj.pdb, and in my local branch test_rmsd_vs_mdtraj is passed. Maybe there's something I'm missing.

@dwhswenson

Copy link
Copy Markdown
Member

I reran tests, and that didn't fix. Looking at the error, it's clear that MDTraj has it right and PLUMED has it wrong: with t=0 as the reference frame, the RMSD should be 0 at t=0. It is for MDTraj; is not for PLUMED. The numbers look like the wrong thing is being used as reference, but I don't see that in the code.

Is it possible that PLUMED is reordering equivalent hydrogens or something? It seems like some value entering the RMSD is off by 0.101, but I couldn't find an obvious culprit. Let's take closer looks tomorrow, and if we can't figure it out there, I'll ping Gareth and Giovanni to see if they can help.

It's possible that something is going wrong because one has waters and one does not? That's another guess. In any case, I probably won't look into it until tomorrow afternoon.

@apdealbao

Copy link
Copy Markdown
Contributor Author

Alright. I think it should be easy to fix. I also had that 0.101 error before, and I corrected it by updating the tests/test_data/plumed_wrapper/AD_plumed_rmsd.pdb, so that it was the same as the first frame of the new trajectory. Now it's clear that I probably didn't update that properly in my commit and push. I'll try again early tomorrow.

@apdealbao

Copy link
Copy Markdown
Contributor Author

Hi @dwhswenson. Strangely, in my previous commit (70c899c ) I can already see the corrected tests/test_data/plumed_wrapper/AD_plumed_rmsd.pdb. Not sure what is going wrong.

@dwhswenson

Copy link
Copy Markdown
Member

It runs fine for me locally, as well. I'm on a Mac; I think that you are, too, @apdealbao. It is possible that this is something specific to the Linux version of PLUMED.

I suspect we're going to need to ask the PLUMED team for help here. Could you add a pure-(py-)PLUMED version to the test (i.e., manually include the commands your wrapper classes automate), and compare that your wrapper version? Showing an implementation only based on PLUMED will make it easier for them to debug.

Note that you should do git pull before starting on this -- I added some changes to really ensure that that both are using the same reference frame. (Before MDTraj was technically using frame 0 of the trajectory, not the separate PDB file, which contains the same information. Now it uses the separate PDB file.)

@dwhswenson

Copy link
Copy Markdown
Member

I've been trying this on a Linux box. I can sometimes reproduce the error.

The little bash script I'm using:

Details
#!/bin/bash

COUNT=0

for i in `seq 10`
do
    py.test --pyargs openpathsampling.tests.test_plumed_wrapper > /dev/null
    result_code=$?
    if [ $result_code -eq 1 ]
    then
        echo -n "X"
        COUNT=$((COUNT+1))
    elif [ $result_code -eq 0 ]
    then
        echo -n "."
    else
        echo -n "?"
    fi
done
echo " : $COUNT failures"

Output gives . if all the plumed wrapper tests pass; X if a test fails; ? if something weird happens. Here's what I got from three runs on a Linux box:

X...X.X..X : 4 failures
......X.X. : 2 failures
X......XX. : 3 failures

Whether it fails seems to be random, with about 30% probability. And on my Mac:

.......... : 0 failures
.......... : 0 failures
.......... : 0 failures

Now, what's really weird is that (on Linux) I get a serious mistake on the first frame if I only run the RMSD test. There are two ways of doing this:

  • ensure that I'm using local data: cd openpathsampling/tests; then py.test test_plumed_wrapper.py::TestPLUMEDCV::test_rmsd_vs_mdtraj
  • use installed data: from anywhere py.test -k rmsd --pyargs openpathsampling.tests.test_plumed_wrapper

Both give me no error on Mac, same error on Linux:

_______________________ TestPLUMEDCV.test_rmsd_vs_mdtraj _______________________

self = <openpathsampling.tests.test_plumed_wrapper.TestPLUMEDCV object at 0x147787734a10>

    def test_rmsd_vs_mdtraj(self):
        plmd = PLUMEDInterface(self.topology)
        rmsd_ref_file = data_filename(os.path.join("plumed_wrapper",
                                                   "AD_plumed_rmsd.pdb"))
        md_ref = md.load(rmsd_ref_file)
        rmsd_md = paths.MDTrajFunctionCV("rmsd_md", md.rmsd, self.topology,
                                         reference=md_ref, frame=0,
                                         atom_indices=range(22))
        rmsd_pl = PLUMEDCV("rmsd_pl", plmd, "RMSD REFERENCE="
                           + rmsd_ref_file + " TYPE=OPTIMAL")

        np.testing.assert_almost_equal(rmsd_md(self.trajectory),
>                                      rmsd_pl(self.trajectory), decimal=3)
E       AssertionError:
E       Arrays are not almost equal to 3 decimals
E
E       Mismatched elements: 1 / 10 (10%)
E       Max absolute difference: 0.2579862
E       Max relative difference: 1.
E        x: array([0.   , 0.003, 0.006, 0.008, 0.012, 0.018, 0.024, 0.03 , 0.036,
E              0.042], dtype=float32)
E        y: array([0.258, 0.003, 0.006, 0.008, 0.012, 0.018, 0.024, 0.03 , 0.036,
E              0.042])

The first frame is way off, and everything else is fine. When I only run the RMSD test, I always get an error on Linux. This looks kind of like an uninitialized variable error in C: for example, it could be that the Mac conda-forge compiler automatically initializes things to 0 and the Linux compiler doesn't, and that might be why we see a difference.

Is there anywhere you might need to initialize something for PLUMED?

@apdealbao

Copy link
Copy Markdown
Contributor Author

Hi @dwhswenson. I'm currently trying to make a test using the plumed module directly. It will take me some time, but I'll let you know what comes out. Indeed that are many things that are initialized in the interface and perhaps one is responsible for the error.

@apdealbao

Copy link
Copy Markdown
Contributor Author

hi @dwhswenson. I added a new test that uses the plumed module directly. The tests is successfully passed in my Mac, but it might show an error in Linux.

@dwhswenson

Copy link
Copy Markdown
Member

@apdealbao : Thanks for assembling that extra test. I can confirm that it does reproduce the errors I'd seen previously. However, when I used it as the basis of a simple script (with no OPS at all; only MDTraj and PLUMED), I couldn't reproduce the errors. I'll be going through the test bit by bit to make your new test more like my MDTraj-based script, and we'll see if that makes anything clearer.

@apdealbao

Copy link
Copy Markdown
Contributor Author

ok, @dwhswenson. Let me know if I can help with anything else.

@apdealbao

Copy link
Copy Markdown
Contributor Author

Hi @dwhswenson. Just saw the fix :) Any idea why this didn't work in Linux? Just as a take-home message for me.

@dwhswenson

Copy link
Copy Markdown
Member

No idea at all. I'm going to post an issue on PLUMED; maybe they'll have an idea. Since it is only a problem for RMSD, I'm wondering if it is a detail there. My best guess is that first binding it to a name somehow prevents garbage collection? Anyway, I'll CC you on that issue when I post it.

I figured it out because I had rewritten something based on your test_direct, but it didn't reproduce the error. So I slowly changed test_direct to be more like my working version. I had to triple check to be sure that change actually fixed it, because I see no reason that it would.

@dwhswenson dwhswenson left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Two more minor comments based on things I noticed.

There is one other thing you'll need to do, which is to rewrite history. I'd like you squash your first 3 commits into 1. That will make it so that the addition/removal of the 40MB trajectory doesn't get into the actual repository history, taking up space.

Here are two good tutorials on squashing commits. Be sure to do git pull to get my most recent updates before you start squashing.

Don't worry about squashing all commits. Part of the reason I'm asking you to do this is so that we can get rid of the big file while still maintaining as much credit as possible for you.

Comment thread openpathsampling/collectivevariables/plumed_wrapper.py Outdated
Comment thread openpathsampling/tests/test_plumed_wrapper.py
tests, skips, resources, examples, no large files

removed extra .nc file, changed to pytest, fixed sourcing

Use same ref frame for MDTraj & PLUMED RMSD

added direct plumed test

switch direct plumed to RMSD (from dist)

you've gotta be kidding...

remove test_direct (looks like it did its job!)
@apdealbao

Copy link
Copy Markdown
Contributor Author

Hi @dwhswenson. Busy day. I just squashed the commits. I'll take a look at the other comments and try to address them by tomorrow. Thanks for the guidance!

@dwhswenson

Copy link
Copy Markdown
Member

Sorry for the delay on getting this merged. It has been ready to go in for a while. Merging now!

@dwhswenson dwhswenson merged commit 1aa6fd3 into openpathsampling:master May 3, 2020
@apdealbao

Copy link
Copy Markdown
Contributor Author

Great news! Thanks a lot @dwhswenson!

@dwhswenson dwhswenson mentioned this pull request Sep 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants