"""
    submtr.orca
    ~~~~~~~~~~~~~~~~

    Implements the OrcaJob class for submitting Orca calculations.

    :copyright: (c) 2014 by Li Research Group.
    :license: MIT, see LICENSE for more details.
"""

import re

from submtr.config import settings
from submtr.job import Job
from submtr.util import match, parse


class OrcaJob(Job):
    """The Orca job class."""
    def __init__(self, filename):
        super(OrcaJob, self).__init__(filename)
        self.program = 'Orca'
        self.summary['Program'] = 'Orca'
        self.template_file = 'subscript_orca'

    def preprocess(self):
        """Build the Orca job."""
        self._digest_input_file()

    def customize_template(self):
        self.template.add_custom_field('BASHDIR', settings.home_dir)

    def _digest_input_file(self):
        # Parse the Orca input file.
        processors = r'PAL(\d+)'
        number_processors = '1'
        contents = self.input_file.get_contents()
        for line in contents:
            if match(processors, line):
                number_processors = parse(processors, line)
        self.processors = number_processors
        self.summary['Processors'] = number_processors
