<jupyter_start><jupyter_text>A Quick Refresher on Using Jupyer NotebooksJupyter Notebooks allow you to run Python in an interactive way.Each of the boxes below is called a "Cell".To run the code in each cell:1. **Click** anywhere in the cell2. The left-hand border should turn green3. **Hit** "Shift and "Enter" at the same time4. In [ ]: in the left-hand margin should display In [*]: as the code runs5. In [ ]: in the left-hand margin should display In [n]: where n is the order of execution when the code has completed Alternatively:1. **Click** anywhere in the cell2. The left-hand border should turn green3. **Select** "Cell" then "Run Cells" from the top menu4. In [ ]: in the left-hand margin should display In [*]: as the code runs5. In [ ]: in the left-hand margin should display In [n]: where n is the order of execution when the code has completed ** NOTE: The order of execution is important - so pay attention to In [n]: **To clear the output of a given cell:1. **Click** anywhere in the cell2. The left-hand border should turn green3. **Select** "Cell" then "Current Outputs" then "Clear" from the top menuTo clear the output of all cells:1. **Click** anywhere in the cell2. The left-hand border should turn green3. **Select** "Cell" then "All Output" then "Clear" from the top menuTo save your progress:1. **Click** "file" then "Save and Checkpoint" from the top menuTo completely reset the Kernel:1. **Click** "Kernel" then "Restart & Clear Output " from the top menu<jupyter_code>import subprocess
import os, sys
# Test polypy install
import polypy
# Test scipy install
import scipy
# Test pylj install
import pylj
# sets the current working directory (cwd) to the Week_1 directory
cwd = os.getcwd()
print(cwd)<jupyter_output><empty_output><jupyter_text>Aim and Objectives The **Aim** of this week's exercise is to introduce molecular dynamics for atomistic simulation.The **first objective** is to make sure that the programmes we need are correctly installed.The **second objective** is to carry out molecular dynamics (MD) simulations of generated structures of simple materials using a package called DL_POLY.By the end of this task you will be able to:1. 	**Perform** molecular dynamics simulations at different temperatures2. 	**Manipulate** the input files3. 	**Adjust** the ensemble for the simulation4.	**Examine** the volume and energy of different simulations5.	**Apply** VMD to visualize the simulation cell and evaluate radial distribution coefficients**PLEASE NOTE** 1. **It is essential that the codes that were downloaded from [here](https://people.bath.ac.uk/chsscp/teach/adv.bho/progs.zip) are in the Codes/ folder in the parent directory, or the following cells will crash**2. Most of the instructions should be performed within this Notebook. However, some have to be executed on your own machineMost of the instructions should be performed within this Notebook. However, some have to be executed on your own machine.  1. Testing Before we can run some MD simulations, we first need to check whether the programs we are using (**Metadise_Test** and **DL_POLY**) are set up correctly:1. **Run** the cells below2. **Check** the output of your Anaconda Prompt is free of errors3. **Check** that files have been produced in the Metadise_Test/ and DLPOLY_Test/ directoriesto make sure that everything is set-up correctly.   METADISE The METADISE code uses simple interatomic potentials to calculate the forces between the atoms and energy minimization to find the most stable structures.METADISE has three core components, that we will be using throughout the course:1. **The structural information**, which can be in a variety of formats.  We will use it to generate a simulation cell of a crystal structure from its cell dimensions, space group and atomic coordinates2. **The potential interaction between ions**, which includes parameters defining the charge, size and hardness of the ions3. **Control parameters**, in this exercise will include information on growing the cell and generating DL_POLY input files for crystalline system run MD calculations (with DL_POLY).Further information about more METADISE functionality can be found [here](https://people.bath.ac.uk/chsscp/teach/metadise.bho/)<jupyter_code># Test METADISE

os.chdir(cwd)

os.chdir("Metadise_Test/")
subprocess.call('../../Codes/metadise.exe')

os.chdir(cwd)<jupyter_output><empty_output><jupyter_text>The METADISE/ directory should contain the following input files:**input.txt**Specifies the structural information including the dimensions of the simulation cell and then positions of all the atoms (in Å ) as well as the instructions to METADISE.as well as the following output files: **summ_o000n.OUT** A summary of the output file.**job_o000n.cml** Structure file in XML format.**fin_o000n.res** A restart file.**field_o000n.DLP**  DL_POLY FIELD file.**config_o000n.DLP** Structure file in DL_POLY CONFIG file format.**control_o000n.DLP** DL_POLY CONTROL file.**code_o000n.OUT** The main output file. This contains a summary of the input information and details of the METADISE operation.**af_co000n.MSI** Structure file in MSI format.**af_co000n.XYZ** Structure file in XYZ format.**af_co000n.CIF** Structure file in CIF format.**af_co000n.CAR** Structure file in CAR format.  DL_POLY DL_POLY is a general purpose parallel molecular dynamics package that was written by Daresbury Laboratory, primarily to support CCP5.The code is available free of charge and was written to be sufficiently flexible that it can be applied to many different condensed matter materials.<jupyter_code># Test DL_POLY

# This may take several minutes

os.chdir(cwd)

os.chdir("DLPOLY_Test/")
subprocess.call("../../Codes/dlpoly_classic")

os.chdir(cwd)<jupyter_output><empty_output><jupyter_text>The  DLPOLY_Test/  directory should contain the following input files:**CONTROL **Specifies the conditions for a run of the program e.g. steps, timestep, temperature, pressure, required ensemble etc. **FIELD** Specifies the force field for the simulation. It is also important to appreciate that it defines the order in which atoms will appear in the configuration. For example, if there were 25 W and 75 O atoms, this file will give the order of atoms in the simulation cell. **CONFIG** Specifies the dimensions of the simulation cell and then positions of all the atoms (in Å ). If it is generated from a previous run, it may also contain the atomic velocities and forces for each atom. as well as the following output files: **OUTPUT** Contains a summary of the simulation, including the input data, simulation progress report and summary of final system averages. **REVCON** This contains the positions, velocities and forces of all the atoms in the system at the end of the simulation. When renamed CONFIG is used as the restart configuration for a continuation run. It is written at the same time as the REVIVE file.  As with the CONFIG file, it is always worth checking that the atoms are at sensible positions. **STATIS** Contains a number of system variables at regular (user-specified) intervals throughout a simulation. It can be used for later statistical analysis. Note the file grows every time DL_POLY is run and is not overwritten. It should be removed from the execute subdirectory if a new simulation is to be started. **HISTORY** This details the atomic positions, (although can be made to contain velocities and forces) at selected intervals in the simulation. It forms the basis for much of the later analysis of the system. This file can become extremely large (beware) and is appended to, not overwritten, by later runs. It should always be removed from the execute subdirectory if a new simulation is to be started.  We also need to check whether the visualisation programs we are using (**VESTA** and **VMD**) are set up correctly:1. **Follow ** instructions in the cells belowto make sure that everything is set-up correctly. If you have not already, please **download** [VESTA](https://jp-minerals.org/vesta/en/download.html) and [VMD](https://www.ks.uiuc.edu/Development/Download/download.cgi?PackageName=VMD)  VESTA **VESTA** is a 3D visualization program for structural models, volumetric data such as electron/nuclear densities, and crystal morphologies.  VESTA TEST 1. **Open** VESTA (Start Menu -> VESTA)2. **Open** the DL_POLY CONFIG file from the DLPOLY_Test/ directory (File -> Open -> CONFIG)3. **Inspect** the structure by experimenting  with using the viewer to manipulate the cell. For example you might try to rotate the cell or change the display type or grow the crystal.  VMD **VMD** is a molecular visualization program for displaying, animating, and analyzing large biomolecular systems using 3D graphics and built-in scripting.We can use VMD to look in more detail at structure and to visualize the trajectories directly. As well as visualization, VMD can also calculate various properties including radial distribution functions g(r) to enable a more quantitative structural analysis, which can easily distinguish between a solid and liquid, based on the structure   VMD TEST 1. **Open** VMD (Start Menu -> VMD)2. **Open** the DL_POLY HISTORY file from the DLPOLY_Test/ directory (File -> New Molecule -> Browse -> HISTORY)3. **Change** file type to DL_POLY V2 History from the ‘Determine file type’ drop-down menu4. **Inspect** the structure by experimenting  with using the viewer to manipulate the cell. For example you might try to rotate the cell or zoom in and out.  2. Extension: Quick Molecular Dynamics Exercise We will mainly be adjusting the DL_POLY CONTROL file to adjust the simulation conditions and analysing the output obtained from MD simulations using a package called VMD. Once this task is complete we will explore the structural changes in different materials.  Checking The Structure A useful first check if the atom positions are not chemically sensible is to open the CONFIG file with VESTA as we did above.The DL_POLY jobs will take just under 10 minutes to run – if you find that yours is terminating immediately, or lasting for significantly longer than 15 minutes, please inform a demonstrator.<jupyter_code># Running DL_POLY

os.chdir(cwd)

os.chdir("DLPOLY_Exercise/")
subprocess.call("../../Codes/dlpoly_classic")
os.chdir(cwd)<jupyter_output><empty_output><jupyter_text>Changing The Parameters Open the file CONTROL in **Notepad++**. This file, as its name suggests, contains all the control variables for the simulation, i.e. it tells the program what to do. We have generated a template file with some standard values for a typical simulation; however for the simulation we are going to perform we will need to change a few of these values.1. 	**Check** that the time step is set at 0.001 ps (1 fs)2.	**Check** the number of ‘steps’ is set to 200003. 	**Change** the values traj 1 250 0 to traj 0 100 0. This changes how often the program writes out to the HISTORY file (more on this later)4.	**Select** a temperature to run: first try 85. This is the temperature in Kelvin.Once you have made these changes save the file as CONTROL. (again, all capitals with no suffix – ignore any warnings about changing suffix type). **NOTE**: The reliability of the result will depend on the number of steps as this improves the statistics. Thus, if the computer is fast enough, or you are leaving it running etc, try increasing the number of steps, but be careful or you may spend too much time waiting.  All DL_POLY simulations should be run in separate folders.   Investigate The System Properties **Open** the OUTPUT file in WordPad or NotePad++ and search for the word “final averages”. Under this line, you should find a table of properties and their fluctuations.Properties we particularly consider are temp_tot, eng_cfg, volume and press (Temperature, Potential Energy, Volume and Pressure).  As this is run in the NVE ensemble, the volume will stay fixed.**Check** that the temperature is close to your chosen value, if not, increase the number of equilibration steps (e.g. from 1000 to 10000) and increase the total number of steps by 10000.**Increase** the total number of steps and see if the properties remain reasonably constant, i.e. checking that the results are not dependent on the number of timesteps.**Repeat** the simulation in a separate folder but at 110 K by changing the CONTROL file and the information in the cell below.Is there a phase change from solid to liquid based on the properties?<jupyter_code># Running your own DL_POLY calculation at 110 K

os.chdir(cwd)
os.chdir("<your directory>)
subprocess.call("<path_to_dl_poly>")
os.chdir(cwd)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.06763590391908976, 'fraction_numerical': 0.010508849557522125, 'mean_word_length': 4.89245810055866, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 30, 'https://': 4, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '123154', 'license': 'MIT', 'n_tokens_mistral': 3372, 'n_tokens_neox': 3174, 'n_words': 1829, 'path': 'Week_1/week_1.ipynb', 'repo_name': 'chsscp/2021_Advanced_Practical_Chemistry_Year_3', 'size': '12656'}