本文整理汇总了Python中pymatgen.core.composition.Composition.keys方法的典型用法代码示例。如果您正苦于以下问题:Python Composition.keys方法的具体用法?Python Composition.keys怎么用?Python Composition.keys使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pymatgen.core.composition.Composition
的用法示例。
在下文中一共展示了Composition.keys方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: parse_tok
# 需要导入模块: from pymatgen.core.composition import Composition [as 别名]
# 或者: from pymatgen.core.composition.Composition import keys [as 别名]
def parse_tok(t):
if re.match("\w+-\d+", t):
return {"task_id": t}
elif "-" in t:
elements = [parse_sym(sym) for sym in t.split("-")]
chemsyss = []
for cs in itertools.product(*elements):
if len(set(cs)) == len(cs):
# Check for valid symbols
cs = [Element(s).symbol for s in cs]
chemsyss.append("-".join(sorted(cs)))
return {"chemsys": {"$in": chemsyss}}
else:
all_formulas = set()
explicit_els = []
wild_card_els = []
for sym in re.findall(
r"(\*[\.\d]*|\{.*\}[\.\d]*|[A-Z][a-z]*)[\.\d]*", t):
if ("*" in sym) or ("{" in sym):
wild_card_els.append(sym)
else:
m = re.match("([A-Z][a-z]*)[\.\d]*", sym)
explicit_els.append(m.group(1))
nelements = len(wild_card_els) + len(set(explicit_els))
parts = re.split(r"(\*|\{.*\})", t)
parts = [parse_sym(s) for s in parts if s != ""]
for f in itertools.product(*parts):
c = Composition("".join(f))
if len(c) == nelements:
# Check for valid Elements in keys.
for e in c.keys():
Element(e.symbol)
all_formulas.add(c.reduced_formula)
return {"pretty_formula": {"$in": list(all_formulas)}}
示例2: parse_tok
# 需要导入模块: from pymatgen.core.composition import Composition [as 别名]
# 或者: from pymatgen.core.composition.Composition import keys [as 别名]
def parse_tok(t):
if re.match("\w+-\d+", t):
return {"task_id": t}
elif "-" in t:
elements = t.split("-")
elements = [[Element(el).symbol] if el != "*" else
ALL_ELEMENT_SYMBOLS for el in elements]
chemsyss = []
for cs in itertools.product(*elements):
if len(set(cs)) == len(cs):
chemsyss.append("-".join(sorted(set(cs))))
return {"chemsys": {"$in": chemsyss}}
else:
all_formulas = set()
syms = re.findall("[A-Z][a-z]*", t)
to_permute = ALL_ELEMENT_SYMBOLS.difference(syms)
parts = t.split("*")
for syms in itertools.permutations(to_permute,
len(parts) - 1):
f = []
for p in zip(parts, syms):
f.extend(p)
f.append(parts[-1])
c = Composition("".join(f))
#Check for valid Elements in keys.
map(lambda e: Element(e.symbol), c.keys())
all_formulas.add(c.reduced_formula)
return {"pretty_formula": {"$in": list(all_formulas)}}
示例3: parse_tok
# 需要导入模块: from pymatgen.core.composition import Composition [as 别名]
# 或者: from pymatgen.core.composition.Composition import keys [as 别名]
def parse_tok(t):
if re.match("\w+-\d+", t):
return {"task_id": t}
elif "-" in t:
elements = [parse_sym(sym) for sym in t.split("-")]
chemsyss = []
for cs in itertools.product(*elements):
if len(set(cs)) == len(cs):
# Check for valid symbols
cs = [Element(s).symbol for s in cs]
chemsyss.append("-".join(sorted(cs)))
return {"chemsys": {"$in": chemsyss}}
else:
all_formulas = set()
parts = re.split(r"(\*|\{.*\})", t)
parts = [parse_sym(s) for s in parts]
for f in itertools.product(*parts):
if len(set(f)) == len(f):
c = Composition("".join(f))
#Check for valid Elements in keys.
for e in c.keys():
Element(e.symbol)
all_formulas.add(c.reduced_formula)
return {"pretty_formula": {"$in": list(all_formulas)}}
示例4: Site
# 需要导入模块: from pymatgen.core.composition import Composition [as 别名]
# 或者: from pymatgen.core.composition.Composition import keys [as 别名]
class Site(collections.Mapping, collections.Hashable, PMGSONable):
"""
A generalized *non-periodic* site. This is essentially a composition
at a point in space, with some optional properties associated with it. A
Composition is used to represent the atoms and occupancy, which allows for
disordered site representation. Coords are given in standard cartesian
coordinates.
"""
position_atol = 1e-5
def __init__(self, atoms_n_occu, coords, properties=None):
"""
Create a *non-periodic* site.
Args:
atoms_n_occu: Species on the site. Can be:
i. A sequence of element / specie specified either as string
symbols, e.g. ["Li", "Fe2+", "P", ...] or atomic numbers,
e.g., (3, 56, ...) or actual Element or Specie objects.
ii. List of dict of elements/species and occupancies, e.g.,
[{"Fe" : 0.5, "Mn":0.5}, ...]. This allows the setup of
disordered structures.
coords: Cartesian coordinates of site.
properties: Properties associated with the site as a dict, e.g.
{"magmom": 5}. Defaults to None.
"""
if isinstance(atoms_n_occu, collections.Mapping):
self._species = Composition(atoms_n_occu)
totaloccu = self._species.num_atoms
if totaloccu > 1 + Composition.amount_tolerance:
raise ValueError("Species occupancies sum to more than 1!")
self._is_ordered = totaloccu == 1 and len(self._species) == 1
else:
self._species = Composition({get_el_sp(atoms_n_occu): 1})
self._is_ordered = True
self._coords = coords
self._properties = properties if properties else {}
@property
def properties(self):
"""
Returns a view of properties as a dict.
"""
return {k: v for k, v in self._properties.items()}
def __getattr__(self, a):
#overriding getattr doens't play nice with pickle, so we
#can't use self._properties
p = object.__getattribute__(self, '_properties')
if a in p:
return p[a]
raise AttributeError(a)
def distance(self, other):
"""
Get distance between two sites.
Args:
other: Other site.
Returns:
Distance (float)
"""
return np.linalg.norm(other.coords - self.coords)
def distance_from_point(self, pt):
"""
Returns distance between the site and a point in space.
Args:
pt: Cartesian coordinates of point.
Returns:
Distance (float)
"""
return np.linalg.norm(np.array(pt) - self._coords)
@property
def species_string(self):
"""
String representation of species on the site.
"""
if self._is_ordered:
return list(self._species.keys())[0].__str__()
else:
sorted_species = sorted(self._species.keys())
return ", ".join(["{}:{:.3f}".format(sp, self._species[sp])
for sp in sorted_species])
@property
def species_and_occu(self):
"""
The species at the site, i.e., a Composition mapping type of
element/species to occupancy.
"""
return self._species
#.........这里部分代码省略.........
示例5: interaction
# 需要导入模块: from pymatgen.core.composition import Composition [as 别名]
# 或者: from pymatgen.core.composition.Composition import keys [as 别名]
class MolecularOrbitals:
'''
Represents the character of bands in a solid. The input is a chemical
formula, since no structural characteristics are taken into account.
The band character of a crystal emerges from the atomic orbitals of the
constituant ions, hybridization/covalent bonds, and the spin-orbit
interaction (ex: Fe2O3). Right now the orbitals are only built from
the uncharged atomic species. Functionality can be improved by:
1) calculate charged ion orbital energies
2) incorportate the coordination enviornment to account for covalant bonds
The atomic orbital energies are stored in pymatgen.core.periodic_table.JSON
>>> MOs = MolecularOrbitals('SrTiO3')
>>> MOs.band_edges
{'HOMO':['O','2p',-0.338381], 'LUMO':['Ti','3d',-0.17001], 'metal':False}
'''
def __init__(self, formula):
'''
Args:
chemical formula as a string. formula must have integer subscripts
Ex: 'SrTiO3'
Attributes:
composition: the composition as a dictionary.
Ex: {'Sr': 1, 'Ti': 1, 'O', 3}
elements: the dictionary keys for the composition
elec_neg: the maximum pairwise electronegetivity difference
aos: the consituant atomic orbitals for each element as a
dictionary
band_edges: dictionary containing the highest occupied molecular
orbital (HOMO), lowest unocupied molecular orbital
(LUMO), and whether the material is predicted to be a
metal
'''
self.composition = Composition(formula).as_dict()
self.elements = self.composition.keys()
for subscript in self.composition.values():
if not float(subscript).is_integer():
raise ValueError('composition subscripts must be integers')
self.elec_neg = self.max_electronegativity()
self.aos = {str(el): [[str(el), k, v]
for k, v in Element(el).atomic_orbitals.items()]
for el in self.elements}
self.band_edges = self.obtain_band_edges()
def max_electronegativity(self):
'''
returns the maximum pairwise electronegativity difference
'''
maximum = 0
for e1, e2 in combinations(self.elements, 2):
if abs(Element(e1).X - Element(e2).X) > maximum:
maximum = abs(Element(e1).X - Element(e2).X)
return maximum
def aos_as_list(self):
'''
Returns a list of atomic orbitals, sorted from lowest to highest energy
'''
return sorted(chain.from_iterable(
[self.aos[el] * int(self.composition[el]) for el in self.elements]
), key=lambda x: x[2])
def obtain_band_edges(self):
'''
Fill up the atomic orbitals with available electrons.
Return HOMO, LUMO, and whether it's a metal.
'''
orbitals = self.aos_as_list()
electrons = Composition(self.composition).total_electrons
partial_filled = []
for orbital in orbitals:
if electrons <= 0:
break
if 's' in orbital[1]:
electrons += -2
elif 'p' in orbital[1]:
electrons += -6
elif 'd' in orbital[1]:
electrons += -10
elif 'f' in orbital[1]:
electrons += -14
partial_filled.append(orbital)
if electrons != 0:
homo = partial_filled[-1]
lumo = partial_filled[-1]
else:
homo = partial_filled[-1]
try:
lumo = orbitals[len(partial_filled)]
except:
lumo = None
if homo == lumo:
metal = True
#.........这里部分代码省略.........