Skip to content

Commit

Permalink
REST API v4: updates to conform with aiida-core==1.0.0
Browse files Browse the repository at this point in the history
The REST API is updated to `v4` to reflect the changes of the ORM of
`aiida-core` in `v1.0.0`, especially in the available endpoints. The
`calculations` and individual `data` endpoints have been removed. Added
are the `processes` and `calcjobs`  endpoints. The `visualization`
endpoints, which were used by the Materials Cloud to retrieve data in
a specific format that was derived from the basic node attributes and
repository contents, has been changed to `derived_properties`.

Also added the endpoints `repo_list` and `repo_contents` to get the
available objects in a node's repository and their contents in the case
of files.

The `schema` endpoints have been replaced with `projectable_properties`.
The `get_schema` class methods on various ORM classes have been
deprecated as this functionality was used strictly by the REST API.

Co-Authored-By: epassaro <elsa.passaro@epfl.ch>
  • Loading branch information
2 people authored and sphuber committed Oct 25, 2019
1 parent e3219cf commit 4ff2829
Show file tree
Hide file tree
Showing 36 changed files with 2,073 additions and 1,897 deletions.
5 changes: 5 additions & 0 deletions aiida/backends/tests/orm/data/test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ def generate_class_instance(data_class):
instance = data_class(file=os.path.join(dirpath_fixtures, 'data', 'Si.cif'))
return instance

if data_class is orm.UpfData:
filename = os.path.join(dirpath_fixtures, 'pseudos', 'Ba.pbesol-spn-rrkjus_psl.0.2.3-tot-pslib030.UPF')
instance = data_class(file=filename)
return instance

if data_class is orm.StructureData:
instance = orm.CifData(file=os.path.join(dirpath_fixtures, 'data', 'Si.cif')).get_structure()
return instance
Expand Down
367 changes: 195 additions & 172 deletions aiida/backends/tests/test_restapi.py

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions aiida/orm/computers.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@

import logging
import os
import warnings
import six

from aiida import transports, schedulers
from aiida.common import exceptions
from aiida.common.warnings import AiidaDeprecationWarning
from aiida.manage.manager import get_manager
from aiida.plugins import SchedulerFactory, TransportFactory

Expand Down Expand Up @@ -732,7 +734,17 @@ def get_schema():
- type: type of the property. e.g. str, dict, int
:return: get schema of the computer
.. deprecated:: 1.0.0
Will be removed in `v2.0.0`.
Use :meth:`~aiida.restapi.translator.base.BaseTranslator.get_projectable_properties` instead.
"""
message = 'method is deprecated, use' \
'`aiida.restapi.translator.base.BaseTranslator.get_projectable_properties` instead'
warnings.warn(message, AiidaDeprecationWarning) # pylint: disable=no-member

return {
'description': {
'display_name': 'Description',
Expand Down
12 changes: 12 additions & 0 deletions aiida/orm/groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@
from __future__ import absolute_import

from enum import Enum
import warnings
import six

from aiida.common import exceptions
from aiida.common.lang import type_check
from aiida.common.warnings import AiidaDeprecationWarning
from aiida.manage.manager import get_manager

from . import convert
Expand Down Expand Up @@ -333,7 +335,17 @@ def get_schema():
:return: schema of the group
:rtype: dict
.. deprecated:: 1.0.0
Will be removed in `v2.0.0`.
Use :meth:`~aiida.restapi.translator.base.BaseTranslator.get_projectable_properties` instead.
"""
message = 'method is deprecated, use' \
'`aiida.restapi.translator.base.BaseTranslator.get_projectable_properties` instead'
warnings.warn(message, AiidaDeprecationWarning) # pylint: disable=no-member

return {
'description': {
'display_name': 'Description',
Expand Down
9 changes: 9 additions & 0 deletions aiida/orm/nodes/data/upf.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,15 @@ def _validate(self):
if attr_md5 != md5:
raise ValidationError("Attribute 'md5' says '{}' but '{}' was parsed instead.".format(attr_md5, md5))

def _prepare_upf(self, main_file_name=''):
"""
Return UPF content.
"""
# pylint: disable=unused-argument
return_string = self.get_content()

return return_string.encode('utf-8'), {}

@classmethod
def get_upf_group(cls, group_label):
"""Return the UPF family group with the given label.
Expand Down
10 changes: 10 additions & 0 deletions aiida/orm/nodes/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -1238,7 +1238,17 @@ def get_schema():
- type: type of the property. e.g. str, dict, int
:return: get schema of the node
.. deprecated:: 1.0.0
Will be removed in `v2.0.0`.
Use :meth:`~aiida.restapi.translator.base.BaseTranslator.get_projectable_properties` instead.
"""
message = 'method is deprecated, use' \
'`aiida.restapi.translator.base.BaseTranslator.get_projectable_properties` instead'
warnings.warn(message, AiidaDeprecationWarning) # pylint: disable=no-member

return {
'attributes': {
'display_name': 'Attributes',
Expand Down
13 changes: 13 additions & 0 deletions aiida/orm/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
from __future__ import print_function
from __future__ import absolute_import

import warnings

from aiida.common import exceptions
from aiida.common.warnings import AiidaDeprecationWarning
from aiida.manage.manager import get_manager

from . import entities
Expand Down Expand Up @@ -162,7 +165,17 @@ def get_schema():
- type: type of the property. e.g. str, dict, int
:return: schema of the user
.. deprecated:: 1.0.0
Will be removed in `v2.0.0`.
Use :meth:`~aiida.restapi.translator.base.BaseTranslator.get_projectable_properties` instead.
"""
message = 'method is deprecated, use' \
'`aiida.restapi.translator.base.BaseTranslator.get_projectable_properties` instead'
warnings.warn(message, AiidaDeprecationWarning) # pylint: disable=no-member

return {
'id': {
'display_name': 'Id',
Expand Down
32 changes: 1 addition & 31 deletions aiida/restapi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,5 @@
"""
In this module, AiiDA provides REST API to access different
AiiDA nodes stored in database. The REST API is implemented
using Flask RESTFul framework. The REST urls provided for
node types Computer, Node (Calculation , Data, Code).
Examples:
Computers:
http://localhost:5000/computers?(COLUMN_FILTERS)&(LIMIT)&(OFFSET)?(ORDERBY)
http://localhost:5000/computers/1
NODES / CALCULATIONS / DATAS / CODES:
(replace nodes with calculations/datas/codes)
http://localhost:5000/nodes?(COLUMN_FILTERS)&(LIMIT)&(OFFSET)&(SORT)
OR
http://localhost:5000/nodes/pages?(COLUMN_FILTERS)&(PER_PAGE)&(SORT)
http://localhost:5000/nodes/pages/1?(COLUMN_FILTERS)&(PER_PAGE)&(SORT)
http://localhost:5000/nodes/1
http://localhost:5000/nodes/1/io
http://localhost:5000/nodes/1/io/inputs
http://localhost:5000/nodes/1/io/inputs?(COLUMN_FILTERS)
http://localhost:5000/nodes/1/io/outputs
http://localhost:5000/nodes/1/io/outputs?(COLUMN_FILTERS)
http://localhost:5000/nodes/1/contents/attributes
http://localhost:5000/nodes/1/contents/attributes?alist=abc
http://localhost:5000/nodes/1/contents/attributes?nalist=c,d
http://localhost:5000/nodes/1/contents/extras
http://localhost:5000/nodes/1/contents/extras?elist=a,b,c
http://localhost:5000/nodes/1/contents/extras?nelist=c,d
...
using Flask RESTFul framework.
"""
Loading

0 comments on commit 4ff2829

Please sign in to comment.