From 06e6ab296d6a80fbd70417afa8cfdfd4817c779f Mon Sep 17 00:00:00 2001 From: "Matthew W. Thompson" Date: Fri, 15 Nov 2024 08:52:17 -0600 Subject: [PATCH 1/5] BUG: Discard other conformers when packing --- openff/interchange/components/_packmol.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/openff/interchange/components/_packmol.py b/openff/interchange/components/_packmol.py index 28c36193c..c9de1ace5 100644 --- a/openff/interchange/components/_packmol.py +++ b/openff/interchange/components/_packmol.py @@ -423,6 +423,10 @@ def _create_molecule_pdbs(molecules: list[Molecule]) -> list[str]: # Generate conformers if they're missing if molecule.n_conformers <= 0: molecule.generate_conformers(n_conformers=1) + else: + # Possible issues writing multi-conformer PDBs with RDKit + # https://github.com/openforcefield/openff-interchange/issues/1107 + molecule._conformers = [molecule.conformers[0]] # RDKitToolkitWrapper is less buggy than OpenEye for writing PDBs # See https://github.com/openforcefield/openff-toolkit/issues/1307 From 03e36ccb7527bc77f933cc2a4ea38a79ba1a4ad4 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 18 Nov 2024 20:45:10 +0000 Subject: [PATCH 2/5] [pre-commit.ci] pre-commit autoupdate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/astral-sh/ruff-pre-commit: v0.7.3 → v0.7.4](https://github.com/astral-sh/ruff-pre-commit/compare/v0.7.3...v0.7.4) - [github.com/kynan/nbstripout: 0.8.0 → 0.8.1](https://github.com/kynan/nbstripout/compare/0.8.0...0.8.1) --- .pre-commit-config.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 80dd27779..a54ff090d 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -12,7 +12,7 @@ repos: hooks: - id: add-trailing-comma - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.7.3 + rev: v0.7.4 hooks: - id: ruff - id: ruff-format @@ -45,7 +45,7 @@ repos: args: - --fix - repo: https://github.com/kynan/nbstripout - rev: 0.8.0 + rev: 0.8.1 hooks: - id: nbstripout files: ^examples From 86482ce5ec46d5d81088ab44300b02f41d1a108e Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 25 Nov 2024 20:44:01 +0000 Subject: [PATCH 3/5] [pre-commit.ci] pre-commit autoupdate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/astral-sh/ruff-pre-commit: v0.7.4 → v0.8.0](https://github.com/astral-sh/ruff-pre-commit/compare/v0.7.4...v0.8.0) - [github.com/igorshubovych/markdownlint-cli: v0.42.0 → v0.43.0](https://github.com/igorshubovych/markdownlint-cli/compare/v0.42.0...v0.43.0) --- .pre-commit-config.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index a54ff090d..37b7073d0 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -12,7 +12,7 @@ repos: hooks: - id: add-trailing-comma - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.7.4 + rev: v0.8.0 hooks: - id: ruff - id: ruff-format @@ -28,7 +28,7 @@ repos: - id: blacken-docs files: ^docs/ - repo: https://github.com/igorshubovych/markdownlint-cli - rev: v0.42.0 + rev: v0.43.0 hooks: - id: markdownlint exclude: .github From 695fafe438eae1c19ff6fe041be8bf4f408e1c1f Mon Sep 17 00:00:00 2001 From: "Matthew W. Thompson" Date: Mon, 25 Nov 2024 15:51:30 -0600 Subject: [PATCH 4/5] MAINT: Update some imports/annotations --- .pre-commit-config.yaml | 12 +----------- openff/interchange/_tests/_openmm.py | 4 ++-- openff/interchange/components/interchange.py | 6 +++--- openff/interchange/drivers/__init__.py | 6 +++--- openff/interchange/drivers/amber.py | 2 +- openff/interchange/drivers/gromacs.py | 2 +- openff/interchange/interop/_virtual_sites.py | 3 +-- openff/interchange/interop/openmm/__init__.py | 4 ++-- openff/interchange/interop/openmm/_nonbonded.py | 10 +++++----- openff/interchange/smirnoff/_nonbonded.py | 14 +++++++++----- stubs/mbuild/__init__.pyi | 3 ++- stubs/mdtraj/__init__.pyi | 3 ++- stubs/nglview/__init__.pyi | 2 +- 13 files changed, 33 insertions(+), 38 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 37b7073d0..67ef9efe7 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -15,6 +15,7 @@ repos: rev: v0.8.0 hooks: - id: ruff + args: ["--fix"] - id: ruff-format - repo: https://github.com/econchick/interrogate rev: 1.7.0 @@ -33,17 +34,6 @@ repos: - id: markdownlint exclude: .github args: ["--disable", "MD013", "MD033", "MD024", "MD046", "--ignore", "docs/using/experimental.md", "--ignore", "docs/using/status.md", "--"] -- repo: https://github.com/nbQA-dev/nbQA - rev: 1.9.1 - hooks: - - id: nbqa-pyupgrade - files: ^examples - args: - - --py310-plus - - id: nbqa-ruff - files: ^examples - args: - - --fix - repo: https://github.com/kynan/nbstripout rev: 0.8.1 hooks: diff --git a/openff/interchange/_tests/_openmm.py b/openff/interchange/_tests/_openmm.py index be3545c91..d57124cd2 100644 --- a/openff/interchange/_tests/_openmm.py +++ b/openff/interchange/_tests/_openmm.py @@ -1,5 +1,5 @@ from collections import defaultdict -from typing import TYPE_CHECKING, DefaultDict +from typing import TYPE_CHECKING from openff.utilities.utilities import has_package, requires_package @@ -37,7 +37,7 @@ def get_14_scaling_factors(omm_sys: "openmm.System") -> tuple[list, list]: def _create_torsion_dict(torsion_force) -> dict[tuple[int], list[tuple]]: - torsions: DefaultDict = defaultdict(list) + torsions = defaultdict(list) for i in range(torsion_force.getNumTorsions()): p1, p2, p3, p4, periodicity, phase, k = torsion_force.getTorsionParameters(i) diff --git a/openff/interchange/components/interchange.py b/openff/interchange/components/interchange.py index c9b6ac0f7..ef2b71de7 100644 --- a/openff/interchange/components/interchange.py +++ b/openff/interchange/components/interchange.py @@ -100,7 +100,7 @@ def from_smirnoff( ---------- force_field : `openff.toolkit.ForceField` The force field to parameterize the topology with. - topology : `openff.toolkit.Topology` or `List[openff.toolkit.Molecule]` + topology : `openff.toolkit.Topology` or `list[openff.toolkit.Molecule]` The topology to parameterize, or a list of molecules to construct a topology from and parameterize. box : `openff.units.Quantity`, optional @@ -109,14 +109,14 @@ def from_smirnoff( positions : `openff.units.Quantity`, optional The positions associated with atoms in the input topology. If ``None``, positions are taken from the molecules in topology, if present on all molecules. - charge_from_molecules : `List[openff.toolkit.molecule.Molecule]`, optional + charge_from_molecules : `list[openff.toolkit.molecule.Molecule]`, optional If specified, partial charges for any molecules isomorphic to those given will be taken from the given molecules' `partial_charges` attribute instead of being determined by the force field. All molecules in this list must have partial charges assigned and must not be isomorphic with any other molecules in the list. For all values of this argument, charges on the input topology are ignored. - partial_bond_orders_from_molecules : List[openff.toolkit.molecule.Molecule], optional + partial_bond_orders_from_molecules : list[openff.toolkit.molecule.Molecule], optional If specified, partial bond orders will be taken from the given molecules instead of being determined by the force field. allow_nonintegral_charges : bool, optional, default=False diff --git a/openff/interchange/drivers/__init__.py b/openff/interchange/drivers/__init__.py index 3de149723..ea5fe7edf 100644 --- a/openff/interchange/drivers/__init__.py +++ b/openff/interchange/drivers/__init__.py @@ -7,10 +7,10 @@ from openff.interchange.drivers.openmm import get_openmm_energies __all__ = [ - "get_openmm_energies", + "get_all_energies", + "get_amber_energies", "get_gromacs_energies", "get_lammps_energies", - "get_amber_energies", - "get_all_energies", + "get_openmm_energies", "get_summary_data", ] diff --git a/openff/interchange/drivers/amber.py b/openff/interchange/drivers/amber.py index 296edab48..f67d810ff 100644 --- a/openff/interchange/drivers/amber.py +++ b/openff/interchange/drivers/amber.py @@ -86,7 +86,7 @@ def _run_sander( Returns ------- - energies: Dict[str, Quantity] + energies: dict[str, Quantity] A dictionary of energies, keyed by the GROMACS energy term name. """ diff --git a/openff/interchange/drivers/gromacs.py b/openff/interchange/drivers/gromacs.py index 71a82f703..ad735eacc 100644 --- a/openff/interchange/drivers/gromacs.py +++ b/openff/interchange/drivers/gromacs.py @@ -140,7 +140,7 @@ def _run_gmx_energy( Returns ------- - energies: Dict[str, Quantity] + energies: dict[str, Quantity] A dictionary of energies, keyed by the GROMACS energy term name. """ diff --git a/openff/interchange/interop/_virtual_sites.py b/openff/interchange/interop/_virtual_sites.py index c3e5b2a53..674d0f560 100644 --- a/openff/interchange/interop/_virtual_sites.py +++ b/openff/interchange/interop/_virtual_sites.py @@ -3,7 +3,6 @@ """ from collections import defaultdict -from typing import DefaultDict import numpy from openff.toolkit import Quantity, unit @@ -75,7 +74,7 @@ def get_positions_with_virtual_sites( raise MissingVirtualSitesError() # map of molecule index to *list* of virtual site keys contained therein - molecule_virtual_site_map: DefaultDict[int, list[VirtualSiteKey]] = defaultdict( + molecule_virtual_site_map: defaultdict[int, list[VirtualSiteKey]] = defaultdict( list, ) diff --git a/openff/interchange/interop/openmm/__init__.py b/openff/interchange/interop/openmm/__init__.py index d4687870b..5348ef592 100644 --- a/openff/interchange/interop/openmm/__init__.py +++ b/openff/interchange/interop/openmm/__init__.py @@ -25,10 +25,10 @@ from openff.interchange import Interchange __all__ = [ + "from_openmm", "to_openmm", - "to_openmm_topology", "to_openmm_positions", - "from_openmm", + "to_openmm_topology", ] diff --git a/openff/interchange/interop/openmm/_nonbonded.py b/openff/interchange/interop/openmm/_nonbonded.py index 5f4de68a9..a4817022b 100644 --- a/openff/interchange/interop/openmm/_nonbonded.py +++ b/openff/interchange/interop/openmm/_nonbonded.py @@ -5,7 +5,7 @@ import itertools import warnings from collections import defaultdict -from typing import DefaultDict, NamedTuple +from typing import NamedTuple from openff.toolkit import Molecule, Quantity, unit from openff.units.openmm import to_openmm as to_openmm_quantity @@ -105,7 +105,7 @@ def _process_nonbonded_forces( # Mapping between OpenFF "particles" and OpenMM particles (via index). OpenFF objects # (keys) are either atom indices (if atoms) or `VirtualSiteKey`s if virtual sites - # openff_openmm_particle_map: Dict[Union[int, VirtualSiteKey], int] = dict() + # openff_openmm_particle_map: dict[Union[int, VirtualSiteKey], int] = dict() openff_openmm_particle_map = _add_particles_to_system( interchange, system, @@ -372,7 +372,7 @@ def _create_single_nonbonded_force( # mapping between (openmm) index of each atom and the (openmm) index of each virtual particle # of that parent atom (if any) # if no virtual sites at all, this remains an empty dict - parent_virtual_particle_mapping: DefaultDict[int, list[int]] = defaultdict(list) + parent_virtual_particle_mapping: defaultdict[int, list[int]] = defaultdict(list) vdw = data.vdw_collection @@ -484,7 +484,7 @@ def _create_exceptions( non_bonded_force: openmm.NonbondedForce, interchange: "Interchange", openff_openmm_particle_map: dict, - parent_virtual_particle_mapping: DefaultDict[int, list[int]], + parent_virtual_particle_mapping: defaultdict[int, list[int]], ): # The topology indices reported by toolkit methods must be converted to openmm indices bonds = [ @@ -849,7 +849,7 @@ def _create_electrostatics_force( # mapping between (openmm) index of each atom and the (openmm) index of each virtual particle # of that parent atom (if any) # if no virtual sites at all, this remains an empty dict - parent_virtual_particle_mapping: DefaultDict[int, list[int]] = defaultdict(list) + parent_virtual_particle_mapping: defaultdict[int, list[int]] = defaultdict(list) for molecule in interchange.topology.molecules: for _ in molecule.atoms: diff --git a/openff/interchange/smirnoff/_nonbonded.py b/openff/interchange/smirnoff/_nonbonded.py index de4b800aa..950cfe92e 100644 --- a/openff/interchange/smirnoff/_nonbonded.py +++ b/openff/interchange/smirnoff/_nonbonded.py @@ -3,7 +3,7 @@ import logging import warnings from collections.abc import Iterable -from typing import Any, Literal, Optional, Union +from typing import Literal, Union import numpy from openff.toolkit import Molecule, Quantity, Topology, unit @@ -11,6 +11,7 @@ ChargeIncrementModelHandler, ElectrostaticsHandler, LibraryChargeHandler, + ParameterHandler, ToolkitAM1BCCHandler, vdWHandler, ) @@ -276,7 +277,10 @@ class SMIRNOFFElectrostaticsCollection(ElectrostaticsCollection, SMIRNOFFCollect ) # type: ignore[assignment] exception_potential: Literal["Coulomb"] = Field("Coulomb") - _charges: dict[Any, _ElementaryChargeQuantity] = PrivateAttr(dict()) + _charges: dict[ + TopologyKey | LibraryChargeTopologyKey | VirtualSiteKey, + _ElementaryChargeQuantity, + ] = PrivateAttr(dict()) _charges_cached: bool = PrivateAttr(default=False) @classmethod @@ -402,7 +406,7 @@ def _get_charges( ) logger.info( - "Charge section ChargeIncrementModel, applying charge increment from atom " + "Charge section ChargeIncrementModel, applying charge increment from atom " # type: ignore[union-attr] f"{topology_key.this_atom_index} to atoms {topology_key.other_atom_indices}", ) @@ -436,7 +440,7 @@ def parameter_handler_precedence(cls) -> list[str]: @classmethod def create( cls, - parameter_handler: Any, + parameter_handler: ParameterHandler | list[ParameterHandler], topology: Topology, molecules_with_preset_charges=None, allow_nonintegral_charges: bool = False, @@ -807,7 +811,7 @@ def _assign_charges_from_molecules( cls, topology: Topology, unique_molecule: Molecule, - molecules_with_preset_charges=Optional[list[Molecule]], + molecules_with_preset_charges=list[Molecule] | None, ) -> tuple[bool, dict, dict]: if molecules_with_preset_charges is None: return False, dict(), dict() diff --git a/stubs/mbuild/__init__.pyi b/stubs/mbuild/__init__.pyi index 9f9b1be16..b2033c2a9 100644 --- a/stubs/mbuild/__init__.pyi +++ b/stubs/mbuild/__init__.pyi @@ -1,4 +1,5 @@ -from typing import Any, Sequence +from collections.abc import Sequence +from typing import Any class Particle: def __init__(self, name: str | None) -> None: ... diff --git a/stubs/mdtraj/__init__.pyi b/stubs/mdtraj/__init__.pyi index 7397e61b2..1b29926c4 100644 --- a/stubs/mdtraj/__init__.pyi +++ b/stubs/mdtraj/__init__.pyi @@ -1,4 +1,5 @@ -from typing import Any, Generator +from collections.abc import Generator +from typing import Any import numpy import pandas diff --git a/stubs/nglview/__init__.pyi b/stubs/nglview/__init__.pyi index 135042fea..8dfe8742d 100644 --- a/stubs/nglview/__init__.pyi +++ b/stubs/nglview/__init__.pyi @@ -1,4 +1,4 @@ -from typing import Iterable +from collections.abc import Iterable class NGLWidget: def __init__( From 2463e8de1a6800f840dcb799aa62da9e13dc1a2e Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 2 Dec 2024 21:02:02 +0000 Subject: [PATCH 5/5] [pre-commit.ci] pre-commit autoupdate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/astral-sh/ruff-pre-commit: v0.8.0 → v0.8.1](https://github.com/astral-sh/ruff-pre-commit/compare/v0.8.0...v0.8.1) --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 67ef9efe7..2fe221e17 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -12,7 +12,7 @@ repos: hooks: - id: add-trailing-comma - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.8.0 + rev: v0.8.1 hooks: - id: ruff args: ["--fix"]