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_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)