Skip to content

Commit 90ad7c0

Browse files
committed
chore: migrate from black to ruff format
1 parent bf5ba50 commit 90ad7c0

6 files changed

Lines changed: 59 additions & 52 deletions

File tree

.github/workflows/test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ jobs:
8383
- name: Lint with ruff
8484
run: ruff check .
8585

86-
- name: Check formatting (Black)
87-
run: black --check .
86+
- name: Check formatting (Ruff)
87+
run: ruff format --check .
8888

8989
- name: Static type check (Mypy)
9090
run: mypy . --explicit-package-bases

.pre-commit-config.yaml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,7 @@ repos:
1414
hooks:
1515
- id: ruff
1616
args: [--fix, --exit-non-zero-on-fix]
17-
18-
- repo: https://github.com/psf/black
19-
rev: 24.10.0
20-
hooks:
21-
- id: black
17+
- id: ruff-format
2218

2319
- repo: https://github.com/pre-commit/mirrors-mypy
2420
rev: v1.15.0

examples/quickstart_ensemble.ipynb

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"import sys\n",
2424
"\n",
2525
"if \"google.colab\" in sys.modules:\n",
26-
" !pip install -q diff-ensemble matplotlib\n"
26+
" !pip install -q diff-ensemble matplotlib"
2727
]
2828
},
2929
{
@@ -64,7 +64,7 @@
6464
"\n",
6565
"# Initialize model parameters\n",
6666
"params = model.init(init_rng, dummy_x, init_rng)\n",
67-
"print(f\"Model initialized! Ready to generate ensembles of {ensemble_size} structures.\")\n"
67+
"print(f\"Model initialized! Ready to generate ensembles of {ensemble_size} structures.\")"
6868
]
6969
},
7070
{
@@ -91,7 +91,7 @@
9191
"coords = model.generate_coordinates(torsions)\n",
9292
"\n",
9393
"print(f\"Generated Coordinates Shape: {coords.shape}\")\n",
94-
"print(\"(ensemble_size, seq_len * 3 atoms, 3 dimensions)\")\n"
94+
"print(\"(ensemble_size, seq_len * 3 atoms, 3 dimensions)\")"
9595
]
9696
},
9797
{
@@ -117,20 +117,20 @@
117117
"coords_np = np.array(coords)\n",
118118
"\n",
119119
"fig = plt.figure(figsize=(10, 8))\n",
120-
"ax = fig.add_subplot(111, projection='3d')\n",
120+
"ax = fig.add_subplot(111, projection=\"3d\")\n",
121121
"\n",
122122
"# Plot the backbone trace of the first 5 structures\n",
123123
"for i in range(5):\n",
124124
" # Extract only the C-alpha atoms (every 3rd atom starting at index 1: N, CA, C)\n",
125125
" ca_coords = coords_np[i, 1::3, :]\n",
126-
" ax.plot(ca_coords[:, 0], ca_coords[:, 1], ca_coords[:, 2], marker='o', label=f'Conf {i+1}')\n",
126+
" ax.plot(ca_coords[:, 0], ca_coords[:, 1], ca_coords[:, 2], marker=\"o\", label=f\"Conf {i + 1}\")\n",
127127
"\n",
128128
"ax.set_title(\"3D Overlay of Sampled IDP Conformations\")\n",
129129
"ax.set_xlabel(\"X (Å)\")\n",
130130
"ax.set_ylabel(\"Y (Å)\")\n",
131131
"ax.set_zlabel(\"Z (Å)\")\n",
132132
"ax.legend()\n",
133-
"plt.show()\n"
133+
"plt.show()"
134134
]
135135
},
136136
{
@@ -154,23 +154,30 @@
154154
" # Center of mass (assuming equal mass for simplicity)\n",
155155
" com = np.mean(coords, axis=0)\n",
156156
" # Mean squared distance from COM\n",
157-
" sq_dist = np.sum((coords - com)**2, axis=1)\n",
157+
" sq_dist = np.sum((coords - com) ** 2, axis=1)\n",
158158
" return np.sqrt(np.mean(sq_dist))\n",
159159
"\n",
160+
"\n",
160161
"# Calculate Rg for all 100 structures (using C-alpha atoms only)\n",
161162
"ca_ensemble = coords_np[:, 1::3, :]\n",
162163
"rg_values = [calculate_rg(ca_ensemble[i]) for i in range(ensemble_size)]\n",
163164
"\n",
164165
"# Plot the distribution\n",
165166
"plt.figure(figsize=(8, 5))\n",
166-
"plt.hist(rg_values, bins=15, color='skyblue', edgecolor='black', alpha=0.7)\n",
167-
"plt.axvline(np.mean(rg_values), color='red', linestyle='dashed', linewidth=2, label=f'Mean Rg: {np.mean(rg_values):.2f} Å')\n",
167+
"plt.hist(rg_values, bins=15, color=\"skyblue\", edgecolor=\"black\", alpha=0.7)\n",
168+
"plt.axvline(\n",
169+
" np.mean(rg_values),\n",
170+
" color=\"red\",\n",
171+
" linestyle=\"dashed\",\n",
172+
" linewidth=2,\n",
173+
" label=f\"Mean Rg: {np.mean(rg_values):.2f} Å\",\n",
174+
")\n",
168175
"plt.title(\"Distribution of Radius of Gyration ($R_g$) across the Ensemble\")\n",
169176
"plt.xlabel(\"Radius of Gyration (Å)\")\n",
170177
"plt.ylabel(\"Frequency\")\n",
171178
"plt.legend()\n",
172-
"plt.grid(axis='y', alpha=0.3)\n",
173-
"plt.show()\n"
179+
"plt.grid(axis=\"y\", alpha=0.3)\n",
180+
"plt.show()"
174181
]
175182
},
176183
{
@@ -197,23 +204,23 @@
197204
"\n",
198205
"# Create a Ramachandran plot\n",
199206
"plt.figure(figsize=(7, 7))\n",
200-
"plt.scatter(phi_angles, psi_angles, alpha=0.3, s=10, color='indigo')\n",
207+
"plt.scatter(phi_angles, psi_angles, alpha=0.3, s=10, color=\"indigo\")\n",
201208
"\n",
202209
"# Draw typical Ramachandran region boundaries\n",
203-
"plt.axhline(0, color='black', lw=1)\n",
204-
"plt.axvline(0, color='black', lw=1)\n",
210+
"plt.axhline(0, color=\"black\", lw=1)\n",
211+
"plt.axvline(0, color=\"black\", lw=1)\n",
205212
"plt.xlim(-180, 180)\n",
206213
"plt.ylim(-180, 180)\n",
207214
"\n",
208215
"# Formatting\n",
209-
"plt.xlabel(r'$\\phi$ (degrees)', fontsize=14)\n",
210-
"plt.ylabel(r'$\\psi$ (degrees)', fontsize=14)\n",
211-
"plt.title('Ramachandran Plot of Generated Ensemble', fontsize=16)\n",
212-
"plt.grid(True, linestyle='--', alpha=0.5)\n",
216+
"plt.xlabel(r\"$\\phi$ (degrees)\", fontsize=14)\n",
217+
"plt.ylabel(r\"$\\psi$ (degrees)\", fontsize=14)\n",
218+
"plt.title(\"Ramachandran Plot of Generated Ensemble\", fontsize=16)\n",
219+
"plt.grid(True, linestyle=\"--\", alpha=0.5)\n",
213220
"plt.xticks(np.arange(-180, 181, 60))\n",
214221
"plt.yticks(np.arange(-180, 181, 60))\n",
215222
"\n",
216-
"plt.show()\n"
223+
"plt.show()"
217224
]
218225
}
219226
],

examples/quickstart_ensemble.nbconvert.ipynb

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"import sys\n",
3131
"\n",
3232
"if \"google.colab\" in sys.modules:\n",
33-
" !pip install -q diff-ensemble matplotlib\n"
33+
" !pip install -q diff-ensemble matplotlib"
3434
]
3535
},
3636
{
@@ -86,7 +86,7 @@
8686
"\n",
8787
"# Initialize model parameters\n",
8888
"params = model.init(init_rng, dummy_x, init_rng)\n",
89-
"print(f\"Model initialized! Ready to generate ensembles of {ensemble_size} structures.\")\n"
89+
"print(f\"Model initialized! Ready to generate ensembles of {ensemble_size} structures.\")"
9090
]
9191
},
9292
{
@@ -129,7 +129,7 @@
129129
"coords = model.generate_coordinates(torsions)\n",
130130
"\n",
131131
"print(f\"Generated Coordinates Shape: {coords.shape}\")\n",
132-
"print(\"(ensemble_size, seq_len * 3 atoms, 3 dimensions)\")\n"
132+
"print(\"(ensemble_size, seq_len * 3 atoms, 3 dimensions)\")"
133133
]
134134
},
135135
{
@@ -173,20 +173,20 @@
173173
"coords_np = np.array(coords)\n",
174174
"\n",
175175
"fig = plt.figure(figsize=(10, 8))\n",
176-
"ax = fig.add_subplot(111, projection='3d')\n",
176+
"ax = fig.add_subplot(111, projection=\"3d\")\n",
177177
"\n",
178178
"# Plot the backbone trace of the first 5 structures\n",
179179
"for i in range(5):\n",
180180
" # Extract only the C-alpha atoms (every 3rd atom starting at index 1: N, CA, C)\n",
181181
" ca_coords = coords_np[i, 1::3, :]\n",
182-
" ax.plot(ca_coords[:, 0], ca_coords[:, 1], ca_coords[:, 2], marker='o', label=f'Conf {i+1}')\n",
182+
" ax.plot(ca_coords[:, 0], ca_coords[:, 1], ca_coords[:, 2], marker=\"o\", label=f\"Conf {i + 1}\")\n",
183183
"\n",
184184
"ax.set_title(\"3D Overlay of Sampled IDP Conformations\")\n",
185185
"ax.set_xlabel(\"X (Å)\")\n",
186186
"ax.set_ylabel(\"Y (Å)\")\n",
187187
"ax.set_zlabel(\"Z (Å)\")\n",
188188
"ax.legend()\n",
189-
"plt.show()\n"
189+
"plt.show()"
190190
]
191191
},
192192
{
@@ -228,23 +228,30 @@
228228
" # Center of mass (assuming equal mass for simplicity)\n",
229229
" com = np.mean(coords, axis=0)\n",
230230
" # Mean squared distance from COM\n",
231-
" sq_dist = np.sum((coords - com)**2, axis=1)\n",
231+
" sq_dist = np.sum((coords - com) ** 2, axis=1)\n",
232232
" return np.sqrt(np.mean(sq_dist))\n",
233233
"\n",
234+
"\n",
234235
"# Calculate Rg for all 100 structures (using C-alpha atoms only)\n",
235236
"ca_ensemble = coords_np[:, 1::3, :]\n",
236237
"rg_values = [calculate_rg(ca_ensemble[i]) for i in range(ensemble_size)]\n",
237238
"\n",
238239
"# Plot the distribution\n",
239240
"plt.figure(figsize=(8, 5))\n",
240-
"plt.hist(rg_values, bins=15, color='skyblue', edgecolor='black', alpha=0.7)\n",
241-
"plt.axvline(np.mean(rg_values), color='red', linestyle='dashed', linewidth=2, label=f'Mean Rg: {np.mean(rg_values):.2f} Å')\n",
241+
"plt.hist(rg_values, bins=15, color=\"skyblue\", edgecolor=\"black\", alpha=0.7)\n",
242+
"plt.axvline(\n",
243+
" np.mean(rg_values),\n",
244+
" color=\"red\",\n",
245+
" linestyle=\"dashed\",\n",
246+
" linewidth=2,\n",
247+
" label=f\"Mean Rg: {np.mean(rg_values):.2f} Å\",\n",
248+
")\n",
242249
"plt.title(\"Distribution of Radius of Gyration ($R_g$) across the Ensemble\")\n",
243250
"plt.xlabel(\"Radius of Gyration (Å)\")\n",
244251
"plt.ylabel(\"Frequency\")\n",
245252
"plt.legend()\n",
246-
"plt.grid(axis='y', alpha=0.3)\n",
247-
"plt.show()\n"
253+
"plt.grid(axis=\"y\", alpha=0.3)\n",
254+
"plt.show()"
248255
]
249256
},
250257
{
@@ -303,23 +310,23 @@
303310
"\n",
304311
"# Create a Ramachandran plot\n",
305312
"plt.figure(figsize=(7, 7))\n",
306-
"plt.scatter(phi_angles, psi_angles, alpha=0.3, s=10, color='indigo')\n",
313+
"plt.scatter(phi_angles, psi_angles, alpha=0.3, s=10, color=\"indigo\")\n",
307314
"\n",
308315
"# Draw typical Ramachandran region boundaries\n",
309-
"plt.axhline(0, color='black', lw=1)\n",
310-
"plt.axvline(0, color='black', lw=1)\n",
316+
"plt.axhline(0, color=\"black\", lw=1)\n",
317+
"plt.axvline(0, color=\"black\", lw=1)\n",
311318
"plt.xlim(-180, 180)\n",
312319
"plt.ylim(-180, 180)\n",
313320
"\n",
314321
"# Formatting\n",
315-
"plt.xlabel(r'$\\phi$ (degrees)', fontsize=14)\n",
316-
"plt.ylabel(r'$\\psi$ (degrees)', fontsize=14)\n",
317-
"plt.title('Ramachandran Plot of Generated Ensemble', fontsize=16)\n",
318-
"plt.grid(True, linestyle='--', alpha=0.5)\n",
322+
"plt.xlabel(r\"$\\phi$ (degrees)\", fontsize=14)\n",
323+
"plt.ylabel(r\"$\\psi$ (degrees)\", fontsize=14)\n",
324+
"plt.title(\"Ramachandran Plot of Generated Ensemble\", fontsize=16)\n",
325+
"plt.grid(True, linestyle=\"--\", alpha=0.5)\n",
319326
"plt.xticks(np.arange(-180, 181, 60))\n",
320327
"plt.yticks(np.arange(-180, 181, 60))\n",
321328
"\n",
322-
"plt.show()\n"
329+
"plt.show()"
323330
]
324331
}
325332
],

pyproject.toml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,6 @@ ignore_missing_imports = true
3232
line-length = 100
3333
target-version = "py310"
3434

35-
[tool.black]
36-
line-length = 100
37-
target-version = ['py310']
3835

3936
[tool.ruff.format]
4037
quote-style = "double"
@@ -113,7 +110,7 @@ dependencies = [
113110
[project.optional-dependencies]
114111
dev = [
115112
"pytest",
116-
"black",
113+
"pytest-cov",
117114
"ruff",
118115
"mypy",
119116
"pre-commit",

tests/test_io.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ def test_save_ensemble_to_pdb_default_res_names(tmp_path):
5858
stack = pdb_file.get_structure()
5959

6060
# Every residue name should be the ALA default
61-
assert all(
62-
name == "ALA" for name in stack.res_name
63-
), f"Expected all 'ALA', got: {set(stack.res_name)}"
61+
assert all(name == "ALA" for name in stack.res_name), (
62+
f"Expected all 'ALA', got: {set(stack.res_name)}"
63+
)
6464

6565

6666
def test_save_ensemble_to_pdb_mismatched_res_names(tmp_path):

0 commit comments

Comments
 (0)