<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Thermal Conductivity from EMD
1. Introduction
In this example, we use the EMD (Green-Kubo) method to calculate the lattice thermal conductivity of graphene at 300 K and zero pressure.
Importing Relevant Functions
The inputs/outputs for GPUMD are processed using the Atomic Simulation Environment (ASE) and the thermo package.
Step1:  2. Preparing the Inputs
The xyz.in  file used is the same as in density of states tutorial.
We use a Tersoff potential [Tersoff 1989] parameterized by Lindsay et al. [Lindsay 2010].
Note that the thickness of the graphene sheet is set to 3.35 $\mathring A$ according to the convention in the literature. This thickness is needed to calculate an effective 3D thermal conductivity for a 2D material.
Generate the  xyz.in file
Step2:  The first few lines of the xyz.in file are
Step3:  Plot HAC (heat current autocorrelations) & RTC (running thermal conductivity)
The hac.out output file is loaded and processed to create the following figure.
<ASSISTANT_TASK:>
Python Code:
from pylab import *
from ase.build import graphene_nanoribbon
from thermo.gpumd.data import load_hac
from thermo.gpumd.io import ase_atoms_to_gpumd
Explanation: Thermal Conductivity from EMD
1. Introduction
In this example, we use the EMD (Green-Kubo) method to calculate the lattice thermal conductivity of graphene at 300 K and zero pressure.
Importing Relevant Functions
The inputs/outputs for GPUMD are processed using the Atomic Simulation Environment (ASE) and the thermo package.
End of explanation
gnr = graphene_nanoribbon(60, 36, type='armchair', sheet=True, vacuum=3.35/2, C_C=1.44)
gnr.euler_rotate(theta=90)
l = gnr.cell.lengths()
gnr.cell = gnr.cell.new((l[0], l[2], l[1]))
l = l[2]
gnr.center()
gnr.pbc = [True, True, False]
gnr
ase_atoms_to_gpumd(gnr, M=3, cutoff=2.1)
Explanation: 2. Preparing the Inputs
The xyz.in  file used is the same as in density of states tutorial.
We use a Tersoff potential [Tersoff 1989] parameterized by Lindsay et al. [Lindsay 2010].
Note that the thickness of the graphene sheet is set to 3.35 $\mathring A$ according to the convention in the literature. This thickness is needed to calculate an effective 3D thermal conductivity for a 2D material.
Generate the  xyz.in file:
End of explanation
aw = 2
fs = 16
font = {'size'   : fs}
matplotlib.rc('font', **font)
matplotlib.rc('axes' , linewidth=aw)
def set_fig_properties(ax_list):
    tl = 8
    tw = 2
    tlm = 4
    
    for ax in ax_list:
        ax.tick_params(which='major', length=tl, width=tw)
        ax.tick_params(which='minor', length=tlm, width=tw)
        ax.tick_params(which='both', axis='both', direction='in', right=True, top=True)
Explanation: The first few lines of the xyz.in file are:
8640 3 2.1 0 0 0
1 1 0 149.649 155.52 3.35
0 1.24708 0 0 12
0 0 0.72 0 12
0 0 2.16 0 12
0 1.24708 2.88 0 12
Explanations for the first line:
The first number states that the number of particles is 8640.
The second number in this line, 3, is good for graphene described by the Tersoff potential because no atom can have more than 3 neighbor atoms at room temperature. Making this number larger only results in more memory usage. If this number is not large enough, GPUMD will give an error message and exit.
The next number, 2.1, means that the initial cutoff distance for the neighbor list construction is 2.1 A. Here, we only need to consider the first nearest neighbors. Any number larger than the first nearest neighbor distance and smaller than the second nearest neighbor distance is OK here. Note that we will also not update the neighbor list. There is no such need in this problem. 
The remaining three zeros in the first line mean:
the box is orthogonal;
the initial velocities are not contained in this file;
there are no grouping methods defined here.
Explanations for the second line:
The numbers 1 1 0 mean that the x and y (in-plane) directions are periodic and the z direction is open (free).
The remaining three numbers are the box lengths in the three directions. The box length in a free direction is chosen based on some convention. This number will only affect the system volume.
Starting from the third line, the numbers in the first column are all 0 here, which means that all the atoms are of type 0 (single atom-type system). The next three columns are the initial coordinates of the atoms. The last column gives the masses of the atoms. Here, we consider isotopically pure C-12 crystal, but this Jupyter notebook will generate an xyz.in file using the average of the various isotopes of C. In some applications, one can consider mass disorder in a flexible way.
The <code>run.in</code> file:
The <code>run.in</code> input file is given below:<br>
```
potential    potentials/tersoff/Graphene_Lindsay_2010_modified.txt
velocity     300
equilibration
ensemble     npt_ber 300 300 100 0 0 0 53.4059 53.4059 53.4059 2000
neighbor     off # we know it is safe to turn off neighbor list update
time_step    1
dump_thermo  1000
run          1000000
production
ensemble     nve
neighbor     off # we know it is safe to turn off neighbor list update
compute_hac  20 50000 10
run          10000000
```
- The first line uses the potential keyword to define the potential to be used, which is specified in the file Graphene_Lindsay_2010_modified.txt.
The second line uses the velocity keyword and sets the velocities to be initialized with a temperature of 300 K. 
There are two runs.
The first run serves as the equilibration stage, where the NPT ensemble (the Berendsen barostat) is used. The temperature is 300 K and the pressures are zero in all the directions. The coupling constants are 100 and 2000 time steps for the thermostat and the barostat (The elastic constant, or inverse compressibility parameter needed in the barostat is estimated to be 53.4059 GPa; this only needs to be correct up to the order of magnitude.), respectively. The time_step for integration is 1 fs. There are $10^6$ steps (1 ns) for this run and the thermodynamic quantities will be output every 1000 steps.
The second run is for production. Here, the NVE ensemble is used. The line with the compute_hac keyword means that heat currents will be recorded every 20 steps (20 fs), 50000 HAC data (the maximum correlation time is then about 1 ns) will be calculated, and the HAC are averaged for every 10 data points before written out. The production time is 10 ns ($10^7$ steps), which is 10 times as long as the maximum correlation time. This is a reasonable choice.
3. Results and Discussion
Computation Time
The results below are from three independent runs, which took about two hours in total using a Tesla K40 card.
Figure Properties
End of explanation
hac = load_hac([50000]*3, [10]*3)
print(hac.keys())
print(hac['run0'].keys())
t = hac['run0']['t']
hac_ave_i = np.zeros(hac['run0']['jxijx'].shape[0])
hac_ave_o = np.zeros_like(hac_ave_i)
ki_ave, ko_ave = np.zeros_like(hac_ave_i), np.zeros_like(hac_ave_o)
for runkey in hac.keys():
    hac_ave_i += hac[runkey]['jxijx']+hac[runkey]['jyijy']
    hac_ave_o += hac[runkey]['jxojx']+hac[runkey]['jyojy']
    ki_ave += (hac[runkey]['kxi']+hac[runkey]['kyi'])
    ko_ave += (hac[runkey]['kxo']+hac[runkey]['kyo'])
hac_ave_i /= hac_ave_i.max()
hac_ave_o /= hac_ave_o.max()
ki_ave /= 6.
ko_ave /= 6.
figure(figsize=(12,10))
subplot(2,2,1)
set_fig_properties([gca()])
loglog(t, hac_ave_i, color='C3')
loglog(t, hac_ave_o, color='C0')
xlim([1e-1, 1e3])
ylim([1e-4, 1])
xlabel('Correlation Time (ps)')
ylabel('Normalized HAC')
title('(a)')
subplot(2,2,2)
set_fig_properties([gca()])
for runkey in hac.keys():
    plot(hac[runkey]['t'], (hac[runkey]['kxi']+hac[runkey]['kyi'])/2, color='C7',alpha=0.5)
plot(t, ki_ave, color='C3', linewidth=3)
xlim([0, 1000])
gca().set_xticks(range(0,1001,200))
ylim([0, 1500])
gca().set_yticks(range(0,1501,500))
xlabel('Correlation Time (ps)')
ylabel(r'$\kappa^{in}$ (W/m/K)')
title('(b)')
subplot(2,2,3)
set_fig_properties([gca()])
for runkey in hac.keys():
    plot(hac[runkey]['t'], (hac[runkey]['kxo']+hac[runkey]['kyo'])/2, color='C7',alpha=0.5)
plot(t, ko_ave, color='C0', linewidth=3)
xlim([0, 1000])
gca().set_xticks(range(0,1001,200))
ylim([0, 1500])
gca().set_yticks(range(0,4001,1000))
xlabel('Correlation Time (ps)')
ylabel(r'$\kappa^{out}$ (W/m/K)')
title('(c)')
subplot(2,2,4)
set_fig_properties([gca()])
plot(t, ko_ave, color='C0', linewidth=3)
plot(t, ki_ave, color='C3', linewidth=3)
plot(t, ki_ave + ko_ave, color='k', linewidth=3)
xlim([0, 1000])
gca().set_xticks(range(0,1001,200))
ylim([0, 1500])
gca().set_yticks(range(0,4001,1000))
xlabel('Correlation Time (ps)')
ylabel(r'$\kappa$ (W/m/K)')
title('(d)')
tight_layout()
show()
Explanation: Plot HAC (heat current autocorrelations) & RTC (running thermal conductivity)
The hac.out output file is loaded and processed to create the following figure.
End of explanation
<END_TASK>