# Path: mpinterfaces/data_processor.py
# class MPINTVasprun(Vasprun):
#     """
#     Extend Vasprun to use custom ComputedEntry: MPINTComputedEntry
#     """
# 
#     def __init__(self, filename, ionic_step_skip=None,
#                  ionic_step_offset=0, parse_dos=True,
#                  parse_eigen=True, parse_projected_eigen=False,
#                  parse_potcar_file=True):
# 
#         Vasprun.__init__(self, filename,
#                          ionic_step_skip=ionic_step_skip,
#                          ionic_step_offset=ionic_step_offset,
#                          parse_dos=parse_dos, parse_eigen=parse_eigen,
#                          parse_projected_eigen=parse_projected_eigen,
#                          parse_potcar_file=parse_potcar_file)
# 
#     def get_computed_entry(self, inc_structure=False,
#                            inc_incar_n_kpoints=False,
#                            parameters=None, data=None):
#         """
#         Returns a ComputedEntry from the vasprun.
# 
#         Args:
#             inc_structure (bool): Set to True if you want
#                 ComputedStructureEntries to be returned instead of
#                 ComputedEntries.
#             inc_incar_n_kpoints (bool): along with inc_structure set
#                 to True if you want MPINTComputedEntries to be
#                 returned
#             parameters (list): Input parameters to include.
#                 It has to be one of the properties supported by the
#                 Vasprun object. If parameters == None, a default set
#                 of parameters that are necessary for typical
#                 post-processing will be set.
#             data (list): Output data to include. Has to be one of the
#                 properties supported by the Vasprun object.
# 
#         Returns:
#             ComputedStructureEntry/ComputedEntry
#         """
#         param_names = {"is_hubbard", "hubbards", "potcar_symbols",
#                        "run_type"}
#         if parameters:
#             param_names.update(parameters)
#         params = {p: getattr(self, p) for p in param_names}
#         data = {p: getattr(self, p) for p in data} if data is not None else {}
# 
#         if inc_structure and inc_incar_n_kpoints:
#             return MPINTComputedEntry(self.final_structure,
#                                       self.kpoints, self.incar,
#                                       self.final_energy,
#                                       parameters=params, data=data)
# 
#         elif inc_structure:
#             return ComputedStructureEntry(self.final_structure,
#                                           self.final_energy,
#                                           parameters=params,
#                                           data=data)
#         else:
#             return ComputedEntry(self.final_structure.composition,
#                                  self.final_energy, parameters=params,
#                                  data=data)
# 
# Path: mpinterfaces/default_logger.py
# def get_default_logger(name, output_stream=sys.stdout):
#     logger = logging.getLogger(name)
#     logger.setLevel(logging.DEBUG)
#     logger.propagate = False
#     formatter = logging.Formatter('%(levelname)s:%(name)s:%(message)s')
#     sh = logging.StreamHandler(stream=output_stream)
#     sh.setFormatter(formatter)
#     logger.addHandler(sh)
#     return logger


import os
import shutil
import subprocess
import logging
from pymatgen.io.vasp.inputs import Incar, Poscar, Potcar, Kpoints
from pymatgen.io.vasp.sets import DictSet
from custodian.custodian import Job, ErrorHandler
from monty.json import MontyDecoder
from fireworks.user_objects.queue_adapters.common_adapter import CommonAdapter
from mpinterfaces.data_processor import MPINTVasprun
from mpinterfaces.default_logger import get_default_logger


class MPINTVaspJob(MPINTJob):
    """
    defines a vasp job i.e setup the required input files and
    launch the job

    Args:
       job_cmd: a list, the command to be issued in each job_dir
                 eg: ['qsub', 'submit_job']
       job_dir: the directory from which the jobs will be launched
    """

    def __init__(self, job_cmd, name='noname', output_file="job.out",
                 parent_job_dir='.', job_dir='untitled', suffix="",
                 final=True, gzipped=False, backup=False, vis=None,
                 auto_npar=True, settings_override=None, wait=True,
                 vjob_logger=None):
        MPINTJob.__init__(self, job_cmd, name=name,
                          output_file=output_file,
                          parent_job_dir=parent_job_dir,
                          job_dir=job_dir, suffix=suffix,
                          final=final, gzipped=gzipped,
                          backup=backup, vis=vis, auto_npar=auto_npar,
                          settings_override=settings_override,
                          wait=wait, vjob_logger=vjob_logger)

    def get_final_energy(self):
        vasprun_file_path = self.job_dir + os.sep + 'vasprun.xml'
        try:

# Path: mpinterfaces/data_processor.py
# class MPINTVasprun(Vasprun):
#     """
#     Extend Vasprun to use custom ComputedEntry: MPINTComputedEntry
#     """
# 
#     def __init__(self, filename, ionic_step_skip=None,
#                  ionic_step_offset=0, parse_dos=True,
#                  parse_eigen=True, parse_projected_eigen=False,
#                  parse_potcar_file=True):
# 
#         Vasprun.__init__(self, filename,
#                          ionic_step_skip=ionic_step_skip,
#                          ionic_step_offset=ionic_step_offset,
#                          parse_dos=parse_dos, parse_eigen=parse_eigen,
#                          parse_projected_eigen=parse_projected_eigen,
#                          parse_potcar_file=parse_potcar_file)
# 
#     def get_computed_entry(self, inc_structure=False,
#                            inc_incar_n_kpoints=False,
#                            parameters=None, data=None):
#         """
#         Returns a ComputedEntry from the vasprun.
# 
#         Args:
#             inc_structure (bool): Set to True if you want
#                 ComputedStructureEntries to be returned instead of
#                 ComputedEntries.
#             inc_incar_n_kpoints (bool): along with inc_structure set
#                 to True if you want MPINTComputedEntries to be
#                 returned
#             parameters (list): Input parameters to include.
#                 It has to be one of the properties supported by the
#                 Vasprun object. If parameters == None, a default set
#                 of parameters that are necessary for typical
#                 post-processing will be set.
#             data (list): Output data to include. Has to be one of the
#                 properties supported by the Vasprun object.
# 
#         Returns:
#             ComputedStructureEntry/ComputedEntry
#         """
#         param_names = {"is_hubbard", "hubbards", "potcar_symbols",
#                        "run_type"}
#         if parameters:
#             param_names.update(parameters)
#         params = {p: getattr(self, p) for p in param_names}
#         data = {p: getattr(self, p) for p in data} if data is not None else {}
# 
#         if inc_structure and inc_incar_n_kpoints:
#             return MPINTComputedEntry(self.final_structure,
#                                       self.kpoints, self.incar,
#                                       self.final_energy,
#                                       parameters=params, data=data)
# 
#         elif inc_structure:
#             return ComputedStructureEntry(self.final_structure,
#                                           self.final_energy,
#                                           parameters=params,
#                                           data=data)
#         else:
#             return ComputedEntry(self.final_structure.composition,
#                                  self.final_energy, parameters=params,
#                                  data=data)
# 
# Path: mpinterfaces/default_logger.py
# def get_default_logger(name, output_stream=sys.stdout):
#     logger = logging.getLogger(name)
#     logger.setLevel(logging.DEBUG)
#     logger.propagate = False
#     formatter = logging.Formatter('%(levelname)s:%(name)s:%(message)s')
#     sh = logging.StreamHandler(stream=output_stream)
#     sh.setFormatter(formatter)
#     logger.addHandler(sh)
#     return logger


# Path: mpinterfaces/instrument.py
import os
import shutil
import subprocess
import logging
from pymatgen.io.vasp.inputs import Incar, Poscar, Potcar, Kpoints
from pymatgen.io.vasp.sets import DictSet
from custodian.custodian import Job, ErrorHandler
from monty.json import MontyDecoder
from fireworks.user_objects.queue_adapters.common_adapter import CommonAdapter
from mpinterfaces.data_processor import MPINTVasprun
from mpinterfaces.default_logger import get_default_logger



class MPINTVaspJob(MPINTJob):
    """
    defines a vasp job i.e setup the required input files and
    launch the job

    Args:
       job_cmd: a list, the command to be issued in each job_dir
                 eg: ['qsub', 'submit_job']
       job_dir: the directory from which the jobs will be launched
    """

    def __init__(self, job_cmd, name='noname', output_file="job.out",
                 parent_job_dir='.', job_dir='untitled', suffix="",
                 final=True, gzipped=False, backup=False, vis=None,
                 auto_npar=True, settings_override=None, wait=True,
                 vjob_logger=None):
        MPINTJob.__init__(self, job_cmd, name=name,
                          output_file=output_file,
                          parent_job_dir=parent_job_dir,
                          job_dir=job_dir, suffix=suffix,
                          final=final, gzipped=gzipped,
                          backup=backup, vis=vis, auto_npar=auto_npar,
                          settings_override=settings_override,
                          wait=wait, vjob_logger=vjob_logger)

    def get_final_energy(self):
        vasprun_file_path = self.job_dir + os.sep + 'vasprun.xml'
        try:

            vasprun = MPINTVasprun(vasprun_file_path,