Giter VIP home page Giter VIP logo

shc-python-tools's Introduction

Spectral decomposition of heat current in Python

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:

  1. K. Sääskilahti, J. Oksanen, J. Tulkki, and S. Volz, Phys. Rev. B 90, 134312 (2014)
  2. 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.

Caveats

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

Installation

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

Prerequisites

  • 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 in scripts folder and have that available in your $PATH.
  • Simulation uses the sw pair style, which is included in the MANYBODY package. See here how to include packages in your LAMMPS build.
  • Code has been tested to work with LAMMPS built on July 30th, 2021.

Contents

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-processing
  • calcFC.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:

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.

Usage

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=",",
)

Example

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/:

  1. prepares a box of atoms by writing LAMMPS atom coordinates file Si.dat,
  2. calls LAMMPS to perform the quenching procedure contained in LAMMPS input file quench.lmp, writing the LAMMPS restart file to quenched.restart,
  3. calls LAMMPS to perform the actual NEMD calculation for a-Si using simulation.lmp and quenched.restart, writing atomic velocities to simu.vels.dat, and
  4. performs the post-processing using sdhc module

Development

Format files using Black:

$ black sdhc example

Check code style with Flake8:

$ flake8 .

Installing LAMMPS on macOS (2021)

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)

shc-python-tools's People

Contributors

ksaaskil avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

shc-python-tools's Issues

TypeError: 'numpy.float64' object cannot be interpreted as an index

When I run the command python silicon_example.py, I get (TypeError: 'numpy.float64' object cannot be interpreted as an index). This should be the reason for the numpy version. The numpy version I used was 1.16.6. To solve this, I can replace the numpy version with 1.11.0. Another better option is to change line 155 in the SHCPostProc.py file to: daniellWindow = np.ones (int (Nwindow)) / Nwindow.

Postprocess and structure

Dear. Kimmo

After diligently reading your papers, I have tried to run your code.

fortunately, in the example, I run silicon_example.py and then get quench.log and simu.log.

However, After lammps work, post processing might not worked I think.

I got the lammps results but, but there is no outputs like 'frequencies_and_currents'

Do I need to run the other command to postprocessing except running ilicon_example.py ?

And when the Si.data was gnerated, the unexpected line at the last was also generated like

Si.dat

.
.
.

Atoms

1 1 17.42690 8.89127 18.37165
2 1 7.03362 18.41037 17.09778

.
.
.

3942 1 95.74134 18.19972 19.59461

3943 1 29.19755 2.47895 0.48650

.77563 <<<<<<< from this line

3941 1 15.12689 0.73260 19.88166

3942 1 60.59043 5.60391 12.09781

3943 1 193.89100 7.43478 0.45105

908 10.99834 12.11397

1 192.99451 7.16329 6.94463 <<<<<<< to the last line

this line changes randomly whenever I run repeatedly code.
For this reason, I could not go next step. just stop here

Could you also experience this problems ?

If not, could I directly read my material data to quench without make_atombox or my structure without quench.lmp ?
by trim the additional lines of Si.dat and changing name to Si2.dat, I read_data Si2.da. but It does not generate result of postprocess, just give lammps outs quench and simulation

Thanks you
Best regards

Error: Unknown pair style

Hi, I'm trying to work through your a-Si example for computing the spectral heat current. I'm pretty new to lammps but I have successfully run a number of lammps benchmarks using the python wrapper, including one that uses the pair_style command. However, when I try an run the silicon_example.py script I get

ERROR: Unknown pair style sw (../force.cpp:246)
Last command: pair_style sw

which occurs when 'quench_Si.lmp' is being executed with iterateFile(lmp,"quench_Si.lmp").

Any ideas on how to fix this issue? I'm really excite at the possibility of using your spectral heat current post processing software in my research.

Best,
Riley

zero heat current

Dear Ksaaskil
Thank you for sharing your scripts. I managed to run the Si_example. However, the heat current column in SHC.txt is zero. Is this some problem with smoothing or example is designed like this on purpose?
Kind Regards,
Movaffaq

width of interface and usage of two potentials

Dear. Kimmo

Thanks for your excellent research

I would like to change the length of the interface width to consider thick layer( > 10nm)

so, I changed the default width = 3.0 to 50.0 in the simulation.lmp

and i changed the width of xxx.py files in sdhc.

but there is some problem to do it

is it right method that I did it to calculate more thicker inteface?

How can I change the length of the width of interface. ?

and also

in the code, it looks like that only one potential looks being available.

Is it possible to use two or more potentials in complex system (e,g SiC+SiO , so there are two potentials used concurrently in single simulation for SiC.meam and SiO.tersoff )

Could you give me comments?

Thanks

How to reproduce figures in your paper and compute the MFP

Hi, I have run the codes in the example folder. However, I found the results could not match the figures in this paper. Also, I am confused about how to compute the MFP according to the post-process results. Looking forward to your response ! Thank you in advance!

Computing force constants fails

With error WARNING: Library error in lammps_scatter_atoms (../library.cpp:1227), most likely because the interface has changed.

shc run error

hi
I just start working on your codes!
thanks for sharing it but it has a little documentation.
I run the sample code as mpirun -np 4 python silicon_example.py
it ends up with the error
AttributeError: type object 'SHCPostProc' has no attribute 'SHCPostProc'

any ideas about what is going on?
thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.