本文整理汇总了Python中pymatgen.analysis.bond_valence.BVAnalyzer.get_valences方法的典型用法代码示例。如果您正苦于以下问题:Python BVAnalyzer.get_valences方法的具体用法?Python BVAnalyzer.get_valences怎么用?Python BVAnalyzer.get_valences使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pymatgen.analysis.bond_valence.BVAnalyzer
的用法示例。
在下文中一共展示了BVAnalyzer.get_valences方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: BVAnalyzerTest
# 需要导入模块: from pymatgen.analysis.bond_valence import BVAnalyzer [as 别名]
# 或者: from pymatgen.analysis.bond_valence.BVAnalyzer import get_valences [as 别名]
class BVAnalyzerTest(PymatgenTest):
def setUp(self):
self.analyzer = BVAnalyzer()
def test_get_valence(self):
s = Structure.from_file(os.path.join(test_dir, "LiMn2O4.json"))
ans = [1, 1, 3, 3, 4, 4, -2, -2, -2, -2, -2, -2, -2, -2]
self.assertEqual(self.analyzer.get_valences(s), ans)
s = self.get_structure("LiFePO4")
ans = [1, 1, 1, 1, 2, 2, 2, 2, 5, 5, 5, 5, -2, -2, -2, -2, -2, -2, -2,
- 2, -2, -2, -2, -2, -2, -2, -2, -2]
self.assertEqual(self.analyzer.get_valences(s), ans)
s = self.get_structure("Li3V2(PO4)3")
ans = [1, 1, 1, 1, 1, 1, 3, 3, 3, 3, 5, 5, 5, 5, 5, 5, -2, -2, -2, -2,
- 2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
- 2, -2, -2, -2]
self.assertEqual(self.analyzer.get_valences(s), ans)
s = Structure.from_file(os.path.join(test_dir, "Li4Fe3Mn1(PO4)4.json"))
ans = [1, 1, 1, 1, 2, 2, 2, 2, 5, 5, 5, 5, -2, -2, -2, -2, -2, -2, -2,
- 2, -2, -2, -2, -2, -2, -2, -2, -2]
self.assertEqual(self.analyzer.get_valences(s), ans)
s = self.get_structure("NaFePO4")
ans = [1, 1, 1, 1, 2, 2, 2, 2, 5, 5, 5, 5, -2, -2, -2, -2, -2, -2, -2,
- 2, -2, -2, -2, -2, -2, -2, -2, -2]
self.assertEqual(self.analyzer.get_valences(s), ans)
def test_get_oxi_state_structure(self):
s = Structure.from_file(os.path.join(test_dir, "LiMn2O4.json"))
news = self.analyzer.get_oxi_state_decorated_structure(s)
self.assertIn(Specie("Mn", 3), news.composition.elements)
self.assertIn(Specie("Mn", 4), news.composition.elements)
示例2: tersoff_potential
# 需要导入模块: from pymatgen.analysis.bond_valence import BVAnalyzer [as 别名]
# 或者: from pymatgen.analysis.bond_valence.BVAnalyzer import get_valences [as 别名]
def tersoff_potential(self, structure):
"""
Generate the species, tersoff potential lines for an oxide structure
Args:
structure:
pymatgen.core.structure.Structure
"""
bv = BVAnalyzer()
el = [site.species_string for site in structure.sites]
valences = bv.get_valences(structure)
el_val_dict = dict(zip(el, valences))
gin = "species \n"
qerfstring = "qerfc\n"
for key in el_val_dict.keys():
if key != "O" and el_val_dict[key] % 1 != 0:
raise SystemError("Oxide has mixed valence on metal")
specie_string = key + " core " + str(el_val_dict[key]) + "\n"
gin += specie_string
qerfstring += key + " " + key + " 0.6000 10.0000 \n"
gin += "# noelectrostatics \n Morse \n"
met_oxi_ters = Tersoff_pot().data
for key in el_val_dict.keys():
if key != "O":
metal = key + "(" + str(int(el_val_dict[key])) + ")"
ters_pot_str = met_oxi_ters[metal]
gin += ters_pot_str
gin += qerfstring
return gin
示例3: __init__
# 需要导入模块: from pymatgen.analysis.bond_valence import BVAnalyzer [as 别名]
# 或者: from pymatgen.analysis.bond_valence.BVAnalyzer import get_valences [as 别名]
def __init__(self, defect):
"""
Args:
defect(Defect): pymatgen Defect object
"""
self.defect = defect
try:
bv = BVAnalyzer()
struct_valences = bv.get_valences(self.defect.bulk_structure)
site_index = self.defect.bulk_structure.get_sites_in_sphere(
self.defect.site.coords, 0.1, include_index=True)[0][2]
def_site_valence = struct_valences[site_index]
except Exception: # sometimes valences cant be assigned
def_site_valence = 0
if isinstance(defect, Vacancy):
self.charges = [-1 * def_site_valence]
elif isinstance(defect, Substitution):
#(minimize difference with host site specie)
probable_chgs = [ox - def_site_valence for ox in self.defect.site.specie.oxidation_states]
self.charges = [min(probable_chgs, key=abs)]
elif isinstance(defect, Interstitial):
self.charges = [0]
else:
raise ValueError("Defect Type not recognized.")
示例4: _get_valences
# 需要导入模块: from pymatgen.analysis.bond_valence import BVAnalyzer [as 别名]
# 或者: from pymatgen.analysis.bond_valence.BVAnalyzer import get_valences [as 别名]
def _get_valences(self):
"""
Computes ionic valences of elements for all sites in the structure.
"""
bv = BVAnalyzer()
valences = bv.get_valences(self._structure)
el = [site.species_string for site in self.structure.sites]
valence_dict = dict(zip(el, valences))
return valence_dict
示例5: _get_valences
# 需要导入模块: from pymatgen.analysis.bond_valence import BVAnalyzer [as 别名]
# 或者: from pymatgen.analysis.bond_valence.BVAnalyzer import get_valences [as 别名]
def _get_valences(self):
"""
Computes ionic valences of elements for all sites in the structure.
"""
bv = BVAnalyzer()
self._structure = bv.get_oxi_state_decorated_structure(self._structure)
try:
valences = bv.get_valences(self._structure)
except:
try:
valences = bv.get_valences(self._structure, symm_tol=0.0)
except:
raise
#print valences
#el = [site.specie.symbol for site in self._structure.sites]
#el = [site.species_string for site in self._structure.sites]
#el = [site.specie for site in self._structure.sites]
#valence_dict = dict(zip(el, valences))
#print valence_dict
return valences
示例6: setUp
# 需要导入模块: from pymatgen.analysis.bond_valence import BVAnalyzer [as 别名]
# 或者: from pymatgen.analysis.bond_valence.BVAnalyzer import get_valences [as 别名]
def setUp(self):
filepath1 = os.path.join(test_dir, 'Li2O.cif')
p = CifParser(filepath1).get_structures(False)[0]
bv = BVAnalyzer()
valences = bv.get_valences(p)
el = [site.species_string for site in p.sites]
val_dict = dict(zip(el, valences))
self._radii = {}
for k,v in val_dict.items():
k1 = re.sub('[1-9,+,\-]', '', k)
self._radii[k] = Specie(k1, v).ionic_radius
p.remove(0)
self._vac_struct = p
示例7: BVAnalyzerTest
# 需要导入模块: from pymatgen.analysis.bond_valence import BVAnalyzer [as 别名]
# 或者: from pymatgen.analysis.bond_valence.BVAnalyzer import get_valences [as 别名]
class BVAnalyzerTest(unittest.TestCase):
def setUp(self):
self.analyzer = BVAnalyzer()
def test_get_valence(self):
parser = CifParser(os.path.join(test_dir, "LiMn2O4.cif"))
s = parser.get_structures()[0]
ans = [1, 1, 3, 3, 4, 4, -2, -2, -2, -2, -2, -2, -2, -2]
self.assertEqual(self.analyzer.get_valences(s), ans)
parser = CifParser(os.path.join(test_dir, "LiFePO4.cif"))
s = parser.get_structures()[0]
ans = [1, 1, 1, 1, 2, 2, 2, 2, 5, 5, 5, 5, -2, -2, -2, -2, -2, -2, -2,
- 2, -2, -2, -2, -2, -2, -2, -2, -2]
self.assertEqual(self.analyzer.get_valences(s), ans)
parser = CifParser(os.path.join(test_dir, "Li3V2(PO4)3.cif"))
s = parser.get_structures()[0]
ans = [1, 1, 1, 1, 1, 1, 3, 3, 3, 3, 5, 5, 5, 5, 5, 5, -2, -2, -2, -2,
- 2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
- 2, -2, -2, -2]
self.assertEqual(self.analyzer.get_valences(s), ans)
parser = CifParser(os.path.join(test_dir, "Li4Fe3Mn1(PO4)4.cif"))
s = parser.get_structures()[0]
ans = [1, 1, 1, 1, 2, 2, 2, 2, 5, 5, 5, 5, -2, -2, -2, -2, -2, -2, -2,
- 2, -2, -2, -2, -2, -2, -2, -2, -2]
self.assertEqual(self.analyzer.get_valences(s), ans)
parser = CifParser(os.path.join(test_dir, "NaFePO4.cif"))
s = parser.get_structures()[0]
ans = [1, 1, 1, 1, 2, 2, 2, 2, 5, 5, 5, 5, -2, -2, -2, -2, -2, -2, -2,
- 2, -2, -2, -2, -2, -2, -2, -2, -2]
self.assertEqual(self.analyzer.get_valences(s), ans)
def test_get_oxi_state_structure(self):
parser = CifParser(os.path.join(test_dir, "LiMn2O4.cif"))
s = parser.get_structures()[0]
news = self.analyzer.get_oxi_state_decorated_structure(s)
self.assertIn(Specie("Mn", 3), news.composition.elements)
self.assertIn(Specie("Mn", 4), news.composition.elements)
示例8: setUp
# 需要导入模块: from pymatgen.analysis.bond_valence import BVAnalyzer [as 别名]
# 或者: from pymatgen.analysis.bond_valence.BVAnalyzer import get_valences [as 别名]
def setUp(self):
filepath = os.path.join(test_dir, 'POSCAR')
p = Poscar.from_file(filepath)
self.structure = p.structure
bv = BVAnalyzer()
self.structure = bv.get_oxi_state_decorated_structure(self.structure)
valences = bv.get_valences(self.structure)
radii = []
for i in range(len(valences)):
el = self.structure.sites[i].specie.symbol
radius = Specie(el, valences[i]).ionic_radius
radii.append(radius)
el = [site.species_string for site in self.structure.sites]
self.rad_dict = dict(zip(el, radii))
for el in self.rad_dict.keys():
print((el, self.rad_dict[el].real))
示例9: _get_valences
# 需要导入模块: from pymatgen.analysis.bond_valence import BVAnalyzer [as 别名]
# 或者: from pymatgen.analysis.bond_valence.BVAnalyzer import get_valences [as 别名]
def _get_valences(self):
"""
Computes ionic valences of elements for all sites in the structure.
"""
bv = BVAnalyzer()
try:
valences = bv.get_valences(self._structure)
except:
err_str = "BVAnalyzer failed. The defect effective charge, and"
err_str += " volume and surface area may not work"
print err_str
raise LookupError()
el = [site.species_string for site in self.structure.sites]
valence_dict = dict(zip(el, valences))
return valence_dict
示例10: get_coordsites_min_max_charge
# 需要导入模块: from pymatgen.analysis.bond_valence import BVAnalyzer [as 别名]
# 或者: from pymatgen.analysis.bond_valence.BVAnalyzer import get_valences [as 别名]
def get_coordsites_min_max_charge(self, n):
"""
Minimum and maximum charge of sites surrounding the vacancy site.
Args:
n: Index of vacancy list
"""
bv = BVAnalyzer()
struct_valences = bv.get_valences(self._structure)
coordinated_site_valences = []
def _get_index(site):
for i in range(len(self._structure.sites)):
if site.is_periodic_image(self._structure.sites[i]):
return i
raise ValueError("Site not found")
for site in self._defect_coord_sites[n]:
ind = _get_index(site)
coordinated_site_valences.append(struct_valences[ind])
coordinated_site_valences.sort()
return coordinated_site_valences[0], coordinated_site_valences[-1]
示例11: buckingham_potential
# 需要导入模块: from pymatgen.analysis.bond_valence import BVAnalyzer [as 别名]
# 或者: from pymatgen.analysis.bond_valence.BVAnalyzer import get_valences [as 别名]
def buckingham_potential(self, structure, val_dict=None):
"""
Generate species, buckingham, and spring options for an oxide structure
using the parameters in default libraries.
Ref:
1. G.V. Lewis and C.R.A. Catlow, J. Phys. C: Solid State Phys.,
18, 1149-1161 (1985)
2. T.S.Bush, J.D.Gale, C.R.A.Catlow and P.D. Battle,
J. Mater Chem., 4, 831-837 (1994)
Args:
structure:
pymatgen.core.structure.Structure
val_dict (Needed if structure is not charge neutral)
El:valence dictionary, where El is element.
"""
if not val_dict:
bv = BVAnalyzer()
el = [site.species_string for site in structure.sites]
valences = bv.get_valences(structure)
val_dict = dict(zip(el, valences))
#Try bush library first
bpb = BuckinghamPotBush()
bpl = BuckinghamPotLewis()
gin = ""
for key in val_dict.keys():
use_bush = True
el = re.sub('[1-9,+,\-]', '', key)
if el not in bpb.species_dict.keys():
use_bush = False
elif val_dict[key] != bpb.species_dict[el]['oxi']:
use_bush = False
if use_bush:
gin += "species \n"
gin += bpb.species_dict[el]['inp_str']
gin += "buckingham \n"
gin += bpb.pot_dict[el]
gin += "spring \n"
gin += bpb.spring_dict[el]
continue
#Try lewis library next if element is not in bush
#use_lewis = True
if el != "O": # For metals the key is "Metal_OxiState+"
k = el + '_' + str(int(val_dict[key])) + '+'
if k not in bpl.species_dict.keys():
#use_lewis = False
raise GulpError("Element {} not in library".format(k))
gin += "species\n"
gin += bpl.species_dict[k]
gin += "buckingham\n"
gin += bpl.pot_dict[k]
else:
gin += "species\n"
k = "O_core"
gin += bpl.species_dict[k]
k = "O_shel"
gin += bpl.species_dict[k]
gin += "buckingham\n"
gin += bpl.pot_dict[key]
gin += 'spring\n'
gin += bpl.spring_dict[key]
return gin
示例12: run_task
# 需要导入模块: from pymatgen.analysis.bond_valence import BVAnalyzer [as 别名]
# 或者: from pymatgen.analysis.bond_valence.BVAnalyzer import get_valences [as 别名]
def run_task(self, fw_spec):
logging.basicConfig(filename='chemenv_structure_environments.log',
format='%(levelname)s:%(module)s:%(funcName)s:%(message)s',
level=logging.DEBUG)
lgf = LocalGeometryFinder()
lgf.setup_parameters(centering_type='centroid', include_central_site_in_centroid=True,
structure_refinement=lgf.STRUCTURE_REFINEMENT_NONE)
if 'chemenv_parameters' in fw_spec:
for param, value in fw_spec['chemenv_parameters'].items():
lgf.setup_parameter(param, value)
identifier = fw_spec['identifier']
if 'structure' in fw_spec:
structure = fw_spec['structure']
else:
if identifier['source'] == 'MaterialsProject' and 'material_id' in identifier:
if not 'mapi_key' in fw_spec:
raise ValueError('The mapi_key should be provided to get the structure from the Materials Project')
# FIXME: Use MPRester from pymatgen
from pymatgen.matproj.rest import MPRester
a = MPRester(fw_spec['mapi_key'])
structure = a.get_structure_by_material_id(identifier['material_id'])
else:
raise ValueError('Either structure or identifier with source = MaterialsProject and material_id '
'should be provided')
info = {}
# Compute the structure environments
lgf.setup_structure(structure)
if 'valences' in fw_spec:
valences = fw_spec['valences']
else:
try:
bva = BVAnalyzer()
valences = bva.get_valences(structure=structure)
info['valences'] = {'origin': 'BVAnalyzer'}
except:
valences = 'undefined'
info['valences'] = {'origin': 'None'}
excluded_atoms = None
if 'excluded_atoms' in fw_spec:
excluded_atoms = fw_spec['excluded_atoms']
se = lgf.compute_structure_environments(only_cations=False, valences=valences, excluded_atoms=excluded_atoms)
# Write to json file
if 'json_file' in fw_spec:
json_file = fw_spec['json_file']
else:
json_file = 'structure_environments.json'
f = open(json_file, 'w')
json.dump(se.as_dict(), f)
f.close()
# Save to database
if 'mongo_database' in fw_spec:
database = fw_spec['mongo_database']
entry = {'identifier': identifier,
'elements': [elmt.symbol for elmt in structure.composition.elements],
'nelements': len(structure.composition.elements),
'pretty_formula': structure.composition.reduced_formula,
'nsites': len(structure)
}
saving_option = fw_spec['saving_option']
if saving_option == 'gridfs':
gridfs_msonables = {'structure': structure,
'structure_environments': se}
elif saving_option == 'storefile':
gridfs_msonables = None
if 'se_prefix' in fw_spec:
se_prefix = fw_spec['se_prefix']
if not se_prefix.isalpha():
raise ValueError('Prefix for structure_environments file is "{}" '
'while it should be alphabetic'.format(se_prefix))
else:
se_prefix = ''
if se_prefix:
se_rfilename = '{}_{}.json'.format(se_prefix, fw_spec['storefile_basename'])
else:
se_rfilename = '{}.json'.format(fw_spec['storefile_basename'])
se_rfilepath = '{}/{}'.format(fw_spec['storefile_dirpath'], se_rfilename)
storage_server = fw_spec['storage_server']
storage_server.put(localpath=json_file, remotepath=se_rfilepath, overwrite=True, makedirs=False)
entry['structure_environments_file'] = se_rfilepath
else:
raise ValueError('Saving option is "{}" while it should be '
'"gridfs" or "storefile"'.format(saving_option))
criteria = {'identifier': identifier}
if database.collection.find(criteria).count() == 1:
database.update_entry(query=criteria, entry_update=entry,
gridfs_msonables=gridfs_msonables)
else:
database.insert_entry(entry=entry, gridfs_msonables=gridfs_msonables)