|
23 | 23 | "import sys\n", |
24 | 24 | "\n", |
25 | 25 | "if \"google.colab\" in sys.modules:\n", |
26 | | - " !pip install -q diff-ensemble matplotlib\n" |
| 26 | + " !pip install -q diff-ensemble matplotlib" |
27 | 27 | ] |
28 | 28 | }, |
29 | 29 | { |
|
64 | 64 | "\n", |
65 | 65 | "# Initialize model parameters\n", |
66 | 66 | "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.\")" |
68 | 68 | ] |
69 | 69 | }, |
70 | 70 | { |
|
91 | 91 | "coords = model.generate_coordinates(torsions)\n", |
92 | 92 | "\n", |
93 | 93 | "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)\")" |
95 | 95 | ] |
96 | 96 | }, |
97 | 97 | { |
|
117 | 117 | "coords_np = np.array(coords)\n", |
118 | 118 | "\n", |
119 | 119 | "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", |
121 | 121 | "\n", |
122 | 122 | "# Plot the backbone trace of the first 5 structures\n", |
123 | 123 | "for i in range(5):\n", |
124 | 124 | " # Extract only the C-alpha atoms (every 3rd atom starting at index 1: N, CA, C)\n", |
125 | 125 | " 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", |
127 | 127 | "\n", |
128 | 128 | "ax.set_title(\"3D Overlay of Sampled IDP Conformations\")\n", |
129 | 129 | "ax.set_xlabel(\"X (Å)\")\n", |
130 | 130 | "ax.set_ylabel(\"Y (Å)\")\n", |
131 | 131 | "ax.set_zlabel(\"Z (Å)\")\n", |
132 | 132 | "ax.legend()\n", |
133 | | - "plt.show()\n" |
| 133 | + "plt.show()" |
134 | 134 | ] |
135 | 135 | }, |
136 | 136 | { |
|
154 | 154 | " # Center of mass (assuming equal mass for simplicity)\n", |
155 | 155 | " com = np.mean(coords, axis=0)\n", |
156 | 156 | " # 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", |
158 | 158 | " return np.sqrt(np.mean(sq_dist))\n", |
159 | 159 | "\n", |
| 160 | + "\n", |
160 | 161 | "# Calculate Rg for all 100 structures (using C-alpha atoms only)\n", |
161 | 162 | "ca_ensemble = coords_np[:, 1::3, :]\n", |
162 | 163 | "rg_values = [calculate_rg(ca_ensemble[i]) for i in range(ensemble_size)]\n", |
163 | 164 | "\n", |
164 | 165 | "# Plot the distribution\n", |
165 | 166 | "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", |
168 | 175 | "plt.title(\"Distribution of Radius of Gyration ($R_g$) across the Ensemble\")\n", |
169 | 176 | "plt.xlabel(\"Radius of Gyration (Å)\")\n", |
170 | 177 | "plt.ylabel(\"Frequency\")\n", |
171 | 178 | "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()" |
174 | 181 | ] |
175 | 182 | }, |
176 | 183 | { |
|
197 | 204 | "\n", |
198 | 205 | "# Create a Ramachandran plot\n", |
199 | 206 | "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", |
201 | 208 | "\n", |
202 | 209 | "# 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", |
205 | 212 | "plt.xlim(-180, 180)\n", |
206 | 213 | "plt.ylim(-180, 180)\n", |
207 | 214 | "\n", |
208 | 215 | "# 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", |
213 | 220 | "plt.xticks(np.arange(-180, 181, 60))\n", |
214 | 221 | "plt.yticks(np.arange(-180, 181, 60))\n", |
215 | 222 | "\n", |
216 | | - "plt.show()\n" |
| 223 | + "plt.show()" |
217 | 224 | ] |
218 | 225 | } |
219 | 226 | ], |
|
0 commit comments