Exemple #1
0
 def setUp(self):
     """
     A function run before each unit test in this class.
     """
     self.frequency = -2017.96
     self.tunneling = Wigner(
         frequency = (self.frequency,"cm^-1"),
     )
Exemple #2
0
def reaction(label, reactants, products, transitionState=None, kinetics=None, tunneling=''):
    """Load a reaction from an input file"""
    global reaction_dict, species_dict, transition_state_dict
    if label in reaction_dict:
        label = label + transitionState
        if label in reaction_dict:
            raise ValueError('Multiple occurrences of reaction with label {0!r}.'.format(label))
    logging.info('Loading reaction {0}...'.format(label))
    reactants = sorted([species_dict[spec] for spec in reactants])
    products = sorted([species_dict[spec] for spec in products])
    if transitionState:
        transitionState = transition_state_dict[transitionState]
    if transitionState and (tunneling == '' or tunneling is None):
        transitionState.tunneling = None
    elif tunneling.lower() == 'wigner':
        transitionState.tunneling = Wigner(frequency=None)
    elif tunneling.lower() == 'eckart':
        transitionState.tunneling = Eckart(frequency=None, E0_reac=None, E0_TS=None, E0_prod=None)

    elif transitionState and not isinstance(tunneling, TunnelingModel):
        raise ValueError('Unknown tunneling model {0!r}.'.format(tunneling))
    rxn = Reaction(label=label, reactants=reactants, products=products, transition_state=transitionState,
                   kinetics=kinetics)

    if rxn.transition_state is None and rxn.kinetics is None:
        logging.info('estimating rate of reaction {0} using RMG-database')
        if not all([m.molecule != [] for m in rxn.reactants + rxn.products]):
            raise ValueError('chemical structures of reactants and products not available for RMG estimation of '
                             'reaction {0}'.format(label))
        db = get_db('kinetics')
        rxns = db.generate_reactions_from_libraries(reactants=rxn.reactants, products=rxn.products)
        rxns = [r for r in rxns if r.elementary_high_p]

        if rxns:
            for r in rxns:
                if isinstance(rxn.kinetics, PDepKineticsModel):
                    boo = rxn.generate_high_p_limit_kinetics()
                if boo:
                    rxn = r
                    break

        if rxns == [] or not boo:
            logging.info('No library reactions tagged with elementary_high_p found for reaction {0}, generating '
                         'reactions from RMG families'.format(label))
            rxn = list(db.generate_reactions_from_families(reactants=rxn.reactants, products=rxn.products))
            model = CoreEdgeReactionModel()
            model.verbose_comments = True
            for r in rxn:
                model.apply_kinetics_to_reaction(r)

    if isinstance(rxn, Reaction):
        reaction_dict[label] = rxn
    else:
        for i in range(len(rxn)):
            reaction_dict[label + str(i)] = rxn[i]

    return rxn
Exemple #3
0
class TestWigner(unittest.TestCase):
    """
    Contains unit tests of the :class:`Wigner` class.
    """
    def setUp(self):
        """
        A function run before each unit test in this class.
        """
        self.frequency = -2017.96
        self.tunneling = Wigner(frequency=(self.frequency, "cm^-1"), )

    def test_frequency(self):
        """
        Test that the Wigner frequency property was properly set.
        """
        self.assertAlmostEqual(self.tunneling.frequency.value_si,
                               self.frequency, 4)

    def test_calculate_tunneling_factor(self):
        """
        Test the Wigner.calculate_tunneling_factor() method.
        """
        Tlist = np.array([300, 500, 1000, 1500, 2000])
        kexplist = np.array([4.90263, 2.40495, 1.35124, 1.15611, 1.08781])
        for T, kexp in zip(Tlist, kexplist):
            kact = self.tunneling.calculate_tunneling_factor(T)
            self.assertAlmostEqual(kexp, kact, 4)

    def test_pickle(self):
        """
        Test that a Wigner object can be successfully pickled and unpickled
        with no loss of information.
        """
        import pickle
        tunneling = pickle.loads(pickle.dumps(self.tunneling, -1))
        self.assertAlmostEqual(self.tunneling.frequency.value,
                               tunneling.frequency.value, 2)
        self.assertEqual(self.tunneling.frequency.units,
                         tunneling.frequency.units)

    def test_repr(self):
        """
        Test that a Wigner object can be successfully reconstructed from its
        repr() output with no loss of information.
        """
        namespace = {}
        exec('tunneling = {0!r}'.format(self.tunneling), globals(), namespace)
        self.assertIn('tunneling', namespace)
        tunneling = namespace['tunneling']
        self.assertAlmostEqual(self.tunneling.frequency.value,
                               tunneling.frequency.value, 2)
        self.assertEqual(self.tunneling.frequency.units,
                         tunneling.frequency.units)
Exemple #4
0
class TestWigner(unittest.TestCase):
    """
    Contains unit tests of the :class:`Wigner` class.
    """
    
    def setUp(self):
        """
        A function run before each unit test in this class.
        """
        self.frequency = -2017.96
        self.tunneling = Wigner(
            frequency = (self.frequency,"cm^-1"),
        )
    
    def test_frequency(self):
        """
        Test that the Wigner frequency property was properly set.
        """
        self.assertAlmostEqual(self.tunneling.frequency.value_si, self.frequency, 4)

    def test_calculateTunnelingFactor(self):
        """
        Test the Wigner.calculateTunnelingFactor() method.
        """
        Tlist = numpy.array([300,500,1000,1500,2000])
        kexplist = numpy.array([4.90263, 2.40495, 1.35124, 1.15611, 1.08781])
        for T, kexp in zip(Tlist, kexplist):
            kact = self.tunneling.calculateTunnelingFactor(T)
            self.assertAlmostEqual(kexp, kact, 4)

    def test_pickle(self):
        """
        Test that a Wigner object can be successfully pickled and unpickled
        with no loss of information.
        """
        import cPickle
        tunneling = cPickle.loads(cPickle.dumps(self.tunneling,-1))
        self.assertAlmostEqual(self.tunneling.frequency.value, tunneling.frequency.value, 2)
        self.assertEqual(self.tunneling.frequency.units, tunneling.frequency.units)

    def test_repr(self):
        """
        Test that a Wigner object can be successfully reconstructed from its
        repr() output with no loss of information.
        """
        tunneling = None
        exec('tunneling = {0!r}'.format(self.tunneling))
        self.assertAlmostEqual(self.tunneling.frequency.value, tunneling.frequency.value, 2)
        self.assertEqual(self.tunneling.frequency.units, tunneling.frequency.units)
def reaction(label,
             reactants,
             products,
             transitionState,
             kinetics=None,
             tunneling=''):
    global reactionDict, speciesDict, transitionStateDict
    #label = 'reaction'+transitionState
    if label in reactionDict:
        label = label + transitionState
        if label in reactionDict:
            raise ValueError(
                'Multiple occurrences of reaction with label {0!r}.'.format(
                    label))
    logging.info('Loading reaction {0}...'.format(label))
    reactants = sorted([speciesDict[spec] for spec in reactants])
    products = sorted([speciesDict[spec] for spec in products])
    transitionState = transitionStateDict[transitionState]
    if tunneling.lower() == 'wigner':
        transitionState.tunneling = Wigner(frequency=None)
    elif tunneling.lower() == 'eckart':
        transitionState.tunneling = Eckart(frequency=None,
                                           E0_reac=None,
                                           E0_TS=None,
                                           E0_prod=None)
    elif tunneling == '' or tunneling is None:
        transitionState.tunneling = None
    elif not isinstance(tunneling, TunnelingModel):
        raise ValueError('Unknown tunneling model {0!r}.'.format(tunneling))
    rxn = Reaction(label=label,
                   reactants=reactants,
                   products=products,
                   transitionState=transitionState,
                   kinetics=kinetics)
    reactionDict[label] = rxn

    return rxn
Exemple #6
0
def reaction(label, reactants, products, transitionState=None, tunneling=''):
    """Load a reaction from an input file"""
    global reaction_dict, species_dict, transition_state_dict
    if label in reaction_dict:
        label = label + transitionState
        if label in reaction_dict:
            raise ValueError(
                'Multiple occurrences of reaction with label {0!r}.'.format(
                    label))
    logging.info('Loading reaction {0}...'.format(label))
    reactants = sorted([species_dict[spec] for spec in reactants])
    products = sorted([species_dict[spec] for spec in products])
    if transitionState:
        transitionState = transition_state_dict[transitionState]
    if transitionState and (tunneling == '' or tunneling is None):
        transitionState.tunneling = None
    elif tunneling.lower() == 'wigner':
        transitionState.tunneling = Wigner(frequency=None)
    elif tunneling.lower() == 'eckart':
        transitionState.tunneling = Eckart(frequency=None,
                                           E0_reac=None,
                                           E0_TS=None,
                                           E0_prod=None)

    elif transitionState and not isinstance(tunneling, TunnelingModel):
        raise ValueError('Unknown tunneling model {0!r}.'.format(tunneling))
    rxn = Reaction(label=label,
                   reactants=reactants,
                   products=products,
                   transition_state=transitionState,
                   output_directory=output_directory)

    if isinstance(rxn, Reaction):
        reaction_dict[label] = rxn

    return rxn
Exemple #7
0
 def setUp(self):
     """
     A function run before each unit test in this class.
     """
     self.frequency = -2017.96
     self.tunneling = Wigner(frequency=(self.frequency, "cm^-1"), )