Commit 2b4b3485 authored by Markus Scheidgen's avatar Markus Scheidgen
Browse files

Fixed labels index and search.

parent 6fd37790
Pipeline #68885 failed with stages
in 14 minutes and 17 seconds
......@@ -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',
......
......@@ -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):
......
......@@ -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)
......
......@@ -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",
......
Markdown is supported
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