PGM Example - Reaction Finder Classes and Functions
Jump to navigation
Jump to search
Navigation: PGMs ➔ Example PGM Files ➔ Reaction Finder Classes and Functions
Related Links: Defining a Class, Defining a Function
Example PGM with ReactionFinder Classes and Functions
;=========================================================================================================
; Project Used: Any with a Reaction Block.
;=========================================================================================================
; Description of the ReactionFinder Class function ---
; This class frees the user from the problem of the reaction index changing when a new reaction
; is added to the reaction file before the controlled reaction(s). The "Init" function should be called
; in the "InitialiseSolution" subroutine and this finds the index of the required reaction.
; The "SetExtent" function then sets the extent of the reaction as a fraction.
;==========================================================================================================
Class Class_ReactionFinder
;--- input variables ------
Textbreak
String ReqdUnit@{Tag} ;the unit containing the reaction file
String ReqdReaction* ;the actual reaction that will be controlled
Real ReqdExtent*("Frac","%") ;the required reaction extent
;---- Output variables ------
long ReactionIndex@ ;the actual reaction index number in the unit
long totalNumReactions@ ;total number of reactions in the reaction file
;--- local variables ------
String NumReactions, ReactionName, RBReact, ReactionTag, errormsg
long Minlength, i, reactioncomp
Sub Init()
ReqdUnit = ClassTag()
if (strlen(ReqdUnit) > 0)
i = 1
ReactionIndex = 0
NumReactions = Concatenate(ReqdUnit, ".RB.NoOfReactions")
totalNumReactions = [NumReactions]
while (i <= totalNumReactions)
ReactionName = Concatenate(ReqdUnit, ".RB.R", IntToStr(i), ".Reaction")
RBReact = [ReactionName]
Minlength = Min(strlen(RBReact),strlen(ReqdReaction))
if (Minlength > 0)
reactioncomp = StriCmp(Left(RBReact,Minlength), Left(ReqdReaction,Minlength))
if (reactioncomp == 0)
ReactionTag = Concatenate(ReqdUnit, ".RB.R", IntToStr(i), ".Extent.Required (%)")
ReactionIndex = i
i = totalNumReactions + 1
endif
endif
i = i + 1
endwhile
if (ReactionIndex == 0)
errormsg = Concatenate("The reaction ", ReqdReaction, " not found in ", ReqdUnit)
lognote(errormsg)
endif
endif
EndSub
Sub SetExtent()
if (ReactionIndex > 0)
[ReactionTag] = ReqdExtent
endif
EndSub
EndClass