Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
nomad-lab
nomad-FAIR
Commits
0c5188ef
Commit
0c5188ef
authored
Mar 06, 2020
by
Markus Scheidgen
Browse files
Removed old m_x function calls.
parent
249559b5
Pipeline
#70283
passed with stages
in 23 minutes and 32 seconds
Changes
9
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
nomad/app/api/repo.py
View file @
0c5188ef
...
...
@@ -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
)
...
...
nomad/app/optimade/filterparser.py
View file @
0c5188ef
...
...
@@ -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
}
...
...
nomad/datamodel/optimade.py
View file @
0c5188ef
...
...
@@ -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
...
...
nomad/metainfo/__init__.py
View file @
0c5188ef
...
...
@@ -297,4 +297,6 @@ from .metainfo import (
MResource
,
m_package
,
units
,
Annotation
)
Annotation
,
DefinitionAnnotation
,
SectionAnnotation
)
nomad/metainfo/elastic_extension.py
View file @
0c5188ef
...
...
@@ -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
...
...
nomad/metainfo/metainfo.py
View file @
0c5188ef
...
...
@@ -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
...
...
nomad/metainfo/search_extension.py
View file @
0c5188ef
...
...
@@ -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
''
...
...
nomad/search.py
View file @
0c5188ef
...
...
@@ -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
(
E
lastic
Document
)
.
document
entry_document
=
datamodel
.
EntryMetadata
.
m_def
.
a_e
lastic
.
document
for
domain
in
datamodel
.
domains
:
order_default_quantities
.
setdefault
(
domain
,
order_default_quantities
.
get
(
'__all__'
))
...
...
tests/metainfo/test_elastic_extension.py
View file @
0c5188ef
...
...
@@ -35,7 +35,7 @@ class DFT(MSection):
a_elastic
=
[
Elastic
(),
Elastic
()])
n_atoms
=
Quantity
(
type
=
int
,
derived
=
lambda
x
:
len
(
x
.
atoms
),
a_el
e
astic
=
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
(
E
lastic
Document
)
annotation
=
Entry
.
m_def
.
a_e
lastic
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
(
E
lastic
)
[
0
].
qualified_field
==
'dft.atoms'
assert
DFT
.
n_atoms
.
m_x
(
E
lastic
)
.
qualified_field
==
'dft.natoms'
assert
DFT
.
atoms
.
a_e
lastic
[
0
].
qualified_field
==
'dft.atoms'
assert
DFT
.
n_atoms
.
a_e
lastic
.
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
(
E
lastic
Document
)
.
create_index_entry
(
entry
)
index_entry
=
Entry
.
m_def
.
a_e
lastic
.
create_index_entry
(
entry
)
assert
index_entry
.
entry_id
==
entry
.
entry_id
assert
index_entry
.
uploader
.
name
==
'Test Tester'
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment