-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathsilicon_example.py
More file actions
164 lines (127 loc) · 4.74 KB
/
Copy pathsilicon_example.py
File metadata and controls
164 lines (127 loc) · 4.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
from pathlib import Path
import os
import numpy as np
# from randomAtomBox import atombox
from sdhc import SHCPostProc
from sdhc.utils import make_atombox
from lammps import lammps
# Speed-up for small machines, use '1' for high-quality data
SCALE = 10
QUENCH_STEPS_HEATING = 5e5 / SCALE
QUENCH_STEPS_QUENCH = 1e6 / SCALE
QUENCH_STEPS_COOLED = 5e5 / SCALE
SIMU_STEPS_EQUIL = 5e5 / SCALE
SIMU_STEPS_STEADY = 1e6 / SCALE
SIMU_STEPS_SIMULATION = 1e6 / SCALE
SYSTEM_LENGTH = 200
SYSTEM_WIDTH = 20
QUENCH_LMP_PATH = Path(__file__).parent.joinpath("quench.lmp")
SIMULATION_LMP_PATH = Path(__file__).parent.joinpath("simulation.lmp")
def iterateFile(lmp: lammps, filename: Path):
"""
Do the same as lmp.file(filename) but allow the script to be
continued after quit.
"""
with filename.open("r") as f:
for line in f:
print(line)
if "quit" in line and line[0] != "#":
return
else:
lmp.command(line)
return
def write_initial_positions_file(filename: Path):
mass = 28.0
rho = 2.291 # Density in g/cm^3
n_atoms = int(
np.round(
rho
* 1e-3
/ 1e-6
* SYSTEM_LENGTH
* SYSTEM_WIDTH ** 2
* 1e-30
/ (mass * 1.66e-27)
)
)
make_atombox(
length=SYSTEM_LENGTH,
width=SYSTEM_WIDTH,
n_atoms=n_atoms,
atom_mass=mass,
output=filename,
)
def do_quench(folder: Path, lammps_data_file: Path, restart_file: Path):
lmp = lammps()
file_prefix = os.path.join(folder, "quench")
lmp.command(f"variable filename string '{file_prefix}'")
lmp.command(f"variable datafile string '{lammps_data_file}'")
lmp.command(f"variable restartfile string '{restart_file}'")
lmp.command(f"variable steps_heating equal {QUENCH_STEPS_HEATING}")
lmp.command(f"variable steps_quench equal {QUENCH_STEPS_QUENCH}")
lmp.command(f"variable steps_cooled equal {QUENCH_STEPS_COOLED}")
iterateFile(lmp, QUENCH_LMP_PATH)
lmp.close()
def do_simulation(folder: Path, restart_file: Path):
file_prefix = folder.joinpath("simu")
lmp = lammps()
lmp.command(f"variable filename string '{file_prefix}'")
lmp.command(f"variable restartfile string '{restart_file}'")
lmp.command(f"variable steps_equil equal {SIMU_STEPS_EQUIL}")
lmp.command(f"variable steps_steady equal {SIMU_STEPS_STEADY}")
lmp.command(f"variable steps_simu equal {SIMU_STEPS_SIMULATION}")
iterateFile(lmp, SIMULATION_LMP_PATH)
lmp.close()
def compute_sdhc(folder: Path, restart_file: Path):
compact_velocities_file = folder.joinpath("vels.dat.compact")
atomic_velocities_file = folder.joinpath("simu.vels.dat")
frequency_window_width = 0.5e12
backup_prefix = folder.joinpath("backup")
force_constant_file_prefix = folder.joinpath("force_constants")
unit_scaling_factor = 1.602e-19 / 1e-20 * 1e4
md_timestep = 2.5e-15
postprocessor = SHCPostProc(
compactVelocityFile=str(compact_velocities_file),
KijFilePrefix=str(force_constant_file_prefix),
dt_md=md_timestep,
scaleFactor=unit_scaling_factor,
LAMMPSDumpFile=str(atomic_velocities_file),
widthWin=frequency_window_width,
NChunks=20,
chunkSize=50000,
backupPrefix=str(backup_prefix),
LAMMPSRestartFile=str(restart_file),
reCalcVels=True,
reCalcFC=True,
)
postprocessor.postProcess()
return postprocessor
def main(folder: Path = Path("lammps-output")):
"""
Run SDHC example for a-Si.
folder: Path to folder where to store output. For example, `090419a`
"""
folder.mkdir(exist_ok=True)
atom_positions_file = folder.joinpath("Si.dat")
write_initial_positions_file(atom_positions_file)
# Do quenching, writing the LAMMPS restart file to `quenched.restart`
restart_file = folder.joinpath("quenched.restart")
do_quench(folder, atom_positions_file, restart_file)
# Gather data from simulation.
# Atomic velocities are written to file `simu.vels.dat`
do_simulation(folder, restart_file)
# Calculate force constants and compute the spectral heat current
postprocessor = compute_sdhc(folder, restart_file)
# Save angular frequencies and heat currents into numpy files
np.save(folder.joinpath("oms.npy"), postprocessor.oms_fft)
np.save(folder.joinpath("SHC.npy"), postprocessor.SHC_smooth)
# Save frequencies and heat currents to CSV file
np.savetxt(
folder.joinpath("SHC.csv"),
np.column_stack((postprocessor.oms_fft, postprocessor.SHC_smooth)),
delimiter=",",
)
# Read back using e.g. pandas
# df = pd.read_csv(CSV_FILE, names=["omega", "sdhc"])
if __name__ == "__main__":
main()