
<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta charset="utf-8" />
    <title>pymatgen.io.abinit.events &#8212; pymatgen 2019.10.4 documentation</title>
    <link rel="stylesheet" href="../../../../_static/proBlue.css" type="text/css" />
    <link rel="stylesheet" href="../../../../_static/pygments.css" type="text/css" />
    <script type="text/javascript" id="documentation_options" data-url_root="../../../../" src="../../../../_static/documentation_options.js"></script>
    <script type="text/javascript" src="../../../../_static/jquery.js"></script>
    <script type="text/javascript" src="../../../../_static/underscore.js"></script>
    <script type="text/javascript" src="../../../../_static/doctools.js"></script>
    <script type="text/javascript" src="../../../../_static/language_data.js"></script>
    <script async="async" type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/latest.js?config=TeX-AMS-MML_HTMLorMML"></script>
    <link rel="index" title="Index" href="../../../../genindex.html" />
    <link rel="search" title="Search" href="../../../../search.html" />
 
<script type="text/javascript">
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-33990148-1']);
  _gaq.push(['_trackPageview']);
</script>

  </head><body>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../../../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../../../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../../../index.html">pymatgen 2019.10.4 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../../../index.html" >Module code</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="../../../pymatgen.html" accesskey="U">pymatgen</a> &#187;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  <h1>Source code for pymatgen.io.abinit.events</h1><div class="highlight"><pre>
<span></span><span class="c1"># coding: utf-8</span>
<span class="c1"># Copyright (c) Pymatgen Development Team.</span>
<span class="c1"># Distributed under the terms of the MIT License.</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd">This module defines the events signaled by abinit during the execution. It also</span>
<span class="sd">provides a parser to extract these events form the main output file and the log file.</span>
<span class="sd">&quot;&quot;&quot;</span>

<span class="kn">import</span> <span class="nn">sys</span>
<span class="kn">import</span> <span class="nn">os.path</span>
<span class="kn">import</span> <span class="nn">datetime</span>
<span class="kn">import</span> <span class="nn">collections</span>
<span class="kn">import</span> <span class="nn">ruamel.yaml</span> <span class="k">as</span> <span class="nn">yaml</span>
<span class="kn">import</span> <span class="nn">abc</span>
<span class="kn">import</span> <span class="nn">logging</span>
<span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>

<span class="kn">from</span> <span class="nn">monty.string</span> <span class="k">import</span> <span class="n">indent</span><span class="p">,</span> <span class="n">is_string</span><span class="p">,</span> <span class="n">list_strings</span>
<span class="kn">from</span> <span class="nn">monty.fnmatch</span> <span class="k">import</span> <span class="n">WildCard</span>
<span class="kn">from</span> <span class="nn">monty.termcolor</span> <span class="k">import</span> <span class="n">colored</span>
<span class="kn">from</span> <span class="nn">monty.inspect</span> <span class="k">import</span> <span class="n">all_subclasses</span>
<span class="kn">from</span> <span class="nn">monty.json</span> <span class="k">import</span> <span class="n">MontyDecoder</span>
<span class="kn">from</span> <span class="nn">pymatgen.core.structure</span> <span class="k">import</span> <span class="n">Structure</span>
<span class="kn">from</span> <span class="nn">monty.json</span> <span class="k">import</span> <span class="n">MSONable</span>
<span class="kn">from</span> <span class="nn">pymatgen.util.serialization</span> <span class="k">import</span> <span class="n">pmg_serialize</span>
<span class="kn">from</span> <span class="nn">.abiinspect</span> <span class="k">import</span> <span class="n">YamlTokenizer</span>

<span class="n">logger</span> <span class="o">=</span> <span class="n">logging</span><span class="o">.</span><span class="n">getLogger</span><span class="p">(</span><span class="vm">__name__</span><span class="p">)</span>

<span class="n">__all__</span> <span class="o">=</span> <span class="p">[</span>
    <span class="s2">&quot;EventsParser&quot;</span><span class="p">,</span>
    <span class="s2">&quot;get_event_handler_classes&quot;</span><span class="p">,</span>
    <span class="s2">&quot;ScfConvergenceWarning&quot;</span><span class="p">,</span>
    <span class="s2">&quot;NscfConvergenceWarning&quot;</span><span class="p">,</span>
    <span class="s2">&quot;RelaxConvergenceWarning&quot;</span><span class="p">,</span>
    <span class="s2">&quot;Correction&quot;</span><span class="p">,</span>
    <span class="s2">&quot;DilatmxError&quot;</span><span class="p">,</span>
    <span class="s2">&quot;DilatmxErrorHandler&quot;</span><span class="p">,</span>
<span class="p">]</span>


<span class="k">def</span> <span class="nf">straceback</span><span class="p">():</span>
    <span class="sd">&quot;&quot;&quot;Returns a string with the traceback.&quot;&quot;&quot;</span>
    <span class="kn">import</span> <span class="nn">traceback</span>
    <span class="k">return</span> <span class="n">traceback</span><span class="o">.</span><span class="n">format_exc</span><span class="p">()</span>


<span class="k">class</span> <span class="nc">AbinitEvent</span><span class="p">(</span><span class="n">yaml</span><span class="o">.</span><span class="n">YAMLObject</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Example (YAML syntax)::</span>

<span class="sd">        Normal warning without any handler:</span>

<span class="sd">        --- !Warning</span>
<span class="sd">        message: |</span>
<span class="sd">            This is a normal warning that won&#39;t</span>
<span class="sd">            trigger any handler in the python code!</span>
<span class="sd">        src_file: routine_name</span>
<span class="sd">        src_line:  112</span>
<span class="sd">        ...</span>

<span class="sd">        Critical warning that will trigger some action in the python code.</span>

<span class="sd">        --- !ScfConvergeWarning</span>
<span class="sd">        message: |</span>
<span class="sd">            The human-readable message goes here!</span>
<span class="sd">        src_file: foo.F90</span>
<span class="sd">        src_line: 112</span>
<span class="sd">        tolname: tolwfr</span>
<span class="sd">        actual_tol: 1.0e-8</span>
<span class="sd">        required_tol: 1.0e-10</span>
<span class="sd">        nstep: 50</span>
<span class="sd">        ...</span>

<span class="sd">    The algorithm to extract the YAML sections is very simple.</span>

<span class="sd">    1) We use YamlTokenizer to extract the documents from the output file</span>
<span class="sd">    2) If we have a tag that ends with &quot;Warning&quot;, &quot;Error&quot;, &quot;Bug&quot;, &quot;Comment</span>
<span class="sd">       we know we have encountered a new ABINIT event</span>
<span class="sd">    3) We parse the document with yaml.safe_load(doc.text) and we get the object</span>

<span class="sd">    Note that:</span>
<span class="sd">        # --- and ... become reserved words (whey they are placed at</span>
<span class="sd">          the begining of a line) since they are used to mark the beginning and</span>
<span class="sd">          the end of YAML documents.</span>

<span class="sd">        # All the possible events should subclass `AbinitEvent` and define</span>
<span class="sd">          the class attribute yaml_tag so that yaml.safe_load will know how to</span>
<span class="sd">          build the instance.</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">color</span> <span class="o">=</span> <span class="kc">None</span>

    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">src_file</span><span class="p">,</span> <span class="n">src_line</span><span class="p">,</span> <span class="n">message</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Basic constructor for :class:`AbinitEvent`.</span>

<span class="sd">        Args:</span>
<span class="sd">            message: String with human-readable message providing info on the event.</span>
<span class="sd">            src_file: String with the name of the Fortran file where the event is raised.</span>
<span class="sd">            src_line Integer giving the line number in src_file.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="c1"># print(&quot;src_file&quot;, src_file, &quot;src_line&quot;, src_line)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">message</span> <span class="o">=</span> <span class="n">message</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">src_file</span> <span class="o">=</span> <span class="n">src_file</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">src_line</span> <span class="o">=</span> <span class="n">src_line</span>

    <span class="nd">@pmg_serialize</span>
    <span class="k">def</span> <span class="nf">as_dict</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="c1"># This is needed because the events printed in the main output file do not define scr_file and src_line</span>
        <span class="n">src_file</span> <span class="o">=</span> <span class="nb">getattr</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="s2">&quot;src_file&quot;</span><span class="p">,</span> <span class="s2">&quot;Unknown&quot;</span><span class="p">)</span>
        <span class="n">src_line</span> <span class="o">=</span> <span class="nb">getattr</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="s2">&quot;src_line&quot;</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span>
        <span class="k">return</span> <span class="nb">dict</span><span class="p">(</span><span class="n">message</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">message</span><span class="p">,</span> <span class="n">src_file</span><span class="o">=</span><span class="n">src_file</span><span class="p">,</span> <span class="n">src_line</span><span class="o">=</span><span class="n">src_line</span><span class="p">,</span> <span class="n">yaml_tag</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">yaml_tag</span><span class="p">)</span>

    <span class="nd">@classmethod</span>
    <span class="k">def</span> <span class="nf">from_dict</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">d</span><span class="p">):</span>
        <span class="bp">cls</span> <span class="o">=</span> <span class="n">as_event_class</span><span class="p">(</span><span class="n">d</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;yaml_tag&quot;</span><span class="p">))</span>
        <span class="k">return</span> <span class="bp">cls</span><span class="p">(</span><span class="o">**</span><span class="p">{</span><span class="n">k</span><span class="p">:</span> <span class="n">v</span> <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">d</span><span class="o">.</span><span class="n">items</span><span class="p">()</span> <span class="k">if</span> <span class="n">k</span> <span class="o">!=</span> <span class="s2">&quot;yaml_tag&quot;</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">k</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s2">&quot;@&quot;</span><span class="p">)})</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">header</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="k">return</span> <span class="s2">&quot;&lt;</span><span class="si">%s</span><span class="s2"> at </span><span class="si">%s</span><span class="s2">:</span><span class="si">%s</span><span class="s2">&gt;&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">src_file</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">src_line</span><span class="p">)</span>
        <span class="k">except</span> <span class="ne">AttributeError</span><span class="p">:</span>
            <span class="c1"># This is needed because the events printed in the main output file do not define scr_file and src_line</span>
            <span class="k">return</span> <span class="s2">&quot;&lt;</span><span class="si">%s</span><span class="s2"> at </span><span class="si">%s</span><span class="s2">:</span><span class="si">%s</span><span class="s2">&gt;&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="p">,</span> <span class="s2">&quot;Unknown&quot;</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">__repr__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">header</span>

    <span class="k">def</span> <span class="nf">__str__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">((</span><span class="bp">self</span><span class="o">.</span><span class="n">header</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">message</span><span class="p">))</span>

    <span class="k">def</span> <span class="nf">__eq__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">other</span><span class="p">):</span>
        <span class="k">if</span> <span class="n">other</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="k">return</span> <span class="kc">False</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">message</span> <span class="o">==</span> <span class="n">other</span><span class="o">.</span><span class="n">message</span>

    <span class="k">def</span> <span class="nf">__ne__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">other</span><span class="p">):</span>
        <span class="k">return</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="fm">__eq__</span><span class="p">(</span><span class="n">other</span><span class="p">)</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">name</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Name of the event (class name)&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__name__</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">baseclass</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;The baseclass of self.&quot;&quot;&quot;</span>
        <span class="k">for</span> <span class="bp">cls</span> <span class="ow">in</span> <span class="n">_BASE_CLASSES</span><span class="p">:</span>
            <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="bp">cls</span><span class="p">):</span>
                <span class="k">return</span> <span class="bp">cls</span>

        <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;Cannot determine the base class of </span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__name__</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">correct</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">task</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        This method is called when an error is detected in a :class:`Task`</span>
<span class="sd">        It should perform any corrective measures relating to the detected error.</span>
<span class="sd">        The idea is similar to the one used in custodian but the handler receives</span>
<span class="sd">        a :class:`Task` object so that we have access to its methods.</span>

<span class="sd">        Returns:</span>
<span class="sd">        (dict) JSON serializable dict that describes the errors and actions taken. E.g.</span>
<span class="sd">        {&quot;errors&quot;: list_of_errors, &quot;actions&quot;: list_of_actions_taken}.</span>
<span class="sd">        If this is an unfixable error, actions should be set to None.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="mi">0</span>


<span class="k">class</span> <span class="nc">AbinitComment</span><span class="p">(</span><span class="n">AbinitEvent</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Base class for Comment events&quot;&quot;&quot;</span>
    <span class="n">yaml_tag</span> <span class="o">=</span> <span class="s1">&#39;!COMMENT&#39;</span>
    <span class="n">color</span> <span class="o">=</span> <span class="s2">&quot;blue&quot;</span>


<span class="k">class</span> <span class="nc">AbinitError</span><span class="p">(</span><span class="n">AbinitEvent</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Base class for Error events&quot;&quot;&quot;</span>
    <span class="n">yaml_tag</span> <span class="o">=</span> <span class="s1">&#39;!ERROR&#39;</span>
    <span class="n">color</span> <span class="o">=</span> <span class="s2">&quot;red&quot;</span>


<span class="k">class</span> <span class="nc">AbinitYamlError</span><span class="p">(</span><span class="n">AbinitError</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Raised if the YAML parser cannot parse the document and the doc tag is an Error.</span>
<span class="sd">    It&#39;s an AbinitError because the msg produced by the code is not valid YAML!</span>
<span class="sd">    &quot;&quot;&quot;</span>


<span class="k">class</span> <span class="nc">AbinitBug</span><span class="p">(</span><span class="n">AbinitEvent</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Base class for Bug events&quot;&quot;&quot;</span>
    <span class="n">yaml_tag</span> <span class="o">=</span> <span class="s1">&#39;!BUG&#39;</span>
    <span class="n">color</span> <span class="o">=</span> <span class="s2">&quot;red&quot;</span>


<span class="k">class</span> <span class="nc">AbinitWarning</span><span class="p">(</span><span class="n">AbinitEvent</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Base class for Warning events (the most important class).</span>
<span class="sd">    Developers should subclass this class to define the different exceptions</span>
<span class="sd">    raised by the code and the possible actions that can be performed.</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">yaml_tag</span> <span class="o">=</span> <span class="s1">&#39;!WARNING&#39;</span>
    <span class="n">color</span> <span class="o">=</span> <span class="s2">&quot;magenta&quot;</span>


<span class="k">class</span> <span class="nc">AbinitCriticalWarning</span><span class="p">(</span><span class="n">AbinitWarning</span><span class="p">):</span>
    <span class="n">color</span> <span class="o">=</span> <span class="s2">&quot;red&quot;</span>


<span class="k">class</span> <span class="nc">AbinitYamlWarning</span><span class="p">(</span><span class="n">AbinitCriticalWarning</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Raised if the YAML parser cannot parse the document and the doc tas is a Warning.</span>
<span class="sd">    &quot;&quot;&quot;</span>


<span class="c1">###############################</span>
<span class="c1"># Warnings triggering restart #</span>
<span class="c1">###############################</span>

<div class="viewcode-block" id="ScfConvergenceWarning"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.events.html#pymatgen.io.abinit.events.ScfConvergenceWarning">[docs]</a><span class="k">class</span> <span class="nc">ScfConvergenceWarning</span><span class="p">(</span><span class="n">AbinitCriticalWarning</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Warning raised when the GS SCF cycle did not converge.&quot;&quot;&quot;</span>
    <span class="n">yaml_tag</span> <span class="o">=</span> <span class="s1">&#39;!ScfConvergenceWarning&#39;</span></div>


<div class="viewcode-block" id="NscfConvergenceWarning"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.events.html#pymatgen.io.abinit.events.NscfConvergenceWarning">[docs]</a><span class="k">class</span> <span class="nc">NscfConvergenceWarning</span><span class="p">(</span><span class="n">AbinitCriticalWarning</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Warning raised when the GS NSCF cycle did not converge.&quot;&quot;&quot;</span>
    <span class="n">yaml_tag</span> <span class="o">=</span> <span class="s1">&#39;!NscfConvergenceWarning&#39;</span></div>


<div class="viewcode-block" id="RelaxConvergenceWarning"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.events.html#pymatgen.io.abinit.events.RelaxConvergenceWarning">[docs]</a><span class="k">class</span> <span class="nc">RelaxConvergenceWarning</span><span class="p">(</span><span class="n">AbinitCriticalWarning</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Warning raised when the structural relaxation did not converge.&quot;&quot;&quot;</span>
    <span class="n">yaml_tag</span> <span class="o">=</span> <span class="s1">&#39;!RelaxConvergenceWarning&#39;</span></div>


<span class="c1"># TODO: for the time being we don&#39;t discern between GS and PhononCalculations.</span>
<span class="c1"># class PhononConvergenceWarning(AbinitCriticalWarning):</span>
<span class="c1">#    &quot;&quot;&quot;Warning raised when the phonon calculation did not converge.&quot;&quot;&quot;</span>
<span class="c1">#    yaml_tag = u&#39;!PhononConvergenceWarning&#39;</span>


<span class="k">class</span> <span class="nc">QPSConvergenceWarning</span><span class="p">(</span><span class="n">AbinitCriticalWarning</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Warning raised when the QPS iteration (GW) did not converge.&quot;&quot;&quot;</span>
    <span class="n">yaml_tag</span> <span class="o">=</span> <span class="s1">&#39;!QPSConvergenceWarning&#39;</span>


<span class="k">class</span> <span class="nc">HaydockConvergenceWarning</span><span class="p">(</span><span class="n">AbinitCriticalWarning</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Warning raised when the Haydock method (BSE) did not converge.&quot;&quot;&quot;</span>
    <span class="n">yaml_tag</span> <span class="o">=</span> <span class="s1">&#39;!HaydockConvergenceWarning&#39;</span>


<span class="c1"># Error classes providing a correct method.</span>

<span class="c1"># Register the concrete base classes.</span>
<span class="n">_BASE_CLASSES</span> <span class="o">=</span> <span class="p">[</span>
    <span class="n">AbinitComment</span><span class="p">,</span>
    <span class="n">AbinitError</span><span class="p">,</span>
    <span class="n">AbinitBug</span><span class="p">,</span>
    <span class="n">AbinitWarning</span><span class="p">,</span>
<span class="p">]</span>


<span class="k">class</span> <span class="nc">EventReport</span><span class="p">(</span><span class="n">collections</span><span class="o">.</span><span class="n">abc</span><span class="o">.</span><span class="n">Iterable</span><span class="p">,</span> <span class="n">MSONable</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Iterable storing the events raised by an ABINIT calculation.</span>

<span class="sd">    Attributes::</span>

<span class="sd">        stat: information about a file as returned by os.stat</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">filename</span><span class="p">,</span> <span class="n">events</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        List of ABINIT events.</span>

<span class="sd">        Args:</span>
<span class="sd">            filename: Name of the file</span>
<span class="sd">            events: List of Event objects</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">filename</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">abspath</span><span class="p">(</span><span class="n">filename</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">stat</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">stat</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">filename</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">start_datetime</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">end_datetime</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span> <span class="kc">None</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">_events</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_events_by_baseclass</span> <span class="o">=</span> <span class="n">collections</span><span class="o">.</span><span class="n">defaultdict</span><span class="p">(</span><span class="nb">list</span><span class="p">)</span>

        <span class="k">if</span> <span class="n">events</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
            <span class="k">for</span> <span class="n">ev</span> <span class="ow">in</span> <span class="n">events</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">ev</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">__len__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_events</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">__iter__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_events</span><span class="o">.</span><span class="fm">__iter__</span><span class="p">()</span>

    <span class="k">def</span> <span class="nf">__getitem__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="nb">slice</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_events</span><span class="p">[</span><span class="nb">slice</span><span class="p">]</span>

    <span class="k">def</span> <span class="nf">__str__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="c1"># has_colours = stream_has_colours(stream)</span>
        <span class="n">has_colours</span> <span class="o">=</span> <span class="kc">True</span>

        <span class="n">lines</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="n">app</span> <span class="o">=</span> <span class="n">lines</span><span class="o">.</span><span class="n">append</span>

        <span class="n">app</span><span class="p">(</span><span class="s2">&quot;Events found in </span><span class="si">%s</span><span class="se">\n</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="bp">self</span><span class="o">.</span><span class="n">filename</span><span class="p">)</span>
        <span class="k">for</span> <span class="n">i</span><span class="p">,</span> <span class="n">event</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
            <span class="k">if</span> <span class="n">has_colours</span><span class="p">:</span>
                <span class="n">app</span><span class="p">(</span><span class="s2">&quot;[</span><span class="si">%d</span><span class="s2">] </span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">i</span> <span class="o">+</span> <span class="mi">1</span><span class="p">,</span> <span class="n">colored</span><span class="p">(</span><span class="n">event</span><span class="o">.</span><span class="n">header</span><span class="p">,</span> <span class="n">color</span><span class="o">=</span><span class="n">event</span><span class="o">.</span><span class="n">color</span><span class="p">)))</span>
                <span class="n">app</span><span class="p">(</span><span class="n">indent</span><span class="p">(</span><span class="n">event</span><span class="o">.</span><span class="n">message</span><span class="p">,</span> <span class="mi">4</span><span class="p">))</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">app</span><span class="p">(</span><span class="s2">&quot;[</span><span class="si">%d</span><span class="s2">] </span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">i</span> <span class="o">+</span> <span class="mi">1</span><span class="p">,</span> <span class="nb">str</span><span class="p">(</span><span class="n">event</span><span class="p">)))</span>

        <span class="n">app</span><span class="p">(</span><span class="s2">&quot;num_errors: </span><span class="si">%s</span><span class="s2">, num_warnings: </span><span class="si">%s</span><span class="s2">, num_comments: </span><span class="si">%s</span><span class="s2">, completed: </span><span class="si">%s</span><span class="se">\n</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="p">(</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">num_errors</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">num_warnings</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">num_comments</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">run_completed</span><span class="p">))</span>

        <span class="k">return</span> <span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">lines</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">append</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">event</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Add an event to the list.&quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_events</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">event</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_events_by_baseclass</span><span class="p">[</span><span class="n">event</span><span class="o">.</span><span class="n">baseclass</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">event</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">set_run_completed</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">boolean</span><span class="p">,</span> <span class="n">start_datetime</span><span class="p">,</span> <span class="n">end_datetime</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Set the value of _run_completed.&quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_run_completed</span> <span class="o">=</span> <span class="n">boolean</span>

        <span class="k">if</span> <span class="p">(</span><span class="n">start_datetime</span><span class="p">,</span> <span class="n">end_datetime</span><span class="p">)</span> <span class="o">!=</span> <span class="p">(</span><span class="kc">None</span><span class="p">,</span> <span class="kc">None</span><span class="p">):</span>
            <span class="c1"># start_datetime: Sat Feb 28 23:54:27 2015</span>
            <span class="c1"># end_datetime: Sat Feb 28 23:54:30 2015</span>
            <span class="k">try</span><span class="p">:</span>
                <span class="n">fmt</span> <span class="o">=</span> <span class="s2">&quot;</span><span class="si">%a</span><span class="s2"> %b </span><span class="si">%d</span><span class="s2"> %H:%M:%S %Y&quot;</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">start_datetime</span> <span class="o">=</span> <span class="n">datetime</span><span class="o">.</span><span class="n">datetime</span><span class="o">.</span><span class="n">strptime</span><span class="p">(</span><span class="n">start_datetime</span><span class="p">,</span> <span class="n">fmt</span><span class="p">)</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">end_datetime</span> <span class="o">=</span> <span class="n">datetime</span><span class="o">.</span><span class="n">datetime</span><span class="o">.</span><span class="n">strptime</span><span class="p">(</span><span class="n">end_datetime</span><span class="p">,</span> <span class="n">fmt</span><span class="p">)</span>
            <span class="k">except</span> <span class="ne">Exception</span> <span class="k">as</span> <span class="n">exc</span><span class="p">:</span>
                <span class="c1"># Maybe LOCALE != en_US</span>
                <span class="n">logger</span><span class="o">.</span><span class="n">warning</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">exc</span><span class="p">))</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">run_etime</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Wall-time of the run as `timedelta` object.&quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">start_datetime</span> <span class="ow">is</span> <span class="kc">None</span> <span class="ow">or</span> <span class="bp">self</span><span class="o">.</span><span class="n">end_datetime</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="k">return</span> <span class="kc">None</span>

        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">end_datetime</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">start_datetime</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">run_completed</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;True if the calculation terminated.&quot;&quot;&quot;</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_run_completed</span>
        <span class="k">except</span> <span class="ne">AttributeError</span><span class="p">:</span>
            <span class="k">return</span> <span class="kc">False</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">comments</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;List of comments found.&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">select</span><span class="p">(</span><span class="n">AbinitComment</span><span class="p">)</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">errors</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;List of errors + bugs found.&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">select</span><span class="p">(</span><span class="n">AbinitError</span><span class="p">)</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">select</span><span class="p">(</span><span class="n">AbinitBug</span><span class="p">)</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">warnings</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;List of warnings found.&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">select</span><span class="p">(</span><span class="n">AbinitWarning</span><span class="p">)</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">num_warnings</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Number of warnings reported.&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">warnings</span><span class="p">)</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">num_errors</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Number of errors reported.&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">errors</span><span class="p">)</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">num_comments</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Number of comments reported.&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">comments</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">select</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">base_class</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Return the list of events that inherits from class base_class</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_events_by_baseclass</span><span class="p">[</span><span class="n">base_class</span><span class="p">]</span>

    <span class="k">def</span> <span class="nf">filter_types</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">event_types</span><span class="p">):</span>
        <span class="n">events</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">for</span> <span class="n">ev</span> <span class="ow">in</span> <span class="bp">self</span><span class="p">:</span>
            <span class="k">if</span> <span class="nb">type</span><span class="p">(</span><span class="n">ev</span><span class="p">)</span> <span class="ow">in</span> <span class="n">event_types</span><span class="p">:</span>
                <span class="n">events</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">ev</span><span class="p">)</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="p">(</span><span class="n">filename</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">filename</span><span class="p">,</span> <span class="n">events</span><span class="o">=</span><span class="n">events</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">get_events_of_type</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">event_class</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Return a list of events of the given class.&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="p">[</span><span class="n">ev</span> <span class="k">for</span> <span class="n">ev</span> <span class="ow">in</span> <span class="bp">self</span> <span class="k">if</span> <span class="nb">type</span><span class="p">(</span><span class="n">ev</span><span class="p">)</span> <span class="o">==</span> <span class="n">event_class</span><span class="p">]</span>

    <span class="nd">@pmg_serialize</span>
    <span class="k">def</span> <span class="nf">as_dict</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="nb">dict</span><span class="p">(</span><span class="n">filename</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">filename</span><span class="p">,</span> <span class="n">events</span><span class="o">=</span><span class="p">[</span><span class="n">e</span><span class="o">.</span><span class="n">as_dict</span><span class="p">()</span> <span class="k">for</span> <span class="n">e</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">_events</span><span class="p">])</span>

    <span class="nd">@classmethod</span>
    <span class="k">def</span> <span class="nf">from_dict</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">d</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">cls</span><span class="p">(</span><span class="n">filename</span><span class="o">=</span><span class="n">d</span><span class="p">[</span><span class="s2">&quot;filename&quot;</span><span class="p">],</span> <span class="n">events</span><span class="o">=</span><span class="p">[</span><span class="n">AbinitEvent</span><span class="o">.</span><span class="n">from_dict</span><span class="p">(</span><span class="n">e</span><span class="p">)</span> <span class="k">for</span> <span class="n">e</span> <span class="ow">in</span> <span class="n">d</span><span class="p">[</span><span class="s2">&quot;events&quot;</span><span class="p">]])</span>


<span class="k">class</span> <span class="nc">EventsParserError</span><span class="p">(</span><span class="ne">Exception</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Base class for the exceptions raised by :class:`EventsParser`.&quot;&quot;&quot;</span>


<div class="viewcode-block" id="EventsParser"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.events.html#pymatgen.io.abinit.events.EventsParser">[docs]</a><span class="k">class</span> <span class="nc">EventsParser</span><span class="p">:</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Parses the output or the log file produced by ABINIT and extract the list of events.</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">Error</span> <span class="o">=</span> <span class="n">EventsParserError</span>

<div class="viewcode-block" id="EventsParser.parse"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.events.html#pymatgen.io.abinit.events.EventsParser.parse">[docs]</a>    <span class="k">def</span> <span class="nf">parse</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">filename</span><span class="p">,</span> <span class="n">verbose</span><span class="o">=</span><span class="mi">0</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Parse the given file. Return :class:`EventReport`.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">run_completed</span><span class="p">,</span> <span class="n">start_datetime</span><span class="p">,</span> <span class="n">end_datetime</span> <span class="o">=</span> <span class="kc">False</span><span class="p">,</span> <span class="kc">None</span><span class="p">,</span> <span class="kc">None</span>
        <span class="n">filename</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">abspath</span><span class="p">(</span><span class="n">filename</span><span class="p">)</span>
        <span class="n">report</span> <span class="o">=</span> <span class="n">EventReport</span><span class="p">(</span><span class="n">filename</span><span class="p">)</span>

        <span class="n">w</span> <span class="o">=</span> <span class="n">WildCard</span><span class="p">(</span><span class="s2">&quot;*Error|*Warning|*Comment|*Bug|*ERROR|*WARNING|*COMMENT|*BUG&quot;</span><span class="p">)</span>
        <span class="kn">import</span> <span class="nn">warnings</span>
        <span class="n">warnings</span><span class="o">.</span><span class="n">simplefilter</span><span class="p">(</span><span class="s1">&#39;ignore&#39;</span><span class="p">,</span> <span class="n">yaml</span><span class="o">.</span><span class="n">error</span><span class="o">.</span><span class="n">UnsafeLoaderWarning</span><span class="p">)</span>
        <span class="k">with</span> <span class="n">YamlTokenizer</span><span class="p">(</span><span class="n">filename</span><span class="p">)</span> <span class="k">as</span> <span class="n">tokens</span><span class="p">:</span>
            <span class="k">for</span> <span class="n">doc</span> <span class="ow">in</span> <span class="n">tokens</span><span class="p">:</span>
                <span class="k">if</span> <span class="n">w</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="n">doc</span><span class="o">.</span><span class="n">tag</span><span class="p">):</span>
                    <span class="c1"># print(&quot;got doc.tag&quot;, doc.tag,&quot;--&quot;)</span>
                    <span class="k">try</span><span class="p">:</span>
                        <span class="c1"># print(doc.text)</span>
                        <span class="n">event</span> <span class="o">=</span> <span class="n">yaml</span><span class="o">.</span><span class="n">load</span><span class="p">(</span><span class="n">doc</span><span class="o">.</span><span class="n">text</span><span class="p">)</span>  <span class="c1"># Can&#39;t use ruamel safe_load!</span>
                        <span class="c1"># yaml.load(doc.text, Loader=ruamel.yaml.Loader)</span>
                        <span class="c1"># print(event.yaml_tag, type(event))</span>
                    <span class="k">except</span> <span class="ne">Exception</span><span class="p">:</span>
                        <span class="c1"># raise</span>
                        <span class="c1"># Wrong YAML doc. Check tha doc tag and instantiate the proper event.</span>
                        <span class="n">message</span> <span class="o">=</span> <span class="s2">&quot;Malformatted YAML document at line: </span><span class="si">%d</span><span class="se">\n</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="n">doc</span><span class="o">.</span><span class="n">lineno</span>
                        <span class="n">message</span> <span class="o">+=</span> <span class="n">doc</span><span class="o">.</span><span class="n">text</span>

                        <span class="c1"># This call is very expensive when we have many exceptions due to malformatted YAML docs.</span>
                        <span class="k">if</span> <span class="n">verbose</span><span class="p">:</span>
                            <span class="n">message</span> <span class="o">+=</span> <span class="s2">&quot;Traceback:</span><span class="se">\n</span><span class="s2"> </span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="n">straceback</span><span class="p">()</span>

                        <span class="k">if</span> <span class="s2">&quot;error&quot;</span> <span class="ow">in</span> <span class="n">doc</span><span class="o">.</span><span class="n">tag</span><span class="o">.</span><span class="n">lower</span><span class="p">():</span>
                            <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;It seems an error. doc.tag:&quot;</span><span class="p">,</span> <span class="n">doc</span><span class="o">.</span><span class="n">tag</span><span class="p">)</span>
                            <span class="n">event</span> <span class="o">=</span> <span class="n">AbinitYamlError</span><span class="p">(</span><span class="n">message</span><span class="o">=</span><span class="n">message</span><span class="p">,</span> <span class="n">src_file</span><span class="o">=</span><span class="vm">__file__</span><span class="p">,</span> <span class="n">src_line</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
                        <span class="k">else</span><span class="p">:</span>
                            <span class="n">event</span> <span class="o">=</span> <span class="n">AbinitYamlWarning</span><span class="p">(</span><span class="n">message</span><span class="o">=</span><span class="n">message</span><span class="p">,</span> <span class="n">src_file</span><span class="o">=</span><span class="vm">__file__</span><span class="p">,</span> <span class="n">src_line</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>

                    <span class="n">event</span><span class="o">.</span><span class="n">lineno</span> <span class="o">=</span> <span class="n">doc</span><span class="o">.</span><span class="n">lineno</span>
                    <span class="n">report</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">event</span><span class="p">)</span>

                <span class="c1"># Check whether the calculation completed.</span>
                <span class="k">if</span> <span class="n">doc</span><span class="o">.</span><span class="n">tag</span> <span class="o">==</span> <span class="s2">&quot;!FinalSummary&quot;</span><span class="p">:</span>
                    <span class="c1"># print(doc)</span>
                    <span class="n">run_completed</span> <span class="o">=</span> <span class="kc">True</span>
                    <span class="n">d</span> <span class="o">=</span> <span class="n">doc</span><span class="o">.</span><span class="n">as_dict</span><span class="p">()</span>
                    <span class="c1"># print(d)</span>
                    <span class="n">start_datetime</span><span class="p">,</span> <span class="n">end_datetime</span> <span class="o">=</span> <span class="n">d</span><span class="p">[</span><span class="s2">&quot;start_datetime&quot;</span><span class="p">],</span> <span class="n">d</span><span class="p">[</span><span class="s2">&quot;end_datetime&quot;</span><span class="p">]</span>

        <span class="n">report</span><span class="o">.</span><span class="n">set_run_completed</span><span class="p">(</span><span class="n">run_completed</span><span class="p">,</span> <span class="n">start_datetime</span><span class="p">,</span> <span class="n">end_datetime</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">report</span></div>

<div class="viewcode-block" id="EventsParser.report_exception"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.events.html#pymatgen.io.abinit.events.EventsParser.report_exception">[docs]</a>    <span class="k">def</span> <span class="nf">report_exception</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">filename</span><span class="p">,</span> <span class="n">exc</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        This method is used when self.parser raises an Exception so that</span>
<span class="sd">        we can report a customized :class:`EventReport` object with info the exception.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="c1"># Build fake event.</span>
        <span class="n">event</span> <span class="o">=</span> <span class="n">AbinitError</span><span class="p">(</span><span class="n">src_file</span><span class="o">=</span><span class="s2">&quot;Unknown&quot;</span><span class="p">,</span> <span class="n">src_line</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">message</span><span class="o">=</span><span class="nb">str</span><span class="p">(</span><span class="n">exc</span><span class="p">))</span>
        <span class="k">return</span> <span class="n">EventReport</span><span class="p">(</span><span class="n">filename</span><span class="p">,</span> <span class="n">events</span><span class="o">=</span><span class="p">[</span><span class="n">event</span><span class="p">])</span></div></div>


<span class="k">class</span> <span class="nc">EventHandler</span><span class="p">(</span><span class="n">MSONable</span><span class="p">,</span> <span class="n">metaclass</span><span class="o">=</span><span class="n">abc</span><span class="o">.</span><span class="n">ABCMeta</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Abstract base class defining the interface for an EventHandler.</span>

<span class="sd">    The__init__ should always provide default values for its arguments so that we can</span>
<span class="sd">    easily instantiate the handlers with:</span>

<span class="sd">        handlers = [cls() for cls in get_event_handler_classes()]</span>

<span class="sd">    The defaul values should be chosen so to cover the most typical cases.</span>

<span class="sd">    Each EventHandler should define the class attribute `can_change_physics`</span>
<span class="sd">    that is true if the handler changes `important` parameters of the</span>
<span class="sd">    run that are tightly connected to the physics of the system.</span>

<span class="sd">    For example, an `EventHandler` that changes the value of `dilatmx` and</span>
<span class="sd">    prepare the restart is not changing the physics. Similarly a handler</span>
<span class="sd">    that changes the mixing algorithm. On the contrary, a handler that</span>
<span class="sd">    changes the value of the smearing is modifying an important physical</span>
<span class="sd">    parameter, and the user should be made aware of this so that</span>
<span class="sd">    there&#39;s an explicit agreement between the user and the code.</span>

<span class="sd">    The default handlers are those that do not change the physics,</span>
<span class="sd">    other handlers can be installed by the user when constructing with the flow with</span>

<span class="sd">        TODO</span>

<span class="sd">    .. warning::</span>

<span class="sd">        The EventHandler should perform any action at the level of the input files</span>
<span class="sd">        needed to solve the problem and then prepare the task for a new submission</span>
<span class="sd">        The handler should never try to resubmit the task. The submission must be</span>
<span class="sd">        delegated to the scheduler or Fireworks.</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="n">event_class</span> <span class="o">=</span> <span class="n">AbinitEvent</span>
    <span class="sd">&quot;&quot;&quot;AbinitEvent subclass associated to this handler.&quot;&quot;&quot;</span>

    <span class="c1"># can_change_physics</span>

    <span class="n">FIXED</span> <span class="o">=</span> <span class="mi">1</span>
    <span class="n">NOT_FIXED</span> <span class="o">=</span> <span class="mi">0</span>

    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Simple init for compatibility with introspection in as_dict/from_dict&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__init__</span><span class="p">()</span>

    <span class="nd">@classmethod</span>
    <span class="k">def</span> <span class="nf">cls2str</span><span class="p">(</span><span class="bp">cls</span><span class="p">):</span>
        <span class="n">lines</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="n">app</span> <span class="o">=</span> <span class="n">lines</span><span class="o">.</span><span class="n">append</span>

        <span class="n">ecls</span> <span class="o">=</span> <span class="bp">cls</span><span class="o">.</span><span class="n">event_class</span>
        <span class="n">app</span><span class="p">(</span><span class="s2">&quot;event name = </span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="n">ecls</span><span class="o">.</span><span class="n">yaml_tag</span><span class="p">)</span>
        <span class="n">app</span><span class="p">(</span><span class="s2">&quot;event documentation: &quot;</span><span class="p">)</span>
        <span class="n">lines</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span><span class="n">ecls</span><span class="o">.</span><span class="vm">__doc__</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span><span class="p">))</span>
        <span class="n">app</span><span class="p">(</span><span class="s2">&quot;handler documentation: &quot;</span><span class="p">)</span>
        <span class="n">lines</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span><span class="bp">cls</span><span class="o">.</span><span class="vm">__doc__</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span><span class="p">))</span>

        <span class="k">return</span> <span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">lines</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">__str__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="s2">&quot;&lt;</span><span class="si">%s</span><span class="s2">&gt;&quot;</span> <span class="o">%</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__name__</span>

    <span class="k">def</span> <span class="nf">can_handle</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">event</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;True if this handler is associated to the given :class:`AbinitEvent`&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">event_class</span> <span class="o">==</span> <span class="n">event</span><span class="o">.</span><span class="vm">__class__</span>

    <span class="c1"># TODO: defined CorrectionRecord object and provide helper functions to build it</span>

    <span class="k">def</span> <span class="nf">count</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">task</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Return the number of times the event associated to this handler</span>
<span class="sd">        has been already fixed in the :class:`Task`.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="nb">len</span><span class="p">([</span><span class="n">c</span> <span class="k">for</span> <span class="n">c</span> <span class="ow">in</span> <span class="n">task</span><span class="o">.</span><span class="n">corrections</span> <span class="k">if</span> <span class="n">c</span><span class="p">[</span><span class="s2">&quot;event&quot;</span><span class="p">][</span><span class="s2">&quot;@class&quot;</span><span class="p">]</span> <span class="o">==</span> <span class="bp">self</span><span class="o">.</span><span class="n">event_class</span><span class="p">])</span>

    <span class="nd">@abc</span><span class="o">.</span><span class="n">abstractmethod</span>
    <span class="k">def</span> <span class="nf">handle_task_event</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">task</span><span class="p">,</span> <span class="n">event</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Method to handle Abinit events.</span>

<span class="sd">        Args:</span>
<span class="sd">            task: :class:`Task` object.</span>
<span class="sd">            event: :class:`AbinitEvent` found in the log file.</span>

<span class="sd">        Return:</span>
<span class="sd">            0 if no action has been applied, 1 if the problem has been fixed.</span>
<span class="sd">        &quot;&quot;&quot;</span>

    <span class="nd">@pmg_serialize</span>
    <span class="k">def</span> <span class="nf">as_dict</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Basic implementation of as_dict if __init__ has no arguments. Subclasses may need to overwrite.</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="n">d</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="k">return</span> <span class="n">d</span>

    <span class="nd">@classmethod</span>
    <span class="k">def</span> <span class="nf">from_dict</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">d</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Basic implementation of from_dict if __init__ has no arguments. Subclasses may need to overwrite.</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="k">return</span> <span class="bp">cls</span><span class="p">()</span>

    <span class="nd">@classmethod</span>
    <span class="k">def</span> <span class="nf">compare_inputs</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">new_input</span><span class="p">,</span> <span class="n">old_input</span><span class="p">):</span>

        <span class="k">def</span> <span class="nf">vars_dict</span><span class="p">(</span><span class="n">d</span><span class="p">):</span>
            <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">            make a simple dictionary and convert numpy arrays to lists</span>
<span class="sd">            &quot;&quot;&quot;</span>
            <span class="n">new_d</span> <span class="o">=</span> <span class="p">{}</span>
            <span class="k">for</span> <span class="n">key</span><span class="p">,</span> <span class="n">value</span> <span class="ow">in</span> <span class="n">d</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
                <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">value</span><span class="p">,</span> <span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">):</span>
                    <span class="n">value</span> <span class="o">=</span> <span class="n">value</span><span class="o">.</span><span class="n">tolist</span><span class="p">()</span>
                <span class="n">new_d</span><span class="p">[</span><span class="n">key</span><span class="p">]</span> <span class="o">=</span> <span class="n">value</span>

            <span class="k">return</span> <span class="n">new_d</span>

        <span class="n">new_vars</span> <span class="o">=</span> <span class="n">vars_dict</span><span class="p">(</span><span class="n">new_input</span><span class="p">)</span>
        <span class="n">old_vars</span> <span class="o">=</span> <span class="n">vars_dict</span><span class="p">(</span><span class="n">old_input</span><span class="p">)</span>

        <span class="n">new_keys</span> <span class="o">=</span> <span class="nb">set</span><span class="p">(</span><span class="n">new_vars</span><span class="o">.</span><span class="n">keys</span><span class="p">())</span>
        <span class="n">old_keys</span> <span class="o">=</span> <span class="nb">set</span><span class="p">(</span><span class="n">old_vars</span><span class="o">.</span><span class="n">keys</span><span class="p">())</span>
        <span class="n">intersect</span> <span class="o">=</span> <span class="n">new_keys</span><span class="o">.</span><span class="n">intersection</span><span class="p">(</span><span class="n">old_keys</span><span class="p">)</span>

        <span class="n">added_keys</span> <span class="o">=</span> <span class="n">new_keys</span> <span class="o">-</span> <span class="n">intersect</span>
        <span class="n">removed_keys</span> <span class="o">=</span> <span class="n">old_keys</span> <span class="o">-</span> <span class="n">intersect</span>
        <span class="n">changed_keys</span> <span class="o">=</span> <span class="nb">set</span><span class="p">(</span><span class="n">v</span> <span class="k">for</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">intersect</span> <span class="k">if</span> <span class="n">new_vars</span><span class="p">[</span><span class="n">v</span><span class="p">]</span> <span class="o">!=</span> <span class="n">old_vars</span><span class="p">[</span><span class="n">v</span><span class="p">])</span>

        <span class="n">log_diff</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="k">if</span> <span class="n">added_keys</span><span class="p">:</span>
            <span class="n">log_diff</span><span class="p">[</span><span class="s1">&#39;_set&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span><span class="n">k</span><span class="p">:</span> <span class="n">new_vars</span><span class="p">[</span><span class="n">k</span><span class="p">]</span> <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">added_keys</span><span class="p">}</span>

        <span class="k">if</span> <span class="n">changed_keys</span><span class="p">:</span>
            <span class="n">log_diff</span><span class="p">[</span><span class="s1">&#39;_update&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="p">({</span><span class="n">k</span><span class="p">:</span> <span class="p">{</span><span class="s1">&#39;new&#39;</span><span class="p">:</span> <span class="n">new_vars</span><span class="p">[</span><span class="n">k</span><span class="p">],</span> <span class="s1">&#39;old&#39;</span><span class="p">:</span> <span class="n">old_vars</span><span class="p">[</span><span class="n">k</span><span class="p">]}</span> <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">changed_keys</span><span class="p">})</span>

        <span class="k">if</span> <span class="n">new_input</span><span class="o">.</span><span class="n">structure</span> <span class="o">!=</span> <span class="n">old_input</span><span class="o">.</span><span class="n">structure</span><span class="p">:</span>
            <span class="n">log_diff</span><span class="p">[</span><span class="s1">&#39;_change_structure&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">new_input</span><span class="o">.</span><span class="n">structure</span><span class="o">.</span><span class="n">as_dict</span><span class="p">()</span>

        <span class="k">if</span> <span class="n">removed_keys</span><span class="p">:</span>
            <span class="n">log_diff</span><span class="p">[</span><span class="s1">&#39;_pop&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span><span class="n">k</span><span class="p">:</span> <span class="n">old_vars</span><span class="p">[</span><span class="n">k</span><span class="p">]</span> <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">removed_keys</span><span class="p">}</span>

        <span class="k">return</span> <span class="n">log_diff</span>


<div class="viewcode-block" id="Correction"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.events.html#pymatgen.io.abinit.events.Correction">[docs]</a><span class="k">class</span> <span class="nc">Correction</span><span class="p">(</span><span class="n">MSONable</span><span class="p">):</span>

    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">handler</span><span class="p">,</span> <span class="n">actions</span><span class="p">,</span> <span class="n">event</span><span class="p">,</span> <span class="n">reset</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">handler</span> <span class="o">=</span> <span class="n">handler</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">actions</span> <span class="o">=</span> <span class="n">actions</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">event</span> <span class="o">=</span> <span class="n">event</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">reset</span> <span class="o">=</span> <span class="n">reset</span>

<div class="viewcode-block" id="Correction.as_dict"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.events.html#pymatgen.io.abinit.events.Correction.as_dict">[docs]</a>    <span class="nd">@pmg_serialize</span>
    <span class="k">def</span> <span class="nf">as_dict</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="nb">dict</span><span class="p">(</span><span class="n">handler</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">handler</span><span class="o">.</span><span class="n">as_dict</span><span class="p">(),</span> <span class="n">actions</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">actions</span><span class="p">,</span> <span class="n">event</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">event</span><span class="o">.</span><span class="n">as_dict</span><span class="p">(),</span> <span class="n">reset</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">reset</span><span class="p">)</span></div>

<div class="viewcode-block" id="Correction.from_dict"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.events.html#pymatgen.io.abinit.events.Correction.from_dict">[docs]</a>    <span class="nd">@classmethod</span>
    <span class="k">def</span> <span class="nf">from_dict</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">d</span><span class="p">):</span>
        <span class="n">dec</span> <span class="o">=</span> <span class="n">MontyDecoder</span><span class="p">()</span>
        <span class="k">return</span> <span class="bp">cls</span><span class="p">(</span><span class="n">handler</span><span class="o">=</span><span class="n">dec</span><span class="o">.</span><span class="n">process_decoded</span><span class="p">(</span><span class="n">d</span><span class="p">[</span><span class="s1">&#39;handler&#39;</span><span class="p">]),</span> <span class="n">actions</span><span class="o">=</span><span class="n">d</span><span class="p">[</span><span class="s1">&#39;actions&#39;</span><span class="p">],</span>
                   <span class="n">event</span><span class="o">=</span><span class="n">dec</span><span class="o">.</span><span class="n">process_decoded</span><span class="p">(</span><span class="n">d</span><span class="p">[</span><span class="s1">&#39;event&#39;</span><span class="p">]),</span> <span class="n">reset</span><span class="o">=</span><span class="n">d</span><span class="p">[</span><span class="s1">&#39;reset&#39;</span><span class="p">])</span></div></div>


<span class="c1"># class WarningHandler(EventHandler):</span>
<span class="c1">#    &quot;&quot;&quot;Base class for handlers associated to ABINIT warnings.&quot;&quot;&quot;</span>
<span class="c1">#    event_class = AbinitWarning</span>
<span class="c1">#</span>
<span class="c1"># class BugHandler(EventHandler):</span>
<span class="c1">#    &quot;&quot;&quot;Base class for handlers associated to ABINIT bugs.&quot;&quot;&quot;</span>
<span class="c1">#    event_class = AbinitBug</span>


<span class="k">class</span> <span class="nc">ErrorHandler</span><span class="p">(</span><span class="n">EventHandler</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Base class for handlers associated to ABINIT errors.&quot;&quot;&quot;</span>
    <span class="n">event_class</span> <span class="o">=</span> <span class="n">AbinitError</span>


<span class="n">_ABC_EVHANDLER_CLASSES</span> <span class="o">=</span> <span class="nb">set</span><span class="p">([</span><span class="n">ErrorHandler</span><span class="p">,</span> <span class="p">])</span>


<span class="c1"># Public API</span>
<span class="k">def</span> <span class="nf">autodoc_event_handlers</span><span class="p">(</span><span class="n">stream</span><span class="o">=</span><span class="n">sys</span><span class="o">.</span><span class="n">stdout</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Print to the given string, the documentation for the events</span>
<span class="sd">    and the associated handlers.</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">lines</span> <span class="o">=</span> <span class="p">[]</span>
    <span class="k">for</span> <span class="bp">cls</span> <span class="ow">in</span> <span class="n">all_subclasses</span><span class="p">(</span><span class="n">EventHandler</span><span class="p">):</span>
        <span class="k">if</span> <span class="bp">cls</span> <span class="ow">in</span> <span class="n">_ABC_EVHANDLER_CLASSES</span><span class="p">:</span>
            <span class="k">continue</span>
        <span class="n">event_class</span> <span class="o">=</span> <span class="bp">cls</span><span class="o">.</span><span class="n">event_class</span>
        <span class="n">lines</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span><span class="bp">cls</span><span class="o">.</span><span class="n">cls2str</span><span class="p">()</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span><span class="p">))</span>

        <span class="c1"># Here we enforce the abstract protocol of the class</span>
        <span class="c1"># The unit test in tests_events will detect the problem.</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="nb">hasattr</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="s2">&quot;can_change_physics&quot;</span><span class="p">):</span>
            <span class="k">raise</span> <span class="ne">RuntimeError</span><span class="p">(</span><span class="s2">&quot;</span><span class="si">%s</span><span class="s2">: can_change_physics must be defined&quot;</span> <span class="o">%</span> <span class="bp">cls</span><span class="p">)</span>

    <span class="n">stream</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">lines</span><span class="p">)</span> <span class="o">+</span> <span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span><span class="p">)</span>


<div class="viewcode-block" id="get_event_handler_classes"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.events.html#pymatgen.io.abinit.events.get_event_handler_classes">[docs]</a><span class="k">def</span> <span class="nf">get_event_handler_classes</span><span class="p">(</span><span class="n">categories</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Return the list of handler classes.&quot;&quot;&quot;</span>
    <span class="n">classes</span> <span class="o">=</span> <span class="p">[</span><span class="n">c</span> <span class="k">for</span> <span class="n">c</span> <span class="ow">in</span> <span class="n">all_subclasses</span><span class="p">(</span><span class="n">EventHandler</span><span class="p">)</span> <span class="k">if</span> <span class="n">c</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">_ABC_EVHANDLER_CLASSES</span><span class="p">]</span>
    <span class="k">return</span> <span class="n">classes</span></div>


<span class="k">def</span> <span class="nf">as_event_class</span><span class="p">(</span><span class="n">obj</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Convert obj into a subclass of AbinitEvent.</span>
<span class="sd">    obj can be either a class or a string with the class name or the YAML tag</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">if</span> <span class="n">is_string</span><span class="p">(</span><span class="n">obj</span><span class="p">):</span>
        <span class="k">for</span> <span class="n">c</span> <span class="ow">in</span> <span class="n">all_subclasses</span><span class="p">(</span><span class="n">AbinitEvent</span><span class="p">):</span>
            <span class="k">if</span> <span class="n">c</span><span class="o">.</span><span class="vm">__name__</span> <span class="o">==</span> <span class="n">obj</span> <span class="ow">or</span> <span class="n">c</span><span class="o">.</span><span class="n">yaml_tag</span> <span class="o">==</span> <span class="n">obj</span><span class="p">:</span>
                <span class="k">return</span> <span class="n">c</span>
        <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;Cannot find event class associated to </span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="n">obj</span><span class="p">)</span>

    <span class="c1"># Assume class.</span>
    <span class="k">assert</span> <span class="n">obj</span> <span class="ow">in</span> <span class="n">all_subclasses</span><span class="p">(</span><span class="n">AbinitEvent</span><span class="p">)</span>
    <span class="k">return</span> <span class="n">obj</span>


<span class="c1">############################################</span>
<span class="c1"># Concrete classes ################</span>
<span class="c1">############################################</span>

<div class="viewcode-block" id="DilatmxError"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.events.html#pymatgen.io.abinit.events.DilatmxError">[docs]</a><span class="k">class</span> <span class="nc">DilatmxError</span><span class="p">(</span><span class="n">AbinitError</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    This Error occurs in variable cell calculations when the increase in the</span>
<span class="sd">    unit cell volume is too large.</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">yaml_tag</span> <span class="o">=</span> <span class="s1">&#39;!DilatmxError&#39;</span></div>


<div class="viewcode-block" id="DilatmxErrorHandler"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.events.html#pymatgen.io.abinit.events.DilatmxErrorHandler">[docs]</a><span class="k">class</span> <span class="nc">DilatmxErrorHandler</span><span class="p">(</span><span class="n">ErrorHandler</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Handle DilatmxError. Abinit produces a netcdf file with the last structure before aborting</span>
<span class="sd">    The handler changes the structure in the input with the last configuration and modify the value of dilatmx.</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">event_class</span> <span class="o">=</span> <span class="n">DilatmxError</span>

    <span class="n">can_change_physics</span> <span class="o">=</span> <span class="kc">False</span>

    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">max_dilatmx</span><span class="o">=</span><span class="mf">1.3</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">max_dilatmx</span> <span class="o">=</span> <span class="n">max_dilatmx</span>

<div class="viewcode-block" id="DilatmxErrorHandler.as_dict"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.events.html#pymatgen.io.abinit.events.DilatmxErrorHandler.as_dict">[docs]</a>    <span class="nd">@pmg_serialize</span>
    <span class="k">def</span> <span class="nf">as_dict</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="p">{</span><span class="s1">&#39;max_dilatmx&#39;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">max_dilatmx</span><span class="p">}</span></div>

<div class="viewcode-block" id="DilatmxErrorHandler.from_dict"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.events.html#pymatgen.io.abinit.events.DilatmxErrorHandler.from_dict">[docs]</a>    <span class="nd">@classmethod</span>
    <span class="k">def</span> <span class="nf">from_dict</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">d</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">cls</span><span class="p">(</span><span class="n">max_dilatmx</span><span class="o">=</span><span class="n">d</span><span class="p">[</span><span class="s1">&#39;max_dilatmx&#39;</span><span class="p">])</span></div>

<div class="viewcode-block" id="DilatmxErrorHandler.handle_task_event"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.events.html#pymatgen.io.abinit.events.DilatmxErrorHandler.handle_task_event">[docs]</a>    <span class="k">def</span> <span class="nf">handle_task_event</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">task</span><span class="p">,</span> <span class="n">event</span><span class="p">):</span>
        <span class="c1"># Read the last structure dumped by ABINIT before aborting.</span>
        <span class="n">filepath</span> <span class="o">=</span> <span class="n">task</span><span class="o">.</span><span class="n">outdir</span><span class="o">.</span><span class="n">has_abiext</span><span class="p">(</span><span class="s2">&quot;DILATMX_STRUCT.nc&quot;</span><span class="p">)</span>
        <span class="n">last_structure</span> <span class="o">=</span> <span class="n">Structure</span><span class="o">.</span><span class="n">from_file</span><span class="p">(</span><span class="n">filepath</span><span class="p">)</span>

        <span class="n">task</span><span class="o">.</span><span class="n">_change_structure</span><span class="p">(</span><span class="n">last_structure</span><span class="p">)</span>

        <span class="c1"># read the suggested dilatmx</span>
        <span class="c1"># new_dilatmx = 1.05</span>
        <span class="c1"># if new_dilatmx &gt; self.max_dilatmx:</span>
        <span class="c1">#     msg = &quot;Suggested dilatmx ({}) exceeds maximux configured value ({}).&quot;.format(new_dilatmx,</span>
        <span class="c1">#     self.max_dilatmx)</span>
        <span class="c1">#     return self.NOT_FIXED</span>
        <span class="c1"># task.strategy.abinit_input.set_vars(dilatmx=new_dilatmx)</span>
        <span class="n">msg</span> <span class="o">=</span> <span class="s2">&quot;Take last structure from DILATMX_STRUCT.nc, will try to restart with dilatmx </span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="n">task</span><span class="o">.</span><span class="n">get_inpvar</span><span class="p">(</span>
            <span class="s2">&quot;dilatmx&quot;</span><span class="p">)</span>
        <span class="n">task</span><span class="o">.</span><span class="n">log_correction</span><span class="p">(</span><span class="n">event</span><span class="p">,</span> <span class="n">msg</span><span class="p">)</span>
        <span class="c1"># Note that we change the structure but we don&#39;t try restart from the previous WFK|DEN file</span>
        <span class="c1"># because Abinit called mpi_abort and therefore no final WFK|DEN file has been produced.</span>

        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">FIXED</span></div>

<div class="viewcode-block" id="DilatmxErrorHandler.handle_input_event"><a class="viewcode-back" href="../../../../pymatgen.io.abinit.events.html#pymatgen.io.abinit.events.DilatmxErrorHandler.handle_input_event">[docs]</a>    <span class="k">def</span> <span class="nf">handle_input_event</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">abiinput</span><span class="p">,</span> <span class="n">outdir</span><span class="p">,</span> <span class="n">event</span><span class="p">):</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="n">old_abiinput</span> <span class="o">=</span> <span class="n">abiinput</span><span class="o">.</span><span class="n">deepcopy</span><span class="p">()</span>
            <span class="c1"># Read the last structure dumped by ABINIT before aborting.</span>
            <span class="n">filepath</span> <span class="o">=</span> <span class="n">outdir</span><span class="o">.</span><span class="n">has_abiext</span><span class="p">(</span><span class="s2">&quot;DILATMX_STRUCT.nc&quot;</span><span class="p">)</span>
            <span class="n">last_structure</span> <span class="o">=</span> <span class="n">Structure</span><span class="o">.</span><span class="n">from_file</span><span class="p">(</span><span class="n">filepath</span><span class="p">)</span>
            <span class="n">abiinput</span><span class="o">.</span><span class="n">set_structure</span><span class="p">(</span><span class="n">last_structure</span><span class="p">)</span>
            <span class="c1"># FIXME restart from DEN files not always working with interpolation</span>
            <span class="k">return</span> <span class="n">Correction</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">compare_inputs</span><span class="p">(</span><span class="n">abiinput</span><span class="p">,</span> <span class="n">old_abiinput</span><span class="p">),</span> <span class="n">event</span><span class="p">,</span> <span class="n">reset</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
            <span class="c1"># return Correction(self, self.compare_inputs(abiinput, old_abiinput), event, event=False)</span>
        <span class="k">except</span> <span class="ne">Exception</span> <span class="k">as</span> <span class="n">exc</span><span class="p">:</span>
            <span class="n">logger</span><span class="o">.</span><span class="n">warning</span><span class="p">(</span><span class="s1">&#39;Error while trying to apply the handler </span><span class="si">{}</span><span class="s1">.&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="p">)),</span> <span class="n">exc</span><span class="p">)</span>
            <span class="k">return</span> <span class="kc">None</span></div></div>


<span class="k">class</span> <span class="nc">TolSymError</span><span class="p">(</span><span class="n">AbinitError</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Class of errors raised by Abinit when it cannot detect the symmetries of the system.</span>
<span class="sd">    The handler assumes the structure makes sense and the error is just due to numerical inaccuracies.</span>
<span class="sd">    We increase the value of tolsym in the input file (default 1-8) so that Abinit can find the space group</span>
<span class="sd">    and re-symmetrize the input structure.</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">yaml_tag</span> <span class="o">=</span> <span class="s1">&#39;!TolSymError&#39;</span>


<span class="k">class</span> <span class="nc">TolSymErrorHandler</span><span class="p">(</span><span class="n">ErrorHandler</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Increase the value of tolsym in the input file.</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">event_class</span> <span class="o">=</span> <span class="n">TolSymError</span>

    <span class="n">can_change_physics</span> <span class="o">=</span> <span class="kc">False</span>

    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">max_nfixes</span><span class="o">=</span><span class="mi">3</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">max_nfixes</span> <span class="o">=</span> <span class="n">max_nfixes</span>

    <span class="nd">@pmg_serialize</span>
    <span class="k">def</span> <span class="nf">as_dict</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="p">{</span><span class="s1">&#39;max_nfixes&#39;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">max_nfixes</span><span class="p">}</span>

    <span class="nd">@classmethod</span>
    <span class="k">def</span> <span class="nf">from_dict</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">d</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">cls</span><span class="p">(</span><span class="n">max_nfixes</span><span class="o">=</span><span class="n">d</span><span class="p">[</span><span class="s1">&#39;max_nfixes&#39;</span><span class="p">])</span>

    <span class="k">def</span> <span class="nf">handle_task_event</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">task</span><span class="p">,</span> <span class="n">event</span><span class="p">):</span>
        <span class="c1"># TODO: Add limit on the number of fixes one can do for the same error</span>
        <span class="c1"># For example in this case, the scheduler will stop after 20 submissions</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">count</span><span class="p">(</span><span class="n">task</span><span class="p">)</span> <span class="o">&gt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">max_nfixes</span><span class="p">:</span>
            <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">NOT_FIXED</span>

        <span class="n">old_tolsym</span> <span class="o">=</span> <span class="n">task</span><span class="o">.</span><span class="n">get_inpvar</span><span class="p">(</span><span class="s2">&quot;tolsym&quot;</span><span class="p">)</span>
        <span class="n">new_tolsym</span> <span class="o">=</span> <span class="mf">1e-6</span> <span class="k">if</span> <span class="n">old_tolsym</span> <span class="ow">is</span> <span class="kc">None</span> <span class="k">else</span> <span class="n">old_tolsym</span> <span class="o">*</span> <span class="mi">10</span>
        <span class="n">task</span><span class="o">.</span><span class="n">set_vars</span><span class="p">(</span><span class="n">tolsym</span><span class="o">=</span><span class="n">new_tolsym</span><span class="p">)</span>

        <span class="n">task</span><span class="o">.</span><span class="n">log_correction</span><span class="p">(</span><span class="n">event</span><span class="p">,</span> <span class="s2">&quot;Increasing tolsym from </span><span class="si">%s</span><span class="s2"> to </span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">old_tolsym</span><span class="p">,</span> <span class="n">new_tolsym</span><span class="p">))</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">FIXED</span>

    <span class="k">def</span> <span class="nf">handle_input_event</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">abiinput</span><span class="p">,</span> <span class="n">outdir</span><span class="p">,</span> <span class="n">event</span><span class="p">):</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="n">old_abiinput</span> <span class="o">=</span> <span class="n">abiinput</span><span class="o">.</span><span class="n">deepcopy</span><span class="p">()</span>
            <span class="n">old_tolsym</span> <span class="o">=</span> <span class="n">abiinput</span><span class="p">[</span><span class="s2">&quot;tolsym&quot;</span><span class="p">]</span>
            <span class="n">new_tolsym</span> <span class="o">=</span> <span class="mf">1e-6</span> <span class="k">if</span> <span class="n">old_tolsym</span> <span class="ow">is</span> <span class="kc">None</span> <span class="k">else</span> <span class="n">old_tolsym</span> <span class="o">*</span> <span class="mi">10</span>
            <span class="n">abiinput</span><span class="o">.</span><span class="n">set_vars</span><span class="p">(</span><span class="n">tolsym</span><span class="o">=</span><span class="n">new_tolsym</span><span class="p">)</span>
            <span class="k">return</span> <span class="n">Correction</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">compare_inputs</span><span class="p">(</span><span class="n">abiinput</span><span class="p">,</span> <span class="n">old_abiinput</span><span class="p">),</span> <span class="n">event</span><span class="p">,</span> <span class="n">reset</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
        <span class="k">except</span> <span class="ne">Exception</span> <span class="k">as</span> <span class="n">exc</span><span class="p">:</span>
            <span class="n">logger</span><span class="o">.</span><span class="n">warning</span><span class="p">(</span><span class="s1">&#39;Error while trying to apply the handler </span><span class="si">{}</span><span class="s1">.&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="p">)),</span> <span class="n">exc</span><span class="p">)</span>
            <span class="k">return</span> <span class="kc">None</span>


<span class="k">class</span> <span class="nc">MemanaError</span><span class="p">(</span><span class="n">AbinitError</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Class of errors raised by the memory analyzer.</span>
<span class="sd">    (the section that estimates the memory requirements from the input parameters).</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">yaml_tag</span> <span class="o">=</span> <span class="s1">&#39;!MemanaError&#39;</span>


<span class="k">class</span> <span class="nc">MemanaErrorHandler</span><span class="p">(</span><span class="n">ErrorHandler</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Set mem_test to 0 to bypass the memory check.</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">event_class</span> <span class="o">=</span> <span class="n">MemanaError</span>

    <span class="n">can_change_physics</span> <span class="o">=</span> <span class="kc">False</span>

    <span class="k">def</span> <span class="nf">handle_task_event</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">task</span><span class="p">,</span> <span class="n">event</span><span class="p">):</span>
        <span class="n">task</span><span class="o">.</span><span class="n">set_vars</span><span class="p">(</span><span class="n">mem_test</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
        <span class="n">task</span><span class="o">.</span><span class="n">log_correction</span><span class="p">(</span><span class="n">event</span><span class="p">,</span> <span class="s2">&quot;Find MemanaError. Setting mem_test to 0 in input file.&quot;</span><span class="p">)</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">FIXED</span>

    <span class="k">def</span> <span class="nf">handle_input_event</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">abiinput</span><span class="p">,</span> <span class="n">outdir</span><span class="p">,</span> <span class="n">event</span><span class="p">):</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="n">old_abiinput</span> <span class="o">=</span> <span class="n">abiinput</span><span class="o">.</span><span class="n">deepcopy</span><span class="p">()</span>
            <span class="n">abiinput</span><span class="o">.</span><span class="n">set_vars</span><span class="p">(</span><span class="n">mem_test</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
            <span class="k">return</span> <span class="n">Correction</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">compare_inputs</span><span class="p">(</span><span class="n">abiinput</span><span class="p">,</span> <span class="n">old_abiinput</span><span class="p">),</span> <span class="n">event</span><span class="p">,</span> <span class="n">reset</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
        <span class="k">except</span> <span class="ne">Exception</span> <span class="k">as</span> <span class="n">exc</span><span class="p">:</span>
            <span class="n">logger</span><span class="o">.</span><span class="n">warning</span><span class="p">(</span><span class="s1">&#39;Error while trying to apply the handler </span><span class="si">{}</span><span class="s1">.&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="p">)),</span> <span class="n">exc</span><span class="p">)</span>
            <span class="k">return</span> <span class="kc">None</span>


<span class="k">class</span> <span class="nc">MemoryError</span><span class="p">(</span><span class="n">AbinitError</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    This error occurs when a checked allocation fails in Abinit</span>
<span class="sd">    The only way to go is to increase memory</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">yaml_tag</span> <span class="o">=</span> <span class="s1">&#39;!MemoryError&#39;</span>


<span class="k">class</span> <span class="nc">MemoryErrorHandler</span><span class="p">(</span><span class="n">ErrorHandler</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Handle MemoryError. Increase the resources requirements</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">event_class</span> <span class="o">=</span> <span class="ne">MemoryError</span>

    <span class="n">can_change_physics</span> <span class="o">=</span> <span class="kc">False</span>

    <span class="k">def</span> <span class="nf">handle_task_event</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">task</span><span class="p">,</span> <span class="n">event</span><span class="p">):</span>
        <span class="n">task</span><span class="o">.</span><span class="n">manager</span><span class="o">.</span><span class="n">increase_resources</span><span class="p">()</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">FIXED</span>

    <span class="k">def</span> <span class="nf">handle_input_event</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">abiinput</span><span class="p">,</span> <span class="n">outdir</span><span class="p">,</span> <span class="n">event</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Shouldn&#39;t do anything on the input</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="kc">None</span>
</pre></div>

          </div>
        </div>
      </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
<div id="searchbox" style="display: none" role="search">
  <h3 id="searchlabel">Quick search</h3>
    <div class="searchformwrapper">
    <form class="search" action="../../../../search.html" method="get">
      <input type="text" name="q" aria-labelledby="searchlabel" />
      <input type="submit" value="Go" />
    </form>
    </div>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../../../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../../../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../../../index.html">pymatgen 2019.10.4 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../../../index.html" >Module code</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="../../../pymatgen.html" >pymatgen</a> &#187;</li> 
      </ul>
    </div>

    <div class="footer" role="contentinfo">
        &#169; Copyright 2011, Pymatgen Development Team.
      Created using <a href="http://sphinx-doc.org/">Sphinx</a> 2.2.0.
    </div>
<div class="footer">This page uses <a href="http://analytics.google.com/">
Google Analytics</a> to collect statistics. You can disable it by blocking
the JavaScript coming from www.google-analytics.com.
<script type="text/javascript">
  (function() {
    var ga = document.createElement('script');
    ga.src = ('https:' == document.location.protocol ?
              'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    ga.setAttribute('async', 'true');
    document.documentElement.firstChild.appendChild(ga);
  })();
</script>
</div>

  </body>
</html>