zincware/MDSuite

View on GitHub
examples/notebooks/Molten_Salt_Comparison.ipynb

Summary

Maintainability
Test Coverage
{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "31e2af23",
   "metadata": {},
   "source": [
    "# Molten Salt Comparison\n",
    "\n",
    "In this tutorial we will compare two large molten salt simulation of NaCl and KCl to see how their structures and properties differ from one another.\n",
    "\n",
    "This tutorial assumes that you are already familiar with the general MDSuite interface and have looked over the previous tutorial."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7c30999d",
   "metadata": {},
   "outputs": [],
   "source": [
    "import mdsuite as mds\n",
    "import matplotlib.pyplot as plt\n",
    "from zinchub import DataHub\n",
    "import tensorflow as tf\n",
    "import numpy as np\n",
    "from scipy.integrate import cumtrapz"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "194e3b1f",
   "metadata": {},
   "source": [
    "In this tutorial we are using two, 1000 atom simulations of NaCl and KCl run for 5000 time steps. Keep in mind, due to the size of these files (~140 MB each) they may take some time to download and unzip (within a minute depending on internet connection)."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b0b9867b",
   "metadata": {},
   "outputs": [],
   "source": [
    "NaCl_file = DataHub(url=\"https://github.com/zincware/DataHub/tree/main/NaCl_rnd_md\", tag=\"v0.1.0\")\n",
    "KCl_file = DataHub(url=\"https://github.com/zincware/DataHub/tree/main/KCl_rnd_md\", tag=\"v0.1.0\")\n",
    "\n",
    "KCl_data = KCl_file.get_file('.')[0]\n",
    "NaCl_data = NaCl_file.get_file('.')[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "52d7bc69",
   "metadata": {},
   "outputs": [],
   "source": [
    "md_project = mds.Project(name=\"Molten_Salt_Comparison\", storage_path='.')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d10a3428",
   "metadata": {},
   "source": [
    "Again, depending on your computer, adding the data may take up between 25s to 1m total."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4816f42b",
   "metadata": {},
   "outputs": [],
   "source": [
    "NaCl_experiment = md_project.add_experiment(\n",
    "    name=\"NaCl\", timestep=0.002, units='metal', temperature=1200.0, simulation_data=NaCl_data\n",
    ")\n",
    "KCl_experiment = md_project.add_experiment(\n",
    "    name=\"KCl\", timestep=0.002, units='metal', temperature=1200.0, simulation_data=KCl_data\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ce92a2f6",
   "metadata": {},
   "source": [
    "## Structural Information\n",
    "\n",
    "The first thing we want to study is how the structure of these salts compare. Let's do so by comparing the RDFs, ADFs, coordination numbers, and potential of mean force values for the dominant interactions in each system.\n",
    "\n",
    "For each of these computations we will directly call the project. This is simply a faster way of performing the same computation on all of the experiments at one time. What is returns is a dictionary of information for each experiment. We will demonstrate here how one can use this to extract relevant information."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "cf852c5f",
   "metadata": {},
   "outputs": [],
   "source": [
    "RDF_Data = md_project.run.RadialDistributionFunction(number_of_configurations=500, cutoff=15.0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "72d522cf",
   "metadata": {
    "scrolled": false
   },
   "outputs": [],
   "source": [
    "NaCl_experiment.run.CoordinationNumbers(\n",
    "    rdf_data=RDF_Data['NaCl'], savgol_window_length=111, savgol_order=9, number_of_shells=3\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a129ebfb",
   "metadata": {},
   "outputs": [],
   "source": [
    "KCl_experiment.run.CoordinationNumbers(\n",
    "    rdf_data=RDF_Data['KCl'], savgol_window_length=111, savgol_order=7, number_of_shells=2\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b2578aba",
   "metadata": {},
   "outputs": [],
   "source": [
    "KCl_experiment.run.PotentialOfMeanForce(\n",
    "    rdf_data=RDF_Data['KCl'], savgol_window_length=111, savgol_order=7, number_of_shells=2\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d07725e4",
   "metadata": {},
   "outputs": [],
   "source": [
    "radii = RDF_Data['NaCl']['Na_Cl']['x']\n",
    "NaCl_rdf = RDF_Data['NaCl']['Na_Cl']['y']\n",
    "KCl_rdf = RDF_Data['KCl']['Cl_K']['y']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "268b12d2",
   "metadata": {},
   "outputs": [],
   "source": [
    "plt.plot(radii, NaCl_rdf, '--', label='NaCl')\n",
    "plt.plot(radii, KCl_rdf, '-.', label='KCl')\n",
    "plt.legend()\n",
    "plt.xlabel(\"Radius / nm\")\n",
    "plt.ylabel(\"g(r)\")\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "05599b8b",
   "metadata": {},
   "source": [
    "We can see that the peak heights of the two salts are very similar whilst the position of the NaCl is left-shifted with respect to the KCl. This suggests that the Na and Cl ions are closer together than the K and Cl ions in their respective systems. This is consistent with the fact that Potassium atoms are larger than Sodium atoms and therefore would equilibrate at a greater separation. Now let's further investigate the peak height by looking at coordination numbers."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "dd02ddae",
   "metadata": {},
   "outputs": [],
   "source": [
    "data = md_project.run.GreenKuboDiffusionCoefficients(data_range=499, correlation_time=10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ae7f7690",
   "metadata": {},
   "outputs": [],
   "source": [
    "data[\"NaCl\"].data_dict[\"Na\"][\"diffusion_coefficient\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b7ce9420",
   "metadata": {},
   "outputs": [],
   "source": [
    "data[\"NaCl\"].data_dict[\"Cl\"][\"diffusion_coefficient\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f40c6cf6",
   "metadata": {},
   "outputs": [],
   "source": [
    "md_project.experiments.NaCl.species[\"Na\"].charge = 1\n",
    "md_project.experiments.NaCl.species[\"Cl\"].charge = -1\n",
    "md_project.experiments.KCl.species[\"K\"].charge = 1\n",
    "md_project.experiments.KCl.species[\"Cl\"].charge = -1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "724f413b",
   "metadata": {
    "scrolled": false
   },
   "outputs": [],
   "source": [
    "md_project.run.GreenKuboIonicConductivity(data_range=506)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "03e6086a",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "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.8.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}