From da8686b177c82c94c174eeecfaf915b3222eb21c Mon Sep 17 00:00:00 2001 From: Mike Henry <11765982+mikemhenry@users.noreply.github.com> Date: Mon, 16 Nov 2026 10:46:04 -0700 Subject: [PATCH 01/12] Add testpypi (#1) * gracefully handle the case where ambertools isn't installed * put onto test pypi --- .github/workflows/publish.yml | 168 ++++++++++++++++++ .../generators/template_generators.py | 13 ++ .../tests/test_system_generator.py | 14 +- .../tests/test_template_generators.py | 27 ++- setup.py | 22 ++- 5 files changed, 227 insertions(+), 17 deletions(-) create mode 100644 .github/workflows/publish.yml diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 00000000..ccc6e22b --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,168 @@ +name: Build and publish package + +on: + pull_request: + release: + # Stable GitHub Releases only. + types: [released] # need another thing to make pre-releases work + +# Deny permissions by default. Each job gets only what it needs. +permissions: {} + +jobs: + build: + name: Build distributions + runs-on: ubuntu-latest + + permissions: + contents: read + + steps: + - name: Check out repository + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + # Important for projects using setuptools-scm. + fetch-depth: 0 + # We don't need the token for more git operations + persist-credentials: false + + - name: Set up Python + uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0 + with: + # Recommend using min python version supported + python-version: "3.12" + + - name: Install build frontend + run: python -m pip install build + + - name: Build distributions + run: python -m build + + - name: Show distributions + run: ls -lh dist/ + + # archive: false means the wheel itself is stored directly rather + # than being wrapped in an additional GitHub artifact ZIP. + # + # This requires the glob to resolve to exactly one file. + - name: Upload wheel + uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 + with: + path: dist/*.whl + archive: false + if-no-files-found: error + + - name: Upload sdist + uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 + with: + path: dist/*.tar.gz + archive: false + if-no-files-found: error + + test-package: + name: Test built package + needs: build + runs-on: ubuntu-latest + + permissions: + contents: read + + steps: + # We need the checkout for the test suite, but we do NOT install + # the package from this checkout. + - name: Check out repository + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + + - name: Download wheel + uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 + with: + pattern: "*.whl" + path: dist + merge-multiple: true + + - name: Set up Python + uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0 + with: + python-version: "3.12" + + - name: Install built wheel with test dependencies + shell: bash + run: | + shopt -s nullglob + wheels=(dist/*.whl) + if (( ${#wheels[@]} != 1 )); then + echo "Expected exactly one wheel, found ${#wheels[@]}" + exit 1 + fi + python -m pip install "${wheels[0]}[test]" --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple + + - name: Verify installed wheel version + env: + PACKAGE: openmmforcefields + DISTRIBUTION: mike-OpenMMForceFields + run: | + python -I - <<'PY' + import importlib + import os + from importlib.metadata import version + + package = os.environ["PACKAGE"] + module = importlib.import_module(package) + installed_version = version(os.getenv("DISTRIBUTION", package)) + + print(f"Package path: {module.__file__}") + print(f"Module version: {module.__version__}") + print(f"Installed version: {installed_version}") + + assert module.__version__ == installed_version + PY + + - name: Run tests + # Use isolated directory and --import-mode=importlib to avoid hiding + # packing bugs by running in checked out repo + working-directory: /tmp + run: | + # Run tests + python -m pytest --import-mode=importlib -v --color=yes --durations=10 $GITHUB_WORKSPACE/openmmforcefields/tests/ + + publish: + name: Publish to PyPI + + # The publish job exists only for an actual GitHub Release. + if: github.event_name == 'release' + + # We only publish if both building and testing the built artifact succeeded. + needs: + - build + - test-package + + runs-on: ubuntu-latest + + environment: + name: testpypi + + # This is the only job that can request an OIDC identity. + permissions: + id-token: write + + steps: + - name: Download wheel + uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 + with: + pattern: "*.whl" + path: dist + merge-multiple: true + + - name: Download sdist + uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 + with: + pattern: "*.tar.gz" + path: dist + merge-multiple: true + + - name: Publish distributions to PyPI + uses: pypa/gh-action-pypi-publish@dc37677b2e1c63e2034f94d8a5b11f265b73ba33 # v1.14.2 + with: + repository-url: https://test.pypi.org/legacy/ diff --git a/openmmforcefields/generators/template_generators.py b/openmmforcefields/generators/template_generators.py index c8e61ac0..3e101cbb 100644 --- a/openmmforcefields/generators/template_generators.py +++ b/openmmforcefields/generators/template_generators.py @@ -576,6 +576,19 @@ def generate_residue_template(self, molecule): * This method preserves stereochemistry during AM1-BCC charge parameterization. * Atom names in molecules will be assigned Tripos atom names if any are blank or not unique. """ + import shutil + + missing = [ + exe for exe in ("antechamber", "parmchk2") + if shutil.which(exe) is None + ] + + if missing: + raise RuntimeError( + f"AmberTools is required for GAFF parameter assignment " + f"(missing from PATH: {', '.join(missing)}).\n" + "Install it with: conda install -c conda-forge 'ambertools>=22'" + ) from openff.units import unit diff --git a/openmmforcefields/tests/test_system_generator.py b/openmmforcefields/tests/test_system_generator.py index 9d2bd131..fa32eb00 100644 --- a/openmmforcefields/tests/test_system_generator.py +++ b/openmmforcefields/tests/test_system_generator.py @@ -225,7 +225,7 @@ def test_barostat(self, barostat_class, args): "small_molecule_forcefield", [ pytest.param("gaff-2.2.20", marks=pytest.mark.gaff), - "openff-2.0.0", + "openff-2.3.0", pytest.param("espaloma-0.3.2", marks=pytest.mark.espaloma), ], ) @@ -259,7 +259,7 @@ def test_create_with_template_generator(self, small_molecule_forcefield): "small_molecule_forcefield", [ pytest.param("gaff-2.2.20", marks=pytest.mark.gaff), - "openff-2.0.0", + "openff-2.3.0", pytest.param("espaloma-0.3.2", marks=pytest.mark.espaloma), ], ) @@ -306,7 +306,7 @@ def test_forcefield_default_kwargs(self, small_molecule_forcefield, test_systems "small_molecule_forcefield", [ pytest.param("gaff-2.2.20", marks=pytest.mark.gaff), - "openff-2.0.0", + "openff-2.3.0", pytest.param("espaloma-0.3.2", marks=pytest.mark.espaloma), ], ) @@ -361,7 +361,7 @@ def test_forcefield_kwargs(self, small_molecule_forcefield, test_systems): "small_molecule_forcefield", [ pytest.param("gaff-2.2.20", marks=pytest.mark.gaff), - "openff-2.0.0", + "openff-2.3.0", pytest.param("espaloma-0.3.2", marks=pytest.mark.espaloma), ], ) @@ -394,7 +394,7 @@ def test_parameterize_molecules_from_creation(self, test_systems, small_molecule "small_molecule_forcefield", [ pytest.param("gaff-2.2.20", marks=pytest.mark.gaff), - "openff-2.0.0", + "openff-2.3.0", pytest.param("espaloma-0.3.2", marks=pytest.mark.espaloma), ], ) @@ -419,7 +419,7 @@ def test_parameterize_molecules_specified_during_create_system(self, test_system "small_molecule_forcefield", [ pytest.param("gaff-2.2.20", marks=pytest.mark.gaff), - "openff-2.0.0", + "openff-2.3.0", pytest.param("espaloma-0.3.2", marks=pytest.mark.espaloma), ], ) @@ -454,7 +454,7 @@ def test_add_molecules(self, test_systems, small_molecule_forcefield): "small_molecule_forcefield", [ pytest.param("gaff-2.2.20", marks=pytest.mark.gaff), - "openff-2.0.0", + "openff-2.3.0", pytest.param("espaloma-0.3.2", marks=pytest.mark.espaloma), ], ) diff --git a/openmmforcefields/tests/test_template_generators.py b/openmmforcefields/tests/test_template_generators.py index 75c5f8aa..f0c3f459 100644 --- a/openmmforcefields/tests/test_template_generators.py +++ b/openmmforcefields/tests/test_template_generators.py @@ -13,6 +13,7 @@ import openmm import pytest from openff.toolkit import Molecule, Topology, ForceField as OFFForceField +from openff.toolkit import AmberToolsToolkitWrapper, OpenEyeToolkitWrapper from openff.units import unit as OFFUnit from openmm.app import PME, ForceField, Modeller, NoCutoff, PDBFile @@ -101,6 +102,14 @@ def _filter_openff(self, force_field: str) -> bool: if "smirnoff99" in force_field: return False + # Older force fields require AM1-BCC, which NAGL cannot provide by name. + if "ToolkitAM1BCC" in OFFForceField(force_field).registered_parameter_handlers: + if not ( + AmberToolsToolkitWrapper.is_available() + or OpenEyeToolkitWrapper.is_available() + ): + return False + return True def setUp(self): @@ -1144,11 +1153,11 @@ def test_forcefield_multiple(self): """Test loading multiple force field components together""" generator = SMIRNOFFTemplateGenerator( - forcefield=["openff-2.0.0.offxml", "tip3p.offxml", OFFForceField().to_string()] + forcefield=["openff-2.3.0.offxml", "tip3p.offxml", OFFForceField().to_string()] ) assert generator.forcefield assert len(generator.smirnoff_filenames) == 3 - assert generator.smirnoff_filenames[0].endswith("openff-2.0.0.offxml") + assert generator.smirnoff_filenames[0].endswith("openff-2.3.0.offxml") assert generator.smirnoff_filenames[1].endswith("tip3p.offxml") assert generator.smirnoff_filenames[2] is None assert os.path.exists(generator.smirnoff_filenames[0]) @@ -1158,10 +1167,10 @@ def test_forcefield_unconstrained(self): """Test that forcefield names resolve to unconstrained versions correctly""" # Should redirect to the unconstrained version - generator = SMIRNOFFTemplateGenerator(forcefield="openff-2.0.0") - assert generator.forcefield == "openff-2.0.0" + generator = SMIRNOFFTemplateGenerator(forcefield="openff-2.3.0") + assert generator.forcefield == "openff-2.3.0" assert len(generator.smirnoff_filenames) == 1 - assert generator.smirnoff_filenames[0].endswith("openff_unconstrained-2.0.0.offxml") + assert generator.smirnoff_filenames[0].endswith("openff_unconstrained-2.3.0.offxml") assert os.path.exists(generator.smirnoff_filenames[0]) # Should not point to any valid force field @@ -1169,10 +1178,10 @@ def test_forcefield_unconstrained(self): SMIRNOFFTemplateGenerator(forcefield="openff_unconstrained-2.0.0") # Specifying a name with .offxml should never get modified - generator = SMIRNOFFTemplateGenerator(forcefield="openff-2.0.0.offxml") + generator = SMIRNOFFTemplateGenerator(forcefield="openff-2.3.0.offxml") assert generator.forcefield assert len(generator.smirnoff_filenames) == 1 - assert generator.smirnoff_filenames[0].endswith("openff-2.0.0.offxml") + assert generator.smirnoff_filenames[0].endswith("openff-2.3.0.offxml") assert os.path.exists(generator.smirnoff_filenames[0]) generator = SMIRNOFFTemplateGenerator(forcefield="openff_unconstrained-2.0.0.offxml") @@ -1620,7 +1629,7 @@ def test_bespoke_force_field(self): the template generator. """ - custom_sage = OFFForceField("openff-2.0.0.offxml") + custom_sage = OFFForceField("openff-2.3.0.offxml") # Create a simple molecule with one bond type ethane = Molecule.from_smiles("CC") # Label ethane to get the bond type (not hard coded incase this changes in future) @@ -1658,7 +1667,7 @@ def test_14_scaling_from_offxml(self): from openmm import unit - custom_sage = OFFForceField("openff-2.0.0.offxml") + custom_sage = OFFForceField("openff-2.3.0.offxml") custom_sage.get_parameter_handler("vdW").scale14 = 0.7 custom_sage.get_parameter_handler("Electrostatics").scale14 = 0.3 diff --git a/setup.py b/setup.py index 031b8a09..9413316f 100644 --- a/setup.py +++ b/setup.py @@ -18,7 +18,7 @@ setup( # Self-descriptive entries which should always be present - name="OpenMMForceFields", + name="mike-OpenMMForceFields", author="Chodera lab // MSKCC", author_email="john.chodera@choderalab.org", description=short_description[0], @@ -53,4 +53,24 @@ ], }, package_data={"openmmforcefields": ["ffxml/amber/*.xml", "ffxml/amber/gaff/*.{xml,dat}", "ffxml/charmm/*.xml"]}, + install_requires=[ + "lxml", + "numpy", + "openff-interchange >=0.4", + "openff-toolkit >=0.16.1", + "openff-units >=0.2", + "openmm >=8.5.1", + "pyyaml", + "tinydb", + "validators", + "parmed", # might not need in this pass + ], + extras_require = { + 'test': [ + "pytest", + "pytest-cov", + "pytest-randomly", + "pytest-xdist", + ], + }, ) From fb56c2621fb8162269b956e44a62841f8d174da5 Mon Sep 17 00:00:00 2001 From: Mike Henry <11765982+mikemhenry@users.noreply.github.com> Date: Mon, 16 Nov 2026 10:57:37 -0700 Subject: [PATCH 02/12] Update setup.py --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 9413316f..cb524aa3 100644 --- a/setup.py +++ b/setup.py @@ -32,7 +32,7 @@ classifiers=[ "Development Status :: 3 - Alpha", "Topic :: Utilities", - "License :: OSI Approved :: MIT", + ""License :: OSI Approved :: MIT License", ], # Don't install as an egg, since OpenMM can't find ffxml files if we do zip_safe=False, From 4c56376e10bab119e684ca9110dc9cbbe8bb4afb Mon Sep 17 00:00:00 2001 From: Mike Henry <11765982+mikemhenry@users.noreply.github.com> Date: Mon, 16 Nov 2026 10:57:56 -0700 Subject: [PATCH 03/12] Update setup.py --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index cb524aa3..a218f022 100644 --- a/setup.py +++ b/setup.py @@ -32,7 +32,7 @@ classifiers=[ "Development Status :: 3 - Alpha", "Topic :: Utilities", - ""License :: OSI Approved :: MIT License", + "License :: OSI Approved :: MIT License", ], # Don't install as an egg, since OpenMM can't find ffxml files if we do zip_safe=False, From 339ef4a86f292c49fc02e82eea358d5d67860ef8 Mon Sep 17 00:00:00 2001 From: Mike Henry <11765982+mikemhenry@users.noreply.github.com> Date: Wed, 18 Nov 2026 23:59:22 -0700 Subject: [PATCH 04/12] enable backfill --- .github/workflows/publish.yml | 37 +++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index ccc6e22b..26bfc647 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -6,6 +6,17 @@ on: # Stable GitHub Releases only. types: [released] # need another thing to make pre-releases work + workflow_dispatch: + inputs: + source_branch: + description: "Branch containing the source code to publish" + required: true + type: string + version: + description: "Package version to publish (e.g. 0.15.1)" + required: true + type: string + # Deny permissions by default. Each job gets only what it needs. permissions: {} @@ -14,6 +25,10 @@ jobs: name: Build distributions runs-on: ubuntu-latest + # We want to track the commit we use to build, so we use the same commit to test + outputs: + source_sha: ${{ steps.source.outputs.sha }} + permissions: contents: read @@ -21,11 +36,20 @@ jobs: - name: Check out repository uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: + # Grab the ref from the workflow dispatch if that method was used as the trigger, else use the ref that triggered the workflow + ref: ${{ github.event_name == 'workflow_dispatch' && format('refs/heads/{0}', inputs.source_branch) || github.ref }} # Important for projects using setuptools-scm. fetch-depth: 0 # We don't need the token for more git operations persist-credentials: false + - name: Record source commit + id: source + run: | + sha=$(git rev-parse HEAD) + echo "sha=$sha" >> "$GITHUB_OUTPUT" + echo "Building from commit: $sha" + - name: Set up Python uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0 with: @@ -36,7 +60,14 @@ jobs: run: python -m pip install build - name: Build distributions - run: python -m build + shell: bash + env: + BACKFILL_VERSION: ${{ inputs.version }} + run: | + if [[ "$GITHUB_EVENT_NAME" == "workflow_dispatch" ]]; then + export SETUPTOOLS_SCM_PRETEND_VERSION="$BACKFILL_VERSION" + fi + python -m build - name: Show distributions run: ls -lh dist/ @@ -73,6 +104,8 @@ jobs: - name: Check out repository uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: + ref: ${{ needs.build.outputs.source_sha }} + fetch-depth: 1 persist-credentials: false - name: Download wheel @@ -131,7 +164,7 @@ jobs: name: Publish to PyPI # The publish job exists only for an actual GitHub Release. - if: github.event_name == 'release' + if: github.event_name == 'release' || github.event_name == 'workflow_dispatch' # We only publish if both building and testing the built artifact succeeded. needs: From 08161628d710fe08e019d49e3c895441927ee9e5 Mon Sep 17 00:00:00 2001 From: Mike Henry <11765982+mikemhenry@users.noreply.github.com> Date: Fri, 20 Nov 2026 10:26:45 -0700 Subject: [PATCH 05/12] make parmed a testing dep + a seperate feature for gaff --- setup.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index a218f022..4fca6493 100644 --- a/setup.py +++ b/setup.py @@ -63,7 +63,6 @@ "pyyaml", "tinydb", "validators", - "parmed", # might not need in this pass ], extras_require = { 'test': [ @@ -71,6 +70,11 @@ "pytest-cov", "pytest-randomly", "pytest-xdist", + "parmed", # needed for some SMIRNOFF tests + ], + # If/when ambertools is on pypi, we can add it here + 'gaff': [ + "parmed", ], }, ) From 8663703c226958387404d7b3054513044ecb922a Mon Sep 17 00:00:00 2001 From: Mike Henry <11765982+mikemhenry@users.noreply.github.com> Date: Fri, 20 Nov 2026 10:29:09 -0700 Subject: [PATCH 06/12] reset some changes to make PR smaller --- .github/workflows/publish.yml | 201 ---------------------------------- setup.py | 28 +---- 2 files changed, 2 insertions(+), 227 deletions(-) delete mode 100644 .github/workflows/publish.yml diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml deleted file mode 100644 index 26bfc647..00000000 --- a/.github/workflows/publish.yml +++ /dev/null @@ -1,201 +0,0 @@ -name: Build and publish package - -on: - pull_request: - release: - # Stable GitHub Releases only. - types: [released] # need another thing to make pre-releases work - - workflow_dispatch: - inputs: - source_branch: - description: "Branch containing the source code to publish" - required: true - type: string - version: - description: "Package version to publish (e.g. 0.15.1)" - required: true - type: string - -# Deny permissions by default. Each job gets only what it needs. -permissions: {} - -jobs: - build: - name: Build distributions - runs-on: ubuntu-latest - - # We want to track the commit we use to build, so we use the same commit to test - outputs: - source_sha: ${{ steps.source.outputs.sha }} - - permissions: - contents: read - - steps: - - name: Check out repository - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - with: - # Grab the ref from the workflow dispatch if that method was used as the trigger, else use the ref that triggered the workflow - ref: ${{ github.event_name == 'workflow_dispatch' && format('refs/heads/{0}', inputs.source_branch) || github.ref }} - # Important for projects using setuptools-scm. - fetch-depth: 0 - # We don't need the token for more git operations - persist-credentials: false - - - name: Record source commit - id: source - run: | - sha=$(git rev-parse HEAD) - echo "sha=$sha" >> "$GITHUB_OUTPUT" - echo "Building from commit: $sha" - - - name: Set up Python - uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0 - with: - # Recommend using min python version supported - python-version: "3.12" - - - name: Install build frontend - run: python -m pip install build - - - name: Build distributions - shell: bash - env: - BACKFILL_VERSION: ${{ inputs.version }} - run: | - if [[ "$GITHUB_EVENT_NAME" == "workflow_dispatch" ]]; then - export SETUPTOOLS_SCM_PRETEND_VERSION="$BACKFILL_VERSION" - fi - python -m build - - - name: Show distributions - run: ls -lh dist/ - - # archive: false means the wheel itself is stored directly rather - # than being wrapped in an additional GitHub artifact ZIP. - # - # This requires the glob to resolve to exactly one file. - - name: Upload wheel - uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 - with: - path: dist/*.whl - archive: false - if-no-files-found: error - - - name: Upload sdist - uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 - with: - path: dist/*.tar.gz - archive: false - if-no-files-found: error - - test-package: - name: Test built package - needs: build - runs-on: ubuntu-latest - - permissions: - contents: read - - steps: - # We need the checkout for the test suite, but we do NOT install - # the package from this checkout. - - name: Check out repository - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - with: - ref: ${{ needs.build.outputs.source_sha }} - fetch-depth: 1 - persist-credentials: false - - - name: Download wheel - uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 - with: - pattern: "*.whl" - path: dist - merge-multiple: true - - - name: Set up Python - uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0 - with: - python-version: "3.12" - - - name: Install built wheel with test dependencies - shell: bash - run: | - shopt -s nullglob - wheels=(dist/*.whl) - if (( ${#wheels[@]} != 1 )); then - echo "Expected exactly one wheel, found ${#wheels[@]}" - exit 1 - fi - python -m pip install "${wheels[0]}[test]" --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple - - - name: Verify installed wheel version - env: - PACKAGE: openmmforcefields - DISTRIBUTION: mike-OpenMMForceFields - run: | - python -I - <<'PY' - import importlib - import os - from importlib.metadata import version - - package = os.environ["PACKAGE"] - module = importlib.import_module(package) - installed_version = version(os.getenv("DISTRIBUTION", package)) - - print(f"Package path: {module.__file__}") - print(f"Module version: {module.__version__}") - print(f"Installed version: {installed_version}") - - assert module.__version__ == installed_version - PY - - - name: Run tests - # Use isolated directory and --import-mode=importlib to avoid hiding - # packing bugs by running in checked out repo - working-directory: /tmp - run: | - # Run tests - python -m pytest --import-mode=importlib -v --color=yes --durations=10 $GITHUB_WORKSPACE/openmmforcefields/tests/ - - publish: - name: Publish to PyPI - - # The publish job exists only for an actual GitHub Release. - if: github.event_name == 'release' || github.event_name == 'workflow_dispatch' - - # We only publish if both building and testing the built artifact succeeded. - needs: - - build - - test-package - - runs-on: ubuntu-latest - - environment: - name: testpypi - - # This is the only job that can request an OIDC identity. - permissions: - id-token: write - - steps: - - name: Download wheel - uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 - with: - pattern: "*.whl" - path: dist - merge-multiple: true - - - name: Download sdist - uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 - with: - pattern: "*.tar.gz" - path: dist - merge-multiple: true - - - name: Publish distributions to PyPI - uses: pypa/gh-action-pypi-publish@dc37677b2e1c63e2034f94d8a5b11f265b73ba33 # v1.14.2 - with: - repository-url: https://test.pypi.org/legacy/ diff --git a/setup.py b/setup.py index 4fca6493..031b8a09 100644 --- a/setup.py +++ b/setup.py @@ -18,7 +18,7 @@ setup( # Self-descriptive entries which should always be present - name="mike-OpenMMForceFields", + name="OpenMMForceFields", author="Chodera lab // MSKCC", author_email="john.chodera@choderalab.org", description=short_description[0], @@ -32,7 +32,7 @@ classifiers=[ "Development Status :: 3 - Alpha", "Topic :: Utilities", - "License :: OSI Approved :: MIT License", + "License :: OSI Approved :: MIT", ], # Don't install as an egg, since OpenMM can't find ffxml files if we do zip_safe=False, @@ -53,28 +53,4 @@ ], }, package_data={"openmmforcefields": ["ffxml/amber/*.xml", "ffxml/amber/gaff/*.{xml,dat}", "ffxml/charmm/*.xml"]}, - install_requires=[ - "lxml", - "numpy", - "openff-interchange >=0.4", - "openff-toolkit >=0.16.1", - "openff-units >=0.2", - "openmm >=8.5.1", - "pyyaml", - "tinydb", - "validators", - ], - extras_require = { - 'test': [ - "pytest", - "pytest-cov", - "pytest-randomly", - "pytest-xdist", - "parmed", # needed for some SMIRNOFF tests - ], - # If/when ambertools is on pypi, we can add it here - 'gaff': [ - "parmed", - ], - }, ) From f26ebabdf427813e145be686946504170d8ac6ec Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 20 Nov 2026 17:30:09 +0000 Subject: [PATCH 07/12] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- openmmforcefields/generators/template_generators.py | 5 +---- openmmforcefields/tests/test_template_generators.py | 5 +---- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/openmmforcefields/generators/template_generators.py b/openmmforcefields/generators/template_generators.py index 3e101cbb..c277224b 100644 --- a/openmmforcefields/generators/template_generators.py +++ b/openmmforcefields/generators/template_generators.py @@ -578,10 +578,7 @@ def generate_residue_template(self, molecule): """ import shutil - missing = [ - exe for exe in ("antechamber", "parmchk2") - if shutil.which(exe) is None - ] + missing = [exe for exe in ("antechamber", "parmchk2") if shutil.which(exe) is None] if missing: raise RuntimeError( diff --git a/openmmforcefields/tests/test_template_generators.py b/openmmforcefields/tests/test_template_generators.py index f0c3f459..b03ca6db 100644 --- a/openmmforcefields/tests/test_template_generators.py +++ b/openmmforcefields/tests/test_template_generators.py @@ -104,10 +104,7 @@ def _filter_openff(self, force_field: str) -> bool: # Older force fields require AM1-BCC, which NAGL cannot provide by name. if "ToolkitAM1BCC" in OFFForceField(force_field).registered_parameter_handlers: - if not ( - AmberToolsToolkitWrapper.is_available() - or OpenEyeToolkitWrapper.is_available() - ): + if not (AmberToolsToolkitWrapper.is_available() or OpenEyeToolkitWrapper.is_available()): return False return True From 179c3b3091276e2b1877f1aef92978ca81bb8e37 Mon Sep 17 00:00:00 2001 From: Mike Henry <11765982+mikemhenry@users.noreply.github.com> Date: Fri, 20 Nov 2026 12:42:51 -0700 Subject: [PATCH 08/12] remove parmed as testing dep and make it optional --- .../generators/template_generators.py | 10 ++++- .../tests/test_optional_parmed.py | 42 +++++++++++++++++++ .../tests/test_system_generator.py | 20 +++------ setup.py | 24 +---------- 4 files changed, 59 insertions(+), 37 deletions(-) create mode 100644 openmmforcefields/tests/test_optional_parmed.py diff --git a/openmmforcefields/generators/template_generators.py b/openmmforcefields/generators/template_generators.py index 3e101cbb..116217fc 100644 --- a/openmmforcefields/generators/template_generators.py +++ b/openmmforcefields/generators/template_generators.py @@ -590,6 +590,15 @@ def generate_residue_template(self, molecule): "Install it with: conda install -c conda-forge 'ambertools>=22'" ) + try: + import parmed + except ModuleNotFoundError as exc: + if exc.name != "parmed": + raise + raise RuntimeError( + "ParmEd is required for GAFF parameter assignment. Install it with: pip install parmed" + ) from exc + from openff.units import unit # Use the canonical isomeric SMILES to uniquely name the template @@ -644,7 +653,6 @@ def generate_residue_template(self, molecule): from io import StringIO leaprc = StringIO(f"parm = loadamberparams {frcmod_filename}") - import parmed params = parmed.amber.AmberParameterSet.from_leaprc(leaprc) kwargs = {} diff --git a/openmmforcefields/tests/test_optional_parmed.py b/openmmforcefields/tests/test_optional_parmed.py new file mode 100644 index 00000000..c10668fe --- /dev/null +++ b/openmmforcefields/tests/test_optional_parmed.py @@ -0,0 +1,42 @@ +"""Exercise the optional GAFF-only ParmEd dependency.""" + +import shutil +import subprocess +import sys + +import pytest + +from openmmforcefields.generators import GAFFTemplateGenerator + + +def test_generators_import_without_parmed(): + """Normal imports must not require the optional GAFF dependency.""" + subprocess.run( + [ + sys.executable, + "-c", + "import sys; sys.modules['parmed'] = None; " + "from openmmforcefields.generators import " + "GAFFTemplateGenerator, SMIRNOFFTemplateGenerator, SystemGenerator", + ], + check=True, + capture_output=True, + text=True, + ) + + +def test_gaff_missing_parmed(monkeypatch): + """Report the missing dependency before starting parameter assignment.""" + monkeypatch.setattr(shutil, "which", lambda _: "/usr/bin/mock-ambertools") + monkeypatch.setitem(sys.modules, "parmed", None) + generator = GAFFTemplateGenerator(forcefield="gaff-2.2.20") + with pytest.raises(RuntimeError, match="ParmEd is required for GAFF"): + generator.generate_residue_template(object()) + + +def test_gaff_missing_ambertools_still_reports_ambertools(monkeypatch): + monkeypatch.setattr(shutil, "which", lambda _: None) + monkeypatch.setitem(sys.modules, "parmed", None) + generator = GAFFTemplateGenerator(forcefield="gaff-2.2.20") + with pytest.raises(RuntimeError, match="AmberTools is required for GAFF"): + generator.generate_residue_template(object()) diff --git a/openmmforcefields/tests/test_system_generator.py b/openmmforcefields/tests/test_system_generator.py index fa32eb00..62b5e0bc 100644 --- a/openmmforcefields/tests/test_system_generator.py +++ b/openmmforcefields/tests/test_system_generator.py @@ -53,19 +53,11 @@ def test_systems(): n_molecules = MAX_MOLECULES molecules = [molecules[index] for index in range(n_molecules)] - # Create structures - import parmed - - # NOTE: This does not work because parmed does not correctly assign bonds for HID - # protein_structure = parmed.load_file(pdb_filename) - # NOTE: This is the workaround - protein_structure = parmed.openmm.load_topology(pdbfile.topology, xyz=pdbfile.positions) - - molecules_structure = parmed.load_file(sdf_filename) - molecules_structure = [molecules_structure[index] for index in range(n_molecules)] - - complex_structures = [(molecules_structure[index] + protein_structure) for index in range(n_molecules)] - complex_structures = [molecules_structure[index] for index in range(n_molecules)] # DEBUG + # The existing tests exercise ligand-only structures, so build them + # directly with OpenMM instead of requiring ParmEd. + complex_structures = [ + Modeller(molecule.to_topology().to_openmm(), molecule.conformers[0].to_openmm()) for molecule in molecules + ] # Store testsystem = { @@ -532,7 +524,7 @@ def test_complex(self, test_systems): cache=cache, ) system = generator.create_system(openmm_topology) - assert system.getNumParticles() == len(complex_structure.atoms) + assert system.getNumParticles() == len(list(complex_structure.topology.atoms())) # Create solvated structure modeller = Modeller(complex_structure.topology, complex_structure.positions) diff --git a/setup.py b/setup.py index a218f022..031b8a09 100644 --- a/setup.py +++ b/setup.py @@ -18,7 +18,7 @@ setup( # Self-descriptive entries which should always be present - name="mike-OpenMMForceFields", + name="OpenMMForceFields", author="Chodera lab // MSKCC", author_email="john.chodera@choderalab.org", description=short_description[0], @@ -32,7 +32,7 @@ classifiers=[ "Development Status :: 3 - Alpha", "Topic :: Utilities", - "License :: OSI Approved :: MIT License", + "License :: OSI Approved :: MIT", ], # Don't install as an egg, since OpenMM can't find ffxml files if we do zip_safe=False, @@ -53,24 +53,4 @@ ], }, package_data={"openmmforcefields": ["ffxml/amber/*.xml", "ffxml/amber/gaff/*.{xml,dat}", "ffxml/charmm/*.xml"]}, - install_requires=[ - "lxml", - "numpy", - "openff-interchange >=0.4", - "openff-toolkit >=0.16.1", - "openff-units >=0.2", - "openmm >=8.5.1", - "pyyaml", - "tinydb", - "validators", - "parmed", # might not need in this pass - ], - extras_require = { - 'test': [ - "pytest", - "pytest-cov", - "pytest-randomly", - "pytest-xdist", - ], - }, ) From ba26facf056fc79113d5a2b0af9769e06b8677a1 Mon Sep 17 00:00:00 2001 From: Mike Henry <11765982+mikemhenry@users.noreply.github.com> Date: Fri, 20 Nov 2026 12:55:57 -0700 Subject: [PATCH 09/12] we can't remove parmed as a testing dep so lest keep this bit --- .../tests/test_system_generator.py | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/openmmforcefields/tests/test_system_generator.py b/openmmforcefields/tests/test_system_generator.py index 62b5e0bc..fa32eb00 100644 --- a/openmmforcefields/tests/test_system_generator.py +++ b/openmmforcefields/tests/test_system_generator.py @@ -53,11 +53,19 @@ def test_systems(): n_molecules = MAX_MOLECULES molecules = [molecules[index] for index in range(n_molecules)] - # The existing tests exercise ligand-only structures, so build them - # directly with OpenMM instead of requiring ParmEd. - complex_structures = [ - Modeller(molecule.to_topology().to_openmm(), molecule.conformers[0].to_openmm()) for molecule in molecules - ] + # Create structures + import parmed + + # NOTE: This does not work because parmed does not correctly assign bonds for HID + # protein_structure = parmed.load_file(pdb_filename) + # NOTE: This is the workaround + protein_structure = parmed.openmm.load_topology(pdbfile.topology, xyz=pdbfile.positions) + + molecules_structure = parmed.load_file(sdf_filename) + molecules_structure = [molecules_structure[index] for index in range(n_molecules)] + + complex_structures = [(molecules_structure[index] + protein_structure) for index in range(n_molecules)] + complex_structures = [molecules_structure[index] for index in range(n_molecules)] # DEBUG # Store testsystem = { @@ -524,7 +532,7 @@ def test_complex(self, test_systems): cache=cache, ) system = generator.create_system(openmm_topology) - assert system.getNumParticles() == len(list(complex_structure.topology.atoms())) + assert system.getNumParticles() == len(complex_structure.atoms) # Create solvated structure modeller = Modeller(complex_structure.topology, complex_structure.positions) From 9baa95260156b1d5ba94ada8d113d1fb6f1c7819 Mon Sep 17 00:00:00 2001 From: Mike Henry <11765982+mikemhenry@users.noreply.github.com> Date: Fri, 20 Nov 2026 13:36:23 -0700 Subject: [PATCH 10/12] update filter so we don't call `OFFForceField('gaff-1.4')` when checking if `AmberToolsToolkitWrapper.is_available()` --- openmmforcefields/tests/test_template_generators.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/openmmforcefields/tests/test_template_generators.py b/openmmforcefields/tests/test_template_generators.py index b03ca6db..12ac20f0 100644 --- a/openmmforcefields/tests/test_template_generators.py +++ b/openmmforcefields/tests/test_template_generators.py @@ -77,9 +77,13 @@ def filter_molecules( def _filter_openff(self, force_field: str) -> bool: """ - Return True only for Parsley and force fields among SMIRNOFF force fields. + Return whether a force field should be included in parameterization tests. - Skips over (returns False) smirnoff99Frosst, ff14SB, water models, and 2.0.0rc1. + Skip protein and solvent force fields, smirnoff99Frosst, and OpenFF + 2.0.0-rc.1. Also skip SMIRNOFF force fields requiring ToolkitAM1BCC + when neither AmberTools nor OpenEye is available. + + GAFF force fields are accepted without SMIRNOFF validation. """ if "ff14sb" in force_field: @@ -102,6 +106,10 @@ def _filter_openff(self, force_field: str) -> bool: if "smirnoff99" in force_field: return False + # GAFF is not a SMIRNOFF force field. + if force_field.startswith("gaff-"): + return True + # Older force fields require AM1-BCC, which NAGL cannot provide by name. if "ToolkitAM1BCC" in OFFForceField(force_field).registered_parameter_handlers: if not (AmberToolsToolkitWrapper.is_available() or OpenEyeToolkitWrapper.is_available()): From 0354cbd69d8a959063d7539a74c4ea330c8c89b1 Mon Sep 17 00:00:00 2001 From: Mike Henry <11765982+mikemhenry@users.noreply.github.com> Date: Fri, 20 Nov 2026 15:22:00 -0700 Subject: [PATCH 11/12] Update openmmforcefields/tests/test_optional_parmed.py Co-authored-by: Evan Pretti --- openmmforcefields/tests/test_optional_parmed.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openmmforcefields/tests/test_optional_parmed.py b/openmmforcefields/tests/test_optional_parmed.py index c10668fe..e61bf603 100644 --- a/openmmforcefields/tests/test_optional_parmed.py +++ b/openmmforcefields/tests/test_optional_parmed.py @@ -10,7 +10,7 @@ def test_generators_import_without_parmed(): - """Normal imports must not require the optional GAFF dependency.""" + """Normal imports must not require the optional ParmEd dependency for GAFF.""" subprocess.run( [ sys.executable, From 62dab92a2c0f57618445f7dfd06c703e3afbd05a Mon Sep 17 00:00:00 2001 From: Mike Henry <11765982+mikemhenry@users.noreply.github.com> Date: Fri, 20 Nov 2026 15:23:50 -0700 Subject: [PATCH 12/12] update the invalid ff to look more like a current valid one --- openmmforcefields/tests/test_template_generators.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openmmforcefields/tests/test_template_generators.py b/openmmforcefields/tests/test_template_generators.py index 12ac20f0..d384c42f 100644 --- a/openmmforcefields/tests/test_template_generators.py +++ b/openmmforcefields/tests/test_template_generators.py @@ -1180,7 +1180,7 @@ def test_forcefield_unconstrained(self): # Should not point to any valid force field with pytest.raises(ValueError, match="Can't load or parse specified SMIRNOFF"): - SMIRNOFFTemplateGenerator(forcefield="openff_unconstrained-2.0.0") + SMIRNOFFTemplateGenerator(forcefield="openff_unconstrained-2.3.0") # Specifying a name with .offxml should never get modified generator = SMIRNOFFTemplateGenerator(forcefield="openff-2.3.0.offxml")