pep.pep

Functions

print_token_by_line(v) Prints tokens separated by spaces on their original line (with line numbering)
processPostfixOperator(postfixStack, operator) Compares the provided operator with a postfix stack to determine where to place a new operator (output list or stack)
process_tokens(tokens, parent, index) Process tokens recurently and return a P system structure (or a subcomponent of the same type as parent)
readInputFile(filename[, printTokens]) parses the given input file and produces a P system object
tokenize(code) generate a token list of input text

Classes

DistributionFunction() Distribution function class (list of distribution rules)
DistributionRule() Class for the distribution rules that make up a program, together with the production rules
Membrane([parentMembrane]) Membrane class, that can contain other membranes or be part of another membrane
MembraneStructure() P system membrane structure (list of structural elements)
NumericalPsystem() Numerical P systems class
OperatorType Enumeration of operator types, ordered by precedence in calculus
Pobject([name, value]) Mutable objects that are needed in order to allow all membranes that use the P object to globally modify the object
ProductionFunction() Production function class that stores expressions using the postfix (reversed polish) form
Program() Program class
Token(type, value, line, column)
class pep.pep.DistributionFunction[source]

Distribution function class (list of distribution rules)

Variables:
  • proportionTotal (int) – the sum of all proportions
  • expression (str) – string representation of the distribution function
distribute(newValue)[source]

Update the variables referenced in the distribution rules according to the specified proportions :newValue: a value that has to be distributed to the variables based on the proportions specified in the distribution rules

class pep.pep.DistributionRule[source]

Class for the distribution rules that make up a program, together with the production rules

Variables:
  • proportion (int) –
  • variable (Pobject) –
print(indentSpaces=2, toString=False)[source]

Print a distribution rule with a given indentation level

IndentSpaces:number of spaces used for indentation
ToString:write to a string instead of stdout
Returns:string print of the rule if toString = True otherwise returns None
class pep.pep.Membrane(parentMembrane=None)[source]

Membrane class, that can contain other membranes or be part of another membrane

Variables:
  • variables (list(Pobject)) – array of P objects
  • programs (list(Program)) – list of Program objects
  • chosenProgramNr (int|list) – the program nr that was chosen for execution OR array of chosen program numbers when enzymes are used
  • newValue (double|list(double)) – the value that was produced during the previous production phase OR array of values when using enzymes
  • enzymes (list(Pobject)) – array of enzyme P objects
  • parent (Membrane) – parent membrane (Membrane object)
  • children (dict) – map (dictioanry) between String membrane_name: Membrane object
print(indentSpaces=2, toString=False, withPrograms=False)[source]

Print a membrane with a given indentation level

IndentSpaces:number of spaces used for indentation
ToString:write to a string instead of stdout
WithPrograms:print out the programs from each membrane, along with the membrane variables
Returns:string print of the membrane if toString = True otherwise returns None
class pep.pep.MembraneStructure[source]

P system membrane structure (list of structural elements)

class pep.pep.NumericalPsystem[source]

Numerical P systems class

Variables:
  • H (array(str)) – array of strings (names of membranes)
  • membranes (dict) – map (dictioanry) between String membrane_name: Membrane object
  • structure (MembraneStructure) – MembraneStructure object (list of structural elements) [1 [2 ]2 ]1
  • variables (list(Pobject)) – list of Pobjects that appear throughtout the P system
  • enzymes (list(Pobject)) – list of enzyme Pobjects that appear throughtout the P system
  • csvFile (file) – file used for Comma Separated Value output
openCsvFile()[source]

Opens a .csv (Comma Separated Value) file where the values of all variables and enzymes are printed at each simulation step The output file is named using the pattern pep_DAY-MONTH-YEAR_HOUR-MINUTE-SECOND.csv

print(indentSpaces=2, toString=False, withPrograms=False)[source]

Print the entire Numerical P system with a given indentation level

IndentSpaces:number of spaces used for indentation
ToString:write to a string instead of stdout
WithPrograms:print out the programs from each membrane, along with the membrane variables
Returns:string print of the membrane if toString = True otherwise returns None
runSimulationStep()[source]

Runs 1 simulation step consisting of executing one program (production & dispersion functions) for all membranes that have programs If a membrane has more than one program, one is chosen randomly for execution

simulate(stepByStepConfirm=False, printEachSystemState=True, maxSteps=-1, maxTime=-1)[source]

Simulates the numericP system until one of the imposed limits is reached

StepByStepConfirm:
 True / False - whether or not to wait for confirmation before starting the next simulation step
PrintEachSystemState:
 True / False - whether or not to print the P system state after the execution ofeach simulation step
MaxSteps:The maximmum number of simulation steps to run
MaxTime:The maximum time span that the entire simulation can last
class pep.pep.OperatorType[source]

Enumeration of operator types, ordered by precedence in calculus

class pep.pep.Pobject(name='', value=0)[source]

Mutable objects that are needed in order to allow all membranes that use the P object to globally modify the object

Variables:
  • name (str) –
  • value (double) –
  • wasConsumed (boolean) – was consumed in production function
class pep.pep.ProductionFunction[source]

Production function class that stores expressions using the postfix (reversed polish) form

Variables:
  • infixExpression (str) – string representation of the original expression from the input file (written in infix form)
  • postfixStack (list) – stack of operands and operators (auxiliary for postfix form)
  • items (list) – list of operands and operators written in postfix (reverse polish) form
evaluate()[source]

Evaluates the postfix form of a production function and returns the computed value. During the evaluation, Pobject references are replaced with their value. :returns: the computed value of the production function, as a numeric value

class pep.pep.Program[source]

Program class

Variables:
isActivatedByEnzyme()[source]

Checks whether the production function activation condition Enzyme > min(PROD_FUNCTION_VARIABLES) is true :returns: True / False

print(indentSpaces=2, toString=False)[source]

Print a program with a given indentation level

IndentSpaces:number of spaces used for indentation
ToString:write to a string instead of stdout
Returns:string print of the rule if toString = True otherwise returns None
class pep.pep.Token(type, value, line, column)
column

Alias for field number 3

line

Alias for field number 2

type

Alias for field number 0

value

Alias for field number 1

pep.pep.print_token_by_line(v)[source]

Prints tokens separated by spaces on their original line (with line numbering)

pep.pep.processPostfixOperator(postfixStack, operator)[source]

Compares the provided operator with a postfix stack to determine where to place a new operator (output list or stack)

PostfixStack:stack used for operators
Operator:OperatorType variable
Returns:postfixStack, outputList - outputList == array of OperatorType elements that have been popped from the stack
pep.pep.process_tokens(tokens, parent, index)[source]

Process tokens recurently and return a P system structure (or a subcomponent of the same type as parent)

Tokens:the list of tokens to be processed
Parent:an object that represents the type of the result
Index:the start index in the list of tokens
Returns:index - the current index in the token list (after finishing this component)
Returns:result - an object that is the result of processing the input parent and tokens
pep.pep.readInputFile(filename, printTokens=False)[source]

parses the given input file and produces a P system object

Filename:string path to the file that will be parsed
Returns:P system object
pep.pep.tokenize(code)[source]

generate a token list of input text adapted from https://docs.python.org/3/library/re.html#writing-a-tokenizer