本文整理汇总了Python中pymatgen.electronic_structure.core.Spin类的典型用法代码示例。如果您正苦于以下问题:Python Spin类的具体用法?Python Spin怎么用?Python Spin使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Spin类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: from_dict
def from_dict(d):
"""
Args:
A dict with all data for a band structure symm line object.
Returns:
A BandStructureSymmLine object
"""
labels_dict = d['labels_dict']
projections = {}
structure = None
if 'projections' in d and len(d['projections']) != 0:
structure = Structure.from_dict(d['structure'])
projections = {
Spin.from_int(int(spin)): [
[{Orbital.from_string(orb): [
d['projections'][spin][i][j][orb][k]
for k in range(len(d['projections'][spin][i][j][orb]))]
for orb in d['projections'][spin][i][j]}
for j in range(len(d['projections'][spin][i]))]
for i in range(len(d['projections'][spin]))]
for spin in d['projections']}
return BandStructureSymmLine(
d['kpoints'], {Spin.from_int(int(k)): d['bands'][k]
for k in d['bands']},
Lattice(d['lattice_rec']['matrix']), d['efermi'],
labels_dict, structure=structure, projections=projections)
示例2: get_cohp
def get_cohp(self, spin=None, integrated=False):
"""
Returns the COHP or ICOHP for a particular spin.
Args:
spin: Spin. Can be parsed as spin object, integer (-1/1)
or str ("up"/"down")
integrated: Return COHP (False) or ICOHP (True)
Returns:
Returns the CHOP or ICOHP for the input spin. If Spin is
None and both spins are present, both spins will be returned
as a dictionary.
"""
if not integrated:
populations = self.cohp
else:
populations = self.icohp
if populations is None:
return None
elif spin is None:
return populations
else:
if isinstance(spin, six.integer_types):
spin = Spin(spin)
elif isinstance(spin, six.string_types):
s = {"up": 1, "down": -1}[spin.lower()]
spin = Spin(s)
return {spin: populations[spin]}
示例3: has_antibnd_states_below_efermi
def has_antibnd_states_below_efermi(self, spin=None, limit=0.01):
"""
Returns dict indicating if there are antibonding states below the Fermi level depending on the spin
spin: Spin
limit: -COHP smaller -limit will be considered.
"""
warnings.warn("This method has not been tested on many examples. Check the parameter limit, pls!")
populations = self.cohp
number_energies_below_efermi = len([x for x in self.energies if x <= self.efermi])
if populations is None:
return None
elif spin is None:
dict_to_return = {}
for spin, cohpvalues in populations.items():
if (max(cohpvalues[0:number_energies_below_efermi])) > limit:
dict_to_return[spin] = True
else:
dict_to_return[spin] = False
else:
dict_to_return = {}
if isinstance(spin, int):
spin = Spin(spin)
elif isinstance(spin, str):
s = {"up": 1, "down": -1}[spin.lower()]
spin = Spin(s)
if (max(populations[spin][0:number_energies_below_efermi])) > limit:
dict_to_return[spin] = True
else:
dict_to_return[spin] = False
return dict_to_return
示例4: from_dict
def from_dict(cls, d):
"""
Args:
A dict with all data for a band structure symm line object.
Returns:
A BandStructureSymmLine object
"""
# Strip the label to recover initial string (see trick used in as_dict to handle $ chars)
labels_dict = {k.strip(): v for k, v in d['labels_dict'].items()}
projections = {}
structure = None
if 'projections' in d and len(d['projections']) != 0:
structure = Structure.from_dict(d['structure'])
projections = {
Spin.from_int(int(spin)): [
[{Orbital.from_string(orb): [
d['projections'][spin][i][j][orb][k]
for k in range(len(d['projections'][spin][i][j][orb]))]
for orb in d['projections'][spin][i][j]}
for j in range(len(d['projections'][spin][i]))]
for i in range(len(d['projections'][spin]))]
for spin in d['projections']}
return BandStructureSymmLine(
d['kpoints'], {Spin.from_int(int(k)): d['bands'][k]
for k in d['bands']},
Lattice(d['lattice_rec']['matrix']), d['efermi'],
labels_dict, structure=structure, projections=projections)
示例5: get_dos_from_id
def get_dos_from_id(self, task_id):
"""
Overrides the get_dos_from_id for the MIT gridfs format.
"""
args = {'task_id': task_id}
fields = ['calculations']
structure = self.get_structure_from_id(task_id)
dosid = None
for r in self.query(fields, args):
dosid = r['calculations'][-1]['dos_fs_id']
if dosid != None:
self._fs = gridfs.GridFS(self.db, 'dos_fs')
with self._fs.get(dosid) as dosfile:
s = dosfile.read()
try:
d = json.loads(s)
except:
s = zlib.decompress(s)
d = json.loads(s)
tdos = Dos.from_dict(d)
pdoss = {}
for i in range(len(d['pdos'])):
ados = d['pdos'][i]
all_ados = {}
for j in range(len(ados)):
orb = Orbital.from_vasp_index(j)
odos = ados[str(orb)]
all_ados[orb] = {Spin.from_int(int(k)): v
for k, v
in odos['densities'].items()}
pdoss[structure[i]] = all_ados
return CompleteDos(structure, tdos, pdoss)
return None
示例6: from_dict
def from_dict(cls, d):
"""
Returns Dos object from dict representation of Dos.
"""
return Dos(d["efermi"], d["energies"],
{Spin.from_int(int(k)): v
for k, v in d["densities"].items()})
示例7: from_dict
def from_dict(d):
"""
Returns PDos object from dict representation.
"""
return PDos(
d["efermi"],
d["energies"],
{Spin.from_int(int(k)): v for k, v in d["densities"].items()},
Orbital.from_string(d["orbital"]),
)
示例8: from_dict
def from_dict(cls, d):
"""
Args:
A dict with all data for a band structure symm line object.
Returns:
A BandStructureSymmLine object
"""
labels_dict = d["labels_dict"]
projections = {}
structure = None
if "projections" in d and len(d["projections"]) != 0:
structure = Structure.from_dict(d["structure"])
projections = {
Spin.from_int(int(spin)): [
[
{
Orbital.from_string(orb): [
d["projections"][spin][i][j][orb][k]
for k in range(len(d["projections"][spin][i][j][orb]))
]
for orb in d["projections"][spin][i][j]
}
for j in range(len(d["projections"][spin][i]))
]
for i in range(len(d["projections"][spin]))
]
for spin in d["projections"]
}
return BandStructureSymmLine(
d["kpoints"],
{Spin.from_int(int(k)): d["bands"][k] for k in d["bands"]},
Lattice(d["lattice_rec"]["matrix"]),
d["efermi"],
labels_dict,
structure=structure,
projections=projections,
)
示例9: test_cached
def test_cached(self):
self.assertEquals(id(Spin.from_int(1)), id(Spin.up))
示例10: test_from_int
def test_from_int(self):
self.assertEquals(Spin.from_int(1), Spin.up)
self.assertEquals(Spin.from_int(-1), Spin.down)
self.assertRaises(ValueError, Spin.from_int, 0)