### Install airsspy Package Source: https://github.com/zhubonan/airsspy/blob/master/README.md Installs the airsspy package and its dependencies from PyPI or directly from the GitHub repository. This is the primary method for setting up the library for use. ```bash pip install airsspy ``` ```bash pip install git+https://github.com/zhubonan/airsspy ``` -------------------------------- ### Import Libraries for airsspy and ASE Source: https://github.com/zhubonan/airsspy/blob/master/examples/example-1.1.ipynb Imports necessary modules from airsspy, ipypb for progress bars, and various optimizers and calculators from the ase library for crystal structure manipulation and calculations. ```python from airsspy import SeedAtoms, Buildcell from ipypb import ipb as tqdm # Import ase assets from ase.optimize import BFGSLineSearch, sciopt, FIRE, BFGS, precon from ase.calculators.lj import LennardJones from ase.constraints import UnitCellFilter, ExpCellFilter ``` -------------------------------- ### Import ASE and Airsspy Libraries Source: https://github.com/zhubonan/airsspy/blob/master/examples/example-1.12.ipynb Imports necessary modules from the Airsspy library and ASE for building and manipulating atomic structures. ```python from airsspy import SeedAtoms, Buildcell from ipypb import ipb as tqdm # Import ase assets from ase import Atoms ``` -------------------------------- ### Import ASE Visualize Module Source: https://github.com/zhubonan/airsspy/blob/master/examples/example-1.12.ipynb Imports the `view` function from the `ase.visualize` module, which is used for displaying atomic structures. ```python from ase.visualize import view ``` -------------------------------- ### Preview buildcell input configuration Source: https://github.com/zhubonan/airsspy/blob/master/examples/example-lj-cluster.ipynb Prints the input configuration lines that will be passed to the `buildcell` program. This allows for verification of the parameters set for structure generation. ```python # Preview the settings to be sent to `buildcell` print('\n'.join(ljatoms.get_cell_inp_lines())) ``` -------------------------------- ### Generate Input Lines for Buildcell Source: https://github.com/zhubonan/airsspy/blob/master/examples/example-1.12.ipynb Prints the input lines required by the `Buildcell` program, formatted as a string, which are generated from the configured `SeedAtoms` object. ```python print(' '.join(seed.get_cell_inp_lines())) ``` -------------------------------- ### Generate Atoms Structure with Buildcell Source: https://github.com/zhubonan/airsspy/blob/master/examples/example-1.12.ipynb Initializes a `Buildcell` object with the configured `seed` and then generates the final atomic structure. ```python bc = Buildcell(seed) atoms = bc.generate() ``` -------------------------------- ### Create Working Directory Source: https://github.com/zhubonan/airsspy/blob/master/examples/example-1.1.ipynb Creates a new directory named 'work' in the current file system. This is often used to organize output files or intermediate data for simulations. ```bash !mkdir work ``` -------------------------------- ### Visualize Atoms Structure with X3D Source: https://github.com/zhubonan/airsspy/blob/master/examples/example-1.12.ipynb Visualizes the generated atomic structure using ASE's 'x3d' viewer. This allows for interactive 3D rotation and inspection of the nanotube. ```python # Note that you may have left click and drag to rotate the view in order to see any atoms # double click to focus on one atom and drag to rotate the view view(atoms, viewer='x3d') ``` -------------------------------- ### Configure Lennard-Jones Potential Source: https://github.com/zhubonan/airsspy/blob/master/examples/example-1.1.ipynb Sets up a Lennard-Jones potential calculator with specified parameters for sigma, epsilon, beta, and cutoff radius (rc). This calculator will be used for energy and force calculations. ```python # LJ potential calculator lj = LennardJones(signma=2, epsilon=1, beta=1, rc=2.5) ``` -------------------------------- ### Get Positions of Atoms in Random Structure Source: https://github.com/zhubonan/airsspy/blob/master/examples/example-1.1.ipynb Retrieves and displays the fractional or Cartesian coordinates of all atoms within the randomly generated `ase.Atoms` object. ```python rand_atoms.get_positions() ``` -------------------------------- ### Import optimization modules Source: https://github.com/zhubonan/airsspy/blob/master/examples/example-lj-cluster.ipynb Imports necessary modules from `ase.calculators.lj` for the Lennard-Jones potential and `ase.optimize` for structure optimization algorithms like FIRE. `ipypb.track` is imported for progress bars. ```python # Optimization can be done with Python using ASE from ase.calculators.lj import LennardJones from ase.optimize import FIRE from ipypb import track # <-- This gives a nice progress bar ``` -------------------------------- ### Define Per-Atom Tags with Airsspy Source: https://github.com/zhubonan/airsspy/blob/master/examples/example-1.12.ipynb Iterates through each atom in the `seed` object and assigns per-atom tags. This example sets specific properties like `fix`, `posamp`, `num`, `zamp`, `xamp`, `yamp`, and `adatom` based on the atom's symbol. ```python # The per atoms tags supports tab completion for atom in seed: if atom.symbol == 'C': atom.fix = True atom.posamp = 0 else: atom.num = 24 atom.zamp = -1 atom.xamp = 5 atom.yamp = 5 atom.adatom = True ``` -------------------------------- ### Get Space Group of Relaxed Structures using spglib Source: https://github.com/zhubonan/airsspy/blob/master/examples/example-1.1.ipynb Imports the `get_spacegroup` function from `spglib` and uses it to determine the space group for each of the relaxed atomic structures stored in the `res` list. A tolerance of 0.5 is used. ```python from spglib import get_spacegroup spg = [get_spacegroup(i, 0.5) for i in res] spg ``` -------------------------------- ### Prepare Atoms for Visualization Source: https://github.com/zhubonan/airsspy/blob/master/examples/example-1.12.ipynb Generates the atoms structure again, translates it to center it within the cell, sets periodic boundary conditions, wraps atoms within the cell, and then translates it back to its original position before visualization. ```python atoms = bc.generate() atoms.translate([atoms.cell[0, 0]/2, atoms.cell[1, 1]/ 2, 0]) atoms.pbc = True atoms.wrap() atoms.translate([-atoms.cell[0, 0]/2, -atoms.cell[1, 1]/ 2, 0]) ``` -------------------------------- ### Get the Cell of the Random Structure Source: https://github.com/zhubonan/airsspy/blob/master/examples/example-1.1.ipynb Retrieves and displays the lattice vectors of the randomly generated `ase.Atoms` object. This shows the current cell dimensions after random generation. ```python rand_atoms.get_cell() ``` -------------------------------- ### Import necessary libraries for AIRSS Source: https://github.com/zhubonan/airsspy/blob/master/examples/example-lj-cluster.ipynb Imports essential modules from the `airsspy`, `pandas`, `ase.visualize`, and `ipypb` libraries. These are required for defining seed atoms, building cells, visualizing structures, and displaying progress bars during the process. ```python import os from airsspy import SeedAtoms, Buildcell import pandas as pd from ase.visualize import view from ipypb import ipb as tqdm ``` -------------------------------- ### Print Seed Cell Input Lines Source: https://github.com/zhubonan/airsspy/blob/master/examples/example-1.1.ipynb Generates and prints the input file lines for the defined seed structure, including lattice information and atomic positions. This is useful for visualization or input to other simulation tools. ```python # The seed in text form print('\n'.join(seed.get_cell_inp_lines())) ``` -------------------------------- ### Run AIRSS Search and Collect Results Source: https://github.com/zhubonan/airsspy/blob/master/examples/example-lj-cluster.ipynb Executes the `airss_search` function to generate 100 clusters using the `lj` calculator and `FIRE` optimizer, storing the relaxed structures in the `results` list. ```python results = [] airss_search(ljatoms, results, lj, FIRE, 100) ``` -------------------------------- ### Define Global Buildcell Tags with Airsspy Source: https://github.com/zhubonan/airsspy/blob/master/examples/example-1.12.ipynb Sets global tags for the `Buildcell` process using the `seed.gentags` object. This includes defining the supercell dimensions, slack, minimum separation between atoms, and fixing the structure. ```python seed.gentags.supercell = '1 1 3' seed.gentags.slack = 0.25 seed.gentags.minsep = [1.0, {'A-A':1.3, 'B-B':2, 'A-B':2}] seed.gentags.fix = True ``` -------------------------------- ### Analyze Relaxation Results (Shell) Source: https://github.com/zhubonan/airsspy/blob/master/examples/example-1.1.ipynb This command-line snippet executes the 'ca' program to analyze relaxation results. It navigates into the 'work' directory, runs 'ca' with specified parameters (recalculating, unique), and then returns to the parent directory. The input is implicitly the files generated in the previous step within the 'work' directory. The output is a tabular list of analyzed structural data. ```Shell !cd work/ && ca -r -u 0.01 && cd - ``` -------------------------------- ### Define Seed Atoms for Crystal Search Source: https://github.com/zhubonan/airsspy/blob/master/examples/example-1.1.ipynb Defines a seed structure for crystal search using `SeedAtoms`. It specifies the element ('Al'), cell dimensions, periodicity, minimum atom separation, and the number of atoms. ```python # Define the search seed seed = SeedAtoms('Al', cell=[2, 2, 2], pbc=True) seed.gentags.minsep = 1.5 # Define per-atom tags, here it is simply request 8 Al atoms al = seed[0] al.num = 8 ``` -------------------------------- ### Perform Structure Relaxation with Different Optimizers Source: https://github.com/zhubonan/airsspy/blob/master/examples/example-1.1.ipynb Iterates 20 times, calling `gen_and_relax` to generate and relax structures using the defined seed, LJ calculator, and BFGSLineSearch optimizer. The relaxed structures are stored in the `res` list. ```python res = [] for i in tqdm(range(20)): # A range of the possible optimization algorithm are possible relaxed = gen_and_relax(seed, lj, BFGSLineSearch) res.append(relaxed) ``` -------------------------------- ### Capture and print buildcell input/output Source: https://github.com/zhubonan/airsspy/blob/master/examples/example-lj-cluster.ipynb Captures and prints the raw standard input, standard error, and standard output from the `buildcell` execution. This is useful for debugging and understanding the generation process. ```python print('#' * 10 + 'INPUTS' + '#' * 10 + '\n') print(bc.bc_in) print('#' * 10 + 'STDERR-DEBUG' + '#' * 10 + '\n') print(bc.bc_err) print('#' * 10 + 'STDOUT-Random structure' + '#' * 10 + '\n') print(bc.bc_out) ``` -------------------------------- ### Generate Random Atomic Structure Source: https://github.com/zhubonan/airsspy/blob/master/examples/example-1.1.ipynb Generates a random atomic structure based on the defined seed using the `build_random_atoms` method. This method returns an `ase.Atoms` object, representing the randomly generated crystal. ```python ## Generate the random structure The random structrue can be built by calling `build_random_atoms` method. An `ase.Atoms` object is returned. rand_atoms = seed.build_random_atoms() ``` -------------------------------- ### Instantiate Buildcell for structure generation Source: https://github.com/zhubonan/airsspy/blob/master/examples/example-lj-cluster.ipynb Initializes the `Buildcell` class with the previously defined `SeedAtoms` object. This prepares the system to generate random atomic structures based on the specified parameters. ```python # Create a Buildcell instance bc = Buildcell(ljatoms) ``` -------------------------------- ### Define Function to Generate and Relax Cell Source: https://github.com/zhubonan/airsspy/blob/master/examples/example-1.1.ipynb Defines a Python function `gen_and_relax` that takes a seed, calculator, and optimizer. It generates a random structure, sets the calculator and periodicity, applies UnitCellFilter, and runs the optimization. ```python def gen_and_relax(seed, calc, opti): """ Generate and relax the cell """ rand_atoms = seed.build_random_atoms() rand_atoms.set_pbc(True) # Set the PBC as we are search from crystal rand_atoms.set_calculator(calc) # Attached hte calculator # Apply the UnitCellFilter as we are also optimizing the cell opt = opti(UnitCellFilter(rand_atoms), logfile=None) opt.run(fmax=0.05) return rand_atoms ``` -------------------------------- ### Initialize Lennard Jones Calculator Source: https://github.com/zhubonan/airsspy/blob/master/examples/example-lj-cluster.ipynb Initializes a Lennard-Jones potential calculator with specified parameters for epsilon, sigma, and cutoff radius (rc). This calculator will be used for energy calculations. ```python lj = LennardJones(epsilon=1, sigma=1, rc=3) ``` -------------------------------- ### Build Nanotube Structure with ASE Source: https://github.com/zhubonan/airsspy/blob/master/examples/example-1.12.ipynb Uses ASE's `nanotube` function to create a nanotube structure. It then manually adjusts the cell dimensions and extends the structure with a 'B' atom. Finally, it initializes a `SeedAtoms` object with the created tube. ```python from ase.build import nanotube # Use ase to create a tube tube = nanotube(8, 8) # Manually set the cell in x,y direction tube.cell[0, 0] = 20 tube.cell[1, 1] = 20 tube.extend(Atoms('B')) seed = SeedAtoms(tube) ``` -------------------------------- ### Write and Process Crystal Structure Data (Python) Source: https://github.com/zhubonan/airsspy/blob/master/examples/example-1.1.ipynb This snippet shows how to write a crystal structure file (seed) and a potential file (pp) using Python. It then invokes an external program 'airss.pl' for relaxation and relaxation analysis. Dependencies include 'seed' object for writing, 'pathlib' for file operations, and the 'airss.pl' executable. The output is the result of the 'airss.pl' command. ```Python %%timeit -n 1 -r 1 seed.write_seed('work/Al.cell') from pathlib import Path Path("work/Al.pp").write_text(pp) !cd work && airss.pl -seed Al -max 20 -pp3 && cd ../ ``` -------------------------------- ### Inspect Cell Volume of Random Structure Source: https://github.com/zhubonan/airsspy/blob/master/examples/example-1.1.ipynb Calculates and returns the volume of the randomly generated crystal structure. The volume is expected to be around the initial cell volume scaled by the number of atoms, with potential variations. ```python rand_atoms.get_volume() ``` -------------------------------- ### Write AIRSS Seed File Source: https://github.com/zhubonan/airsspy/blob/master/README.md Shows how to write the prepared seed structure to a file in a format that AIRSS can process. It includes an example of using the `buildcell` executable externally to generate a random cell from the seed file. ```bash atoms.write_seed('C6.cell') # With IPython # Use the buildcell executable to generate the file !buildcell < C6.cell > C6-rand.cell ``` -------------------------------- ### Calculate Energy of Global Minimum Configuration Source: https://github.com/zhubonan/airsspy/blob/master/examples/example-lj-cluster.ipynb Calculates the potential energy of the known global minimum configuration (c8) using the initialized Lennard-Jones calculator (`lj`). This is done to verify if the search has found the global minimum. ```python lj.get_potential_energy(c8) ``` -------------------------------- ### Perform AIRSS Search for Atomic Structures Source: https://github.com/zhubonan/airsspy/blob/master/examples/example-lj-cluster.ipynb Conducts a simple Automated Interactive Structure Search (AIRSS) to generate and relax candidate atomic structures. It requires the `buildcell` utility to be in the system's PATH. The function takes a seed, a list to store results, a calculator, an optimizer class, and a maximum search count as input. It returns the minimum energy found during the search. ```python def airss_search(seed, alist, calc, opti_class, max_search=100): """ Conduct a simple AIRSS search. Randomly genrate candiates and relax them. """ min_eng = 9999 for i in tqdm(range(max_search), total=max_search): # Requires `buildcell` in PATH atoms, bc = seed.build_random_atoms(also_buildcell=True) alist.append(atoms) atoms.set_calculator(calc) opti = opti_class(atoms=atoms, logfile=None) opti.run(fmax=0.05) atoms.cached_energy = atoms.get_potential_energy() if atoms.cached_energy < min_eng: min_eng = atoms.cached_energy print(min_eng) ``` -------------------------------- ### Define Known Global Minimum Structure Source: https://github.com/zhubonan/airsspy/blob/master/examples/example-lj-cluster.ipynb Defines the atomic positions for a known global minimum configuration (c8) of a Lennard-Jones system. The positions are provided as a multi-line string and then parsed into a list of lists of floats. ```python c8_pos = """ 0.2730989500 1.1469629952 -0.3319578813 -0.4728837298 -0.6223685080 0.7664213265 -0.9666537615 -0.2393056630 -0.1698094248 0.6209419539 -0.3628130566 0.7094425990 0.8035441992 0.1648033307 -0.2639206823 -0.1784380914 0.2412141513 -0.8077599510 0.0639788373 -0.6647479592 -0.2089132333 -0.1435883576 0.3362547097 0.3064972473 """ c8_pos = c8_pos.split('\n') c8_pos = [list(map(float, l.strip().split())) for l in c8_pos if l] c8 = SeedAtoms('H8', positions=c8_pos) ``` -------------------------------- ### Analyze Relaxed Structures and Plot Energy Distribution Source: https://github.com/zhubonan/airsspy/blob/master/examples/example-lj-cluster.ipynb Collects processed data for the first 500 relaxed structures into a pandas DataFrame, identifies the structure with the minimum energy, prints this minimum energy, and generates a histogram of the energy distribution. ```python # Collect the data into a dataframe and analyse df = pd.DataFrame([process(atoms) for atoms in results[:500]]) idmin = df.energy.idxmin() mineng = df.energy.loc[idmin] print('Minimum energy found: {:.5f}'.format(mineng)) df.hist('energy', bins=100) ``` -------------------------------- ### Set Global Buildcell Parameters with AIRSSpy SeedAtoms Source: https://context7.com/zhubonan/airsspy/llms.txt This example shows how to configure global parameters for random structure generation using the `gentags` attribute of the `SeedAtoms` class in AIRSSpy. It covers volume and cell constraints, symmetry constraints, minimum separation, and positional/angular randomization. ```python from airsspy import SeedAtoms seed = SeedAtoms('C8Si4', cell=[6, 6, 6], pbc=True) # Volume and cell constraints seed.gentags.varvol = 30 # Volume variation percentage seed.gentags.targvol = (50, 100) # Target volume range seed.gentags.compact = True # Apply Niggli reduction seed.gentags.system = 'cubic' # Enforce cubic system # Symmetry constraints seed.gentags.symmops = (4, 8) # Request 4-8 symmetry operations seed.gentags.symmorphic = True # Enforce symmorphic symmetry seed.gentags.sgrank = (10, 50) # Space group rank range # Minimum separation with species-specific values seed.gentags.minsep = (2.0, {'C-C': 1.5, 'Si-Si': 2.5, 'C-Si': 2.0}) # Positional randomization seed.gentags.posamp = (0.5, {'C': 1.0, 'Si': 0.8}) seed.gentags.angamp = (10, 30) # Angular amplitude range # Write configured seed seed.write_seed('C8Si4-complex.cell') ``` -------------------------------- ### Generate random atomic structure Source: https://github.com/zhubonan/airsspy/blob/master/examples/example-lj-cluster.ipynb Calls the `generate` method of the `Buildcell` instance to create a random atomic structure. A timeout is specified to limit the execution time for this step. The generated `atoms` object contains the new structure. ```python atoms = bc.generate(timeout=1) ``` -------------------------------- ### Group Structures by Energy Source: https://github.com/zhubonan/airsspy/blob/master/examples/example-lj-cluster.ipynb Groups atomic structures based on their energy values, identifying clusters of structures with similar energies. It iterates through sorted energies and groups indices if the energy difference is within a small tolerance (0.01). ```python ## Get the 'clusters' in energy tmp = df.sort_values('energy') groups = [] current_group = 0 current_index = [] last_eng = -9999 for idx, row in tmp.iterrows(): if abs(last_eng - row.energy) > 0.01 and current_index: current_group += 1 groups.append([last_eng, current_index]) current_index = [] else: current_index.append(idx) last_eng = row.energy for eng, index in groups: print('Energy: {:.3f} - indices {}'.format(eng, ', '.join(map(str, index)))) ``` -------------------------------- ### Define LJ-8 cluster seed structure Source: https://github.com/zhubonan/airsspy/blob/master/examples/example-lj-cluster.ipynb Creates a `SeedAtoms` object for an 8-atom LJ cluster of Hydrogen (H). It configures generation tags such as position amplitude, fixing atoms, number of formula units, clustering, minimum separation, symmetry operations, slack, and a confining sphere potential. ```python # Create the seed ljatoms = SeedAtoms('H', cell=(20, 20, 20, 90, 90, 90)) # Configure tags for generation ljatoms[0].num = 8 ljatoms.gentags.posamp = 4 ljatoms.gentags.fix = True ljatoms.gentags.nform = 1 ljatoms.gentags.cluster = True # Request a minsep of 0.5 ljatoms.gentags.minsep = 0.5 # Request 2-4 symmetry opterations ljatoms.gentags.symmops = (2, 4) ljatoms.gentags.slack = 0.1 # Use a sphere confining potential ljatoms.gentags.sphere = 3 ``` -------------------------------- ### Process Atomic Structure Data Source: https://github.com/zhubonan/airsspy/blob/master/examples/example-lj-cluster.ipynb Processes a single atomic structure to extract key properties, including its chemical formula, number of atoms, minimum interatomic separation, volume, and cached potential energy. This function is designed to collect data for analysis. ```python def process(atoms): """Collect results""" sep_all = atoms.get_all_distances(mic=True) sep_all[sep_all > 0].min() res = { 'formula': atoms.get_chemical_formula(), 'natoms': len(atoms), 'minsep': sep_all[sep_all > 0].min(), 'volume': atoms.get_volume(), 'energy': atoms.cached_energy } return res ``` -------------------------------- ### Prepare AIRSS Seed with airsspy Source: https://github.com/zhubonan/airsspy/blob/master/README.md Demonstrates how to create and configure a seed for AIRSS using the `SeedAtoms` class from the airsspy package. This involves setting basic parameters like the chemical formula and modifying properties such as cell volume and symmetry operations. It also shows how to tag individual atoms for specific roles. ```python from airsspy import SeedAtoms seed = SeedAtoms('C6') seed.build.varvol = 20 seed.build.symmops = (2, 4) # Can also access per `atom` tags/ketwords just like in ASE for i in range(0, 6, 2): atom = seed[i] atom.tagname = 'CX' atom.posamp = 2 ``` -------------------------------- ### Generate Random Structures with Buildcell Wrapper Source: https://github.com/zhubonan/airsspy/blob/master/README.md Illustrates the usage of the `Buildcell` wrapper class to interact with AIRSS's `buildcell` program for generating random atomic structures based on a prepared seed. It also presents a shortcut method directly available on the `SeedAtoms` object. ```python from airsspy import Buildcell buidcell = Buildcell(seed) random_atoms = builcell.generate() ``` ```python random_atoms = seed.build_random_atoms() ``` -------------------------------- ### Generate Random Structures using Buildcell Class in Python Source: https://context7.com/zhubonan/airsspy/llms.txt Illustrates using the Buildcell class to interface with AIRSS's buildcell program for generating random crystal structures. It shows initializing Buildcell with a SeedAtoms template, performing structure generation with a timeout, writing the output cell file, and accessing the input/output streams of the buildcell process. ```python from airsspy import SeedAtoms, Buildcell # Create seed template seed = SeedAtoms('Si4', cell=[5, 5, 5], pbc=True) seed.gentags.minsep = 2.0 seed.gentags.varvol = 25 # Initialize Buildcell with seed buildcell = Buildcell(seed) # Generate random structure with timeout try: random_structure = buildcell.generate(timeout=10, write_cell='Si4-random') print(f"Generated {len(random_structure)} atoms") print(f"Cell parameters: {random_structure.get_cell_lengths_and_angles()}") except Exception as e: print(f"Structure generation failed: {e}") # Access buildcell input/output print("Input to buildcell:") print(buildcell.bc_in) print("\nOutput from buildcell:") print(buildcell.bc_out[:200]) # First 200 characters ``` -------------------------------- ### Configure Per-Atom Tags for Structure Generation with AIRSSpy Source: https://context7.com/zhubonan/airsspy/llms.txt This Python code demonstrates how to set individual atom parameters for fine-grained control over structure generation using AIRSSpy. It shows how to configure parameters like number of atoms, randomization amplitudes, fixing atom positions, and coordination/radius for specific atom types. ```python from airsspy import SeedAtoms # Create seed with multiple atom types seed = SeedAtoms('H2O', cell=[10, 10, 10], pbc=True) # Configure hydrogen atoms h1 = seed[0] h1.tagname = 'H1' h1.num = 8 # Generate 8 hydrogen atoms with this tag h1.posamp = 1.5 # Position randomization amplitude h1.fix = False # Allow movement h1.coord = (2, 4) # Coordination number range h2 = seed[1] h2.tagname = 'H2' h2.num = 8 h2.posamp = 1.2 h2.angamp = (10, 45) # Angular randomization for fragments # Configure oxygen atom o = seed[2] o.tagname = 'O' o.num = 8 o.posamp = 2.0 o.rad = 1.4 # Atomic radius for packing o.coord = 4 # Fixed coordination # Generate structures with these constraints random_structure = seed.build_random_atoms(timeout=15, fail_ok=True) if random_structure: print(f"Generated structure: {random_structure.get_chemical_formula()}") ``` -------------------------------- ### Create and Configure SeedAtoms Template in Python Source: https://context7.com/zhubonan/airsspy/llms.txt Demonstrates how to initialize a SeedAtoms object for a carbon structure search, set randomization parameters like volume variation and symmetry operations, configure per-atom properties such as position amplitude, and generate a random structure directly. This facilitates programmatic control over AIRSS search seeds. ```python from airsspy import SeedAtoms # Create a simple seed for carbon structure search seed = SeedAtoms('C6') # 6 carbon atoms seed.gentags.varvol = 20 # Allow 20% volume variation seed.gentags.symmops = (2, 4) # Request 2-4 symmetry operations seed.gentags.minsep = 1.5 # Minimum separation between atoms # Configure per-atom tags for specific atoms for i in range(0, 6, 2): atom = seed[i] atom.tagname = 'CX' # Custom tag name atom.posamp = 2 # Position amplitude for randomization # Write seed to file seed.write_seed('C6.cell') # Generate a random structure directly random_atoms = seed.build_random_atoms(timeout=10) print(f"Generated structure with {len(random_atoms)} atoms") print(f"Cell volume: {random_atoms.get_volume():.2f} ų") ``` -------------------------------- ### High-Throughput Structure Generation and Relaxation with airsspy and ASE (Python) Source: https://context7.com/zhubonan/airsspy/llms.txt This script performs high-throughput structure generation using `airsspy` and subsequent relaxation using ASE's EMT calculator and FIRE optimizer. It includes error handling for failed searches and collects statistics on successful and failed attempts, along with energy and volume data. The lowest energy structure found is saved to a file. ```python from airsspy import SeedAtoms from ase.calculators.emt import EMT from ase.optimize import FIRE from ase.constraints import UnitCellFilter import numpy as np # Setup search parameters seed = SeedAtoms('Cu8', cell=[5, 5, 5], pbc=True) seed.gentags.minsep = 2.2 seed.gentags.varvol = 30 seed[0].num = 8 calculator = EMT() # Batch generation with statistics n_searches = 50 successful = [] failed = 0 energies = [] for i in range(n_searches): try: # Generate random structure atoms = seed.build_random_atoms(timeout=10, fail_ok=False) # Relax atoms.set_calculator(calculator) opt = FIRE(UnitCellFilter(atoms), logfile=None) opt.run(fmax=0.05, steps=200) # Collect results energy = atoms.get_potential_energy() / len(atoms) volume = atoms.get_volume() / len(atoms) successful.append({ 'atoms': atoms, 'energy': energy, 'volume': volume, 'index': i }) energies.append(energy) except Exception as e: failed += 1 continue # Analyze results energies = np.array([s['energy'] for s in successful]) print(f"\nSearch Results:") print(f"Successful: {len(successful)}/{n_searches}") print(f"Failed: {failed}/{n_searches}") print(f"Energy range: {energies.min():.4f} to {energies.max():.4f} eV/atom") print(f"Mean energy: {energies.mean():.4f} ± {energies.std():.4f} eV/atom") # Find lowest energy structure best = min(successful, key=lambda x: x['energy']) print(f"\nLowest energy structure (#{best['index']}):") print(f" Energy: {best['energy']:.4f} eV/atom") print(f" Volume: {best['volume']:.2f} ų/atom") best['atoms'].write('best_structure.xyz') ``` -------------------------------- ### Define Crystalline Seed with Explicit Cell Parameters in Python Source: https://context7.com/zhubonan/airsspy/llms.txt Shows how to create a SeedAtoms template for a crystalline material like Aluminum, specifying explicit cell dimensions and periodic boundary conditions. It also demonstrates setting minimum separation constraints and per-atom parameters, then printing the generated AIRSS input file content. ```python from airsspy import SeedAtoms # Define search seed with explicit cell seed = SeedAtoms('Al', cell=[2, 2, 2], pbc=True) seed.gentags.minsep = 1.5 # Minimum separation constraint # Set per-atom parameters al_atom = seed[0] al_atom.num = 8 # Request 8 aluminum atoms # View the generated seed file content seed_content = '\n'.join(seed.get_cell_inp_lines()) print(seed_content) # Output: # %BLOCK lattice_cart # 2.0000000000 0.0000000000 0.0000000000 # 0.0000000000 2.0000000000 0.0000000000 # 0.0000000000 0.0000000000 2.0000000000 # %ENDBLOCK lattice_cart # %BLOCK positions_abs # Al 0.0000000000 0.0000000000 0.0000000000 # Al0 %NUM=8 # %ENDBLOCK positions_abs # #MINSEP=1.5 ``` -------------------------------- ### Structure Relaxation with ASE Calculators and Optimizers in Python Source: https://context7.com/zhubonan/airsspy/llms.txt Presents a Python function utilizing airsspy and ASE to perform structure prediction workflows. It demonstrates generating a random structure from a seed, setting up a LennardJones calculator, and using an optimizer (BFGSLineSearch with UnitCellFilter) to relax both atomic positions and the unit cell. ```python from airsspy import SeedAtoms from ase.calculators.lj import LennardJones from ase.optimize import BFGSLineSearch from ase.constraints import UnitCellFilter # Define search seed seed = SeedAtoms('Al', cell=[2, 2, 2], pbc=True) seed.gentags.minsep = 1.5 seed[0].num = 8 # Setup calculator calc = LennardJones(sigma=2, epsilon=1, rc=2.5) # Function to generate and relax structures def generate_and_relax(seed, calculator, optimizer_class): # Generate random structure atoms = seed.build_random_atoms() if atoms is None: return None atoms.set_pbc(True) atoms.set_calculator(calculator) # Optimize structure and cell optimizer = optimizer_class(UnitCellFilter(atoms), logfile=None) optimizer.run(fmax=0.05) return atoms ``` -------------------------------- ### Configure Advanced Search Scenarios with AIRSSpy SeedAtoms Source: https://context7.com/zhubonan/airsspy/llms.txt This Python code demonstrates configuring advanced structure search scenarios in AIRSSpy, including settings for surface, cluster, molecular crystal, and constrained cell searches. It utilizes the `gentags` attribute of `SeedAtoms` to specify various search modes and constraints. ```python from airsspy import SeedAtoms # Surface structure search seed = SeedAtoms('Ti2O4', cell=[8, 8, 15], pbc=True) seed.gentags.surface = True # Enable surface mode seed.gentags.vacuum = 10.0 # Add vacuum layer seed.gentags.slab = 'z' # Define slab orientation seed.gentags.width = 2.0 # Confining width # Cluster search cluster_seed = SeedAtoms('Au20', cell=[20, 20, 20], pbc=True) cluster_seed.gentags.cluster = True # Enable cluster mode cluster_seed.gentags.sphere = 5.0 # Confining sphere radius cluster_seed.gentags.minsep = 2.5 # Molecular crystal search mol_seed = SeedAtoms('C6H12', cell=[10, 10, 10], pbc=True) mol_seed.gentags.molecules = True # Treat as molecules mol_seed.gentags.flip = True # Allow mirror reflections mol_seed.gentags.nform = (2, 4) # Number of formula units # Constrained cell search const_seed = SeedAtoms('Fe8O12', cell=[7, 7, 12], pbc=True) const_seed.gentags.cfix = True # Fix c-axis const_seed.gentags.abfix = True # Fix a and b axes const_seed.gentags.slack = (0.1, 0.5) # Relax MINSEP constraints const_seed.gentags.overlap = 0.1 # Overlap threshold ``` -------------------------------- ### Generate Structures with AIRSS Configurations (Python) Source: https://context7.com/zhubonan/airsspy/llms.txt This snippet demonstrates how to generate random atomic structures using the `airsspy` library with various seed configurations. It iterates through different seed types and attempts to build random atoms, printing the chemical formula and volume of successful generations. This is useful for initial exploration of possible structures. ```python from airsspy import SeedAtoms # Assuming seed, cluster_seed, mol_seed, const_seed are SeedAtoms objects # Example initialization (replace with actual seed objects): seed = SeedAtoms('Cu8') cluster_seed = SeedAtoms('Fe13') mol_seed = SeedAtoms('H2O') const_seed = SeedAtoms('NaCl') for search_seed in [seed, cluster_seed, mol_seed, const_seed]: result = search_seed.build_random_atoms(timeout=20, fail_ok=True) if result: print(f"Generated: {result.get_chemical_formula()}, " f"V={{result.get_volume():.2f}} ų") ``` -------------------------------- ### Perform Multiple Searches and Analyze Symmetries with AIRSSpy and spglib Source: https://context7.com/zhubonan/airsspy/llms.txt This code snippet demonstrates how to perform multiple structure searches using AIRSSpy, collect the results, and then analyze their symmetries using the spglib library. It includes generating relaxed structures, extracting energies and volumes, and identifying unique space groups. ```python results = [] for i in range(20): relaxed = generate_and_relax(seed, calc, BFGSLineSearch) if relaxed: results.append(relaxed) energy = relaxed.get_potential_energy() volume = relaxed.get_volume() print(f"Structure {i+1}: E={energy:.4f} eV, V={volume:.2f} ų") from spglib import get_spacegroup symmetries = [get_spacegroup(atoms, symprec=0.5) for atoms in results] print(f"\nFound symmetries: {set(symmetries)}") ``` -------------------------------- ### Extract and Save Structure Information in AIRSS RES Format Source: https://context7.com/zhubonan/airsspy/llms.txt This Python code illustrates how to work with AIRSS RES files using `airsspy.restools`. It covers extracting detailed information from an existing RES file (UID, pressure, volume, enthalpy, symmetry, etc.) and saving a relaxed structure into the RES format with associated metadata. ```python from airsspy.restools import extract_res, save_airss_res from ase import Atoms # Extract information from existing RES file res_info = extract_res('structure-1234-56.res') print(f"UID: {res_info['uid']}") print(f"Pressure: {res_info['P']} GPa") print(f"Volume: {res_info['V']} ų") print(f"Enthalpy: {res_info['H']} eV") print(f"Number of atoms: {res_info['nat']}") print(f"Space group: {res_info['sym']}") print(f"Remarks: {res_info['rem']}") # Save relaxed structure in RES format from ase.io import read relaxed_atoms = read('relaxed_structure.xyz') info_dict = { 'uid': 'Si-12345-1', 'P': 0.0, # Pressure in GPa 'V': relaxed_atoms.get_volume(), 'H': relaxed_atoms.get_potential_energy(), 'nat': len(relaxed_atoms), 'sym': 'Fd-3m', # Space group 'rem': ['Relaxed with LJ potential', 'fmax=0.01'] } save_airss_res( relaxed_atoms, info_dict, fname='Si-12345-1.res', force_write=True ) print("Structure saved in AIRSS RES format") ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.