pyRBM.Build package

Submodules

pyRBM.Build.Classes module

class Classes(allow_base_model_classes: bool = True)

Bases: object

addClass(class_name: str, class_measurement_unit: str, class_restriction: str = 'None') None
returnBuiltInClasses() list[list[str]]
returnClassDict() dict[str, dict[str, str]]

pyRBM.Build.Compartment module

pyRBM.Build.ProcessDescriptionFiles module

Module to load compartments from file and create a function to be used in model creation.

class LoadedCompartments(compartment_type_dict)

Bases: object

loadCompartmentsFromJSONFile(filename)

pyRBM.Build.RuleMatching module

Generic framework to match metarules to compartments, find all compartment indices that match and rewrite the propensities and stoichiometries to use array indices.

isSubtypeOf(parent_type: str, child_type: str) bool

Indicates whether the “child_type” rule type is a subtype of the parent_type.

Current returns parent_type == child_type.

In the future this should be determined by a tree based hierachical graph.

obtainPropensity(rule: dict[str, Any], compartments: list[dict[str, Any]], builtin_classes: list[list[str]]) list[str]
obtainStochiometry(rule: dict[str, Any], compartments: list[dict[str, Any]]) list[list[numpy.float64]]

Remaps the rule to fit the class size found in each compartment

Example: Original Rule mapping {0:”Class1”, 1:”Class2”} (size of input to Stochiometry and Propensity functions: 2)

Compartment and Fitted Rule mapping {0:”ClassA”, 1:”Class1”, 2:”ClassB”, 3:”Class2”} (size of input to Stochiometry and Propensity functions: 4)

Parameters:
  • rule (-) – the Rule that we are remapping the propensity and stochiometry to fit each compartment.

  • compartments (-) – compartment instances (a list the length of rule.types) that fit each of the rule.types.

Returns: list of expanded stochiometries for all rule compartments

returnMatchedRulesDict(rules: dict[str, dict[str, Any]], compartments: dict[str, dict[str, Any]], builtin_classes: list[list[str]] | None) dict[str, dict[str, Any]]
returnRuleMatchingIndices(rules: dict[str, dict[str, Any]], compartments: dict[str, dict[str, Any]]) dict[str, list[int]]

pyRBM.Build.RuleTemplates module

Provides classes to initialise common types of rules with simpler init functions.

class ExitEntranceRule(target: str, transport_class: str, transport_amount: float | int, propensity: str, propensity_classes: list[str] | str, rule_name: str = 'EXIT/ENTRANCE RULE')

Bases: Rule

A template for either an exit rule or an entrance rule for a single class for a single compartment.

class SingleLocationProductionRule(target: str, reactant_classes: list[str] | str, reactant_amount: list[Union[float, int]], product_classes: list[str] | str, product_amount: list[Union[float, int]], propensity: str, propensity_classes: list[str] | str, rule_name: str = 'SINGLE LOCATION PRODUCTION RULE')

Bases: SingleLocationRule

class SingleLocationRule(target: str, propensity: str, stoichiomety, propensity_classes: list[str] | str, stoichiometry_classes: str | list[str], rule_name: str = 'SINGLE LOCATION RULE')

Bases: Rule

A template for a rule at a single compartment.

class TransportRule(source: str, target: str, transport_class: str, propensities: list[str], transport_amount: float | int, propensity_classes: list[list[str]], rule_name: str = 'TRANSPORT RULE')

Bases: Rule

A template for a transport rule for a single class between a single source compartment and a single target compartment.

pyRBM.Build.Rules module

Defines a Rule class and a Rules helper class

class Rule(rule_name: str, targets: Sequence[str])

Bases: object

addLinearStoichiomety(target_indices: list[int], stoichiometies, required_target_classes: list[list[str]]) None
addSimplePropensityFunction(target_indices: list[int], values, required_target_classes: list[list[str]]) None
addWaitTimeDistribution(wait_time_distrib: str | Distribution)
checkRuleDefinition(builtin_class_symbols: dict[str, sympy.core.symbol.Symbol] | None, compartments_constant_symbols: dict[str, sympy.core.symbol.Symbol] | None) None
Perform the following validation on the rule definition:
  1. self.stoichiometies, self.propensities, self.propensity_classes are of the same length as the rule targets.

  2. each element of self.stoichiometies, self.propensities, self.propensity_classes are not None.

  3. each propensity at index i, in self.propensities, evaluates to a number when the builtin_class_symbols,

    compartments_constant_symbols and the propensity_classes[i] symbols are evaluated as 1 (i.e. the propensity is a valid numerical formula).

Parameters:
  • builtin_class_symbols

  • compartments_constant_symbols

returnRuleDict() dict[str, Any]
validateFormula(formula: str, class_symbols: dict[str, sympy.core.symbol.Symbol], safe_num: float | int = 1) bool
class Rules(defined_classes: Iterable[str], compartment_constants: list[str] | None)

Bases: object

addRule(rule: Rule) None
addRules(rules: Iterable[Rule] | Rule) None
removeTypeRequirement(default_type: str = 'any') None

Used to remove the user set (or unset) type requirements for all rules by setting to the default_type. Used for no-compartment models. Should not be used for any multi-compartmental models.

returnMetaRuleDict() dict[str, dict[str, Any]]
isNonDefaultTargetArray(target_array: list[str]) bool

Checks if the provided target_array contains any non default (i.e. non None or “Any”/”any”) target requirmments. :returns: True if any none default target requirment in target_array, False otherwise. :rtype: bool

returnSympyClassVarsDict(classes: list[str]) dict[str, sympy.core.symbol.Symbol] | None

pyRBM.Build.Utils module

createArgsDict(default_values_dict, user_provided_dict)
createEuclideanDistanceMatrix(lats: Sequence[float | int], longs: Sequence[float | int]) ndarray
haversine(lon1: float | int, lat1: float | int, lon2: float | int, lat2: float | int) float

Calculate the great circle distance between two points on the earth (specified in decimal degrees)

Module contents