diff --git a/nomad/datamodel/dft.py b/nomad/datamodel/dft.py index 4fd6905f8a4b04a467af42cdb4d3218a5987f672..d2ca7cb930638b5175f4d98a6f4697ad15cc99a1 100644 --- a/nomad/datamodel/dft.py +++ b/nomad/datamodel/dft.py @@ -18,7 +18,7 @@ DFT specific metadata from typing import List import re -from elasticsearch_dsl import Integer, Object, InnerDoc +from elasticsearch_dsl import Integer, Object, InnerDoc, Keyword import ase.data from nomadcore.local_backend import ParserEvent @@ -82,9 +82,15 @@ class Label(MSection): m_def = Section(a_elastic=dict(type=InnerDoc)) - label = Quantity(type=str) - type = Quantity(type=MEnum('compound_class', 'classification', 'prototype', 'prototype_id')) - source = Quantity(type=MEnum('springer', 'aflow_prototype_library')) + label = Quantity(type=str, a_elastic=dict(type=Keyword)) + + type = Quantity(type=MEnum( + 'compound_class', 'classification', 'prototype', 'prototype_id'), + a_elastic=dict(type=Keyword)) + + source = Quantity( + type=MEnum('springer', 'aflow_prototype_library'), + a_elastic=dict(type=Keyword)) ESLabel = elastic_mapping(Label.m_def, InnerDoc) @@ -253,6 +259,13 @@ def only_atoms(atoms): return ''.join(only_atoms) +def _elastic_label_value(label): + if isinstance(label, str): + return label + else: + return elastic_obj(label, ESLabel) + + Domain( 'DFT', DFTCalcWithMetadata, quantities=dict( @@ -304,7 +317,7 @@ Domain( 'Search based for springer classification and aflow prototypes', elastic_field='labels.label', elastic_mapping=Object(ESLabel), - elastic_value=lambda labels: [elastic_obj(label, ESLabel) for label in labels], + elastic_value=lambda labels: [_elastic_label_value(label) for label in labels], multi=True), optimade=DomainQuantity( 'Search based on optimade\'s filter query language', diff --git a/nomad/search.py b/nomad/search.py index 7e3e6080658845b351c4c19f3b0df68380c266e7..859308bcebe58f83ad7254b657b012a46034f4cd 100644 --- a/nomad/search.py +++ b/nomad/search.py @@ -158,9 +158,8 @@ class Entry(Document, metaclass=WithDomain): self.external_id = source.external_id for quantity in datamodel.Domain.instance.domain_quantities.values(): - setattr( - self, quantity.name, - quantity.elastic_value(getattr(source, quantity.metadata_field))) + quantity_value = quantity.elastic_value(getattr(source, quantity.metadata_field)) + setattr(self, quantity.name, quantity_value) def delete_upload(upload_id): diff --git a/tests/app/test_api.py b/tests/app/test_api.py index d5b9c6e443ac82735ca5a2d58600856482b51a5f..8da6e5e8feedc9709f2a9bb2746a81b2bc626c5a 100644 --- a/tests/app/test_api.py +++ b/tests/app/test_api.py @@ -1078,9 +1078,9 @@ class TestRepo(): data = json.loads(rv.data) assert data['pagination']['total'] > 0 - def test_label(self, api, non_empty_processed, test_user_auth): + def test_labels(self, api, non_empty_processed, test_user_auth): rv = api.get( - '/repo/?%s' % urlencode(dict(owner='all', label=['oxide', 'metal']), doseq=True), + '/repo/?%s' % urlencode(dict(owner='all', labels=['nonmetal', 'semiconductor']), doseq=True), headers=test_user_auth) assert rv.status_code == 200 data = json.loads(rv.data) diff --git a/tests/data/proc/examples_template.zip b/tests/data/proc/examples_template.zip index 4fb6efc6a809584d3caa0ef6a6164d818985b0c9..be5b6bc8c6093ca01f808c71c346746102e9e153 100644 Binary files a/tests/data/proc/examples_template.zip and b/tests/data/proc/examples_template.zip differ diff --git a/tests/data/proc/examples_template/template.json b/tests/data/proc/examples_template/template.json index a53ec20df94bb3040e6a56a80d380330572cfb44..43f367e7c068c98c6a6b371692c130e7446e1683 100644 --- a/tests/data/proc/examples_template/template.json +++ b/tests/data/proc/examples_template/template.json @@ -27,19 +27,19 @@ "_gIndex": 0, "simulation_cell": [ [ - 5.76372622e-10, - 0.0, + 2.732389e-10, + -2.732389e-10, 0.0 ], [ + -2.732389e-10, 0.0, - 5.76372622e-10, - 0.0 + -2.732389e-10 ], [ - 0.0, - 0.0, - 4.0755698899999997e-10 + 2.732389e-10, + 2.732389e-10, + 0.0 ] ], "configuration_periodic_dimensions": [ @@ -49,29 +49,15 @@ ], "atom_positions": [ [ - 2.88186311e-10, - 0.0, - 2.0377849449999999e-10 + 0.0, 0.0, 0.0 ], [ - 0.0, - 2.88186311e-10, - 2.0377849449999999e-10 - ], - [ - 0.0, - 0.0, - 0.0 - ], - [ - 2.88186311e-10, - 2.88186311e-10, - 0.0 + 1.3661901828253802e-10, + -1.36619021014927e-10, + -1.36619021014927e-10 ] ], "atom_labels": [ - "Br", - "K", "Si", "Si" ] @@ -95,7 +81,6 @@ "sampling_method": "geometry_optimization" } ], -UNPARSABLE "section_frame_sequence": [ { "_name": "section_frame_sequence",