This repository contains Python code for calculating the spectral decomposition of heat current from the data produced by non-equilibrium molecular dynamics simulation with LAMMPS software. The relevant equations were published in:
- K. Sääskilahti, J. Oksanen, J. Tulkki, and S. Volz, Phys. Rev. B 90, 134312 (2014)
- K. Sääskilahti, J. Oksanen, S. Volz, and J. Tulkki, Phys. Rev. B 91, 115426 (2015)
These codes are meant to help anyone interested in implementing the spectral heat current decomposition calculations for their own applications. If you want to use the codes for research purposes, please cite the above-mentioned publications and let me know.
- This is research code and not unit-tested
- The logic how atom IDs are tracked throughtout the process is fragile. For example, the interface atoms are computed independently both when starting the LAMMPS simulation (to know which velocities to dump) and when calculating force constants afterwards. Currently these atom IDs must match.
$ git clone [email protected]:ksaaskil/shc-python-tools.git
$ cd shc-python-tools
# If you need development dependencies:
$ pip install -e '.[dev]'
# If not:
$ pip install -e .
- Using LAMMPS from Python requires that you have built LAMMPS as a dynamically shared library as instructed in the LAMMPS manual
- You need to build
compactify_vels.cpp
inscripts
folder and have that available in your$PATH
. - Simulation uses the
sw
pair style, which is included in theMANYBODY
package. See here how to include packages in your LAMMPS build. - Code has been tested to work with LAMMPS built on July 30th, 2021.
The actual library for computing spectral heat current distributions is found
in the sdhc
folder. It contains:
SHCPostProc.py
: Python class for performing the post-processingcalcFC.py
: Class for calculating the force constants (note that the definition of the "left" and "right" interfaces must be the same in the NEMD simulation and in the calculation of the force constants)
Additionally, the scripts
folder contains:
compactify_vels.cpp
: C++ script for formatting the LAMMPS's dump velocity file into a more easily readable column file. The program can be compiled by runningmake
inscripts
folder (ifg++
is found, otherwise modifyMakefile
such that appropriate compiler is defined in variableCC
). Example input and output for the script can be found intests/resources/small.simu.vels.dat
andtests/resources/small.simu.vels.dat.compact
.
In addition, the root directory contains the script calcSHC.py demonstrating how the post-processing class is used and how the data could be saved to file.
import numpy as np
from sdhc import SHCPostProc
# See the accepted arguments in source code
postprocessor = SHCPostProc(*args, **kwargs)
postprocessor.postProcess()
# Angular frequencies
oms_fft = postprocessor.oms_fft
# Smoothened spectral decomposition of heat current
SHC_smooth = postprocessor.SHC_smooth
# Save frequencies and smoothened spectral heat currents as NumPy files
np.save('angular_frequencies.npy', oms_fft)
np.save('heat_currents.npy', SHC_smooth)
# Save the frequencies and heat currents to CSV file
np.savetxt(
folder.joinpath("SHC.csv"),
np.column_stack((oms_fft, SHC_smooth)),
delimiter=",",
)
Folder example contains a self-contained example for calculating the spectral heat current flowing across a slab of amorphous Si. The script to be run is called silicon_example.py
. Execute as follows:
$ cd example
$ python silicon_example.py
The script performs the following steps and writes all output by default to folder lammps-output/
:
- prepares a box of atoms by writing LAMMPS atom coordinates file
Si.dat
, - calls LAMMPS to perform the quenching procedure contained in LAMMPS input file
quench.lmp
, writing the LAMMPS restart file toquenched.restart
, - calls LAMMPS to perform the actual NEMD calculation for a-Si using
simulation.lmp
andquenched.restart
, writing atomic velocities tosimu.vels.dat
, and - performs the post-processing using
sdhc
module
Format files using Black:
$ black sdhc example
Check code style with Flake8:
$ flake8 .
Download the tarball from LAMMPS downloads
$ mkdir ~/lammps
$ cd ~/lammps
$ wget https://download.lammps.org/tars/lammps.tar.gz
$ tar -xvf lammps.tar.gz
$ cd lammps-30Jul2021
Edit the target Makefile
such as src/MAKE/Makefile.serial
to use clang++
and C++11
:
# Makefile.serial
CC = clang++ -std=c++11 -stdlib=libc++
LINK = clang++
Build as shared library and include any required packages:
$ cd src
$ make yes-MANYBODY
$ make mode=shared serial
Test the executable:
$ ./lmp_serial -i ../examples/min/in.min
Make the executable available in your PATH
:
# Assuming you have ~/bin in your PATH
$ ln -sf ${LAMMPS_PATH}/src/lmp_serial ~/bin/lmp_serial
Add LAMMPS to LD_LIBRARY_PATH
, DYLD_LIBRARY_PATH
and PYTHONPATH
:
# .bash_profile
export LAMMPS_PATH=${HOME}/lammps/lammps-30Jul2021
export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:${LAMMPS_PATH}/src
export DYLD_LIBRARY_PATH=${DYLD_LIBRARY_PATH}:${LAMMPS_PATH}/src
export PYTHONPATH=${PYTHONPATH}:${LAMMPS_PATH}/python
export PATH=$PATH:${HOME}/git/shc-python-tools/scripts
For some reason, setting library paths didn't work as lammps
Python package was searching for the liblammps.so
file in the folder of the Python package. So I added a soft link:
$ ln -sf ${LAMMPS_PATH}/src/liblammps.so ${LAMMPS_PATH}/python/lammps/liblammps.so
I also needed to update python/core.py
as follows:
if platform.system() == "Darwin":
# lib_ext = ".dylib"
lib_ext = ".so"
Now test running LAMMPS from Python:
>>> from lammps import lammps
>>> lmp = lammps()
LAMMPS (30 Jul 2021)