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_pxrd_plot(self): structure = res2dict(REAL_PATH + "data/res_files/KPSn-OQMD_123456.res", as_model=True)[0] plot_pxrd(structure, png=True) self.assertTrue(os.path.isfile("K7PSn_pxrd.png")) plot_pdf([structure, structure], filename="test_pxrd", png=True) self.assertTrue(os.path.isfile("test_pxrd.png"))
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_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_binary_battery_plots(self): """ Test plotting binary hull. """ expected_files = ["KP_hull.png", "KP_voltage.png", "KP_volume.png"] cursor = res2dict(REAL_PATH + "data/hull-KP-KSnP_pub/*.res")[0] QueryConvexHull( cursor=cursor, elements=["K", "P"], no_plot=False, png=True, quiet=False, voltage=True, labels=True, label_cutoff=0.05, hull_cutoff=0.1, volume=True, plot_kwargs={"colour_by_source": True}, ) for expected_file in expected_files: self.assertTrue(os.path.isfile(expected_file))
#!/usr/bin/env python """ This example runs directly from a matador DBQuery. """ from matador.hull import QueryConvexHull from matador.scrapers import res2dict from ilustrado.ilustrado import ArtificialSelector # prepare best structures from hull as gene pool cursor, failures = res2dict("hull/*.res") hull = QueryConvexHull( cursor=cursor, intersection=True, no_plot=True, kpoint_tolerance=0.03, summary=True, hull_cutoff=7.5e-2 ) def filter_fn(doc): """ Filter out any non-binary phases. """ return len(doc['stoichiometry']) == 2 print('Filtering down to only ternary phases... {}'.format(len(hull.hull_cursor))) cursor = [doc for doc in hull.hull_cursor if len(doc['stoichiometry']) == 2] print('Final cursor length... {}'.format(len(cursor))) ArtificialSelector( gene_pool=cursor, compute_mode="manual", hull=hull, fitness_metric='hull', check_dupes=True, check_dupes_hull=False,
def emt_relax(): """ Perform a test run of Ilustrado with dummy DFT, on all cores of current machine. """ from matador.hull import QueryConvexHull from ilustrado.ilustrado import ArtificialSelector from ase.calculators.emt import EMT if os.uname()[1] == "cluster2": cpus = cpu_count() - 2 else: cpus = cpu_count() structures, _ = res2dict(REAL_PATH + "AuCu_structures/*.res") # prepare best structures from hull as gene pool hull = QueryConvexHull( cursor=structures, elements=["Au", "Cu"], intersection=True, subcmd="hull", no_plot=True, hull_cutoff=0, ) from multiprocessing import Queue cursor = hull.cursor for doc in cursor: queue = Queue() relaxer = AseRelaxation(doc, queue) relaxer.relax() doc.update(queue.get()) print("Running on {} cores on {}.".format(cpus, os.uname()[1])) def filter_fn(doc): return len(doc["stoichiometry"]) == 2 ArtificialSelector( gene_pool=cursor, hull=hull, debug=False, fitness_metric="hull", nprocs=cpus, structure_filter=filter_fn, check_dupes=0, check_dupes_hull=False, ncores=1, testing=True, ase_calculator=EMT(), mutations=[ "nudge_positions", "permute_atoms", "random_strain", "vacancy" ], max_num_mutations=1, max_num_atoms=50, mutation_rate=0.5, crossover_rate=0.5, num_generations=3, population=20, num_survivors=10, elitism=0.5, loglevel="debug", )