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

Removed old m_x function calls.

parent 249559b5
Pipeline #70283 passed with stages
in 23 minutes and 32 seconds
......@@ -406,7 +406,7 @@ class EditRepoCalcsResource(Resource):
if quantity is None:
abort(400, 'Unknown quantity %s' % action_quantity_name)
quantity_flask = quantity.m_x('flask', {})
quantity_flask = quantity.m_get_annotations('flask', {})
if quantity_flask.get('admin_only', False):
if not g.user.is_admin():
abort(404, 'Only the admin user can set %s' % quantity.name)
......
......@@ -29,7 +29,7 @@ class FilterException(Exception):
quantities: Dict[str, Quantity] = {
q.name: Quantity(
q.name, es_field='dft.optimade.%s' % q.name,
elastic_mapping_type=q.m_x('search').mapping.__class__)
elastic_mapping_type=q.a_search.mapping.__class__)
for q in OptimadeEntry.m_def.all_quantities.values()
if 'search' in q.m_annotations}
......
......@@ -2,7 +2,7 @@ from ase.data import chemical_symbols
from elasticsearch_dsl import Keyword, Float, InnerDoc, Nested
import numpy as np
from nomad.metainfo import MSection, Section, Quantity, SubSection, MEnum, units
from nomad.metainfo import MSection, Section, Quantity, SubSection, MEnum, units, DefinitionAnnotation
from nomad.metainfo.search_extension import Search
......@@ -25,7 +25,7 @@ class ElementRatio(InnerDoc):
for i in range(0, entry.nelements)]
class Optimade():
class Optimade(DefinitionAnnotation):
def __init__(self, query: bool = False, entry: bool = False):
pass
......
......@@ -297,4 +297,6 @@ from .metainfo import (
MResource,
m_package,
units,
Annotation)
Annotation,
DefinitionAnnotation,
SectionAnnotation)
......@@ -16,7 +16,9 @@ from typing import Callable, Any, Dict, cast
import uuid
from .metainfo import Section, Quantity, MSection, MEnum, Datetime, Reference, Annotation, SectionAnnotation, DefinitionAnnotation
from .metainfo import (
Section, Quantity, MSection, MEnum, Datetime, Reference, Annotation, SectionAnnotation,
DefinitionAnnotation)
'''
This module provides metainfo annotation class :class:`Elastic` and
......@@ -62,7 +64,7 @@ class ElasticDocument(SectionAnnotation):
def create_index_entry(cls, section: MSection):
''' Creates an elasticsearch_dsl document instance for the given section. '''
m_def = section.m_def
annotation = m_def.m_x(ElasticDocument)
annotation = m_def.m_get_annotations(ElasticDocument)
document_cls = ElasticDocument._all_documents[m_def.qualified_name()]
if annotation is None:
......@@ -75,7 +77,7 @@ class ElasticDocument(SectionAnnotation):
obj = document_cls(meta=dict(id=id))
for quantity in m_def.all_quantities.values():
for annotation in quantity.m_x(Elastic, as_list=True):
for annotation in quantity.m_get_annotations(Elastic, as_list=True):
if annotation.mapping is None:
continue
......@@ -151,7 +153,7 @@ class ElasticDocument(SectionAnnotation):
# create an field for each quantity
for quantity in section.all_quantities.values():
first = True
for annotation in quantity.m_x(Elastic, as_list=True):
for annotation in quantity.m_get_annotations(Elastic, as_list=True):
if annotation.mapping is None and first:
kwargs = dict(index=annotation.index)
# find a mapping based on quantity type
......
......@@ -514,7 +514,7 @@ class MSection(metaclass=MObjectMeta): # TODO find a way to make this a subclas
# get additional annotations from the section definition
if not is_bootstrapping:
for section_annotation in self.m_def.m_x(SectionAnnotation, as_list=True):
for section_annotation in self.m_def.m_get_annotations(SectionAnnotation, as_list=True):
for name, annotation in section_annotation.new(self).items():
self.m_annotations[name] = annotation
......@@ -1203,10 +1203,6 @@ class MSection(metaclass=MObjectMeta): # TODO find a way to make this a subclas
return cast(MSectionBound, context)
def m_x(self, *args, **kwargs):
# TODO remove
return self.m_get_annotations(*args, **kwargs)
def m_get_annotations(self, key: Union[str, type], default=None, as_list: bool = False):
'''
Convinience method to get annotations
......@@ -1409,7 +1405,7 @@ class Definition(MSection):
'''
# initialize definition annotations
for annotation in self.m_x(DefinitionAnnotation, as_list=True):
for annotation in self.m_get_annotations(DefinitionAnnotation, as_list=True):
annotation.init_annotation(self)
@classmethod
......
......@@ -119,7 +119,7 @@ class Search(Elastic):
def register(self, prefix, field):
# TODO support more deeply nested quantities
domain_or_all = self.definition.m_parent.m_x('domain', '__all__')
domain_or_all = self.definition.m_parent.m_get_annotations('domain', '__all__')
prefix_and_dot = prefix + '.' if prefix is not None else ''
......
......@@ -25,7 +25,6 @@ import json
from nomad import config, datamodel, infrastructure, datamodel, utils, processing as proc
from nomad.metainfo.search_extension import search_quantities, metrics, order_default_quantities, default_statistics
from nomad.metainfo.elastic_extension import ElasticDocument
path_analyzer = analyzer(
......@@ -42,7 +41,7 @@ class ElasticSearchError(Exception): pass
class ScrollIdNotFound(Exception): pass
entry_document = datamodel.EntryMetadata.m_def.m_x(ElasticDocument).document
entry_document = datamodel.EntryMetadata.m_def.a_elastic.document
for domain in datamodel.domains:
order_default_quantities.setdefault(domain, order_default_quantities.get('__all__'))
......
......@@ -35,7 +35,7 @@ class DFT(MSection):
a_elastic=[Elastic(), Elastic()])
n_atoms = Quantity(
type=int, derived=lambda x: len(x.atoms),
a_eleastic=Elastic(index=False, field='natoms'))
a_elastic=Elastic(index=False, field='natoms'))
only_atoms = Quantity(
type=str, shape=['0..*'], derived=lambda x: x.atoms,
a_elastic=Elastic(value=lambda x: ','.join(x.atoms)))
......@@ -52,15 +52,15 @@ class Entry(MSection):
def test_document():
annotation = Entry.m_def.m_x(ElasticDocument)
annotation = Entry.m_def.a_elastic
document = annotation.document
assert issubclass(document, Document)
assert DFT.m_def.qualified_name() in ElasticDocument._all_documents
assert EMS.m_def.qualified_name() not in ElasticDocument._all_documents
assert DFT.atoms.m_x(Elastic)[0].qualified_field == 'dft.atoms'
assert DFT.n_atoms.m_x(Elastic).qualified_field == 'dft.natoms'
assert DFT.atoms.a_elastic[0].qualified_field == 'dft.atoms'
assert DFT.n_atoms.a_elastic.qualified_field == 'dft.natoms'
def test_create_entry():
......@@ -68,7 +68,7 @@ def test_create_entry():
entry = Entry(entry_id='test_id', uploader=user)
entry.m_create(DFT).atoms = ['H', 'O']
index_entry = Entry.m_def.m_x(ElasticDocument).create_index_entry(entry)
index_entry = Entry.m_def.a_elastic.create_index_entry(entry)
assert index_entry.entry_id == entry.entry_id
assert index_entry.uploader.name == 'Test Tester'
......
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