{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Running the production TPS simulation" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This is file runs the main calculation for the flexible length TPS simulation. It requires the file `ad_tps_equil.nc`, which is written in the notebook `AD_tps_1_trajectory.ipynb`.\n", "\n", "In this file, you will learn:\n", "\n", "* how to load simulation objects from a file and reuse them\n", "* how to run a production simulation\n", "\n", "NB: This is a long calculation. In practice, it would be best to export the Python from this notebook and run non-interactively on a computing node, or to use save the setup to a file and use the [OpenPathSampling CLI](http://openpathsampling.org/latest/cli.html)." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "%matplotlib inline\n", "import openpathsampling as paths" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Load simulation objects from file\n", "\n", "In setting up the equilibration simulation, we've already defined everything we need for path sampling. One of the big strengths of OPS is that all simulation objects are saved in the storage file. This means that you can easily reload them for other simulations, and you have a clear chain of provenance, so you know that settings are *exactly* the same. This is why we name OPS objects using the `.named()` method -- it makes it easy to load them up later.\n", "\n", "In this example, we'll create a new scheme. This scheme is actually identical to our equilibration scheme, so we could have just reused that old one. However, in many situations, you might use a different move scheme for equilibration than for production. For example, you might use only one-way shooting to equilibrate a TIS network, and but then use a full RETIS move scheme for the production run." ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "old_storage = paths.Storage(\"ad_tps_equil.nc\", mode='r')" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "network = old_storage.networks['tps_network']\n", "engine = old_storage.engines['300K']\n", "last_result = old_storage.steps[-1].active" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "# note that we could have loaded other things from storage, for example:\n", "#C_7eq = old_storage.volumes['C_7eq']\n", "#alpha_R = old_storage.volumes['alpha_R']\n", "# however, we don't need to, since all the information is in the network" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Run TPS\n", "\n", "As always, the process for setting up a simulation is:\n", "\n", "1. Create a `network`\n", "2. Create a `move_scheme`\n", "3. Set up `initial_conditions`\n", "4. Create the `PathSampling` object and run it.\n", "\n", "Since we already created all the input to these when we set up the first trajectory, we can load use the versions we loaded above." ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "scheme = paths.OneWayShootingMoveScheme(network, \n", " selector=paths.UniformSelector(),\n", " engine=engine)" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "No missing ensembles.\n", "No extra ensembles.\n" ] } ], "source": [ "initial_conditions = scheme.initial_conditions_from_trajectories(last_result)" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [], "source": [ "storage = paths.Storage(\"ad_tps.nc\", \"w\")\n", "storage.save(initial_conditions); # save these to give storage a template" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [], "source": [ "# we can only close the old storage after we've saved the initial conditions -- \n", "# this is because details of the snapshot aren't loaded until needed\n", "old_storage.close()" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [], "source": [ "sampler = paths.PathSampling(storage=storage,\n", " move_scheme=scheme,\n", " sample_set=initial_conditions).named(\"Flexible_TPS_Sampling\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Note: 10000 steps will take a long time. If you just want to run a little bit, reduce this number." ] }, { "cell_type": "code", "execution_count": 10, "metadata": { "scrolled": true }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Working on Monte Carlo cycle number 10000\n", "Running for 3 hours 29 seconds - 1.08 seconds per step\n", "Estimated time remaining: 1 second\n", "DONE! Completed 10000 Monte Carlo cycles.\n" ] } ], "source": [ "sampler.run(10000)" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [], "source": [ "storage.close()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "With this done, you can go on to do the flexible-length parts of the analysis in `AD_tps_3a_analysis_flex.ipynb`." ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.8" }, "toc": { "base_numbering": 1, "nav_menu": {}, "number_sections": true, "sideBar": true, "skip_h1_title": true, "title_cell": "Table of Contents", "title_sidebar": "Contents", "toc_cell": false, "toc_position": {}, "toc_section_display": true, "toc_window_display": true }, "varInspector": { "cols": { "lenName": 16, "lenType": 16, "lenVar": 40 }, "kernels_config": { "python": { "delete_cmd_postfix": "", "delete_cmd_prefix": "del ", "library": "var_list.py", "varRefreshCmd": "print(var_dic_list())" }, "r": { "delete_cmd_postfix": ") ", "delete_cmd_prefix": "rm(", "library": "var_list.r", "varRefreshCmd": "cat(var_dic_list()) " } }, "types_to_exclude": [ "module", "function", "builtin_function_or_method", "instance", "_Feature" ], "window_display": false }, "widgets": { "application/vnd.jupyter.widget-state+json": { "state": {}, "version_major": 2, "version_minor": 0 } } }, "nbformat": 4, "nbformat_minor": 4 }