Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Jan 13, 2025
1 parent ac35a02 commit 71e37a0
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 79 deletions.
6 changes: 3 additions & 3 deletions openff/interchange/_tests/_openmm.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,9 @@ def _compare_nonbonded_parameters(force1, force2):
q2, sig2, eps2 = force2.getParticleParameters(i)
assert abs(q2 - q1) < 1e-8 * openmm.unit.elementary_charge, f"charge mismatch in particle {i}: {q1} vs {q2}"
assert abs(sig2 - sig1) < 1e-12 * openmm.unit.nanometer, f"sigma mismatch in particle {i}: {sig1} vs {sig2}"
assert (
abs(eps2 - eps1) < 1e-12 * openmm.unit.kilojoule_per_mole
), f"epsilon mismatch in particle {i}: {eps1} vs {eps2}"
assert abs(eps2 - eps1) < 1e-12 * openmm.unit.kilojoule_per_mole, (
f"epsilon mismatch in particle {i}: {eps1} vs {eps2}"
)


@requires_package("openmm")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -785,9 +785,9 @@ def test_preserve_per_residue_unique_atom_names(self, explicit_arg, sage):

# Assert the test's assumptions
_ace, ala1, ala2, _nme = off_topology.hierarchy_iterator("residues")
assert [a.name for a in ala1.atoms] == [
a.name for a in ala2.atoms
], "Test assumes both alanines have same atom names"
assert [a.name for a in ala1.atoms] == [a.name for a in ala2.atoms], (
"Test assumes both alanines have same atom names"
)

for res in off_topology.hierarchy_iterator("residues"):
res_atomnames = [atom.name for atom in res.atoms]
Expand Down
6 changes: 3 additions & 3 deletions openff/interchange/_tests/test_issues.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,9 @@ def test_issue_1049():

# the same index in system should also be a virtual site in the topology
for particle_index, particle in enumerate(openmm_topology.atoms()):
assert openmm_system.isVirtualSite(particle_index) == (
particle.element is None
), f"particle index {particle_index} is a virtual site in the system OR topology but not both"
assert openmm_system.isVirtualSite(particle_index) == (particle.element is None), (
f"particle index {particle_index} is a virtual site in the system OR topology but not both"
)


def test_issue_1052(sage, ethanol):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ def test_error_topology_mismatch(self, monkeypatch, sage_unconstrained, ethanol)
with pytest.raises(
UnsupportedImportError,
match=re.escape(
"The number of particles in the system (9) and "
"the number of atoms in the topology (3) do not match.",
"The number of particles in the system (9) and the number of atoms in the topology (3) do not match.",
),
):
from_openmm(
Expand Down
3 changes: 1 addition & 2 deletions openff/interchange/components/mdconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ class MDConfig(_BaseModel):
coul_cutoff: _DistanceQuantity = Field(
Quantity(9.0, unit.angstrom),
description=(
"The distance at which electrostatic interactions are truncated or transition from "
"short- to long-range."
"The distance at which electrostatic interactions are truncated or transition from short- to long-range."
),
)

Expand Down
114 changes: 55 additions & 59 deletions openff/interchange/interop/gromacs/export/_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,13 @@ def _get_new_entry_name(atom_type_list) -> str:
mapping_to_reduced_atom_types[atom_type.name] = _at_name
else:
top.write(
f"{atom_type.name :<11s}\t"
f"{atom_type.atomic_number :6d}\t"
f"{atom_type.mass.m :.16g}\t"
f"{atom_type.charge.m :.16f}\t"
f"{atom_type.particle_type :5s}\t"
f"{atom_type.sigma.m :.16g}\t"
f"{atom_type.epsilon.m :.16g}\n",
f"{atom_type.name:<11s}\t"
f"{atom_type.atomic_number:6d}\t"
f"{atom_type.mass.m:.16g}\t"
f"{atom_type.charge.m:.16f}\t"
f"{atom_type.particle_type:5s}\t"
f"{atom_type.sigma.m:.16g}\t"
f"{atom_type.epsilon.m:.16g}\n",
)

if not merge_atom_types:
Expand All @@ -156,13 +156,13 @@ def _get_new_entry_name(atom_type_list) -> str:

for atom_type_name, atom_type in reduced_atom_types:
top.write(
f"{atom_type_name :<11s}\t"
f"{atom_type.atomic_number :6d}\t"
f"{atom_type.mass.m :.16g}\t"
f"{atom_type.charge.m :.16f}\t"
f"{atom_type.particle_type :5s}\t"
f"{atom_type.sigma.m :.16g}\t"
f"{atom_type.epsilon.m :.16g}\n",
f"{atom_type_name:<11s}\t"
f"{atom_type.atomic_number:6d}\t"
f"{atom_type.mass.m:.16g}\t"
f"{atom_type.charge.m:.16f}\t"
f"{atom_type.particle_type:5s}\t"
f"{atom_type.sigma.m:.16g}\t"
f"{atom_type.epsilon.m:.16g}\n",
)
top.write("\n")
return mapping_to_reduced_atom_types
Expand Down Expand Up @@ -225,25 +225,25 @@ def _write_atoms(
for atom in molecule_type.atoms:
if merge_atom_types:
top.write(
f"{atom.index :6d} "
f"{mapping_to_reduced_atom_types[atom.atom_type] :6s}"
f"{atom.residue_index % 100_000 :8d} "
f"{atom.residue_name :8s} "
f"{atom.name :6s}"
f"{atom.charge_group_number :6d}"
f"{atom.charge.m :20.12f}"
f"{atom.mass.m :20.12f}\n",
f"{atom.index:6d} "
f"{mapping_to_reduced_atom_types[atom.atom_type]:6s}"
f"{atom.residue_index % 100_000:8d} "
f"{atom.residue_name:8s} "
f"{atom.name:6s}"
f"{atom.charge_group_number:6d}"
f"{atom.charge.m:20.12f}"
f"{atom.mass.m:20.12f}\n",
)
else:
top.write(
f"{atom.index :6d} "
f"{atom.atom_type :6s}"
f"{atom.residue_index % 100_000 :8d} "
f"{atom.residue_name :8s} "
f"{atom.name :6s}"
f"{atom.charge_group_number :6d}"
f"{atom.charge.m :20.12f}"
f"{atom.mass.m :20.12f}\n",
f"{atom.index:6d} "
f"{atom.atom_type:6s}"
f"{atom.residue_index % 100_000:8d} "
f"{atom.residue_name:8s} "
f"{atom.name:6s}"
f"{atom.charge_group_number:6d}"
f"{atom.charge.m:20.12f}"
f"{atom.mass.m:20.12f}\n",
)

top.write("\n")
Expand All @@ -256,7 +256,7 @@ def _write_pairs(self, top, molecule_type):

for pair in molecule_type.pairs:
top.write(
f"{pair.atom1 :6d}\t{pair.atom2 :6d}\t{function :6d}\n",
f"{pair.atom1:6d}\t{pair.atom2:6d}\t{function:6d}\n",
)

top.write("\n")
Expand All @@ -269,11 +269,7 @@ def _write_bonds(self, top, molecule_type):

for bond in molecule_type.bonds:
top.write(
f"{bond.atom1 :6d} "
f"{bond.atom2 :6d} "
f"{function :6d}"
f"{bond.length.m :20.12f} "
f"{bond.k.m :20.12f} ",
f"{bond.atom1:6d} {bond.atom2:6d} {function:6d}{bond.length.m:20.12f} {bond.k.m:20.12f} ",
)

top.write("\n")
Expand All @@ -288,12 +284,12 @@ def _write_angles(self, top, molecule_type):

for angle in molecule_type.angles:
top.write(
f"{angle.atom1 :6d} "
f"{angle.atom2 :6d} "
f"{angle.atom3 :6d} "
f"{function :6d} "
f"{angle.angle.m :20.12f} "
f"{angle.k.m :20.12f} ",
f"{angle.atom1:6d} "
f"{angle.atom2:6d} "
f"{angle.atom3:6d} "
f"{function:6d} "
f"{angle.angle.m:20.12f} "
f"{angle.k.m:20.12f} ",
)

top.write("\n")
Expand All @@ -314,26 +310,26 @@ def _write_dihedrals(self, top, molecule_type):
function = functions[type(dihedral)]

top.write(
f"{dihedral.atom1 :6d}"
f"{dihedral.atom2 :6d}"
f"{dihedral.atom3 :6d}"
f"{dihedral.atom4 :6d}"
f"{functions[type(dihedral)] :6d}",
f"{dihedral.atom1:6d}"
f"{dihedral.atom2:6d}"
f"{dihedral.atom3:6d}"
f"{dihedral.atom4:6d}"
f"{functions[type(dihedral)]:6d}",
)

if function in [1, 4]:
top.write(
f"{dihedral.phi.m :20.12f}{dihedral.k.m :20.12f}{dihedral.multiplicity :18d}",
f"{dihedral.phi.m:20.12f}{dihedral.k.m:20.12f}{dihedral.multiplicity:18d}",
)

elif function == 3:
top.write(
f"{dihedral.c0.m :20.12f}"
f"{dihedral.c1.m :20.12f}"
f"{dihedral.c2.m :20.12f}"
f"{dihedral.c3.m :20.12f}"
f"{dihedral.c4.m :20.12f}"
f"{dihedral.c5.m :20.12f}",
f"{dihedral.c0.m:20.12f}"
f"{dihedral.c1.m:20.12f}"
f"{dihedral.c2.m:20.12f}"
f"{dihedral.c3.m:20.12f}"
f"{dihedral.c4.m:20.12f}"
f"{dihedral.c5.m:20.12f}",
)

else:
Expand Down Expand Up @@ -397,11 +393,11 @@ def _write_exclusions(self, top, molecule_type):

for exclusion in molecule_type.exclusions:
top.write(
f"{exclusion.first_atom :6d}",
f"{exclusion.first_atom:6d}",
)
for other_atom in exclusion.other_atoms:
top.write(
f"{other_atom :6d}",
f"{other_atom:6d}",
)

top.write("\n")
Expand All @@ -416,9 +412,9 @@ def _write_settles(self, top, molecule_type):

for settle in molecule_type.settles:
top.write(
f"{settle.first_atom :6d}\t"
f"{function :6d}\t"
f"{settle.oxygen_hydrogen_distance.m_as(unit.nanometer) :20.12f}\t"
f"{settle.first_atom:6d}\t"
f"{function:6d}\t"
f"{settle.oxygen_hydrogen_distance.m_as(unit.nanometer):20.12f}\t"
f"{settle.hydrogen_hydrogen_distance.m_as(unit.nanometer):20.12f}\n",
)

Expand Down
14 changes: 7 additions & 7 deletions plugins/nonbonded_plugins/nonbonded.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ class SMIRNOFFBuckinghamCollection(_SMIRNOFFNonbondedCollection):

acts_as: str = "vdW"

expression: str = "a*exp(-b*r)-c*r^-6;" "a=sqrt(a1*a2);" "b=2/(1/b1+1/b2);" "c=sqrt(c1*c2);"
expression: str = "a*exp(-b*r)-c*r^-6;a=sqrt(a1*a2);b=2/(1/b1+1/b2);c=sqrt(c1*c2);"

periodic_method: str = "cutoff"
nonperiodic_method: str = "no-cutoff"
Expand Down Expand Up @@ -177,9 +177,9 @@ def pre_computed_terms(self) -> dict[str, float]:
@classmethod
def check_openmm_requirements(cls, combine_nonbonded_forces: bool) -> None:
"""Run through a list of assertions about what is compatible when exporting this to OpenMM."""
assert (
not combine_nonbonded_forces
), "Custom non-bonded functional forms require `combine_nonbonded_forces=False`."
assert not combine_nonbonded_forces, (
"Custom non-bonded functional forms require `combine_nonbonded_forces=False`."
)

def store_potentials(self, parameter_handler: BuckinghamHandler) -> None:
"""
Expand Down Expand Up @@ -331,9 +331,9 @@ def modify_parameters(
@classmethod
def check_openmm_requirements(cls, combine_nonbonded_forces: bool) -> None:
"""Run through a list of assertions about what is compatible when exporting this to OpenMM."""
assert (
not combine_nonbonded_forces
), "Custom non-bonded functional forms require `combine_nonbonded_forces=False`."
assert not combine_nonbonded_forces, (
"Custom non-bonded functional forms require `combine_nonbonded_forces=False`."
)

def store_potentials(self, parameter_handler: DoubleExponentialHandler) -> None:
"""
Expand Down

0 comments on commit 71e37a0

Please sign in to comment.