From aeffb12e35a80ebd36b7480e2972f903cf110ff0 Mon Sep 17 00:00:00 2001
From: Markus Scheidgen <markus.scheidgen@gmail.com>
Date: Mon, 28 Sep 2020 16:11:49 +0200
Subject: [PATCH] Added some tutorial examples.

---
 examples/tutorials/api_with_archive_query.py | 26 ++++++++++++++++++++
 examples/tutorials/api_with_requests.py      | 26 ++++++++++++++++++++
 2 files changed, 52 insertions(+)
 create mode 100644 examples/tutorials/api_with_archive_query.py
 create mode 100644 examples/tutorials/api_with_requests.py

diff --git a/examples/tutorials/api_with_archive_query.py b/examples/tutorials/api_with_archive_query.py
new file mode 100644
index 0000000000..9074a35245
--- /dev/null
+++ b/examples/tutorials/api_with_archive_query.py
@@ -0,0 +1,26 @@
+'''
+A simple example used in the NOMAD webinar API tutorial
+'''
+
+from nomad.client import ArchiveQuery
+
+query = ArchiveQuery(
+    url='http://labdev-nomad.esc.rzg.mpg.de/fairdi/nomad/reprocess/api',
+    query={
+        'dft.code_name': 'VASP',
+        'atoms': ['Ti', 'O']
+    },
+    required={
+        'section_run': {
+            'section_single_configuration_calculation[-1]': {
+                'energy_total': '*',
+                'section_dos': '*'
+            }
+        }
+    },
+    parallel=1,
+    max=10)
+
+print(query)
+result = query[0]
+print(result.section_run[0].section_single_configuration_calculation[-1].section_dos[0].dos_energies)
diff --git a/examples/tutorials/api_with_requests.py b/examples/tutorials/api_with_requests.py
new file mode 100644
index 0000000000..9e83e24a4e
--- /dev/null
+++ b/examples/tutorials/api_with_requests.py
@@ -0,0 +1,26 @@
+# type: ignore
+
+'''
+A simple example used in the NOMAD webinar API tutorial
+'''
+
+import requests
+import json
+
+base_url = 'http://nomad-lab.eu/prod/rae/api'
+
+# response = requests.get(base_url + '/repo?datasets.name=NOMAD%20webinar')
+response = requests.get(
+    base_url + '/repo',
+    params={'datasets.name': 'NOMAD webinar', 'per_page': 1})
+
+data = response.json()
+upload_id = data['results'][0]['upload_id']
+calc_id = data['results'][0]['calc_id']
+
+response = requests.get(
+    base_url + '/archive/%s/%s' % (upload_id, calc_id))
+
+print(json.dumps(response.json(), indent=2))
+print(
+    response.json()['section_run'][0]['section_single_configuration_calculation'][-1]['section_dos'][0]['dos_energies'])
-- 
GitLab