Exemplo n.º 1
0
 def log_footer(self):
     """
     Output a footer to the log.
     """
     execution_time = time_lapse(self.t0)
     self.log(f'\n\n\nTotal APIOxy execution time: {execution_time}',
              level='always')
     self.log(f'APIOxy execution terminated on {time.asctime()}\n',
              level='always')
Exemplo n.º 2
0
def determine_scaling_factors(
    levels: List[Union[Level, dict, str]],
    ess_settings: Optional[dict] = None,
    init_log: Optional[bool] = True,
) -> list:
    """
    Determine the zero-point energy, harmonic frequencies, and fundamental frequencies scaling factors
    for a given frequencies level of theory.

    Args:
        levels (list): A list of frequencies levels of theory for which scaling factors are determined.
                       Entries are either Level instances, dictionaries, or simple string representations.
                       If a single entry is given, it will be converted to a list.
        ess_settings (dict, optional): A dictionary of available ESS (keys) and a corresponding server list (values).
        init_log (bool, optional): Whether to initialize the logger. ``True`` to initialize.
                                   Should be ``True`` when called as a standalone, but ``False`` when called within ARC.

    Returns:
        list: The determined frequency scaling factors.
    """
    if init_log:
        initialize_log(log_file='scaling_factor.log',
                       project='Scaling Factors')

    if not isinstance(levels, (list, tuple)):
        levels = [levels]
    levels = [
        Level(repr=level) if not isinstance(level, Level) else level
        for level in levels
    ]

    t0 = time.time()

    logger.info('\n\n\n')
    logger.info(HEADER)
    logger.info('\n\nstarting ARC...\n')

    # only run opt (fine) and freq
    job_types = initialize_job_types(
        dict())  # get the defaults, so no job type is missing
    job_types = {job_type: False for job_type in job_types.keys()}
    job_types['opt'], job_types['fine'], job_types['freq'] = True, True, True

    lambda_zpes, zpe_dicts, times = list(), list(), list()
    for level in levels:
        t1 = time.time()
        logger.info(
            f'\nComputing scaling factors at the {level} level of theory...\n\n'
        )
        renamed_level = rename_level(str(level))
        project = 'scaling_' + renamed_level
        project_directory = os.path.join(arc_path, 'Projects',
                                         'scaling_factors', project)
        if os.path.isdir(project_directory):
            shutil.rmtree(project_directory)

        species_list = get_species_list()

        if level.method_type == 'composite':
            freq_level = None
            composite_method = level
            job_types['freq'] = False
        else:
            freq_level = level
            composite_method = None

        ess_settings = check_ess_settings(ess_settings or global_ess_settings)

        Scheduler(project=project,
                  project_directory=project_directory,
                  species_list=species_list,
                  composite_method=composite_method,
                  opt_level=freq_level,
                  freq_level=freq_level,
                  ess_settings=ess_settings,
                  job_types=job_types,
                  allow_nonisomorphic_2d=True)

        zpe_dict = dict()
        for spc in species_list:
            zpe_dict[spc.label] = parse_zpe(
                os.path.join(project_directory, 'output', 'Species', spc.label,
                             'geometry',
                             'freq.out')) * 1000  # convert to J/mol
        zpe_dicts.append(zpe_dict)

        lambda_zpes.append(
            calculate_truhlar_scaling_factors(zpe_dict=zpe_dict,
                                              level=str(level)))
        times.append(time_lapse(t1))

    summarize_results(lambda_zpes=lambda_zpes,
                      levels=[str(level) for level in levels],
                      zpe_dicts=zpe_dicts,
                      times=times,
                      overall_time=time_lapse(t0))
    logger.info('\n\n\n')
    logger.info(HEADER)

    harmonic_freq_scaling_factors = [
        lambda_zpe * 1.014 for lambda_zpe in lambda_zpes
    ]
    return harmonic_freq_scaling_factors
Exemplo n.º 3
0
 def test_time_lapse(self):
     """Test the time_lapse() function"""
     t0 = time.time()
     time.sleep(2)
     lap = common.time_lapse(t0)
     self.assertEqual(lap, '00:00:02')
Exemplo n.º 4
0
def determine_scaling_factors(levels_of_theory,
                              ess_settings=None,
                              init_log=True):
    """
    Determine the zero-point energy, harmonic frequencies, and fundamental frequencies scaling factors
    for a given frequencies level of theory.

    Args:
        levels_of_theory (list, str): A list of frequencies levels of theory
                                               for which scaling factors are determined.
                                               A string can also be passed for just one level of theory.
        ess_settings (dict, optional): A dictionary of available ESS (keys) and a corresponding server list (values).
        init_log (bool, optional): Whether to initialize the logger. True to initialize.
                                   Should be True when called as a stand alone, and False when called within ARC.

    Returns:
        str: The modified level of theory
    """
    if init_log:
        initialize_log(log_file='scaling_factor.log',
                       project='Scaling Factors')

    if isinstance(levels_of_theory, (str, unicode)):
        levels_of_theory = [levels_of_theory]
    if not isinstance(levels_of_theory, list):
        raise InputError(
            'levels_of_theory must be a list (or a string if only one level is desired). Got: {0}'
            .format(type(levels_of_theory)))
    t0 = time.time()

    logger.info('\n\n\n')
    logger.info(HEADER)
    logger.info('\n\nstarting ARC...\n')

    # only run opt (fine) and freq
    job_types = initialize_job_types(
        dict())  # get the defaults, so no job type is missing
    job_types = {job_type: False for job_type in job_types.keys()}
    job_types['opt'], job_types['fine'], job_types['freq'] = True, True, True

    lambda_zpes, zpe_dicts, times = list(), list(), list()
    for level_of_theory in levels_of_theory:
        t1 = time.time()
        logger.info(
            '\nComputing scaling factors at the {0} level of theory...\n\n'.
            format(level_of_theory))
        renamed_level = rename_level(level_of_theory)
        project = 'scaling_' + renamed_level
        project_directory = os.path.join(arc_path, 'Projects',
                                         'scaling_factors', project)

        species_list = get_species_list()

        if '//' in level_of_theory:
            raise InputError(
                'Level of theory should either be a composite method or in a method/basis-set format. '
                'Got {0}'.format(level_of_theory))
        if '/' not in level_of_theory:  # assume this is a composite method
            freq_level = ''
            composite_method = level_of_theory.lower()
            job_types['freq'] = False
        else:
            freq_level = level_of_theory.lower()
            composite_method = ''
            job_types['freq'] = True

        ess_settings = check_ess_settings(ess_settings or global_ess_settings)

        Scheduler(project=project,
                  project_directory=project_directory,
                  species_list=species_list,
                  composite_method=composite_method,
                  opt_level=freq_level,
                  freq_level=freq_level,
                  ess_settings=ess_settings,
                  job_types=job_types,
                  allow_nonisomorphic_2d=True)

        zpe_dict = dict()
        for spc in species_list:
            try:
                zpe = get_zpe(
                    os.path.join(project_directory, 'output', 'Species',
                                 spc.label, 'geometry', 'freq.out'))
            except Exception:
                zpe = None
            zpe_dict[spc.label] = zpe
        zpe_dicts.append(zpe_dict)

        lambda_zpes.append(
            calculate_truhlar_scaling_factors(zpe_dict, level_of_theory))
        times.append(time_lapse(t1))

    summarize_results(lambda_zpes, levels_of_theory, zpe_dicts, times,
                      time_lapse(t0))
    logger.info('\n\n\n')
    logger.info(HEADER)

    harmonic_freq_scaling_factors = [
        lambda_zpe * 1.014 for lambda_zpe in lambda_zpes
    ]
    return harmonic_freq_scaling_factors