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/15c872721527724bd50b0b866b3a77fffbe28561b3e5eb42f7cb3a458bfe930f.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/ded6eb67473614a94ce4b1b5e2558fb04348a0be8864dc726ac1ed69a387798b.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:461647f1-f75a-4af4-b2d1-5a30e837a269 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:29ce9ade-d71c-4e76-abfe-4e61caa072d9 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