Skip to content

Commit 09bec3f

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 0322437 commit 09bec3f

1 file changed

Lines changed: 28 additions & 28 deletions

File tree

feflow/utils/vendored.py

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
Copyright (c) 2025 Open Free Energy
1212
"""
1313

14-
from typing import Optional, Iterable
14+
from typing import Optional
15+
from collections.abc import Iterable
1516

1617
import numpy as np
1718
import numpy.typing as npt
@@ -28,8 +29,8 @@ def get_omm_modeller(
2829
protein_comps: Optional[Iterable[ProteinComponent] | ProteinComponent],
2930
solvent_comps: Optional[Iterable[SolventComponent] | SolventComponent],
3031
small_mols: Optional[Iterable[SmallMoleculeComponent] | SmallMoleculeComponent],
31-
omm_forcefield : ForceField,
32-
solvent_settings : OpenMMSolvationSettings
32+
omm_forcefield: ForceField,
33+
solvent_settings: OpenMMSolvationSettings,
3334
) -> ModellerReturn:
3435
"""
3536
Generate an OpenMM Modeller class based on a potential input ProteinComponent,
@@ -58,19 +59,15 @@ def get_omm_modeller(
5859
"""
5960
component_resids = {}
6061

61-
def _add_small_mol(comp,
62-
mol,
63-
system_modeller: Modeller,
64-
comp_resids: dict[Component, npt.NDArray]):
62+
def _add_small_mol(
63+
comp, mol, system_modeller: Modeller, comp_resids: dict[Component, npt.NDArray]
64+
):
6565
"""
6666
Helper method to add OFFMol to an existing Modeller object and
6767
update a dictionary tracking residue indices for each component.
6868
"""
6969
omm_top = mol.to_topology().to_openmm()
70-
system_modeller.add(
71-
omm_top,
72-
ensure_quantity(mol.conformers[0], 'openmm')
73-
)
70+
system_modeller.add(omm_top, ensure_quantity(mol.conformers[0], "openmm"))
7471

7572
nres = omm_top.getNumResidues()
7673
resids = [res.index for res in system_modeller.topology.residues()]
@@ -86,19 +83,20 @@ def _add_small_mol(comp,
8683
except TypeError:
8784
protein_comps = {protein_comps} # make it a set/iterable with the comp
8885
for protein_comp in protein_comps:
89-
system_modeller.add(protein_comp.to_openmm_topology(),
90-
protein_comp.to_openmm_positions())
86+
system_modeller.add(
87+
protein_comp.to_openmm_topology(), protein_comp.to_openmm_positions()
88+
)
9189
# add missing virtual particles (from crystal waters)
9290
system_modeller.addExtraParticles(omm_forcefield)
9391
component_resids[protein_comp] = np.array(
94-
[r.index for r in system_modeller.topology.residues()]
92+
[r.index for r in system_modeller.topology.residues()]
9593
)
9694
# if we solvate temporarily rename water molecules to 'WAT'
9795
# see openmm issue #4103
9896
if solvent_comps is not None:
9997
for r in system_modeller.topology.residues():
100-
if r.name == 'HOH':
101-
r.name = 'WAT'
98+
if r.name == "HOH":
99+
r.name = "WAT"
102100

103101
# Now loop through small mols
104102
if small_mols:
@@ -107,8 +105,12 @@ def _add_small_mol(comp,
107105
except TypeError:
108106
small_mols = {small_mols} # make it a set/iterable with the comp
109107
for small_mol_comp in small_mols:
110-
_add_small_mol(small_mol_comp, small_mol_comp.to_openff(), system_modeller,
111-
component_resids)
108+
_add_small_mol(
109+
small_mol_comp,
110+
small_mol_comp.to_openff(),
111+
system_modeller,
112+
component_resids,
113+
)
112114

113115
# Add solvent if neeeded
114116
if solvent_comps:
@@ -120,7 +122,9 @@ def _add_small_mol(comp,
120122
# TODO: Support multiple solvent components? Is there a use case for it?
121123
# Error out when we iter(have more than one solvent component in the states/systems
122124
if len(solvent_comps) > 1:
123-
raise ValueError("More than one solvent component found in systems. Only one supported.")
125+
raise ValueError(
126+
"More than one solvent component found in systems. Only one supported."
127+
)
124128
solvent_comp = solvent_comps[0] # Get the first (and only?) solvent component
125129
# Do unit conversions if necessary
126130
solvent_padding = None
@@ -150,20 +154,16 @@ def _add_small_mol(comp,
150154
numAdded=solvent_settings.number_of_solvent_molecules,
151155
)
152156

153-
all_resids = np.array(
154-
[r.index for r in system_modeller.topology.residues()]
155-
)
157+
all_resids = np.array([r.index for r in system_modeller.topology.residues()])
156158

157159
existing_resids = np.concatenate(
158160
[resids for resids in component_resids.values()]
159161
)
160162

161-
component_resids[solvent_comp] = np.setdiff1d(
162-
all_resids, existing_resids
163-
)
163+
component_resids[solvent_comp] = np.setdiff1d(all_resids, existing_resids)
164164
# undo rename of pre-existing waters
165165
for r in system_modeller.topology.residues():
166-
if r.name == 'WAT':
167-
r.name = 'HOH'
166+
if r.name == "WAT":
167+
r.name = "HOH"
168168

169-
return system_modeller, component_resids
169+
return system_modeller, component_resids

0 commit comments

Comments
 (0)