def test_binary_from_fake_query(self): cursor, s = res2dict(REAL_PATH + "data/hull-KP-KSnP_pub/*.res") print() print(80 * "-") self.assertEqual( len(cursor), 295, "Error with test res files, please check installation...") hull = QueryConvexHull(cursor=cursor, elements=["KP"], no_plot=True) self.assertEqual(len(hull.cursor), 295) self.assertEqual(len(hull.hull_cursor), 7) fake_query = DBQuery.__new__(DBQuery) fake_query.cursor = hull.cursor for ind, doc in enumerate(fake_query.cursor): fake_query.cursor[ind]["_id"] = None fake_query.cursor[ind]["text_id"] = [doc["source"][0], "."] del fake_query.cursor[ind]["hull_distance"] del fake_query.cursor[ind]["concentration"] fake_query._non_elemental = False fake_query._create_hull = True fake_query.args = dict() fake_query.args["intersection"] = False fake_query.args["subcmd"] = "hull" fake_query.args["composition"] = ["KP"] hull = QueryConvexHull(query=fake_query, chempots=[-791.456765, -219.58161025], no_plot=True) # now need to include custom chempots in counts self.assertEqual(len(hull.cursor), 297) self.assertEqual(len(hull.hull_cursor), 9)
def test_pseudoternary_hull_with_custom_chempots(self): cursor, s = res2dict(REAL_PATH + "data/hull-LLZO/*.res") print() print(80 * "-") self.assertEqual( len(cursor), 12, "Error with test res files, please check installation...") hull = QueryConvexHull( cursor=cursor, elements=["La2O3", "ZrO2", "Li2O"], chempots=[-3275.040 / 5, -2178.987 / 3, -848.148 / 3], no_plot=True, ) self.assertEqual(len(hull.cursor), 10) self.assertEqual(len(hull.hull_cursor), 5) # cursor, s = res2dict(REAL_PATH + 'data/hull-LLZO/*.res') hull = QueryConvexHull( cursor=cursor, elements=["La2O3", "ZrO2", "Li2O"], hull_cutoff=0.20, chempots=[26200.3194 / 40, -8715.94784 / 12, -3392.59361 / 12], no_plot=True, ) self.assertEqual(len(hull.cursor), 10) self.assertEqual(len(hull.hull_cursor), 10) for doc in hull.hull_cursor: if "cubic-LLZO" in doc["source"][0]: self.assertAlmostEqual(doc["formation_enthalpy_per_atom"], -0.05758265622) self.assertAlmostEqual(doc["hull_distance"], 0.008746875) break else: raise RuntimeError("Did not find cubic-LLZO in cursor")
def test_ternary_hull_distances(self): """ Test computing ternary hull distances. """ res_list = glob(REAL_PATH + "data/hull-KPSn-KP/*.res") self.assertEqual( len(res_list), 87, "Could not find test res files, please check installation...", ) cursor = [res2dict(res)[0] for res in res_list] hull = QueryConvexHull(cursor=cursor, elements=["K", "Sn", "P"], no_plot=True) self.assertEqual(len(hull.hull_cursor), 16) self.assertEqual(len(hull.cursor), 87) for ind, doc in enumerate(hull.cursor): hull.cursor[ind]["filename"] = doc["source"][0].split("/")[-1] structures = np.loadtxt(REAL_PATH + "data/test_KSnP.dat") hull_dist_test = np.loadtxt(REAL_PATH + "data/test_KSnP_hull_dist.dat") precomp_hull_dist = hull.get_hull_distances(structures, precompute=True) no_precomp_hull_dist = hull.get_hull_distances(structures, precompute=False) np.testing.assert_array_almost_equal(np.sort(hull_dist_test), np.sort(hull.hull_dist), decimal=3) np.testing.assert_array_almost_equal(np.sort(hull.hull_dist), np.sort(precomp_hull_dist), decimal=3) np.testing.assert_array_almost_equal(no_precomp_hull_dist, precomp_hull_dist, decimal=5) self.assertFalse(np.isnan(hull.hull_dist).any())
def test_pseudoternary_hull(self): cursor, s = res2dict(REAL_PATH + "data/hull-LLZO/*.res") print() print(80 * "-") self.assertEqual( len(cursor), 12, "Error with test res files, please check installation...") hull = QueryConvexHull(cursor=cursor, elements=["La2O3", "ZrO2", "Li2O"], no_plot=True) self.assertEqual(len(hull.cursor), 7) self.assertEqual(len(hull.hull_cursor), 5) hull = QueryConvexHull( cursor=cursor, elements=["La2O3", "ZrO2", "Li2O"], hull_cutoff=0.01, no_plot=True, ) self.assertEqual(len(hull.cursor), 7) self.assertEqual(len(hull.hull_cursor), 6) self.assertEqual(len(hull.convex_hull.vertices), 5) for doc in hull.hull_cursor: if "cubic-LLZO" in doc["source"][0]: self.assertAlmostEqual(doc["formation_enthalpy_per_atom"], -0.05758265622) self.assertAlmostEqual(doc["hull_distance"], 0.008746875) break else: raise RuntimeError("Did not find cubic-LLZO in cursor")
def test_pseudoternary_from_fake_query(self): cursor, s = res2dict(REAL_PATH + "data/hull-LLZO/*.res") print() print(80 * "-") self.assertEqual( len(cursor), 12, "Error with test res files, please check installation...") hull = QueryConvexHull(cursor=cursor, elements=["La2O3", "ZrO2", "Li2O"], no_plot=True) self.assertEqual(len(hull.cursor), 7) fake_query = DBQuery.__new__(DBQuery) fake_query.cursor = hull.cursor for ind, doc in enumerate(fake_query.cursor): fake_query.cursor[ind]["_id"] = None fake_query.cursor[ind]["text_id"] = [doc["source"][0], "."] fake_query._non_elemental = True fake_query._create_hull = True fake_query.args = dict() fake_query.args["intersection"] = True fake_query.args["subcmd"] = "hull" fake_query.args["composition"] = ["La2O3:ZrO2:Li2O"] hull = QueryConvexHull( query=fake_query, hull_cutoff=0.01, chempots=[26200.3194 / 40, -8715.94784 / 12, -3392.59361 / 12], no_plot=True, ) self.assertEqual(len(hull.cursor), 10) self.assertEqual(len(hull.hull_cursor), 9)
def diff_hulls(client, collections, **args): """ Helper function to diff hulls from cmd-line args. Parameters: client (MongoClient): connection to database collections (dict of Collection): dict of collections to query Keyword arguments: args: dict, command-line arguments to select hulls. """ from matador.query import DBQuery from matador.hull import QueryConvexHull diff_args = args['compare'] del args['compare'] args['no_plot'] = True if args.get('verbosity') in [0, None] and not args.get('debug'): args['quiet'] = True diff_args = sorted(diff_args) args['time'] = diff_args[0] print('Calculating hull {} days ago...'.format(args['time'])) query_old = DBQuery(client, collections, **args) hull_old = QueryConvexHull(query_old, **args) if len(diff_args) == 1 or isinstance(diff_args, str): args['time'] = '0' else: args['time'] = diff_args[1] if args['time'] == '0': print('... to compare with up-to-date hull.') else: print('... to compare with hull {} days ago.'.format(args['time'])) query_new = DBQuery(client, collections, **args) hull_new = QueryConvexHull(query_new, **args) HullDiff(hull_old, hull_new, **args)
def main(): """ Run GA. """ from glob import glob from sys import argv from matador.hull import QueryConvexHull from matador.fingerprints.similarity import get_uniq_cursor from matador.utils.chem_utils import get_formula_from_stoich from matador.scrapers.castep_scrapers import res2dict from ilustrado.ilustrado import ArtificialSelector cursor = [res2dict(res)[0] for res in glob('seed/*.res')] hull = QueryConvexHull(cursor=cursor, no_plot=True, kpoint_tolerance=0.03, summary=True, hull_cutoff=1e-1) print('Filtering down to only ternary phases... {}'.format( len(hull.hull_cursor))) hull.hull_cursor = [ doc for doc in hull.hull_cursor if len(doc['stoichiometry']) == 3 ] print('Filtering unique structures... {}'.format(len(hull.hull_cursor))) # uniq_list, _, _, _ = list(get_uniq_cursor(hull.hull_cursor[1:-1], debug=False)) # cursor = [hull.hull_cursor[1:-1][ind] for ind in uniq_list] cursor = hull.hull_cursor print('Final cursor length... {}'.format(len(cursor))) print('over {} stoichiometries...'.format( len( set([ get_formula_from_stoich(doc['stoichiometry']) for doc in cursor ])))) print([doc['stoichiometry'] for doc in cursor]) def filter_fn(doc): """ Filter out any non-ternary phases. """ return True if len(doc['stoichiometry']) == 3 else False ArtificialSelector(gene_pool=cursor, seed='KPSn', compute_mode='slurm', entrypoint=__file__, walltime_hrs=12, slurm_template='template.slurm', max_num_nodes=100, hull=hull, check_dupes=0, structure_filter=filter_fn, best_from_stoich=True, max_num_mutations=3, max_num_atoms=50, mutation_rate=0.4, crossover_rate=0.6, num_generations=20, population=30, num_survivors=20, elitism=0.5, loglevel='debug')
def test_binary_volume_curve(self): """ Test simple binary volume curve. """ res_list = glob(REAL_PATH + "data/hull-LiP-mdm_chem_mater/*.res") cursor = [res2dict(res)[0] for res in res_list] hull = QueryConvexHull(cursor=cursor, elements=["Li", "P"], no_plot=True) hull.volume_curve() self.assertEqual(len(hull.volume_data["x"][0]), len(hull.hull_cursor) - 1) self.assertEqual(len(hull.volume_data["electrode_volume"][0]), len(hull.hull_cursor) - 1)
def test_binary_voltage_mayo(self): """ Test binary voltages from cursor for Mayo et al, DOI: 10.1021/acs.chemmater.5b04208. """ res_list = glob(REAL_PATH + "data/hull-LiP-mdm_chem_mater/*.res") cursor = [res2dict(res)[0] for res in res_list] hull = QueryConvexHull(cursor=cursor, elements=["Li", "P"], no_plot=True, voltage=True) for profile in hull.voltage_data: self.assertEqual(len(profile.voltages), len(profile.capacities)) LiP_voltage_curve = np.loadtxt(REAL_PATH + "data/LiP_voltage.csv", delimiter=",") self.assertTrue(len(hull.voltage_data) == 1) np.testing.assert_allclose( hull.voltage_data[0].voltages, LiP_voltage_curve[:, 1], verbose=True, rtol=1e-4, ) np.testing.assert_allclose(hull.voltage_data[0].capacities, LiP_voltage_curve[:, 0], verbose=True, rtol=1e-4) self._check_voltages_match_capacities(hull.voltage_data)
def test_multivalent_binary_voltage(self): """ Test simple binary voltage curve. """ hull_cursor = [] test_Q = np.loadtxt(REAL_PATH + "data/voltage_data/LiAs_Q.dat") test_V = np.loadtxt(REAL_PATH + "data/voltage_data/LiAs_V.dat") for i in range(5): with open(REAL_PATH + "data/voltage_data/hull_data" + str(i) + ".json") as f: flines = f.readlines() # replace all Li with Mg flines = [line.replace("Li", "Mg") for line in flines] hull_cursor.append(json.loads("\n".join(flines))) hull = QueryConvexHull(cursor=hull_cursor, species=["Mg", "As"], voltage=True, no_plot=True) self.assertEqual(len(hull.voltage_data), 1) np.testing.assert_array_almost_equal(hull.voltage_data[0].voltages, 2 * test_V, decimal=5, verbose=True) np.testing.assert_array_almost_equal(hull.voltage_data[0].capacities, test_Q, decimal=5) self.assertAlmostEqual(hull.voltage_data[0].average_voltage, 2 * 0.949184, places=3) self._check_voltages_match_capacities(hull.voltage_data)
def test_binary_voltage(self): """ Test simple binary voltage curve. """ hull_cursor = [] test_Q = np.loadtxt(REAL_PATH + "data/voltage_data/LiAs_Q.dat") test_V = np.loadtxt(REAL_PATH + "data/voltage_data/LiAs_V.dat") for i in range(5): with open(REAL_PATH + "data/voltage_data/hull_data" + str(i) + ".json") as f: hull_cursor.append(json.load(f)) hull = QueryConvexHull(cursor=hull_cursor, species=["Li", "As"], voltage=True, no_plot=True) self.assertTrue(len(hull.voltage_data) == 1) np.testing.assert_array_almost_equal(hull.voltage_data[0].voltages, test_V, decimal=5, verbose=True) np.testing.assert_array_almost_equal(hull.voltage_data[0].capacities, test_Q, decimal=5) self.assertAlmostEqual(hull.voltage_data[0].average_voltage, 0.949184, places=3) self._check_voltages_match_capacities(hull.voltage_data)
def test_ternary_voltage_with_exclusively_two_phase_regions(self): """ Test ternary voltages exclusively awkward two-phase regions. """ # load old hull then rejig it to go through a ternary phase res_list = glob(REAL_PATH + "data/hull-KPSn-KP/*.res") self.assertEqual( len(res_list), 87, "Could not find test res files, please check installation...", ) cursor = [res2dict(res)[0] for res in res_list] cursor = [ doc for doc in cursor if (doc["stoichiometry"] == [["P", 1], ["Sn", 1]] or doc["stoichiometry"] == [["K", 1], ["P", 1], ["Sn", 1]] or doc["stoichiometry"] == [["P", 1]] or doc["stoichiometry"] == [["K", 1]] or doc["stoichiometry"] == [["Sn", 1]]) ] hull = QueryConvexHull( cursor=cursor, elements=["K", "Sn", "P"], no_plot=True, pathways=True, voltage=True, ) self.assertEqual(len(hull.voltage_data), 1) self._check_voltages_match_capacities(hull.voltage_data)
def pseudoternary_hull(): """ Import some other res files ready to make a hull. """ os.chdir(REAL_PATH + "/data/hull-LLZO") sys.argv = ["matador", "import", "--force", "--db", DB_NAME] if CONFIG_FNAME is not None: sys.argv += ["--config", CONFIG_FNAME] if DEBUG: sys.argv += ["--debug"] matador.cli.cli.main(no_quickstart=True) query = DBQuery( db=DB_NAME, subcmd="hull", composition="La2O3:Li2O:ZrO2", config=CONFIG_FNAME, details=True, source=True, no_plot=True, ) hull = QueryConvexHull(query=query) os.chdir(OUTPUT_DIR) return query, hull
def test_ternary_voltage_with_single_phase_region(self): """ Test ternary voltages with single-phase regions. """ # load old hull then rejig it to go through a ternary phase cursor = res2dict(REAL_PATH + "data/hull-LiSiP/*.res")[0] hull = QueryConvexHull(cursor=cursor, species="LiSiP", no_plot=True, voltage=True) np.testing.assert_array_almost_equal( np.asarray(hull.voltage_data[0].voltages), np.asarray([ 1.1683, 1.1683, 1.0759, 0.7983, 0.6447, 0.3726, 0.3394, 0.1995, 0.1570, 0.1113, 0.1041, 0.0000, ]), decimal=3, ) self.assertEqual(len(hull.voltage_data[0].capacities), 12) self.assertEqual(len(hull.voltage_data[1].capacities), 11) self._check_voltages_match_capacities(hull.voltage_data)
def test_ternary_hull_plot(self): """ Test plotting ternary hull. """ expected_files = ["KSnP_hull.png", "KSnP_voltage.png"] for expected_file in expected_files: if os.path.isfile(expected_file): os.remove(expected_file) res_list = glob(REAL_PATH + "data/hull-KPSn-KP/*.res") self.assertEqual( len(res_list), 87, "Could not find test res files, please check installation...", ) cursor = [res2dict(res)[0] for res in res_list] QueryConvexHull( cursor=cursor, elements=["K", "Sn", "P"], no_plot=False, png=True, quiet=False, voltage=True, labels=True, label_cutoff=0.05, hull_cutoff=0.1, capmap=True, ) self.assertTrue(os.path.isfile(expected_file)) for expected_file in expected_files: os.remove(expected_file)
def test_pseudoternary_hull_with_custom_chempots_below_hull(self): cursor, s = res2dict(REAL_PATH + "data/hull-LLZO/*.res") hull = QueryConvexHull( cursor=cursor, elements=["La2O3", "ZrO2", "Li2O"], hull_cutoff=0.02, chempots=[26200.3194 / 40, -8715.94784 / 12, -3392.59361 / 12], no_plot=True, ) self.assertEqual(len(hull.cursor), 10) self.assertEqual(len(hull.hull_cursor), 9) for doc in cursor: if "La2O3" in doc["source"][0]: new_doc = copy.deepcopy(doc) new_doc["enthalpy_per_atom"] -= 1 new_doc["source"][0] = "IMAGINARY.res" hull_dists = hull.get_hull_distances([[1, 0, -1]]) self.assertAlmostEqual(hull_dists[0], -1)
def test_hull_from_file_with_extraneous_elements(self): """ Loading hull structures from files with too many elements. """ res_list = glob(REAL_PATH + "data/hull-KPSn-KP/*.res") cursor = [res2dict(res)[0] for res in res_list] hull = QueryConvexHull(cursor=cursor, elements=["K", "Sn"], no_plot=True, debug=True) self.assertEqual(len(hull.hull_cursor), 5)
def test_pseudoternary_hull_failure(self): cursor, s = res2dict(REAL_PATH + "data/hull-LLZO/*.res") print() print(80 * "-") self.assertEqual( len(cursor), 12, "Error with test res files, please check installation...") with self.assertRaises(RuntimeError): QueryConvexHull(cursor=cursor, no_plot=True)
def test_filter_cursor(self): cursor, s = res2dict(REAL_PATH + "data/hull-LLZO/*.res") species = ["Li2O", "La2O3", "ZrO2"] new_cursor = QueryConvexHull.filter_cursor_by_chempots(species, cursor) self.assertEqual(len(cursor), 12) self.assertEqual(len(new_cursor), 7) cursor = [{ "stoichiometry": [["Li", 7], ["O", 12], ["Zr", 2], ["La", 3]] }] new_cursor = QueryConvexHull.filter_cursor_by_chempots(species, cursor) self.assertEqual(len(new_cursor), 1) self.assertAlmostEqual(new_cursor[0]["concentration"][0], 0.5, msg="Concentrations do not match") self.assertAlmostEqual( new_cursor[0]["concentration"][1], 1.5 / 7.0, msg="Concentrations do not match", )
def test_hull_pseudobinary_hull(self): cursor, s = res2dict(REAL_PATH + "data/query-SrTiO-oqmd_1.1/*.res") print() print(80 * "-") self.assertEqual( len(cursor), 202, "Error with test res files, please check installation...") hull = QueryConvexHull(cursor=cursor, species=["Sr", "TiO3"], no_plot=True) self.assertEqual(len(hull.cursor), 37) self.assertEqual(len(hull.hull_cursor), 3) hull = QueryConvexHull(cursor=cursor, species=["Sr", "TiO3"], hull_cutoff=0.05, no_plot=True) self.assertEqual(len(hull.cursor), 37) self.assertEqual(len(hull.hull_cursor), 10)
def test_hull_from_file(self): """ Loading hull structures from files. """ res_list = glob(REAL_PATH + "data/hull-KPSn-KP/*.res") self.assertEqual( len(res_list), 87, "Could not find test res files, please check installation...", ) cursor = [res2dict(res)[0] for res in res_list] hull = QueryConvexHull(cursor=cursor, elements=["K", "Sn", "P"], no_plot=True) self.assertEqual(len(hull.hull_cursor), 16)
def test_voltage_labels(self): expected_files = ["KP_voltage.png"] cursor = res2dict(REAL_PATH + "data/hull-KP-KSnP_pub/*.res")[0] hull = QueryConvexHull(cursor=cursor, species="KP", no_plot=True, voltage=True, labels=True) plot_voltage_curve(hull.voltage_data, labels=True, savefig=expected_files[0]) for expected_file in expected_files: self.assertTrue(os.path.isfile(expected_file))
def test_pseudoternary_hull_NaVSO4(self): cursor, s = castep2dict(REAL_PATH + "data/hull-NaVSO4/*.castep") print(80 * "-") self.assertEqual( len(cursor), 9, "Error with test castep files, please check installation...") hull = QueryConvexHull( cursor=cursor, elements=["Na", "V", "SO4"], chempots=[-999, -999, 100], no_plot=True, ) self.assertEqual(len(hull.cursor), 8) self.assertEqual(len(hull.hull_cursor), 6)
def pseudoternary_hull_no_query(): """ Import some other res files ready to make a hull. """ hull = QueryConvexHull( db=DB_NAME, composition="La2O3:Li2O:ZrO2", config=CONFIG_FNAME, details=True, source=True, no_plot=True, ) os.chdir(OUTPUT_DIR) return hull
def test_variations_of_element_parsing(self): cursor, s = res2dict(REAL_PATH + "data/hull-KP-KSnP_pub/*.res") self.assertEqual( len(cursor), 295, "Error with test res files, please check installation...") msg = "failed to parse elements=['KP']" hull = QueryConvexHull(cursor=cursor, elements=["KP"], no_plot=True) self.assertEqual(len(hull.cursor), 295, msg=msg) self.assertEqual(len(hull.hull_cursor), 7, msg=msg) msg = "failed to parse species=['KP']" hull = QueryConvexHull(cursor=cursor, species=["KP"], no_plot=True) self.assertEqual(len(hull.cursor), 295, msg=msg) self.assertEqual(len(hull.hull_cursor), 7, msg=msg) msg = "failed to parse elements=['K', 'P']" hull = QueryConvexHull(cursor=cursor, elements=["K", "P"], no_plot=True) self.assertEqual(len(hull.cursor), 295, msg=msg) self.assertEqual(len(hull.hull_cursor), 7, msg=msg) msg = "failed to parse species=['K', 'P']" hull = QueryConvexHull(cursor=cursor, species=["K", "P"], no_plot=True) self.assertEqual(len(hull.cursor), 295, msg=msg) self.assertEqual(len(hull.hull_cursor), 7, msg=msg) msg = "failed to parse species='KP'" hull = QueryConvexHull(cursor=cursor, species="KP", no_plot=True) self.assertEqual(len(hull.cursor), 295, msg=msg) self.assertEqual(len(hull.hull_cursor), 7, msg=msg) msg = "failed to parse elements='KP'" hull = QueryConvexHull(cursor=cursor, elements="KP", no_plot=True) self.assertEqual(len(hull.cursor), 295, msg=msg) self.assertEqual(len(hull.hull_cursor), 7, msg=msg) msg = "failed to parse elements='K:P'" hull = QueryConvexHull(cursor=cursor, elements="K:P", no_plot=True) self.assertEqual(len(hull.cursor), 295, msg=msg) self.assertEqual(len(hull.hull_cursor), 7, msg=msg) msg = "failed to parse species='K:P'" hull = QueryConvexHull(cursor=cursor, species="K:P", no_plot=True) self.assertEqual(len(hull.cursor), 295, msg=msg) self.assertEqual(len(hull.hull_cursor), 7, msg=msg)
def test_binary_hull_plot(self): """ Test plotting binary hull. """ expected_files = ["KP_hull_simple.svg"] cursor = res2dict(REAL_PATH + "data/hull-KP-KSnP_pub/*.res")[0] QueryConvexHull( cursor=cursor, elements=["K", "P"], svg=True, hull_cutoff=0.0, plot_kwargs={ "plot_fname": "KP_hull_simple", "svg": True }, ) for expected_file in expected_files: self.assertTrue(os.path.isfile(expected_file))
def test_ternary_voltage_problematic_with_crystal_models(self): """ Test for NaSnP voltages which triggered a bug in the capacity calculation. """ cursor = res2dict(REAL_PATH + "data/voltage_data/voltage-NaSnP/*.res", as_model=True)[0] hull = QueryConvexHull(cursor=cursor, species="NaSnP", no_plot=True, voltage=True, volume=True) self._check_voltages_match_capacities(hull.voltage_data) self.assertEqual(len(hull.voltage_data), 2) self.assertEqual(len(hull.voltage_data[0].capacities), 13) self.assertEqual(len(hull.voltage_data[1].capacities), 12)
def test_binary_hull_distances(self): """ Test computing binary hull distances. """ res_list = glob(REAL_PATH + "data/hull-KP-KSnP_pub/*.res") self.assertEqual( len(res_list), 295, "Could not find test res files, please check installation...", ) cursor = [res2dict(res)[0] for res in res_list] hull = QueryConvexHull(cursor=cursor, elements=["K", "P"], no_plot=True) hull_dist_test = np.loadtxt(REAL_PATH + "data/test_KP_hull_dist.dat") np.testing.assert_array_almost_equal(np.sort(hull_dist_test), np.sort(hull.hull_dist), decimal=3)
def test_hull_from_custom_chempots(self): """ Loading hull structures from files. """ res_list = glob(REAL_PATH + "data/hull-KPSn-KP/*.res") self.assertEqual( len(res_list), 87, "Could not find test res files, please check installation...", ) cursor = [res2dict(res)[0] for res in res_list] cursor = [doc for doc in cursor if len(doc["stoichiometry"]) != 1] hull = QueryConvexHull( cursor=cursor, elements=["K", "Sn", "P"], no_plot=True, chempots=[-791.456765, -928.045026 / 2.0, 878.326441 / 4.0], ) self.assertEqual(len(hull.hull_cursor), 16)
def test_hull_with_crystal_models(self): """ Loading hull structures from files. """ cursor, failures = res2dict(REAL_PATH + "data/hull-KPSn-KP/*.res", as_model=True) self.assertEqual( len(cursor), 87, "Could not find all test res files, please check installation...", ) cursor = [doc for doc in cursor if doc.num_elements != 1] hull = QueryConvexHull( cursor=cursor, elements=["K", "Sn", "P"], no_plot=True, chempots=[-791.456765, -928.045026 / 2.0, 878.326441 / 4.0], ) self.assertEqual(len(hull.hull_cursor), 16)