Commit 0cb7bc99 authored by Markus Scheidgen's avatar Markus Scheidgen
Browse files

Added URL provider specific fiels to optimade.

parent 8cf02ca2
Pipeline #108832 passed with stages
in 25 minutes and 33 seconds
......@@ -14,7 +14,7 @@ from optimade.models import StructureResource, StructureResourceAttributes
from optimade.models.utils import OptimadeField, SupportLevel
from optimade.server.schemas import ENTRY_INFO_SCHEMAS
from nomad import datamodel, files, search, utils, metainfo
from nomad import datamodel, files, search, utils, metainfo, config
from nomad.normalizing.optimade import (
optimade_chemical_formula_reduced, optimade_chemical_formula_anonymous,
optimade_chemical_formula_hill)
......@@ -28,6 +28,24 @@ float64 = np.dtype('float64')
class StructureResourceAttributesByAlias(StructureResourceAttributes):
nmd_entry_page_url: Optional[str] = OptimadeField(
None,
alias='_nmd_entry_page_url',
description='The url for the NOMAD gui entry page for this structure.',
support=SupportLevel.OPTIONAL)
nmd_raw_file_download_url: Optional[str] = OptimadeField(
None,
alias='_nmd_raw_file_download_url',
description='The url to download all calculation raw files as .zip file.',
support=SupportLevel.OPTIONAL)
nmd_archive_url: Optional[str] = OptimadeField(
None,
alias='_nmd_archive_url',
description='The url to the NOMAD archive json of this structure.',
support=SupportLevel.OPTIONAL)
def dict(self, *args, **kwargs):
kwargs['by_alias'] = True
return super().dict(*args, **kwargs)
......@@ -195,6 +213,18 @@ class StructureCollection(EntryCollection):
if not request_field.startswith('_nmd_'):
continue
if request_field == '_nmd_archive_url':
attrs[request_field] = config.api_url() + f'/archive/{upload_id}/{calc_id}'
continue
if request_field == '_nmd_entry_page_url':
attrs[request_field] = config.gui_url(f'entry/id/{upload_id}/{calc_id}')
continue
if request_field == '_nmd_raw_file_download_url':
attrs[request_field] = config.api_url() + f'/raw/calc/{upload_id}/{calc_id}'
continue
try:
if request_field.startswith('_nmd_dft_'):
attrs[request_field] = getattr(entry.dft, request_field[9:])
......
......@@ -290,10 +290,11 @@ def test_nmd_properties_info(client):
assert '_nmd_dft_system' in data['data']['properties']
assert '_nmd_encyclopedia_material_formula' in data['data']['properties']
assert '_nmd_atoms' in data['data']['properties']
assert '_nmd_archive_url' in data['data']['properties']
def test_nmd_properties(client, example_structures):
rv = client.get('/optimade/structures/%s' % 'test_calc_id_1?response_fields=_nmd_atoms,_nmd_dft_system,_nmd_doesnotexist')
rv = client.get('/optimade/structures/%s' % 'test_calc_id_1?response_fields=_nmd_atoms,_nmd_dft_system,_nmd_doesnotexist,_nmd_archive_url')
assert rv.status_code == 200
data = rv.json()
assert data.get('data') is not None
......@@ -302,6 +303,7 @@ def test_nmd_properties(client, example_structures):
assert attr.get('_nmd_atoms') == ['H', 'O']
assert '_nmd_dft_system' in attr
assert '_nmd_doesnotexist' not in attr
assert '_nmd_archive_url' in attr
def test_nmd_properties_include_all(client, example_structures):
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment