本文整理汇总了Python中pymatgen.util.testing.PymatgenTest类的典型用法代码示例。如果您正苦于以下问题:Python PymatgenTest类的具体用法?Python PymatgenTest怎么用?Python PymatgenTest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PymatgenTest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_get_kpoint_weights
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)
示例2: test_batch_write_input
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)))
示例3: test_modes
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)
示例4: test_charge_gen
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)
示例5: test_wf_functions
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))
示例6: setUpClass
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"))
示例7: test_CsCl_ionic
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)
示例8: setUp
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.}
示例9: test_input_sets
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'])
示例10: test_bandedgeshifting
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.)
示例11: test_mutable_sequence_methods
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")
示例12: setUp
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)
示例13: test_dimensionality
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)
示例14: setUp
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)
示例15: test_substitution
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)