From 96d24b86d10468d00a64eca6daa90a386dd13502 Mon Sep 17 00:00:00 2001 From: Charlles Abreu Date: Wed, 6 Dec 2023 13:59:02 -0500 Subject: [PATCH 1/4] Fixes RMSD force management --- devtools/linters/pylintrc | 17 ----------------- docs/readme.rst | 17 ++++++----------- ufedmm/tests/test_ufedmm.py | 24 ++++++++++++++++++++++++ ufedmm/ufedmm.py | 17 +++++++++++------ 4 files changed, 41 insertions(+), 34 deletions(-) delete mode 100644 devtools/linters/pylintrc diff --git a/devtools/linters/pylintrc b/devtools/linters/pylintrc deleted file mode 100644 index 4d6f9e8..0000000 --- a/devtools/linters/pylintrc +++ /dev/null @@ -1,17 +0,0 @@ -[MAIN] - -ignored-modules=openmm.unit -ignore=_version.py - -[DESIGN] - -max-locals=25 # Maximum number of local variables for function/method body - -[MESSAGES CONTROL] - -disable = unexpected-keyword-arg, # Avoids false-positives with Context.getState method - too-many-arguments - -[FORMAT] - -good-names=i,j,k,m,n,_,v,x,y,z diff --git a/docs/readme.rst b/docs/readme.rst index 858a9a9..ea8881e 100644 --- a/docs/readme.rst +++ b/docs/readme.rst @@ -6,11 +6,11 @@ UFEDMM is an OpenMM extension for applying the Unified Free Energy Dynamics meth * Free software: MIT license +============ Installation ============ -UFEDMM is available as a conda package installable from the -[craabreu](https://anaconda.org/craabreu) channel. +UFEDMM is available as a conda package installable from the `craabreu `_ conda channel. To install it, either run: .. code-block:: bash @@ -29,15 +29,10 @@ To use UFEDMM in your own Python script or Jupyter notebook, import it as follow import ufedmm -Documentation -============= - -https://craabreu.github.io/ufedmm/ - +============ Contributing ============ -Feedback, bug reports, and feature requests are welcome. They should be -submitted to https://github.com/craabreu/ufedmm/issues. - -Pull requests are greatly appreciated! \ No newline at end of file +Feedback, bug reports, and feature requests are welcome. They should be submitted to +UFEDMM's `issue tracker `_. Pull requests are +alo greatly appreciated! diff --git a/ufedmm/tests/test_ufedmm.py b/ufedmm/tests/test_ufedmm.py index d492dfd..fc32263 100644 --- a/ufedmm/tests/test_ufedmm.py +++ b/ufedmm/tests/test_ufedmm.py @@ -5,12 +5,14 @@ # Import package, test suite, and other packages as needed import io import sys +from copy import deepcopy import openmm import pytest from openmm import unit import ufedmm +import numpy as np def ufed_model( @@ -171,3 +173,25 @@ def test_well_tempered_metadynamics(): simulation.step(100) energy = simulation.context.getState(getEnergy=True).getPotentialEnergy() assert energy / energy.unit == pytest.approx(153.17, abs=0.1) + + +def test_rmsd_forces(): + model, ufed = ufed_model(constraints=None) + rmsd = openmm.RMSDForce( # Level 1 + model.positions, np.arange(model.system.getNumParticles()) + ) + cvforce = openmm.CustomCVForce("rmsd + cvforce") + cvforce.addCollectiveVariable("rmsd", deepcopy(rmsd)) # Level 2 + inner_cvforce = openmm.CustomCVForce("rmsd") + inner_cvforce.addCollectiveVariable("rmsd", deepcopy(rmsd)) # Level 3 + cvforce.addCollectiveVariable("cvforce", inner_cvforce) + model.system.addForce(rmsd) + model.system.addForce(cvforce) + integrator = ufedmm.MiddleMassiveNHCIntegrator( + 300 * unit.kelvin, 10 * unit.femtoseconds, 1 * unit.femtoseconds + ) + platform = openmm.Platform.getPlatformByName("Reference") + simulation = ufed.simulation(model.topology, model.system, integrator, platform) + simulation.context.setPositions(model.positions) + simulation.context.setVelocitiesToTemperature(300 * unit.kelvin, 1234) + simulation.step(1) diff --git a/ufedmm/ufedmm.py b/ufedmm/ufedmm.py index d2d9e49..4b0dd6c 100644 --- a/ufedmm/ufedmm.py +++ b/ufedmm/ufedmm.py @@ -47,7 +47,7 @@ def _standardized(quantity): def _update_RMSD_forces(system): N = system.getNumParticles() - def update_RMSDForce(force): + def _update_RMSDForce(force): positions = force.getReferencePositions()._value if len(positions) >= N: positions = positions[:N] @@ -55,14 +55,19 @@ def update_RMSDForce(force): positions += [openmm.Vec3(0, 0, 0)] * (N - len(positions)) force.setReferencePositions(positions) + def _update_RMSD_forces_in_cvforce(cvforce): + for index in range(cvforce.getNumCollectiveVariables()): + force = cvforce.getCollectiveVariable(index) + if isinstance(force, openmm.RMSDForce): + _update_RMSDForce(force) + elif isinstance(force, openmm.CustomCVForce): + _update_RMSD_forces_in_cvforce(force) + for force in system.getForces(): if isinstance(force, openmm.RMSDForce): - update_RMSDForce(force) + _update_RMSDForce(force) elif isinstance(force, openmm.CustomCVForce): - for index in range(force.getNumCollectiveVariables()): - cv = force.getCollectiveVariable(index) - if isinstance(cv, openmm.RMSDForce): - update_RMSDForce(cv) + _update_RMSD_forces_in_cvforce(force) class CollectiveVariable(object): From 02e769422a7b3fe313611144b2f9534dae3c9ecd Mon Sep 17 00:00:00 2001 From: Charlles Abreu Date: Wed, 6 Dec 2023 14:04:18 -0500 Subject: [PATCH 2/4] Fixed linting --- ufedmm/tests/test_ufedmm.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ufedmm/tests/test_ufedmm.py b/ufedmm/tests/test_ufedmm.py index fc32263..d76641c 100644 --- a/ufedmm/tests/test_ufedmm.py +++ b/ufedmm/tests/test_ufedmm.py @@ -7,12 +7,12 @@ import sys from copy import deepcopy +import numpy as np import openmm import pytest from openmm import unit import ufedmm -import numpy as np def ufed_model( From 613bc4d279616e38987890105d28334b40b27575 Mon Sep 17 00:00:00 2001 From: Charlles Abreu Date: Wed, 6 Dec 2023 14:06:58 -0500 Subject: [PATCH 3/4] Changed commands in Linter workflow --- .github/workflows/Linter.yaml | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/.github/workflows/Linter.yaml b/.github/workflows/Linter.yaml index a66595a..cfc7c2c 100644 --- a/.github/workflows/Linter.yaml +++ b/.github/workflows/Linter.yaml @@ -45,16 +45,12 @@ jobs: - name: Run flake8 shell: bash -l {0} - run: flake8 --max-line-length=100 --ignore=E203,W503 ufedmm/ + run: flake8 ufedmm/ - name: Run black shell: bash -l {0} - run: black --line-length 100 --diff --color ufedmm/ + run: black --diff --color ufedmm/ - name: Run isort shell: bash -l {0} - run: isort --line-length=100 --check-only ufedmm/ - - # - name: Run pylint - # shell: bash -l {0} - # run: pylint --rcfile=devtools/linters/pylintrc ufedmm/ + run: isort --check-only ufedmm/ From 490d973f1b590058997296418fcefa498e5cba45 Mon Sep 17 00:00:00 2001 From: Charlles Abreu Date: Wed, 6 Dec 2023 14:47:55 -0500 Subject: [PATCH 4/4] Added dependency --- devtools/conda-envs/lint_env.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/devtools/conda-envs/lint_env.yaml b/devtools/conda-envs/lint_env.yaml index fe20add..c2c8763 100644 --- a/devtools/conda-envs/lint_env.yaml +++ b/devtools/conda-envs/lint_env.yaml @@ -15,6 +15,7 @@ dependencies: # Linting - flake8 + - flake8-pyproject - black - isort # - pylint