From 303e6f4c3f0142c89865eef77fd945300d7f3f91 Mon Sep 17 00:00:00 2001 From: Michael Howard Date: Mon, 9 Dec 2024 09:41:55 -0600 Subject: [PATCH] Update to HOOMD 5 (#95) * Support HOOMD 5 build configuration * Add new required method to anisotropic pair potentials * Update readthedocs environment * Run pre-commit on all files * Cleanup automock list --- .github/workflows/unit-test.yaml | 2 +- .pre-commit-config.yaml | 9 ++- .readthedocs.yaml | 10 ++-- .ruff.toml | 54 ------------------ CMakeLists.txt | 2 +- doc/conf.py | 81 +++++++++++++-------------- doc/environment.yaml | 4 +- doc/mock_install.py | 6 +- ruff.toml | 43 ++++++++++++++ src/AnisoPairEvaluator.h | 5 ++ src/AnisoPairEvaluatorTwoPatchMorse.h | 5 ++ src/__init__.py | 2 +- src/bond.py | 12 ++-- src/conftest.py | 4 +- src/flow.py | 8 ++- src/pair.py | 72 +++++++++++++----------- src/pytest/test_bond.py | 10 ++-- src/pytest/test_pair.py | 54 +++++++++--------- src/pytest/test_pair_aniso.py | 72 ++++++++++++------------ src/pytest/test_pair_dpd.py | 2 +- 20 files changed, 230 insertions(+), 227 deletions(-) delete mode 100644 .ruff.toml create mode 100644 ruff.toml diff --git a/.github/workflows/unit-test.yaml b/.github/workflows/unit-test.yaml index f4b55a50..5e9c26f1 100644 --- a/.github/workflows/unit-test.yaml +++ b/.github/workflows/unit-test.yaml @@ -8,7 +8,7 @@ env: ############################################################################################# # HOOMD-blue version to build. - HOOMD_BLUE_VERSION: v4.8.2 + HOOMD_BLUE_VERSION: v5.0.0 # prevent deadlocked MPI tests from causing the job to cancel MPIEXEC_TIMEOUT: 3000 # allow mpirun to execute as root in the tests diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index fd6dd03e..db664a61 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -14,9 +14,6 @@ repos: - id: check-json - id: check-yaml - id: check-case-conflict - - id: fix-encoding-pragma - args: - - --remove - id: mixed-line-ending - repo: https://github.com/glotzerlab/fix-license-header rev: v0.4.1 @@ -48,12 +45,14 @@ repos: - --keep-after=.. automodule - --comment-prefix=.. - repo: https://github.com/pre-commit/mirrors-clang-format - rev: v19.1.1 + rev: v19.1.4 hooks: - id: clang-format types_or: [c, c++, cuda, inc] - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.6.9 + rev: v0.8.1 hooks: - id: ruff-format + types_or: [python] - id: ruff + types_or: [python] diff --git a/.readthedocs.yaml b/.readthedocs.yaml index 5b2dd203..053b527e 100644 --- a/.readthedocs.yaml +++ b/.readthedocs.yaml @@ -5,14 +5,14 @@ sphinx: fail_on_warning: true build: - os: ubuntu-22.04 + os: ubuntu-24.04 tools: - python: "mambaforge-22.9" + python: "mambaforge-23.11" jobs: post_install: - - wget https://github.com/glotzerlab/hoomd-blue/releases/download/v4.8.2/hoomd-4.8.2.tar.gz - - tar -xzvf hoomd-4.8.2.tar.gz - - python doc/mock_install.py hoomd-4.8.2/hoomd src + - wget https://github.com/glotzerlab/hoomd-blue/releases/download/v5.0.0/hoomd-5.0.0.tar.gz + - tar -xzvf hoomd-5.0.0.tar.gz + - python doc/mock_install.py hoomd-5.0.0/hoomd src conda: environment: doc/environment.yaml diff --git a/.ruff.toml b/.ruff.toml deleted file mode 100644 index faef7fa0..00000000 --- a/.ruff.toml +++ /dev/null @@ -1,54 +0,0 @@ -target-version = "py38" - -[lint] - -extend-select = [ - "A", - "B", - "D", - "E501", - "EM", - "I", - "ICN", - "ISC", - "N", - "NPY", - "PL", - "PT", - "RET", - "RUF", - "UP", - "W", -] - -ignore = [ - "N806", "N803", # Allow occasional use of uppercase variable and argument names (e.g. N). - "D107", # Do not document __init__ separately from the class. - "PLR09", # Allow "too many" statements/arguments/etc... - "N816", # Allow mixed case names like kT. -] - -[lint.per-file-ignores] - -"__init__.py" = ["F401", # __init__.py import submodules for use by the package importer. -] -"*/pytest/*.py" = ["PLR2004", # allow "magic numbers" in tests -] - -[lint.pydocstyle] -convention = "google" - -[lint.flake8-import-conventions] -# Prefer no import aliases -aliases = {} -# Always import hoomd without 'from' -banned-from = ["hoomd"] - -# Ban standard import conventions and force common packages to be imported by their actual name. -[lint.flake8-import-conventions.banned-aliases] -"numpy" = ["np"] -"pandas" = ["pd"] -"matplotlib" = ["mpl"] - -[format] -quote-style = "single" diff --git a/CMakeLists.txt b/CMakeLists.txt index 9cec8227..cfa4d7ce 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,7 +5,7 @@ CMAKE_MINIMUM_REQUIRED(VERSION 3.9 FATAL_ERROR) project(azplugins LANGUAGES C CXX) # Find the installed HOOMD. -find_package(HOOMD 4.0.0 REQUIRED) +find_package(HOOMD 5.0.0 REQUIRED) message(STATUS "Found HOOMD ${HOOMD_VERSION}: ${HOOMD_INSTALL_PREFIX}/${PYTHON_SITE_INSTALL_DIR}") diff --git a/doc/conf.py b/doc/conf.py index 6fc093c8..387aacf2 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -14,79 +14,76 @@ import datetime import os -project = 'azplugins' +project = "azplugins" year = datetime.date.today().year -copyright = f'2018-2020, Michael P. Howard. 2021-{year}, Auburn University.' # noqa: A001 -author = 'Michael P. Howard' -release = '1.0.0' +copyright = f"2018-2020, Michael P. Howard. 2021-{year}, Auburn University." +author = "Michael P. Howard" +release = "1.0.0" # -- General configuration --------------------------------------------------- # https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration -default_role = 'any' +default_role = "any" -templates_path = ['_templates'] -exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store'] +templates_path = ["_templates"] +exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"] extensions = [ - 'sphinx.ext.mathjax', + "sphinx.ext.mathjax", ] -extensions += ['sphinx.ext.autodoc', 'sphinx.ext.autosummary'] +extensions += ["sphinx.ext.autodoc", "sphinx.ext.autosummary"] autodoc_docstring_signature = True -autodoc_typehints_format = 'short' -autodoc_mock_imports = ['hoomd.azplugins._azplugins'] -if os.getenv('READTHEDOCS'): +autodoc_typehints_format = "short" +autodoc_mock_imports = ["hoomd.azplugins._azplugins"] +if os.getenv("READTHEDOCS"): autodoc_mock_imports += [ - 'hoomd._hoomd', - 'hoomd.version_config', - 'hoomd.md._md', - 'hoomd.metal._metal', - 'hoomd.mpcd._mpcd', - 'hoomd.minimize._minimize', - 'hoomd.hpmc._jit', - 'hoomd.hpmc._hpmc', + "hoomd._hoomd", + "hoomd.version_config", + "hoomd.hpmc._hpmc", + "hoomd.md._md", + "hoomd.mpcd._mpcd", ] -extensions += ['sphinx.ext.napoleon'] +extensions += ["sphinx.ext.napoleon"] napoleon_include_special_with_doc = True -extensions += ['sphinx.ext.intersphinx'] +extensions += ["sphinx.ext.intersphinx"] intersphinx_mapping = { - 'python': ('https://docs.python.org/3', None), - 'numpy': ('https://numpy.org/doc/stable', None), - 'gsd': ('https://gsd.readthedocs.io/en/stable/', None), - 'hoomd': ('https://hoomd-blue.readthedocs.io/en/stable/', None), + "python": ("https://docs.python.org/3", None), + "numpy": ("https://numpy.org/doc/stable", None), + "gsd": ("https://gsd.readthedocs.io/en/stable/", None), + "hoomd": ("https://hoomd-blue.readthedocs.io/en/stable/", None), } -extensions += ['sphinx.ext.todo'] +extensions += ["sphinx.ext.todo"] todo_include_todos = False -extensions += ['sphinx_copybutton'] -copybutton_prompt_text = '$ ' +extensions += ["sphinx_copybutton"] +copybutton_prompt_text = "$ " copybutton_remove_prompts = True -copybutton_line_continuation_character = '\\' +copybutton_line_continuation_character = "\\" # -- Options for HTML output ------------------------------------------------- # https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output -html_theme = 'furo' -html_static_path = ['_static'] +html_theme = "furo" +html_static_path = ["_static"] # html_logo = "hoomdblue-logo-vertical.svg" html_theme_options = { # "sidebar_hide_name": True, - 'top_of_page_buttons': [], - 'navigation_with_keys': True, - 'dark_css_variables': { - 'color-brand-primary': '#5187b2', - 'color-brand-content': '#5187b2', + "top_of_page_buttons": [], + "navigation_with_keys": True, + "dark_css_variables": { + "color-brand-primary": "#5187b2", + "color-brand-content": "#5187b2", }, - 'light_css_variables': { - 'color-brand-primary': '#406a8c', - 'color-brand-content': '#406a8c', + "light_css_variables": { + "color-brand-primary": "#406a8c", + "color-brand-content": "#406a8c", }, } # html_favicon = "hoomdblue-logo-favicon.svg" -pygments_style = 'friendly' -pygments_dark_style = 'native' +pygments_style = "friendly" +pygments_dark_style = "native" diff --git a/doc/environment.yaml b/doc/environment.yaml index ab80ea28..86b581fa 100644 --- a/doc/environment.yaml +++ b/doc/environment.yaml @@ -4,8 +4,8 @@ channels: - defaults dependencies: - python=3.12 - - numpy=2.1.2 + - numpy=2.1.3 - sphinx=8.1.3 - furo=2024.8.6 - - tornado=6.4.1 + - tornado=6.4.2 - sphinx-copybutton=0.5.2 diff --git a/doc/mock_install.py b/doc/mock_install.py index f8ccbc19..98227351 100644 --- a/doc/mock_install.py +++ b/doc/mock_install.py @@ -13,13 +13,13 @@ install_dir = Path(site.getsitepackages()[0]) hoomd_dir = Path(sys.argv[1]) -for file in hoomd_dir.rglob('*.py'): +for file in hoomd_dir.rglob("*.py"): relative_file = file.relative_to(hoomd_dir.parent) os.makedirs(install_dir / relative_file.parent, exist_ok=True) shutil.copy(file, install_dir / relative_file.parent) azplugins_dir = Path(sys.argv[2]) -for file in azplugins_dir.rglob('*.py'): - relative_file = Path('hoomd') / 'azplugins' / file.relative_to(azplugins_dir) +for file in azplugins_dir.rglob("*.py"): + relative_file = Path("hoomd") / "azplugins" / file.relative_to(azplugins_dir) os.makedirs(install_dir / relative_file.parent, exist_ok=True) shutil.copy(file, install_dir / relative_file.parent) diff --git a/ruff.toml b/ruff.toml new file mode 100644 index 00000000..24fdda2d --- /dev/null +++ b/ruff.toml @@ -0,0 +1,43 @@ +include = ["*.py"] +extend-exclude = [".git", + "__pycache__", + "build", + ] +line-length = 88 +indent-width = 4 + +[lint] +select = [ + "E", + "F", + "N", + "W", + "D", + "NPY", + "RUF", +] +ignore = [ + "D105", # Magic methods don't require documentation + "D107", # do not document __init__ separately from the class + "D301", # Allow backslashes in docstrings + "D205", "D415", # Allow no summary line. The rendered Sphinx documentation is cleaner without them. + "N816", "N806","N803", # allow occasional use of uppercase variable and argument names + "D214", # ignore overindented sections in Trigger - this is Google napoleon formatting + "RUF012", # hoomd does not use typing annotations + "NPY002", # TODO: refactor tests to use modern numpy Generator API. +] + +[lint.pydocstyle] +convention = "google" + +[lint.per-file-ignores] +# allow unused imports in init files +"__init__.py" = ["F401"] +# do not require docstrings in unit test or documentation example files +"**/pytest/*" = ["D", "F811", "N999"] + +[format] +indent-style = "space" +line-ending = "auto" +docstring-code-line-length = 72 +docstring-code-format = true diff --git a/src/AnisoPairEvaluator.h b/src/AnisoPairEvaluator.h index 76c171cf..76d536b2 100644 --- a/src/AnisoPairEvaluator.h +++ b/src/AnisoPairEvaluator.h @@ -196,6 +196,11 @@ class AnisoPairEvaluator throw std::runtime_error("Name not defined for this pair potential."); } + static std::string getShapeParamName() + { + throw std::runtime_error("Shape name not defined for this pair potential."); + } + std::string getShapeSpec() const { throw std::runtime_error("Shape definition not supported for this pair potential."); diff --git a/src/AnisoPairEvaluatorTwoPatchMorse.h b/src/AnisoPairEvaluatorTwoPatchMorse.h index 4aefe8ed..4691ab15 100644 --- a/src/AnisoPairEvaluatorTwoPatchMorse.h +++ b/src/AnisoPairEvaluatorTwoPatchMorse.h @@ -220,6 +220,11 @@ class AnisoPairEvaluatorTwoPatchMorse : public AnisoPairEvaluator { return std::string("TwoPatchMorse"); } + + static std::string getShapeParamName() + { + return std::string(""); + } #endif private: diff --git a/src/__init__.py b/src/__init__.py index 740d46fe..872f73b6 100644 --- a/src/__init__.py +++ b/src/__init__.py @@ -6,4 +6,4 @@ from hoomd.azplugins import bond, flow, pair -__version__ = '1.0.0' +__version__ = "1.0.0" diff --git a/src/bond.py b/src/bond.py index a6dd858c..3f080b1b 100644 --- a/src/bond.py +++ b/src/bond.py @@ -51,13 +51,13 @@ class DoubleWell(bond.Bond): """ _ext_module = _azplugins - _cpp_class_name = 'PotentialBondDoubleWell' + _cpp_class_name = "PotentialBondDoubleWell" def __init__(self): super().__init__() params = TypeParameter( - 'params', - 'bond_types', + "params", + "bond_types", TypeParameterDict( r_0=float, r_1=float, U_1=float, U_tilt=float, len_keys=1 ), @@ -135,13 +135,13 @@ class Quartic(bond.Bond): """ _ext_module = _azplugins - _cpp_class_name = 'PotentialBondQuartic' + _cpp_class_name = "PotentialBondQuartic" def __init__(self): super().__init__() params = TypeParameter( - 'params', - 'bond_types', + "params", + "bond_types", TypeParameterDict( k=float, r_0=float, diff --git a/src/conftest.py b/src/conftest.py index 283caa0e..661d9b84 100644 --- a/src/conftest.py +++ b/src/conftest.py @@ -7,13 +7,13 @@ import pytest -@pytest.fixture(scope='session') +@pytest.fixture(scope="session") def bonded_two_particle_snapshot_factory(two_particle_snapshot_factory): """Fixture for a single bond.""" def make_snapshot(bond_types=None, **kwargs): if bond_types is None: - bond_types = ['A-A'] + bond_types = ["A-A"] snap = two_particle_snapshot_factory(**kwargs) if snap.communicator.rank == 0: snap.bonds.types = bond_types diff --git a/src/flow.py b/src/flow.py index 13a6828c..d1c29b59 100644 --- a/src/flow.py +++ b/src/flow.py @@ -29,14 +29,14 @@ class ConstantFlow(FlowField): Example:: - u = hoomd.azplugins.flow.ConstantFlow(velocity=(1,0,0)) + u = hoomd.azplugins.flow.ConstantFlow(velocity=(1, 0, 0)) """ def __init__(self, velocity): super().__init__() param_dict = ParameterDict(velocity=(float, float, float)) - param_dict['velocity'] = velocity + param_dict["velocity"] = velocity self._param_dict.update(param_dict) def _attach_hook(self): @@ -67,7 +67,9 @@ class ParabolicFlow(FlowField): Example:: - u = hoomd.azplugins.flow.ParabolicFlow(mean_velocity=2.0, separation=0.5) + u = hoomd.azplugins.flow.ParabolicFlow( + mean_velocity=2.0, separation=0.5 + ) Note: Creating a flow profile does **not** imply anything about the simulation diff --git a/src/pair.py b/src/pair.py index a0a49539..48ec9e89 100644 --- a/src/pair.py +++ b/src/pair.py @@ -104,14 +104,14 @@ class Colloid(pair.Pair): """ _ext_module = _azplugins - _cpp_class_name = 'PotentialPairColloid' - _accepted_modes = ('none', 'shift', 'xplor') + _cpp_class_name = "PotentialPairColloid" + _accepted_modes = ("none", "shift", "xplor") - def __init__(self, nlist, default_r_cut=None, default_r_on=0, mode='none'): + def __init__(self, nlist, default_r_cut=None, default_r_on=0, mode="none"): super().__init__(nlist, default_r_cut, default_r_on, mode) params = TypeParameter( - 'params', - 'particle_types', + "params", + "particle_types", # TypeParameterDict needs updated still TypeParameterDict(A=float, a_1=float, a_2=float, sigma=float, len_keys=2), ) @@ -181,9 +181,9 @@ class DPDGeneralWeight(pair.Pair): nl = nlist.Cell() dpd = pair.DPDGeneralWeight(nlist=nl, kT=1.0, default_r_cut=1.0) - dpd.params[('A', 'A')] = dict(A=25.0, gamma=4.5, s=0.5) - dpd.params[('A', 'B')] = dict(A=50.0, gamma=4.5, s=0.5) - dpd.params[('B', 'B')] = dict(A=25.0, gamma=4.5, s=0.5) + dpd.params[("A", "A")] = dict(A=25.0, gamma=4.5, s=0.5) + dpd.params[("A", "B")] = dict(A=50.0, gamma=4.5, s=0.5) + dpd.params[("B", "B")] = dict(A=25.0, gamma=4.5, s=0.5) .. py:attribute:: params @@ -211,8 +211,8 @@ class DPDGeneralWeight(pair.Pair): """ _ext_module = _azplugins - _cpp_class_name = 'PotentialPairDPDThermoGeneralWeight' - _accepted_modes = ('none',) + _cpp_class_name = "PotentialPairDPDThermoGeneralWeight" + _accepted_modes = ("none",) def __init__( self, @@ -221,16 +221,16 @@ def __init__( default_r_cut=None, ): super().__init__( - nlist=nlist, default_r_cut=default_r_cut, default_r_on=0, mode='none' + nlist=nlist, default_r_cut=default_r_cut, default_r_on=0, mode="none" ) params = TypeParameter( - 'params', - 'particle_types', + "params", + "particle_types", TypeParameterDict(A=float, gamma=float, s=float, len_keys=2), ) self._add_typeparam(params) param_dict = ParameterDict(kT=Variant) - param_dict['kT'] = kT + param_dict["kT"] = kT self._param_dict.update(param_dict) def _attach_hook(self): @@ -258,8 +258,8 @@ class Hertz(pair.Pair): nl = hoomd.md.nlist.cell() hertz = azplugins.pair.Hertz(r_cut=3.0, nlist=nl) - hertz.params[('A', 'A')] = dict(epsilon=1.0) - hertz.r_cut[('A', 'B')] = 3.0 + hertz.params[("A", "A")] = dict(epsilon=1.0) + hertz.r_cut[("A", "B")] = 3.0 .. py:attribute:: params @@ -280,14 +280,14 @@ class Hertz(pair.Pair): """ _ext_module = _azplugins - _cpp_class_name = 'PotentialPairHertz' - _accepted_modes = ('none', 'shift', 'xplor') + _cpp_class_name = "PotentialPairHertz" + _accepted_modes = ("none", "shift", "xplor") - def __init__(self, nlist, default_r_cut=None, default_r_on=0, mode='none'): + def __init__(self, nlist, default_r_cut=None, default_r_on=0, mode="none"): super().__init__(nlist, default_r_cut, default_r_on, mode) params = TypeParameter( - 'params', - 'particle_types', + "params", + "particle_types", TypeParameterDict(epsilon=float, len_keys=2), ) self._add_typeparam(params) @@ -353,14 +353,14 @@ class PerturbedLennardJones(pair.Pair): """ _ext_module = _azplugins - _cpp_class_name = 'PotentialPairPerturbedLennardJones' - _accepted_modes = ('none', 'shift', 'xplor') + _cpp_class_name = "PotentialPairPerturbedLennardJones" + _accepted_modes = ("none", "shift", "xplor") - def __init__(self, nlist, default_r_cut=None, default_r_on=0, mode='none'): + def __init__(self, nlist, default_r_cut=None, default_r_on=0, mode="none"): super().__init__(nlist, default_r_cut, default_r_on, mode) params = TypeParameter( - 'params', - 'particle_types', + "params", + "particle_types", TypeParameterDict( epsilon=float, sigma=float, attraction_scale_factor=float, len_keys=2 ), @@ -412,9 +412,15 @@ class TwoPatchMorse(pair.aniso.AnisotropicPair): nl = hoomd.md.nlist.Cell() m2p = azplugins.pair.TwoPatchMorse(nlist=nl) - m2p.params[('A', 'A')] = dict(M_d=1.8347, M_r=0.0302, r_eq=1.0043, - omega=20, alpha=0.50, repulsion=True) - m2p.r_cut[('A', 'A')] = 3.0 + m2p.params[("A", "A")] = dict( + M_d=1.8347, + M_r=0.0302, + r_eq=1.0043, + omega=20, + alpha=0.50, + repulsion=True, + ) + m2p.r_cut[("A", "A")] = 3.0 .. py:attribute:: params @@ -441,13 +447,13 @@ class TwoPatchMorse(pair.aniso.AnisotropicPair): """ _ext_module = _azplugins - _cpp_class_name = 'AnisoPotentialPairTwoPatchMorse' + _cpp_class_name = "AnisoPotentialPairTwoPatchMorse" - def __init__(self, nlist, default_r_cut=None, mode='none'): + def __init__(self, nlist, default_r_cut=None, mode="none"): super().__init__(nlist, default_r_cut, mode) params = TypeParameter( - 'params', - 'particle_types', + "params", + "particle_types", TypeParameterDict( M_d=float, M_r=float, diff --git a/src/pytest/test_bond.py b/src/pytest/test_bond.py index 1a242a38..8e687db5 100644 --- a/src/pytest/test_bond.py +++ b/src/pytest/test_bond.py @@ -12,8 +12,8 @@ import pytest PotentialTestCase = collections.namedtuple( - 'PotentialTestCase', - ['potential', 'params', 'distance', 'energy', 'force'], + "PotentialTestCase", + ["potential", "params", "distance", "energy", "force"], ) potential_tests = [] @@ -194,7 +194,7 @@ @pytest.mark.parametrize( - 'potential_test', potential_tests, ids=lambda x: x.potential.__name__ + "potential_test", potential_tests, ids=lambda x: x.potential.__name__ ) def test_energy_and_force( simulation_factory, bonded_two_particle_snapshot_factory, potential_test @@ -212,7 +212,7 @@ def test_energy_and_force( # setup pair potential potential = potential_test.potential() - potential.params['A-A'] = potential_test.params + potential.params["A-A"] = potential_test.params integrator.forces = [potential] # calculate energies and forces @@ -220,7 +220,7 @@ def test_energy_and_force( sim.run(0) # test that parameters are still correct after attach runs - assert potential.params['A-A'] == potential_test.params + assert potential.params["A-A"] == potential_test.params # test that the energies match reference values, half goes to each particle energies = potential.energies diff --git a/src/pytest/test_pair.py b/src/pytest/test_pair.py index 97ad79c6..0f742de6 100644 --- a/src/pytest/test_pair.py +++ b/src/pytest/test_pair.py @@ -13,8 +13,8 @@ import pytest PotentialTestCase = collections.namedtuple( - 'PotentialTestCase', - ['potential', 'params', 'r_cut', 'shift', 'distance', 'energy', 'force'], + "PotentialTestCase", + ["potential", "params", "r_cut", "shift", "distance", "energy", "force"], ) potential_tests = [] @@ -23,7 +23,7 @@ # test the calculation of force and potential PotentialTestCase( hoomd.azplugins.pair.Hertz, - {'epsilon': 2.0}, + {"epsilon": 2.0}, 1.5, False, 1.05, @@ -32,7 +32,7 @@ ), PotentialTestCase( hoomd.azplugins.pair.Hertz, - {'epsilon': 3.0}, + {"epsilon": 3.0}, 2.05, False, 1.05, @@ -43,7 +43,7 @@ # outside cutoff PotentialTestCase( hoomd.azplugins.pair.Hertz, - {'epsilon': 1.0}, + {"epsilon": 1.0}, 1.0, False, 1.05, @@ -53,7 +53,7 @@ # inside cutoff but epsilon = 0 PotentialTestCase( hoomd.azplugins.pair.Hertz, - {'epsilon': 0.0}, + {"epsilon": 0.0}, 3.0, False, 1.05, @@ -67,7 +67,7 @@ # test when it's in the wca part, no potential shifting PotentialTestCase( hoomd.azplugins.pair.PerturbedLennardJones, - {'epsilon': 2.0, 'sigma': 1.05, 'attraction_scale_factor': 0.0}, + {"epsilon": 2.0, "sigma": 1.05, "attraction_scale_factor": 0.0}, 3.0, False, 1.05, @@ -78,7 +78,7 @@ # of energy (force stays the same) PotentialTestCase( hoomd.azplugins.pair.PerturbedLennardJones, - {'epsilon': 2.0, 'sigma': 1.05, 'attraction_scale_factor': 0.5}, + {"epsilon": 2.0, "sigma": 1.05, "attraction_scale_factor": 0.5}, 3.0, False, 1.05, @@ -89,7 +89,7 @@ # when attraction_scale_factor = 0, then the potential and force are zero PotentialTestCase( hoomd.azplugins.pair.PerturbedLennardJones, - {'epsilon': 2.0, 'sigma': 0.5, 'attraction_scale_factor': 0.0}, + {"epsilon": 2.0, "sigma": 0.5, "attraction_scale_factor": 0.0}, 3.0, False, 1.05, @@ -99,7 +99,7 @@ # partially switch on the LJ with attraction_scale_factor = 0.5 PotentialTestCase( hoomd.azplugins.pair.PerturbedLennardJones, - {'epsilon': 2.0, 'sigma': 0.5, 'attraction_scale_factor': 0.5}, + {"epsilon": 2.0, "sigma": 0.5, "attraction_scale_factor": 0.5}, 3.0, False, 1.05, @@ -111,7 +111,7 @@ # check wca is shifted first PotentialTestCase( hoomd.azplugins.pair.PerturbedLennardJones, - {'epsilon': 2.0, 'sigma': 1.05, 'attraction_scale_factor': 0.5}, + {"epsilon": 2.0, "sigma": 1.05, "attraction_scale_factor": 0.5}, 3.0, True, 1.05, @@ -121,7 +121,7 @@ # and check lj PotentialTestCase( hoomd.azplugins.pair.PerturbedLennardJones, - {'epsilon': 2.0, 'sigma': 0.85, 'attraction_scale_factor': 0.5}, + {"epsilon": 2.0, "sigma": 0.85, "attraction_scale_factor": 0.5}, 3.0, True, 1.05, @@ -132,7 +132,7 @@ # outside cutoff PotentialTestCase( hoomd.azplugins.pair.PerturbedLennardJones, - {'epsilon': 1.0, 'sigma': 1.0, 'attraction_scale_factor': 0.5}, + {"epsilon": 1.0, "sigma": 1.0, "attraction_scale_factor": 0.5}, 1.0, False, 1.05, @@ -142,7 +142,7 @@ # inside cutoff but epsilon = 0 PotentialTestCase( hoomd.azplugins.pair.PerturbedLennardJones, - {'epsilon': 0.0, 'sigma': 1.0, 'attraction_scale_factor': 0.5}, + {"epsilon": 0.0, "sigma": 1.0, "attraction_scale_factor": 0.5}, 3.0, False, 1.05, @@ -156,7 +156,7 @@ # test the calculation of force and potential for Solvent-Solvent PotentialTestCase( hoomd.azplugins.pair.Colloid, - {'A': 100.0, 'a_1': 0, 'a_2': 0, 'sigma': 2.0}, + {"A": 100.0, "a_1": 0, "a_2": 0, "sigma": 2.0}, 6.0, False, 3.0, @@ -166,7 +166,7 @@ # test the calculation of force and potential for Colloid-Solvent PotentialTestCase( hoomd.azplugins.pair.Colloid, - {'A': 100.0, 'a_1': 1.5, 'a_2': 0, 'sigma': 1.05}, + {"A": 100.0, "a_1": 1.5, "a_2": 0, "sigma": 1.05}, 6.0, False, 3.0, @@ -175,7 +175,7 @@ ), PotentialTestCase( hoomd.azplugins.pair.Colloid, - {'A': 100.0, 'a_1': 0, 'a_2': 1.5, 'sigma': 1.05}, + {"A": 100.0, "a_1": 0, "a_2": 1.5, "sigma": 1.05}, 6.0, False, 3.0, @@ -185,7 +185,7 @@ # test the calculation of force and potential for Colloid-Colloid PotentialTestCase( hoomd.azplugins.pair.Colloid, - {'A': 100.0, 'a_1': 1.5, 'a_2': 0.75, 'sigma': 1.05}, + {"A": 100.0, "a_1": 1.5, "a_2": 0.75, "sigma": 1.05}, 6.0, False, 3.0, @@ -195,7 +195,7 @@ # test the calculation of force and potential outside r_cut PotentialTestCase( hoomd.azplugins.pair.Colloid, - {'A': 100.0, 'a_1': 1.5, 'a_2': 0.75, 'sigma': 1.05}, + {"A": 100.0, "a_1": 1.5, "a_2": 0.75, "sigma": 1.05}, 6.0, False, 7.0, @@ -209,7 +209,7 @@ # test the calculation of force and potential (needs kT=0 for zero random force) PotentialTestCase( hoomd.azplugins.pair.DPDGeneralWeight, - {'A': 2.0, 'gamma': 4.5, 's': 0.5}, + {"A": 2.0, "gamma": 4.5, "s": 0.5}, 1.0, False, 0.5, @@ -220,7 +220,7 @@ # outside cutoff PotentialTestCase( hoomd.azplugins.pair.DPDGeneralWeight, - {'A': 25.0, 'gamma': 4.5, 's': 2}, + {"A": 25.0, "gamma": 4.5, "s": 2}, 1.0, False, 1.05, @@ -230,7 +230,7 @@ # inside cutoff but A = 0 PotentialTestCase( hoomd.azplugins.pair.DPDGeneralWeight, - {'A': 0.0, 'gamma': 4.5, 's': 2}, + {"A": 0.0, "gamma": 4.5, "s": 2}, 1.0, False, 0.5, @@ -241,7 +241,7 @@ @pytest.mark.parametrize( - 'potential_test', potential_tests, ids=lambda x: x.potential.__name__ + "potential_test", potential_tests, ids=lambda x: x.potential.__name__ ) def test_energy_and_force( simulation_factory, two_particle_snapshot_factory, potential_test @@ -263,16 +263,16 @@ def test_energy_and_force( # setup pair potential extra_args = {} if potential_test.potential is hoomd.azplugins.pair.DPDGeneralWeight: - extra_args['kT'] = 0.0 + extra_args["kT"] = 0.0 else: - extra_args['mode'] = 'shift' if potential_test.shift else 'none' + extra_args["mode"] = "shift" if potential_test.shift else "none" potential = potential_test.potential( nlist=hoomd.md.nlist.Cell(buffer=r_buff), default_r_cut=potential_test.r_cut, **extra_args, ) - potential.params[('A', 'A')] = potential_test.params + potential.params[("A", "A")] = potential_test.params integrator.forces = [potential] # calculate energies and forces @@ -280,7 +280,7 @@ def test_energy_and_force( sim.run(0) # test that parameters are still correct after attach runs - assert potential.params[('A', 'A')] == potential_test.params + assert potential.params[("A", "A")] == potential_test.params # test that the energies match reference values, half goes to each particle energies = potential.energies diff --git a/src/pytest/test_pair_aniso.py b/src/pytest/test_pair_aniso.py index 1328fb13..ac74f45a 100644 --- a/src/pytest/test_pair_aniso.py +++ b/src/pytest/test_pair_aniso.py @@ -13,8 +13,8 @@ import pytest PotentialTestCase = collections.namedtuple( - 'PotentialTestCase', - ['potential', 'params', 'r_cut', 'shift', 'energy', 'force', 'torque'], + "PotentialTestCase", + ["potential", "params", "r_cut", "shift", "energy", "force", "torque"], ) potential_tests = [] @@ -25,12 +25,12 @@ PotentialTestCase( hoomd.azplugins.pair.TwoPatchMorse, { - 'M_d': 1.8341, - 'M_r': 0.0302, - 'r_eq': 1.0043, - 'omega': 5.0, - 'alpha': 0.40, - 'repulsion': False, + "M_d": 1.8341, + "M_r": 0.0302, + "r_eq": 1.0043, + "omega": 5.0, + "alpha": 0.40, + "repulsion": False, }, 1.6, False, @@ -42,12 +42,12 @@ PotentialTestCase( hoomd.azplugins.pair.TwoPatchMorse, { - 'M_d': 1.8341, - 'M_r': 0.0302, - 'r_eq': 1.0043, - 'omega': 5.0, - 'alpha': 0.40, - 'repulsion': False, + "M_d": 1.8341, + "M_r": 0.0302, + "r_eq": 1.0043, + "omega": 5.0, + "alpha": 0.40, + "repulsion": False, }, 1.10, True, @@ -60,12 +60,12 @@ PotentialTestCase( hoomd.azplugins.pair.TwoPatchMorse, { - 'M_d': 1.8341, - 'M_r': 0.0302, - 'r_eq': 1.0043, - 'omega': 5.0, - 'alpha': 0.40, - 'repulsion': False, + "M_d": 1.8341, + "M_r": 0.0302, + "r_eq": 1.0043, + "omega": 5.0, + "alpha": 0.40, + "repulsion": False, }, 1.0, True, @@ -77,12 +77,12 @@ PotentialTestCase( hoomd.azplugins.pair.TwoPatchMorse, { - 'M_d': 0.0, - 'M_r': 0.0302, - 'r_eq': 1.0043, - 'omega': 5.0, - 'alpha': 0.40, - 'repulsion': False, + "M_d": 0.0, + "M_r": 0.0302, + "r_eq": 1.0043, + "omega": 5.0, + "alpha": 0.40, + "repulsion": False, }, 1.6, True, @@ -94,12 +94,12 @@ PotentialTestCase( hoomd.azplugins.pair.TwoPatchMorse, { - 'M_d': 1.8341, - 'M_r': 0.0302, - 'r_eq': 1.1, - 'omega': 100.0, - 'alpha': 0.40, - 'repulsion': False, + "M_d": 1.8341, + "M_r": 0.0302, + "r_eq": 1.1, + "omega": 100.0, + "alpha": 0.40, + "repulsion": False, }, 1.6, False, @@ -111,7 +111,7 @@ @pytest.mark.parametrize( - 'potential_test', potential_tests, ids=lambda x: x.potential.__name__ + "potential_test", potential_tests, ids=lambda x: x.potential.__name__ ) def test_energy_force_and_torque( simulation_factory, two_particle_snapshot_factory, potential_test @@ -134,9 +134,9 @@ def test_energy_force_and_torque( potential = potential_test.potential( nlist=hoomd.md.nlist.Cell(buffer=0.4), default_r_cut=potential_test.r_cut, - mode='shift' if potential_test.shift else 'none', + mode="shift" if potential_test.shift else "none", ) - potential.params[('A', 'A')] = potential_test.params + potential.params[("A", "A")] = potential_test.params integrator.forces = [potential] # calculate energies and forces @@ -145,7 +145,7 @@ def test_energy_force_and_torque( # test that parameters are still correct after attach runs ref_values = (list(potential_test.params.values()),) - test_values = [potential.params[('A', 'A')][k] for k in potential_test.params] + test_values = [potential.params[("A", "A")][k] for k in potential_test.params] assert numpy.allclose(test_values, ref_values) # test that the energies match reference values, half goes to each particle diff --git a/src/pytest/test_pair_dpd.py b/src/pytest/test_pair_dpd.py index a0cde02a..86c1f845 100644 --- a/src/pytest/test_pair_dpd.py +++ b/src/pytest/test_pair_dpd.py @@ -24,7 +24,7 @@ def test_dpd_temperature(simulation_factory, lattice_snapshot_factory): # create DPD with no repulsion to test random part only cell = hoomd.md.nlist.Cell(buffer=0.4) dpd = hoomd.azplugins.pair.DPDGeneralWeight(nlist=cell, kT=1.5, default_r_cut=1.0) - dpd.params[('A', 'A')] = dict(A=0.0, gamma=4.5, s=0.5) + dpd.params[("A", "A")] = dict(A=0.0, gamma=4.5, s=0.5) integrator.forces.append(dpd) # set up NVE integration to test thermostatting part of DPD General Weight