Creating Grain Boundaries#

In this notebook, creation and querying of GBs are discussed. These features are still under active development.

from atomrdf import KnowledgeGraph
import atomrdf.build as build

from ase.visualize import view
kg = KnowledgeGraph()

We start by creating a \(\Sigma 5 (3 \bar{1} 0)\)

struct_gb_1 = build.defect.grain_boundary(axis=[0,0,1], 
                        sigma=5, 
                        gb_plane=[3, -1, 0],
                        element='Fe',
                        graph=kg)
---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
File ~/checkouts/readthedocs.org/user_builds/pyscal-rdf/conda/latest/lib/python3.11/site-packages/atomrdf/build/defect.py:373, in grain_boundary(element, axis, sigma, gb_plane, crystalstructure, a, b, c, alpha, covera, overlap, gap, vacuum, delete_layer, tolerance, uc_a, uc_b, repeat, graph, primitive)
    372 from pymatgen.io.ase import AseAtomsAdaptor
--> 373 from aimsgb import GrainBoundary as AIMSGrainBoundary
    374 from aimsgb import Grain as AIMSGrain

ModuleNotFoundError: No module named 'aimsgb'

During handling of the above exception, another exception occurred:

ImportError                               Traceback (most recent call last)
Cell In[3], line 1
----> 1 struct_gb_1 = build.defect.grain_boundary(axis=[0,0,1], 
      2                         sigma=5,
      3                         gb_plane=[3, -1, 0],
      4                         element='Fe',

File ~/checkouts/readthedocs.org/user_builds/pyscal-rdf/conda/latest/lib/python3.11/site-packages/atomrdf/build/defect.py:376, in grain_boundary(element, axis, sigma, gb_plane, crystalstructure, a, b, c, alpha, covera, overlap, gap, vacuum, delete_layer, tolerance, uc_a, uc_b, repeat, graph, primitive)
    374     from aimsgb import Grain as AIMSGrain
    375 except ImportError:
--> 376     raise ImportError(
    377         "This function requires the aimsgb and pymatgen packages to be installed"
    378     )
    380 a = _declass(a)
    381 b = _declass(b)

ImportError: This function requires the aimsgb and pymatgen packages to be installed

We can visualise the structure

view(struct_gb_1, viewer='x3d')
ASE atomic visualization

Some other examples, \(\Sigma 3 (1\bar{-1}0)\) and \(\Sigma 19 (111)\)

struct_gb_2 = build.defect.grain_boundary(axis=[1,1,2], 
                        sigma=3, 
                        gb_plane=[1, -1, 0],
                        element='Fe',
                        graph=kg)

struct_gb_3 = build.defect.grain_boundary(axis=[1,1,1], 
                        sigma=19, 
                        gb_plane=[1, 1, 1],
                        element='Fe',
                        graph=kg)

What are all the samples with symmetric tilt grain boundaries?

res = kg.query_sample(kg.ontology.terms.pldo.SymmetricalTiltGrainBoundary)
res
AtomicScaleSample SymmetricalTiltGrainBoundary
0 sample:4878c894-b017-4e05-be07-6669c450888f sample:4878c894-b017-4e05-be07-6669c450888f_Sy...

We see we have one structure in the database. We can also find what is the sigma value of this structure by modifying our query.

res = kg.query_sample([kg.ontology.terms.pldo.SymmetricalTiltGrainBoundary, 
                     kg.ontology.terms.pldo.hasSigmaValue])
res
AtomicScaleSample SymmetricalTiltGrainBoundary hasSigmaValuevalue
0 sample:4878c894-b017-4e05-be07-6669c450888f sample:4878c894-b017-4e05-be07-6669c450888f_Sy... 5

We can choose the sample, and save it

sample = res.AtomicScaleSample[0]
sample
rdflib.term.URIRef('sample:4878c894-b017-4e05-be07-6669c450888f')
kg.to_file(sample, filename="POSCAR", format="vasp")
! head -20 POSCAR
Fe
 1.0000000000000000
    18.1514737693664969   -0.0000000000000006    0.0000000000000000
     0.0000000000000000    9.0757368846832485    0.0000000000000000
     0.0000000000000011    0.0000000000000006    2.8699999999999997
 Fe 
  40
Cartesian
  0.0000000000000000  0.0000000000000000  0.0000000000000000
  2.7227210654049743  0.9075736884683246  0.0000000000000002
  1.8151473769366497  3.6302947538732990  0.0000000000000003
  0.9075736884683242  6.3530158192782737  0.0000000000000004
  5.4454421308099485  1.8151473769366493  0.0000000000000004
  4.5378684423416242  4.5378684423416233  0.0000000000000006
  3.6302947538732995  7.2605895077465981  0.0000000000000007
  8.1681631962149215  2.7227210654049738  0.0000000000000007
  7.2605895077465972  5.4454421308099477  0.0000000000000008
  6.3530158192782693  8.1681631962149215  0.0000000000000009
  0.9075736884683249  1.8151473769366495  1.4350000000000001
  3.6302947538732990  2.7227210654049743  1.4350000000000003