Skip to content

Commit 29906d7

Browse files
committed
provide more details for self-guided users
1 parent 730a1d5 commit 29906d7

File tree

6 files changed

+291
-56
lines changed

6 files changed

+291
-56
lines changed

0_jupyter_intro.ipynb

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
},
1010
{
1111
"cell_type": "code",
12-
"execution_count": null,
12+
"execution_count": 1,
1313
"metadata": {},
1414
"outputs": [],
1515
"source": [
@@ -187,9 +187,51 @@
187187
"name": "python",
188188
"nbconvert_exporter": "python",
189189
"pygments_lexer": "ipython3",
190-
"version": "3.7.2"
190+
"version": "3.7.3"
191+
},
192+
"toc": {
193+
"base_numbering": 1,
194+
"nav_menu": {},
195+
"number_sections": true,
196+
"sideBar": true,
197+
"skip_h1_title": true,
198+
"title_cell": "Table of Contents",
199+
"title_sidebar": "Contents",
200+
"toc_cell": false,
201+
"toc_position": {},
202+
"toc_section_display": true,
203+
"toc_window_display": true
204+
},
205+
"varInspector": {
206+
"cols": {
207+
"lenName": 16,
208+
"lenType": 16,
209+
"lenVar": 40
210+
},
211+
"kernels_config": {
212+
"python": {
213+
"delete_cmd_postfix": "",
214+
"delete_cmd_prefix": "del ",
215+
"library": "var_list.py",
216+
"varRefreshCmd": "print(var_dic_list())"
217+
},
218+
"r": {
219+
"delete_cmd_postfix": ") ",
220+
"delete_cmd_prefix": "rm(",
221+
"library": "var_list.r",
222+
"varRefreshCmd": "cat(var_dic_list()) "
223+
}
224+
},
225+
"types_to_exclude": [
226+
"module",
227+
"function",
228+
"builtin_function_or_method",
229+
"instance",
230+
"_Feature"
231+
],
232+
"window_display": false
191233
}
192234
},
193235
"nbformat": 4,
194-
"nbformat_minor": 1
236+
"nbformat_minor": 4
195237
}

1_tps_sampling_tutorial.ipynb

Lines changed: 74 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,7 @@
4141
"import openpathsampling as paths\n",
4242
"import openpathsampling.engines.openmm as ops_openmm\n",
4343
"\n",
44-
"import mdtraj as md\n",
45-
"\n",
46-
"# Jupyter is raising deprecation warning from JSON now... ignore\n",
47-
"import warnings\n",
48-
"warnings.filterwarnings('ignore')"
44+
"import mdtraj as md"
4945
]
5046
},
5147
{
@@ -61,7 +57,7 @@
6157
"cell_type": "markdown",
6258
"metadata": {},
6359
"source": [
64-
"The next cell shows you how to set up several things specific to OpenMM. We'll be running in the $NVT$ ensemble, with $T=300 K$. We're using the [Velocity Verlet with Velocity Randomization (VVVR) integrator](http://arxiv.org/abs/1301.3800), which simulates Langevin dynamics. Note that the integrator itself comes from [`openmmtools`](https://github.com/choderalab/openmmtools), a library that extends `OpenMM`.\n",
60+
"The next cell shows you how to set up several things specific to OpenMM. We'll be running in the $NVT$ ensemble, with $T=300 K$. We're using the [Velocity Verlet with Velocity Randomization (VVVR) integrator](http://arxiv.org/abs/1301.3800), which simulates Langevin dynamics. Note that the integrator itself comes from [`openmmtools`](https://github.com/choderalab/openmmtools), a library that extends OpenMM. You should always use a reversible integrator when performing path sampling simulations. The default integrators in OpenMM are leapfrog-based, and therefore not reversible.\n",
6561
"\n",
6662
"You can learn a lot more about setting up OpenMM simulations from the [OpenMM documentation](http://docs.openmm.org/). However, it is often even easier to use the [OpenMM Script Builder](http://builder.openmm.org/) to learn how to set up the simulation the way you'd like."
6763
]
@@ -135,7 +131,7 @@
135131
"\n",
136132
"We'll need the atom numbers for these (just as Gromacs put those atom numbers into an `idx` file). To find them, we'll use MDTraj's `Topology` object. First, we convert the OPS `Topology` object to an MDTraj `Topology` object.\n",
137133
"\n",
138-
"> NB: There are several types of `Topology` objects. See, for example, what you get from `type(engine.topology)` vs. `type(engine.simulation.topology)` and then `type(md_topology)` after you make it. The tricks discussed below are for the MDTraj topology objects."
134+
"> NB: There are several types of `Topology` objects. See, for example, what you get from `type(engine.topology)` vs. `type(engine.simulation.topology)` and then `type(md_topology)` after you make it. The atom selection language discussed below is only for MDTraj topology objects."
139135
]
140136
},
141137
{
@@ -259,7 +255,7 @@
259255
"network = paths.TPSNetwork(initial_states=C_7eq, final_states=alpha_R)\n",
260256
"scheme = paths.OneWayShootingMoveScheme(network=network, \n",
261257
" selector=paths.UniformSelector(),\n",
262-
" engine=engine)"
258+
" engine=engine).named(\"tps_scheme\")"
263259
]
264260
},
265261
{
@@ -268,7 +264,9 @@
268264
"source": [
269265
"## Getting an initial trajectory\n",
270266
"\n",
271-
"In practice, getting the initial trajectory can be one of the hardest parts of path sampling. For this example, you could easily do it by running high temperature MD to get an unphysical path, and then equilibrate it for a while. However, for the purposes of this tutorial, I already did that for you. So we'll just load the equilibrated trajectory from a file."
267+
"In practice, getting the initial trajectory can be one of the hardest parts of path sampling. For this example, you could easily do it by running high temperature MD to get an unphysical path, and then equilibrate it for a while. However, for the purposes of this tutorial, I already did that for you. So we'll just load the equilibrated trajectory from a file.\n",
268+
"\n",
269+
"Note that this trajectory comes from an OPS NetCDF file. This should not be confused with the Amber NetCDF trajectory format. NetCDF is a storage backend that can handle arbitrary data. The way that data is organized for OPS is different from the way it is organized in Amber, so the file formats are not compatible."
272270
]
273271
},
274272
{
@@ -281,6 +279,13 @@
281279
"init_traj = init_traj_storage.trajectories[0]"
282280
]
283281
},
282+
{
283+
"cell_type": "markdown",
284+
"metadata": {},
285+
"source": [
286+
"The CVs you created act like functions when applied to a snapshot or trajectory. This allows us to easily plot the trajectory in $\\phi$ and $\\psi$, using `matplotlib`."
287+
]
288+
},
284289
{
285290
"cell_type": "code",
286291
"execution_count": null,
@@ -330,7 +335,22 @@
330335
"metadata": {},
331336
"outputs": [],
332337
"source": [
333-
"storage = paths.Storage(\"tps_simulation_results.nc\", \"w\", template=init_traj[0])\n",
338+
"storage = paths.Storage(\"tps_simulation_results.nc\", \"w\", template=init_traj[0])"
339+
]
340+
},
341+
{
342+
"cell_type": "markdown",
343+
"metadata": {},
344+
"source": [
345+
"If you get a `PermissionError` when doing that, it probably means that you have already opened this file for writing. Use `storage.close()` to close the old file."
346+
]
347+
},
348+
{
349+
"cell_type": "code",
350+
"execution_count": null,
351+
"metadata": {},
352+
"outputs": [],
353+
"source": [
334354
"sampler = paths.PathSampling(storage=storage,\n",
335355
" move_scheme=scheme,\n",
336356
" sample_set=initial_conditions)"
@@ -378,9 +398,51 @@
378398
"name": "python",
379399
"nbconvert_exporter": "python",
380400
"pygments_lexer": "ipython3",
381-
"version": "3.7.2"
401+
"version": "3.7.3"
402+
},
403+
"toc": {
404+
"base_numbering": 1,
405+
"nav_menu": {},
406+
"number_sections": true,
407+
"sideBar": true,
408+
"skip_h1_title": true,
409+
"title_cell": "Table of Contents",
410+
"title_sidebar": "Contents",
411+
"toc_cell": false,
412+
"toc_position": {},
413+
"toc_section_display": true,
414+
"toc_window_display": false
415+
},
416+
"varInspector": {
417+
"cols": {
418+
"lenName": 16,
419+
"lenType": 16,
420+
"lenVar": 40
421+
},
422+
"kernels_config": {
423+
"python": {
424+
"delete_cmd_postfix": "",
425+
"delete_cmd_prefix": "del ",
426+
"library": "var_list.py",
427+
"varRefreshCmd": "print(var_dic_list())"
428+
},
429+
"r": {
430+
"delete_cmd_postfix": ") ",
431+
"delete_cmd_prefix": "rm(",
432+
"library": "var_list.r",
433+
"varRefreshCmd": "cat(var_dic_list()) "
434+
}
435+
},
436+
"types_to_exclude": [
437+
"module",
438+
"function",
439+
"builtin_function_or_method",
440+
"instance",
441+
"_Feature"
442+
],
443+
"window_display": false
382444
}
383445
},
384446
"nbformat": 4,
385-
"nbformat_minor": 2
447+
"nbformat_minor": 4
386448
}

2_tps_analysis_tutorial.ipynb

Lines changed: 63 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,15 @@
3434
"\n",
3535
"import matplotlib.pyplot as plt\n",
3636
"import matplotlib\n",
37+
"# set some matplotlib parameters\n",
3738
"matplotlib.rcParams.update({'font.size': 18})\n",
3839
"matplotlib.rcParams.update({'figure.figsize': (8.8, 6.6)})\n",
40+
"\n",
3941
"from openpathsampling.numerics import HistogramPlotter2D\n",
4042
"import openpathsampling.visualize as ops_vis\n",
4143
"from IPython.display import SVG\n",
4244
"\n",
43-
"import nglview as nv\n",
44-
"\n",
45-
"# Jupyter is raising deprecation warning from JSON now... ignore\n",
46-
"import warnings\n",
47-
"warnings.filterwarnings('ignore')"
45+
"import nglview as nv"
4846
]
4947
},
5048
{
@@ -120,7 +118,7 @@
120118
"source": [
121119
"# YOUR TURN: load a trajectory from your simulation. \n",
122120
"# Replace #### in the line below with the number of one of your steps\n",
123-
"# (and uncomment it the line).\n",
121+
"# (and uncomment the line).\n",
124122
"#traj = storage.steps[####].active[0].trajectory"
125123
]
126124
},
@@ -147,9 +145,7 @@
147145
"\n",
148146
"```python\n",
149147
"traj.to_mdtraj().save(\"filename.dcd\")\n",
150-
"```\n",
151-
"\n",
152-
"(`DCD` format does not require a separate topology file, the way `.xtc` requires ` .gro`)"
148+
"```"
153149
]
154150
},
155151
{
@@ -192,7 +188,8 @@
192188
"outputs": [],
193189
"source": [
194190
"%%time\n",
195-
"flexible = paths.AnalysisStorage(\"alanine_dipeptide_tps_split.nc\")"
191+
"flexible = paths.AnalysisStorage(\"alanine_dipeptide_tps_split.nc\")\n",
192+
"# loading as AnalysisStorage massively speeds up the move_summary"
196193
]
197194
},
198195
{
@@ -247,7 +244,7 @@
247244
"cell_type": "markdown",
248245
"metadata": {},
249246
"source": [
250-
"#### Replica history tree and decorrelated trajectories\n",
247+
"### Replica history tree and decorrelated trajectories\n",
251248
"\n",
252249
"The `PathTree` object gives us both the history tree (often called the \"move tree\") and the number of decorrelated trajectories.\n",
253250
"\n",
@@ -302,7 +299,7 @@
302299
"cell_type": "markdown",
303300
"metadata": {},
304301
"source": [
305-
"#### Path length distribution\n",
302+
"### Path length distribution\n",
306303
"\n",
307304
"Flexible length TPS gives a distribution of path lengths. Here we calculate the length of every accepted trajectory, then histogram those lengths, and calculate the maximum and average path lengths.\n",
308305
"\n",
@@ -312,9 +309,7 @@
312309
{
313310
"cell_type": "code",
314311
"execution_count": null,
315-
"metadata": {
316-
"scrolled": false
317-
},
312+
"metadata": {},
318313
"outputs": [],
319314
"source": [
320315
"path_lengths = [len(step.active[0].trajectory) for step in flexible.steps]\n",
@@ -334,7 +329,7 @@
334329
"cell_type": "markdown",
335330
"metadata": {},
336331
"source": [
337-
"#### Path density histogram\n",
332+
"### Path density histogram\n",
338333
"\n",
339334
"Next we will create a path density histogram. Calculating the histogram itself is quite easy: first we reload the collective variables we want to plot it in (we choose the phi and psi angles). Then we create the empty path density histogram, by telling it which CVs to use and how to make the histogram (bin sizes, etc). Finally, we build the histogram by giving it the list of active trajectories to histogram."
340335
]
@@ -365,7 +360,7 @@
365360
"cell_type": "markdown",
366361
"metadata": {},
367362
"source": [
368-
"The next step is will take the longest (perhaps up to 20 minutes):"
363+
"Next we loop over all trajectories and calculate the path density:"
369364
]
370365
},
371366
{
@@ -374,8 +369,8 @@
374369
"metadata": {},
375370
"outputs": [],
376371
"source": [
377-
"%%time\n",
378-
"path_dens_counter = path_density.histogram([s.active[0].trajectory for s in flexible.steps])"
372+
"trajs = [s.active[0].trajectory for s in flexible.steps]\n",
373+
"path_dens_counter = path_density.histogram(trajs)"
379374
]
380375
},
381376
{
@@ -485,9 +480,56 @@
485480
"name": "python",
486481
"nbconvert_exporter": "python",
487482
"pygments_lexer": "ipython3",
488-
"version": "3.7.2"
483+
"version": "3.7.3"
484+
},
485+
"toc": {
486+
"base_numbering": 1,
487+
"nav_menu": {},
488+
"number_sections": true,
489+
"sideBar": true,
490+
"skip_h1_title": true,
491+
"title_cell": "Table of Contents",
492+
"title_sidebar": "Contents",
493+
"toc_cell": false,
494+
"toc_position": {
495+
"height": "calc(100% - 180px)",
496+
"left": "10px",
497+
"top": "150px",
498+
"width": "277.797px"
499+
},
500+
"toc_section_display": true,
501+
"toc_window_display": false
502+
},
503+
"varInspector": {
504+
"cols": {
505+
"lenName": 16,
506+
"lenType": 16,
507+
"lenVar": 40
508+
},
509+
"kernels_config": {
510+
"python": {
511+
"delete_cmd_postfix": "",
512+
"delete_cmd_prefix": "del ",
513+
"library": "var_list.py",
514+
"varRefreshCmd": "print(var_dic_list())"
515+
},
516+
"r": {
517+
"delete_cmd_postfix": ") ",
518+
"delete_cmd_prefix": "rm(",
519+
"library": "var_list.r",
520+
"varRefreshCmd": "cat(var_dic_list()) "
521+
}
522+
},
523+
"types_to_exclude": [
524+
"module",
525+
"function",
526+
"builtin_function_or_method",
527+
"instance",
528+
"_Feature"
529+
],
530+
"window_display": false
489531
}
490532
},
491533
"nbformat": 4,
492-
"nbformat_minor": 1
534+
"nbformat_minor": 4
493535
}

0 commit comments

Comments
 (0)