def run_statmech(
        self,
        arkane_species: Type[Species],
        arkane_file_path: str,
        arkane_output_path: str = None,
        bac_type: Optional[str] = None,
        sp_level: Optional[Level] = None,
        plot: bool = False,
    ) -> bool:
        """
        A helper function for running an Arkane statmech job.

        Args:
            arkane_species (arkane_input_species): An instance of an Arkane species() object.
            arkane_file_path (str): The path to the Arkane species file (either in .py or YAML form).
            arkane_output_path (str): The path to the folder in which the Arkane output.py file will be saved.
            bac_type (str, optional): The bond additivity correction type. 'p' for Petersson- or 'm' for Melius-type BAC.
                                      ``None`` to not use BAC.
            sp_level (Level, optional): The level of theory used for energy corrections.
            plot (bool): A flag indicating whether to plot a PDF of the calculated thermo properties (True to plot)

        Returns:
            bool: Whether the statmech job was successful.
        """
        success = True
        stat_mech_job = StatMechJob(arkane_species, arkane_file_path)
        stat_mech_job.applyBondEnergyCorrections = bac_type is not None and sp_level is not None
        if bac_type is not None:
            stat_mech_job.bondEnergyCorrectionType = bac_type
        if sp_level is None:
            # if this is a kinetics computation and we don't have a valid model chemistry, don't bother about it
            stat_mech_job.applyAtomEnergyCorrections = False
        else:
            stat_mech_job.level_of_theory = sp_level.to_arkane_level_of_theory(
            )
        stat_mech_job.frequencyScaleFactor = self.freq_scale_factor
        try:
            stat_mech_job.execute(output_directory=arkane_output_path,
                                  plot=plot)
        except Exception as e:
            logger.error(
                f'Arkane statmech job for species {arkane_species.label} failed with the error message:\n{e}'
            )
            if stat_mech_job.applyBondEnergyCorrections \
                    and 'missing' in str(e).lower() and 'bac parameters for model chemistry' in str(e).lower():
                # try executing Arkane w/o BACs
                logger.warning('Trying to run Arkane without BACs')
                stat_mech_job.applyBondEnergyCorrections = False
                try:
                    stat_mech_job.execute(output_directory=arkane_output_path,
                                          plot=plot)
                except Exception as e:
                    logger.error(
                        f'Arkane statmech job for {arkane_species.label} failed with the error message:\n{e}'
                    )
                    success = False
            else:
                success = False
        return success
Exemple #2
0
    def test_specifying_absolute_file_paths(self):
        """Test specifying absolute file paths of statmech files"""
        h2o2_input = """#!/usr/bin/env python
# -*- coding: utf-8 -*-

bonds = {{'H-O': 2, 'O-O': 1}}

externalSymmetry = 2

spinMultiplicity = 1

opticalIsomers = 1

energy = {{'b3lyp/6-311+g(3df,2p)': Log('{energy}')}}

geometry = Log('{freq}')

frequencies = Log('{freq}')

rotors = [HinderedRotor(scanLog=Log('{scan}'), pivots=[1, 2], top=[1, 3], symmetry=1, fit='fourier')]

"""
        abs_arkane_path = os.path.abspath(os.path.dirname(
            __file__))  # this is the absolute path to `.../RMG-Py/arkane`
        energy_path = os.path.join('arkane', 'data', 'H2O2', 'sp_a19032.out')
        freq_path = os.path.join('arkane', 'data', 'H2O2', 'freq_a19031.out')
        scan_path = os.path.join('arkane', 'data', 'H2O2', 'scan_a19034.out')
        h2o2_input = h2o2_input.format(energy=energy_path,
                                       freq=freq_path,
                                       scan=scan_path)
        h2o2_path = os.path.join(abs_arkane_path, 'data', 'H2O2', 'H2O2.py')
        if not os.path.exists(os.path.dirname(h2o2_path)):
            os.makedirs(os.path.dirname(h2o2_path))
        with open(h2o2_path, 'w') as f:
            f.write(h2o2_input)
        h2o2 = Species(label='H2O2', smiles='OO')
        self.assertIsNone(h2o2.conformer)
        statmech_job = StatMechJob(species=h2o2, path=h2o2_path)
        statmech_job.level_of_theory = LevelOfTheory('b3lyp',
                                                     '6-311+g(3df,2p)')
        statmech_job.load(pdep=False, plot=False)
        self.assertAlmostEqual(h2o2.conformer.E0.value_si, -146031.49933673252)
        os.remove(h2o2_path)