def test_load_properties(self): mpid = 'mp-1153' mpr = MPRester() mat = mpr.get_material_for_mpid(mpid) quantity = next(iter(mat['structure'])) self.assertEqual(quantity.provenance.source, "Materials Project") self.assertIn('structure', mat.get_symbols())
def generate_composite_data_files(): """ Generates data files for testing composite graph evaluation. """ mpr = MPRester() mpids = ['mp-13', 'mp-24972'] materials = mpr.get_materials_for_mpids(mpids) for m in materials: mpid = [ q.value for q in m.get_quantities() if q.symbol == "external_identifier_mp" ][0] with open(os.path.join(TEST_DATA_DIR, '{}.json'.format(mpid)), 'w') as f: qs = jsanitize(m.get_quantities(), strict=True) json.dump(qs, f)
def test_super_evaluate(self): """ Tests the graph's composite material evaluation. """ mpr = MPRester() m1 = mpr.get_material_for_mpid("mp-13") m2 = mpr.get_material_for_mpid("mp-24972") sm = CompositeMaterial([m1, m2]) g = Graph() sm = g.super_evaluate(sm) self.assertTrue( 'pilling_bedworth_ratio' in sm._symbol_to_quantity.keys(), "Super Evaluate failed to derive expected outputs.") self.assertTrue( len(sm._symbol_to_quantity['pilling_bedworth_ratio']) > 0, "Super Evaluate failed to derive expected outputs.")
def test_super_evaluate(self): """ Tests the graph's composite material evaluation. """ mpr = MPRester() m1 = mpr.get_material_for_mpid("mp-13") # Temporary hack for problem with zero band-gap materials m1.remove_symbol("band_gap_pbe") m1.add_quantity(Quantity("band_gap", 0.0)) m2 = mpr.get_material_for_mpid("mp-24972") sm = CompositeMaterial([m1, m2]) g = Graph() sm = g.super_evaluate(sm, allow_model_failure=False) self.assertTrue('pilling_bedworth_ratio' in sm._symbol_to_quantity.keys(), "Super Evaluate failed to derive expected outputs.") self.assertTrue(len(sm._symbol_to_quantity['pilling_bedworth_ratio']) > 0, "Super Evaluate failed to derive expected outputs.")
class MPResterTest(unittest.TestCase): def setUp(self): mpid = 'mp-1153' self.mpr = MPRester() self.mat = self.mpr.get_material_for_mpid(mpid) def test_load_properties(self): mpid = 'mp-1153' mpr = MPRester() mat = mpr.get_material_for_mpid(mpid) quantity = next(iter(mat['structure'])) self.assertEqual(quantity.provenance.source['source'], "Materials Project") self.assertIn('structure', mat.get_symbols()) def test_get_mpid_from_formula(self): mp_id = self.mpr.get_mpid_from_formula("Si") self.assertEqual("mp-149", mp_id) def test_get_properties_for_mpids(self): props = self.mpr.get_properties_for_mpids(["mp-124", "mp-81"]) self.assertAlmostEqual(props[0]['e_above_hull'], 0) self.assertAlmostEqual(props[1]['pretty_formula'], 'Au') def test_get_properties_for_mpid(self): props = self.mpr.get_properties_for_mpid("mp-2") self.assertEqual(props['pretty_formula'], "Pd") def test_get_materials_for_mpids(self): ag, au = self.mpr.get_materials_for_mpids(["mp-124", "mp-81"]) self.assertEqual(list(ag['external_identifier_mp'])[0].value, 'mp-124') self.assertEqual(list(au['external_identifier_mp'])[0].value, 'mp-81') def test_get_materials_for_mpid(self): pd = self.mpr.get_material_for_mpid("mp-2") self.assertEqual(list(pd['external_identifier_mp'])[0].value, 'mp-2') def test_apply_material_to_graph(self): g = Graph() new_mat = g.evaluate(self.mat) # TODO: # For some reason Travis and this version are not commensurate # 257 != 263, should resolve this self.assertGreater(len(new_mat.get_quantities()), 250)
import unittest from propnet.core.graph import Graph from propnet.ext.matproj import MPRester from propnet.models import add_builtin_models_to_registry mpr = MPRester() @unittest.skipIf(mpr.api_key == "", "No API key provided. Skipping MPRester tests.") class MPResterTest(unittest.TestCase): @classmethod def setUpClass(cls): add_builtin_models_to_registry() cls.mpr = mpr mpid = 'mp-1153' cls.mat = cls.mpr.get_material_for_mpid(mpid) def test_load_properties(self): mpid = 'mp-1153' mat = self.mpr.get_material_for_mpid(mpid) quantity = next(iter(mat['structure'])) self.assertEqual(quantity.provenance.source['source'], "Materials Project") self.assertIn('structure', mat.get_symbols()) def test_get_mpid_from_formula(self): mp_id = self.mpr.get_mpid_from_formula("Si") self.assertEqual("mp-149", mp_id)
def setUp(self): mpid = 'mp-1153' self.mpr = MPRester() self.mat = self.mpr.get_material_for_mpid(mpid)
def test_load_properties(self): mpid = 'mp-1153' mpr = MPRester() mat = mpr.get_material_for_mpid(mpid) self.assertIn('structure', mat.get_symbols())
from collections import OrderedDict # noinspection PyUnresolvedReferences import propnet.symbols from propnet.core.registry import Registry from propnet import ureg, logger from propnet.core.quantity import QuantityFactory from propnet.core.materials import Material from propnet.core.graph import Graph from propnet.ext.matproj import MPRester from propnet.ext.aflow import AflowAdapter MPR = MPRester() AFA = AflowAdapter() graph_evaluator = Graph(parallel=True, max_workers=4) # explicitly making this an OrderedDict so we can go back from the # display name to the symbol name # Removed condition symbols from table until we can handle combinatorics blow-up that results # from adding a temperature -cml # TODO: Add condition symbols back when combinartorics problem solved SCALAR_SYMBOLS = OrderedDict({ k: v for k, v in sorted(Registry("symbols").items(), key=lambda x: x[1].display_names[0]) if (v.category == 'property' and v.shape == 1) }) ROW_IDX_TO_SYMBOL_NAME = [symbol for symbol in SCALAR_SYMBOLS.keys()]