Skip to content

Commit 301dad9

Browse files
eprettimikemhenry
andauthored
Fixes for issues and assorted cleanups to generators (#391)
* Cleanups: * Remove residue_atoms argument of generate_residue_template() methods: fixes #379 * OpenMMSystemMixin.convert_system_to_ffxml improper_atom_ordering was silently ignored * Removal of unused kwargs that could cause misspelled parameters to be silently ignored * Removal of some unused local variables * DummySystemGenerator: was broken due to early return * Consolidate custom classproperty implementation * Docstrings: parameters out of order, errors, formatting * Fix OpenFF units import for older openff-toolkit version compatible with espaloma * Fix broken DummySystemGenerator feature * Partial charge normalization * Use common logic for checking user-specified partial charges sum to total formal charge, and raising a warning if so * GAFFTemplateGenerator no longer silently adjusts user-specified partial charges if they don't sum to the formal charge: fixes #373 * Cleanups to test cases: * Consolidate propagate_dynamics() implementations into TemplateGeneratorBaseCase * Remove charges_from_system(), charges_are_equal(), compute_energy(), and compare_energies() from TestGAFFTemplateGenerator since identical implementations are available in TemplateGeneratorBaseCase * Bump CI OpenMM versions * Testing template generator user charge feature: * Ensure warnings are raised / not raised as appropriate (GAFF, SMIRNOFF) * SMIRNOFF should accept user charges not matching once we warn about it * Make template_generator_kwargs explicit * ruff format * Remove unused imports * Formatting, remove unused local assignments * Remove references to and tests for DummySystemGenerator * Style update: import classproperty --------- Co-authored-by: Mike Henry <11765982+mikemhenry@users.noreply.github.com>
1 parent 6f372f0 commit 301dad9

File tree

6 files changed

+384
-558
lines changed

6 files changed

+384
-558
lines changed

.github/workflows/test_charmm.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
matrix:
2626
os: [ubuntu-latest]
2727
python-version: ["3.12"]
28-
openmm-version: ["8.2.0dev1"]
28+
openmm-version: ["8.3.1"]
2929

3030
steps:
3131
- uses: actions/checkout@v4

openmmforcefields/generators/system_generators.py

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,22 @@
11
"""
22
System generators that build an OpenMM System object from a Topology object.
3-
43
"""
54

5+
from openmmforcefields.utils import classproperty
6+
67
################################################################################
78
# LOGGER
89
################################################################################
910

1011
import logging
1112

12-
_logger = logging.getLogger("openmmforcefields.system_generators")
13+
_logger = logging.getLogger("openmmforcefields.generators.system_generators")
1314

1415
################################################################################
1516
# System generator base class
1617
################################################################################
1718

1819

19-
class classproperty(property):
20-
def __get__(self, obj, objtype=None):
21-
return super().__get__(objtype)
22-
23-
def __set__(self, obj, value):
24-
super().__set__(type(obj), value)
25-
26-
def __delete__(self, obj):
27-
super().__delete__(type(obj))
28-
29-
3020
class SystemGenerator:
3121
"""
3222
Common interface for generating OpenMM Systems from OpenMM Topology objects
@@ -97,7 +87,7 @@ def __init__(
9787
----------
9888
forcefields : list of str, optional, default=None
9989
List of the names of ffxml files that will be used in System creation for the biopolymer.
100-
small_molecule_forcefield : str, optional, default='openff-1.0.0'
90+
small_molecule_forcefield : str, optional, default='openff-2.2.0'
10191
Small molecule force field to use.
10292
Must be supported by one of the registered template generators:
10393
[GAFFTemplateGenerator, SMIRNOFFTemplateGenerator]
@@ -113,7 +103,7 @@ def __init__(
113103
periodic_forcefield_kwargs : NonbondedMethod, optional, default={'nonbondedMethod' : PME}
114104
Keyword arguments added to forcefield_kwargs when the Topology is periodic.
115105
template_generator_kwargs : dict, optional, default=None
116-
Keyword arguments to be passed to subclasses of
106+
The value of an extra keyword argument called `template_generator_kwargs` to be passed to subclasses of
117107
``openmmforcefields.generators.template_generators.SmallMoleculeTemplateGenerator``.
118108
Currently only used for ``openmmforcefields.generators.template_generators.EspalomaTemplateGenerator``.
119109
barostat : openmm.MonteCarloBarostat, optional, default=None
@@ -202,7 +192,6 @@ def __init__(
202192
>>> system_generator.particle_epsilons = False # will zero out Lennard-Jones particle-particle interactions
203193
>>> system_generator.particle_exceptions = False # will zero out all 1-4 Lennard-Jones interactions
204194
>>> system_generator.torsions = False # will zero out all torsion terms
205-
206195
""" # noqa
207196

208197
# Initialize
@@ -301,8 +290,8 @@ def add_molecules(self, molecules):
301290
Can also be a list of Molecule objects or objects that can be used to construct a Molecule.
302291
If specified, these molecules will be recognized and parameterized as needed.
303292
The parameters will be cached in case they are encountered again the future.
304-
305293
"""
294+
306295
if self.template_generator is None:
307296
raise ValueError(
308297
"You must have a small molecule residue template generator registered to add small molecules"
@@ -314,6 +303,7 @@ def _modify_forces(self, system):
314303
"""
315304
Add barostat and modify forces if requested.
316305
"""
306+
317307
# Add barostat if requested and the system uses periodic boundary conditions
318308
if (self.barostat is not None) and system.usesPeriodicBoundaryConditions():
319309
import numpy as np
@@ -368,21 +358,21 @@ def create_system(self, topology, molecules=None):
368358
369359
Parameters
370360
----------
371-
topology : openmmtools.topology.Topology object
361+
topology : openmm.app.Topology object
372362
The topology describing the system to be created
373363
molecules : openff.toolkit.topology.Molecule or list of Molecules, optional, default=None
374364
Can alternatively be an object (such as an OpenEye OEMol or RDKit Mol or SMILES string) that can be used
375365
to construct a Molecule.
376366
Can also be a list of Molecule objects or objects that can be used to construct a Molecule.
377-
If specified, these molecules will be recognized and parameterized with antechamber as needed.
367+
If specified, these molecules will be recognized and parameterized as needed.
378368
The parameters will be cached in case they are encountered again the future.
379369
380370
Returns
381371
-------
382372
system : openmm.System
383373
A system object generated from the topology
384-
385374
"""
375+
386376
# Inform the template generator about any specified molecules
387377
if (self.template_generator is not None) and (molecules is not None):
388378
self.template_generator.add_molecules(molecules)

0 commit comments

Comments
 (0)