class MDB: cmp_tbl = { ">": "$gt", ">=": "$gte", "<": "$lt", "<=": "$lte", "==": "$eq", "!=": "$ne" } def __init__(self): from mongogrant import Client self.client = Client() self.core_db = self.client.db("ro:dev/optimade_core") def get_structure(self, structure_id): doc = self.core_db.materials.find_one({"task_id": structure_id}) if doc: return Structure.from_material_doc(doc) def get_structures(self, filter_): match = re.search(r'nelements([^0-9]+)([0-9]+)', filter_) if match: comp, n = match.groups() crit = {"nelements": {self.cmp_tbl[comp]: int(n)}} return [ Structure.from_material_doc(doc) for doc in mdb.core_db.materials.find( crit, Structure.material_doc_projection()) ] else: return []
def connect(self, force_reset=False): if not self._collection or force_reset: if self.mgclient_config_path: config = Config(check=check, path=self.mgclient_config_path) client = Client(config) else: client = Client() db = client.db(self.mongogrant_spec) self._collection = db[self.collection_name]
client = Client() client.set_alias("mg2.lbl", "matgen2.lbl.gov", "host") client.set_alias("m01.nersc", "mongodb01.nersc.gov", "host") client.set_alias("m03.nersc", "mongodb03.nersc.gov", "host") client.set_alias("m04.nersc", "mongodb04.nersc.gov", "host") client.set_alias("build", "mp_prod", "db") client.set_alias("core", "fw_mp_prod_atomate", "db") client.set_alias("app", "mg_apps_prod", "db") client.set_alias("elastic", "fw_jhm_kpoints", "db") client.set_alias("SCAN", "fw_shyamd", "db") dbs = { "elastic": client.db("ro:m03.nersc/elastic", connect=False), "SCAN": client.db("ro:m03.nersc/SCAN", connect=False), "core": client.db("ro:m01.nersc/core", connect=False), "app": client.db("ro:m04.nersc/app", connect=False), "build": client.db("ro:mg2.lbl/build", connect=False), } @app.route('/mongometric') def mongometric(): dbname = request.args.get("db") collname = request.args.get("collection") filt = request.args.get("filter") timefield = request.args.get("timefield") start = request.args.get("start") stop = request.args.get("stop")
@app.route('/cubism') def cubism(): return current_app.send_static_file('cubism.v1.js') client = Client() client.set_alias("m01.nersc", "mongodb01.nersc.gov", "host") client.set_alias("m03.nersc", "mongodb03.nersc.gov", "host") client.set_alias("core", "fw_mp_prod_atomate", "db") client.set_alias("elastic", "fw_jhm_kpoints", "db") client.set_alias("SCAN", "fw_shyamd", "db") dbs = { "elastic": client.db("ro:m03.nersc/elastic", connect=False), "SCAN": client.db("ro:m03.nersc/SCAN", connect=False), "core": client.db("ro:m01.nersc/core", connect=False), } @app.route('/mongometric') def mongometric(): dbname = request.args.get("db") collname = request.args.get("collection") filt = request.args.get("filter") timefield = request.args.get("timefield") start = request.args.get("start") stop = request.args.get("stop") step = request.args.get("step")
from tqdm import tqdm from emmet.common.utils import get_chemsys_space html_out = len(sys.argv) > 1 and sys.argv[1] == 'html' if html_out: sys_print = print def print(s=None): s = s or "" sys_print(s + "<br>") print("Connecting to databases and retrieving on-hull materials...") client = Client() db_stag = client.db("ro:staging/mp_core") db_prod = client.db("ro:production/mp_emmet_prod") onhull_prod = db_prod.materials.distinct("task_id", { "e_above_hull": 0, "deprecated": { "$ne": True } }) onhull_stag = db_stag.materials.distinct("task_id", { "e_above_hull": 0, "deprecated": False }) onhull_prod_but_not_stag = set(onhull_prod) - set(onhull_stag) print( f"{len(onhull_prod_but_not_stag)} on hull in production but not in staging"