Exemplo n.º 1
0
def create_correlation_test_docs():
    """
    Creates JSON file containing a certain number of materials and their
    necessary properties to load the propnet store for correlation tests.

    """
    n_materials = 200
    pnstore = MongograntStore("ro:mongodb03.nersc.gov/propnet",
                              "propnet_july2019")
    pnstore.connect()
    cursor = pnstore.query(criteria={
        '$and': [{
            '$or': [{
                p: {
                    '$exists': True
                }
            }, {
                'inputs.symbol_type': p
            }]
        } for p in PROPNET_PROPS]
    },
                           properties=['task_id', 'inputs'] +
                           [p + '.mean' for p in PROPNET_PROPS] +
                           [p + '.units' for p in PROPNET_PROPS] +
                           [p + '.quantities' for p in PROPNET_PROPS])
    data = []
    for item in cursor:
        if len(data) < n_materials:
            data.append(item)
        else:
            cursor.close()
            break
    dumpfn(data, os.path.join(CORR_TEST_DIR, "correlation_propnet_data.json"))
Exemplo n.º 2
0
def create_mp_builder_test_docs():
    """
    Create documents for propnet MP builder tests. Outputs JSON file to test directory.
    """
    formulas = ["BaNiO3", "Si", "Fe2O3", "Cs"]
    mgstore = MongograntStore("ro:knowhere.lbl.gov/mp_core", "materials")
    builder = PropnetBuilder(mgstore,
                             MemoryStore(),
                             criteria={
                                 "pretty_formula": {
                                     "$in": formulas
                                 },
                                 "e_above_hull": 0
                             })
    builder.connect()

    materials = list(builder.get_items())
    deprecated_item = mgstore.query_one({'deprecated': True, 'sbxn': 'core'})

    # Create fake, non-core sandboxed material to represent proprietary info
    sandboxed_item = materials[0].copy()
    sandboxed_item.update({'sbxn': ['test_sbx'], 'task_id': 'mp-fakesbx'})
    del sandboxed_item['_id']
    materials.extend([deprecated_item, sandboxed_item])
    dumpfn(materials, os.path.join(MP_TEST_DIR, "test_materials.json"))
Exemplo n.º 3
0
def process_sdf_file(filename):
    mp_pubchem = MongograntStore("rw:knowhere.lbl.gov/mp_pubchem",
                                 "mp_pubchem",
                                 key="pubchem_id")
    mp_pubchem.connect()
    coll = mp_pubchem.collection

    skipped = 0
    pubchem_molecules = []
    for i, mol in enumerate(pybel.readfile("sdf", filename)):
        try:
            pubchem_id = int(mol.data["PUBCHEM_COMPOUND_CID"])
            xyz = mol.write(format="xyz")

            data = {"pubchem_id": pubchem_id, "xyz": xyz}
            for key in keys:
                if key in mol.data:
                    data[key_map[key]] = mol.data[key]

            pubchem_molecules.append(data)

        except KeyError:
            skipped += 1

    coll.insert_many(pubchem_molecules)

    os.rename(filename, filename + ".processed")
    return len(pubchem_molecules), skipped
Exemplo n.º 4
0
 def create_test_docs(self):
     formulas = ["BaNiO3", "Si", "Fe2O3", "Cs"]
     from maggma.advanced_stores import MongograntStore
     from monty.serialization import dumpfn
     mgstore = MongograntStore("ro:matgen2.lbl.gov/mp_prod", "materials")
     builder = PropnetBuilder(
         mgstore, self.propstore, criteria={"pretty_formula": {"$in": formulas},
                                            "e_above_hull": 0})
     builder.connect()
     dumpfn(list(builder.get_items()), "test_materials.json")
Exemplo n.º 5
0
 def create_test_docs(self):
     from maggma.advanced_stores import MongograntStore
     from monty.serialization import dumpfn
     pnstore = MongograntStore("ro:knowhere.lbl.gov/mp_core", "propnet")
     pnstore.connect()
     mpstore = MongograntStore("ro:knowhere.lbl.gov/mp_core", "materials")
     mpstore.connect()
     cursor = pnstore.query(criteria={
         '$and': [{
             '$or': [{
                 p: {
                     '$exists': True
                 }
             }, {
                 'inputs.symbol_type': p
             }]
         } for p in self.propnet_props]
     },
                            properties=['task_id'])
     pn_mpids = [item['task_id'] for item in cursor]
     cursor = mpstore.query(
         criteria={p: {
             '$exists': True
         }
                   for p in self.mp_query_props},
         properties=['task_id'])
     mp_mpids = [item['task_id'] for item in cursor]
     mpids = list(set(pn_mpids).intersection(set(mp_mpids)))[:200]
     pn_data = pnstore.query(criteria={'task_id': {
         '$in': mpids
     }},
                             properties=['task_id', 'inputs'] +
                             [p + '.mean' for p in self.propnet_props] +
                             [p + '.units' for p in self.propnet_props])
     dumpfn(list(pn_data),
            os.path.join(TEST_DIR, "correlation_propnet_data.json"))
     mp_data = mpstore.query(criteria={'task_id': {
         '$in': mpids
     }},
                             properties=['task_id'] + self.mp_query_props)
     dumpfn(list(mp_data), os.path.join(TEST_DIR,
                                        "correlation_mp_data.json"))