Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pre-commit.ci] pre-commit autoupdate #860

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ ci:
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.7.0
rev: v0.9.1
hooks:
# Run the linter.
- id: ruff
Expand Down
2 changes: 1 addition & 1 deletion gmso/abc/abstract_potential.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def add_tag(self, tag: str, value: Any, overwrite=True) -> None:
"""Add metadata for a particular tag"""
if self.tags.get(tag) and not overwrite:
raise ValueError(
f"Tag {tag} already exists. " f"Please use overwrite=True to overwrite"
f"Tag {tag} already exists. Please use overwrite=True to overwrite"
)
self.tags[tag] = value

Expand Down
2 changes: 1 addition & 1 deletion gmso/core/box.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def _validate_lengths(lengths):
):
if lengths[0] > 0 and lengths[1] > 0:
warnings.warn(
"A c value of 0 was passed. This will be " "interpreted as a 2-D box."
"A c value of 0 was passed. This will be interpreted as a 2-D box."
)
else:
raise ValueError(
Expand Down
5 changes: 2 additions & 3 deletions gmso/core/parametric_potential.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ def etree(self, units=None):
f"Please specify member_classes or member_types attribute."
)
for idx, value in enumerate(iterating_attribute):
attrib[f"{prefix}{idx+1}"] = str(value)
attrib[f"{prefix}{idx + 1}"] = str(value)
xml_element = etree.Element(self.__class__.__name__, attrib=attrib)
params = etree.SubElement(xml_element, "Parameters")

Expand Down Expand Up @@ -340,7 +340,6 @@ def member_types(x):

desc = desc.replace(
">",
f", \n parameters: {self.parameters},\n"
f"member types: {member_types(self)}>",
f", \n parameters: {self.parameters},\nmember types: {member_types(self)}>",
)
return desc
5 changes: 2 additions & 3 deletions gmso/core/topology.py
Original file line number Diff line number Diff line change
Expand Up @@ -793,8 +793,7 @@ def _set_scaling_factor(self, value, molecule_id, interaction, name, index):

if any(np.isnan(value)):
raise ValueError(
f"Cannot assign a nan/NoneType to `{name}`. "
f"Provided value: {org_value}"
f"Cannot assign a nan/NoneType to `{name}`. Provided value: {org_value}"
)

if value.shape != (1,) and value.shape != (3,):
Expand Down Expand Up @@ -1788,7 +1787,7 @@ def _parse_parameter_expression(self, df, parameter, unyts_bool):
getattr(getattr(self, parameter)[0], parameter[:-1] + "_type").parameters
):
df[
f"Parameter {i} ({param}) {getattr(getattr(self, parameter)[0], parameter[:-1]+'_type').parameters[param].units}"
f"Parameter {i} ({param}) {getattr(getattr(self, parameter)[0], parameter[:-1] + '_type').parameters[param].units}"
] = list(
_return_float_for_unyt(
getattr(connection, parameter[:-1] + "_type").parameters[param],
Expand Down
2 changes: 1 addition & 1 deletion gmso/external/convert_foyer_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ def _write_nbforces(forcefield, ff_kwargs):
nonBondedAtomTypes,
"AtomType",
attrib_dict={
"name": atom_type.get("name", f"AtomType-{j+1}"),
"name": atom_type.get("name", f"AtomType-{j + 1}"),
"atomclass": atom_type.get("class", ""),
"element": atom_type.get("element", ""),
"charge": atom_type.get("charge", "0.0"),
Expand Down
2 changes: 1 addition & 1 deletion gmso/external/convert_hoomd.py
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,7 @@ def _parse_nonbonded_forces(
if i == 0:
exclusions.append("bond")
else:
exclusions.append(f"1-{i+2}")
exclusions.append(f"1-{i + 2}")
nlist = hoomd.md.nlist.Cell(exclusions=exclusions, buffer=nlist_buffer)

nbonded_forces = list()
Expand Down
6 changes: 4 additions & 2 deletions gmso/formats/lammpsdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,9 @@ def _validate_unit_compatibility(top, base_unyts):
float(base_unyts.convert_parameter(parameter, n_decimals=6, name=name)),
parameter.value,
atol=1e-3,
), f"Units System {base_unyts.usystem} is not compatible with {atype} with value {parameter}"
), (
f"Units System {base_unyts.usystem} is not compatible with {atype} with value {parameter}"
)


def _write_header(out_file, top, atom_style, dihedral_parser):
Expand Down Expand Up @@ -1171,7 +1173,7 @@ def _write_conn_data(out_file, top, connStr, sorted_typesList):
if sort_by_types(ele) == ctype_members
]
for index in indexList:
typeStr = f"{i+1:<6d}\t{index+1:<6d}\t"
typeStr = f"{i + 1:<6d}\t{index + 1:<6d}\t"
sorted_membersList = sort_connection_members(conn, sort_by="index", top=top)
indexStr = "\t".join(
[
Expand Down
23 changes: 11 additions & 12 deletions gmso/formats/mcf.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ def _write_atom_information(mcf, top, in_ring):
mcf.write("{:d}\n".format(len(top.sites)))
for idx, site in enumerate(top.sites):
mcf.write(
"{:<4d} " "{:<6s} " "{:<2s} " "{:8.4f} " "{:12.8f} ".format(
"{:<4d} {:<6s} {:<2s} {:8.4f} {:12.8f} ".format(
idx + 1,
atypes_list[idx],
names[idx],
Expand All @@ -325,15 +325,15 @@ def _write_atom_information(mcf, top, in_ring):
)
if vdw_style == "LJ":
mcf.write(
"{:3s} " "{:10.5f} " "{:10.5f}".format(
"{:3s} {:10.5f} {:10.5f}".format(
vdw_style,
(site.atom_type.parameters["epsilon"] / u.kb).in_units("K").value,
site.atom_type.parameters["sigma"].in_units("Angstrom").value,
)
)
elif vdw_style == "Mie":
mcf.write(
"{:3s} " "{:10.5f} " "{:10.5f} " "{:8.3f} " "{:8.3f}".format(
"{:3s} {:10.5f} {:10.5f} {:8.3f} {:8.3f}".format(
vdw_style,
(site.atom_type.parameters["epsilon"] / u.kb).in_units("K").value,
site.atom_type.parameters["sigma"].in_units("Angstrom").value,
Expand Down Expand Up @@ -363,7 +363,7 @@ def _write_bond_information(mcf, top):
mcf.write("{:d}\n".format(len(top.bonds)))
for idx, bond in enumerate(top.bonds):
mcf.write(
"{:<4d} " "{:<4d} " "{:<4d} " "{:s} " "{:10.5f}\n".format(
"{:<4d} {:<4d} {:<4d} {:s} {:10.5f}\n".format(
idx + 1,
top.get_index(bond.connection_members[0]) + 1,
top.get_index(bond.connection_members[1]) + 1,
Expand Down Expand Up @@ -403,7 +403,7 @@ def _write_angle_information(mcf, top):
angle_style = _get_angle_style(angle)
if angle_style == "fixed":
mcf.write(
"{:s} " "{:10.5f}\n".format(
"{:s} {:10.5f}\n".format(
angle_style,
angle.connection_type.parameters["theta_eq"]
.in_units(u.degree)
Expand All @@ -412,7 +412,7 @@ def _write_angle_information(mcf, top):
)
elif angle_style == "harmonic":
mcf.write(
"{:s} " "{:10.5f} " "{:10.5f}\n".format(
"{:s} {:10.5f} {:10.5f}\n".format(
angle_style,
(0.5 * angle.connection_type.parameters["k"] / u.kb)
.in_units("K/rad**2")
Expand Down Expand Up @@ -452,7 +452,7 @@ def _write_dihedral_information(mcf, top):
mcf.write("{:d}\n".format(len(top.dihedrals)))
for idx, dihedral in enumerate(top.dihedrals):
mcf.write(
"{:<4d} " "{:<4d} " "{:<4d} " "{:<4d} " "{:<4d} ".format(
"{:<4d} {:<4d} {:<4d} {:<4d} {:<4d} ".format(
idx + 1,
top.get_index(dihedral.connection_members[0]) + 1,
top.get_index(dihedral.connection_members[1]) + 1,
Expand Down Expand Up @@ -488,7 +488,7 @@ def _write_dihedral_information(mcf, top):
# So we need to exclude the last term in the GMSO topology.
dihedral_style = "OPLS"
mcf.write(
"{:s} " "{:10.5f} " "{:10.5f} " "{:10.5f} " "{:10.5f}\n".format(
"{:s} {:10.5f} {:10.5f} {:10.5f} {:10.5f}\n".format(
dihedral_style,
0.5
* dihedral.connection_type.parameters["k0"]
Expand All @@ -510,7 +510,7 @@ def _write_dihedral_information(mcf, top):
)
elif dihedral_style == "CHARMM":
mcf.write(
"{:s} " "{:10.5f} " "{:10.5f} " "{:10.5f}\n".format(
"{:s} {:10.5f} {:10.5f} {:10.5f}\n".format(
dihedral_style,
dihedral.connection_type.parameters["k"].in_units("kJ/mol").value,
dihedral.connection_type.parameters["n"],
Expand All @@ -521,7 +521,7 @@ def _write_dihedral_information(mcf, top):
)
elif dihedral_style == "HARMONIC":
mcf.write(
"{:s} " "{:10.5f} " "{:10.5f}\n".format(
"{:s} {:10.5f} {:10.5f}\n".format(
dihedral_style.lower(),
0.5
* dihedral.connection_type.parameters["k"].in_units("kJ/mol").value,
Expand Down Expand Up @@ -558,8 +558,7 @@ def _write_improper_information(mcf, top):
improper_style = "harmonic"
for i, improper in enumerate(top.impropers):
mcf.write(
"{:<4d} {:<4d} {:<4d} {:<4d} {:<4d}"
" {:s} {:10.5f} {:10.5f}\n".format(
"{:<4d} {:<4d} {:<4d} {:<4d} {:<4d} {:s} {:10.5f} {:10.5f}\n".format(
i + 1,
top.get_index(improper.connection_members[0]) + 1,
top.get_index(improper.connection_members[1]) + 1,
Expand Down
47 changes: 11 additions & 36 deletions gmso/formats/top.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,10 @@ def write_top(top, filename, top_vars=None):
)
)
out_file.write(
"[ defaults ]\n"
"; nbfunc\t"
"comb-rule\t"
"gen-pairs\t"
"fudgeLJ\t\t"
"fudgeQQ\n"
"[ defaults ]\n; nbfunc\tcomb-rule\tgen-pairs\tfudgeLJ\t\tfudgeQQ\n"
)
out_file.write(
"{0}\t\t" "{1}\t\t" "{2}\t\t" "{3}\t\t" "{4}\n\n".format(
"{0}\t\t{1}\t\t{2}\t\t{3}\t\t{4}\n\n".format(
top_vars["nbfunc"],
top_vars["comb-rule"],
top_vars["gen-pairs"],
Expand All @@ -76,25 +71,12 @@ def write_top(top, filename, top_vars=None):
)

out_file.write(
"[ atomtypes ]\n"
"; name\t"
"at.num\t\t"
"mass\t"
"charge\t\t"
"ptype\t"
"sigma\t"
"epsilon\n"
"[ atomtypes ]\n; name\tat.num\t\tmass\tcharge\t\tptype\tsigma\tepsilon\n"
)

for atom_type in top.atom_types(PotentialFilters.UNIQUE_NAME_CLASS):
out_file.write(
"{0:12s}"
"{1:4s}"
"{2:12.5f}"
"{3:12.5f}\t"
"{4:4s}"
"{5:12.5f}"
"{6:12.5f}\n".format(
"{0:12s}{1:4s}{2:12.5f}{3:12.5f}\t{4:4s}{5:12.5f}{6:12.5f}\n".format(
atom_type.name,
str(_lookup_atomic_number(atom_type)),
atom_type.mass.in_units(u.amu).value,
Expand All @@ -115,7 +97,7 @@ def write_top(top, filename, top_vars=None):
"bond_restraints": "\n[ bonds ] ;Harmonic potential restraint\n"
"; ai\taj\tfunct\tb0\t\tkb\n",
"pairs": "\n[ pairs ]\n; ai\taj\tfunct\n",
"angles": "\n[ angles ]\n" "; ai\taj\tak\tfunct\tphi_0\t\tk0\n",
"angles": "\n[ angles ]\n; ai\taj\tak\tfunct\tphi_0\t\tk0\n",
"angle_restraints": (
"\n[ angle_restraints ]\n"
"; ai\taj\tai\tak\tfunct\ttheta_eq\tk\tmultiplicity\n"
Expand All @@ -132,14 +114,14 @@ def write_top(top, filename, top_vars=None):
}
for tag in unique_molecules:
"""Write out nrexcl for each unique molecule."""
out_file.write("\n[ moleculetype ]\n" "; name\tnrexcl\n")
out_file.write("\n[ moleculetype ]\n; name\tnrexcl\n")

# TODO: Lookup and join nrexcl from each molecule object
out_file.write("{0}\t" "{1}\n\n".format(tag, top_vars["nrexcl"]))
out_file.write("{0}\t{1}\n\n".format(tag, top_vars["nrexcl"]))

"""Write out atoms for each unique molecule."""
out_file.write(
"[ atoms ]\n" "; nr\ttype\tresnr\tresidue\t\tatom\tcgnr\tcharge\tmass\n"
"[ atoms ]\n; nr\ttype\tresnr\tresidue\t\tatom\tcgnr\tcharge\tmass\n"
)
# Each unique molecule need to be reindexed (restarting from 0)
# The shifted_idx_map is needed to make sure all the atom index used in
Expand All @@ -148,14 +130,7 @@ def write_top(top, filename, top_vars=None):
for idx, site in enumerate(unique_molecules[tag]["sites"]):
shifted_idx_map[top.get_index(site)] = idx
out_file.write(
"{0:8s}"
"{1:12s}"
"{2:8s}"
"{3:12s}"
"{4:8s}"
"{5:4s}"
"{6:12.5f}"
"{7:12.5f}\n".format(
"{0:8s}{1:12s}{2:8s}{3:12s}{4:8s}{5:4s}{6:12.5f}{7:12.5f}\n".format(
str(idx + 1),
site.atom_type.name,
str(site.molecule.number + 1 if site.molecule else 1),
Expand Down Expand Up @@ -302,9 +277,9 @@ def write_top(top, filename, top_vars=None):
)
)

out_file.write("\n[ system ]\n" "; name\n" "{0}\n\n".format(top.name))
out_file.write("\n[ system ]\n; name\n{0}\n\n".format(top.name))

out_file.write("[ molecules ]\n" "; molecule\tnmols\n")
out_file.write("[ molecules ]\n; molecule\tnmols\n")
for tag in unique_molecules:
out_file.write(
"{0}\t{1}\n".format(tag, len(unique_molecules[tag]["subtags"]))
Expand Down
14 changes: 7 additions & 7 deletions gmso/lib/potential_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@
def _verify_potential_template_keys(_dict, name):
"""Verify the potential template is properly formatted."""
assert "name" in _dict, f"Key name not found in the potential template {name}.json"
assert (
"expression" in _dict
), f"Key expression not found in the potential template {name}.json"
assert (
"independent_variables" in _dict
), f"Key independent_variables not found in the potential template {name}.json"
assert "expression" in _dict, (
f"Key expression not found in the potential template {name}.json"
)
assert "independent_variables" in _dict, (
f"Key independent_variables not found in the potential template {name}.json"
)
if str(name) != _dict["name"]:
raise GMSOError(f'Mismatch between Potential name {name} and {_dict["name"]}')
raise GMSOError(f"Mismatch between Potential name {name} and {_dict['name']}")


def _load_template_json(item, json_dir=JSON_DIR):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def test_no_molecule_dict_ff(self, oplsaa_gmso):
def test_missing_group_name_ff(self, oplsaa_gmso):
top = Topology(name="top1")
for j in range(0, 10, 2):
top.add_site(gmso.Atom(name=f"Atom_{j+1}", group="groupB"))
top.add_site(gmso.Atom(name=f"Atom_{j + 1}", group="groupB"))
with pytest.warns(
UserWarning,
match=r"Group/molecule groupB will not be parameterized, as the forcefield "
Expand Down
2 changes: 1 addition & 1 deletion gmso/tests/test_convert_parmed.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ def test_from_parmed_impropers(self):
):
pmd_member_names = list(
atom.name
for atom in [getattr(pmd_improper, f"atom{j+1}") for j in range(4)]
for atom in [getattr(pmd_improper, f"atom{j + 1}") for j in range(4)]
)
gmso_member_names = list(
map(lambda a: a.name, gmso_improper.connection_members)
Expand Down
3 changes: 1 addition & 2 deletions gmso/tests/test_expression.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ def test_non_parametric_expression(self):
with pytest.raises(AttributeError) as e:
assert expression.parameters
assert (
"Object of type _PotentialExpression "
"has no attribute parameters" in e
"Object of type _PotentialExpression has no attribute parameters" in e
)

def test_set_indep_variables(self):
Expand Down
6 changes: 3 additions & 3 deletions gmso/tests/test_improper.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,9 @@ def sort_improper_connection_members(improper):
last_site = site
else:
middle_sitesList.append(site)
assert (
len(middle_sitesList) == 2
), f"The improper_type {improper.improper_type} could not find 2 middle sites from {middle_sitesList}"
assert len(middle_sitesList) == 2, (
f"The improper_type {improper.improper_type} could not find 2 middle sites from {middle_sitesList}"
)
middle_sitesList = sorted(
middle_sitesList,
key=lambda site: getattr(site.atom_type, orderStr),
Expand Down
6 changes: 3 additions & 3 deletions gmso/tests/test_lammps.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ def compare_lammps_files(line1, line2, skip_linesList=[], offsets=None):
comp1 = str(arg1)
comp2 = str(arg2)
if isinstance(comp1, float):
assert np.isclose(
comp1, comp2, 1e-3
), f"The following two lines have not been found to have equality {l1} and {l2}"
assert np.isclose(comp1, comp2, 1e-3), (
f"The following two lines have not been found to have equality {l1} and {l2}"
)
line_counter1 += 1
line_counter2 += 1
if line_counter1 >= length1 or line_counter2 >= length2:
Expand Down
4 changes: 2 additions & 2 deletions gmso/utils/connectivity.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,10 +323,10 @@ def generate_pairs_lists(
if refer_from_scaling_factor:
for i in range(3):
if nb_scalings[i] or coulombic_scalings[i]:
pairs_dict[f"pairs1{i+2}"] = list()
pairs_dict[f"pairs1{i + 2}"] = list()
else:
for i in range(3):
pairs_dict = {f"pairs1{i+2}": list() for i in range(3)}
pairs_dict = {f"pairs1{i + 2}": list() for i in range(3)}

if molecule is None:
bonds, angles, dihedrals = top.bonds, top.angles, top.dihedrals
Expand Down
Loading
Loading