Skip to content

Commit e180a47

Browse files
committed
skip imports for NNpops and openmmtorch if not triggered
1 parent 9dba84e commit e180a47

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ ase = ["ase>=3.23.0"]
6565
# tblite py3.12 support tracked in https://github.com/tblite/tblite/issues/198
6666
ase-ext = ["tblite>=0.3.0; python_version < '3.12'"]
6767
openmm = [
68-
"mdanalysis>=2.7.0",
68+
"mdanalysis>=2.8.0",
6969
"openmm-mdanalysis-reporter>=0.1.0",
7070
"openmm>=8.1.0",
7171
]

src/atomate2/openmm/mace_utils.py

+19-6
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,30 @@ class written by Harry Moore. The nnpops_nl function
3636
import numpy as np
3737
import openmm
3838
import openmm.app
39-
import openmmtorch
4039
import torch
4140
from e3nn.util import jit
4241
from mace.tools import atomic_numbers_to_indices, to_one_hot, utils
4342

4443
try:
4544
from NNPOps.neighbors import getNeighborPairs
46-
except ImportError as err:
47-
raise ImportError(
48-
"NNPOps is not installed. Please install it from conda-forge."
49-
) from err
45+
except ImportError:
46+
47+
def getNeighborPairs(*args, **kwargs) -> None: # noqa: N802, ARG001
48+
"""Raise ImportError if NNPOps is not installed."""
49+
raise ImportError(
50+
"NNPOps is not installed. Please install it from conda-forge."
51+
)
52+
53+
54+
try:
55+
from openmmtorch import TorchForce
56+
except ImportError:
57+
58+
def TorchForce(*args, **kwargs) -> None: # noqa: N802, ARG001
59+
"""Raise ImportError if openmmtorch is not installed."""
60+
raise ImportError(
61+
"openmmtorch is not installed. Please install it from conda-forge."
62+
)
5063

5164

5265
class MaceForce(torch.nn.Module):
@@ -314,7 +327,7 @@ def add_forces(
314327
module = torch.jit.script(maceforce)
315328

316329
# Create the TorchForce and add it to the System.
317-
force = openmmtorch.TorchForce(module)
330+
force = TorchForce(module)
318331
force.setForceGroup(0)
319332
force.setUsesPeriodicBoundaryConditions(periodic)
320333
system.addForce(force)

0 commit comments

Comments
 (0)