Skip to content

Commit

Permalink
Progress on implementing temperature scanning calculations -- SO--
Browse files Browse the repository at this point in the history
  • Loading branch information
nfaguirrec committed Nov 14, 2023
1 parent b4ccb88 commit cfce9f1
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 8 deletions.
15 changes: 15 additions & 0 deletions core/ElementaryReaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ def __init__(self,
self.__label = None
self.__updateLabel()

# Hidden attributes. Only for using with AMS
self._kf_prefactors_forward = RKFPrefactors()
self._kf_prefactors_backward = RKFPrefactors()


def __eq__(self, other):
"""
Expand Down Expand Up @@ -325,3 +329,14 @@ def replace_site_types( self, site_types_old, site_types_new ):
self.site_types[j] = site_types_new[i]

self.__updateLabel()


def set_temperature( self, temperature ):
"""
Sets the temperature of the reaction. It recalculates the pre-exponential factors if needed.
* ``temperature`` -- Temperature in K
"""

for erxn in self:
erxn.set_temperature( temperature )
10 changes: 10 additions & 0 deletions core/Mechanism.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,3 +345,13 @@ def find_one( self, label ):
"""
return next(rxn for rxn in self if rxn.label().find(label) != -1)


def set_temperature( self, temperature ):
"""
Sets the temperature of the mechanism. It recalculates the pre-exponential factors if needed.
* ``temperature`` -- Temperature in K
"""

for erxn in self:
erxn.set_temperature( temperature )
26 changes: 18 additions & 8 deletions core/RKFLoader.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ def __deriveLatticeAndMechanism( self, results ):
isTS = results.readrkf("EnergyLandscape", "isTS")
reactants = results.readrkf("EnergyLandscape", "reactants")
products = results.readrkf("EnergyLandscape", "products")
prefactorsTemperature = results.readrkf("EnergyLandscape", "prefactorsTemperature")
prefactorsFromReactant = results.readrkf("EnergyLandscape", "prefactorsFromReactant")
prefactorsFromProduct = results.readrkf("EnergyLandscape", "prefactorsFromProduct")

Expand Down Expand Up @@ -491,6 +492,11 @@ def getGasFormationEnergy( mol, energy ):
pe_ratio=pe_ratio,
activation_energy=activationEnergy )

reaction._prefactors_temperature = prefactorsTemperature
reaction._prefactors_model = REACTION_MEDIATED_BY_A_TRANSITION_STATE
reaction._kf_reactants = fileName[idReactant]
reaction._kf_products = fileName[idProduct]

#self.clusterExpansion.extend( [clusterReactant, clusterProduct] )
self.mechanism.append( reaction )

Expand Down Expand Up @@ -543,14 +549,18 @@ def getGasFormationEnergy( mol, energy ):
activationEnergy = 0.0 if state2Energy[idState]<energy else state2Energy[idState]-energy

reaction = ElementaryReaction( site_types=cluster_data['site_types'],
final_entity_number=cluster_data['entity_number'],
neighboring=cluster_data['neighboring'],
initial=speciesFState,
final=cluster_data['species'],
reversible=True,
pre_expon=prefactorAdsorption,
pe_ratio=pe_ratio,
activation_energy=activationEnergy )
final_entity_number=cluster_data['entity_number'],
neighboring=cluster_data['neighboring'],
initial=speciesFState,
final=cluster_data['species'],
reversible=True,
pre_expon=prefactorAdsorption,
pe_ratio=pe_ratio,
activation_energy=activationEnergy)

reaction._prefactorsTemperature = prefactorsTemperature
reaction._kf_reactants = fileName[idReactant]
reaction._kf_fragments = fileName[idProduct]

self.clusterExpansion.extend( [clusterState] )
self.mechanism.append( reaction )
Expand Down
70 changes: 70 additions & 0 deletions core/RKFPrefactors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import chemparse

__all__ = ['RKFPrefactors']

class RKFPrefactors:
"""
Contains the information needed to calculate the prefactors based on kf files from an AMS calculation
* ``temperature`` --
* ``kf_initial`` --
* ``kf_final`` --
Example
kind = MEDIATED_BY_A_TRANSITION_STATE
kf_initial = 'State-1_MIN.rkf'
kf_final = 'State-4_TS_1-3.rkf'
kind = NON_ACTIVATED_EXOTHERMIC_DESORPTION
kf_initial = 'State-1_MIN.rkf'
kf_final = ['Fragment-1.rkf', 'Fragment-2.rkf']
kind = NON_ACTIVATED_EXOTHERMIC_ADSORPTION
kf_initial = ['Fragment-1.rkf', 'Fragment-2.rkf']
kf_final = None
"""

UNSPECIFIED = -1
MEDIATED_BY_A_TRANSITION_STATE = 0
NON_ACTIVATED_EXOTHERMIC_ADSORPTION = 1
NON_ACTIVATED_EXOTHERMIC_DESORPTION = 2

def __init__(self, temperature=None, kind=None, kf_initial=None, kf_final=None ):
"""
Creates a new RKFPrefactors object.
"""
self.temperature = temperature
self.kind = kind
self.kf_initial = kf_initial
self.kf_final = kf_final


def __eq__( self, other ):
"""
Returns True if both objects are the same (same temperature, and kf files)
* ``other`` --
"""
if( type(other) == int and other == Species.UNSPECIFIED ):
return False

if( self.symbol == other.symbol ):
return True
else:
return False


def __hash__(self):
"""
Returns a hash based on the symbol.
"""
return hash(self.symbol)


def __str__( self ):
"""
Translates the object to a string
"""
output = self.symbol
return output
3 changes: 3 additions & 0 deletions core/ZacrosJob.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ def check_molar_fraction(settings=Settings, species_list=SpeciesList):
self.mechanism = mechanism
if( type(mechanism) == list ): self.mechanism = Mechanism(mechanism)

if( 'temperature' in kwargs['settings'] ):
self.mechanism.set_temperature( kwargs['settings']['temperature'] )

#if( set(map(type, self.mechanism.site_types_set())) == {int} )

if( not self.mechanism.site_types_set().issubset( self.lattice.site_types_set() ) ):
Expand Down

0 comments on commit cfce9f1

Please sign in to comment.