From 804a6570e39ef7a2f37a68a19bb95a42d372fb4d Mon Sep 17 00:00:00 2001 From: Mike Henry <11765982+mikemhenry@users.noreply.github.com> Date: Fri, 16 Feb 2024 01:44:51 -0700 Subject: [PATCH] linted! --- openfe/analysis/plotting.py | 2 +- openfe/due.py | 2 +- .../openmm_rfe/_rfe_utils/lambdaprotocol.py | 2 +- openfe/protocols/openmm_rfe/_rfe_utils/multistate.py | 10 +++++----- .../openmm_rfe/_rfe_utils/topologyhelpers.py | 12 +++++------- openfe/protocols/openmm_utils/system_validation.py | 2 +- .../abstract_alchemical_network_planner.py | 2 +- .../relative_alchemical_network_planner.py | 5 +++-- openfe/setup/atom_mapping/ligandatommapper.py | 2 +- .../abstract_chemicalsystem_generator.py | 2 +- .../easy_chemicalsystem_generator.py | 3 ++- openfe/setup/ligand_network_planning.py | 9 +++++---- openfe/storage/metadatastore.py | 2 +- .../protocols/test_openmm_equil_rfe_protocols.py | 4 ++-- openfe/tests/setup/atom_mapping/conftest.py | 8 ++++---- openfe/tests/storage/test_metadatastore.py | 4 ++-- openfe/tests/storage/test_resultclient.py | 2 +- openfe/tests/storage/test_resultserver.py | 6 +++--- openfe/tests/utils/conftest.py | 3 ++- .../tests/utils/test_atommapping_network_plotting.py | 2 +- openfe/tests/utils/test_network_plotting.py | 2 +- openfe/utils/atommapping_network_plotting.py | 6 +++--- openfe/utils/network_plotting.py | 8 ++++---- openfe/utils/system_probe.py | 3 ++- openfe/utils/visualization_3D.py | 11 ++++++----- openfecli/commands/gather.py | 4 ++-- openfecli/commands/plan_rbfe_network.py | 2 +- openfecli/commands/plan_rhfe_network.py | 2 +- openfecli/parameters/plan_network_options.py | 2 +- openfecli/tests/commands/test_quickrun.py | 2 +- 30 files changed, 65 insertions(+), 61 deletions(-) diff --git a/openfe/analysis/plotting.py b/openfe/analysis/plotting.py index de907749d..fffb225f6 100644 --- a/openfe/analysis/plotting.py +++ b/openfe/analysis/plotting.py @@ -33,7 +33,7 @@ def plot_lambda_transition_matrix(matrix: npt.NDArray) -> Axes: ax.axhline(y=i, ls="-", lw=0.5, color="k", alpha=0.25) for j in range(num_states): val = matrix[i, j] - val_str = "{:.2f}".format(val)[1:] + val_str = f"{val:.2f}"[1:] rel_prob = val / matrix.max() # shade box diff --git a/openfe/due.py b/openfe/due.py index 4a4179488..cdc7d8a7f 100644 --- a/openfe/due.py +++ b/openfe/due.py @@ -27,7 +27,7 @@ __version__ = "0.0.9" -class InactiveDueCreditCollector(object): +class InactiveDueCreditCollector: """Just a stub at the Collector which would not do anything""" def _donothing(self, *args, **kwargs): diff --git a/openfe/protocols/openmm_rfe/_rfe_utils/lambdaprotocol.py b/openfe/protocols/openmm_rfe/_rfe_utils/lambdaprotocol.py index 38b494c93..66869775d 100644 --- a/openfe/protocols/openmm_rfe/_rfe_utils/lambdaprotocol.py +++ b/openfe/protocols/openmm_rfe/_rfe_utils/lambdaprotocol.py @@ -9,7 +9,7 @@ from openmmtools.alchemy import AlchemicalState -class LambdaProtocol(object): +class LambdaProtocol: """Protocols for perturbing each of the component energy terms in alchemical free energy simulations. diff --git a/openfe/protocols/openmm_rfe/_rfe_utils/multistate.py b/openfe/protocols/openmm_rfe/_rfe_utils/multistate.py index 7c7fd8c1e..6545b0707 100644 --- a/openfe/protocols/openmm_rfe/_rfe_utils/multistate.py +++ b/openfe/protocols/openmm_rfe/_rfe_utils/multistate.py @@ -24,7 +24,7 @@ logger = logging.getLogger(__name__) -class HybridCompatibilityMixin(object): +class HybridCompatibilityMixin: """ Mixin that allows the MultistateSampler to accommodate the situation where unsampled endpoints have a different number of degrees of freedom. @@ -32,7 +32,7 @@ class HybridCompatibilityMixin(object): def __init__(self, *args, hybrid_factory=None, **kwargs): self._hybrid_factory = hybrid_factory - super(HybridCompatibilityMixin, self).__init__(*args, **kwargs) + super().__init__(*args, **kwargs) def setup( self, @@ -167,7 +167,7 @@ class HybridRepexSampler(HybridCompatibilityMixin, replicaexchange.ReplicaExchan """ def __init__(self, *args, hybrid_factory=None, **kwargs): - super(HybridRepexSampler, self).__init__(*args, hybrid_factory=hybrid_factory, **kwargs) + super().__init__(*args, hybrid_factory=hybrid_factory, **kwargs) self._factory = hybrid_factory @@ -178,7 +178,7 @@ class HybridSAMSSampler(HybridCompatibilityMixin, sams.SAMSSampler): """ def __init__(self, *args, hybrid_factory=None, **kwargs): - super(HybridSAMSSampler, self).__init__(*args, hybrid_factory=hybrid_factory, **kwargs) + super().__init__(*args, hybrid_factory=hybrid_factory, **kwargs) self._factory = hybrid_factory @@ -189,7 +189,7 @@ class HybridMultiStateSampler(HybridCompatibilityMixin, multistatesampler.MultiS """ def __init__(self, *args, hybrid_factory=None, **kwargs): - super(HybridMultiStateSampler, self).__init__(*args, hybrid_factory=hybrid_factory, **kwargs) + super().__init__(*args, hybrid_factory=hybrid_factory, **kwargs) self._factory = hybrid_factory diff --git a/openfe/protocols/openmm_rfe/_rfe_utils/topologyhelpers.py b/openfe/protocols/openmm_rfe/_rfe_utils/topologyhelpers.py index c816ba6fd..181e7345b 100644 --- a/openfe/protocols/openmm_rfe/_rfe_utils/topologyhelpers.py +++ b/openfe/protocols/openmm_rfe/_rfe_utils/topologyhelpers.py @@ -277,13 +277,11 @@ def get_alchemical_waters( periodic=True, )[0] - solvent_indices = set( - [ - atom.residue.index - for atom in traj.topology.atoms - if (atom.index in water_atoms) and (atom.index not in excluded_waters) - ], - ) + solvent_indices = { + atom.residue.index + for atom in traj.topology.atoms + if (atom.index in water_atoms) and (atom.index not in excluded_waters) + } if len(solvent_indices) < 1: errmsg = ( diff --git a/openfe/protocols/openmm_utils/system_validation.py b/openfe/protocols/openmm_utils/system_validation.py index 8f99b4d2e..65eb4e866 100644 --- a/openfe/protocols/openmm_utils/system_validation.py +++ b/openfe/protocols/openmm_utils/system_validation.py @@ -126,7 +126,7 @@ def validate_protein(state: ChemicalSystem): raise ValueError(errmsg) -ParseCompRet = Tuple[ +ParseCompRet = tuple[ Optional[SolventComponent], Optional[ProteinComponent], list[SmallMoleculeComponent], diff --git a/openfe/setup/alchemical_network_planner/abstract_alchemical_network_planner.py b/openfe/setup/alchemical_network_planner/abstract_alchemical_network_planner.py index 70b5f79d9..2d1b7fce5 100644 --- a/openfe/setup/alchemical_network_planner/abstract_alchemical_network_planner.py +++ b/openfe/setup/alchemical_network_planner/abstract_alchemical_network_planner.py @@ -2,7 +2,7 @@ # For details, see https://github.com/OpenFreeEnergy/openfe import abc -from typing import Iterable +from collections.abc import Iterable from gufe import AlchemicalNetwork diff --git a/openfe/setup/alchemical_network_planner/relative_alchemical_network_planner.py b/openfe/setup/alchemical_network_planner/relative_alchemical_network_planner.py index 1046bf645..9b4b0eb08 100644 --- a/openfe/setup/alchemical_network_planner/relative_alchemical_network_planner.py +++ b/openfe/setup/alchemical_network_planner/relative_alchemical_network_planner.py @@ -2,7 +2,8 @@ # For details, see https://github.com/OpenFreeEnergy/openfe import abc import copy -from typing import Callable, Iterable, Optional, Type +from collections.abc import Iterable +from typing import Callable, Optional, Type from gufe import ( AlchemicalNetwork, @@ -93,7 +94,7 @@ def transformation_protocol(self) -> Protocol: @property def chemical_system_generator_type( self, - ) -> Type[AbstractChemicalSystemGenerator]: + ) -> type[AbstractChemicalSystemGenerator]: return self._chemical_system_generator_type def _construct_ligand_network(self, ligands: Iterable[SmallMoleculeComponent]) -> LigandNetwork: diff --git a/openfe/setup/atom_mapping/ligandatommapper.py b/openfe/setup/atom_mapping/ligandatommapper.py index c68e6a7b0..17a493b90 100644 --- a/openfe/setup/atom_mapping/ligandatommapper.py +++ b/openfe/setup/atom_mapping/ligandatommapper.py @@ -1,7 +1,7 @@ # This code is part of OpenFE and is licensed under the MIT license. # For details, see https://github.com/OpenFreeEnergy/openfe import abc -from typing import Iterable +from collections.abc import Iterable import gufe from gufe import SmallMoleculeComponent diff --git a/openfe/setup/chemicalsystem_generator/abstract_chemicalsystem_generator.py b/openfe/setup/chemicalsystem_generator/abstract_chemicalsystem_generator.py index af515555f..cd96d0c23 100644 --- a/openfe/setup/chemicalsystem_generator/abstract_chemicalsystem_generator.py +++ b/openfe/setup/chemicalsystem_generator/abstract_chemicalsystem_generator.py @@ -1,8 +1,8 @@ # This code is part of OpenFE and is licensed under the MIT license. # For details, see https://github.com/OpenFreeEnergy/openfe import abc +from collections.abc import Iterable from enum import Enum -from typing import Iterable from gufe import ChemicalSystem diff --git a/openfe/setup/chemicalsystem_generator/easy_chemicalsystem_generator.py b/openfe/setup/chemicalsystem_generator/easy_chemicalsystem_generator.py index 344b0f16d..be138b682 100644 --- a/openfe/setup/chemicalsystem_generator/easy_chemicalsystem_generator.py +++ b/openfe/setup/chemicalsystem_generator/easy_chemicalsystem_generator.py @@ -1,7 +1,8 @@ # This code is part of OpenFE and is licensed under the MIT license. # For details, see https://github.com/OpenFreeEnergy/openfe -from typing import Iterable, Optional +from collections.abc import Iterable +from typing import Optional from gufe import ChemicalSystem, Component, ProteinComponent, SmallMoleculeComponent, SolventComponent diff --git a/openfe/setup/ligand_network_planning.py b/openfe/setup/ligand_network_planning.py index ec5977950..c5e9de184 100644 --- a/openfe/setup/ligand_network_planning.py +++ b/openfe/setup/ligand_network_planning.py @@ -5,8 +5,9 @@ import math import warnings from collections import Counter +from collections.abc import Iterable from pathlib import Path -from typing import Callable, Iterable, Optional, Union +from typing import Callable, Optional, Union import networkx as nx from gufe import AtomMapper, SmallMoleculeComponent @@ -330,7 +331,7 @@ def generate_network_from_names( nm2idx = {l.name: i for i, l in enumerate(ligands)} if len(nm2idx) < len(ligands): - dupes = Counter((l.name for l in ligands)) + dupes = Counter(l.name for l in ligands) dupe_names = [k for k, v in dupes.items() if v > 1] raise ValueError(f"Duplicate names: {dupe_names}") @@ -418,7 +419,7 @@ def load_orion_network( If an unexpected line format is encountered. """ - with open(network_file, "r") as f: + with open(network_file) as f: network_lines = [l.strip().split(" ") for l in f if not l.startswith("#")] names = [] @@ -458,7 +459,7 @@ def load_fepplus_network( If an unexpected line format is encountered. """ - with open(network_file, "r") as f: + with open(network_file) as f: network_lines = [l.split() for l in f.readlines()] names = [] diff --git a/openfe/storage/metadatastore.py b/openfe/storage/metadatastore.py index ff702ee60..5916777dd 100644 --- a/openfe/storage/metadatastore.py +++ b/openfe/storage/metadatastore.py @@ -19,7 +19,7 @@ def store_metadata(self, location: str, metadata: Metadata): raise NotImplementedError() @abc.abstractmethod - def load_all_metadata(self) -> Dict[str, Metadata]: + def load_all_metadata(self) -> dict[str, Metadata]: raise NotImplementedError() @abc.abstractmethod diff --git a/openfe/tests/protocols/test_openmm_equil_rfe_protocols.py b/openfe/tests/protocols/test_openmm_equil_rfe_protocols.py index 22efeacd1..0a916148e 100644 --- a/openfe/tests/protocols/test_openmm_equil_rfe_protocols.py +++ b/openfe/tests/protocols/test_openmm_equil_rfe_protocols.py @@ -1477,7 +1477,7 @@ def tyk2_xml(tmp_path_factory): def tyk2_reference_xml(): with resources.files("openfe.tests.data.openmm_rfe") as d: f = d / "reference.xml" - with open(f, "r") as i: + with open(f) as i: xmldata = i.read() return ET.fromstring(xmldata) @@ -1620,7 +1620,7 @@ def test_filenotfound_replica_states(self, protocolresult): def test_get_charge_difference(mapping_name, result, request): mapping = request.getfixturevalue(mapping_name) if result != 0: - ion = "Na\+" if result == -1 else "Cl\-" + ion = r"Na\+" if result == -1 else r"Cl\-" wmsg = ( f"A charge difference of {result} is observed " "between the end states. This will be addressed by " diff --git a/openfe/tests/setup/atom_mapping/conftest.py b/openfe/tests/setup/atom_mapping/conftest.py index 0890a277b..e21b9215d 100644 --- a/openfe/tests/setup/atom_mapping/conftest.py +++ b/openfe/tests/setup/atom_mapping/conftest.py @@ -13,12 +13,12 @@ from ...conftest import mol_from_smiles -def _translate_lomap_mapping(atom_mapping_str: str) -> Dict[int, int]: +def _translate_lomap_mapping(atom_mapping_str: str) -> dict[int, int]: mapped_atom_tuples = map(lambda x: tuple(map(int, x.split(":"))), atom_mapping_str.split(",")) return {i: j for i, j in mapped_atom_tuples} -def _get_atom_mapping_dict(lomap_atom_mappings) -> Dict[Tuple[int, int], Dict[int, int]]: +def _get_atom_mapping_dict(lomap_atom_mappings) -> dict[tuple[int, int], dict[int, int]]: return { mol_pair: _translate_lomap_mapping(atom_mapping_str) for mol_pair, atom_mapping_str in lomap_atom_mappings.mcs_map_store.items() @@ -29,7 +29,7 @@ def _get_atom_mapping_dict(lomap_atom_mappings) -> Dict[Tuple[int, int], Dict[in def gufe_atom_mapping_matrix( lomap_basic_test_files_dir, atom_mapping_basic_test_files, -) -> Dict[Tuple[int, int], LigandAtomMapping]: +) -> dict[tuple[int, int], LigandAtomMapping]: dbmols = lomap.DBMolecules(lomap_basic_test_files_dir, verbose="off") _, _ = dbmols.build_matrices() molecule_pair_atom_mappings = _get_atom_mapping_dict(dbmols) @@ -48,7 +48,7 @@ def gufe_atom_mapping_matrix( @pytest.fixture() -def mol_pair_to_shock_perses_mapper() -> Tuple[SmallMoleculeComponent, SmallMoleculeComponent]: +def mol_pair_to_shock_perses_mapper() -> tuple[SmallMoleculeComponent, SmallMoleculeComponent]: """ This pair of Molecules leads to an empty Atom mapping in Perses Mapper with certain settings. diff --git a/openfe/tests/storage/test_metadatastore.py b/openfe/tests/storage/test_metadatastore.py index 40dd34dcc..4ca116d68 100644 --- a/openfe/tests/storage/test_metadatastore.py +++ b/openfe/tests/storage/test_metadatastore.py @@ -75,7 +75,7 @@ def test_store_metadata(self, json_metadata): base_path = json_metadata.external_store.root_dir metadata_json = base_path / "metadata.json" assert metadata_json.exists() - with open(metadata_json, mode="r") as f: + with open(metadata_json) as f: metadata_dict = json.load(f) metadata = {key: Metadata(**val) for key, val in metadata_dict.items()} @@ -117,7 +117,7 @@ def test_store_metadata(self, per_file_metadata): per_file_metadata.store_metadata("path/to/other.txt", meta) assert expected_path.exists() expected = {"path": "path/to/other.txt", "metadata": {"md5": "other"}} - with open(expected_path, mode="r") as f: + with open(expected_path) as f: assert json.load(f) == expected def test_load_all_metadata(self, per_file_metadata): diff --git a/openfe/tests/storage/test_resultclient.py b/openfe/tests/storage/test_resultclient.py index 68a72c646..470a3844a 100644 --- a/openfe/tests/storage/test_resultclient.py +++ b/openfe/tests/storage/test_resultclient.py @@ -14,7 +14,7 @@ def result_client(tmpdir): result_client = ResultClient(external) # store one file with contents "foo" - result_client.result_server.store_bytes("transformations/MAIN_TRANS/0/0/file.txt", "foo".encode("utf-8")) + result_client.result_server.store_bytes("transformations/MAIN_TRANS/0/0/file.txt", b"foo") # create some empty files as well empty_files = [ diff --git a/openfe/tests/storage/test_resultserver.py b/openfe/tests/storage/test_resultserver.py index 35729fd9b..b3a2ef075 100644 --- a/openfe/tests/storage/test_resultserver.py +++ b/openfe/tests/storage/test_resultserver.py @@ -15,7 +15,7 @@ def result_server(tmpdir): external = FileStorage(tmpdir) metadata = JSONMetadataStore(external) result_server = ResultServer(external, metadata) - result_server.store_bytes("path/to/foo.txt", "foo".encode("utf-8")) + result_server.store_bytes("path/to/foo.txt", b"foo") return result_server @@ -32,7 +32,7 @@ def test_store_bytes(self, result_server): mock_hash = mock.Mock(return_value=mock.Mock(hexdigest=mock.Mock(return_value="deadbeef"))) bar_loc = "path/to/bar.txt" with mock.patch("hashlib.md5", mock_hash): - result_server.store_bytes(bar_loc, "bar".encode("utf-8")) + result_server.store_bytes(bar_loc, b"bar") assert len(metadata_store) == 2 assert bar_loc in metadata_store @@ -46,7 +46,7 @@ def test_store_path(self, result_server, tmp_path): orig_file = tmp_path / ".hidden" / "bar.txt" orig_file.parent.mkdir(parents=True, exist_ok=True) with open(orig_file, mode="wb") as f: - f.write("bar".encode("utf-8")) + f.write(b"bar") mock_hash = mock.Mock(return_value=mock.Mock(hexdigest=mock.Mock(return_value="deadc0de"))) bar_loc = "path/to/bar.txt" diff --git a/openfe/tests/utils/conftest.py b/openfe/tests/utils/conftest.py index 3799f5837..90be909d3 100644 --- a/openfe/tests/utils/conftest.py +++ b/openfe/tests/utils/conftest.py @@ -1,7 +1,8 @@ # This code is part of OpenFE and is licensed under the MIT license. # For details, see https://github.com/OpenFreeEnergy/openfe +from collections.abc import Iterable from importlib import resources -from typing import Iterable, NamedTuple +from typing import NamedTuple import pytest from rdkit import Chem diff --git a/openfe/tests/utils/test_atommapping_network_plotting.py b/openfe/tests/utils/test_atommapping_network_plotting.py index bf421465a..1ce12d91d 100644 --- a/openfe/tests/utils/test_atommapping_network_plotting.py +++ b/openfe/tests/utils/test_atommapping_network_plotting.py @@ -101,7 +101,7 @@ def test_select_mock_drawing(self, edge_str, left_right, molA_to_molB, network_d node_dict = {node.smiles: node for node in network_drawing.graph.nodes} edge_tuple = tuple(node_dict[node] for node in edge_str) edge = network_drawing.edges[edge_tuple] - left, right = [network_drawing.nodes[node_dict[node]] for node in left_right] + left, right = (network_drawing.nodes[node_dict[node]] for node in left_right) # ensure that we have them labelled correctly assert left.xy[0] < right.xy[0] func = edge._draw_mapped_molecule # save for bound_args diff --git a/openfe/tests/utils/test_network_plotting.py b/openfe/tests/utils/test_network_plotting.py index d65c78179..18bef583b 100644 --- a/openfe/tests/utils/test_network_plotting.py +++ b/openfe/tests/utils/test_network_plotting.py @@ -158,7 +158,7 @@ def test_on_drag(self): event = mock_event("drag", 0.7, 0.7, self.fig) # this test some integration, so we need more than a mock drawing_graph = GraphDrawing( - nx.MultiDiGraph(([("A", "B"), ("B", "C"), ("B", "D")])), + nx.MultiDiGraph([("A", "B"), ("B", "C"), ("B", "D")]), positions={"A": (0.0, 0.0), "B": (0.5, 0.0), "C": (0.5, 0.5), "D": (0.0, 0.5)}, ) # set up things that should happen on mousedown diff --git a/openfe/utils/atommapping_network_plotting.py b/openfe/utils/atommapping_network_plotting.py index 7f6b1cd6b..cd26299b4 100644 --- a/openfe/utils/atommapping_network_plotting.py +++ b/openfe/utils/atommapping_network_plotting.py @@ -27,17 +27,17 @@ class AtomMappingEdge(Edge): to an :class:`.AtomMapping`. """ - def __init__(self, node_artist1: Node, node_artist2: Node, data: Dict): + def __init__(self, node_artist1: Node, node_artist2: Node, data: dict): super().__init__(node_artist1, node_artist2, data) self.left_image = None self.right_image = None def _draw_mapped_molecule( self, - extent: Tuple[float, float, float, float], + extent: tuple[float, float, float, float], molA: SmallMoleculeComponent, molB: SmallMoleculeComponent, - molA_to_molB: Dict[int, int], + molA_to_molB: dict[int, int], ): # create the image in a format matplotlib can handle d2d = Chem.Draw.rdMolDraw2D.MolDraw2DCairo(300, 300, 300, 300) diff --git a/openfe/utils/network_plotting.py b/openfe/utils/network_plotting.py index 6a6c9da62..11a4f38f1 100644 --- a/openfe/utils/network_plotting.py +++ b/openfe/utils/network_plotting.py @@ -44,7 +44,7 @@ def __init__(self, node, x: float, y: float, dx=0.1, dy=0.1): self.dy = dx self.artist = self._make_artist(x, y, dx, dy) self.picked = False - self.press: Optional[ClickLocation] = None + self.press: ClickLocation | None = None def _make_artist(self, x, y, dx, dy): return Rectangle((x, y), dx, dy, color="blue") @@ -245,9 +245,9 @@ class EventHandler: def __init__(self, graph: GraphDrawing): self.graph = graph - self.active: Optional[Union[Node, Edge]] = None - self.selected: Optional[Union[Node, Edge]] = None - self.click_location: Optional[tuple[Optional[float], Optional[float]]] = None + self.active: Node | Edge | None = None + self.selected: Node | Edge | None = None + self.click_location: tuple[float | None, float | None] | None = None self.connections: list[int] = [] def connect(self, canvas: MPL_FigureCanvasBase): diff --git a/openfe/utils/system_probe.py b/openfe/utils/system_probe.py index e752be258..dee600e59 100644 --- a/openfe/utils/system_probe.py +++ b/openfe/utils/system_probe.py @@ -4,7 +4,8 @@ import socket import subprocess import sys -from typing import Iterable, Optional +from collections.abc import Iterable +from typing import Optional import psutil from psutil._common import bytes2human diff --git a/openfe/utils/visualization_3D.py b/openfe/utils/visualization_3D.py index 9905c15a4..0b86003bf 100644 --- a/openfe/utils/visualization_3D.py +++ b/openfe/utils/visualization_3D.py @@ -1,4 +1,5 @@ -from typing import Dict, Iterable, Optional, Tuple, Union +from collections.abc import Iterable +from typing import Dict, Optional, Tuple, Union import numpy as np from matplotlib import pyplot as plt @@ -43,7 +44,7 @@ def _get_max_dist_in_x(atom_mapping: AtomMapping) -> float: return estm if (estm > 5) else 5 -def _translate(mol, shift: Union[Tuple[float, float, float], NDArray[np.float64]]): +def _translate(mol, shift: Union[tuple[float, float, float], NDArray[np.float64]]): """ shifts the molecule by the shift vector @@ -68,7 +69,7 @@ def _translate(mol, shift: Union[Tuple[float, float, float], NDArray[np.float64] return mol -def _add_spheres(view: py3Dmol.view, mol1: Chem.Mol, mol2: Chem.Mol, mapping: Dict[int, int]): +def _add_spheres(view: py3Dmol.view, mol1: Chem.Mol, mol2: Chem.Mol, mapping: dict[int, int]): """ will add spheres according to mapping to the view. (inplace!) @@ -111,7 +112,7 @@ def _add_spheres(view: py3Dmol.view, mol1: Chem.Mol, mol2: Chem.Mol, mapping: Di def view_components_3d( mols: Iterable[ExplicitMoleculeComponent], style: Optional[str] = "stick", - shift: Optional[Tuple[float, float, float]] = None, + shift: Optional[tuple[float, float, float]] = None, view: py3Dmol.view = None, ) -> py3Dmol.view: """visualize multiple component coordinates in one interactive view. @@ -160,7 +161,7 @@ def view_mapping_3d( spheres: Optional[bool] = True, show_atomIDs: Optional[bool] = False, style: Optional[str] = "stick", - shift: Optional[Union[Tuple[float, float, float], NDArray[np.float64]]] = None, + shift: Optional[Union[tuple[float, float, float], NDArray[np.float64]]] = None, ) -> py3Dmol.view: """ Render relative transformation edge in 3D using py3Dmol. diff --git a/openfecli/commands/gather.py b/openfecli/commands/gather.py index d9c71b62c..a8a33dd0a 100644 --- a/openfecli/commands/gather.py +++ b/openfecli/commands/gather.py @@ -47,7 +47,7 @@ def format_estimate_uncertainty( def is_results_json(f): # sanity check on files before we try and deserialize - return "estimate" in open(f, "r").read(20) + return "estimate" in open(f).read(20) def load_results(f): @@ -56,7 +56,7 @@ def load_results(f): from gufe.tokenization import JSON_HANDLER - return json.load(open(f, "r"), cls=JSON_HANDLER.decoder) + return json.load(open(f), cls=JSON_HANDLER.decoder) def get_names(result) -> tuple[str, str]: diff --git a/openfecli/commands/plan_rbfe_network.py b/openfecli/commands/plan_rbfe_network.py index 7819d0416..d712053f4 100644 --- a/openfecli/commands/plan_rbfe_network.py +++ b/openfecli/commands/plan_rbfe_network.py @@ -81,7 +81,7 @@ def plan_rbfe_network_main( ) @print_duration def plan_rbfe_network( - molecules: List[str], + molecules: list[str], protein: str, cofactors: tuple[str], yaml_settings: str, diff --git a/openfecli/commands/plan_rhfe_network.py b/openfecli/commands/plan_rhfe_network.py index 39d05136e..539114338 100644 --- a/openfecli/commands/plan_rhfe_network.py +++ b/openfecli/commands/plan_rhfe_network.py @@ -68,7 +68,7 @@ def plan_rhfe_network_main( default="alchemicalNetwork", ) @print_duration -def plan_rhfe_network(molecules: List[str], yaml_settings: str, output_dir: str): +def plan_rhfe_network(molecules: list[str], yaml_settings: str, output_dir: str): """ Plan a relative hydration free energy network, saved as JSON files for the quickrun command. diff --git a/openfecli/parameters/plan_network_options.py b/openfecli/parameters/plan_network_options.py index 96bff0049..e17371e6e 100644 --- a/openfecli/parameters/plan_network_options.py +++ b/openfecli/parameters/plan_network_options.py @@ -113,7 +113,7 @@ def load_yaml_planner_options(path: Optional[str], context) -> PlanNetworkOption ) if path is not None: - with open(path, "r") as f: + with open(path) as f: raw = f.read() # convert raw yaml to normalised pydantic model diff --git a/openfecli/tests/commands/test_quickrun.py b/openfecli/tests/commands/test_quickrun.py index e2ea1b4d6..71ffdd158 100644 --- a/openfecli/tests/commands/test_quickrun.py +++ b/openfecli/tests/commands/test_quickrun.py @@ -31,7 +31,7 @@ def test_quickrun(extra_args, json_file): if outfile := extra_args.get("-o"): assert pathlib.Path(outfile).exists() - with open(outfile, mode="r") as outf: + with open(outfile) as outf: dct = json.load(outf, cls=JSON_HANDLER.decoder) assert set(dct) == {"estimate", "uncertainty", "protocol_result", "unit_results"}