class VaspToComputedEntryDroneTest(unittest.TestCase): def setUp(self): self.test_dir = os.path.join(os.path.dirname(__file__), "..", "..", "..", "..", 'test_files') self.drone = VaspToComputedEntryDrone(data=["efermi"]) self.structure_drone = VaspToComputedEntryDrone(True) def test_get_valid_paths(self): for path in os.walk(self.test_dir): if path[0] == self.test_dir: self.assertTrue(len(self.drone.get_valid_paths(path)) > 0) def test_assimilate(self): entry = self.drone.assimilate(self.test_dir) for p in ["hubbards", "is_hubbard", "potcar_symbols", "run_type"]: self.assertIn(p, entry.parameters) self.assertAlmostEqual(entry.data["efermi"], 1.8301027) self.assertEqual(entry.composition.reduced_formula, "LiFe4(PO4)4") self.assertAlmostEqual(entry.energy, -269.38319884) entry = self.structure_drone.assimilate(self.test_dir) self.assertEqual(entry.composition.reduced_formula, "LiFe4(PO4)4") self.assertAlmostEqual(entry.energy, -269.38319884) self.assertIsInstance(entry, ComputedStructureEntry) self.assertIsNotNone(entry.structure) compat = MITCompatibility() self.assertIsNone(compat.process_entry(entry)) def test_to_from_dict(self): d = self.structure_drone.to_dict drone = VaspToComputedEntryDrone.from_dict(d) self.assertEqual(type(drone), VaspToComputedEntryDrone)
class VaspToComputedEntryDroneTest(unittest.TestCase): def setUp(self): self.test_dir = os.path.join(os.path.dirname(__file__), "..", "..", "..", "..", 'test_files') self.drone = VaspToComputedEntryDrone(data=["efermi"]) self.structure_drone = VaspToComputedEntryDrone(True) def test_get_valid_paths(self): for path in os.walk(self.test_dir): if path[0] == self.test_dir: self.assertTrue(len(self.drone.get_valid_paths(path)) > 0) def test_assimilate(self): with warnings.catch_warnings(): warnings.simplefilter("ignore") entry = self.drone.assimilate(self.test_dir) for p in ["hubbards", "is_hubbard", "potcar_spec", "run_type"]: self.assertIn(p, entry.parameters) self.assertAlmostEqual(entry.data["efermi"], -6.62148548) self.assertEqual(entry.composition.reduced_formula, "Xe") self.assertAlmostEqual(entry.energy, 0.5559329) entry = self.structure_drone.assimilate(self.test_dir) self.assertEqual(entry.composition.reduced_formula, "Xe") self.assertAlmostEqual(entry.energy, 0.5559329) self.assertIsInstance(entry, ComputedStructureEntry) self.assertIsNotNone(entry.structure) # self.assertEqual(len(entry.parameters["history"]), 2) def test_to_from_dict(self): d = self.structure_drone.as_dict() drone = VaspToComputedEntryDrone.from_dict(d) self.assertEqual(type(drone), VaspToComputedEntryDrone)
class VaspToComputedEntryDroneTest(unittest.TestCase): def setUp(self): self.test_dir = os.path.join(os.path.dirname(__file__), "..", "..", "..", "..", 'test_files') self.drone = VaspToComputedEntryDrone(data=["efermi"]) self.structure_drone = VaspToComputedEntryDrone(True) def test_get_valid_paths(self): for path in os.walk(self.test_dir): if path[0] == self.test_dir: self.assertTrue(len(self.drone.get_valid_paths(path)) > 0) def test_assimilate(self): with warnings.catch_warnings(): warnings.simplefilter("ignore") entry = self.drone.assimilate(self.test_dir) for p in ["hubbards", "is_hubbard", "potcar_spec", "run_type"]: self.assertIn(p, entry.parameters) self.assertAlmostEqual(entry.data["efermi"], -6.62148548) self.assertEqual(entry.composition.reduced_formula, "Xe") self.assertAlmostEqual(entry.energy, 0.5559329) entry = self.structure_drone.assimilate(self.test_dir) self.assertEqual(entry.composition.reduced_formula, "Xe") self.assertAlmostEqual(entry.energy, 0.5559329) self.assertIsInstance(entry, ComputedStructureEntry) self.assertIsNotNone(entry.structure) self.assertEqual(len(entry.parameters["history"]), 2) def test_to_from_dict(self): d = self.structure_drone.as_dict() drone = VaspToComputedEntryDrone.from_dict(d) self.assertEqual(type(drone), VaspToComputedEntryDrone)
class VaspToComputedEntryDroneTest(unittest.TestCase): def setUp(self): self.test_dir = os.path.join(os.path.dirname(__file__), "..", "..", "..", "..", 'test_files') self.drone = VaspToComputedEntryDrone(data=["efermi"]) self.structure_drone = VaspToComputedEntryDrone(True) def test_get_valid_paths(self): for path in os.walk(self.test_dir): if path[0] == self.test_dir: self.assertTrue(len(self.drone.get_valid_paths(path)) > 0) def test_assimilate(self): entry = self.drone.assimilate(self.test_dir) for p in ["hubbards", "is_hubbard", "potcar_spec", "run_type"]: self.assertIn(p, entry.parameters) self.assertAlmostEqual(entry.data["efermi"], 1.8301027) self.assertEqual(entry.composition.reduced_formula, "LiFe4(PO4)4") self.assertAlmostEqual(entry.energy, -269.38319884) entry = self.structure_drone.assimilate(self.test_dir) self.assertEqual(entry.composition.reduced_formula, "LiFe4(PO4)4") self.assertAlmostEqual(entry.energy, -269.38319884) self.assertIsInstance(entry, ComputedStructureEntry) self.assertIsNotNone(entry.structure) self.assertEqual(len(entry.parameters["history"]), 2) compat = MITCompatibility(check_potcar_hash=False) self.assertIsNone(compat.process_entry(entry)) def test_to_from_dict(self): d = self.structure_drone.as_dict() drone = VaspToComputedEntryDrone.from_dict(d) self.assertEqual(type(drone), VaspToComputedEntryDrone)
def create_entry(cdir): """create_entry Creates a ComputedStructure entry from a local calculation. :param cdir: Directory containing VASP calculation. :return: A ComputedStructureEntry object. """ drone = VaspToComputedEntryDrone(inc_structure=True) e = drone.assimilate(cdir) if e is None: print("Missing local calculation for", cdir) sys.exit(0) else: e.entry_id = cdir.rsplit("/", 3)[-2] return e
def calculate_phase_stability(args): #This initializes the REST adaptor. a = MPRester(args.api_key) drone = VaspToComputedEntryDrone() entry = drone.assimilate(args.directory) compat = MaterialsProjectCompatibility() entry = compat.process_entry(entry) if not entry: print "Calculation parameters are not consistent with Materials " + \ "Project parameters." sys.exit() syms = [el.symbol for el in entry.composition.elements] #This gets all entries belonging to the relevant system. entries = a.get_entries_in_chemsys(syms) entries.append(entry) #Process entries with Materials Project compatibility. entries = compat.process_entries(entries) print [e.composition.reduced_formula for e in entries]