From 5bee735ef84e3ef362a10709f9c82cb2a52bcb3a Mon Sep 17 00:00:00 2001 From: Markus Scheidgen <markus.scheidgen@gmail.com> Date: Fri, 16 Apr 2021 14:55:19 +0200 Subject: [PATCH] Added support for latest optimade features. --- = | 7 +++++++ nomad/app/optimade/filterparser.py | 4 +++- nomad/datamodel/optimade.py | 1 + tests/app/flask/utils.py | 4 +++- tests/app/test_optimade.py | 6 ++++-- 5 files changed, 18 insertions(+), 4 deletions(-) create mode 100644 = diff --git a/= b/= new file mode 100644 index 0000000000..9b92bcf0f4 --- /dev/null +++ b/= @@ -0,0 +1,7 @@ +============================= test session starts ============================== +platform darwin -- Python 3.7.7, pytest-3.10.0, py-1.10.0, pluggy-0.13.1 -- /Users/markus/Documents/Projects/nomad-fairdi/.pyenv/bin/python +cachedir: .pytest_cache +rootdir: /Users/markus/Documents/Projects/nomad-fairdi/tests, inifile: pytest.ini +plugins: celery-4.4.7, cov-2.7.1, timeout-1.4.2 +collecting ... +========================= no tests ran in 0.01 seconds ========================= diff --git a/nomad/app/optimade/filterparser.py b/nomad/app/optimade/filterparser.py index f233403361..2cab798bd6 100644 --- a/nomad/app/optimade/filterparser.py +++ b/nomad/app/optimade/filterparser.py @@ -17,7 +17,7 @@ # from typing import Dict -from elasticsearch_dsl import Q +from elasticsearch_dsl import Q, Date from cachetools import cached from optimade.filterparser import LarkParser @@ -49,6 +49,8 @@ def _get_transformer(nomad_properties, without_prefix): quantities['id'] = Quantity('id', es_field='calc_id') quantities['immutable_id'] = Quantity('immutable_id', es_field='calc_id') + quantities['last_modified'] = Quantity( + 'last_modified', es_field='upload_time', elastic_mapping_type=Date) quantities['elements'].length_quantity = quantities['nelements'] quantities['elements'].has_only_quantity = Quantity(name='only_atoms') diff --git a/nomad/datamodel/optimade.py b/nomad/datamodel/optimade.py index b617069a14..b42b5e0b9a 100644 --- a/nomad/datamodel/optimade.py +++ b/nomad/datamodel/optimade.py @@ -240,6 +240,7 @@ class OptimadeEntry(MSection): species_at_sites = Quantity( type=str, shape=['nsites'], links=optimade_links('h.6.2.12'), + a_search=Search(), a_optimade=Optimade(query=False, entry=True, sortable=False, type='list'), description=''' Name of the species at each site (where values for sites are specified with the same order of the cartesian_site_positions property). The properties of the species are diff --git a/tests/app/flask/utils.py b/tests/app/flask/utils.py index 3e20e664ef..02268e90f3 100644 --- a/tests/app/flask/utils.py +++ b/tests/app/flask/utils.py @@ -18,6 +18,7 @@ from typing import List import numpy as np +import datetime from nomad import processing, files from nomad.datamodel import EntryMetadata, MongoMetadata, EntryArchive @@ -102,7 +103,8 @@ class Upload(): entry_metadata.m_update( domain='dft', upload_id=self.upload_id, calc_id='test_calc_id_%d' % id, - mainfile='test_mainfile', published=True, processed=True, with_embargo=False) + mainfile='test_mainfile', published=True, processed=True, with_embargo=False, + upload_time=datetime.datetime.now()) entry_metadata.apply_domain_metadata(archive) diff --git a/tests/app/test_optimade.py b/tests/app/test_optimade.py index 77eea728df..b684da761e 100644 --- a/tests/app/test_optimade.py +++ b/tests/app/test_optimade.py @@ -60,7 +60,7 @@ def example_structures(elastic_infra, mongo_infra, raw_files_infra): upload.create_test_structure(1, 2, 1, [], 0) upload.create_test_structure(2, 2, 1, ['C'], 0) upload.create_test_structure(3, 2, 1, [], 1) - upload.create_test_structure(4, 1, 1, [], 0) + upload.create_test_structure(4, 1, 1, [], 0, metadata=dict(upload_time='1978-04-08T10:10:00Z')) upload.create_upload_files() search.refresh() @@ -126,7 +126,9 @@ def example_structures(elastic_infra, mongo_infra, raw_files_infra): ('nelements LENGTH = 1', -1), ('LENGTH nelements = 1', -1), ('chemical_formula_anonymous starts with "A"', -1), - ('elements HAS ONY "H", "O"', -1) + ('elements HAS ONY "H", "O"', -1), + ('last_modified >= "2009-02-01T20:07:00Z"', 3), + ('species_at_sites HAS "C"', 1) ]) def test_optimade_parser(example_structures, query, results): if results >= 0: -- GitLab