pymatgen.analysis.reaction_calculator module

This module provides classes that define a chemical reaction.

class BalancedReaction(reactants_coeffs, products_coeffs)[source]

Bases: monty.json.MSONable

An object representing a complete chemical reaction.

Reactants and products to be specified as dict of {Composition: coeff}.

Parameters
  • ({Composition (products_coeffs) – float}): Reactants as dict of {Composition: amt}.

  • ({Composition – float}): Products as dict of {Composition: amt}.

TOLERANCE = 1e-06[source]
property all_comp[source]

List of all compositions in the reaction.

as_dict()[source]
Returns

A dictionary representation of BalancedReaction.

as_entry(energies)[source]

Returns a ComputedEntry representation of the reaction. :return:

calculate_energy(energies)[source]

Calculates the energy of the reaction.

Parameters

({Composition (energies) – float}): Energy for each composition. E.g ., {comp1: energy1, comp2: energy2}.

Returns

reaction energy as a float.

property coeffs[source]

Final coefficients of the calculated reaction

property elements[source]

List of elements in the reaction

classmethod from_dict(d)[source]
Parameters

d (dict) – from as_dict()

Returns

A BalancedReaction object.

static from_string(rxn_string)[source]

Generates a balanced reaction from a string. The reaction must already be balanced.

Parameters

rxn_string – The reaction string. For example, “4 Li + O2-> 2Li2O”

Returns

BalancedReaction

get_coeff(comp)[source]

Returns coefficient for a particular composition

get_el_amount(element)[source]

Returns the amount of the element in the reaction.

Parameters

element (Element/Species) – Element in the reaction

Returns

Amount of that element in the reaction.

normalize_to(comp, factor=1)[source]

Normalizes the reaction to one of the compositions. By default, normalizes such that the composition given has a coefficient of 1. Another factor can be specified.

Parameters
  • comp (Composition) – Composition to normalize to

  • factor (float) – Factor to normalize to. Defaults to 1.

normalize_to_element(element, factor=1)[source]

Normalizes the reaction to one of the elements. By default, normalizes such that the amount of the element is 1. Another factor can be specified.

Parameters
  • element (Element/Species) – Element to normalize to.

  • factor (float) – Factor to normalize to. Defaults to 1.

property normalized_repr[source]

A normalized representation of the reaction. All factors are converted to lowest common factors.

normalized_repr_and_factor()[source]

Normalized representation for a reaction For example, 4 Li + 2 O -> 2Li2O becomes 2 Li + O -> Li2O

property products[source]

List of products

property reactants[source]

List of reactants

class ComputedReaction(reactant_entries, product_entries)[source]

Bases: pymatgen.analysis.reaction_calculator.Reaction

Convenience class to generate a reaction from ComputedEntry objects, with some additional attributes, such as a reaction energy based on computed energies.

Parameters
property all_entries[source]

Equivalent of all_comp but returns entries, in the same order as the coefficients.

as_dict()[source]
Returns

A dictionary representation of ComputedReaction.

property calculated_reaction_energy[source]

Returns (float): The calculated reaction energy.

property calculated_reaction_energy_uncertainty[source]

Calculates the uncertainty in the reaction energy based on the uncertainty in the energies of the products and reactants

classmethod from_dict(d)[source]
Parameters

d (dict) – from as_dict()

Returns

A ComputedReaction object.

class Reaction(reactants, products)[source]

Bases: pymatgen.analysis.reaction_calculator.BalancedReaction

A more flexible class representing a Reaction. The reaction amounts will be automatically balanced. Reactants and products can swap sides so that all coefficients are positive, however this class will find the solution with the minimum number of swaps and coefficients of 0. Normalizes so that the FIRST product (or products, if underdetermined) has a coefficient of one.

Reactants and products to be specified as list of pymatgen.core.structure.Composition. e.g., [comp1, comp2]

Parameters
as_dict()[source]
Returns

A dictionary representation of Reaction.

copy()[source]

Returns a copy of the Reaction object.

classmethod from_dict(d)[source]
Parameters

d (dict) – from as_dict()

Returns

A Reaction object.

exception ReactionError(msg)[source]

Bases: Exception

Exception class for Reactions. Allows more information in exception messages to cover situations not covered by standard exception classes.

Create a ReactionError.

Parameters

msg (str) – More information about the ReactionError.