# Path: twod_materials/utils.py
# def is_converged(directory):
#     """
#     Check if a relaxation has converged.
# 
#     Args:
#         directory (str): path to directory to check.
# 
#     Returns:
#         boolean. Whether or not the job is converged.
#     """
# 
#     try:
#         if Vasprun('{}/vasprun.xml'.format(directory)).converged:
#             return True
#         else:
#             return False
# 
#     except:
#         return False


import os
import operator
import matplotlib as mpl
import matplotlib.pyplot as plt
import twod_materials
from pymatgen.phasediagram.analyzer import PDAnalyzer
from pymatgen.phasediagram.maker import PhaseDiagram
from pymatgen.core.structure import Structure
from pymatgen.io.vasp.outputs import Vasprun
from pymatgen.entries.computed_entries import ComputedEntry
from pymatgen.matproj.rest import MPRester
from monty.serialization import loadfn
from twod_materials.utils import is_converged
         entry.entry_id) for entry in decomp[0]
        ]

    return competing_phases


def get_hull_distance(competing_phase_directory='../competing_phases'):
    """
    Calculate the material's distance to the thermodynamic hull,
    based on species in the Materials Project database.

    Args:
        competing_phase_directory (str): absolute or relative path
            to the location where your competing phases have been
            relaxed. The default expectation is that they are stored
            in a directory named 'competing_phases' at the same level
            as your material's relaxation directory.
    Returns:
        float. distance (eV/atom) between the material and the
            hull.
    """

    finished_competitors = {}
    original_directory = os.getcwd()
    # Determine which competing phases have been relaxed in the current
    # framework and store them in a dictionary ({formula: entry}).
    if os.path.isdir(competing_phase_directory):
        os.chdir(competing_phase_directory)
        for comp_dir in [
            dir for dir in os.listdir(os.getcwd()) if os.path.isdir(dir) and

# Path: twod_materials/utils.py
# def is_converged(directory):
#     """
#     Check if a relaxation has converged.
# 
#     Args:
#         directory (str): path to directory to check.
# 
#     Returns:
#         boolean. Whether or not the job is converged.
#     """
# 
#     try:
#         if Vasprun('{}/vasprun.xml'.format(directory)).converged:
#             return True
#         else:
#             return False
# 
#     except:
#         return False


# Path: twod_materials/stability/analysis.py
import os
import operator
import matplotlib as mpl
import matplotlib.pyplot as plt
import twod_materials
from pymatgen.phasediagram.analyzer import PDAnalyzer
from pymatgen.phasediagram.maker import PhaseDiagram
from pymatgen.core.structure import Structure
from pymatgen.io.vasp.outputs import Vasprun
from pymatgen.entries.computed_entries import ComputedEntry
from pymatgen.matproj.rest import MPRester
from monty.serialization import loadfn
from twod_materials.utils import is_converged

         entry.entry_id) for entry in decomp[0]
        ]

    return competing_phases


def get_hull_distance(competing_phase_directory='../competing_phases'):
    """
    Calculate the material's distance to the thermodynamic hull,
    based on species in the Materials Project database.

    Args:
        competing_phase_directory (str): absolute or relative path
            to the location where your competing phases have been
            relaxed. The default expectation is that they are stored
            in a directory named 'competing_phases' at the same level
            as your material's relaxation directory.
    Returns:
        float. distance (eV/atom) between the material and the
            hull.
    """

    finished_competitors = {}
    original_directory = os.getcwd()
    # Determine which competing phases have been relaxed in the current
    # framework and store them in a dictionary ({formula: entry}).
    if os.path.isdir(competing_phase_directory):
        os.chdir(competing_phase_directory)
        for comp_dir in [
            dir for dir in os.listdir(os.getcwd()) if os.path.isdir(dir) and

            is_converged(dir)