diff --git a/examples/tutorials/api_with_archive_query.py b/examples/tutorials/api_with_archive_query.py new file mode 100644 index 0000000000000000000000000000000000000000..9074a35245400b2ddf74130e91cd1c79fad83a5f --- /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 0000000000000000000000000000000000000000..9e83e24a4eb73fb6592e6153a2c01545e7c12103 --- /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'])