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
---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
Cell In[1], line 1
----> 1 from atomrdf import KnowledgeGraph
      2 import atomrdf.build as build
      3 
      4 from ase.visualize import view

File ~/checkouts/readthedocs.org/user_builds/pyscal-rdf/conda/latest/lib/python3.11/site-packages/atomrdf/__init__.py:21
      1 """atomRDF — ontology-based knowledge graphs for atomistic simulation data.
      2 
      3 atomRDF combines `pyscal3 <https://github.com/pyscal/pyscal3>`_,
   (...)     17 documentation at https://atomrdf.pyscal.org.
     18 """
     20 from atomrdf._version import __version__
---> 21 from atomrdf.graph import KnowledgeGraph
     22 from atomrdf.io.workflow_parser import WorkflowParser
     24 __all__ = [
     25     "__version__",
     26     "KnowledgeGraph",
     27     "WorkflowParser",
     28 ]

File ~/checkouts/readthedocs.org/user_builds/pyscal-rdf/conda/latest/lib/python3.11/site-packages/atomrdf/graph.py:46
     44 from atomrdf.stores import create_store, purge
     45 import atomrdf.json_io as json_io
---> 46 import atomrdf.mp as amp
     49 from atomrdf.namespace import (
     50     CMSO,
     51     PLDO,
   (...)     56     Literal,
     57 )
     59 # read element data file

File ~/checkouts/readthedocs.org/user_builds/pyscal-rdf/conda/latest/lib/python3.11/site-packages/atomrdf/mp.py:5
      1 """
      2 Wrapper around Materials Project to query structures and get it as a KG
      3 """
----> 5 from mp_api.client import MPRester
      6 import numpy as np
      8 def query_mp(api_key, chemical_system=None, material_ids=None, is_stable=True):

ModuleNotFoundError: No module named 'mp_api'
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)

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