Skip to main content

Grain boundary generation code with pymatgen/ASE output support (fork of GB_code)

Project description

GB_code DOI DOI

A Python package for creating orthogonal grain boundary supercells for atomistic calculations. Based on the coincident site lattice (CSL) formulation for cubic materials (sc, bcc, fcc, diamond).

Structures can be exported to pymatgen Structure, ASE Atoms, LAMMPS or VASP file formats.

For more details please read the paper.

Installation

pip install .

With optional pymatgen/ASE support:

pip install ".[all]"      # both pymatgen and ASE
pip install ".[pymatgen]"  # pymatgen only
pip install ".[ase]"       # ASE only

Requirements: Python >= 3.5.1, numpy >= 1.14.

Quick start (Python API)

The new v2 API separates structure building from export, so you can work with GB structures programmatically without writing intermediate files.

from gb_code.gb_generator import GB_character

# 1. Set up the GB: Sigma-5 [1,0,0] fcc Al, (0,3,1) symmetric tilt
gb = GB_character()
gb.ParseGB(axis=[1, 0, 0], basis='fcc', LatP=4.05, m=2, n=1, gb=[0, 3, 1])

# 2. Build the bicrystal unit cells
gb.CSL_Bicrystal_Atom_generator()

# 3. Build the supercell (remove overlapping atoms, expand)
gb.build(overlap=0.0, whichG='g1', dim=[2, 1, 1])

# 4. Export to pymatgen or ASE
structure = gb.to_pymatgen(element='Al')   # pymatgen Structure
atoms = gb.to_ase(element='Al')            # ASE Atoms

# Or write files directly
gb.write_lammps('my_gb.lammps')
gb.write_vasp('POSCAR_gb')

Each exported structure carries grain membership labels (grain_id = 1 or 2), making it easy to distinguish the two grains for analysis or visualisation.

A complete worked example is in examples/minimal_gb_example.ipynb.

In-plane rigid body translations

To scan microscopic degrees of freedom (rigid body translations on the GB plane), use the standalone inplane_shift module:

from gb_code.gb_generator import GB_character
from gb_code.inplane_shift import generate_shifts, apply_shift, get_all_shifted_structures

# Build GB as above ...
gb = GB_character()
gb.ParseGB([1, 0, 0], 'fcc', 4.05, 2, 1, [0, 3, 1])
gb.CSL_Bicrystal_Atom_generator()
gb.build(overlap=0.3, whichG='g1', dim=[2, 1, 1])

# Get all shift vectors on a 10x5 grid
shifts = generate_shifts(gb, a=10, b=5)

# Apply one shift and get a pymatgen Structure
struct = apply_shift(gb, shifts[0], output='pymatgen', element='Al')

# Or get all 50 shifted structures at once
all_structs = get_all_shifted_structures(gb, a=10, b=5, output='pymatgen', element='Al')

Command-line usage (legacy workflow)

The original CLI workflow is still fully supported.

Step 1: Find CSL sigma values

csl_generator.py 1 1 1 50

   List of possible CSLs for [1 1 1] axis sorted by Sigma
Sigma:     1  Theta:   0.00
Sigma:     3  Theta:  60.00
Sigma:     7  Theta:  38.21
Sigma:    13  Theta:  27.80
...

Step 2: List GB planes for a given sigma

csl_generator.py 1 1 1 diamond 13

----------List of possible CSL planes for Sigma 13---------
 GB1-------------------GB2-------------------Type----------Number of Atoms
[ 2  1 -2]             [ 1  2 -2]             Mixed                  3744
[-1 -1 -1]             [-1 -1 -1]             Twist                  1248
[ 1  3 -4]             [-1  4 -3]             Symmetric Tilt         1248
...

This writes an io_file (YAML) with your chosen axis, basis and sigma.

Step 3: Customise the io_file

## input parameters for gb_generator.py ###
GB_plane: [2, 1, -2]
lattice_parameter: 4
overlap_distance: 0.3
which_g: g1
rigid_trans: no
a: 10
b: 5
dimensions: [1,1,1]
File_type: LAMMPS

# Written by csl_generator — do not change:
axis: [1, 1, 1]
m: 7
n: 1
basis: diamond

Step 4: Generate the GB structure

gb_generator.py io_file
<<------ 32 atoms are being removed! ------>>
<<------ 1 GB structure is being created! ------>>

Key parameters

Parameter Description
axis Rotation axis, e.g. [1,0,0], [1,1,0], [1,1,1]
basis Crystal structure: fcc, bcc, sc, or diamond
LatP Lattice parameter in Angstrom
m, n Integers that define the CSL sigma and rotation angle
gbplane GB plane (Miller indices), chosen from the CSL plane list
overlap Fraction of lattice parameter; atoms closer than this across the GB are removed
whichG Which grain to remove overlapping atoms from (g1 or g2)
dim Supercell dimensions [dimX, dimY, dimZ]. Make dimX large enough so the GB and its periodic image don't interact

Notes on energy minimisation

To find the minimum-energy GB structure, microscopic degrees of freedom must be explored:

  1. Atom removal: set overlap > 0 to delete atoms that are too close across the GB plane.
  2. Rigid body translations: scan in-plane shifts using inplane_shift. A 10x5 grid (50 structures) is typically sufficient for fcc metals.

A typical LAMMPS minimisation protocol: conjugate gradient on atoms, then on the box, then on atoms again — followed by NVT annealing and damped dynamics.

Jupyter notebooks

Citation

If you find this code useful, please cite:

Hadian et al., (2018). GB code: A grain boundary generation code. Journal of Open Source Software, 3(29), 900. https://doi.org/10.21105/joss.00900

License

MIT.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lz_gb_code-0.1.0.tar.gz (29.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

lz_gb_code-0.1.0-py3-none-any.whl (23.6 kB view details)

Uploaded Python 3

File details

Details for the file lz_gb_code-0.1.0.tar.gz.

File metadata

  • Download URL: lz_gb_code-0.1.0.tar.gz
  • Upload date:
  • Size: 29.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for lz_gb_code-0.1.0.tar.gz
Algorithm Hash digest
SHA256 7f61783a7dd04eb8f46a1c4cbd7d334f9b82634ad34fac80b43b2faf95fbc84d
MD5 c2838fca6d76c516dcc7698d4f52ecc3
BLAKE2b-256 2995ea281e513eac9a8971015a5751d215c11bda1f5444ef71096b7801009030

See more details on using hashes here.

Provenance

The following attestation bundles were made for lz_gb_code-0.1.0.tar.gz:

Publisher: publish.yml on ligerzero-ai/GB_code

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file lz_gb_code-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: lz_gb_code-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 23.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for lz_gb_code-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cc1f16a66050c737e9ad661724b812f7741a8246a70f2d7522ce7aa1379b311d
MD5 2eafd4f4be7a8bba516b3f2dc042f155
BLAKE2b-256 7c61d3cd6c1118dd7501772745700437e9fd35e55dcc979dcd23fed5cce77a1d

See more details on using hashes here.

Provenance

The following attestation bundles were made for lz_gb_code-0.1.0-py3-none-any.whl:

Publisher: publish.yml on ligerzero-ai/GB_code

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page