# Path: twod_materials/stability/startup.py
# def relax(dim=2, submit=True, force_overwrite=False):
#     """
#     Writes input files and (optionally) submits a self-consistent
#     relaxation. Should be run before pretty much anything else, in
#     order to get the right energy and structure of the material.
# 
#     Args:
#         dim (int): 2 for relaxing a 2D material, 3 for a 3D material.
#         submit (bool): Whether or not to submit the job.
#         force_overwrite (bool): Whether or not to overwrite files
#             if an already converged vasprun.xml exists in the
#             directory.
#     """
# 
#     if force_overwrite or not utl.is_converged(os.getcwd()):
#         directory = os.getcwd().split('/')[-1]
# 
#         # vdw_kernel.bindat file required for VDW calculations.
#         if VDW_KERNEL != '/path/to/vdw_kernel.bindat':
#             os.system('cp {} .'.format(VDW_KERNEL))
#         # KPOINTS
#         Kpoints.automatic_density(Structure.from_file('POSCAR'),
#                                   1000).write_file('KPOINTS')
# 
#         # INCAR
#         INCAR_DICT.update({'MAGMOM': utl.get_magmom_string()})
#         Incar.from_dict(INCAR_DICT).write_file('INCAR')
#         # POTCAR
#         utl.write_potcar()
# 
#         # Special tasks only performed for 2D materials.
#         if dim == 2:
#             # Ensure 20A interlayer vacuum
#             utl.add_vacuum(20 - utl.get_spacing(), 0.9)
#             # Remove all z k-points.
#             kpts_lines = open('KPOINTS').readlines()
#             with open('KPOINTS', 'w') as kpts:
#                 for line in kpts_lines[:3]:
#                     kpts.write(line)
#                 kpts.write(kpts_lines[3].split()[0] + ' '
#                            + kpts_lines[3].split()[1] + ' 1')
# 
#         # Submission script
#         if QUEUE == 'pbs':
#             utl.write_pbs_runjob(directory, 1, 16, '800mb', '6:00:00',
#                                  VASP_2D)
#             submission_command = 'qsub runjob'
# 
#         elif QUEUE == 'slurm':
#             utl.write_slurm_runjob(directory, 16, '800mb', '6:00:00',
#                                    VASP_2D)
#             submission_command = 'sbatch runjob'
# 
#         if submit:
#             os.system(submission_command)


import os
import numpy as np
import math
import twod_materials
from twod_materials.utils import *
from twod_materials.stability.startup import relax
from pymatgen.io.vasp.inputs import Kpoints, Incar
from pymatgen.symmetry.bandstructure import HighSymmKpath
from pymatgen.core.structure import Structure
from monty.serialization import loadfn
from __future__ import print_function, division, unicode_literals









PACKAGE_PATH = twod_materials.__file__.replace('__init__.pyc', '')
PACKAGE_PATH = PACKAGE_PATH.replace('__init__.py', '')
PACKAGE_PATH = '/'.join(PACKAGE_PATH.split('/')[:-2])

try:
    config_vars = loadfn(os.path.join(os.path.expanduser('~'), 'config.yaml'))
except:
    print('WARNING: No config.yaml file was found. please configure the '\
    'config.yaml and put it in your home directory.')
    # Still set them for testing purposes.
    config_vars = loadfn(os.path.join(PACKAGE_PATH, 'config.yaml'))
    VASP = config_vars['normal_binary']
if 'queue_system' in config_vars:
    QUEUE = config_vars['queue_system'].lower()
elif '/ufrc/' in os.getcwd():
    QUEUE = 'slurm'

# Path: twod_materials/stability/startup.py
# def relax(dim=2, submit=True, force_overwrite=False):
#     """
#     Writes input files and (optionally) submits a self-consistent
#     relaxation. Should be run before pretty much anything else, in
#     order to get the right energy and structure of the material.
# 
#     Args:
#         dim (int): 2 for relaxing a 2D material, 3 for a 3D material.
#         submit (bool): Whether or not to submit the job.
#         force_overwrite (bool): Whether or not to overwrite files
#             if an already converged vasprun.xml exists in the
#             directory.
#     """
# 
#     if force_overwrite or not utl.is_converged(os.getcwd()):
#         directory = os.getcwd().split('/')[-1]
# 
#         # vdw_kernel.bindat file required for VDW calculations.
#         if VDW_KERNEL != '/path/to/vdw_kernel.bindat':
#             os.system('cp {} .'.format(VDW_KERNEL))
#         # KPOINTS
#         Kpoints.automatic_density(Structure.from_file('POSCAR'),
#                                   1000).write_file('KPOINTS')
# 
#         # INCAR
#         INCAR_DICT.update({'MAGMOM': utl.get_magmom_string()})
#         Incar.from_dict(INCAR_DICT).write_file('INCAR')
#         # POTCAR
#         utl.write_potcar()
# 
#         # Special tasks only performed for 2D materials.
#         if dim == 2:
#             # Ensure 20A interlayer vacuum
#             utl.add_vacuum(20 - utl.get_spacing(), 0.9)
#             # Remove all z k-points.
#             kpts_lines = open('KPOINTS').readlines()
#             with open('KPOINTS', 'w') as kpts:
#                 for line in kpts_lines[:3]:
#                     kpts.write(line)
#                 kpts.write(kpts_lines[3].split()[0] + ' '
#                            + kpts_lines[3].split()[1] + ' 1')
# 
#         # Submission script
#         if QUEUE == 'pbs':
#             utl.write_pbs_runjob(directory, 1, 16, '800mb', '6:00:00',
#                                  VASP_2D)
#             submission_command = 'qsub runjob'
# 
#         elif QUEUE == 'slurm':
#             utl.write_slurm_runjob(directory, 16, '800mb', '6:00:00',
#                                    VASP_2D)
#             submission_command = 'sbatch runjob'
# 
#         if submit:
#             os.system(submission_command)


# Path: twod_materials/electronic_structure/startup.py
import os
import numpy as np
import math
import twod_materials
from twod_materials.utils import *
from twod_materials.stability.startup import relax
from pymatgen.io.vasp.inputs import Kpoints, Incar
from pymatgen.symmetry.bandstructure import HighSymmKpath
from pymatgen.core.structure import Structure
from monty.serialization import loadfn

from __future__ import print_function, division, unicode_literals









PACKAGE_PATH = twod_materials.__file__.replace('__init__.pyc', '')
PACKAGE_PATH = PACKAGE_PATH.replace('__init__.py', '')
PACKAGE_PATH = '/'.join(PACKAGE_PATH.split('/')[:-2])

try:
    config_vars = loadfn(os.path.join(os.path.expanduser('~'), 'config.yaml'))
except:
    print('WARNING: No config.yaml file was found. please configure the '\
    'config.yaml and put it in your home directory.')
    # Still set them for testing purposes.
    config_vars = loadfn(os.path.join(PACKAGE_PATH, 'config.yaml'))
    VASP = config_vars['normal_binary']
if 'queue_system' in config_vars:
    QUEUE = config_vars['queue_system'].lower()
elif '/ufrc/' in os.getcwd():
    QUEUE = 'slurm'

elif '/scratch/' in os.getcwd():