Skip to content

Commit cfe9555

Browse files
committed
Updates for Python 3
1 parent 295aa4f commit cfe9555

File tree

5 files changed

+61
-113
lines changed

5 files changed

+61
-113
lines changed

0_jupyter_intro.ipynb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
},
1616
"outputs": [],
1717
"source": [
18+
"from __future__ import print_function\n",
1819
"import openpathsampling as paths"
1920
]
2021
},
@@ -135,7 +136,7 @@
135136
"metadata": {},
136137
"outputs": [],
137138
"source": [
138-
"print message"
139+
"print(message)"
139140
]
140141
},
141142
{
@@ -200,7 +201,7 @@
200201
"name": "python",
201202
"nbconvert_exporter": "python",
202203
"pygments_lexer": "ipython2",
203-
"version": "2.7.13"
204+
"version": "2.7.14"
204205
}
205206
},
206207
"nbformat": 4,

1_tps_sampling_tutorial.ipynb

Lines changed: 19 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,11 @@
2525
{
2626
"cell_type": "code",
2727
"execution_count": null,
28-
"metadata": {
29-
"collapsed": true
30-
},
28+
"metadata": {},
3129
"outputs": [],
3230
"source": [
3331
"%matplotlib inline\n",
32+
"from __future__ import print_function\n",
3433
"import matplotlib.pyplot as plt\n",
3534
"import numpy as np\n",
3635
"\n",
@@ -70,9 +69,7 @@
7069
{
7170
"cell_type": "code",
7271
"execution_count": null,
73-
"metadata": {
74-
"collapsed": true
75-
},
72+
"metadata": {},
7673
"outputs": [],
7774
"source": [
7875
"# this cell is all OpenMM specific\n",
@@ -104,9 +101,7 @@
104101
{
105102
"cell_type": "code",
106103
"execution_count": null,
107-
"metadata": {
108-
"collapsed": true
109-
},
104+
"metadata": {},
110105
"outputs": [],
111106
"source": [
112107
"openmm_properties = {}\n",
@@ -146,9 +141,7 @@
146141
{
147142
"cell_type": "code",
148143
"execution_count": null,
149-
"metadata": {
150-
"collapsed": true
151-
},
144+
"metadata": {},
152145
"outputs": [],
153146
"source": [
154147
"md_topology = md.Topology.from_openmm(engine.simulation.topology)"
@@ -164,13 +157,11 @@
164157
{
165158
"cell_type": "code",
166159
"execution_count": null,
167-
"metadata": {
168-
"collapsed": true
169-
},
160+
"metadata": {},
170161
"outputs": [],
171162
"source": [
172163
"for atom_number in md_topology.select(\"backbone\"):\n",
173-
" print atom_number, md_topology.atom(atom_number)"
164+
" print(atom_number, md_topology.atom(atom_number))"
174165
]
175166
},
176167
{
@@ -183,9 +174,7 @@
183174
{
184175
"cell_type": "code",
185176
"execution_count": null,
186-
"metadata": {
187-
"collapsed": true
188-
},
177+
"metadata": {},
189178
"outputs": [],
190179
"source": [
191180
"# ACE0-C, ALA1-N, ALA1-CA, ALA1-C: 4,6,8,14\n",
@@ -195,9 +184,7 @@
195184
{
196185
"cell_type": "code",
197186
"execution_count": null,
198-
"metadata": {
199-
"collapsed": true
200-
},
187+
"metadata": {},
201188
"outputs": [],
202189
"source": [
203190
"# YOUR TURN: Define `psi`, similarly to `phi` above.\n",
@@ -223,9 +210,7 @@
223210
{
224211
"cell_type": "code",
225212
"execution_count": null,
226-
"metadata": {
227-
"collapsed": true
228-
},
213+
"metadata": {},
229214
"outputs": [],
230215
"source": [
231216
"deg = 180.0/np.pi # for conversion between radians and degrees\n",
@@ -241,9 +226,7 @@
241226
{
242227
"cell_type": "code",
243228
"execution_count": null,
244-
"metadata": {
245-
"collapsed": true
246-
},
229+
"metadata": {},
247230
"outputs": [],
248231
"source": [
249232
"# YOUR TURN: define the `alpha_R` state"
@@ -270,9 +253,7 @@
270253
{
271254
"cell_type": "code",
272255
"execution_count": null,
273-
"metadata": {
274-
"collapsed": true
275-
},
256+
"metadata": {},
276257
"outputs": [],
277258
"source": [
278259
"network = paths.TPSNetwork(initial_states=C_7eq, final_states=alpha_R)\n",
@@ -293,9 +274,7 @@
293274
{
294275
"cell_type": "code",
295276
"execution_count": null,
296-
"metadata": {
297-
"collapsed": true
298-
},
277+
"metadata": {},
299278
"outputs": [],
300279
"source": [
301280
"init_traj_storage = paths.Storage(\"initial_trajectory.nc\", 'r')\n",
@@ -305,9 +284,7 @@
305284
{
306285
"cell_type": "code",
307286
"execution_count": null,
308-
"metadata": {
309-
"collapsed": true
310-
},
287+
"metadata": {},
311288
"outputs": [],
312289
"source": [
313290
"plt.plot(phi(init_traj), psi(init_traj))\n",
@@ -325,9 +302,7 @@
325302
{
326303
"cell_type": "code",
327304
"execution_count": null,
328-
"metadata": {
329-
"collapsed": true
330-
},
305+
"metadata": {},
331306
"outputs": [],
332307
"source": [
333308
"initial_conditions = scheme.initial_conditions_from_trajectories(init_traj)"
@@ -345,9 +320,7 @@
345320
{
346321
"cell_type": "code",
347322
"execution_count": null,
348-
"metadata": {
349-
"collapsed": true
350-
},
323+
"metadata": {},
351324
"outputs": [],
352325
"source": [
353326
"storage = paths.Storage(\"tps_simulation_results.nc\", \"w\", template=init_traj[0])\n",
@@ -359,9 +332,7 @@
359332
{
360333
"cell_type": "code",
361334
"execution_count": null,
362-
"metadata": {
363-
"collapsed": true
364-
},
335+
"metadata": {},
365336
"outputs": [],
366337
"source": [
367338
"sampler.run(40)"
@@ -370,9 +341,7 @@
370341
{
371342
"cell_type": "code",
372343
"execution_count": null,
373-
"metadata": {
374-
"collapsed": true
375-
},
344+
"metadata": {},
376345
"outputs": [],
377346
"source": [
378347
"storage.close()"
@@ -395,7 +364,7 @@
395364
"name": "python",
396365
"nbconvert_exporter": "python",
397366
"pygments_lexer": "ipython2",
398-
"version": "2.7.13"
367+
"version": "2.7.14"
399368
}
400369
},
401370
"nbformat": 4,

2_tps_analysis_tutorial.ipynb

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"outputs": [],
3030
"source": [
3131
"%matplotlib inline\n",
32+
"from __future__ import print_function\n",
3233
"import openpathsampling as paths\n",
3334
"import numpy as np\n",
3435
"import os\n",
@@ -231,11 +232,11 @@
231232
},
232233
"outputs": [],
233234
"source": [
234-
"print \"File size: {0} for {1} steps, {2} snapshots\".format(\n",
235+
"print(\"File size: {0} for {1} steps, {2} snapshots\".format(\n",
235236
" flexible.file_size_str,\n",
236237
" len(flexible.steps),\n",
237238
" len(flexible.snapshots)\n",
238-
")"
239+
"))"
239240
]
240241
},
241242
{
@@ -311,7 +312,7 @@
311312
" )\n",
312313
")\n",
313314
"\n",
314-
"print \"Decorrelated trajectories:\", len(full_tree.generator.decorrelated_trajectories)"
315+
"print(\"Decorrelated trajectories:\", len(full_tree.generator.decorrelated_trajectories))"
315316
]
316317
},
317318
{
@@ -345,8 +346,8 @@
345346
"source": [
346347
"path_lengths = [len(step.active[0].trajectory) for step in flexible.steps]\n",
347348
"plt.hist(path_lengths, bins=40, alpha=0.5);\n",
348-
"print \"Maximum:\", max(path_lengths), \"(\"+str(max(path_lengths)*engine.snapshot_timestep)+\")\"\n",
349-
"print \"Average:\", \"{0:.2f}\".format(np.mean(path_lengths)), \"(\"+(np.mean(path_lengths)*engine.snapshot_timestep).format(\"%.3f\")+\")\""
349+
"print(\"Maximum:\", max(path_lengths), \"(\"+str(max(path_lengths)*engine.snapshot_timestep)+\")\")\n",
350+
"print(\"Average:\", \"{0:.2f}\".format(np.mean(path_lengths)), \"(\"+(np.mean(path_lengths)*engine.snapshot_timestep).format(\"%.3f\")+\")\")"
350351
]
351352
},
352353
{
@@ -395,7 +396,7 @@
395396
"cell_type": "markdown",
396397
"metadata": {},
397398
"source": [
398-
"The next step is will take the longest (perhaps 10-15 minutes):"
399+
"The next step is will take the longest (perhaps up to 20 minutes):"
399400
]
400401
},
401402
{
@@ -470,7 +471,7 @@
470471
"ax = plotter.plot(xlim=(-np.pi, 0), ylim=(-np.pi/2, np.pi), cmap=\"Blues\")\n",
471472
"plotter.plot_trajectory(trajA, '-r', lw=1)\n",
472473
"plotter.plot_trajectory(trajB, '-k', lw=1)\n",
473-
"#plt.savefig(\"AD_tps_pathdensity.pdf\")"
474+
"#plt.savefig(\"AD_tps_pathdensity.pdf\") # uncomment this line to save as PDF"
474475
]
475476
},
476477
{
@@ -527,7 +528,7 @@
527528
"name": "python",
528529
"nbconvert_exporter": "python",
529530
"pygments_lexer": "ipython2",
530-
"version": "2.7.13"
531+
"version": "2.7.14"
531532
}
532533
},
533534
"nbformat": 4,

3_committor_analysis_tutorial.ipynb

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,11 @@
7171
},
7272
"outputs": [],
7373
"source": [
74-
"print \"File size: {0} for {1} steps, {2} snapshots\".format(\n",
74+
"print(\"File size: {0} for {1} steps, {2} snapshots\".format(\n",
7575
" simulation_storage.file_size_str,\n",
7676
" len(simulation_storage.steps),\n",
7777
" len(simulation_storage.snapshots)\n",
78-
")"
78+
"))"
7979
]
8080
},
8181
{
@@ -130,6 +130,7 @@
130130
},
131131
"outputs": [],
132132
"source": [
133+
"%time\n",
133134
"phi_hash = lambda x : float(phi(x))\n",
134135
"analyzer.to_pandas(label_function=phi_hash)"
135136
]
@@ -151,7 +152,7 @@
151152
"source": [
152153
"hist1D, phi_bins = analyzer.committor_histogram(phi_hash, alpha_R, bins=10)\n",
153154
"bin_widths = [phi_bins[i+1]-phi_bins[i] for i in range(len(phi_bins)-1)]\n",
154-
"plt.bar(left=phi_bins[:-1], height=hist1D, width=bin_widths)\n",
155+
"plt.bar(x=phi_bins[:-1], height=hist1D, width=bin_widths)\n",
155156
"plt.xlabel(\"$\\phi$\")\n",
156157
"plt.ylabel(\"$p_B$\");"
157158
]
@@ -204,6 +205,7 @@
204205
},
205206
"outputs": [],
206207
"source": [
208+
"%time\n",
207209
"ramachandran_hash = lambda x : (float(phi(x)), float(psi(x)))\n",
208210
"hist2D, bins_phi, bins_psi = analyzer.committor_histogram(ramachandran_hash, alpha_R, bins=20)"
209211
]
@@ -282,7 +284,9 @@
282284
"cell_type": "markdown",
283285
"metadata": {},
284286
"source": [
285-
"Try a few different values of `psi_star_min` and `psi_star_max`. Do you ever get a distribution that is peaked around $p_B = 0.5$?"
287+
"Try a few different values of `psi_star_min` and `psi_star_max`. \n",
288+
"\n",
289+
"* Do you ever get a distribution that is peaked around $p_B = 0.5$?"
286290
]
287291
},
288292
{
@@ -352,7 +356,7 @@
352356
"name": "python",
353357
"nbconvert_exporter": "python",
354358
"pygments_lexer": "ipython2",
355-
"version": "2.7.13"
359+
"version": "2.7.14"
356360
}
357361
},
358362
"nbformat": 4,

0 commit comments

Comments
 (0)