Finding the MSD uncertainties from a VASP file#

Using kinisi to obtain the mean-squared displacement and uncertainty in a VASP Xdatcar type file is straightforward and involves using the DiffusionAnalyzer class.

[1]:
import numpy as np
from kinisi.analyze import DiffusionAnalyzer
np.random.seed(1)

There the params dictionary describes details about the simulation, and are fully documented in the parser module. The 'specie' is the atomic/ionic species that you want to calculate the MSD for, the 'time_step' is the simulation timestep in your molecular dynamics, and the 'step_skip' is the frequency which with the data was written in your simulation trajectory.

[2]:
params = {'specie': 'Li',
          'time_step': 2.0,
          'step_skip': 50}

Therefore, for this example, we have a simulation that had a timestep of 2 femtoseconds (note the FAQs about units) but we only stored the trajectory information every 50 steps and we want to investigate only the lithium motion.

[3]:
msd = DiffusionAnalyzer.from_file('example_XDATCAR.gz', parser_params=params)
Reading Trajectory: 0%| | 0/140 [00:00<?, ?it/s]

</pre>

Reading Trajectory: 0%| | 0/140 [00:00<?, ?it/s]

end{sphinxVerbatim}

Reading Trajectory: 0%| | 0/140 [00:00<?, ?it/s]

Reading Trajectory: 100%|██████████| 140/140 [00:00&lt;00:00, 4336.29it/s]

</pre>

Reading Trajectory: 100%|██████████| 140/140 [00:00<00:00, 4336.29it/s]

end{sphinxVerbatim}

Reading Trajectory: 100%|██████████| 140/140 [00:00<00:00, 4336.29it/s]


Getting Displacements: 0%| | 0/100 [00:00&lt;?, ?it/s]

</pre>

Getting Displacements: 0%| | 0/100 [00:00<?, ?it/s]

end{sphinxVerbatim}

Getting Displacements: 0%| | 0/100 [00:00<?, ?it/s]

Getting Displacements: 100%|██████████| 100/100 [00:00&lt;00:00, 17782.27it/s]

</pre>

Getting Displacements: 100%|██████████| 100/100 [00:00<00:00, 17782.27it/s]

end{sphinxVerbatim}

Getting Displacements: 100%|██████████| 100/100 [00:00<00:00, 17782.27it/s]


Finding Means and Variances: 0%| | 0/100 [00:00&lt;?, ?it/s]

</pre>

Finding Means and Variances: 0%| | 0/100 [00:00<?, ?it/s]

end{sphinxVerbatim}

Finding Means and Variances: 0%| | 0/100 [00:00<?, ?it/s]

Finding Means and Variances: 18%|█▊ | 18/100 [00:00&lt;00:00, 171.81it/s]

</pre>

Finding Means and Variances: 18%|█▊ | 18/100 [00:00<00:00, 171.81it/s]

end{sphinxVerbatim}

Finding Means and Variances: 18%|█▊ | 18/100 [00:00<00:00, 171.81it/s]

Finding Means and Variances: 36%|███▌ | 36/100 [00:00&lt;00:00, 173.70it/s]

</pre>

Finding Means and Variances: 36%|███▌ | 36/100 [00:00<00:00, 173.70it/s]

end{sphinxVerbatim}

Finding Means and Variances: 36%|███▌ | 36/100 [00:00<00:00, 173.70it/s]

Finding Means and Variances: 55%|█████▌ | 55/100 [00:00&lt;00:00, 179.43it/s]

</pre>

Finding Means and Variances: 55%|█████▌ | 55/100 [00:00<00:00, 179.43it/s]

end{sphinxVerbatim}

Finding Means and Variances: 55%|█████▌ | 55/100 [00:00<00:00, 179.43it/s]

Finding Means and Variances: 76%|███████▌ | 76/100 [00:00&lt;00:00, 189.66it/s]

</pre>

Finding Means and Variances: 76%|███████▌ | 76/100 [00:00<00:00, 189.66it/s]

end{sphinxVerbatim}

Finding Means and Variances: 76%|███████▌ | 76/100 [00:00<00:00, 189.66it/s]

Finding Means and Variances: 100%|██████████| 100/100 [00:00&lt;00:00, 203.63it/s]

</pre>

Finding Means and Variances: 100%|██████████| 100/100 [00:00<00:00, 203.63it/s]

end{sphinxVerbatim}

Finding Means and Variances: 100%|██████████| 100/100 [00:00<00:00, 203.63it/s]


The DiffusionAnalyzer will perform the bootstrapping process to obtain the displacements and uncertainties (this is detailed in the methodology. To find out how to determine the diffusion coefficient with DiffusionAnalyzer continue here.

Then the MSD (msd) as a function of timestep (dt) can be plotted.

[4]:
import matplotlib.pyplot as plt
[5]:
plt.errorbar(msd.dt, msd.msd, msd.msd_std)
plt.ylabel('MSD/Å$^2$')
plt.xlabel('$\Delta t$/ps')
plt.show()
_images/vasp_msd_8_0.png