Skip to content

Commit afe87a3

Browse files
committed
Autoformat and lint with ruff.
1 parent 09ff8fd commit afe87a3

107 files changed

Lines changed: 328 additions & 387 deletions

File tree

Some content is hidden

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

pyproject.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,9 @@ file = "src/BioSimSpace/_version.py"
4040
[tool.pytest.ini_options]
4141
# Ensure that test/Sandpit/Exscientia could have the same name as the tests in test
4242
addopts = "--import-mode=importlib"
43+
44+
[tool.ruff.lint]
45+
ignore = ["E402"]
46+
47+
[tool.ruff.lint.per-file-ignores]
48+
"tests/**" = ["F841"]

src/BioSimSpace/Align/_align.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
if _have_imported(_rdkit):
4848
from rdkit import Chem as _Chem
4949
from rdkit import RDLogger as _RDLogger
50-
from rdkit.Chem import AllChem, Draw
5150
from rdkit.Chem import rdFMCS as _rdFMCS
5251

5352
# Disable RDKit warnings.
@@ -265,17 +264,17 @@ def generateNetwork(
265264
)
266265

267266
# Make sure that the ligands are in the names list.
268-
if not records[0] in names:
267+
if records[0] not in names:
269268
raise ValueError(f"Ligand '{records[0]}' not in 'names' list!")
270-
if not records[1] in names:
269+
if records[1] not in names:
271270
raise ValueError(f"Ligand '{records[1]}' not in 'names' list!")
272271

273272
else:
274273
raise IOError(f"The links file doesn't exist: {links_file}")
275274

276275
# Validate the number of edges parameter.
277276
if n_edges_forced is not None:
278-
if not type(n_edges_forced) is int:
277+
if type(n_edges_forced) is not int:
279278
raise TypeError("'n_edges_forced' must be of type 'int'")
280279

281280
n_edges_fully_connected = int((len(molecules) ** 2 - len(molecules)) / 2) + 1
@@ -470,7 +469,7 @@ def generateNetwork(
470469

471470
# Update the list while checking that the inverse edge is not already in
472471
# the network.
473-
if not (mol1, mol0) in edges:
472+
if (mol1, mol0) not in edges:
474473
edges_excluded.append((mol0, mol1, score))
475474

476475
# If the user has specified a forced number of edges, adjust the network
@@ -931,7 +930,7 @@ def _matchAtoms(
931930
# Strip underscores and whitespace, then convert to upper case.
932931
_scoring_function = scoring_function.replace("_", "").upper()
933932
_scoring_function = _scoring_function.replace(" ", "").upper()
934-
if not _scoring_function in scoring_functions:
933+
if _scoring_function not in scoring_functions:
935934
raise ValueError(
936935
"Unsupported scoring function '%s'. Options are: %s"
937936
% (scoring_function, scoring_functions)
@@ -943,7 +942,7 @@ def _matchAtoms(
943942
"https://pdbj.org/kcombu"
944943
)
945944

946-
if not type(matches) is int:
945+
if type(matches) is not int:
947946
raise TypeError("'matches' must be of type 'int'")
948947
else:
949948
if matches < 0:
@@ -963,7 +962,7 @@ def _matchAtoms(
963962
if not isinstance(complete_rings_only, bool):
964963
raise TypeError("'complete_rings_only' must be of type 'bool'")
965964

966-
if not type(max_scoring_matches) is int:
965+
if type(max_scoring_matches) is not int:
967966
raise TypeError("'max_scoring_matches' must be of type 'int'")
968967

969968
if max_scoring_matches <= 0:
@@ -1437,7 +1436,6 @@ def _roiMatch(
14371436
# In the case when we are not at the last residue of interest,
14381437
# we need to map the atoms to the next ROI.
14391438
if res_idx != roi[-1]:
1440-
14411439
# If the next ROI residue index in the ROI list is next to
14421440
# the current ROI index, after_roi atom index list will be empty
14431441
# i.e. if we're currently at residue 10 and the next ROI is 11,
@@ -2266,7 +2264,7 @@ def viewMapping(
22662264

22672265
if isinstance(pixels, float):
22682266
pixels = int(pixels)
2269-
if not type(pixels) is int:
2267+
if type(pixels) is not int:
22702268
raise TypeError("'pixels' must be of type 'int'")
22712269
if pixels <= 0:
22722270
raise ValueError("pixels' must be > 0!")
@@ -2716,7 +2714,7 @@ def _score_rdkit_mappings(
27162714
}
27172715

27182716
# This is a new mapping:
2719-
if not mapping in mappings:
2717+
if mapping not in mappings:
27202718
# Check that the mapping contains the pre-match.
27212719
is_valid = True
27222720
for idx0, idx1 in prematch.items():

src/BioSimSpace/Align/_merge.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ def merge(
337337

338338
# lambda = 0
339339
for prop in props0:
340-
if not prop in ignored_props:
340+
if prop not in ignored_props:
341341
# This is a perturbable property.
342342
if prop in shared_props:
343343
name = f"{prop}0"
@@ -357,7 +357,7 @@ def merge(
357357

358358
# lambda = 1
359359
for prop in props1:
360-
if not prop in ignored_props:
360+
if prop not in ignored_props:
361361
# This is a perturbable property.
362362
if prop in shared_props:
363363
name = f"{prop}1"

src/BioSimSpace/Convert/_convert.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ def to(obj, format="biosimspace", property_map={}, **kwargs):
179179
# Convert to lower case and strip whitespace.
180180
format = format.lower().replace(" ", "")
181181

182-
if not format in supportedFormats():
182+
if format not in supportedFormats():
183183
raise ValueError(
184184
f"Unsupported format '{format}', options are: {', '.join(supportedFormats())}."
185185
)

src/BioSimSpace/FreeEnergy/_atm.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@
2828
from .. import _is_notebook
2929
from ..Notebook import View as _View
3030

31-
if _is_notebook:
32-
from IPython.display import FileLink as _FileLink
33-
3431

3532
class ATMSetup:
3633
"""
@@ -601,7 +598,6 @@ def _makeSystemFromThree(protein, ligand_bound, ligand_free, displacement):
601598
from ..Types import Vector as _Vector
602599

603600
def _findTranslationVector(system, displacement, protein, ligand):
604-
605601
import warnings as _warnings
606602

607603
from sire.legacy.Maths import Vector
@@ -1418,8 +1414,6 @@ def getData(self, name="data", file_link=False, work_dir=None):
14181414
import pathlib as _pathlib
14191415
import zipfile as _zipfile
14201416

1421-
from IPython.display import FileLink as _FileLink
1422-
14231417
if self._work_dir is None:
14241418
raise ValueError("'work_dir' must be set!")
14251419
else:
@@ -1461,6 +1455,8 @@ def getData(self, name="data", file_link=False, work_dir=None):
14611455
# Return a link to the archive.
14621456
if _is_notebook:
14631457
if file_link:
1458+
from IPython.display import FileLink as _FileLink
1459+
14641460
# Create a FileLink to the archive.
14651461
f_link = _FileLink(zipname)
14661462

@@ -1722,7 +1718,6 @@ def __init__(self, handle, property_map={}, is_lambda1=False):
17221718
super().__init__(handle, property_map, is_lambda1)
17231719

17241720
def _create_view(self, system=None, view=None, gui=True, **kwargs):
1725-
17261721
from sire.legacy import IO as _SireIO
17271722

17281723
from .. import _isVerbose

src/BioSimSpace/FreeEnergy/_relative.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ def analyse(work_dir, estimator="MBAR", method="alchemlyb", **kwargs):
454454
if data and engine == "AMBER":
455455
if method != "ALCHEMLYB":
456456
raise _AnalysisError(
457-
f"AMBER can only use the 'alchemlyb' analysis method."
457+
"AMBER can only use the 'alchemlyb' analysis method."
458458
)
459459
if data and engine == "SOMD" and estimator == "TI" and method == "native":
460460
raise _AnalysisError(
@@ -463,7 +463,7 @@ def analyse(work_dir, estimator="MBAR", method="alchemlyb", **kwargs):
463463
if data and engine == "SOMD2":
464464
if method != "ALCHEMLYB":
465465
raise _AnalysisError(
466-
f"SOMD2 can only use the 'alchemlyb' analysis method."
466+
"SOMD2 can only use the 'alchemlyb' analysis method."
467467
)
468468
if data and engine == "GROMACS" and method == "native":
469469
_warnings.warn(
@@ -694,15 +694,15 @@ def _get_data(files, temperatures, engine, estimator):
694694
if not isinstance(engine, str):
695695
raise TypeError("'engine' must be of type 'str'.")
696696
engine = engine.replace(" ", "").upper()
697-
if not engine in Relative._engines_analysis:
697+
if engine not in Relative._engines_analysis:
698698
raise ValueError(
699699
f"Unsupported engine '{engine}'. Options are: {', '.join(Relative._engines_analysis)}"
700700
)
701701

702702
if not isinstance(estimator, str):
703703
raise TypeError("'estimator' must be of type 'str'.")
704704
estimator = estimator.replace(" ", "").upper()
705-
if not estimator in ["MBAR", "TI"]:
705+
if estimator not in ["MBAR", "TI"]:
706706
raise ValueError("'estimator' must be either 'MBAR' or 'TI'.")
707707

708708
if estimator == "MBAR":
@@ -1154,7 +1154,7 @@ def _preprocess_data(data, estimator, **kwargs):
11541154

11551155
if not isinstance(estimator, str):
11561156
raise TypeError("'estimator' must be of type 'str'.")
1157-
if not estimator.replace(" ", "").upper() in ["MBAR", "TI"]:
1157+
if estimator.replace(" ", "").upper() not in ["MBAR", "TI"]:
11581158
raise ValueError("'estimator' must be either 'MBAR' or 'TI'.")
11591159

11601160
# Assign defaults in case not passed via kwargs.
@@ -1307,15 +1307,15 @@ def _analyse_internal(files, temperatures, lambdas, engine, estimator, **kwargs)
13071307

13081308
if not isinstance(engine, str):
13091309
raise TypeError("'engine' must be of type 'str'.")
1310-
if not engine.replace(" ", "").upper() in Relative._engines_analysis:
1310+
if engine.replace(" ", "").upper() not in Relative._engines_analysis:
13111311
raise ValueError(
13121312
f"Unsupported engine '{engine}'. Options are: {', '.join(Relative._engines_analysis)}"
13131313
)
13141314

13151315
if not isinstance(estimator, str):
13161316
raise TypeError("'estimator' must be of type 'str'.")
13171317
estimator = estimator.replace(" ", "").upper()
1318-
if not estimator in ["MBAR", "TI"]:
1318+
if estimator not in ["MBAR", "TI"]:
13191319
raise ValueError("'estimator' must be either 'MBAR' or 'TI'.")
13201320

13211321
if estimator == "MBAR":
@@ -1544,7 +1544,7 @@ def _analyse_gromacs(work_dir=None, estimator="MBAR", method="alchemlyb", **kwar
15441544

15451545
if not isinstance(estimator, str):
15461546
raise TypeError("'estimator' must be of type 'str'.")
1547-
if not estimator.replace(" ", "").upper() in ["MBAR", "TI"]:
1547+
if estimator.replace(" ", "").upper() not in ["MBAR", "TI"]:
15481548
raise ValueError("'estimator' must be either 'MBAR' or 'TI'.")
15491549

15501550
if not isinstance(method, str):
@@ -1735,7 +1735,7 @@ def _analyse_somd(work_dir=None, estimator="MBAR", method="alchemlyb", **kwargs)
17351735
if not isinstance(method, str):
17361736
raise TypeError("'method' must be of type 'str'.")
17371737
method = method.replace(" ", "").upper()
1738-
if not method in ["ALCHEMLYB", "NATIVE"]:
1738+
if method not in ["ALCHEMLYB", "NATIVE"]:
17391739
raise ValueError("'method' must be either 'alchemlyb' or 'native'.")
17401740

17411741
if method == "ALCHEMLYB":

src/BioSimSpace/Gateway/_node.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,6 @@
3434

3535
from .. import _is_notebook
3636

37-
# Enable Jupyter widgets.
38-
if _is_notebook:
39-
from IPython.display import FileLink as _FileLink
40-
41-
import ipywidgets as _widgets
42-
import zipfile as _zipfile
43-
4437
from ._requirements import Area as _Area
4538
from ._requirements import Charge as _Charge
4639
from ._requirements import Energy as _Energy
@@ -133,7 +126,6 @@ def __call__(self, parser, namespace, values, option_string=None):
133126
exe = _sys.executable
134127

135128
# Store the absolute path of the node.
136-
import __main__
137129

138130
node = _os.path.abspath(__main__.__file__)
139131

@@ -1140,7 +1132,7 @@ def addAuthor(self, name=None, email=None, affiliation=None):
11401132
self._authors = [{"name": name, "email": email, "affiliation": affiliation}]
11411133
else:
11421134
author = {"name": name, "email": email, "affiliation": affiliation}
1143-
if not author in self._authors:
1135+
if author not in self._authors:
11441136
self._authors.append(author)
11451137

11461138
def getAuthors(self):
@@ -1321,7 +1313,7 @@ def _validateInput(self):
13211313
if value is True:
13221314
self._strict_file_naming = True
13231315
else:
1324-
if not key in ["config", "export_cwl"]:
1316+
if key not in ["config", "export_cwl"]:
13251317
self._inputs[key].setValue(value, name=key)
13261318

13271319
def validate(self, file_prefix="output"):
@@ -1346,8 +1338,6 @@ def validate(self, file_prefix="output"):
13461338
import sys as _sys
13471339
import zipfile as _zipfile
13481340

1349-
from IPython.display import FileLink as _FileLink
1350-
13511341
from ._requirements import File as _File
13521342
from ._requirements import FileSet as _FileSet
13531343

@@ -1380,6 +1370,8 @@ def validate(self, file_prefix="output"):
13801370

13811371
# Create a compressed archive containing all file output for the node.
13821372
if self._is_notebook:
1373+
from IPython.display import FileLink as _FileLink
1374+
13831375
# There are files.
13841376
if len(file_outputs) > 0:
13851377
# Create the archive name.

src/BioSimSpace/Gateway/_resources.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def setNodes(self, nodes):
9999
The number of nodes.
100100
"""
101101

102-
if not type(nodes) is int:
102+
if type(nodes) is not int:
103103
raise TypeError("'nodes' must be of type 'int'.")
104104

105105
if nodes < 0:
@@ -130,7 +130,7 @@ def setCPUs(self, cpus):
130130
The number of cpus.
131131
"""
132132

133-
if not type(cpus) is int:
133+
if type(cpus) is not int:
134134
raise TypeError("'cpus' must be of type 'int'.")
135135

136136
if cpus < 0:
@@ -161,7 +161,7 @@ def setGPUs(self, gpus):
161161
The number of GPUs.
162162
"""
163163

164-
if not type(gpus) is int:
164+
if type(gpus) is not int:
165165
raise TypeError("'gpus' must be of type 'int'.")
166166

167167
if gpus < 0:

src/BioSimSpace/MD/_md.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
__all__ = ["run"]
2828

2929

30-
from .. import _amber_home, _gmx_exe
30+
from .. import _gmx_exe
3131

3232
# A dictionary mapping MD engines to their executable names and GPU support.
3333
# engine, exe, gpu
@@ -120,7 +120,6 @@ def _find_md_engines(system, protocol, engine="AUTO", gpu_support=False):
120120
from sire.legacy import Base as _SireBase
121121

122122
from .. import Protocol as _Protocol
123-
from .. import _gmx_exe
124123
from .._Exceptions import MissingSoftwareError as _MissingSoftwareError
125124

126125
# The input has already been validated in the run method, so no need
@@ -129,7 +128,7 @@ def _find_md_engines(system, protocol, engine="AUTO", gpu_support=False):
129128
fileformat = system.fileFormat()
130129

131130
# Make sure that this format is supported.
132-
if not fileformat in _file_extensions:
131+
if fileformat not in _file_extensions:
133132
raise ValueError(
134133
"Cannot find an MD engine that supports format: %s" % fileformat
135134
)
@@ -348,7 +347,7 @@ def run(
348347
raise TypeError("'work_dir' must be of type 'str'")
349348

350349
if seed is not None:
351-
if not type(seed) is int:
350+
if type(seed) is not int:
352351
raise TypeError("'seed' must be of type 'int'")
353352

354353
if not isinstance(property_map, dict):

src/BioSimSpace/Metadynamics/CollectiveVariable/_rmsd.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ def __init__(
335335
# Also strip any TER records.
336336
self._reference_pdb = []
337337
for line, idx in zip(lines[1:-2], abs_atom_indices):
338-
if not "TER" in line:
338+
if "TER" not in line:
339339
self._reference_pdb.append(line[:6] + str(idx).rjust(5) + line[11:])
340340
self._reference_pdb.append(lines[-1])
341341

@@ -678,7 +678,7 @@ def _compute_initial_rmsd(
678678
i.value(): i.value()
679679
for i in align_indices[ref._sire_object.number()]
680680
}
681-
except Exception as e:
681+
except Exception:
682682
pass
683683

684684
if len(align_mapping) > 0:
@@ -699,7 +699,7 @@ def _compute_initial_rmsd(
699699

700700
try:
701701
rmsd_mapping = {i: i for i in rmsd_indices[ref._sire_object.number()]}
702-
except Exception as e:
702+
except Exception:
703703
pass
704704

705705
if len(rmsd_mapping) > 0:

0 commit comments

Comments
 (0)