def test_get_kpoint_weights(self): for name in ["SrTiO3", "LiFePO4", "Graphite"]: s = PymatgenTest.get_structure(name) a = SpacegroupAnalyzer(s) ir_mesh = a.get_ir_reciprocal_mesh((4, 4, 4)) weights = [i[1] for i in ir_mesh] weights = np.array(weights) / sum(weights) for i, w in zip(weights, a.get_kpoint_weights([i[0] for i in ir_mesh])): self.assertAlmostEqual(i, w) for name in ["SrTiO3", "LiFePO4", "Graphite"]: s = PymatgenTest.get_structure(name) a = SpacegroupAnalyzer(s) ir_mesh = a.get_ir_reciprocal_mesh((1, 2, 3)) weights = [i[1] for i in ir_mesh] weights = np.array(weights) / sum(weights) for i, w in zip(weights, a.get_kpoint_weights([i[0] for i in ir_mesh])): self.assertAlmostEqual(i, w) v = Vasprun(os.path.join(test_dir, "vasprun.xml")) a = SpacegroupAnalyzer(v.final_structure) wts = a.get_kpoint_weights(v.actual_kpoints) for w1, w2 in zip(v.actual_kpoints_weights, wts): self.assertAlmostEqual(w1, w2) kpts = [[0, 0, 0], [0.15, 0.15, 0.15], [0.2, 0.2, 0.2]] self.assertRaises(ValueError, a.get_kpoint_weights, kpts)
def test_batch_write_input(self): with ScratchDir("."): structures = [PymatgenTest.get_structure("Li2O"), PymatgenTest.get_structure("LiFePO4")] batch_write_input(structures) for d in ['Li4Fe4P4O16_1', 'Li2O1_0']: for f in ["INCAR", "KPOINTS", "POSCAR", "POTCAR"]: self.assertTrue(os.path.exists(os.path.join(d, f)))
def test_modes(self): s = PymatgenTest.get_structure("CsCl") nacl = PymatgenTest.get_structure("CsCl") nacl.replace_species({"Cs": "Na"}) nacl.scale_lattice(184.384551033) p = RLSVolumePredictor(radii_type="ionic", use_bv=False) self.assertRaises(ValueError, p.predict, s, nacl) p = RLSVolumePredictor(radii_type="ionic-atomic", use_bv=False) self.assertAlmostEqual(p.predict(s, nacl), 391.884366481) p = RLSVolumePredictor(radii_type="ionic-atomic", use_bv=True) self.assertAlmostEqual(p.predict(s, nacl), 342.84905395082535)
def test_input_sets(self): # Test bulk bulk_set = MPSurfaceSet(self.struct_ir, bulk=True) self.assertFalse(bulk_set.auto_dipole) self.assertIsNone(bulk_set.incar.get('LDIPOL')) self.assertIsNone(bulk_set.incar.get('LVTOT')) # Test slab slab_set = MPSurfaceSet(self.slab_100) self.assertTrue(slab_set.auto_dipole) self.assertTrue(slab_set.incar.get('LDIPOL')) self.assertTrue(slab_set.incar.get('LVTOT')) banio3_slab = generate_all_slabs( PymatgenTest.get_structure('BaNiO3'), 1, 7.0, 20.0)[0] banio3_slab_set = MPSurfaceSet(banio3_slab) self.assertTrue(banio3_slab_set.incar['LDAU'], True) # Test adsorbates fe_ads = self.wf_1.fws[-1].tasks[-1]['additional_fields']['slab'].copy() fe_ads.replace_species({'H': 'O', "Ir": "Fe"}) fe_ads_set = MPSurfaceSet(fe_ads) self.assertFalse(fe_ads_set.incar['LDAU']) # Test interaction of adsorbates and LDAU banio3_ads = banio3_slab.copy() banio3_ads.add_adsorbate_atom([-1], 'O', 0.5) banio3_ads.add_site_property('surface_properties', ['surface'] * len( banio3_slab) + ['adsorbate']) banio3_ads_set = MPSurfaceSet(banio3_ads) self.assertTrue(banio3_ads_set.incar['LDAU']) banio3_ads_set_noldau = MPSurfaceSet( banio3_ads, user_incar_settings={'LDAU': False}) self.assertFalse(banio3_ads_set_noldau.incar['LDAU'])
def setUpClass(cls): if not os.environ.get("VASP_PSP_DIR"): os.environ["VASP_PSP_DIR"] = os.path.join(module_dir, "reference_files") print( 'Note: This system is not set up to run VASP jobs. ' 'Please set your VASP_PSP_DIR environment variable.') cls.struct_si = PymatgenTest.get_structure("Si") cls.ref_incar = Incar.from_file( os.path.join(module_dir, "reference_files", "setup_test", "INCAR")) cls.ref_poscar = Poscar.from_file( os.path.join(module_dir, "reference_files", "setup_test", "POSCAR")) cls.ref_potcar = Potcar.from_file( os.path.join(module_dir, "reference_files", "setup_test", "POTCAR")) cls.ref_kpoints = Kpoints.from_file( os.path.join(module_dir, "reference_files", "setup_test", "KPOINTS")) cls.ref_incar_preserve = Incar.from_file(os.path.join(module_dir, "reference_files", "preserve_incar", "INCAR"))
def test_mutable_sequence_methods(self): s = self.structure s[0] = "Fe" self.assertEqual(s.formula, "Fe1 Si1") s[0] = "Fe", [0.5, 0.5, 0.5] self.assertEqual(s.formula, "Fe1 Si1") self.assertArrayAlmostEqual(s[0].frac_coords, [0.5, 0.5, 0.5]) s.reverse() self.assertEqual(s[0].specie, Element("Si")) self.assertArrayAlmostEqual(s[0].frac_coords, [0.75, 0.5, 0.75]) s[0] = {"Mn": 0.5} self.assertEqual(s.formula, "Mn0.5 Fe1") del s[1] self.assertEqual(s.formula, "Mn0.5") s[0] = "Fe", [0.9, 0.9, 0.9], {"magmom": 5} self.assertEqual(s.formula, "Fe1") self.assertEqual(s[0].magmom, 5) # Test atomic replacement. s["Fe"] = "Mn" self.assertEqual(s.formula, "Mn1") # Test slice replacement. s = PymatgenTest.get_structure("Li2O") s[1:3] = "S" self.assertEqual(s.formula, "Li1 S2")
def test_charge_gen(self): struc = PymatgenTest.get_structure("VO2") #assemble set of defects to get charges for vac_gen = VacancyGenerator(struc) vacs = list(vac_gen) full_subs = [] for sub_elt in ['V', 'O', 'S']: sub_gen = SubstitutionGenerator(struc, sub_elt) full_subs.extend( list(sub_gen)) int_gen = VoronoiInterstitialGenerator(struc, "H") inters = list(int_gen) defect_list = list(set().union( vacs, full_subs, inters)) #test simple charges true_charges = {'Vac_O_mult4': 2, 'Int_H_Voronoi1_mult8': 0, 'Int_H_Voronoi2_mult8': 0, 'Vac_V_mult2': -4, 'Sub_S_on_V_mult2': 0, 'Int_H_Voronoi3_mult4': 0, 'Int_H_Voronoi4_mult4': 0, 'Sub_O_on_V_mult2': -2, 'Sub_S_on_O_mult4': 0, 'Sub_V_on_O_mult4': 1} for defect in defect_list: scg = SimpleChargeGenerator(defect) charged_defects_list = list(scg) def_name = charged_defects_list[0].name charge = charged_defects_list[0].charge self.assertEqual(len(charged_defects_list), 1) self.assertEqual( true_charges[def_name], charge)
def test_bandedgeshifting(self): struc = PymatgenTest.get_structure("VO2") struc.make_supercell(3) struc = struc vac = Vacancy(struc, struc.sites[0], charge=-3) besc = BandEdgeShiftingCorrection() params = {'hybrid_cbm': 1., 'hybrid_vbm': -1., 'vbm': -0.5, 'cbm': 0.6, 'num_hole_vbm': 0., 'num_elec_cbm': 0.} de = DefectEntry(vac, 0., corrections={}, parameters=params, entry_id=None) #test with no free carriers corr = besc.get_correction(de) self.assertEqual(corr['vbm_shift_correction'], 1.5) self.assertEqual(corr['elec_cbm_shift_correction'], 0.) self.assertEqual(corr['hole_vbm_shift_correction'], 0.) #test with free holes de.parameters.update({'num_hole_vbm': 1.}) corr = besc.get_correction(de) self.assertEqual(corr['vbm_shift_correction'], 1.5) self.assertEqual(corr['elec_cbm_shift_correction'], 0.) self.assertEqual(corr['hole_vbm_shift_correction'], 0.5) #test with free electrons de.parameters.update({'num_hole_vbm': 0., 'num_elec_cbm': 1.}) corr = besc.get_correction(de) self.assertEqual(corr['vbm_shift_correction'], 1.5) self.assertEqual(corr['elec_cbm_shift_correction'], 0.4) self.assertEqual(corr['hole_vbm_shift_correction'], 0.)
def test_CsCl_ionic(self): s = PymatgenTest.get_structure("CsCl") self.assertAlmostEqual(VolumePredictor(ionic_factor=0.20).predict(s), 112.36, 1) s.replace_species({"Cs": "Li", "Cl": "F"}) self.assertAlmostEqual(VolumePredictor(ionic_factor=0.20).predict(s), 16.974592999999995, 1)
def test_wf_functions(self): # Test slab trans params generator for slab in self.slabs: trans_params = get_slab_trans_params(slab) trans = SlabTransformation(**trans_params) new_slab = trans.apply_transformation(slab.oriented_unit_cell) self.assertTrue(np.allclose(new_slab.cart_coords, slab.cart_coords)) self.assertTrue(np.allclose(new_slab.lattice.matrix, slab.lattice.matrix)) # Try something a bit more complicated formulas = ['Si', 'Sn', 'SrTiO3', 'Li2O'] structs = [PymatgenTest.get_structure(s) for s in formulas] for struct in structs: slabs = generate_all_slabs(struct, max_index=2, min_slab_size=10, min_vacuum_size=20) for slab in slabs: trans_params = get_slab_trans_params(slab) trans = SlabTransformation(**trans_params) new_slab = trans.apply_transformation(slab.oriented_unit_cell) old_coords = np.around(slab.frac_coords, 10) % 1 new_coords = np.around(new_slab.frac_coords, 10) % 1 self.assertTrue(np.allclose(old_coords, new_coords)) self.assertTrue(np.allclose(new_slab.lattice.matrix, slab.lattice.matrix))
def setUp(self): struc = PymatgenTest.get_structure("VO2") struc.make_supercell(3) struc = struc self.vac = Vacancy(struc, struc.sites[0], charge=-3) abc = self.vac.bulk_structure.lattice.abc axisdata = [np.arange(0., lattval, 0.2) for lattval in abc] bldata = [np.array([1. for u in np.arange(0., lattval, 0.2)]) for lattval in abc] dldata = [ np.array([(-1 - np.cos(2 * np.pi * u / lattval)) for u in np.arange(0., lattval, 0.2)]) for lattval in abc ] self.frey_params = {'axis_grid': axisdata, 'bulk_planar_averages': bldata, 'defect_planar_averages': dldata, 'dielectric': 15} v = Vasprun(os.path.join(test_dir, 'vasprun.xml')) eigenvalues = v.eigenvalues.copy() kptweights = v.actual_kpoints_weights potalign = -0.1 vbm = v.eigenvalue_band_properties[2] cbm = v.eigenvalue_band_properties[1] self.bandfill_params = { 'eigenvalues': eigenvalues, 'kpoint_weights': kptweights, 'potalign': potalign, 'vbm': vbm, 'cbm': cbm } self.band_edge_params = {'hybrid_cbm': 1., 'hybrid_vbm': -1., 'vbm': -0.5, 'cbm': 0.6, 'num_hole_vbm': 1., 'num_elec_cbm': 1.}
def test_dimensionality(self): cscl = PymatgenTest.get_structure("CsCl") df = Dimensionality(bonds={("Cs", "Cl"): 3.5}) self.assertEqual(df.featurize(cscl)[0], 1) df = Dimensionality(bonds={("Cs", "Cl"): 3.7}) self.assertEqual(df.featurize(cscl)[0], 3)
def test_apply_transformation(self): structure = PymatgenTest.get_structure("LiFePO4") a = SpacegroupAnalyzer(structure, 0.1) structure = a.get_refined_structure() t = DopingTransformation("Ca2+", min_length=10) ss = t.apply_transformation(structure, 100) self.assertEqual(len(ss), 1) t = DopingTransformation("Al3+", min_length=15, ionic_radius_tol=0.1) ss = t.apply_transformation(structure, 100) self.assertEqual(len(ss), 0) # Aliovalent doping with vacancies for dopant, nstructures in [("Al3+", 2), ("N3-", 235), ("Cl-", 8)]: t = DopingTransformation(dopant, min_length=4, alio_tol=1, max_structures_per_enum=1000) ss = t.apply_transformation(structure, 1000) self.assertEqual(len(ss), nstructures) for d in ss: self.assertEqual(d["structure"].charge, 0) # Aliovalent doping with codopant for dopant, nstructures in [("Al3+", 3), ("N3-", 37), ("Cl-", 37)]: t = DopingTransformation(dopant, min_length=4, alio_tol=1, codopant=True, max_structures_per_enum=1000) ss = t.apply_transformation(structure, 1000) self.assertEqual(len(ss), nstructures) for d in ss: self.assertEqual(d["structure"].charge, 0) # Make sure compensation is done with lowest oxi state structure = PymatgenTest.get_structure("SrTiO3") t = DopingTransformation("Nb5+", min_length=5, alio_tol=1, max_structures_per_enum=1000, allowed_doping_species=["Ti4+"]) ss = t.apply_transformation(structure, 1000) self.assertEqual(len(ss), 3) for d in ss: self.assertEqual(d["structure"].formula, "Sr7 Ti6 Nb2 O24")
def setUp(self): super(TestBulkModulusWorkflow, self).setUp() self.struct_si = PymatgenTest.get_structure("Si") self.ndeformations = 6 self.deformations = [(np.identity(3) * (1 + x)).tolist() for x in np.linspace(-0.05, 0.05, self.ndeformations)] self.wf_config = {"VASP_CMD": ">>vasp_cmd<<", "DB_FILE": ">>db_file<<"} self.wf = wf_bulk_modulus(self.struct_si, self.wf_config)
def setUp(self): self.struc = PymatgenTest.get_structure("VO2") V_index = self.struc.indices_from_symbol("V")[0] sub_site = PeriodicSite("Sr", self.struc[V_index].coords, self.struc.lattice, coords_are_cartesian=True) self.substitution = Substitution(self.struc, sub_site)
def setUp(self): """ 1) Basic check for pymatgen configurations. 2) Setup all test workflow. """ super(TestNudgedElasticBandWorkflow, self).setUp() # Structures used for test: parent = PymatgenTest.get_structure("Li2O") parent.remove_oxidation_states() parent.make_supercell(2) ep0, ep1 = get_endpoints_from_index(parent, [0, 1]) neb_dir = [os.path.join(module_dir, "..", "..", "test_files", "neb_wf", "4", "inputs", "{:02}", "POSCAR").format(i) for i in range(5)] self.structures = [Structure.from_file(n) for n in neb_dir] # Run fake vasp test_yaml = os.path.join(module_dir, "../../test_files/neb_wf/config/neb_unittest.yaml") with open(test_yaml, 'r') as stream: self.config = yaml.safe_load(stream) # Use scratch directory as destination directory for testing self.config["common_params"]["_fw_env"] = {"run_dest_root": self.scratch_dir} # Config 1: The parent structure & two endpoint indexes provided; need relaxation first. self.config_1 = copy.deepcopy(self.config) self.config_1["common_params"]["is_optimized"] = False self.config_1["common_params"]["wf_name"] = "NEB_test_1" # Config 2: The parent structure & two endpoint indexes provided; no need to relax. self.config_2 = copy.deepcopy(self.config) del self.config_2["fireworks"][0] self.config_2["common_params"]["is_optimized"] = True self.config_2["common_params"]["wf_name"] = "NEB_test_2" # Config 3: Two endpoints provided; need to relax two endpoints. self.config_3 = copy.deepcopy(self.config) del self.config_3["fireworks"][0] self.config_3["common_params"]["is_optimized"] = False self.config_3["common_params"]["wf_name"] = "NEB_test_3" # Config 4: Two relaxed endpoints provided; no need to relax two endpoints. self.config_4 = copy.deepcopy(self.config_3) del self.config_4["fireworks"][0] self.config_4["common_params"]["is_optimized"] = True self.config_4["common_params"]["wf_name"] = "NEB_test_4" # Config 5: All images including two endpoints are provided. self.config_5 = copy.deepcopy(self.config) del self.config_5["fireworks"][0: 2] self.config_5["common_params"]["wf_name"] = "NEB_test_5" self.wf_1 = wf_nudged_elastic_band([parent], parent, self.config_1) self.wf_2 = wf_nudged_elastic_band([parent], parent, self.config_2) self.wf_3 = wf_nudged_elastic_band([ep0, ep1], parent, self.config_3) self.wf_4 = wf_nudged_elastic_band([ep0, ep1], parent, self.config_4) self.wf_5 = wf_nudged_elastic_band(self.structures, parent, self.config_5) # Workflow without the config file self.wf_6 = wf_nudged_elastic_band(self.structures, parent)
def setUp(self): super().setUp() self.tf_loc = os.path.join(ref_dir, "elastic_wf") self.struct_si = PymatgenTest.get_structure("Si") self.struct_si = SpacegroupAnalyzer( self.struct_si ).get_conventional_standard_structure() self.opt_struct = Structure.from_file( os.path.join(self.tf_loc, "1", "inputs", "POSCAR") ) # Base WF self.base_wf = get_wf( self.struct_si, "optimize_only.yaml", params=[{"db_file": ">>db_file<<"}] ) self.base_wf.append_wf( get_wf_elastic_constant( self.struct_si, db_file=">>db_file<<", stencils=[[0.01]] * 3 + [[0.03]] * 3, copy_vasp_outputs=True, ), self.base_wf.leaf_fw_ids, ) self.base_wf_noopt = get_wf_elastic_constant( self.opt_struct, stencils=[[0.01]] * 3 + [[0.03]] * 3, copy_vasp_outputs=False, sym_reduce=False, db_file=">>db_file<<", ) ec_incar_update = {"incar_update": {"EDIFF": 1e-6, "ENCUT": 700}} self.base_wf = add_modify_incar(self.base_wf, ec_incar_update) self.base_wf_noopt = add_modify_incar(self.base_wf_noopt, ec_incar_update) # Full preset WF self.preset_wf = wf_elastic_constant(self.struct_si) # Minimal WF self.minimal_wf = wf_elastic_constant_minimal(self.opt_struct) self.minimal_wf = add_modify_incar(self.minimal_wf, ec_incar_update) # TOEC WF (minimal) self.toec_wf = wf_elastic_constant_minimal(self.struct_si, order=3) self.toec_wf = add_modify_incar(self.toec_wf, ec_incar_update) toec_data = loadfn(os.path.join(self.tf_loc, "toec_data.json")) # Rather than run entire workflow, preload the spec to test the analysis toec_analysis = Firework( [ ElasticTensorToDb( structure=self.struct_si, order=3, db_file=">>db_file<<" ) ], spec={"deformation_tasks": toec_data["deformation_tasks"]}, ) self.toec_analysis = Workflow([toec_analysis]) # Check 4th order to see if constructed correctly self.foec_wf = wf_elastic_constant_minimal(self.struct_si, order=4)
def test_interstitial(self): struc = PymatgenTest.get_structure("VO2") V_index = struc.indices_from_symbol("V")[0] int_site = PeriodicSite("V", struc[V_index].coords + [0.1, 0.1, 0.1], struc.lattice) interstitial = Interstitial(struc, int_site) # test generation and super cell int_struc = interstitial.generate_defect_structure(1) self.assertEqual(int_struc.composition.as_dict(), {"V": 3, "O": 4}) # Ensure the site is in the right place self.assertEqual(int_site, int_struc.get_sites_in_sphere(int_site.coords, 0.1)[0][0]) int_struc = interstitial.generate_defect_structure(2) self.assertEqual(int_struc.composition.as_dict(), {"V": 17, "O": 32}) int_struc = interstitial.generate_defect_structure(3) self.assertEqual(int_struc.composition.as_dict(), {"V": 55, "O": 108}) int_struc = interstitial.generate_defect_structure([[2.0, 0, 0], [0, 0, -3.0], [0, 2.0, 0]]) self.assertEqual(int_struc.composition.as_dict(), {"V": 25, "O": 48}) # test charge interstitial = Interstitial(struc, int_site) int_struc = interstitial.generate_defect_structure(1) self.assertEqual(int_struc.charge, 0.0) interstitial = Interstitial(struc, int_site, charge=1.0) int_struc = interstitial.generate_defect_structure(1) self.assertEqual(int_struc.charge, 1.0) interstitial = Interstitial(struc, int_site, charge=-1.0) int_struc = interstitial.generate_defect_structure(1) self.assertEqual(int_struc.charge, -1.0) # test multiplicity interstitial = Interstitial(struc, int_site) self.assertEqual(interstitial.multiplicity, 8.0) # test manual setting of multiplicity interstitial = Interstitial(struc, int_site, multiplicity=4.0) self.assertEqual(interstitial.multiplicity, 4.0) # Test composition self.assertEqual(dict(interstitial.defect_composition.as_dict()), {"V": 3, "O": 4}) # test that structure generation doesn't break if velocities existed previously # (previously caused failures for structure printing) vel_struc = Structure( struc.lattice, struc.species, struc.frac_coords, site_properties={"velocities": [[0.0, 0.0, 0.0]] * len(struc)}, ) interstitial = Interstitial(vel_struc, int_site, charge=-1.0) int_struc = interstitial.generate_defect_structure(1) self.assertTrue("velocities" not in int_struc.site_properties)
def test_vacancy_gen(self): struc = PymatgenTest.get_structure("VO2") vac_gen = VacancyGenerator(struc) vacs = list(vac_gen) self.assertEqual(len(vacs), 2) multiplicities = {str(v.site.specie): v.multiplicity for v in vacs} self.assertEqual(multiplicities, {"O": 4, "V": 2})
def setUpClass(cls): struct_si = PymatgenTest.get_structure("Si") vis = MPRelaxSet(struct_si, force_gamma=True) cls.bs_wf = get_wf(struct_si, "bandstructure.yaml", vis=vis, common_params={"vasp_cmd": "test_VASP"}) cls.bsboltz_wf = get_wf(struct_si, "bandstructure_boltztrap.yaml", vis=vis)
def test_predict(self): p = DLSVolumePredictor() fen = Structure.from_file(os.path.join(dir_path, "FeN_mp-6988.cif")) self.assertAlmostEquals(p.predict(fen), 18.2252568873) fen.scale_lattice(3.0) self.assertAlmostEquals(p.predict(fen), 18.2252568873) fen.scale_lattice(0.24) self.assertAlmostEquals(p.predict(fen), 18.2252568873) lfpo = PymatgenTest.get_structure("LiFePO4") lfpo.scale_lattice(10.1) self.assertAlmostEqual(p.predict(lfpo), 291.62094410192924) lfpo.scale_lattice(0.2) self.assertAlmostEqual(p.predict(lfpo), 291.62094410192924) lmpo = PymatgenTest.get_structure("LiFePO4") lmpo.replace_species({"Fe": "Mn"}) self.assertAlmostEquals(p.predict(lmpo), 290.795329052)
def test_get_distinct_rotations(self): struct = PymatgenTest.get_structure("Si") conv = SpacegroupAnalyzer(struct).get_conventional_standard_structure() rots = get_distinct_rotations(conv) ops = SpacegroupAnalyzer(conv).get_symmetry_operations() for op in ops: self.assertTrue( any([np.allclose(op.rotation_matrix, r) for r in rots])) self.assertEqual(len(rots), 48)
def test_vacancy_gen_charges(self): # Ensure correct BV charges are assigned struc = PymatgenTest.get_structure("VO2") vac_gen = VacancyGenerator(struc, include_bv_charge=True) for vac in vac_gen: if str(vac.site.specie) == "V": self.assertEqual(vac.charge, -4) if str(vac.site.specie) == "O": self.assertEqual(vac.charge, 2)
def test_predict(self): p = DLSVolumePredictor() fen = Structure.from_file(os.path.join(dir_path, "FeN_mp-6988.cif")) self.assertAlmostEqual(p.predict(fen), 18.2252568873) fen.scale_lattice(3.0) self.assertAlmostEqual(p.predict(fen), 18.2252568873) fen.scale_lattice(0.24) self.assertAlmostEqual(p.predict(fen), 18.2252568873) lfpo = PymatgenTest.get_structure("LiFePO4") lfpo.scale_lattice(10.1) self.assertAlmostEqual(p.predict(lfpo), 291.62094410192924) # lfpo.scale_lattice(0.2) # self.assertAlmostEqual(p.predict(lfpo), 291.62094410192924) lmpo = PymatgenTest.get_structure("LiFePO4") lmpo.replace_species({"Fe": "Mn"}) self.assertAlmostEqual(p.predict(lmpo), 290.795329052)
def test_vacancy(self): struc = PymatgenTest.get_structure("VO2") V_index = struc.indices_from_symbol("V")[0] vac = Vacancy(struc, struc[V_index]) # test generation and super cell vac_struc = vac.generate_defect_structure(1) self.assertEqual(vac_struc.composition.as_dict(), {"V": 1, "O": 4}) vac_struc = vac.generate_defect_structure(2) self.assertEqual(vac_struc.composition.as_dict(), {"V": 15, "O": 32}) vac_struc = vac.generate_defect_structure(3) self.assertEqual(vac_struc.composition.as_dict(), {"V": 53, "O": 108}) vac_struc = vac.generate_defect_structure([[2.0, 0, 0], [0, 0, -3.0], [0, 2.0, 0]]) self.assertEqual(vac_struc.composition.as_dict(), {"V": 23, "O": 48}) # test charge vac = Vacancy(struc, struc[V_index]) vac_struc = vac.generate_defect_structure(1) self.assertEqual(vac_struc.charge, 0.0) vac = Vacancy(struc, struc[V_index], charge=1.0) vac_struc = vac.generate_defect_structure(1) self.assertEqual(vac_struc.charge, 1.0) vac = Vacancy(struc, struc[V_index], charge=-1.0) vac_struc = vac.generate_defect_structure(1) self.assertEqual(vac_struc.charge, -1.0) # test multiplicity vac = Vacancy(struc, struc[V_index]) self.assertEqual(vac.multiplicity, 2) O_index = struc.indices_from_symbol("O")[0] vac = Vacancy(struc, struc[O_index]) self.assertEqual(vac.multiplicity, 4) # Test composition self.assertEqual(dict(vac.defect_composition.as_dict()), { "V": 2, "O": 3 }) # test lattice value error occurs for different lattices sc_scaled_struc = struc.copy() sc_scaled_struc.make_supercell(2) self.assertRaises(ValueError, Vacancy, struc, sc_scaled_struc[V_index]) self.assertRaises(ValueError, Vacancy, sc_scaled_struc, struc[V_index]) # test value error raised for site not in the structure non_site = PeriodicSite("V", struc[V_index].frac_coords + [0.0, 0.0, 0.1], struc.lattice) self.assertRaises(ValueError, Vacancy, struc, non_site)
def test_substitution(self): struc = PymatgenTest.get_structure("VO2") V_index = struc.indices_from_symbol("V")[0] sub_site = PeriodicSite("Sr", struc[V_index].coords, struc.lattice, coords_are_cartesian=True) substitution = Substitution(struc, sub_site) # test generation and super cell sub_struc = substitution.generate_defect_structure(1) self.assertEqual(sub_struc.composition.as_dict(), {"V": 1, "Sr": 1, "O": 4}) sub_struc = substitution.generate_defect_structure(2) self.assertEqual(sub_struc.composition.as_dict(), {"V": 15, "Sr": 1, "O": 32}) sub_struc = substitution.generate_defect_structure(3) self.assertEqual(sub_struc.composition.as_dict(), {"V": 53, "Sr": 1, "O": 108}) sub_struc = substitution.generate_defect_structure([[2., 0, 0], [0, 0, -3.], [0, 2., 0]]) self.assertEqual(sub_struc.composition.as_dict(), {"V": 23, "O": 48, "Sr": 1}) # test charge substitution = Substitution(struc, sub_site) sub_struc = substitution.generate_defect_structure(1) self.assertEqual(sub_struc.charge, 0.0) substitution = Substitution(struc, sub_site, charge=1.0) sub_struc = substitution.generate_defect_structure(1) self.assertEqual(sub_struc.charge, 1.0) substitution = Substitution(struc, sub_site, charge=-1.0) sub_struc = substitution.generate_defect_structure(1) self.assertEqual(sub_struc.charge, -1.0) # test multiplicity substitution = Substitution(struc, sub_site) self.assertEqual(substitution.multiplicity, 2.0) O_index = struc.indices_from_symbol("O")[0] sub_site = PeriodicSite("Sr", struc[O_index].coords, struc.lattice, coords_are_cartesian=True) substitution = Substitution(struc, sub_site) self.assertEqual(substitution.multiplicity, 4) # Test composition self.assertEqual(dict(substitution.defect_composition.as_dict()), {"V": 2, "Sr": 1, "O": 3}) # test that structure generation doesn't break if velocities existed previously # (previously caused failures for structure printing) vel_struc = Structure( struc.lattice, struc.species, struc.frac_coords, site_properties= {'velocities': [[0., 0., 0.]]*len(struc) } ) substitution = Substitution(vel_struc, sub_site) sub_struc = substitution.generate_defect_structure(1) self.assertTrue( 'velocities' not in sub_struc.site_properties) # test value error raised for site not in the structure non_site = PeriodicSite( "Sr", struc[V_index].frac_coords - [0., 0., .1], struc.lattice) self.assertRaises( ValueError, Substitution, struc, non_site)
class ElementPropertyTest(unittest.TestCase): s = PymatgenTest.get_structure("Li2O") def test_element_property(self): ep = ElementProperty.from_preset("magpie") ep.verbose = True res = ep.transform([self.s.composition]) self.assertEqual(res.shape, (1, 132))
def setUpClass(cls): # TODO: update this for the latest pymatgen... if not SETTINGS.get("VASP_PSP_DIR"): SETTINGS["VASP_PSP_DIR"] = os.path.join(module_dir, "reference_files") print('This system is not set up to run VASP jobs. ' 'Please set VASP_PSP_DIR variable in your ~/.pmgrc.yaml file.') cls.struct_si = PymatgenTest.get_structure("Si") cls.scratch_dir = os.path.join(module_dir, "scratch")
def setUpClass(cls): if not os.environ.get("VASP_PSP_DIR"): os.environ["VASP_PSP_DIR"] = os.path.join(module_dir, "reference_files") print( 'Note: This system is not set up to run VASP jobs. ' 'Please set your VASP_PSP_DIR environment variable.') cls.struct_si = PymatgenTest.get_structure("Si") cls.scratch_dir = os.path.join(module_dir, "scratch")
def setUp(self): super(TestRamanWorkflow, self).setUp() self.struct_si = PymatgenTest.get_structure("Si") self.raman_config = { "MODES": [0, 1], "STEP_SIZE": 0.005, "VASP_CMD": ">>vasp_cmd<<", "DB_FILE": ">>db_file<<" } self.wf = wf_raman_spectra(self.struct_si, self.raman_config)
def setUp(self): super(TestBulkModulusWorkflow, self).setUp() self.struct_si = PymatgenTest.get_structure("Si") self.ndeformations = 6 self.deformations = [ (np.identity(3) * (1 + x)).tolist() for x in np.linspace(-0.05, 0.05, self.ndeformations) ] self.wf_config = {"VASP_CMD": ">>vasp_cmd<<", "DB_FILE": ">>db_file<<"} self.wf = wf_bulk_modulus(self.struct_si, self.wf_config)
def test_materials_aggregator(self): materials_dict = generate_formula_dict(self.test_materials) docs = [] grouped_by_mpid = group_by_material_id( materials_dict['Si'], [{ 'structure': PymatgenTest.get_structure('Si').as_dict(), 'magnetic_type': "non-magnetic" }]) self.assertEqual(len(grouped_by_mpid), 1) materials_dict = generate_formula_dict(self.test_materials)
def test_interstitial(self): struc = PymatgenTest.get_structure("VO2") V_index = struc.indices_from_symbol("V")[0] int_site = PeriodicSite("V", struc[V_index].coords + [0.1, 0.1, 0.1], struc.lattice) interstitial = Interstitial(struc, int_site) # test generation and super cell int_struc = interstitial.generate_defect_structure(1) self.assertEqual(int_struc.composition.as_dict(), {"V": 3, "O": 4}) # Ensure the site is in the right place self.assertEqual(int_site, int_struc.get_sites_in_sphere(int_site.coords, 0.1)[0][0]) int_struc = interstitial.generate_defect_structure(2) self.assertEqual(int_struc.composition.as_dict(), {"V": 17, "O": 32}) int_struc = interstitial.generate_defect_structure(3) self.assertEqual(int_struc.composition.as_dict(), {"V": 55, "O": 108}) int_struc = interstitial.generate_defect_structure([[2., 0, 0], [0, 0, -3.], [0, 2., 0]]) self.assertEqual(int_struc.composition.as_dict(), {"V": 25, "O": 48}) # test charge interstitial = Interstitial(struc, int_site) int_struc = interstitial.generate_defect_structure(1) self.assertEqual(int_struc.charge, 0.0) interstitial = Interstitial(struc, int_site, charge=1.0) int_struc = interstitial.generate_defect_structure(1) self.assertEqual(int_struc.charge, 1.0) interstitial = Interstitial(struc, int_site, charge=-1.0) int_struc = interstitial.generate_defect_structure(1) self.assertEqual(int_struc.charge, -1.0) # test multiplicity interstitial = Interstitial(struc, int_site) self.assertEqual(interstitial.multiplicity, 1.0) interstitial = Interstitial(struc, int_site, multiplicity=4.0) self.assertEqual(interstitial.multiplicity, 4.0) # Test composoition self.assertEqual(dict(interstitial.defect_composition.as_dict()), {"V": 3, "O": 4}) # test that structure has all velocities equal if velocities previously existed # (previously caused failures for structure printing) vel_struc = Structure( struc.lattice, struc.species, struc.frac_coords, site_properties= {'velocities': [[0., 0., 0.]]*len(struc) } ) interstitial = Interstitial(vel_struc, int_site, charge=-1.0) int_struc = interstitial.generate_defect_structure(1) self.assertTrue( (np.array(int_struc.site_properties['velocities']) == 0.).all()) self.assertEqual( len(int_struc.site_properties['velocities']), len(int_struc))
def setUpClass(cls): if not SETTINGS.get("VASP_PSP_DIR"): SETTINGS["VASP_PSP_DIR"] = os.path.join(module_dir, "..", "..", "tests", "reference_files") print('This system is not set up to run VASP jobs. ' 'Please set VASP_PSP_DIR variable in your ~/.pmgrc.yaml file.') cls.struct_si = PymatgenTest.get_structure("Si") cls.scratch_dir = os.path.join(module_dir, "scratch") cls.raman_config = {"modes": [0, 1], "step_size": 0.005, "vasp_cmd": ">>vasp_cmd<<", "db_file": ">>db_file<<"} cls.wf = wf_raman_spectra(cls.struct_si, cls.raman_config)
def test_substitution(self): struc = PymatgenTest.get_structure("VO2") V_index = struc.indices_from_symbol("V")[0] sub_site = PeriodicSite("Sr", struc[V_index].coords, struc.lattice, coords_are_cartesian=True) substitution = Substitution(struc, sub_site) # test generation and super cell sub_struc = substitution.generate_defect_structure(1) self.assertEqual(sub_struc.composition.as_dict(), {"V": 1, "Sr": 1, "O": 4}) sub_struc = substitution.generate_defect_structure(2) self.assertEqual(sub_struc.composition.as_dict(), {"V": 15, "Sr": 1, "O": 32}) sub_struc = substitution.generate_defect_structure(3) self.assertEqual(sub_struc.composition.as_dict(), {"V": 53, "Sr": 1, "O": 108}) sub_struc = substitution.generate_defect_structure([[2., 0, 0], [0, 0, -3.], [0, 2., 0]]) self.assertEqual(sub_struc.composition.as_dict(), {"V": 23, "O": 48, "Sr": 1}) # test charge substitution = Substitution(struc, sub_site) sub_struc = substitution.generate_defect_structure(1) self.assertEqual(sub_struc.charge, 0.0) substitution = Substitution(struc, sub_site, charge=1.0) sub_struc = substitution.generate_defect_structure(1) self.assertEqual(sub_struc.charge, 1.0) substitution = Substitution(struc, sub_site, charge=-1.0) sub_struc = substitution.generate_defect_structure(1) self.assertEqual(sub_struc.charge, -1.0) # test multiplicity substitution = Substitution(struc, sub_site) self.assertEqual(substitution.multiplicity, 2.0) O_index = struc.indices_from_symbol("O")[0] sub_site = PeriodicSite("Sr", struc[O_index].coords, struc.lattice, coords_are_cartesian=True) substitution = Substitution(struc, sub_site) self.assertEqual(substitution.multiplicity, 4) # Test composition self.assertEqual(dict(substitution.defect_composition.as_dict()), {"V": 2, "Sr": 1, "O": 3}) # test that structure has all velocities equal if velocities previously existed # (previously caused failures for structure printing) vel_struc = Structure( struc.lattice, struc.species, struc.frac_coords, site_properties= {'velocities': [[0., 0., 0.]]*len(struc) } ) substitution = Substitution(vel_struc, sub_site) sub_struc = substitution.generate_defect_structure(1) self.assertTrue( (np.array(sub_struc.site_properties['velocities']) == 0.).all()) self.assertEqual( len(sub_struc.site_properties['velocities']), len(sub_struc))
def setUpClass(cls): materials = MemoryStore("materials") materials.connect() docs = [] for n, mat_string in enumerate(["Si", "Sn", "TiO2", "VO2"]): docs.append({"task_id": n, "structure": PymatgenTest.get_structure(mat_string).as_dict()}) materials.update(docs, key='task_id') elasticity = MemoryStore("elasticity") elasticity.connect() elasticity.update(docs[0:1], key="task_id") cls.materials = materials cls.elasticity = elasticity
def setUpClass(cls): # TODO: update this for the latest pymatgen... if not SETTINGS.get("VASP_PSP_DIR"): SETTINGS["VASP_PSP_DIR"] = os.path.join(module_dir, "reference_files") print( 'This system is not set up to run VASP jobs. ' 'Please set VASP_PSP_DIR variable in your ~/.pmgrc.yaml file.') cls.struct_si = PymatgenTest.get_structure("Si") cls.scratch_dir = os.path.join(module_dir, "scratch")
def setUpClass(cls): if not SETTINGS.get("VASP_PSP_DIR"): SETTINGS["VASP_PSP_DIR"] = os.path.join(module_dir, "..", "..", "tests", "reference_files") print( "This system is not set up to run VASP jobs. " "Please set VASP_PSP_DIR variable in your ~/.pmgrc.yaml file." ) cls.struct_si = PymatgenTest.get_structure("Si") cls.scratch_dir = os.path.join(module_dir, "scratch") cls.raman_config = {"modes": [0, 1], "step_size": 0.005, "vasp_cmd": ">>vasp_cmd<<", "db_file": ">>db_file<<"} cls.wf = wf_raman_spectra(cls.struct_si, cls.raman_config)
def test_query(self): m = CrystalAIRester() models = m.get_available_models() self.assertIn("formation_energy", models) self.assertIn("band_gap", models) self.assertIn("log10K", models) self.assertAlmostEqual(m.predict_mp("formation_energy", "mp-1143"), -3.446291923522949) s = PymatgenTest.get_structure("Li2O") self.assertAlmostEqual(m.predict_structure("formation_energy", s), -2.015296220779419)
def test_bandedgeshifting(self): struc = PymatgenTest.get_structure("VO2") struc.make_supercell(3) struc = struc vac = Vacancy(struc, struc.sites[0], charge=-3) besc = BandEdgeShiftingCorrection() params = {'hybrid_cbm': 1., 'hybrid_vbm': -1., 'vbm': -0.5, 'cbm': 0.6} de = DefectEntry(vac, 0., corrections={}, parameters=params, entry_id=None) corr = besc.get_correction(de) self.assertEqual(corr['bandedgeshifting_correction'], 1.5)
def test_bandedgeshifting(self): struc = PymatgenTest.get_structure("VO2") struc.make_supercell(3) struc = struc vac = Vacancy(struc, struc.sites[0], charge=-3) besc = BandEdgeShiftingCorrection() params = {"hybrid_cbm": 1.0, "hybrid_vbm": -1.0, "vbm": -0.5, "cbm": 0.6} de = DefectEntry(vac, 0.0, corrections={}, parameters=params, entry_id=None) corr = besc.get_correction(de) self.assertEqual(corr["bandedgeshifting_correction"], 1.5)
def test_magnetic(self): lfp = PymatgenTest.get_structure("LiFePO4") sg = SpacegroupAnalyzer(lfp, 0.1) self.assertEqual(sg.get_spacegroup_symbol(), "Pnma") magmoms = [0] * len(lfp) magmoms[4] = 1 magmoms[5] = -1 magmoms[6] = 1 magmoms[7] = -1 lfp.add_site_property("magmom", magmoms) sg = SpacegroupAnalyzer(lfp, 0.1) self.assertEqual(sg.get_spacegroup_symbol(), "Pnma")
def test_magnetic(self): lfp = PymatgenTest.get_structure("LiFePO4") sg = SpacegroupAnalyzer(lfp, 0.1) self.assertEqual(sg.get_space_group_symbol(), "Pnma") magmoms = [0] * len(lfp) magmoms[4] = 1 magmoms[5] = -1 magmoms[6] = 1 magmoms[7] = -1 lfp.add_site_property("magmom", magmoms) sg = SpacegroupAnalyzer(lfp, 0.1) self.assertEqual(sg.get_space_group_symbol(), "Pnma")
def test_interstitial(self): struc = PymatgenTest.get_structure("VO2") V_index = struc.indices_from_symbol("V")[0] int_site = PeriodicSite("V", struc[V_index].coords + [0.1, 0.1, 0.1], struc.lattice) interstitial = Interstitial(struc, int_site) # test generation and super cell int_struc = interstitial.generate_defect_structure(1) self.assertEqual(int_struc.composition.as_dict(), {"V": 3, "O": 4}) # Ensure the site is in the right place self.assertEqual( int_site, int_struc.get_sites_in_sphere(int_site.coords, 0.1)[0][0]) int_struc = interstitial.generate_defect_structure(2) self.assertEqual(int_struc.composition.as_dict(), {"V": 17, "O": 32}) int_struc = interstitial.generate_defect_structure(3) self.assertEqual(int_struc.composition.as_dict(), {"V": 55, "O": 108}) int_struc = interstitial.generate_defect_structure([[2., 0, 0], [0, 0, -3.], [0, 2., 0]]) self.assertEqual(int_struc.composition.as_dict(), {"V": 25, "O": 48}) # test charge interstitial = Interstitial(struc, int_site) int_struc = interstitial.generate_defect_structure(1) self.assertEqual(int_struc.charge, 0.0) interstitial = Interstitial(struc, int_site, charge=1.0) int_struc = interstitial.generate_defect_structure(1) self.assertEqual(int_struc.charge, 1.0) interstitial = Interstitial(struc, int_site, charge=-1.0) int_struc = interstitial.generate_defect_structure(1) self.assertEqual(int_struc.charge, -1.0) # test multiplicity interstitial = Interstitial(struc, int_site) self.assertEqual(interstitial.multiplicity, 1.0) interstitial = Interstitial(struc, int_site, multiplicity=4.0) self.assertEqual(interstitial.multiplicity, 4.0) # Test composoition self.assertEqual(dict(interstitial.defect_composition.as_dict()), { "V": 3, "O": 4 })
def setUpClass(cls): if not SETTINGS.get("VASP_PSP_DIR"): SETTINGS["VASP_PSP_DIR"] = os.path.join(module_dir, "..", "..", "tests", "reference_files") print('This system is not set up to run VASP jobs. ' 'Please set VASP_PSP_DIR variable in your ~/.pmgrc.yaml file.') cls.struct_si = SpacegroupAnalyzer( PymatgenTest.get_structure("Si")).get_conventional_standard_structure() cls.scratch_dir = os.path.join(module_dir, "scratch") cls.elastic_config = {"norm_deformations":[0.01], "shear_deformations":[0.03], "vasp_cmd": ">>vasp_cmd<<", "db_file": ">>db_file<<"} cls.wf = wf_elastic_constant(cls.struct_si, cls.elastic_config)
def test_apply_transformation(self): structure = PymatgenTest.get_structure("LiFePO4") t = DopingTransformation("Ca2+", min_length=10) ss = t.apply_transformation(structure, 100) self.assertEqual(len(ss), 1) t = DopingTransformation("Al3+", min_length=15, ionic_radius_tol=0.1) ss = t.apply_transformation(structure, 100) self.assertEqual(len(ss), 0) # Aliovalent doping with vacancies for dopant, nstructures in [("Al3+", 4), ("N3-", 420), ("Cl-", 16)]: t = DopingTransformation(dopant, min_length=4, alio_tol=1, max_structures_per_enum=1000) ss = t.apply_transformation(structure, 1000) self.assertEqual(len(ss), nstructures) for d in ss: self.assertEqual(d["structure"].charge, 0) # Aliovalent doping with codopant for dopant, nstructures in [("Al3+", 3), ("N3-", 60), ("Cl-", 60)]: t = DopingTransformation(dopant, min_length=4, alio_tol=1, codopant=True, max_structures_per_enum=1000) ss = t.apply_transformation(structure, 1000) self.assertEqual(len(ss), nstructures) if __name__ == '__main__': for d in ss: self.assertEqual(d["structure"].charge, 0) # Make sure compensation is done with lowest oxi state structure = PymatgenTest.get_structure("SrTiO3") t = DopingTransformation("Nb5+", min_length=5, alio_tol=1, max_structures_per_enum=1000, allowed_doping_species=["Ti4+"]) ss = t.apply_transformation(structure, 1000) self.assertEqual(len(ss), 3) for d in ss: self.assertEqual(d["structure"].formula, "Sr7 Ti6 Nb2 O24")
def test_properties(self): # Test units, magnitude q = Quantity("bulk_modulus", 100) self.assertEqual(q.units, "gigapascal") self.assertEqual(q.magnitude, 100) # Ensure non-pint values raise error with units, magnitude structure = PymatgenTest.get_structure('Si') q = Quantity("structure", structure) with self.assertRaises(ValueError): print(q.units) with self.assertRaises(ValueError): print(q.magnitude)
def test_vacancy(self): struc = PymatgenTest.get_structure("VO2") V_index = struc.indices_from_symbol("V")[0] vac = Vacancy(struc, struc[V_index]) # test generation and super cell vac_struc = vac.generate_defect_structure(1) self.assertEqual(vac_struc.composition.as_dict(), {"V": 1, "O": 4}) vac_struc = vac.generate_defect_structure(2) self.assertEqual(vac_struc.composition.as_dict(), {"V": 15, "O": 32}) vac_struc = vac.generate_defect_structure(3) self.assertEqual(vac_struc.composition.as_dict(), {"V": 53, "O": 108}) vac_struc = vac.generate_defect_structure([[2., 0, 0], [0, 0, -3.], [0, 2., 0]]) self.assertEqual(vac_struc.composition.as_dict(), {"V": 23, "O": 48}) # test charge vac = Vacancy(struc, struc[V_index]) vac_struc = vac.generate_defect_structure(1) self.assertEqual(vac_struc.charge, 0.0) vac = Vacancy(struc, struc[V_index], charge=1.0) vac_struc = vac.generate_defect_structure(1) self.assertEqual(vac_struc.charge, 1.0) vac = Vacancy(struc, struc[V_index], charge=-1.0) vac_struc = vac.generate_defect_structure(1) self.assertEqual(vac_struc.charge, -1.0) # test multiplicity vac = Vacancy(struc, struc[V_index]) self.assertEqual(vac.multiplicity, 2) O_index = struc.indices_from_symbol("O")[0] vac = Vacancy(struc, struc[O_index]) self.assertEqual(vac.multiplicity, 4) # Test composition self.assertEqual(dict(vac.defect_composition.as_dict()), {"V": 2, "O": 3}) # test lattice value error occurs for different lattices sc_scaled_struc = struc.copy() sc_scaled_struc.make_supercell(2) self.assertRaises( ValueError, Vacancy, struc, sc_scaled_struc[V_index]) self.assertRaises( ValueError, Vacancy, sc_scaled_struc, struc[V_index]) # test value error raised for site not in the structure non_site = PeriodicSite( "V", struc[V_index].frac_coords + [0., 0., .1], struc.lattice) self.assertRaises( ValueError, Vacancy, struc, non_site)
def setUp(self): super(TestElasticWorkflow, self).setUp() self.tf_loc = os.path.join(ref_dir, 'elastic_wf') self.struct_si = PymatgenTest.get_structure("Si") self.struct_si = SpacegroupAnalyzer( self.struct_si).get_conventional_standard_structure() self.opt_struct = Structure.from_file( os.path.join(self.tf_loc, '1', 'inputs', 'POSCAR')) # Base WF self.base_wf = get_wf(self.struct_si, "optimize_only.yaml", params=[{ "db_file": ">>db_file<<" }]) self.base_wf.append_wf( get_wf_elastic_constant(self.struct_si, db_file='>>db_file<<', stencils=[[0.01]] * 3 + [[0.03]] * 3, copy_vasp_outputs=True), self.base_wf.leaf_fw_ids) self.base_wf_noopt = get_wf_elastic_constant(self.opt_struct, stencils=[[0.01]] * 3 + [[0.03]] * 3, copy_vasp_outputs=False, sym_reduce=False, db_file='>>db_file<<') ec_incar_update = {'incar_update': {'EDIFF': 1e-6, 'ENCUT': 700}} self.base_wf = add_modify_incar(self.base_wf, ec_incar_update) self.base_wf_noopt = add_modify_incar(self.base_wf_noopt, ec_incar_update) # Full preset WF self.preset_wf = wf_elastic_constant(self.struct_si) # Minimal WF self.minimal_wf = wf_elastic_constant_minimal(self.opt_struct) self.minimal_wf = add_modify_incar(self.minimal_wf, ec_incar_update) # TOEC WF (minimal) self.toec_wf = wf_elastic_constant_minimal(self.struct_si, order=3) self.toec_wf = add_modify_incar(self.toec_wf, ec_incar_update) toec_data = loadfn(os.path.join(self.tf_loc, 'toec_data.json')) # Rather than run entire workflow, preload the spec to test the analysis toec_analysis = Firework( [ ElasticTensorToDb( structure=self.struct_si, order=3, db_file=">>db_file<<") ], spec={"deformation_tasks": toec_data['deformation_tasks']}) self.toec_analysis = Workflow([toec_analysis])
def setUp(self): if "PMG_VASP_PSP_DIR" not in os.environ: os.environ["PMG_VASP_PSP_DIR"] = test_dir s = PymatgenTest.get_structure("Li2O") gen = SlabGenerator(s, (1, 0, 0), 10, 10) self.slab = gen.get_slab() self.bulk = self.slab.oriented_unit_cell vis_bulk = MVLSlabSet(self.bulk, bulk=True) vis = MVLSlabSet(self.slab) self.d_bulk = vis_bulk.all_input self.d_slab = vis.all_input
def test_substitutor(self): s_list = [Specie('O', -2), Specie('Li', 1)] subs = self.s.pred_from_list(s_list) self.assertEqual(len(subs), 4, 'incorrect number of substitutions') c = Composition({'O2-': 1, 'Li1+': 2}) subs = self.s.pred_from_comp(c) self.assertEqual(len(subs), 4, 'incorrect number of substitutions') structures = [{ "structure": PymatgenTest.get_structure("Li2O"), "id": "pmgtest" }] subs = self.s.pred_from_structures(["Na+", "O2-"], structures) self.assertEqual(subs[0].formula, "Na2 O1")
def setUp(self): self.epsilon = 15. struc = PymatgenTest.get_structure("VO2") struc.make_supercell(3) vac = Vacancy(struc, struc.sites[0], charge=-3) # load neccessary parameters for defect_entry to make use # of Freysoldt and Kumagai corrections p = {} ids = vac.generate_defect_structure(1) abc = struc.lattice.abc axisdata = [np.arange(0., lattval, 0.2) for lattval in abc] bldata = [np.array([1. for u in np.arange(0., lattval, 0.2)]) for lattval in abc] dldata = [ np.array([(-1 - np.cos(2 * np.pi * u / lattval)) for u in np.arange(0., lattval, 0.2)]) for lattval in abc ] p.update({'axis_grid': axisdata, 'bulk_planar_averages': bldata, 'defect_planar_averages': dldata, 'initial_defect_structure': ids, 'defect_frac_sc_coords': struc.sites[0].frac_coords, 'bulk_sc_structure': struc}) bulk_atomic_site_averages, defect_atomic_site_averages = [], [] defect_site_with_sc_lattice = PeriodicSite( struc.sites[0].specie, struc.sites[0].coords, struc.lattice, coords_are_cartesian = True) max_dist = 9.6 pert_amnt = 1. for site_ind, site in enumerate(struc.sites): if site.specie.symbol == "O": Oval = -30.6825 bulk_atomic_site_averages.append( Oval) if site_ind: dist_to_defect = site.distance_and_image( defect_site_with_sc_lattice)[0] defect_site_val = Oval - .3 + pert_amnt * ((max_dist - dist_to_defect)/max_dist)**2 defect_atomic_site_averages.append( defect_site_val) else: Vval = -51.6833 bulk_atomic_site_averages.append( Vval) if site_ind: dist_to_defect = site.distance_and_image( defect_site_with_sc_lattice)[0] defect_site_val = Vval - .3 + pert_amnt * ((max_dist - dist_to_defect)/max_dist)**2 defect_atomic_site_averages.append( defect_site_val) site_matching_indices = [[ind, ind-1] for ind in range(len(struc.sites)) if ind != 0] p.update({ "bulk_atomic_site_averages": bulk_atomic_site_averages, "defect_atomic_site_averages": defect_atomic_site_averages, "site_matching_indices": site_matching_indices}) self.defect_entry = DefectEntry( vac, 0., parameters = p)
def setUp(self): s = PymatgenTest.get_structure("Li2O") gen = SlabGenerator(s, (1, 0, 0), 10, 10) self.slab = gen.get_slab() self.bulk = self.slab.oriented_unit_cell vis_bulk = MVLSlabSet(self.bulk, bulk=True) vis = MVLSlabSet(self.slab) vis_dipole = MVLSlabSet(self.slab, auto_dipole=True) self.d_bulk = vis_bulk.all_input self.d_slab = vis.all_input self.d_dipole = vis_dipole.all_input self.vis = vis warnings.simplefilter("ignore")