本文整理汇总了Python中pymatgen.analysis.reaction_calculator.Reaction类的典型用法代码示例。如果您正苦于以下问题:Python Reaction类的具体用法?Python Reaction怎么用?Python Reaction使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Reaction类的17个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: _get_reaction
def _get_reaction(self, x):
"""
Generates balanced reaction at mixing ratio x : (1-x) for
self.comp1 : self.comp2.
Args:
x (float): Mixing ratio x of reactants, a float between 0 and 1.
Returns:
Reaction object.
"""
mix_comp = self.comp1 * x + self.comp2 * (1-x)
decomp = self.pd.get_decomposition(mix_comp)
# Uses original composition for reactants.
reactant = list(set([self.c1_original, self.c2_original]))
if self.grand:
reactant += [Composition(e.symbol)
for e, v in self.pd.chempots.items()]
product = [Composition(k.name) for k, v in decomp.items()]
reaction = Reaction(reactant, product)
if np.isclose(x, 1):
reaction.normalize_to(self.c1_original, 1)
else:
reaction.normalize_to(self.c2_original, 1)
return reaction
开发者ID:mbkumar,项目名称:pymatgen,代码行数:29,代码来源:interface_reactions.py
示例2: test_normalize_to
def test_normalize_to(self):
products = [Composition("Fe"), Composition("O2")]
reactants = [Composition("Fe2O3")]
rxn = Reaction(reactants, products)
rxn.normalize_to(Composition("Fe"), 3)
self.assertEqual(str(rxn), "1.500 Fe2O3 -> 3.000 Fe + 2.250 O2",
"Wrong reaction obtained!")
开发者ID:antoinedewandre,项目名称:pymatgen,代码行数:7,代码来源:test_reaction_calculator.py
示例3: process_multientry
def process_multientry(entry_list, prod_comp, coeff_threshold=1e-4):
"""
Static method for finding a multientry based on
a list of entries and a product composition.
Essentially checks to see if a valid aqueous
reaction exists between the entries and the
product composition and returns a MultiEntry
with weights according to the coefficients if so.
Args:
entry_list ([Entry]): list of entries from which to
create a MultiEntry
prod_comp (Composition): composition constraint for setting
weights of MultiEntry
coeff_threshold (float): threshold of stoichiometric
coefficients to filter, if weights are lower than
this value, the entry is not returned
"""
dummy_oh = [Composition("H"), Composition("O")]
try:
# Get balanced reaction coeffs, ensuring all < 0 or conc thresh
# Note that we get reduced compositions for solids and non-reduced
# compositions for ions because ions aren't normalized due to
# their charge state.
entry_comps = [e.composition for e in entry_list]
rxn = Reaction(entry_comps + dummy_oh, [prod_comp])
coeffs = -np.array([rxn.get_coeff(comp) for comp in entry_comps])
# Return None if reaction coeff threshold is not met
# TODO: this filtration step might be put somewhere else
if (coeffs > coeff_threshold).all():
return MultiEntry(entry_list, weights=coeffs.tolist())
else:
return None
except ReactionError:
return None
开发者ID:ExpHP,项目名称:pymatgen,代码行数:35,代码来源:pourbaix_diagram.py
示例4: test_to_from_dict
def test_to_from_dict(self):
reactants = [Composition("Fe"), Composition("O2")]
products = [Composition("Fe2O3")]
rxn = Reaction(reactants, products)
d = rxn.as_dict()
rxn = Reaction.from_dict(d)
self.assertEqual(rxn.normalized_repr, "4 Fe + 3 O2 -> 2 Fe2O3")
开发者ID:antoinedewandre,项目名称:pymatgen,代码行数:7,代码来源:test_reaction_calculator.py
示例5: process_multientry
def process_multientry(entry_list, prod_comp):
"""
Static method for finding a multientry based on
a list of entries and a product composition.
Essentially checks to see if a valid aqueous
reaction exists between the entries and the
product composition and returns a MultiEntry
with weights according to the coefficients if so.
Args:
entry_list ([Entry]): list of entries from which to
create a MultiEntry
comp (Composition): composition constraint for setting
weights of MultiEntry
"""
dummy_oh = [Composition("H"), Composition("O")]
try:
# Get balanced reaction coeffs, ensuring all < 0 or conc thresh
# Note that we get reduced compositions for solids and non-reduced
# compositions for ions because ions aren't normalized due to
# their charge state.
entry_comps = [e.composition if e.phase_type=='Ion'
else e.composition.reduced_composition
for e in entry_list]
rxn = Reaction(entry_comps + dummy_oh, [prod_comp])
thresh = np.array([pe.conc if pe.phase_type == "Ion"
else 1e-3 for pe in entry_list])
coeffs = -np.array([rxn.get_coeff(comp) for comp in entry_comps])
if (coeffs > thresh).all():
weights = coeffs / coeffs[0]
return MultiEntry(entry_list, weights=weights.tolist())
else:
return None
except ReactionError:
return None
开发者ID:czhengsci,项目名称:pymatgen,代码行数:35,代码来源:maker.py
示例6: test_as_entry
def test_as_entry(self):
reactants = [Composition("MgO"), Composition("Al2O3")]
products = [Composition("MgAl2O4")]
energies = {Composition("MgO"): -0.1, Composition("Al2O3"): -0.2, Composition("MgAl2O4"): -0.5}
rxn = Reaction(reactants, products)
entry = rxn.as_entry(energies)
self.assertEqual(entry.name, "1.000 MgO + 1.000 Al2O3 -> 1.000 MgAl2O4")
self.assertAlmostEquals(entry.energy, -0.2, 5)
开发者ID:rousseab,项目名称:pymatgen,代码行数:8,代码来源:test_reaction_calculator.py
示例7: test_calculate_energy
def test_calculate_energy(self):
reactants = [Composition("MgO"), Composition("Al2O3")]
products = [Composition("MgAl2O4")]
energies = {Composition("MgO"): -0.1, Composition("Al2O3"): -0.2, Composition("MgAl2O4"): -0.5}
rxn = Reaction(reactants, products)
self.assertEqual(str(rxn), "1.000 MgO + 1.000 Al2O3 -> 1.000 MgAl2O4")
self.assertEqual(rxn.normalized_repr, "MgO + Al2O3 -> MgAl2O4")
self.assertAlmostEquals(rxn.calculate_energy(energies), -0.2, 5)
开发者ID:rousseab,项目名称:pymatgen,代码行数:8,代码来源:test_reaction_calculator.py
示例8: test_scientific_notation
def test_scientific_notation(self):
products = [Composition("FePO3.9999"), Composition("O2")]
reactants = [Composition("FePO4")]
rxn = Reaction(reactants, products)
self.assertEqual(str(rxn), "FePO4 -> Fe1P1O3.9999 + 5e-05 O2")
self.assertEqual(rxn, Reaction.from_string(str(rxn)))
rxn2 = Reaction.from_string("FePO4 + 20 CO -> 1e1 O2 + Fe1P1O4 + 20 C")
self.assertEqual(str(rxn2), "20 CO -> 10 O2 + 20 C")
开发者ID:bocklund,项目名称:pymatgen,代码行数:9,代码来源:test_reaction_calculator.py
示例9: test_products_reactants
def test_products_reactants(self):
reactants = [Composition.from_formula("Li3Fe2(PO4)3"), Composition.from_formula("Fe2O3"), Composition.from_formula("O2")]
products = [Composition.from_formula("LiFePO4")]
energies = {Composition.from_formula("Li3Fe2(PO4)3"):-0.1, Composition.from_formula("Fe2O3"):-0.2, Composition.from_formula("O2"):-0.2, Composition.from_formula("LiFePO4"):-0.5}
rxn = Reaction(reactants, products)
self.assertIn(Composition.from_formula("O2"), rxn.products, "O not in products!")
self.assertIn(Composition.from_formula("Li3Fe2(PO4)3"), rxn.reactants, "Li3Fe2(PO4)4 not in reactants!")
self.assertEquals(str(rxn), "0.333 Li3Fe2(PO4)3 + 0.167 Fe2O3 -> 0.250 O2 + 1.000 LiFePO4", "Wrong reaction obtained!")
self.assertEquals(rxn.normalized_repr, "4 Li3Fe2(PO4)3 + 2 Fe2O3 -> 3 O2 + 12 LiFePO4", "Wrong normalized reaction obtained!")
self.assertAlmostEquals(rxn.calculate_energy(energies), -0.48333333, 5)
开发者ID:chenweis,项目名称:pymatgen,代码行数:11,代码来源:test_reaction_calculator.py
示例10: transform_entries
def transform_entries(self, entries, terminal_compositions):
"""
Method to transform all entries to the composition coordinate in the
terminal compositions. If the entry does not fall within the space
defined by the terminal compositions, they are excluded. For example,
Li3PO4 is mapped into a Li2O:1.5, P2O5:0.5 composition. The terminal
compositions are represented by DummySpecies.
Args:
entries:
Sequence of all input entries
terminal_compositions:
Terminal compositions of phase space.
Returns:
Sequence of TransformedPDEntries falling within the phase space.
"""
new_entries = []
if self.normalize_terminals:
fractional_comp = [c.get_fractional_composition()
for c in terminal_compositions]
else:
fractional_comp = terminal_compositions
#Map terminal compositions to unique dummy species.
sp_mapping = collections.OrderedDict()
for i, comp in enumerate(fractional_comp):
sp_mapping[comp] = DummySpecie("X" + chr(102 + i))
for entry in entries:
try:
rxn = Reaction(fractional_comp, [entry.composition])
rxn.normalize_to(entry.composition)
#We only allow reactions that have positive amounts of
#reactants.
if all([rxn.get_coeff(comp) <= CompoundPhaseDiagram.amount_tol
for comp in fractional_comp]):
newcomp = {sp_mapping[comp]: -rxn.get_coeff(comp)
for comp in fractional_comp}
newcomp = {k: v for k, v in newcomp.items()
if v > CompoundPhaseDiagram.amount_tol}
transformed_entry = \
TransformedPDEntry(Composition(newcomp), entry)
new_entries.append(transformed_entry)
except ReactionError:
#If the reaction can't be balanced, the entry does not fall
#into the phase space. We ignore them.
pass
return new_entries, sp_mapping
开发者ID:bkappes,项目名称:pymatgen,代码行数:49,代码来源:pdmaker.py
示例11: get_element_profile
def get_element_profile(self, element, comp):
"""
Provides the element evolution data for a composition.
For example, can be used to analyze Li conversion voltages by varying uLi and looking at the phases formed.
Also can be used to analyze O2 evolution by varying uO2.
Args:
element:
An element. Must be in the phase diagram.
comp:
A Composition
Returns:
Evolution data as a list of dictionaries of the following format: [ {'chempot': -10.487582010000001, 'evolution': -2.0, 'reaction': Reaction Object], ...]
"""
if element not in self._pd.elements:
raise ValueError("get_transition_chempots can only be called with elements in the phase diagram.")
chempots = self.get_transition_chempots(element)
stable_entries = self._pd.stable_entries
gccomp = Composition({el:amt for el, amt in comp.items() if el != element})
elref = self._pd.el_refs[element]
elcomp = Composition.from_formula(element.symbol)
prev_decomp = [];
evolution = []
def are_same_decomp(decomp1, decomp2):
for comp in decomp2:
if comp not in decomp1:
return False
return True
for c in chempots:
gcpd = GrandPotentialPhaseDiagram(stable_entries, {element:c - 0.01}, self._pd.elements)
analyzer = PDAnalyzer(gcpd)
decomp = [gcentry.original_entry.composition for gcentry, amt in analyzer.get_decomposition(gccomp).items() if amt > 1e-5]
decomp_entries = [gcentry.original_entry for gcentry, amt in analyzer.get_decomposition(gccomp).items() if amt > 1e-5]
if not are_same_decomp(prev_decomp, decomp):
if elcomp not in decomp:
decomp.insert(0, elcomp)
rxn = Reaction([comp], decomp)
rxn.normalize_to(comp)
prev_decomp = decomp
evolution.append({'chempot':c, 'evolution' :-rxn.coeffs[rxn.all_comp.index(elcomp)], 'element_reference': elref, 'reaction':rxn, 'entries':decomp_entries})
return evolution
开发者ID:chenweis,项目名称:pymatgen,代码行数:45,代码来源:pdanalyzer.py
示例12: test_as_entry
def test_as_entry(self):
reactants = [Composition("MgO"), Composition("Al2O3")]
products = [Composition("MgAl2O4")]
energies = {Composition("MgO"): -0.1, Composition("Al2O3"): -0.2,
Composition("MgAl2O4"): -0.5}
rxn = Reaction(reactants, products)
entry = rxn.as_entry(energies)
self.assertEqual(entry.name,
"MgO + Al2O3 -> MgAl2O4")
self.assertAlmostEqual(entry.energy, -0.2, 5)
products = [Composition("Fe"), Composition("O2")]
reactants = [Composition("Fe2O3")]
rxn = Reaction(reactants, products)
energies = {Composition("Fe"): 0, Composition("O2"): 0,
Composition("Fe2O3"): 0.5}
entry = rxn.as_entry(energies)
self.assertEqual(entry.composition, Composition("Fe1.0 O1.5"))
self.assertAlmostEqual(entry.energy, -0.25, 5)
开发者ID:bocklund,项目名称:pymatgen,代码行数:19,代码来源:test_reaction_calculator.py
示例13: test_as_entry
def test_as_entry(self):
reactants = [Composition("MgO"), Composition("Al2O3")]
products = [Composition("MgAl2O4")]
energies = {Composition("MgO"): -0.1, Composition("Al2O3"): -0.2,
Composition("MgAl2O4"): -0.5}
rxn = Reaction(reactants, products)
entry = rxn.as_entry(energies)
self.assertEqual(entry.name,
"1.000 MgO + 1.000 Al2O3 -> 1.000 MgAl2O4")
self.assertAlmostEqual(entry.energy, -0.2, 5)
products = [Composition("Fe"), Composition("O2")]
reactants = [Composition("Fe2O3")]
rxn = Reaction(reactants, products)
energies = {Composition("Fe"): 0, Composition("O2"): 0,
Composition("Fe2O3"): 0.5}
entry = rxn.as_entry(energies)
self.assertEqual(entry.composition.formula, "Fe1.33333333 O2")
self.assertAlmostEqual(entry.energy, -0.333333, 5)
开发者ID:Lightslayer,项目名称:pymatgen,代码行数:19,代码来源:test_reaction_calculator.py
示例14: _get_reaction
def _get_reaction(self, x, normalize=False):
"""
Generates balanced reaction at mixing ratio x : (1-x) for
self.comp1 : self.comp2.
Args:
x (float): Mixing ratio x of reactants, a float between 0 and 1.
normalize (bool): Whether or not to normalize the sum of
coefficients of reactants to 1. For not normalized case,
use original reactant compositions in reaction for clarity.
Returns:
Reaction object.
"""
mix_comp = self.comp1 * x + self.comp2 * (1-x)
decomp = self.pd.get_decomposition(mix_comp)
if normalize:
reactant = list(set([self.c1, self.c2]))
else:
# Uses original composition for reactants.
reactant = list(set([self.c1_original, self.c2_original]))
if self.grand:
reactant += [Composition(e.symbol)
for e, v in self.pd.chempots.items()]
product = [Composition(k.name) for k, v in decomp.items()]
reaction = Reaction(reactant, product)
if normalize:
x = self._convert(x, self.factor1, self.factor2)
if x == 1:
reaction.normalize_to(self.c1, x)
else:
reaction.normalize_to(self.c2, 1-x)
return reaction
开发者ID:matk86,项目名称:pymatgen,代码行数:37,代码来源:interface_reactions.py
示例15: test_init
def test_init(self):
reactants = [Composition("Fe"),
Composition("O2")]
products = [Composition("Fe2O3")]
rxn = Reaction(reactants, products)
self.assertEqual(str(rxn), "2 Fe + 1.5 O2 -> Fe2O3")
self.assertEqual(rxn.normalized_repr, "4 Fe + 3 O2 -> 2 Fe2O3")
d = rxn.as_dict()
rxn = Reaction.from_dict(d)
repr, factor = rxn.normalized_repr_and_factor()
self.assertEqual(repr, "4 Fe + 3 O2 -> 2 Fe2O3")
self.assertAlmostEqual(factor, 2)
reactants = [Composition("FePO4"), Composition('Mn')]
products = [Composition("FePO4"), Composition('Xe')]
rxn = Reaction(reactants, products)
self.assertEqual(str(rxn), "FePO4 -> FePO4")
products = [Composition("Ti2 O4"), Composition("O1")]
reactants = [Composition("Ti1 O2")]
rxn = Reaction(reactants, products)
self.assertEqual(str(rxn), "2 TiO2 -> 2 TiO2")
reactants = [Composition("FePO4"), Composition("Li")]
products = [Composition("LiFePO4")]
rxn = Reaction(reactants, products)
self.assertEqual(str(rxn), "FePO4 + Li -> LiFePO4")
reactants = [Composition("MgO")]
products = [Composition("MgO")]
rxn = Reaction(reactants, products)
self.assertEqual(str(rxn), "MgO -> MgO")
reactants = [Composition("Mg")]
products = [Composition("Mg")]
rxn = Reaction(reactants, products)
self.assertEqual(str(rxn), "Mg -> Mg")
reactants = [Composition("FePO4"), Composition("LiPO3")]
products = [Composition("LiFeP2O7")]
rxn = Reaction(reactants, products)
self.assertEqual(str(rxn),
"FePO4 + LiPO3 -> LiFeP2O7")
reactants = [Composition("Na"), Composition("K2O")]
products = [Composition("Na2O"), Composition("K")]
rxn = Reaction(reactants, products)
self.assertEqual(str(rxn),
"2 Na + K2O -> Na2O + 2 K")
# Test for an old bug which has a problem when excess product is
# defined.
products = [Composition("FePO4"), Composition("O")]
reactants = [Composition("FePO4")]
rxn = Reaction(reactants, products)
self.assertEqual(str(rxn), "FePO4 -> FePO4")
products = list(map(Composition, ['LiCrO2', 'La8Ti8O12', 'O2']))
reactants = [Composition('LiLa3Ti3CrO12')]
rxn = Reaction(reactants, products)
self.assertEqual(str(rxn),
"LiLa3Ti3CrO12 -> LiCrO2 + 1.5 La2Ti2O3 + 2.75 O2")
开发者ID:bocklund,项目名称:pymatgen,代码行数:67,代码来源:test_reaction_calculator.py
示例16: test_init
def test_init(self):
reactants = [Composition("Fe"),
Composition("O2")]
products = [Composition("Fe2O3")]
rxn = Reaction(reactants, products)
self.assertEqual(str(rxn), "2.000 Fe + 1.500 O2 -> 1.000 Fe2O3",
"Wrong reaction obtained!")
self.assertEqual(rxn.normalized_repr, "4 Fe + 3 O2 -> 2 Fe2O3",
"Wrong normalized reaction obtained!")
d = rxn.as_dict()
rxn = Reaction.from_dict(d)
self.assertEqual(rxn.normalized_repr, "4 Fe + 3 O2 -> 2 Fe2O3",
"Wrong normalized reaction obtained!")
reactants = [Composition("Fe"), Composition("O"), Composition("Mn"),
Composition("P")]
products = [Composition("FeP"), Composition("MnO")]
rxn = Reaction(reactants, products)
self.assertEqual(str(rxn),
"1.000 Fe + 0.500 O2 + 1.000 Mn + 1.000 P -> 1.000 FeP + 1.000 MnO",
"Wrong reaction obtained!")
self.assertEqual(rxn.normalized_repr,
"2 Fe + O2 + 2 Mn + 2 P -> 2 FeP + 2 MnO",
"Wrong normalized reaction obtained!")
reactants = [Composition("FePO4")]
products = [Composition("FePO4")]
rxn = Reaction(reactants, products)
self.assertEqual(str(rxn), "1.000 FePO4 -> 1.000 FePO4",
"Wrong reaction obtained!")
products = [Composition("Ti2 O4"), Composition("O1")]
reactants = [Composition("Ti1 O2")]
rxn = Reaction(reactants, products)
self.assertEqual(str(rxn), "2.000 TiO2 -> 2.000 TiO2",
"Wrong reaction obtained!")
reactants = [Composition("FePO4"), Composition("Li")]
products = [Composition("LiFePO4")]
rxn = Reaction(reactants, products)
self.assertEqual(str(rxn), "1.000 FePO4 + 1.000 Li -> 1.000 LiFePO4",
"Wrong reaction obtained!")
reactants = [Composition("MgO")]
products = [Composition("MgO")]
rxn = Reaction(reactants, products)
self.assertEqual(str(rxn), "1.000 MgO -> 1.000 MgO",
"Wrong reaction obtained!")
reactants = [Composition("Mg")]
products = [Composition("Mg")]
rxn = Reaction(reactants, products)
self.assertEqual(str(rxn), "1.000 Mg -> 1.000 Mg",
"Wrong reaction obtained!")
reactants = [Composition("FePO4"), Composition("LiPO3")]
products = [Composition("LiFeP2O7")]
rxn = Reaction(reactants, products)
self.assertEqual(str(rxn),
"1.000 FePO4 + 1.000 LiPO3 -> 1.000 LiFeP2O7",
"Wrong reaction obtained!")
reactants = [Composition("Na"), Composition("K2O")]
products = [Composition("Na2O"), Composition("K")]
rxn = Reaction(reactants, products)
self.assertEqual(str(rxn),
"1.000 Na + 0.500 K2O -> 0.500 Na2O + 1.000 K",
"Wrong reaction obtained!")
# Test for an old bug which has a problem when excess product is
# defined.
products = [Composition("FePO4"), Composition("O")]
reactants = [Composition("FePO4")]
rxn = Reaction(reactants, products)
self.assertEqual(str(rxn), "1.000 FePO4 -> 1.000 FePO4",
"Wrong reaction obtained!")
products = list(map(Composition, ['La8Ti8O12', 'O2', 'LiCrO2']))
reactants = [Composition('LiLa3Ti3CrO12')]
rxn = Reaction(reactants, products)
self.assertEqual(str(rxn),
"1.000 LiLa3Ti3CrO12 -> 1.500 La2Ti2O3 + 2.750 O2 + 1.000 LiCrO2",
"Wrong reaction obtained!")
开发者ID:antoinedewandre,项目名称:pymatgen,代码行数:88,代码来源:test_reaction_calculator.py
示例17: test_normalize_to
def test_normalize_to(self):
products = [Composition("Fe"), Composition("O2")]
reactants = [Composition("Fe2O3")]
rxn = Reaction(reactants, products)
rxn.normalize_to(Composition("Fe"), 3)
self.assertEqual(str(rxn), "1.5 Fe2O3 -> 3 Fe + 2.25 O2")
开发者ID:bocklund,项目名称:pymatgen,代码行数:6,代码来源:test_reaction_calculator.py
注:本文中的pymatgen.analysis.reaction_calculator.Reaction类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论