Getting started#

Ontology based atomic structure creation, manipulation, querying.

Imports

from atomrdf import KnowledgeGraph, System

The initial step is to create a Knowledge Graph

kg = KnowledgeGraph(enable_log=True)

Creation of structures#

We will create three structures for the demonstration.

First a BCC Iron structure

struct_Fe = System.create.element.Fe(graph=kg)

Note that we passed an argument graph=kg which ensures that when the structure is created, it is also added to the Graph automatically. We can visualise the graph.

kg.visualise(hide_types=True)
../_images/b4c940f2fae25c604d7ddb1c061fb14d5f9e3c76515911fd4e97b4921d7aa014.svg

Now a Si diamond structure

struct_Si = System.create.element.Si(graph=kg)

Finally, an L12 \(Ni_3 Al\) structure

struct_l12 = System.create.lattice.l12(element=['Al', 'Ni'], 
                         lattice_constant=3.57, graph=kg)
kg.visualise(hide_types=True, size=(60,30))
../_images/154cea5c7f5eb4ae3bfb12af4a9d8edf163545373977645754df7f42a71016d3.svg

We can save the graph and reload it as needed

kg.write('serial.ttl', format='ttl')
kg = KnowledgeGraph(graph_file='serial.ttl')
kg.n_samples
3

Querying the graph#

An example question would be, what are the space group of all structures with 4 atoms?

The corresponding SPARQL query looks like this:

query = """
PREFIX cmso: <http://purls.helmholtz-metadaten.de/cmso/>
SELECT DISTINCT ?symbol
WHERE {
    ?sample cmso:hasNumberOfAtoms ?number .
    ?sample cmso:hasMaterial ?material .
    ?material cmso:hasStructure ?structure .
    ?structure cmso:hasSpaceGroupSymbol ?symbol .
FILTER (?number="4"^^xsd:integer)
}"""
res = kg.query(query)

And print the results

res
symbol
0 Pm-3m

The query system can also be used without experience in SPARQL, or deep knowledge about the ontology terms. The same query would be:

kg.query_sample([kg.terms.cmso.hasSpaceGroupSymbol, kg.terms.cmso.hasNumberOfAtoms==4])
AtomicScaleSample hasSpaceGroupSymbolvalue hasNumberOfAtomsvalue
0 sample:09669f97-0715-4322-b7a4-6ff594a9da4a Pm-3m 4

Another one: What are all the samples with Bravais lattice bcc?. First how this looks like:

res = kg.query_sample( 
             [kg.ontology.terms.cmso.hasAltName=='bcc'])
res
AtomicScaleSample hasAltNamevalue
0 sample:843e7581-b2bc-4602-8111-bbb03a03f773 bcc

As expected, there is only one sample, since Fe is the only bcc structure we added. We can extract the sample

sample = res.AtomicScaleSample[0]

We can write this sample to a file, for example, a LAMMPS data format, to use it for further simulations

kg.to_file(sample, 'bcc.data', format="lammps-data")
! more bcc.data
(written by ASE)

2 atoms
1 atom types

0.0      2.8700000000000001  xlo xhi
0.0      2.8700000000000001  ylo yhi
0.0      2.8700000000000001  zlo zhi

Atoms # atomic

     1   1                       0                       0                      
 0
     2   1      1.4350000000000001      1.4350000000000001      1.43500000000000
01

We can also export as an ASE object

aseobj = kg.to_file(sample, format="ase")
aseobj