Skip to content

Commit 9f29507

Browse files
mattwthompsonj-wagspre-commit-ci[bot]
authored
Actually format with ruff (#2085)
* initial implementation of NAGLChargesHandler * have testing env use naglcharges interchange branch * implement doi and hash fields * add tests * fix tests * add docstring * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * force use of nagl for test * fix whitespace * Actually format with `ruff` * Update `Atom.stereochemistry` docstring * add doi and file_hash to nagltoolkitwrapper.assign_partial_charges, switch to use nagl_models' get_model method * raise specific error for blank/none model_file values * improve docstring * test with new openff-nagl-models * update nagl test for bad suffix error * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Run `pre-commit autoupdate && pre-commit run -a` * update toolkit registry check to use types rather than repr * add compatibility checks for doi and hash fields, add tests * lint * move imports to top of file * thread naglcharges handler into inits for correct import paths and docs * remove commented code * have tests run without interchange branch * point to nagl-models main branch for pip installs * update expected error message in test * revert tests to using conda packages * revert other test envs --------- Co-authored-by: Jeffrey Wagner <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent d70974d commit 9f29507

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+1432
-4123
lines changed

.pre-commit-config.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ ci:
33
files: ^openff|(^examples/((?!deprecated).)*$)|^docs|(^utilities/((?!deprecated).)*$)
44
repos:
55
- repo: https://github.com/astral-sh/ruff-pre-commit
6-
rev: v0.12.2
6+
rev: v0.12.8
77
hooks:
8-
- id: ruff
8+
- id: ruff-format
9+
- id: ruff-check
910
args: [--fix]
1011
- repo: https://github.com/adamchainz/blacken-docs
1112
rev: 1.19.1

docs/conf.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -272,9 +272,7 @@
272272

273273
# One entry per manual page. List of tuples
274274
# (source start file, name, description, authors, manual section).
275-
man_pages = [
276-
(master_doc, "openff-toolkit", "OpenFF Toolkit Documentation", [author], 1)
277-
]
275+
man_pages = [(master_doc, "openff-toolkit", "OpenFF Toolkit Documentation", [author], 1)]
278276

279277

280278
# -- Options for Texinfo output -------------------------------------------

docs/users/molecule_cookbook.ipynb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1135,9 +1135,7 @@
11351135
}
11361136
],
11371137
"source": [
1138-
"inchi = Molecule.from_inchi(\n",
1139-
" \"InChI=1S/C3H7NO2/c1-2(4)3(5)6/h2H,4H2,1H3,(H,5,6)/t2-/m0/s1\"\n",
1140-
")\n",
1138+
"inchi = Molecule.from_inchi(\"InChI=1S/C3H7NO2/c1-2(4)3(5)6/h2H,4H2,1H3,(H,5,6)/t2-/m0/s1\")\n",
11411139
"\n",
11421140
"inchi.visualize()"
11431141
]

examples/conformer_energies/conformer_energies.ipynb

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,7 @@
196196
" simulation.context.setPositions(conformer.to_openmm())\n",
197197
"\n",
198198
" # Keep a record of the initial energy\n",
199-
" initial_energies.append(\n",
200-
" simulation.context.getState(getEnergy=True).getPotentialEnergy()\n",
201-
" )\n",
199+
" initial_energies.append(simulation.context.getState(getEnergy=True).getPotentialEnergy())\n",
202200
"\n",
203201
" # Perform the minimization\n",
204202
" simulation.minimizeEnergy()\n",
@@ -309,7 +307,7 @@
309307
" # Save the minimized conformer to file\n",
310308
" working_mol.add_conformer(min_coords)\n",
311309
" working_mol.to_file(\n",
312-
" f\"{molecule.name}_conf{i+1}_minimized.sdf\",\n",
310+
" f\"{molecule.name}_conf{i + 1}_minimized.sdf\",\n",
313311
" file_format=\"sdf\",\n",
314312
" )\n",
315313
"\n",
@@ -329,11 +327,7 @@
329327
" minimization_rms,\n",
330328
" ]\n",
331329
" )\n",
332-
" print(\n",
333-
" f\"{{:5d}} / {n_confs:5d} : {{:8.3f}} kcal/mol {{:8.3f}} kcal/mol {{:8.3f}} Å\".format(\n",
334-
" *output[-1]\n",
335-
" )\n",
336-
" )\n",
330+
" print(f\"{{:5d}} / {n_confs:5d} : {{:8.3f}} kcal/mol {{:8.3f}} kcal/mol {{:8.3f}} Å\".format(*output[-1]))\n",
337331
"\n",
338332
"# Write the results out to CSV\n",
339333
"with open(f\"{molecule.name}.csv\", \"w\") as of:\n",

examples/conformer_energies/conformer_energies.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,7 @@ def compute_conformer_energies_from_file(filename):
6666
simulation.context.setPositions(conformer.to_openmm())
6767

6868
# Keep a record of the initial energy
69-
initial_energies.append(
70-
simulation.context.getState(getEnergy=True).getPotentialEnergy()
71-
)
69+
initial_energies.append(simulation.context.getState(getEnergy=True).getPotentialEnergy())
7270

7371
# Perform the minimization
7472
simulation.minimizeEnergy()
@@ -109,7 +107,7 @@ def compute_conformer_energies_from_file(filename):
109107
# Save the minimized conformer to file
110108
working_mol.add_conformer(min_coords)
111109
working_mol.to_file(
112-
f"{molecule.name}_conf{i+1}_minimized.sdf",
110+
f"{molecule.name}_conf{i + 1}_minimized.sdf",
113111
file_format="sdf",
114112
)
115113

@@ -129,11 +127,7 @@ def compute_conformer_energies_from_file(filename):
129127
minimization_rms,
130128
]
131129
)
132-
print(
133-
f"{{:5d}} / {n_confs:5d} : {{:8.3f}} kcal/mol {{:8.3f}} kcal/mol {{:8.3f}} Å".format(
134-
*output[-1]
135-
)
136-
)
130+
print(f"{{:5d}} / {n_confs:5d} : {{:8.3f}} kcal/mol {{:8.3f}} kcal/mol {{:8.3f}} Å".format(*output[-1]))
137131

138132
# Write the results out to CSV
139133
with open(f"{molecule.name}.csv", "w") as of:
@@ -150,9 +144,7 @@ def compute_conformer_energies_from_file(filename):
150144
"structure (both as STDOUT and a csv file). The minimized conformers will be written out to SDF."
151145
),
152146
)
153-
parser.add_argument(
154-
"-f", "--filename", help="Name of an input file containing conformers"
155-
)
147+
parser.add_argument("-f", "--filename", help="Name of an input file containing conformers")
156148
args = parser.parse_args()
157149

158150
compute_conformer_energies_from_file(args.filename)

examples/inspect_assigned_parameters/inspect_assigned_parameters.ipynb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,7 @@
143143
" atomstr = \"\"\n",
144144
" for idx in atom_indices:\n",
145145
" atomstr += f\"{idx:>3}\"\n",
146-
" print(\n",
147-
" f\"atoms: {atomstr} parameter_id: {parameter.id} smirks {parameter.smirks}\"\n",
148-
" )"
146+
" print(f\"atoms: {atomstr} parameter_id: {parameter.id} smirks {parameter.smirks}\")"
149147
]
150148
},
151149
{

examples/toolkit_showcase/toolkit_showcase.ipynb

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -327,9 +327,7 @@
327327
"outputs": [],
328328
"source": [
329329
"fixer = PDBFixer(receptor_path)\n",
330-
"fixer.addSolvent(\n",
331-
" padding=1.0 * openmm_unit.nanometer, ionicStrength=0.15 * openmm_unit.molar\n",
332-
")\n",
330+
"fixer.addSolvent(padding=1.0 * openmm_unit.nanometer, ionicStrength=0.15 * openmm_unit.molar)\n",
333331
"\n",
334332
"with open(\"receptor_solvated.pdb\", \"w\") as f:\n",
335333
" openmm.app.PDBFile.writeFile(fixer.topology, fixer.positions, f)\n",
@@ -390,9 +388,7 @@
390388
"\n",
391389
" # np.linalg.norm doesn't work on Pint quantities 😢\n",
392390
" working_unit = unit.nanometer\n",
393-
" distance_matrix = (\n",
394-
" np.linalg.norm(diff_matrix.m_as(working_unit), axis=-1) * working_unit\n",
395-
" )\n",
391+
" distance_matrix = np.linalg.norm(diff_matrix.m_as(working_unit), axis=-1) * working_unit\n",
396392
"\n",
397393
" if distance_matrix.min() > radius:\n",
398394
" # This molecule is not clashing, so add it to the topology\n",

examples/using_smirnoff_with_amber_protein_forcefield/BRD4_inhibitor_benchmark.ipynb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@
2121
"# https://github.com/MobleyLab/benchmarksets\n",
2222
"import requests\n",
2323
"\n",
24-
"repo_url = (\n",
25-
" \"https://raw.githubusercontent.com/MobleyLab/benchmarksets/master/input_files/\"\n",
26-
")\n",
24+
"repo_url = \"https://raw.githubusercontent.com/MobleyLab/benchmarksets/master/input_files/\"\n",
2725
"sources = {\n",
2826
" \"receptor.pdb\": repo_url + \"BRD4/pdb/BRD4.pdb\",\n",
2927
" \"ligand.pdb\": repo_url + \"BRD4/pdb/ligand-1.pdb\",\n",

examples/virtual_sites/vsite_showcase.ipynb

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -500,10 +500,7 @@
500500
" state = sim.context.getState(getEnergy=True, getPositions=True)\n",
501501
" ene = state.getPotentialEnergy()\n",
502502
" pos = openmm.unit.Quantity(\n",
503-
" [\n",
504-
" list(xyz)\n",
505-
" for xyz in state.getPositions().value_in_unit(openmm.unit.nanometer)\n",
506-
" ],\n",
503+
" [list(xyz) for xyz in state.getPositions().value_in_unit(openmm.unit.nanometer)],\n",
507504
" openmm.unit.nanometer,\n",
508505
" )\n",
509506
"\n",
@@ -628,12 +625,8 @@
628625
" # First, get an OpenMM Topology and atom positions with no virtual sites\n",
629626
" _topology: openmm.app.Topology = Topology.from_molecules(water).to_openmm()\n",
630627
"\n",
631-
" atom_positions_unitless = numpy.vstack(\n",
632-
" [mol.conformers[0].m_as(unit.nanometer) for mol in water]\n",
633-
" )\n",
634-
" atom_positions = openmm.unit.Quantity(\n",
635-
" atom_positions_unitless, openmm.unit.nanometer\n",
636-
" )\n",
628+
" atom_positions_unitless = numpy.vstack([mol.conformers[0].m_as(unit.nanometer) for mol in water])\n",
629+
" atom_positions = openmm.unit.Quantity(atom_positions_unitless, openmm.unit.nanometer)\n",
637630
"\n",
638631
" # Use OpenMM's Modeller to add virtual particles as perscribed by the force field\n",
639632
" modeller = openmm.app.Modeller(_topology, atom_positions)\n",
@@ -642,16 +635,12 @@
642635
" # This topology includes virtual particles, so we can use it to create a System\n",
643636
" topology = modeller.getTopology()\n",
644637
"\n",
645-
" system: openmm.System = openmm_force_field.createSystem(\n",
646-
" topology, nonbondedMethod=openmm.app.NoCutoff\n",
647-
" )\n",
638+
" system: openmm.System = openmm_force_field.createSystem(topology, nonbondedMethod=openmm.app.NoCutoff)\n",
648639
"\n",
649640
" # Add positions of virtual particles now that the topology includes them\n",
650641
" particle_positions = modeller.getPositions()\n",
651642
"\n",
652-
" return _evaluate_positions_and_energy(\n",
653-
" topology, system, particle_positions, minimize=minimize\n",
654-
" )"
643+
" return _evaluate_positions_and_energy(topology, system, particle_positions, minimize=minimize)"
655644
]
656645
},
657646
{
@@ -802,12 +791,10 @@
802791
" f\"{coordinate_difference.m:0.3e}\\n\"\n",
803792
")\n",
804793
"\n",
805-
"assert coordinate_difference < Quantity(\n",
806-
" 1e-6, unit.angstrom\n",
807-
"), f\"Coordinates differ by a norm of {coordinate_difference}\"\n",
808-
"assert (\n",
809-
" energy_difference < 1e-4 * openmm.unit.kilojoule_per_mole\n",
810-
"), f\"Energies differ by {energy_difference}\""
794+
"assert coordinate_difference < Quantity(1e-6, unit.angstrom), (\n",
795+
" f\"Coordinates differ by a norm of {coordinate_difference}\"\n",
796+
")\n",
797+
"assert energy_difference < 1e-4 * openmm.unit.kilojoule_per_mole, f\"Energies differ by {energy_difference}\""
811798
]
812799
},
813800
{

examples/visualization/visualization.ipynb

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -734,10 +734,7 @@
734734
},
735735
"outputs": [],
736736
"source": [
737-
"\n",
738-
"topology = Topology.from_pdb(\n",
739-
" get_data_file_path(\"systems/test_systems/T4_lysozyme_water_ions.pdb\")\n",
740-
")"
737+
"topology = Topology.from_pdb(get_data_file_path(\"systems/test_systems/T4_lysozyme_water_ions.pdb\"))"
741738
]
742739
},
743740
{

0 commit comments

Comments
 (0)