Skip to content

Commit

Permalink
make a new excpetion for dropping gaff support (#333)
Browse files Browse the repository at this point in the history
* make a new excpetion for dropping gaff support

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* make sure we catch GAFFNotSupportedError if needed

* raise the error if the user wants gaff

* lol whats syntax??

* Update openmmforcefields/generators/system_generators.py

Co-authored-by: Matt Thompson <mattwthompson@protonmail.com>

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Matt Thompson <mattwthompson@protonmail.com>
  • Loading branch information
3 people authored May 3, 2024
1 parent a0b79a6 commit f943979
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
10 changes: 9 additions & 1 deletion openmmforcefields/generators/system_generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ def __init__(
# Create and cache a residue template generator
from openmmforcefields.generators.template_generators import (
SmallMoleculeTemplateGenerator,
GAFFNotSupportedError,
)

self.template_generator = None
Expand All @@ -260,10 +261,17 @@ def __init__(
template_generator_kwargs=self.template_generator_kwargs,
)
break
except (ValueError, NotImplementedError) as e:
except (ValueError, GAFFNotSupportedError) as e:
_logger.debug(f" {template_generator_cls.__name__} cannot load {small_molecule_forcefield}")
_logger.debug(e)
if self.template_generator is None:
if small_molecule_forcefield.startswith("gaff"):
raise GAFFNotSupportedError(
"This release (0.13.x) of openmmforcefields temporarily drops GAFF support and "
"thereby the GAFFTemplateGenerator class. Support will be re-introduced in "
"future releases (0.14.x). To use this class, install version 0.12.0 or older."
)

msg = (
"No registered small molecule template generators could load force field "
f"'{small_molecule_forcefield}'\n"
Expand Down
6 changes: 5 additions & 1 deletion openmmforcefields/generators/template_generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ class ForceException(Exception):
"""Exception for forces"""


class GAFFNotSupportedError(Exception):
"""Exception for missing GAFF support"""


class SmallMoleculeTemplateGenerator:
"""
Abstract base class for small molecule template generation for OpenMM ForceField.
Expand Down Expand Up @@ -503,7 +507,7 @@ def __init__(self, molecules=None, forcefield=None, cache=None, **kwargs):
Newly parameterized molecules will be written to the cache, saving time next time!
"""
raise NotImplementedError(
raise GAFFNotSupportedError(
"This release (0.13.x) of openmmforcefields temporarily drops GAFF support and "
"thereby the GAFFTemplateGenerator class. Support will be re-introduced in "
"future releases (0.14.x). To use this class, install version 0.12.0 or older."
Expand Down

0 comments on commit f943979

Please sign in to comment.