Point defects: vacancies, interstitials, substitutionals#

atomRDF can build common point defects on top of any bulk structure and annotate them with the PODO (Point-Defect Ontology) terms, so they can be queried later just like any other sample.

In this notebook we will:

  1. Build a bulk Fe matrix.

  2. Add a vacancy, an interstitial and a substitutional defect.

  3. Use the term-builder to query the graph for samples that contain a specific defect type.

from atomrdf import KnowledgeGraph
import atomrdf.build as build
---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
Cell In[1], line 1
----> 1 from atomrdf import KnowledgeGraph
      2 import atomrdf.build as build

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()

1. The pristine matrix#

bulk_fe = build.bulk("Fe", cubic=True, repeat=3, graph=kg)

2. Vacancy#

Remove one atom at random; the resulting sample is annotated as a podo:Vacancy.

vac = build.defect.vacancy(
    "Fe",
    no_of_vacancies=1,
    crystalstructure="bcc",
    cubic=True,
    repeat=3,
    graph=kg,
)

3. Octahedral self-interstitial#

inter = build.defect.interstitial(
    bulk_fe,
    element="Fe",
    void_type="octahedral",
    number=1,
    graph=kg,
)

4. Substitutional Cr atom#

sub = build.defect.substitutional(
    bulk_fe,
    element="Cr",
    number=1,
    graph=kg,
)

5. Browse and query#

How many samples are now in the graph?

kg.n_samples

Find all samples that contain a vacancy (PODO term). The fluent term builder kg.terms.podo.Vacancy makes the SPARQL implicit when the ontology network is available; otherwise the equivalent SPARQL works everywhere.

q = """
PREFIX podo: <http://purls.helmholtz-metadaten.de/podo/>
PREFIX cmso: <http://purls.helmholtz-metadaten.de/cmso/>
SELECT DISTINCT ?sample
WHERE {
    ?sample cmso:hasMaterial/cmso:hasDefect ?d .
    ?d a podo:Vacancy .
}
"""
kg.query(q)

Now ask for substitutional defects:

q = """
PREFIX podo: <http://purls.helmholtz-metadaten.de/podo/>
PREFIX cmso: <http://purls.helmholtz-metadaten.de/cmso/>
SELECT DISTINCT ?sample
WHERE {
    ?sample cmso:hasMaterial/cmso:hasDefect ?d .
    ?d a podo:SubstitutionalDefect .
}
"""
kg.query(q)

Persist the whole defect mini-database to Turtle so it can be reloaded or shared.

kg.write("defects.ttl", format="ttl")