Skip to content

Commit

Permalink
Condense materials and tasks endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
munrojm committed May 29, 2021
1 parent 4d90c7a commit 045f3ad
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 46 deletions.
103 changes: 59 additions & 44 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import os
from monty.serialization import loadfn
from mp_api.core.api import MAPI

# from mp_api.core.api import MAPI
from maggma.api.API import API
from mp_api.core.settings import MAPISettings

resources = {}
Expand Down Expand Up @@ -345,133 +347,144 @@
)

resources.update(
{"materials": materials_resource(materials_store, formula_autocomplete_store)}
{
"materials": [
materials_resource(materials_store, formula_autocomplete_store),
find_structure_resource(materials_store),
]
}
)

resources.update({"find_structure": find_structure_resource(materials_store)})
# resources.update({"find_structure": find_structure_resource(materials_store)})

# Tasks
from mp_api.routes.tasks.resources import task_resource

resources.update({"tasks": task_resource(task_store)})

# Task Deprecation
from mp_api.routes.tasks.resources import task_deprecation_resource

resources.update({"deprecation": task_deprecation_resource(materials_store)})

# Trajectory
from mp_api.routes.tasks.resources import trajectory_resource
from mp_api.routes.tasks.resources import (
task_resource,
trajectory_resource,
task_deprecation_resource,
)

resources.update({"trajectory": trajectory_resource(task_store)})
resources.update(
{
"tasks": [
task_resource(task_store),
trajectory_resource(task_store),
task_deprecation_resource(materials_store),
]
}
)

# Thermo
from mp_api.routes.thermo.resources import thermo_resource

resources.update({"thermo": thermo_resource(thermo_store)})
resources.update({"thermo": [thermo_resource(thermo_store)]})

# Dielectric
from mp_api.routes.dielectric.resources import dielectric_resource

resources.update({"dielectric": dielectric_resource(dielectric_piezo_store)})
resources.update({"dielectric": [dielectric_resource(dielectric_piezo_store)]})

# Magnetism
from mp_api.routes.magnetism.resources import magnetism_resource

resources.update({"magnetism": magnetism_resource(magnetism_store)})
resources.update({"magnetism": [magnetism_resource(magnetism_store)]})

# Piezoelectric
from mp_api.routes.piezo.resources import piezo_resource

resources.update({"piezoelectric": piezo_resource(dielectric_piezo_store)})
resources.update({"piezoelectric": [piezo_resource(dielectric_piezo_store)]})

# Phonon
from mp_api.routes.phonon.resources import phonon_bs_resource, phonon_img_resource

resources.update({"phonon": phonon_bs_resource(phonon_bs_store)})
resources.update({"phonon_img": phonon_img_resource(phonon_img_store)})
resources.update({"phonon": [phonon_bs_resource(phonon_bs_store)]})
resources.update({"phonon_img": [phonon_img_resource(phonon_img_store)]})

# EOS
from mp_api.routes.eos.resources import eos_resource

resources.update({"eos": eos_resource(eos_store)})
resources.update({"eos": [eos_resource(eos_store)]})

# Similarity
from mp_api.routes.similarity.resources import similarity_resource

resources.update({"similarity": similarity_resource(similarity_store)})
resources.update({"similarity": [similarity_resource(similarity_store)]})

# XAS
from mp_api.routes.xas.resources import xas_resource

resources.update({"xas": xas_resource(xas_store)})
resources.update({"xas": [xas_resource(xas_store)]})

# Grain Boundaries
from mp_api.routes.grain_boundary.resources import gb_resource

resources.update({"grain_boundary": gb_resource(gb_store)})
resources.update({"grain_boundary": [gb_resource(gb_store)]})

# Fermi Surface
from mp_api.routes.fermi.resources import fermi_resource

resources.update({"fermi": fermi_resource(fermi_store)})
resources.update({"fermi": [fermi_resource(fermi_store)]})

# Elasticity
from mp_api.routes.elasticity.resources import elasticity_resource

resources.update({"elasticity": elasticity_resource(elasticity_store)})
resources.update({"elasticity": [elasticity_resource(elasticity_store)]})

# DOIs
from mp_api.routes.dois.resources import dois_resource

resources.update({"doi": dois_resource(doi_store)})
resources.update({"doi": [dois_resource(doi_store)]})

# Substrates
from mp_api.routes.substrates.resources import substrates_resource

resources.update({"substrates": substrates_resource(substrates_store)})
resources.update({"substrates": [substrates_resource(substrates_store)]})

# Surface Properties
from mp_api.routes.surface_properties.resources import surface_props_resource

resources.update({"surface_properties": surface_props_resource(surface_props_store)})
resources.update({"surface_properties": [surface_props_resource(surface_props_store)]})

# Wulff
from mp_api.routes.wulff.resources import wulff_resource

resources.update({"wulff": wulff_resource(wulff_store)})
resources.update({"wulff": [wulff_resource(wulff_store)]})

# Robocrystallographer
from mp_api.routes.robocrys.resources import robo_resource

resources.update({"robocrys": robo_resource(robo_store)})
resources.update({"robocrys": [robo_resource(robo_store)]})

# Synthesis
from mp_api.routes.synthesis.resources import synth_resource

resources.update({"synthesis": synth_resource(synth_store)})
resources.update({"synthesis": [synth_resource(synth_store)]})

# Electrodes
from mp_api.routes.electrodes.resources import insertion_electrodes_resource

resources.update(
{"insertion_electrodes": insertion_electrodes_resource(insertion_electrodes_store)}
{
"insertion_electrodes": [
insertion_electrodes_resource(insertion_electrodes_store)
]
}
)

# Molecules
from mp_api.routes.molecules.resources import molecules_resource

resources.update({"molecules": molecules_resource(molecules_store)})
resources.update({"molecules": [molecules_resource(molecules_store)]})

# Charge Density
from mp_api.routes.charge_density.resources import charge_density_resource

resources.update({"charge_density": charge_density_resource(s3_chgcar)})
resources.update({"charge_density": [charge_density_resource(s3_chgcar)]})

# Search
from mp_api.routes.search.resources import search_resource

resources.update({"search": search_resource(search_store)})
resources.update({"search": [search_resource(search_store)]})

# Electronic Structure
from mp_api.routes.electronic_structure.resources import (
Expand All @@ -480,24 +493,26 @@
dos_resource,
)

resources.update({"electronic_structure": es_resource(es_store)})
resources.update({"bandstructure": bs_resource(es_store, s3_bs)})
resources.update({"dos": dos_resource(es_store, s3_dos)})
resources.update({"electronic_structure": [es_resource(es_store)]})
resources.update({"bandstructure": [bs_resource(es_store, s3_bs)]})
resources.update({"dos": [dos_resource(es_store, s3_dos)]})

# MPComplete
from mp_api.routes.mpcomplete.resources import mpcomplete_resource

resources.update({"mpcomplete": mpcomplete_resource(mpcomplete_store)})
resources.update({"mpcomplete": [mpcomplete_resource(mpcomplete_store)]})

# Consumers
from mp_api.routes._consumer.resources import (
set_settings_resource,
get_settings_resource,
)

resources.update({"user_settings": get_settings_resource(consumer_settings_store)})
resources.update({"user_settings/set": set_settings_resource(consumer_settings_store)})
resources.update({"user_settings": [get_settings_resource(consumer_settings_store)]})
resources.update(
{"user_settings/set": [set_settings_resource(consumer_settings_store)]}
)


api = MAPI(resources=resources, debug=debug)
api = API(resources=resources, debug=debug)
app = api.app
3 changes: 2 additions & 1 deletion src/mp_api/routes/materials/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ async def formula_autocomplete(
),
],
tags=["Materials"],
custom_endpoint_funcs=[custom_version_prep, custom_autocomplete_prep,],
custom_endpoint_funcs=[custom_version_prep, custom_autocomplete_prep],
)

return resource
Expand All @@ -194,6 +194,7 @@ def find_structure_resource(materials_store):
key_fields=["structure", "task_id"],
query_operators=[FindStructureQuery()],
tags=["Materials"],
path="/find_structure/",
)

return resource
6 changes: 5 additions & 1 deletion src/mp_api/routes/tasks/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ def task_resource(task_store):
MultipleTaskIDsQuery(),
SortQuery(),
PaginationQuery(),
SparseFieldsQuery(TaskDoc, default_fields=["task_id", "formula_pretty", "last_updated"],),
SparseFieldsQuery(
TaskDoc, default_fields=["task_id", "formula_pretty", "last_updated"],
),
],
tags=["Tasks"],
)
Expand All @@ -39,6 +41,7 @@ def task_deprecation_resource(materials_store):
tags=["Tasks"],
enable_get_by_key=False,
enable_default_search=True,
path="/deprecation/",
)

return resource
Expand All @@ -51,6 +54,7 @@ def trajectory_resource(task_store):
query_operators=[TrajectoryQuery(), PaginationQuery()],
key_fields=["task_id", "calcs_reversed"],
tags=["Tasks"],
path="/trajectory/",
)

return resource

0 comments on commit 045f3ad

Please sign in to comment.