{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Basic Substitutions\n", "\n", "This guide demonstrates how to use `bsym` to generate symmetry-inequivalent structures by substituting atoms in a parent structure.\n", "\n", "## Overview\n", "\n", "The `bsym.interface.pymatgen.unique_structure_substitutions` function takes a parent structure and generates all symmetry-unique configurations when substituting specific sites with different species.\n", "\n", "**Key parameters:**\n", "- `structure`: The parent pymatgen Structure\n", "- `to_substitute`: The atomic species label to be replaced\n", "- `site_distribution`: Dictionary specifying how many of each substituting species (e.g., `{'Na': 1, 'Li': 15}`)\n", "\n", "**Returns:** A list of Structure objects, each representing a symmetry-inequivalent configuration." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Simple Example: Single Substitution\n", "\n", "Let's start with a simple 4×4 square lattice of lithium atoms and substitute one Li with Na.\n", "\n", "### Setting Up the Parent Structure" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "from pymatgen.core import Structure, Lattice\n", "from bsym.interface.pymatgen import unique_structure_substitutions\n", "\n", "# Create a simple square lattice\n", "coords = np.array([[0.0, 0.0, 0.0]])\n", "atom_list = ['Li']\n", "lattice = Lattice.from_parameters(a=1.0, b=1.0, c=1.0, alpha=90, beta=90, gamma=90)\n", "parent_structure = Structure(lattice, atom_list, coords) * [4, 4, 1]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This creates a 4×4 supercell with 16 lithium atoms." ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Full Formula (Li16)\n", "Reduced Formula: Li\n", "abc : 4.000000 4.000000 1.000000\n", "angles: 90.000000 90.000000 90.000000\n", "pbc : True True True\n", "Sites (16)\n", " # SP a b c\n", "--- ---- ---- ---- ---\n", " 0 Li 0 0 0\n", " 1 Li 0 0.25 0\n", " 2 Li 0 0.5 0\n", " 3 Li 0 0.75 0\n", " 4 Li 0.25 0 0\n", " 5 Li 0.25 0.25 0\n", " 6 Li 0.25 0.5 0\n", " 7 Li 0.25 0.75 0\n", " 8 Li 0.5 0 0\n", " 9 Li 0.5 0.25 1\n", " 10 Li 0.5 0.5 0\n", " 11 Li 0.5 0.75 0\n", " 12 Li 0.75 0 0\n", " 13 Li 0.75 0.25 0\n", " 14 Li 0.75 0.5 1\n", " 15 Li 0.75 0.75 0\n" ] } ], "source": [ "print(parent_structure)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Performing the Substitution\n", "\n", "Now we substitute one Li atom with Na:" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Number of unique structures: 1\n" ] } ], "source": [ "unique_structures = unique_structure_substitutions(\n", " parent_structure, \n", " 'Li',\n", " {'Na': 1, 'Li': 15}\n", ")\n", "\n", "print(f\"Number of unique structures: {len(unique_structures)}\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Due to the high symmetry of the square lattice, all single-site substitutions are symmetry-equivalent, so we get only **one unique structure**.\n", "\n", "