コード例 #1
0
 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]
コード例 #2
0
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 []
コード例 #3
0
ファイル: advanced_stores.py プロジェクト: mkhorton/maggma
    def __init__(
        self,
        mongogrant_spec: str,
        collection_name: str,
        mgclient_config_path: Optional[str] = None,
        **kwargs,
    ):
        """
        Args:
            mongogrant_spec: of the form `<role>`:`<host>`/`<db>`, where
                role is one of {"read", "readWrite"} or aliases {"ro", "rw"};
                host is a db host (w/ optional port) or alias; and db is a db
                on that host, or alias. See mongogrant documentation.
            collection_name: name of mongo collection
            mgclient_config_path: Path to mongogrant client config file,
               or None if default path (`mongogrant.client.path`).
        """
        self.mongogrant_spec = mongogrant_spec
        self.collection_name = collection_name
        self.mgclient_config_path = mgclient_config_path
        self._collection = None

        if self.mgclient_config_path:
            config = Config(check=check, path=self.mgclient_config_path)
            client = Client(config)
        else:
            client = Client()

        if set(("username", "password", "database", "host")) & set(kwargs):
            raise StoreError("MongograntStore does not accept "
                             "username, password, database, or host "
                             "arguments. Use `mongogrant_spec`.")

        self.kwargs = kwargs
        _auth_info = client.get_db_auth_from_spec(self.mongogrant_spec)
        super(MongograntStore, self).__init__(
            host=_auth_info["host"],
            database=_auth_info["authSource"],
            username=_auth_info["username"],
            password=_auth_info["password"],
            collection_name=self.collection_name,
            **kwargs,
        )
コード例 #4
0
def mgrant_user(mgrant_server):
    config_path, mdport, dbname = mgrant_server

    config = Config(check=check, path=config_path, seed=seed())
    client = Client(config)
    client.set_auth(
        host=f"localhost:{mdport}",
        db=dbname,
        role="read",
        username="******",
        password="******",
    )
    client.set_auth(
        host=f"localhost:{mdport}",
        db=dbname,
        role="readWrite",
        username="******",
        password="******",
    )
    client.set_alias("testhost", f"localhost:{mdport}", which="host")
    client.set_alias("testdb", dbname, which="db")

    return client
コード例 #5
0
    def setUpClass(cls):
        # `nosetests` does not see class decorators
        # https://github.com/nose-devs/nose/issues/946
        if "TRAVIS" in os.environ and os.environ["TRAVIS"] == "true":
            raise unittest.SkipTest("Skipping this test on Travis CI.")
        cls.client = Client()
        cls.db_stag = cls.client.db("ro:staging/mp_core")
        cls.db_prod = cls.client.db("ro:prod/mp_emmet_prod")
        cls.db_phonons = cls.client.db("ro:prod/phonondb")
        cls.mats_stag = cls.db_stag.materials
        cls.mats_prod = cls.db_prod.materials

        idset_stag = set(cls.mats_stag.distinct("task_id"))
        idset_prod = set(cls.mats_prod.distinct("task_id"))

        n_new_ids = len(idset_stag - idset_prod)
        if n_new_ids:
            logging.info("{} new material ids".format(n_new_ids))
        n_retiring_ids = len(idset_prod - idset_stag)
        if n_retiring_ids:
            logging.warning("{} retiring material ids".format(n_retiring_ids))
コード例 #6
0
@app.route('/cubism')
def cubism():
    return current_app.send_static_file('cubism.v1.js')


@app.route('/structureViewer')
def structure_viewer():
    return current_app.send_static_file('structureViewerBuilt.js')


@app.route("/container")
def get_style():
    return current_app.send_static_file('container.css')


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),
コード例 #7
0
from mongogrant import Client

app = Flask(__name__)


@app.route('/')
def hello_world():
    return current_app.send_static_file('main.html')


@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),
}

コード例 #8
0
 def __init__(self):
     from mongogrant import Client
     self.client = Client()
     self.core_db = self.client.db("ro:dev/optimade_core")
コード例 #9
0
import numpy as np
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(