From e2c0c7daa16c63455d0641ea5ebdfddaae019342 Mon Sep 17 00:00:00 2001 From: Pablo Zubieta <8410335+pabloferz@users.noreply.github.com> Date: Thu, 22 Aug 2024 13:32:15 -0500 Subject: [PATCH 1/2] Improve synchronization with OpenMM --- pysages/backends/openmm.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pysages/backends/openmm.py b/pysages/backends/openmm.py index 0c5f8e44..b2cc83d8 100644 --- a/pysages/backends/openmm.py +++ b/pysages/backends/openmm.py @@ -157,13 +157,12 @@ def bias(snapshot, state, sync_backend): """Adds the computed bias to the forces.""" if state.bias is None: return - biases = adapt(state.bias) # Forces may be computed asynchronously on the GPU, so we need to # synchronize them before applying the bias. sync_backend() + biases = adapt(state.bias) forces = view(snapshot.forces) - biases = view(biases.block_until_ready()) - forces += biases + forces += view(biases.block_until_ready()) sync_forces() def dimensionality(): From a45ee8ecf892b1decf2fda85a69cf38f7f145c2c Mon Sep 17 00:00:00 2001 From: Pablo Zubieta <8410335+pabloferz@users.noreply.github.com> Date: Thu, 22 Aug 2024 13:40:10 -0500 Subject: [PATCH 2/2] Remove no-longer necessary shift --- examples/hoomd-blue/spectral_abf/Butane-SpectralABF.ipynb | 3 +-- examples/hoomd-blue/spectral_abf/Butane-SpectralABF.md | 1 - examples/hoomd-blue/spectral_abf/butane.py | 3 +-- examples/hoomd3/spectral_abf/butane.py | 1 - examples/openmm/spectral_abf/ADP_SpectralABF.ipynb | 1 - examples/openmm/spectral_abf/ADP_SpectralABF.md | 1 - examples/openmm/spectral_abf/alanine-dipeptide.py | 3 +-- 7 files changed, 3 insertions(+), 10 deletions(-) diff --git a/examples/hoomd-blue/spectral_abf/Butane-SpectralABF.ipynb b/examples/hoomd-blue/spectral_abf/Butane-SpectralABF.ipynb index 0ae6b9df..e346d8cd 100644 --- a/examples/hoomd-blue/spectral_abf/Butane-SpectralABF.ipynb +++ b/examples/hoomd-blue/spectral_abf/Butane-SpectralABF.ipynb @@ -638,8 +638,7 @@ "A = result[\"free_energy\"]\n", "# Alternatively:\n", "# fes_fn = result[\"fes_fn\"]\n", - "# A = fes_fn(mesh)\n", - "A = A.max() - A" + "# A = fes_fn(mesh)" ] }, { diff --git a/examples/hoomd-blue/spectral_abf/Butane-SpectralABF.md b/examples/hoomd-blue/spectral_abf/Butane-SpectralABF.md index 520b3834..78d15f3f 100644 --- a/examples/hoomd-blue/spectral_abf/Butane-SpectralABF.md +++ b/examples/hoomd-blue/spectral_abf/Butane-SpectralABF.md @@ -386,7 +386,6 @@ A = result["free_energy"] # Alternatively: # fes_fn = result["fes_fn"] # A = fes_fn(mesh) -A = A.max() - A ``` ```python colab={"base_uri": "https://localhost:8080/", "height": 302} id="7_d_XfVLLkbI" outputId="e35db259-31f8-4a3b-b1fa-7e91a8a5c88a" diff --git a/examples/hoomd-blue/spectral_abf/butane.py b/examples/hoomd-blue/spectral_abf/butane.py index 77a68bb7..405010ba 100644 --- a/examples/hoomd-blue/spectral_abf/butane.py +++ b/examples/hoomd-blue/spectral_abf/butane.py @@ -257,7 +257,7 @@ def get_args(argv): ("time-steps", "t", int, 5e5, "Number of simulation steps"), ] parser = argparse.ArgumentParser(description="Example script to run SpectralABF") - for (name, short, T, val, doc) in available_args: + for name, short, T, val, doc in available_args: parser.add_argument("--" + name, "-" + short, type=T, default=T(val), help=doc) return parser.parse_args(argv) @@ -283,7 +283,6 @@ def main(argv=[]): mesh = result["mesh"] fes_fn = result["fes_fn"] A = fes_fn(mesh) - A = A.max() - A # plot the free energy fig, ax = plt.subplots() diff --git a/examples/hoomd3/spectral_abf/butane.py b/examples/hoomd3/spectral_abf/butane.py index baedfa2e..ae6c11f3 100644 --- a/examples/hoomd3/spectral_abf/butane.py +++ b/examples/hoomd3/spectral_abf/butane.py @@ -298,7 +298,6 @@ def main(argv=[]): mesh = result["mesh"] fes_fn = result["fes_fn"] A = fes_fn(mesh) - A = A.max() - A # plot the free energy fig, ax = plt.subplots() diff --git a/examples/openmm/spectral_abf/ADP_SpectralABF.ipynb b/examples/openmm/spectral_abf/ADP_SpectralABF.ipynb index ac651e9c..2fc5ecb4 100644 --- a/examples/openmm/spectral_abf/ADP_SpectralABF.ipynb +++ b/examples/openmm/spectral_abf/ADP_SpectralABF.ipynb @@ -342,7 +342,6 @@ "# mesh = result[\"mesh\"]\n", "# fes_fn = result[\"fes_fn\"]\n", "# A = fes_fn(mesh)\n", - "A = A.max() - A\n", "A = A.reshape(grid.shape)" ] }, diff --git a/examples/openmm/spectral_abf/ADP_SpectralABF.md b/examples/openmm/spectral_abf/ADP_SpectralABF.md index 192a3c85..f0bd66a1 100644 --- a/examples/openmm/spectral_abf/ADP_SpectralABF.md +++ b/examples/openmm/spectral_abf/ADP_SpectralABF.md @@ -211,7 +211,6 @@ A = result["free_energy"] # mesh = result["mesh"] # fes_fn = result["fes_fn"] # A = fes_fn(mesh) -A = A.max() - A A = A.reshape(grid.shape) ``` diff --git a/examples/openmm/spectral_abf/alanine-dipeptide.py b/examples/openmm/spectral_abf/alanine-dipeptide.py index 3f5c611d..166dce33 100644 --- a/examples/openmm/spectral_abf/alanine-dipeptide.py +++ b/examples/openmm/spectral_abf/alanine-dipeptide.py @@ -78,7 +78,7 @@ def get_args(argv): ("time-steps", "t", int, 5e5, "Number of simulation steps"), ] parser = argparse.ArgumentParser(description="Example script to run Spectral ABF") - for (name, short, T, val, doc) in available_args: + for name, short, T, val, doc in available_args: parser.add_argument("--" + name, "-" + short, type=T, default=T(val), help=doc) return parser.parse_args(argv) @@ -108,7 +108,6 @@ def main(argv=[]): # Set min free energy to zero A = fes_fn(xi) - A = A.max() - A A = A.reshape(plot_grid.shape) # plot and save free energy to a PNG file