Molten Salt Comparison

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.

This tutorial assumes that you are already familiar with the general MDSuite interface and have looked over the previous tutorial.

[1]:
import mdsuite as mds
import matplotlib.pyplot as plt
from zinchub import DataHub
import tensorflow as tf
import numpy as np
from scipy.integrate import cumtrapz
2022-07-27 15:51:56.424715: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libcudart.so.11.0'; dlerror: libcudart.so.11.0: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH: /opt/slurm/lib:/opt/slurm/lib:
2022-07-27 15:51:56.424771: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
2022-07-27 15:52:10.977679: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libcublas.so.11'; dlerror: libcublas.so.11: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH: /opt/slurm/lib:/opt/slurm/lib:
2022-07-27 15:52:10.978019: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libcublasLt.so.11'; dlerror: libcublasLt.so.11: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH: /opt/slurm/lib:/opt/slurm/lib:
2022-07-27 15:52:10.978302: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libcufft.so.10'; dlerror: libcufft.so.10: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH: /opt/slurm/lib:/opt/slurm/lib:
2022-07-27 15:52:10.978584: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libcurand.so.10'; dlerror: libcurand.so.10: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH: /opt/slurm/lib:/opt/slurm/lib:
2022-07-27 15:52:10.978862: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libcusolver.so.11'; dlerror: libcusolver.so.11: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH: /opt/slurm/lib:/opt/slurm/lib:
2022-07-27 15:52:10.979221: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libcusparse.so.11'; dlerror: libcusparse.so.11: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH: /opt/slurm/lib:/opt/slurm/lib:
2022-07-27 15:52:10.979509: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libcudnn.so.8'; dlerror: libcudnn.so.8: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH: /opt/slurm/lib:/opt/slurm/lib:
2022-07-27 15:52:10.979543: W tensorflow/core/common_runtime/gpu/gpu_device.cc:1850] Cannot dlopen some GPU libraries. Please make sure the missing libraries mentioned above are installed properly if you would like to use GPU. Follow the guide at https://www.tensorflow.org/install/gpu for how to download and setup the required libraries for your platform.
Skipping registering GPU devices...

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).

[2]:
NaCl_file = DataHub(url="https://github.com/zincware/DataHub/tree/main/NaCl_rnd_md", tag="v0.1.0")
KCl_file = DataHub(url="https://github.com/zincware/DataHub/tree/main/KCl_rnd_md", tag="v0.1.0")

KCl_data = KCl_file.get_file('.')[0]
NaCl_data = NaCl_file.get_file('.')[0]
[3]:
md_project = mds.Project(name="Molten_Salt_Comparison", storage_path='.')
2022-07-27 15:52:23,051 - INFO: Loading the class state
2022-07-27 15:52:23,131 - INFO: Available experiments are: [1: NaCl, 2: KCl]

Again, depending on your computer, adding the data may take up between 25s to 1m total.

[4]:
NaCl_experiment = md_project.add_experiment(
    name="NaCl", timestep=0.002, units='metal', temperature=1200.0, simulation_data=NaCl_data
)
KCl_experiment = md_project.add_experiment(
    name="KCl", timestep=0.002, units='metal', temperature=1200.0, simulation_data=KCl_data
)
2022-07-27 15:52:23,204 - INFO: This experiment already exists
2022-07-27 15:52:23,343 - INFO: This experiment already exists

Structural Information

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.

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.

[5]:
RDF_Data = md_project.run.RadialDistributionFunction(number_of_configurations=500, cutoff=15.0)
Loading BokehJS ...
Loading BokehJS ...
[6]:
NaCl_experiment.run.CoordinationNumbers(
    rdf_data=RDF_Data['NaCl'], savgol_window_length=111, savgol_order=9, number_of_shells=3
)
Loading BokehJS ...
[6]:
Exp1_Coordination_Numbers_3
[7]:
KCl_experiment.run.CoordinationNumbers(
    rdf_data=RDF_Data['KCl'], savgol_window_length=111, savgol_order=7, number_of_shells=2
)
Loading BokehJS ...
[7]:
Exp2_Coordination_Numbers_4
[8]:
KCl_experiment.run.PotentialOfMeanForce(
    rdf_data=RDF_Data['KCl'], savgol_window_length=111, savgol_order=7, number_of_shells=2
)
Loading BokehJS ...
[8]:
Exp2_Potential_of_Mean_Force_5
[9]:
radii = RDF_Data['NaCl']['Na_Cl']['x']
NaCl_rdf = RDF_Data['NaCl']['Na_Cl']['y']
KCl_rdf = RDF_Data['KCl']['Cl_K']['y']
[10]:
plt.plot(radii, NaCl_rdf, '--', label='NaCl')
plt.plot(radii, KCl_rdf, '-.', label='KCl')
plt.legend()
plt.xlabel("Radius / nm")
plt.ylabel("g(r)")
plt.show()
../_images/_notebooks_Molten_salt_Comparison_13_0.png

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.

[11]:
data = md_project.run.GreenKuboDiffusionCoefficients(data_range=499, correlation_time=10)
2022-07-27 15:52:27.070656: I tensorflow/core/platform/cpu_feature_guard.cc:151] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations:  AVX2 AVX512F FMA
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
Na: 100%|███████████████████████████████| 1/1 [00:35<00:00, 35.29s/it]
Cl: 100%|███████████████████████████████| 1/1 [00:31<00:00, 31.22s/it]
Loading BokehJS ...
K: 100%|████████████████████████████████| 1/1 [00:31<00:00, 31.94s/it]
Cl: 100%|███████████████████████████████| 1/1 [00:31<00:00, 31.09s/it]
Loading BokehJS ...
[12]:
data["NaCl"].data_dict["Na"]["diffusion_coefficient"]
[12]:
[1.1699497443817538e-08]
[13]:
data["NaCl"].data_dict["Cl"]["diffusion_coefficient"]
[13]:
[9.289197074221018e-09]
[14]:
md_project.experiments.NaCl.species["Na"].charge = 1
md_project.experiments.NaCl.species["Cl"].charge = -1
md_project.experiments.KCl.species["K"].charge = 1
md_project.experiments.KCl.species["Cl"].charge = -1
[15]:
md_project.run.GreenKuboIonicConductivity(data_range=506)
Applying transformation 'Ionic_Current': 100%|█| 1/1 [00:00<00:00,  2.
100%|███████████████████████████████████| 1/1 [00:08<00:00,  8.25s/it]
Loading BokehJS ...
Applying transformation 'Ionic_Current': 100%|█| 1/1 [00:00<00:00,  2.
100%|███████████████████████████████████| 1/1 [00:08<00:00,  8.06s/it]
Loading BokehJS ...
[15]:
{'NaCl': Exp1_Green_Kubo_Ionic_Conductivity_8,
 'KCl': Exp2_Green_Kubo_Ionic_Conductivity_9}
[ ]: