Inputs not yet validated. Runtimes are estimates. The README describes what to check in the outputs.
What you will learn
- How to run a melt–quench protocol
- How cooling rate changes the solid
- How to fit Young’s modulus from the elastic region
Set up
Set up LAMMPS. Download the potential files below and keep them next to the input.
python -m pip install numpy matplotlibFiles for this tutorial:
in.solder.lmp— Melt–quench–tension inputanalyze.py— Stress–strain + modulus fitREADME.md— Potential and notes
How it works
Get the potential
The README names a documented Sn MEAM from the NIST repository. The paper’s exact parameter set was not available as a download.
Melt and quench
Heat above the melting point, hold, then cool at the chosen rate.
Stretch and fit
Uniaxial tension; Young’s modulus is fitted from the first 2% of strain.
Run it
lmp -in in.solder.lmp -var cool 10 -var out tension_10.txt
lmp -in in.solder.lmp -var cool 100 -var out tension_100.txt
python analyze.pyHow this differs from the paper
The paper compared pure Sn, Sn–Ag and SAC305 at 2.5, 10, 50 and 100 K/ps with a MEAM potential for the alloys. It found SAC305 strength falling from 6.91 to 6.16 GPa as cooling sped up. This tutorial runs pure Sn with a substitute potential.
Full source
in.solder.lmp (41 lines)
units metal
atom_style atomic
boundary p p p
variable T index 300
variable rate index 0.01
variable seed index 87287
variable cool index 10
variable out index tension_10.txt
timestep 0.001
# A compact FCC starting structure is melted before quenching.
lattice fcc 5.8
region box block 0 8 0 8 0 8
create_box 1 box
create_atoms 1 box
mass 1 118.710
pair_style meam
pair_coeff * * library.meam Sn Sn.meam Sn
neighbor 2 bin
minimize 1e-7 1e-7 200 2000
velocity all create 1200 ${seed} mom yes rot yes dist gaussian
fix heat all nvt temp 1200 1200 0.1
thermo 500
run 5000
unfix heat
# cool is K/ps; the timestep is 0.001 ps.
variable nquench equal ceil((1200-v_T)/(v_cool*0.001))
fix quench all nvt temp 1200 ${T} 0.1
run ${nquench}
unfix quench
fix relax all npt temp ${T} ${T} 0.1 iso 0 0 1
run 5000
unfix relax
variable L0 equal $(lz)
variable V0 equal $(vol)
variable strain equal (lz-v_L0)/v_L0
variable stress equal -pzz*vol/(v_V0)*0.0001
fix heat all nvt temp ${T} ${T} 0.1
fix deform all deform 1 z erate ${rate} units box remap x
fix output all print 100 "${strain} ${stress}" file ${out} screen no title "# strain stress_GPa"
run 15000
analyze.py (36 lines)
from pathlib import Path
import numpy as np
import matplotlib.pyplot as plt
CASES = [('tension_10.txt','10 K/ps'),('tension_100.txt','100 K/ps')]
fig, ax = plt.subplots()
found = 0
for filename, label in CASES:
path = Path(filename)
if not path.exists():
print(f"Missing output: {path}. Run the matching LAMMPS command first.")
continue
try:
data = np.loadtxt(path, comments="#", ndmin=2)
if data.shape[1] < 2 or data.shape[0] == 0:
print(f"{path}: expected strain and stress_GPa columns; skipping.")
continue
data = data[np.isfinite(data[:, :2]).all(axis=1)]
if not len(data):
print(f"{path}: no finite data rows; skipping.")
continue
except (ValueError, OSError) as exc:
print(f"Cannot read {path}: {exc}")
continue
strain, stress = data[:, 0], data[:, 1]
ax.plot(strain, stress, label=label); mask = (strain >= 0) & (strain <= 0.02); print(f"{label}: modulus = {np.polyfit(strain[mask], stress[mask], 1)[0]:.4g} GPa" if mask.sum() >= 2 and np.ptp(strain[mask]) > 0 else f"{label}: insufficient points for modulus")
found += 1
if found:
ax.set(xlabel="Engineering strain", ylabel="Engineering stress (GPa)")
ax.legend()
fig.tight_layout()
fig.savefig("stress_strain.png", dpi=200)
print("Saved stress_strain.png")
else:
print("No usable data; no figure written.")