Interfaces#

Use find_interfaces() to compare two Surface objects. Each candidate reports pairs of bulk crystal directions that become parallel in the constructed interface. The returned BuiltInterface contains the full ChemicalSystem and serializable provenance metadata. Its interface_atoms(distance) method selects atoms near the gap midpoint for visualization; use the complete system for calculations.

from scm.structures import Surface, find_interfaces

bottom = Surface.from_bulk(copper_bulk, miller=(1, 1, 1), num_layers=4)
top = Surface.from_bulk(brucite_bulk, miller=(0, 0, 0, 1), num_layers=3)
matches = find_interfaces(bottom, top, max_strain=0.04, strain_mode="both")
interface = matches.best().build(separation=3.0, vacuum=12.0)
for pair in interface.parallel_directions:
    print(pair.bottom, "||", pair.top)
closeup = interface.interface_atoms(distance=4.0)
find_interfaces(bottom: Surface, top: Surface, *, angles: Sequence[float] | None = None, angle_tolerance: float = 1.0, max_index: int = 3, max_atoms: int = 500, max_strain: float = 0.02, strain_mode: Literal['top', 'bottom', 'both'] = 'top', strain_weight: float = 0.5, max_area: float | None = None, max_vector_length: float | None = None, min_vector_angle: float = 0.0) → InterfaceSearchResult#

Search two surfaces, keeping crystal directions attached to every match.

Every pair of integer supercells within max_index and max_atoms is checked. Relative rotation is solved from each pair. Optional angles filter the resulting standardized-frame rotations within angle_tolerance degrees. Without angles, all rotations are allowed. The reported direction pairs are exact in the conventional bulk bases; their Cartesian vectors become parallel after the chosen match is built.

class InterfaceSearchResult(candidates: tuple[InterfaceCandidate, ...])#

Ranked matches; the first is the smallest allowed cell with a good shape.

Iterate over candidates or use best() for the first choice. pareto() shows the atom-count versus strain alternatives.

best() → InterfaceCandidate#

Return the first ranked match, or raise if the search found none.

pareto() → tuple[InterfaceCandidate, ...]#

Matches not beaten in both atom count and maximum principal strain.

class InterfaceCandidate(bottom: Surface, top: Surface, match: InterfaceMatch)#

A geometric match bound to the two bulk-derived surfaces it connects.

match contains the supercell matrices, common cell, transforms, and principal strains. bottom and top retain the bulk directions.

build(*, separation: float = 3.3, registry: tuple[float, float] = (0.0, 0.0), vacuum: float | None = None) → BuiltInterface#

Stack the two surfaces and retain their direction provenance.

separation is the gap in Å between the facing atomic planes. registry shifts the top by fractional common-cell vectors. vacuum adds a third lattice vector and this much empty space between periodic stack images; omit it for a 2D periodic interface. The atoms are not relaxed.

property atom_count: int#

Total number of atoms in the interface supercell.

property frame_rotation_degrees: float#

Rotation between standardized input frames, not necessarily atomic twist.

property max_strain: float#

Largest absolute in-plane principal strain, as a fraction.

property parallel_directions: tuple[ParallelDirections, ParallelDirections]#

Corresponding crystal translations along both common-cell axes.

class BuiltInterface(system: ChemicalSystem, candidate: InterfaceCandidate, separation: float, registry: tuple[float, float], vacuum: float | None)#

The ChemicalSystem and the provenance needed to interpret it.

interface_atoms(distance: float) → ChemicalSystem#

Return atoms within distance Å of the interface gap midpoint.

The subset retains the interface lattice and atom attributes. It is intended for visualization; ChemicalSystem.extract_atoms resets total charge and removes bonds to omitted atoms.

property interface_plane_z: float#

Midpoint of the gap between the facing atomic planes, in Å.

property metadata: dict[str, object]#

Serializable surface, direction, match, and stacking provenance.

property parallel_directions: tuple[ParallelDirections, ParallelDirections]#

Two pairs of bulk directions spanning the common interface cell.

system: ChemicalSystem#

Complete interface ChemicalSystem.

BuiltInterface.system is the complete interface ChemicalSystem.

class ParallelDirections(bottom: CrystalDirection, top: CrystalDirection, final_length: float)#

One pair of bulk translations made parallel in the final interface.

bottom and top refer to their respective conventional bulk cells. final_length is their shared length in Å after the match’s rotation and strain have been applied.

bottom: CrystalDirection#

Translation in the bottom conventional bulk cell.

final_length: float#

Shared length after matching, in Å.

top: CrystalDirection#

Corresponding translation in the top conventional bulk cell.

ParallelDirections.bottom and top are the corresponding translations in the two conventional bulk cells. final_length is their shared length after matching, in ångströms.

Lower-level interface builder#

The lower-level builder can match and stack two prepared periodic layers. For a workflow starting from bulk crystals, use find_interfaces().

class InterfaceMatch(bottom_matrix: tuple[tuple[int, int], tuple[int, int]], top_matrix: tuple[tuple[int, int], tuple[int, int]], common_cell: tuple[tuple[float, float], tuple[float, float]], bottom_transform: tuple[tuple[float, float], tuple[float, float]], top_transform: tuple[tuple[float, float], tuple[float, float]], bottom_cell: tuple[tuple[float, float], tuple[float, float]], top_cell: tuple[tuple[float, float], tuple[float, float]], bottom_atom_count: int, top_atom_count: int, search_angle: float, strain_weight: float)#

Immutable lattice correspondence in each input’s standardized plane frame.

matrix @ input_cell @ transform == common_cell for each layer. Transforms include rotation; strain properties remove rigid rotation by polar decomposition. Reference cells and counts allow compatible inputs to be checked at build time; they do not identify chemical composition.

find_interface_matches(bottom: ChemicalSystem, top: ChemicalSystem, *, angles: Sequence[float] = (0.0,), max_index: int = 3, max_atoms: int = 500, max_strain: float = 0.02, strain_mode: Literal['top', 'bottom', 'both'] = 'top', strain_weight: float = 0.5) → list[InterfaceMatch]#

Find small common in-plane cells, sorted by atom count then strain.

Enumerate top lattice vectors with coefficients in [-max_index, max_index], rotate them by each angle, and round their bottom fractional coordinates to integers. Pair independent vectors to form candidate cells. This inexpensive nearest-in-fractional-coordinates search can miss matches in skew cells. Equivalent bases are not symmetry-reduced.

max_strain bounds every absolute principal stretch minus one, in each layer. top keeps the bottom fixed; bottom keeps the top fixed. both interpolates the aligned cells with strain_weight (0 keeps bottom fixed, 1 keeps top fixed). This is not elastic-energy minimization. Angles are relative to frames with each layer’s first vector along x. Three-dimensional inputs must be prepared slabs, contiguous across z: their third lattice vector is ignored. Inputs are never modified.

build_interface(bottom: ChemicalSystem, top: ChemicalSystem, match: InterfaceMatch, *, separation: float = 3.3, registry: tuple[float, float] = (0.0, 0.0), vacuum: float | None = None) → ChemicalSystem#

Build a match, preserving layer thickness and leaving inputs unchanged.

Output is aligned to the xy plane. separation is the positive gap between facing atomic z extents. registry shifts the top by fractional common-cell coordinates. Default output is 2D periodic; positive vacuum creates a 3D cell with that total empty gap between periodic images of the stack. Atoms are mapped to fractional coordinates in [0, 1) along the periodic directions. No relaxation or registry optimization is performed.