{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import warnings\n", "from pylj import md, sample\n", "import numpy as np\n", "import matplotlib.pyplot as plt\n", "\n", "warnings.filterwarnings('ignore')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def md_simulation(number_of_particles, temperature, box_length, number_of_steps, sample_frequency):\n", " # Creates the visualisation environment\n", " %matplotlib notebook\n", " # Initialise the system\n", " system = md.initialise(number_of_particles, temperature, box_length, 'square')\n", " # This sets the sampling class\n", " sample_system = sample.MaxBolt(system)\n", " # Start at time 0\n", " system.time = 0\n", " # Begin the molecular dynamics loop\n", " for i in range(0, number_of_steps):\n", " # Run the equations of motion integrator algorithm, this \n", " # includes the force calculation\n", " system.integrate(md.velocity_verlet)\n", " # Sample the thermodynamic and structural parameters of the system\n", " system.md_sample()\n", " # Allow the system to interact with a heat bath\n", " system.heat_bath(temperature)\n", " # Iterate the time\n", " system.time += system.timestep_length\n", " system.step += 1\n", " # At a given frequency sample the positions and plot the RDF\n", " if system.step % sample_frequency == 0:\n", " sample_system.update(system)\n", " return system" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The `md_simulation` function takes five variables:\n", "- The number of particles\n", "- The simulation temperature\n", "- The simulation cell vector\n", "- The number of steps\n", "- The sampling frequency (how often the image is updated)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "scrolled": false }, "outputs": [], "source": [ "md_simulation(20, 1000, 100, 50000, 100)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "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.1" }, "latex_envs": { "LaTeX_envs_menu_present": true, "autoclose": false, "autocomplete": true, "bibliofile": "biblio.bib", "cite_by": "apalike", "current_citInitial": 1, "eqLabelWithNumbers": true, "eqNumInitial": 1, "hotkeys": { "equation": "Ctrl-E", "itemize": "Ctrl-I" }, "labels_anchors": false, "latex_user_defs": false, "report_style_numbering": false, "user_envs_cfg": false } }, "nbformat": 4, "nbformat_minor": 2 }