Tutorial 4 · Crystals & Defects¶
What you'll learn: how to build bulk crystals with arbitrary structures and lattice constants, create supercells, and introduce point defects (vacancies, substitutions, interstitials).
Prerequisites: Tutorial 1. No extra dependencies.
Building a bulk crystal¶
[run]
name = "bulk_vacancy_md"
seed = 7
[geometry.builder]
type = "crystal"
name = "Cu" # (1)
crystalstructure = "fcc" # (2)
a = 3.61 # (3)
cubic = true # (4)
supercell = [2, 2, 2] # (5)
[[geometry.builder.defects]] # (6)
kind = "vacancy"
index = 0
[calculator]
type = "emt"
[sampling]
type = "md"
temperature = 600.0
steps = 200
interval = 20
[selection]
steps = ["physicality", "dedup", "diversity"]
budget = 8
[dataset]
path = "dataset"
Crystal builder parameters¶
-
name— the element symbol (or compound formula for multi-element crystals, e.g."NaCl","GaAs","TiO2"). -
crystalstructure— the crystal structure type. Common values:fcc,bcc,hcp,diamond,rocksalt,wurtzite,zincblende. Leavenullto let ASE infer it from the element. -
a— the primary lattice constant in Å. Leavenullto use ASE's built-in experimental value. -
cubic— whether to use the cubic conventional cell (larger but orthogonal). Recommended for most MD runs. -
supercell— repeat the primitive/conventional cell before adding defects.[2,2,2]→ 8× the unit cell. -
[[geometry.builder.defects]]— a list of point defects to introduce (see below).
Point defects¶
Vacancy¶
Remove one atom from the supercell:
index— the atom index in the pre-defect supercell (0-based). Index 0 is the first atom.
Substitution¶
Replace an atom with a different element:
Interstitial¶
Insert an extra atom at a specific position:
[[geometry.builder.defects]]
kind = "interstitial"
element = "H"
position = [0.5, 0.5, 0.5] # (1)
cartesian = false # (2)
-
position— where to insert the atom. -
cartesian—falsemeans the position is in fractional coordinates (relative to the supercell vectors). Set totruefor Cartesian coordinates in Å.
Combining multiple defects¶
Defects are applied in a stable order: substitutions first, then vacancies,
then interstitials. The index fields always refer to the supercell before
any atoms are added or removed.
[geometry.builder]
type = "crystal"
name = "Cu"
crystalstructure = "fcc"
a = 3.61
cubic = true
supercell = [3, 3, 3]
[[geometry.builder.defects]]
kind = "substitution"
index = 0
element = "Ni" # swap atom 0 for Ni
[[geometry.builder.defects]]
kind = "vacancy"
index = 1 # remove atom 1 from the original supercell
[[geometry.builder.defects]]
kind = "interstitial"
element = "H"
position = [0.25, 0.25, 0.25]
cartesian = false
Common crystal systems¶
Inspecting defect provenance¶
Defect information is stored in provenance.extra:
from traincraft.geometry import build_geometry
from traincraft.config.models import CrystalBuilder, DefectSpec, GeometryConfig
s = build_geometry(GeometryConfig(
builder=CrystalBuilder(
name="Cu", crystalstructure="fcc", a=3.6, cubic=True,
supercell=(2, 2, 2),
defects=[DefectSpec(kind="vacancy", index=0)],
)
))
print(s.provenance.extra)
# {'defects': [{'kind': 'vacancy', 'index': 0, 'element': None}]}
Summary¶
| Defect type | TOML kind |
Required fields |
|---|---|---|
| Remove an atom | "vacancy" |
index |
| Swap an element | "substitution" |
index, element |
| Add an atom | "interstitial" |
element, position |
Next: Tutorial 5 — standalone surface slabs and mechanical deformation.