def setUp(self): """ A function run before each unit test in this class. """ self.frequency = -2017.96 self.E0_reac = -295.563 self.E0_TS = -12.7411 self.E0_prod = (-10.2664) + (-253.48) self.tunneling = Eckart( frequency=(self.frequency, "cm^-1"), E0_reac=(self.E0_reac, "kJ/mol"), E0_TS=(self.E0_TS, "kJ/mol"), E0_prod=(self.E0_prod, "kJ/mol"), )
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
def setUp(self): """ A function run before each unit test in this class. """ self.frequency = -2017.96 self.E0_reac = -295.563 self.E0_TS = -12.7411 self.E0_prod = (-10.2664) + (-253.48) self.tunneling = Eckart( frequency = (self.frequency,"cm^-1"), E0_reac = (self.E0_reac,"kJ/mol"), E0_TS = (self.E0_TS,"kJ/mol"), E0_prod = (self.E0_prod,"kJ/mol"), )
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
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
class TestEckart(unittest.TestCase): """ Contains unit tests of the :class:`Eckart` class. """ def setUp(self): """ A function run before each unit test in this class. """ self.frequency = -2017.96 self.E0_reac = -295.563 self.E0_TS = -12.7411 self.E0_prod = (-10.2664) + (-253.48) self.tunneling = Eckart( frequency=(self.frequency, "cm^-1"), E0_reac=(self.E0_reac, "kJ/mol"), E0_TS=(self.E0_TS, "kJ/mol"), E0_prod=(self.E0_prod, "kJ/mol"), ) def test_frequency(self): """ Test that the Eckart frequency property was properly set. """ self.assertAlmostEqual(self.tunneling.frequency.value_si, self.frequency, 4) def test_E0_reac(self): """ Test that the Eckart E0_reac property was properly set. """ self.assertAlmostEqual(self.tunneling.E0_reac.value_si * 0.001, self.E0_reac, 4) def test_E0_TS(self): """ Test that the Eckart E0_TS property was properly set. """ self.assertAlmostEqual(self.tunneling.E0_TS.value_si * 0.001, self.E0_TS, 4) def test_E0_prod(self): """ Test that the Eckart E0_prod property was properly set. """ self.assertAlmostEqual(self.tunneling.E0_prod.value_si * 0.001, self.E0_prod, 4) def test_calculateTunnelingFactor(self): """ Test the Eckart.calculateTunnelingFactor() method. """ Tlist = numpy.array([300, 500, 1000, 1500, 2000]) kexplist = numpy.array([1623051., 7.69349, 1.46551, 1.18111, 1.09858]) for T, kexp in zip(Tlist, kexplist): kact = self.tunneling.calculateTunnelingFactor(T) self.assertAlmostEqual(kexp, kact, delta=1e-3 * kexp) def test_pickle(self): """ Test that an Eckart 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) self.assertAlmostEqual(self.tunneling.E0_reac.value, tunneling.E0_reac.value, 3) self.assertEqual(self.tunneling.E0_reac.units, tunneling.E0_reac.units) self.assertAlmostEqual(self.tunneling.E0_TS.value, tunneling.E0_TS.value, 3) self.assertEqual(self.tunneling.E0_TS.units, tunneling.E0_TS.units) self.assertAlmostEqual(self.tunneling.E0_prod.value, tunneling.E0_prod.value, 3) self.assertEqual(self.tunneling.E0_prod.units, tunneling.E0_prod.units) def test_repr(self): """ Test that an Eckart 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) self.assertAlmostEqual(self.tunneling.E0_reac.value, tunneling.E0_reac.value, 3) self.assertEqual(self.tunneling.E0_reac.units, tunneling.E0_reac.units) self.assertAlmostEqual(self.tunneling.E0_TS.value, tunneling.E0_TS.value, 3) self.assertEqual(self.tunneling.E0_TS.units, tunneling.E0_TS.units) self.assertAlmostEqual(self.tunneling.E0_prod.value, tunneling.E0_prod.value, 3) self.assertEqual(self.tunneling.E0_prod.units, tunneling.E0_prod.units)
class TestEckart(unittest.TestCase): """ Contains unit tests of the :class:`Eckart` class. """ def setUp(self): """ A function run before each unit test in this class. """ self.frequency = -2017.96 self.E0_reac = -295.563 self.E0_TS = -12.7411 self.E0_prod = (-10.2664) + (-253.48) self.tunneling = Eckart( frequency = (self.frequency,"cm^-1"), E0_reac = (self.E0_reac,"kJ/mol"), E0_TS = (self.E0_TS,"kJ/mol"), E0_prod = (self.E0_prod,"kJ/mol"), ) def test_frequency(self): """ Test that the Eckart frequency property was properly set. """ self.assertAlmostEqual(self.tunneling.frequency.value_si, self.frequency, 4) def test_E0_reac(self): """ Test that the Eckart E0_reac property was properly set. """ self.assertAlmostEqual(self.tunneling.E0_reac.value_si*0.001, self.E0_reac, 4) def test_E0_TS(self): """ Test that the Eckart E0_TS property was properly set. """ self.assertAlmostEqual(self.tunneling.E0_TS.value_si*0.001, self.E0_TS, 4) def test_E0_prod(self): """ Test that the Eckart E0_prod property was properly set. """ self.assertAlmostEqual(self.tunneling.E0_prod.value_si*0.001, self.E0_prod, 4) def test_calculateTunnelingFactor(self): """ Test the Eckart.calculateTunnelingFactor() method. """ Tlist = numpy.array([300,500,1000,1500,2000]) kexplist = numpy.array([1623051., 7.69349, 1.46551, 1.18111, 1.09858]) for T, kexp in zip(Tlist, kexplist): kact = self.tunneling.calculateTunnelingFactor(T) self.assertAlmostEqual(kexp, kact, delta=1e-3*kexp) def test_pickle(self): """ Test that an Eckart 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) self.assertAlmostEqual(self.tunneling.E0_reac.value, tunneling.E0_reac.value, 3) self.assertEqual(self.tunneling.E0_reac.units, tunneling.E0_reac.units) self.assertAlmostEqual(self.tunneling.E0_TS.value, tunneling.E0_TS.value, 3) self.assertEqual(self.tunneling.E0_TS.units, tunneling.E0_TS.units) self.assertAlmostEqual(self.tunneling.E0_prod.value, tunneling.E0_prod.value, 3) self.assertEqual(self.tunneling.E0_prod.units, tunneling.E0_prod.units) def test_repr(self): """ Test that an Eckart 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) self.assertAlmostEqual(self.tunneling.E0_reac.value, tunneling.E0_reac.value, 3) self.assertEqual(self.tunneling.E0_reac.units, tunneling.E0_reac.units) self.assertAlmostEqual(self.tunneling.E0_TS.value, tunneling.E0_TS.value, 3) self.assertEqual(self.tunneling.E0_TS.units, tunneling.E0_TS.units) self.assertAlmostEqual(self.tunneling.E0_prod.value, tunneling.E0_prod.value, 3) self.assertEqual(self.tunneling.E0_prod.units, tunneling.E0_prod.units)