.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/plot_rdf.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_plot_rdf.py: .. _rdf: Calculating the radial distribution function ******************************************** In this tutorial we will learn how to analyse (ab-initio) molecular dynamics trajectories. We will use the tool MDAnalysis to read our simulation data files and calculate the radial distribution function. `Wikipedia page on RDF: `_ `MDAnalysis documentation on RDF: `_ We first import our python modules .. GENERATED FROM PYTHON SOURCE LINES 17-25 .. code-block:: Python import numpy as np import matplotlib.pyplot as plt from pathlib import Path import MDAnalysis as mda from MDAnalysis.analysis.rdf import InterRDF .. GENERATED FROM PYTHON SOURCE LINES 26-27 Then we define our project path. Replace the path with your own project path .. GENERATED FROM PYTHON SOURCE LINES 27-30 .. code-block:: Python PROJECT_PATH=Path("../../../solutions/") .. GENERATED FROM PYTHON SOURCE LINES 31-32 Next, we load our simulation output. .. GENERATED FROM PYTHON SOURCE LINES 32-35 .. code-block:: Python universe = mda.Universe(PROJECT_PATH / "dft"/ "Argon_Simulation-pos-1.xyz") .. GENERATED FROM PYTHON SOURCE LINES 36-38 # The Universe object contains the atomic positions for each timestep. # Note that the xyz file does not contain any information on the dimensions .. GENERATED FROM PYTHON SOURCE LINES 38-41 .. code-block:: Python print(f"dimensions from xyz file {universe.dimensions}") .. rst-class:: sphx-glr-script-out .. code-block:: none dimensions from xyz file None .. GENERATED FROM PYTHON SOURCE LINES 42-43 So we must set the dimensions ourself to .. GENERATED FROM PYTHON SOURCE LINES 43-47 .. code-block:: Python box_l = 17.0742 universe.dimensions = [box_l, box_l, box_l, 90, 90, 90] .. GENERATED FROM PYTHON SOURCE LINES 48-49 Let's also check how many frames we've loaded with .. GENERATED FROM PYTHON SOURCE LINES 49-52 .. code-block:: Python print(f"loaded {len(universe.trajectory)} frames") .. rst-class:: sphx-glr-script-out .. code-block:: none loaded 10001 frames .. GENERATED FROM PYTHON SOURCE LINES 53-54 We now want to run an radial distribution analysis using InterRDF .. GENERATED FROM PYTHON SOURCE LINES 54-60 .. code-block:: Python rdf = InterRDF(universe.atoms, universe.atoms, n_bins = 100, range = (1.0, box_l / 2) ) .. GENERATED FROM PYTHON SOURCE LINES 61-62 We then run the analysis with .. GENERATED FROM PYTHON SOURCE LINES 62-65 .. code-block:: Python rdf.run() .. rst-class:: sphx-glr-script-out .. code-block:: none /fibus/fs3/0b/ckf7015/.local/lib/python3.11/site-packages/MDAnalysis/analysis/base.py:522: UserWarning: Reader has no dt information, set to 1.0 ps self.times[idx] = ts.time .. GENERATED FROM PYTHON SOURCE LINES 66-67 Next, we plot our results .. GENERATED FROM PYTHON SOURCE LINES 67-72 .. code-block:: Python plt.plot(rdf.results.bins, rdf.results.rdf) plt.xlabel("$r$ in A") plt.ylabel("g(r)") .. image-sg:: /auto_examples/images/sphx_glr_plot_rdf_001.png :alt: plot rdf :srcset: /auto_examples/images/sphx_glr_plot_rdf_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none Text(42.597222222222214, 0.5, 'g(r)') .. GENERATED FROM PYTHON SOURCE LINES 73-74 and save our figure .. GENERATED FROM PYTHON SOURCE LINES 74-77 .. code-block:: Python plt.savefig(PROJECT_PATH / "lammps" / "rdf.png", dpi=300) .. image-sg:: /auto_examples/images/sphx_glr_plot_rdf_002.png :alt: plot rdf :srcset: /auto_examples/images/sphx_glr_plot_rdf_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 7.606 seconds) .. _sphx_glr_download_auto_examples_plot_rdf.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_rdf.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_rdf.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_rdf.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_