# 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/electronic_structure/startup.py
# PACKAGE_PATH = twod_materials.__file__.replace('__init__.pyc', '')
# PACKAGE_PATH = PACKAGE_PATH.replace('__init__.py', '')
# PACKAGE_PATH = '/'.join(PACKAGE_PATH.split('/')[:-2])
#     VASP = config_vars['normal_binary']
#     QUEUE = config_vars['queue_system'].lower()
#     QUEUE = 'slurm'
#     QUEUE = 'pbs'
#     PBE_INCAR_DICT = {'EDIFF': 1e-6, 'IBRION': 2, 'ISIF': 3,
#                       'ISMEAR': 1, 'NSW': 0, 'LVTOT': True, 'LVHAR': True,
#                       'LORBIT': 1, 'LREAL': 'Auto', 'NPAR': 4,
#                       'PREC': 'Accurate', 'LWAVE': True, 'SIGMA': 0.1,
#                       'ENCUT': 500, 'ISPIN': 2}
#     HSE_INCAR_DICT = {'LHFCALC': True, 'HFSCREEN': 0.2, 'AEXX': 0.25,
#                       'ALGO': 'D', 'TIME': 0.4, 'NSW': 0,
#                       'LVTOT': True, 'LVHAR': True, 'LORBIT': 11,
#                       'LWAVE': True, 'NPAR': 8, 'PREC': 'Accurate',
#                       'EDIFF': 1e-4, 'ENCUT': 450, 'ICHARG': 2, 'ISMEAR': 1,
#                       'SIGMA': 0.1, 'IBRION': 2, 'ISIF': 3, 'ISPIN': 2}
# def run_pbe_calculation(dim=2, submit=True, force_overwrite=False):
# def run_hse_prep_calculation(dim=2, submit=True):
# def run_hse_calculation(dim=2, submit=True, force_overwrite=False,
#                         destroy_prep_directory=False):
# 
# Path: twod_materials/electronic_structure/analysis.py
# def get_band_edges():
# def plot_band_alignments(directories, run_type='PBE', fmt='pdf'):
# def plot_local_potential(axis=2, ylim=(-20, 0), fmt='pdf'):
# def plot_band_structure(ylim=(-5, 5), draw_fermi=False, fmt='pdf'):
# def plot_color_projected_bands(ylim=(-5, 5), fmt='pdf'):
# def plot_elt_projected_bands(ylim=(-5, 5), fmt='pdf'):
# def plot_orb_projected_bands(orbitals, fmt='pdf', ylim=(-5, 5)):
# def get_effective_mass():
# def plot_density_of_states(fmt='pdf'):
# def get_fermi_velocities():
# def find_dirac_nodes():
# def plot_spin_texture(inner_index, outer_index, center=(0, 0), fmt='pdf'):
#     H_BAR = 6.582119514e-16  # eV*s
#     M_0 = 9.10938356e-31  # kg
#     N_KPTS = 6  # Number of k-points included in the parabola.
#     E = {'electron': {'left': [], 'right': []},
#          'hole': {'left': [], 'right': []}}


import os
import time
from twod_materials.utils import is_converged
from twod_materials.electronic_structure.startup import (
    run_linemode_calculation
    )
from twod_materials.electronic_structure.analysis import (
    plot_normal_band_structure
    )
"""
Relaxes 2D materials in all subdirectories of the current working
directory, along with their most stable competing species. At a
specified INTERVAL, checks if all relaxations have converged. Once all
are converged, calculates and plots the formation energies of all 2D
materials as stability_plot.pdf.
"""
from __future__ import print_function, division, unicode_literals




INTERVAL = 360  # Seconds between convergence checks

directories = [dir for dir in os.listdir(os.getcwd()) if os.path.isdir(dir)
               and dir not in ['all_competitors']]

if __name__ == '__main__':

    for directory in directories:
        os.chdir(directory)
        run_linemode_calculation()
        os.chdir('../')

    loop = True
    while loop:
        print('>> Checking convergence')
        finished = []

        for directory in directories:

# 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/electronic_structure/startup.py
# PACKAGE_PATH = twod_materials.__file__.replace('__init__.pyc', '')
# PACKAGE_PATH = PACKAGE_PATH.replace('__init__.py', '')
# PACKAGE_PATH = '/'.join(PACKAGE_PATH.split('/')[:-2])
#     VASP = config_vars['normal_binary']
#     QUEUE = config_vars['queue_system'].lower()
#     QUEUE = 'slurm'
#     QUEUE = 'pbs'
#     PBE_INCAR_DICT = {'EDIFF': 1e-6, 'IBRION': 2, 'ISIF': 3,
#                       'ISMEAR': 1, 'NSW': 0, 'LVTOT': True, 'LVHAR': True,
#                       'LORBIT': 1, 'LREAL': 'Auto', 'NPAR': 4,
#                       'PREC': 'Accurate', 'LWAVE': True, 'SIGMA': 0.1,
#                       'ENCUT': 500, 'ISPIN': 2}
#     HSE_INCAR_DICT = {'LHFCALC': True, 'HFSCREEN': 0.2, 'AEXX': 0.25,
#                       'ALGO': 'D', 'TIME': 0.4, 'NSW': 0,
#                       'LVTOT': True, 'LVHAR': True, 'LORBIT': 11,
#                       'LWAVE': True, 'NPAR': 8, 'PREC': 'Accurate',
#                       'EDIFF': 1e-4, 'ENCUT': 450, 'ICHARG': 2, 'ISMEAR': 1,
#                       'SIGMA': 0.1, 'IBRION': 2, 'ISIF': 3, 'ISPIN': 2}
# def run_pbe_calculation(dim=2, submit=True, force_overwrite=False):
# def run_hse_prep_calculation(dim=2, submit=True):
# def run_hse_calculation(dim=2, submit=True, force_overwrite=False,
#                         destroy_prep_directory=False):
# 
# Path: twod_materials/electronic_structure/analysis.py
# def get_band_edges():
# def plot_band_alignments(directories, run_type='PBE', fmt='pdf'):
# def plot_local_potential(axis=2, ylim=(-20, 0), fmt='pdf'):
# def plot_band_structure(ylim=(-5, 5), draw_fermi=False, fmt='pdf'):
# def plot_color_projected_bands(ylim=(-5, 5), fmt='pdf'):
# def plot_elt_projected_bands(ylim=(-5, 5), fmt='pdf'):
# def plot_orb_projected_bands(orbitals, fmt='pdf', ylim=(-5, 5)):
# def get_effective_mass():
# def plot_density_of_states(fmt='pdf'):
# def get_fermi_velocities():
# def find_dirac_nodes():
# def plot_spin_texture(inner_index, outer_index, center=(0, 0), fmt='pdf'):
#     H_BAR = 6.582119514e-16  # eV*s
#     M_0 = 9.10938356e-31  # kg
#     N_KPTS = 6  # Number of k-points included in the parabola.
#     E = {'electron': {'left': [], 'right': []},
#          'hole': {'left': [], 'right': []}}


# Path: examples/pbe_bandstructure.py
import os
import time
from twod_materials.utils import is_converged
from twod_materials.electronic_structure.startup import (
    run_linemode_calculation
    )
from twod_materials.electronic_structure.analysis import (
    plot_normal_band_structure
    )

"""
Relaxes 2D materials in all subdirectories of the current working
directory, along with their most stable competing species. At a
specified INTERVAL, checks if all relaxations have converged. Once all
are converged, calculates and plots the formation energies of all 2D
materials as stability_plot.pdf.
"""
from __future__ import print_function, division, unicode_literals




INTERVAL = 360  # Seconds between convergence checks

directories = [dir for dir in os.listdir(os.getcwd()) if os.path.isdir(dir)
               and dir not in ['all_competitors']]

if __name__ == '__main__':

    for directory in directories:
        os.chdir(directory)
        run_linemode_calculation()
        os.chdir('../')

    loop = True
    while loop:
        print('>> Checking convergence')
        finished = []

        for directory in directories:

            if is_converged('{}/pbe_bands'.format(directory)):