Advertisement
Lulz-Tigre

mechanism

Jul 7th, 2016
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.99 KB | None | 0 0
  1. from analysis_base import *
  2. import numpy as np
  3. from math import log
  4. from catmap.functions import convert_formation_energies
  5.  
  6. class MechanismAnalysis(MechanismPlot,ReactionModelWrapper,MapPlot):
  7.     """
  8.      A simple tool for the generation of potential energy diagrams
  9.      from a reaction network.
  10.    """
  11.     def __init__(self,reaction_model=None):
  12.         """
  13.        Class for generating potential energy diagrams.
  14.        :param reaction_model: The ReactionModel object to load.
  15.        """
  16.         self._rxm = reaction_model
  17.         defaults = {'pressure_correction':True,
  18.                     'min_pressure':1e-12,
  19.                     'energy_type':'free_energy',
  20.                     'include_labels':False,
  21.                     'subplots_adjust_kwargs':{},
  22.                     'line_offset':0,
  23.                     'kwarg_dict':{}}
  24.         self._rxm.update(defaults)
  25.         self.data_dict = {}
  26.         MechanismPlot.__init__(self,[0])
  27.  
  28.     def plot(self,ax=None,plot_variants=None,mechanisms=None,
  29.             labels=None,save=True):
  30.         """
  31.        Generates the potential energy diagram plot
  32.        :param ax: Matplotlib Axes object to optionally plot into
  33.        :param plot_variants: Which PEDs to plot. Defaults to all surfaces
  34.                              or all applied voltages
  35.        :param plot_variants: list of voltages (if electrochemical) or
  36.                              descriptor tuples to plot
  37.        :param mechanisms: Which reaction pathways to plot.  Each integer
  38.                           corresponds to an elementary step. Elementary
  39.                           steps are indexed in the order that they are
  40.                           input with 1 being the first index. Negative
  41.                           integers are used to designate reverse reactions.
  42.                           Read in from model.rxn_mechanisms by default
  43.        :type mechanisms: {string:[int]}
  44.        :param labels: Labels for each state.  Can be generated automatically
  45.        :type labels: [string]
  46.        :param save: Whether to write plot to file
  47.        :type save: bool
  48.        """
  49.         if not ax:
  50.             fig = plt.figure()
  51.             ax = fig.add_subplot(111)
  52.         else:
  53.             fig = ax.get_figure()
  54.         if not mechanisms:
  55.             mechanisms = self.rxn_mechanisms.values()
  56.         if not plot_variants and self.descriptor_dict:
  57.             plot_variants = self.surface_names
  58.         elif not plot_variants and 'voltage' in self.descriptor_names:
  59.             voltage_idx = self.descriptor_names.index('voltage')
  60.             v_min, v_max = self.descriptor_ranges[voltage_idx]
  61.             plot_variants = np.linspace(v_min, v_max, 5)
  62.         if not self.plot_variant_colors:
  63.             self.plot_variant_colors = get_colors(max(len(plot_variants),len(mechanisms)))
  64.  
  65.         self.kwarg_list = []
  66.         for key in self.rxn_mechanisms.keys():
  67.             self.kwarg_list.append(self.kwarg_dict.get(key,{}))
  68.  
  69.         for n,mech in enumerate(mechanisms):
  70.             for i, variant in enumerate(plot_variants):
  71.                 if self.descriptor_dict:
  72.                     xy = self.descriptor_dict[variant]
  73.                 elif 'voltage' in self.descriptor_names:
  74.                     voltage_idx = self.descriptor_names.index('voltage')
  75.                     xy = [0, 0]
  76.                     xy[voltage_idx] = variant
  77.                     xy[1-voltage_idx] = self.descriptor_ranges[1-voltage_idx][0]
  78.                 else:
  79.                     xy = variant
  80.                 if '-' not in xy:
  81.                     self.thermodynamics.current_state = None #force recalculation
  82.                     self._rxm._descriptors = xy
  83.  
  84.                     if self.energy_type == 'free_energy':
  85.                         energy_dict = self.scaler.get_free_energies(xy)
  86.                     elif self.energy_type == 'potential_energy':
  87.                         energy_dict = self.scaler.get_free_energies(xy)
  88.                         energy_dict.update(self.scaler.get_electronic_en
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement