Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow Pydantic v2 in test environments #1684

Open
wants to merge 21 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@ defaults:
jobs:
test:
if: (github.event_name == 'schedule' && github.repository == 'openforcefield/openff-toolkit') || (github.event_name != 'schedule')
name: Test on ${{ matrix.os }}, Python ${{ matrix.python-version }}, RDKit=${{ matrix.rdkit }}, OpenEye=${{ matrix.openeye }}
name: Test on ${{ matrix.os }}, Python ${{ matrix.python-version }}, RDKit=${{ matrix.rdkit }}, OpenEye=${{ matrix.openeye }}, Pydantic v${{ matrix.pydantic-version }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest]
python-version: ["3.9", "3.10", "3.11"]
pydantic-version: ["1", "2"]
rdkit: [true, false]
openeye: [true, false]
exclude:
Expand Down Expand Up @@ -79,6 +80,7 @@ jobs:
environment-file: devtools/conda-envs/${{ env.ENVFILE }}.yaml
create-args: >-
python=${{ matrix.python-version }}
pydantic=${{ matrix.pydantic-version }}

- name: Additional info about the build
run: |
Expand Down Expand Up @@ -106,6 +108,10 @@ jobs:
run: |
python -m pip install utilities/test_plugins

- name: Install QCPortal
if: ${{ matrix.pydantic-version == 1 }}
run: micromamba install qcelemental "qcportal ==0.15.8" -c conda-forge

- name: Remove undesired toolkits
run: |
if [ ! -z "${{ env.PACKAGES_TO_REMOVE }}" ]; then
Expand Down Expand Up @@ -162,12 +168,12 @@ jobs:
pytest -v --no-cov --doctest-glob="docs/*.rst" --doctest-glob="docs/*.md" docs/

- name: Run notebooks in docs
if: ${{ matrix.rdkit == true && matrix.openeye == true }}
if: ${{ matrix.rdkit == true && matrix.openeye == true && matrix.pydantic-version == 1 }}
run: |
pytest -v --no-cov --durations=5 --nbval --ignore docs/_build/ docs/

- name: Run examples in docstrings
if: ${{ matrix.rdkit == true && matrix.openeye == true }}
if: ${{ matrix.rdkit == true && matrix.openeye == true && matrix.pydantic-version == 1 }}
run: |
pytest openff \
-v -x -n logical --no-cov --doctest-modules \
Expand Down
5 changes: 5 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ ci:
autoupdate_schedule: "quarterly"
files: ^openff|(^examples/((?!deprecated).)*$)|^docs
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: end-of-file-fixer
exclude: '\.(json|pdb)$'
- repo: https://github.com/psf/black
rev: 24.1.1
hooks:
Expand Down
2 changes: 0 additions & 2 deletions devtools/conda-envs/beta_rc_env.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ dependencies:
- mdtraj
- nbval
- mypy
- typing_extensions
- pydantic =1
- pip:
- types-setuptools
- types-toml
Expand Down
1 change: 0 additions & 1 deletion devtools/conda-envs/openeye-examples.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ channels:
dependencies:
# Base depends
- python
- pydantic =1
- packaging
- numpy
- networkx
Expand Down
3 changes: 1 addition & 2 deletions devtools/conda-envs/openeye.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ channels:
dependencies:
# Base depends
- python
- pydantic =1
- packaging
- numpy
- networkx
Expand Down Expand Up @@ -39,4 +38,4 @@ dependencies:
- qcengine
- mdtraj
- nglview
- parmed =3
- parmed =3
1 change: 0 additions & 1 deletion devtools/conda-envs/rdkit-examples.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ channels:
dependencies:
# Base depends
- python
- pydantic =1
- packaging
- numpy
- networkx
Expand Down
1 change: 0 additions & 1 deletion devtools/conda-envs/rdkit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ channels:
dependencies:
# Base depends
- python
- pydantic =1
- packaging
- numpy
- networkx
Expand Down
3 changes: 1 addition & 2 deletions devtools/conda-envs/test_env.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,8 @@ dependencies:
- nomkl
- mypy
- typing_extensions
- pydantic =1
- pip:
- types-setuptools
- types-toml
- types-PyYAML
- mongo-types
- mongo-types
2 changes: 1 addition & 1 deletion docs/_static/images/favicon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion docs/_templates/autosummary/base.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ but free functions do not.

.. currentmodule:: {{ module }}

.. auto{{ objtype }}:: {{ objname }}
.. auto{{ objtype }}:: {{ objname }}
1 change: 0 additions & 1 deletion docs/topology.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,3 @@ including offering serialization to a variety of standard formats (including [XM
HierarchyScheme
HierarchyElement
```

2 changes: 1 addition & 1 deletion docs/users/figures/vsite_examples.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion docs/users/figures/vsite_matches.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion docs/users/figures/vsite_matches_name.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion docs/users/figures/vsite_smirks_to_particle.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion docs/users/smirnoff.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,4 @@ general or as specific as needed.
:::{hint}
This page is not the SMIRNOFF spec; it has been moved to the
[standards repository].
:::
:::
1 change: 0 additions & 1 deletion docs/utils.rst
Original file line number Diff line number Diff line change
Expand Up @@ -162,4 +162,3 @@ Exceptions raised by the Toolkit.
:toctree: api/generated/

exceptions

2 changes: 1 addition & 1 deletion examples/conformer_energies/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
ruxolitinib.csv
ruxolitinib_conf*_minimized.sdf
ruxolitinib_conf*_minimized.sdf
1 change: 0 additions & 1 deletion examples/external/swap_amber_parameters/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@ This example illustrates how the [ParmEd](http://parmed.github.io/ParmEd/html/in
### BRD4:inhibitor complex

* [`swap_existing_ligand_parameters.ipynb`](swap_existing_ligand_parameters.ipynb) contains an example illustrating taking a fully parameterized BRD4 protein-ligand system, with an AMBER protein force field and GAFF ligand parameters, and replacing the ligand parameters with OpenFF parameters from SMIRNOFF format. The BRD4:inhibitor complex is taken from the [free energy benchmark systems living review](https://www.annualreviews.org/doi/abs/10.1146/annurev-biophys-070816-033654) [GitHub repo](https://github.com/MobleyLab/benchmarksets/tree/master/input_files/BRD4).

Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
complex.*
receptor.*
ligand.*
ligand.*
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@
### BRD4:inhibitor complex

[`BRD4_inhibitor_benchmark.ipynb`](BRD4_inhibitor_benchmark.ipynb) contains an example illustrating applying Sage and ff14SB parameters to a BRD4:inhibitor complex taken from the [free energy benchmark systems living review](https://www.annualreviews.org/doi/abs/10.1146/annurev-biophys-070816-033654) [GitHub repo](https://github.com/MobleyLab/benchmarksets/tree/master/input_files/BRD4).

1 change: 0 additions & 1 deletion examples/toolkit_showcase/sim.mdp
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,3 @@ constraint-algorithm = LINCS ; Use fast and stable LINCS constraint algorithm
continuation = no ; Apply constraints to the initial configuration (important since energy minimisation was unconstrained)
lincs-order = 4 ; Increase if you get LINCS errors
lincs-iter = 1 ; Increase if you get LINCS errors

11 changes: 9 additions & 2 deletions openff/toolkit/_tests/test_molecule.py
Original file line number Diff line number Diff line change
Expand Up @@ -3417,8 +3417,8 @@ def test_qcschema_molecule_record_round_trip_from_to_from(self):
Molecule.from_qcschema(mol_dict)


@requires_pkg("IPython")
class TestMoleculeVisualization:
@requires_pkg("IPython")
@requires_rdkit
def test_visualize_rdkit(self):
"""
Expand Down Expand Up @@ -3476,8 +3476,15 @@ def test_visualize_openeye(self):
)
def test_ipython_repr_no_nglview(self):
"""Test that the default Molecule repr does not break when nglview is not installed"""
from openff.toolkit.utils.toolkits import OPENEYE_AVAILABLE, RDKIT_AVAILABLE

molecule = Molecule().from_smiles("CCO")
molecule._ipython_display_()

if RDKIT_AVAILABLE:
# the default is `backend="rdkit"`
molecule.visualize()
elif OPENEYE_AVAILABLE:
molecule.visualize(backend="openeye")

def test_get_coordinates(self):
from openff.toolkit.utils._viz import MoleculeNGLViewTrajectory
Expand Down
56 changes: 3 additions & 53 deletions openff/toolkit/_tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import collections
import copy
import functools
import importlib
import itertools
import os
import pprint
Expand All @@ -17,6 +16,7 @@
import openmm
import pytest
from openff.units.openmm import to_openmm
from openff.utilities import has_package, skip_if_missing
from openmm import unit as openmm_unit

from openff.toolkit import unit
Expand Down Expand Up @@ -45,59 +45,9 @@
)


def has_pkg(pkg_name):
"""
Helper function to generically check if a package is installed. Intended
to be used to check for optional dependencies.

Parameters
----------
pkg_name : str
The name of the package to check the availability of

Returns
-------
pkg_available : bool
Boolean indicator if the package is available or not
has_pkg = has_package

Examples
--------
>>> has_numpy = has_pkg('numpy')
>>> has_numpy
True
>>> has_foo = has_pkg('other_non_installed_pkg')
>>> has_foo
False
"""
try:
importlib.import_module(pkg_name)
except ModuleNotFoundError:
return False
return True


def requires_pkg(pkg_name, reason=None):
"""
Helper function to generate a pytest.mark.skipif decorator
for any package. This allows tests to be skipped if some
optional dependency is not found.

Parameters
----------
pkg_name : str
The name of the package that is required for a test(s)
reason : str, optional
Explanation of why the skipped it to be tested

Returns
-------
requires_pkg : _pytest.mark.structures.MarkDecorator
A pytest decorator that will skip tests if the package is not available
"""
if not reason:
reason = f"Package {pkg_name} is required, but was not found."
requires_pkg = pytest.mark.skipif(not has_pkg(pkg_name), reason=reason)
return requires_pkg
requires_pkg = skip_if_missing


@contextmanager
Expand Down
1 change: 0 additions & 1 deletion openff/toolkit/data/molecules/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,3 @@ contains all the molecules in `AlkEthOH_tripos.tar.gz/AlkEthOH_test_filt1`.
**For all molecule sets**
- `*` = `ff` for parm@frosst atom types
- `*` = `tripos` for tripos atom types

2 changes: 1 addition & 1 deletion openff/toolkit/data/molecules/z_3_hydroxy_propenal.sdf
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@
3 8 1 0 0 0 0
4 9 1 0 0 0 0
M END
$$$$
$$$$
2 changes: 1 addition & 1 deletion openff/toolkit/data/reference_energies/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
- `reference_after_802.json` - generated by `openff/toolkit/tests/test_energies.py` with conda environment reference_after_802.txt, corresponds to commit 02dba85c51dcff3ee3426d2a407811ac9bac1749 in PR #802, between 0.9.0 and 0.9.1
- `reference_after_1007.json` - generated by `openff/toolkit/tests/test_energies.py` with conda environment reference_after_1007.txt, corresponds to commit 6ac06efb7d0e91a960325cfc45874500af52274c in PR #948, between 0.9.2 and 0.9.3.
This change tracks the effect of partial charge normalization on the reference energies of the test set.
Note that that PR #948 was superseded by #1007, since it #948 gained an irreconcilably large merge conflict with master during its development.
Note that that PR #948 was superseded by #1007, since it #948 gained an irreconcilably large merge conflict with master during its development.
Original file line number Diff line number Diff line change
Expand Up @@ -347,4 +347,4 @@ dependencies:
- pytraj==2.0.5
- sander==16.0
- z3-solver==4.8.10.0
prefix: /Users/jeffreywagner/miniconda3/envs/off-tk-dev
prefix: /Users/jeffreywagner/miniconda3/envs/off-tk-dev
1 change: 0 additions & 1 deletion openff/toolkit/data/test_forcefields/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,3 @@
- `GBSA_HCT-1.0.offxml`: An experimental force field used in validation tests against OpenMM's implementation of the [Hawkins-Cramer-Truhlar](http://docs.openmm.org/latest/userguide/zbibliography.html#hawkins1995) GBSA model (corresponding to igb=1 in AMBER)
- `GBSA_OBC1-1.0.offxml`: An experimental force field used in validation tests against OpenMM's implementation of the [Onufriev-Bashford-Case](http://docs.openmm.org/latest/userguide/zbibliography.html#onufriev2004) using the GB(OBC)I model (corresponding to igb=2 in AMBER)
- `GBSA_OBC2-1.0.offxml`: An experimental force field used in validation tests against OpenMM's implementation of the [Onufriev-Bashford-Case](http://docs.openmm.org/latest/userguide/zbibliography.html#onufriev2004) using the GB(OBC)II model (corresponding to igb=5 in AMBER)

Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,3 @@ MOD4 RE
CT 1.9080 0.1094 PrmIdVdw008 Spellmeyer

END

Original file line number Diff line number Diff line change
Expand Up @@ -326,4 +326,4 @@
<Atom smirks="[#35:1]" epsilon="0.32 * mole**-1 * kilocalorie" id="n26" rmin_half="2.22 * angstrom"></Atom>
<Atom smirks="[#53:1]" epsilon="0.4 * mole**-1 * kilocalorie" id="n27" rmin_half="2.35 * angstrom"></Atom>
</vdW>
</SMIRNOFF>
</SMIRNOFF>
Original file line number Diff line number Diff line change
Expand Up @@ -334,4 +334,4 @@
<Atom smirks="[#35X0-1:1]" epsilon="0.0586554 * mole**-1 * kilocalorie" id="n34" rmin_half="2.608 * angstrom"></Atom>
<Atom smirks="[#53X0-1:1]" epsilon="0.0536816 * mole**-1 * kilocalorie" id="n35" rmin_half="2.86 * angstrom"></Atom>
</vdW>
</SMIRNOFF>
</SMIRNOFF>
Original file line number Diff line number Diff line change
Expand Up @@ -334,4 +334,4 @@
<Atom smirks="[#35X0-1:1]" epsilon="0.0586554 * mole**-1 * kilocalorie" id="n34" rmin_half="2.608 * angstrom"></Atom>
<Atom smirks="[#53X0-1:1]" epsilon="0.0536816 * mole**-1 * kilocalorie" id="n35" rmin_half="2.86 * angstrom"></Atom>
</vdW>
</SMIRNOFF>
</SMIRNOFF>
1 change: 1 addition & 0 deletions openff/toolkit/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ def get_data_file_path(relative_path: str) -> str:

_DATA_ROOT = files("openff.toolkit") / "data"

# mypy unhappy because this might not return a path, might be fixed with 3.10+
file_path = _DATA_ROOT / relative_path

if not file_path.exists(): # type: ignore[attr-defined]
Expand Down
Loading