{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Creating Atoms and Accessing Properties" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This tutorial explains how to create atoms and access their relevant properties. This module allows for various isotopes to be specified as well as the natural abundances. To conclude this tutorial there is a short example of creating a water molecule with deuterium instead of hydrogen." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# imports used for this tutorial\n", "from MDMC.MD.structures import Atom\n", "from MDMC.trajectory_analysis.observables.fqt import calc_incoherent_scatt_length\n", "from MDMC.MD import *" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now that the Atom class has been imported, we can create an atom. This can be done to create an atom which represents the natural abundance of the element, or a specific isotope." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Creating an oxygen atom using MDMC Atom class\n", "\n", "# Standard chemical symbol will give natural abundance\n", "oxygen_na = Atom('O')\n", "\n", "# Chemical symbol followed by the mass number will give the specific isotope\n", "oxygen_16 = Atom('O[16]')\n", "\n", "# Example for specifying different isotope\n", "oxygen_17 = Atom('O[17]')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now that the atoms have been created, we can start accessing their associated properties. MDMC uses the Python package `periodictable` for a database of atomic properties." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Accessing general properties\n", "print(\"atomic mass: \", oxygen_na.mass)\n", "print(\"atomic number: \", oxygen_na.element.number)\n", "\n", "# Showing the atomic mass for the different oxygen atoms\n", "print(\"O[16] mass: \", oxygen_16.mass)\n", "print(\"O[17] mass: \", oxygen_17.mass)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "As well as basic properties like mass and atomic number, we can access scattering-specific properties like scattering lengths and cross-sections." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Accessing scattering specific properties, like scattering lengths and cross sections\n", "print(\"O[16] coherent cross section: \", oxygen_16.element.neutron.coherent)\n", "print(\"O[16] incoherent cross section \", oxygen_16.element.neutron.incoherent)\n", "print(\"O[16] coherent scattering length: \", oxygen_16.element.neutron.b_c)\n", "print(\"O[16] incoherent scattering length: \", oxygen_16.element.neutron.b_c_i)\n", "\n", "print(\" \") # for better formatting\n", "\n", "# Many incoherent scattering lengths are stored as 0, but with non-zero cross sections.\n", "# The lengths can be approximated in MDMC using 'calc_incoherent_scatt_length'.status\n", "nitrogen_na = Atom('N')\n", "print(\"Nitrogen incoherent cross section \", nitrogen_na.element.neutron.incoherent)\n", "print(\"Nitrogen (periodictable) incoherent scattering length: \", nitrogen_na.element.neutron.b_c_i)\n", "print(\"Nitrogen (MDMC) incoherent scattering length: \", calc_incoherent_scatt_length('N'))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "For further information about key attributes of a periodictable object, we can use help()." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "help(oxygen_na.element.neutron)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now as a final example of this functionality, let's create a molecule. We will create a heavy water molecule, using deuterium in the place of hydrogen." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Conveniently, deuterium can be specified directly through this artificial chemical symbol 'D' \n", "# It can also be specified using 'H[2]' as expected.\n", "\n", "D1 = Atom('D') # or Atom(\"H[2]\")\n", "D2 = Atom('D', position=(0., 1.63298, 0.))\n", "O = Atom('O', position=(0., 0.81649, 0.57736))\n", "\n", "D_coulombic = Coulombic(atoms=[D1, D2], cutoff=10.)\n", "O_coulombic = Coulombic(atoms=O, cutoff=10.)\n", "\n", "heavy_water_mol = Molecule(position=(0, 0, 0),\n", " velocity=(0, 0, 0),\n", " atoms=[D1, D2, O],\n", " interactions=[Bond((D1, O), (D2, O), constrained=True),\n", " BondAngle(D1, O, D2, constrained=True)],\n", " name='heavy_water')\n", "\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "For a more in depth explanation of molecule and bond creation please see the MDMC tutorial on [creating atomic configurations](https://mdmcproject.org/how-to/use-MDMC/notebooks/creating-atomic-configurations.html).." ] } ], "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.11.2" } }, "nbformat": 4, "nbformat_minor": 2 }