2. Algorithm & Key Advantages of Option 33¶
Multiwfn's Option 33 implements the rigorous Zur–McGill (1984) 2D lattice-matching framework in compiled Fortran (PBC.f90), enhanced with several engineering safeguards tailored specifically to real-world DFT input files. Complete global searches up to 300–600 atoms typically finish in 30–80 milliseconds.
Five-Stage Matching & Construction Pipeline¶
1. Smart Periodic Preprocessing (Eliminating Common Input Pitfalls)¶
Crystal files downloaded from materials databases (C2DB, Materials Project) or exported by DFT codes often suffer from two hidden traps:
- Slabs split across the \(z = 0/1\) periodic boundary (e.g., Mo at \(z = 0.00\) with two S layers at \(z = 0.08\) and \(z = 0.92\), where naive min/max subtraction miscomputes a \(3.12\text{ Å}\) monolayer as \(16.6\text{ Å}\) thick!).
- Tilted stacking axes (\(\mathbf{c}\) not perpendicular to the \(ab\) plane in monoclinic/triclinic inputs).
Multiwfn performs circular maximum vacuum-gap detection along the stacking axis to unwrap any boundary-split slab seamlessly into one contiguous layer, followed by exact 3D rigid projection onto the surface normal—guaranteeing zero artificial shear even for tilted cells.
2. Canonical Hermite Normal Form (HNF) Enumeration + 2D Gauss Reduction + Binary Search¶
Every distinct 2D sublattice of area multiplier \(N\) corresponds uniquely to an upper-triangular integer Hermite Normal Form matrix:
Unlike naive 8-nested brute-force loops (which examine vast numbers of equivalent bases and can take minutes), HNF enumerates each sublattice exactly once. Every candidate basis is reduced via 2D Gauss reduction (\(\gamma \in [60^\circ, 120^\circ]\)), sorted by shortest vector length, and matched using binary search so only length-compatible pairs are ever evaluated.
3. Full 8-Boundary SL(2,ℤ) Equivalence Check + Analytic Polar Decomposition¶
Near the boundaries of the Gauss fundamental domain (nearly square, rectangular, or hexagonal supercells), all 8 orientation-preserving unimodular boundary matrices (\(\det = +1\)) are tested to ensure no valid match is ever missed. Closed-form 2D polar decomposition \(\mathbf{F} = \mathbf{U}\mathbf{R}(\theta)\) then yields both the exact relative twist angle \(\theta\) and the exact Biot principal strains \((\varepsilon_1, \varepsilon_2)\).
4. Exact 6-Minor Primitive-Heterostructure Filter + Pareto-Protected Candidate Pool¶
Using the GCD of all six \(2\times 2\) minors of the joint \(2\times 4\) matrix \([\mathbf{M}_A \mid \mathbf{M}_B]\), Multiwfn strictly eliminates redundant oblique non-primitive supercell multiples (while preserving practical \(90^\circ\) orthogonal doubled cells). Its 2,000-entry candidate buffer uses Pareto-preserving eviction, ensuring that large high-multiplicity supercells can never crowd out compact classic matches (such as 6-atom \(1\times 1\) MoS2/WSe2).
5. Exact HNF Coset Atom Population & DFT-Friendly Output Ordering¶
Atomic coordinates are populated by exact HNF integer coset enumeration, mathematically guaranteeing exactly \(N_A n_A + N_B n_B\) atoms with zero floating-point boundary drops or duplicates. The final simulation cell is rigidly oriented with \(\mathbf{a}' \parallel +X\), \(\mathbf{b}'\) in the \(XY\) plane, and \(\mathbf{c}' \parallel +Z\) (\(\alpha = \beta = 90^\circ\)). Crucially, Part A occupies the first contiguous block of atom indices and Part B the second, each sorted strictly from bottom to top in \(Z\)—making selective-dynamics layer freezing and Multiwfn fragment definitions effortless.