API Reference
qspy.core
QSPy Core Model Extensions and Utilities
This module extends the PySB modeling framework with QSPy-specific features for quantitative systems pharmacology (QSP) workflows. It provides enhanced Model and Monomer classes, operator overloads for semantic annotation, and utilities for metadata, logging, and summary/diagram generation.
Classes:
Name | Description |
---|---|
Model : QSPy extension of the PySB Model class with metadata, summary, and diagram support. |
|
Monomer : QSPy extension of the PySB Monomer class with functional tag support. |
|
Functions:
Name | Description |
---|---|
mp_lshift : Overloads '<<' for MonomerPattern/ComplexPattern to create Initial objects. |
|
mp_invert : Overloads '~' for MonomerPattern/ComplexPattern to create Observables with auto-naming. |
|
mp_gt : Overloads '>' for MonomerPattern/ComplexPattern to create Observables with custom names. |
|
_make_mono_string : Utility to generate string names for MonomerPatterns. |
|
_make_complex_string : Utility to generate string names for ComplexPatterns. |
|
Operator Overloads
- MonomerPattern/ComplexPattern << value : Create Initial objects.
- ~MonomerPattern/ComplexPattern : Create Observable objects with auto-generated names.
- MonomerPattern/ComplexPattern > "name" : Create Observable objects with custom names.
- Monomer @ tag : Attach a functional tag to a Monomer.
Examples:
>>> from qspy.core import Model, Monomer
>>> m = Monomer("A", ["b"])
>>> m @ PROTEIN.LIGAND
>>> model = Model()
>>> model.with_units("nM", "min", "uL")
>>> ~m(b=None)
Observable('A_u', m(b=None))
Model
Bases: Model
QSPy extension of the PySB Model class.
Adds QSPy-specific utilities, metadata handling, and summary/diagram generation to the standard PySB Model. Supports custom units, logging, and functional tagging.
Methods:
Name | Description |
---|---|
with_units |
Set simulation units for concentration, time, and volume. |
component_names |
List of component names in the model. |
qspy_metadata |
Dictionary of QSPy metadata for the model. |
summarize |
Generate a Markdown summary of the model and optionally a diagram. |
Source code in qspy\core.py
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 |
|
component_names
property
List the names of all components in the model.
Returns:
Type | Description |
---|---|
list of str
|
Names of model components. |
qspy_metadata
property
Return QSPy metadata dictionary for the model.
Returns:
Type | Description |
---|---|
dict
|
Metadata dictionary if available, else empty dict. |
markdown_summary(path=SUMMARY_DIR, include_diagram=True)
Generate a Markdown summary of the model and optionally a diagram.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path
|
str or Path
|
Output path for the summary file (default: SUMMARY_DIR). |
SUMMARY_DIR
|
include_diagram
|
bool
|
Whether to include a model diagram if SBMLDiagrams is available (default: True). |
True
|
Returns:
Type | Description |
---|---|
None
|
|
Source code in qspy\core.py
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 |
|
with_units(concentration='mg/L', time='h', volume='L')
staticmethod
Set simulation units for the model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
concentration
|
str
|
Concentration units (default "mg/L"). |
'mg/L'
|
time
|
str
|
Time units (default "h"). |
'h'
|
volume
|
str
|
Volume units (default "L"). |
'L'
|
Source code in qspy\core.py
Monomer
Bases: Monomer
QSPy extension of the PySB Monomer class.
Adds support for functional tags and operator overloading for semantic annotation.
Methods:
Name | Description |
---|---|
__matmul__ |
Attach a functional tag to the monomer using the '@' operator. |
__imatmul__ |
Attach a functional tag to the monomer in-place using the '@=' operator. |
__repr__ |
String representation including the functional tag if present. |
Source code in qspy\core.py
452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 |
|
__imatmul__(other)
Attach a functional tag to the monomer in-place using the '@=' operator.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other
|
Enum
|
Enum member representing the functional tag. |
required |
Returns:
Type | Description |
---|---|
Monomer
|
The monomer instance with the functional tag set. |
Source code in qspy\core.py
__init__(*args, **kwargs)
Initialize a Monomer with optional functional tag.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*args
|
Arguments passed to the PySB Monomer constructor. |
()
|
|
**kwargs
|
Arguments passed to the PySB Monomer constructor. |
()
|
Source code in qspy\core.py
__matmul__(other)
Attach a functional tag to the monomer using the '@' operator.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other
|
Enum
|
Enum member representing the functional tag. |
required |
Returns:
Type | Description |
---|---|
Monomer
|
The monomer instance with the functional tag set. |
Source code in qspy\core.py
__pow__(compartment)
Overload the '**' operator to allow monomers to be passed with a compartment.
This is a shortcut for creating a MonomerPattern with a compartment:
i.e., monomer ** compartment
is equivalent to monomer() ** compartment
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
compartment
|
Compartment
|
The compartment in which the monomer pattern resides. |
required |
Returns:
Type | Description |
---|---|
MonomerPattern
|
A MonomerPattern from calling the monomer with the compartment. |
Source code in qspy\core.py
__repr__()
Return a string representation of the monomer, including the functional tag if present.
Returns:
Type | Description |
---|---|
str
|
String representation of the monomer. |
Source code in qspy\core.py
mp_gt(self, other)
Overload the '>' operator for MonomerPattern and ComplexPattern.
Allows creation of Observable objects with a custom name using the syntax: pattern > "observable_name"
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other
|
str
|
Name for the observable. |
required |
Returns:
Type | Description |
---|---|
Observable
|
Observable object with the specified name. |
Raises:
Type | Description |
---|---|
ValueError
|
If the provided name is not a string. |
Source code in qspy\core.py
mp_invert(self)
Overload the '~' operator for MonomerPattern and ComplexPattern.
Allows creation of Observable objects using the syntax: ~pattern
Returns:
Type | Description |
---|---|
Observable
|
Observable object with an auto-generated name. |
Source code in qspy\core.py
mp_lshift(self, value)
Overload the '<<' operator for MonomerPattern and ComplexPattern.
Allows creation of Initial objects using the syntax: monomer_pattern << value
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value
|
float or Parameter
|
Initial value for the pattern. |
required |
Returns:
Type | Description |
---|---|
Initial
|
Initial object for the pattern. |
Source code in qspy\core.py
qspy.config
QSPy Configuration Module
This module centralizes configuration constants for QSPy, including logging, unit defaults, output/reporting directories, and versioning information.
Attributes:
Name | Type | Description |
---|---|---|
LOGGER_NAME |
str
|
Name of the logger used throughout QSPy. |
LOG_PATH |
Path
|
Path to the QSPy log file. |
DEFAULT_UNITS |
dict
|
Default units for concentration, time, and volume. |
METADATA_DIR |
Path
|
Directory for storing model metadata files. |
SUMMARY_DIR |
Path
|
Path for the model summary markdown file. |
QSPY_VERSION |
str
|
The current version of QSPy. |
set_log_path(path)
Set the log file path for QSPy.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path
|
Path
|
The new log file path. |
required |
set_logger_name(name)
Set the logger name for QSPy.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
The new logger name. |
required |
set_output_dir(path)
Set the output directory for QSPy reports and metadata.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path
|
Path
|
The new output directory path. |
required |
Source code in qspy\config.py
qspy.contexts.contexts
QSPy Context Managers for Model Construction
This module provides context managers and utilities for structured, validated construction of quantitative systems pharmacology (QSP) models using QSPy. Each context manager encapsulates the logic for defining a specific model component (parameters, compartments, monomers, expressions, rules, initials, observables), ensuring type safety, unit checking, and extensibility.
Classes:
Name | Description |
---|---|
parameters : Context manager for defining model parameters |
|
compartments : Context manager for defining model compartments. |
|
monomers : Context manager for defining model monomers with optional functional tags. |
|
expressions : Context manager for defining model expressions |
|
rules : Context manager for defining model rules |
|
pk_macros : Stub context manager for future pharmacokinetic macro support. |
|
Functions:
Name | Description |
---|---|
initials |
|
observables |
|
Examples:
compartments
Bases: ComponentContext
Context manager for defining model compartments in a QSPy model.
Provides validation and creation logic for compartments.
Methods:
Name | Description |
---|---|
_validate_value |
Validate the size for a compartment. |
create_component |
Create a compartment component. |
Source code in qspy\contexts\contexts.py
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 |
|
create_component(name, size, dimensions)
staticmethod
Create a compartment component.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
Name of the compartment. |
required |
size
|
Parameter or Expression
|
Size of the compartment. |
required |
Returns:
Type | Description |
---|---|
Compartment
|
The created compartment. |
Source code in qspy\contexts\contexts.py
expressions
Bases: ComponentContext
Context manager for defining model expressions in a QSPy model.
Provides validation and creation logic for expressions.
Methods:
Name | Description |
---|---|
_validate_value |
Validate the value for an expression. |
create_component |
Create an expression component. |
Source code in qspy\contexts\contexts.py
create_component(name, expr)
staticmethod
Create an expression component.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
Name of the expression. |
required |
expr
|
Expr
|
The sympy expression. |
required |
Returns:
Type | Description |
---|---|
Expression
|
The created expression. |
Source code in qspy\contexts\contexts.py
monomers
Bases: ComponentContext
Context manager for defining model monomers in a QSPy model.
Provides validation and creation logic for monomers, including optional functional tags.
Methods:
Name | Description |
---|---|
_validate_value |
Validate the tuple for monomer definition. |
create_component |
Create a monomer component. |
Source code in qspy\contexts\contexts.py
268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 |
|
create_component(name, sites, site_states, functional_tag)
staticmethod
Create a monomer component.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
Name of the monomer. |
required |
sites
|
list
|
List of site names. |
required |
site_states
|
dict
|
Dictionary of site states. |
required |
functional_tag
|
Enum or None
|
Functional tag for the monomer. |
required |
Returns:
Type | Description |
---|---|
Monomer
|
The created monomer. |
Source code in qspy\contexts\contexts.py
parameters
Bases: ComponentContext
Context manager for defining model parameters in a QSPy model.
Provides validation and creation logic for parameters, supporting both numeric and symbolic (sympy.Expr) values.
Methods:
Name | Description |
---|---|
_validate_value |
Validate the value and unit for a parameter. |
create_component |
Create a parameter or expression component. |
Source code in qspy\contexts\contexts.py
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 |
|
__exit__(exc_type, exc_val, exc_tb)
Exit the parameter context and perform unit checking.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
exc_type
|
type
|
Exception type, if any. |
required |
exc_val
|
Exception
|
Exception value, if any. |
required |
exc_tb
|
traceback
|
Traceback, if any. |
required |
Returns:
Type | Description |
---|---|
None
|
|
Source code in qspy\contexts\contexts.py
create_component(name, value, unit)
staticmethod
Create a parameter or expression component.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
Name of the parameter. |
required |
value
|
int, float, or sympy.Expr
|
Value of the parameter or a sympy expression. |
required |
unit
|
str or None
|
Unit for the parameter. |
required |
Returns:
Type | Description |
---|---|
Parameter or Expression
|
The created parameter or expression. |
Source code in qspy\contexts\contexts.py
rules
Bases: ComponentContext
Context manager for defining model rules in a QSPy model.
Provides validation and creation logic for rules, supporting both reversible and irreversible forms.
Methods:
Name | Description |
---|---|
_validate_value |
Validate the tuple for rule definition. |
create_component |
Create a rule component. |
Source code in qspy\contexts\contexts.py
427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 |
|
create_component(name, rxp, rate_forward, rate_reverse)
staticmethod
Create a rule component.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
Name of the rule. |
required |
rxp
|
RuleExpression
|
The rule expression. |
required |
rate_forward
|
Parameter or Expression
|
Forward rate parameter or expression. |
required |
rate_reverse
|
Parameter or Expression or None
|
Reverse rate parameter or expression (if reversible). |
required |
Returns:
Type | Description |
---|---|
Rule
|
The created rule. |
Source code in qspy\contexts\contexts.py
initials()
Context manager for defining initial conditions in a QSPy model.
Tracks which initials are added within the context and logs them.
Yields:
Type | Description |
---|---|
None
|
|
Source code in qspy\contexts\contexts.py
macros()
Context manager for managing macros in a QSPy model.
Yields:
Type | Description |
---|---|
None
|
|
Source code in qspy\contexts\contexts.py
observables()
Context manager for defining observables in a QSPy model.
Yields:
Type | Description |
---|---|
None
|
|
Source code in qspy\contexts\contexts.py
qspy.contexts.base
QSPy Base Context Infrastructure
This module provides the abstract base class for QSPy context managers, which enable structured and validated construction of model components (parameters, monomers, compartments, etc.) in a PySB/QSPy model. The ComponentContext class handles introspection, variable tracking, and component injection for both manual and automatic (module-level) usage.
Classes:
Name | Description |
---|---|
ComponentContext : Abstract base class for all QSPy context managers. |
|
Examples:
>>> class MyContext(ComponentContext):
... def create_component(self, name, *args):
... # Custom creation logic
... pass
...
>>> with MyContext():
... my_param = (1.0, "1/min")
ComponentContext
Bases: ABC
Abstract base class for QSPy context managers.
Handles variable introspection, manual and automatic component addition, and provides a template for context-managed model construction.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
manual
|
bool
|
If True, enables manual mode for explicit component addition (default: False). |
False
|
verbose
|
bool
|
If True, prints verbose output during component addition (default: False). |
False
|
Attributes:
Name | Type | Description |
---|---|---|
component_name |
str
|
Name of the component type (e.g., 'parameter', 'monomer'). |
model |
Model
|
The active PySB model instance. |
_manual_adds |
list
|
List of manually added components (used in manual mode). |
_frame |
frame
|
Reference to the caller's frame for introspection. |
_locals_before |
dict
|
Snapshot of local variables before entering the context. |
_override |
bool
|
If True, disables module-scope enforcement. |
Methods:
Name | Description |
---|---|
__enter__ |
Enter the context, track local variables, and enforce module scope. |
__exit__ |
Exit the context, detect new variables, validate, and add components. |
__call__ |
Add a component manually (manual mode only). |
_add_component |
Validate and add a component to the model. |
_validate_value |
Validate or transform the right-hand-side value (override in subclasses). |
create_component |
Abstract method to create a component (must be implemented in subclasses). |
add_component |
Add the component to the model. |
Source code in qspy\contexts\base.py
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 |
|
__call__(name, *args)
Add a component manually (manual mode only).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
Name of the component. |
required |
*args
|
Arguments for component creation. |
()
|
Raises:
Type | Description |
---|---|
RuntimeError
|
If called when manual mode is not enabled. |
Source code in qspy\contexts\base.py
__enter__()
Enter the context manager.
Tracks local variables for automatic detection of new assignments. Enforces module-level usage unless manual mode or override is enabled.
Returns:
Type | Description |
---|---|
self or None
|
Returns self in manual mode, otherwise None. |
Raises:
Type | Description |
---|---|
RuntimeError
|
If no active model is found or used outside module scope. |
Source code in qspy\contexts\base.py
__exit__(exc_type, exc_val, exc_tb)
Exit the context manager.
Detects new variables, validates, and adds components to the model. In manual mode, adds components explicitly provided via call.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
exc_type
|
type
|
Exception type, if any. |
required |
exc_val
|
Exception
|
Exception value, if any. |
required |
exc_tb
|
traceback
|
Traceback, if any. |
required |
Returns:
Type | Description |
---|---|
None
|
|
Source code in qspy\contexts\base.py
__init__(manual=False, verbose=False)
Initialize the context manager.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
manual
|
bool
|
If True, enables manual mode for explicit component addition (default: False). |
False
|
verbose
|
bool
|
If True, prints verbose output during component addition (default: False). |
False
|
Source code in qspy\contexts\base.py
add_component(component)
Add the component to the model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
component
|
Component
|
The component to add. |
required |
create_component(name, *args)
abstractmethod
Abstract method to create a component.
Must be implemented in subclasses.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
Name of the component. |
required |
*args
|
Arguments for component creation. |
()
|
Raises:
Type | Description |
---|---|
NotImplementedError
|
Always, unless implemented in subclass. |
Source code in qspy\contexts\base.py
is_module(obj)
Check if the object is a module.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj
|
object
|
The object to check. |
required |
Returns:
Type | Description |
---|---|
bool
|
True if the object is a module, False otherwise. |
Source code in qspy\contexts\base.py
qspy.functionaltags
Functional Tagging Utilities for QSP Model Components
This module provides standardized functional tag definitions and utilities for semantic annotation of model components in quantitative systems pharmacology (QSP) models. Tags are constructed as canonical strings (e.g., "protein::ligand") that combine a molecular class and a functional subclass, enabling consistent labeling, introspection, and validation of model entities.
Classes and Enums
- FunctionalTag : Dataclass for representing and parsing functional tags.
- PROTEIN : Enum of common protein roles (e.g., ligand, receptor, kinase).
- DRUG : Enum of drug roles (e.g., inhibitor, agonist, antibody).
- RNA : Enum of RNA roles (e.g., messenger, micro, siRNA).
- DNA : Enum of DNA roles (e.g., gene, promoter, enhancer).
- METABOLITE : Enum of metabolite roles (e.g., substrate, product, cofactor).
- LIPID : Enum of lipid roles (e.g., phospholipid, sterol).
- ION : Enum of ion types (e.g., Ca2+, Na+, K+).
- NANOPARTICLE : Enum of nanoparticle roles (e.g., drug delivery, imaging).
Functions:
Name | Description |
---|---|
- prefixer : Utility to construct canonical tag strings from class and function labels. |
|
Examples:
>>> from qspy.functionaltags import FunctionalTag, PROTEIN
>>> tag = FunctionalTag("protein", "ligand")
>>> tag.value
'protein::ligand'
DNA
Bases: Enum
Functional tag definitions for DNA-based monomer classes.
This enum provides standardized semantic tags for common DNA roles
in quantitative systems pharmacology models. Each member is constructed
using the prefixer
utility to combine the DNA_PREFIX
with a
functional subclass label, producing values like "dna::gene".
Members
GENE : str A gene region. PROMOTER : str A promoter region. ENHANCER : str An enhancer region.
Examples:
Source code in qspy\functionaltags.py
DRUG
Bases: Enum
Functional tag definitions for drug-based monomer classes.
This enum provides standardized semantic tags for common drug roles
in quantitative systems pharmacology models. Each member is constructed
using the prefixer
utility to combine the DRUG_PREFIX
with a
functional subclass label, producing values like "drug::inhibitor".
These tags are used in monomer definitions to support validation, introspection, and expressive annotation of pharmacological roles.
Members
SMALL_MOLECULE : str A low molecular weight compound, typically orally bioavailable. BIOLOGIC : str A therapeutic product derived from biological sources. ANTIBODY : str An immunoglobulin-based therapeutic. MAB : str A monoclonal antibody. INHIBITOR : str A molecule that inhibits a biological process or target. AGONIST : str A molecule that activates a receptor or pathway. ANTAGONIST : str A molecule that blocks or dampens a biological response. INVERSE_AGONIST : str A molecule that induces the opposite effect of an agonist. MODULATOR : str A molecule that modulates the activity of a target. ADC : str An antibody-drug conjugate. RLT : str A radioligand therapy agent. PROTAC : str A proteolysis targeting chimera. IMUNNOTHERAPY : str An agent used in immunotherapy. CHEMOTHERAPY : str A cytotoxic agent used in chemotherapy.
Examples:
Source code in qspy\functionaltags.py
FunctionalTag
dataclass
Represents a functional tag for labeling monomers with semantic class/function metadata.
A functional tag captures both a high-level molecular class (e.g., 'protein', 'rna') and a subclass or functional role (e.g., 'ligand', 'receptor'). These tags enable semantic annotation of model components to support introspection, filtering, and validation workflows.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
class_
|
str
|
The molecular class label (e.g., 'protein'). |
required |
function
|
str
|
The functional or subclass label (e.g., 'receptor'). |
required |
Attributes:
Name | Type | Description |
---|---|---|
value |
str
|
The canonical string representation of the tag (e.g., "protein__receptor"). This is derived by prefixing the function with its class using the defined separator. |
Methods:
Name | Description |
---|---|
__eq__ |
Compares functional tags by class and function. Supports comparison with other FunctionalTag instances or Enum-based tag values. |
parse |
Parses a canonical tag string into its (class, function) components. |
Examples:
Source code in qspy\functionaltags.py
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
|
value
property
parse(prefix_tag)
staticmethod
Parse a canonical tag string into its class and function components.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
prefix_tag
|
str
|
The canonical tag string (e.g., "protein::ligand"). |
required |
Returns:
Type | Description |
---|---|
tuple of (str, str)
|
The class and function components as a tuple. |
Examples:
Source code in qspy\functionaltags.py
ION
Bases: Enum
Functional tag definitions for ion-based monomer classes.
This enum provides standardized semantic tags for common ion types
in quantitative systems pharmacology models. Each member is constructed
using the prefixer
utility to combine the ION_PREFIX
with a
functional subclass label, producing values like "ion::ca2+".
Members
CALCIUM : str Calcium ion (Ca2+). POTASSIUM : str Potassium ion (K+). SODIUM : str Sodium ion (Na+). CHLORIDE : str Chloride ion (Cl-). MAGNESIUM : str Magnesium ion (Mg2+).
Examples:
Source code in qspy\functionaltags.py
LIPID
Bases: Enum
Functional tag definitions for lipid-based monomer classes.
This enum provides standardized semantic tags for common lipid roles
in quantitative systems pharmacology models. Each member is constructed
using the prefixer
utility to combine the LIPID_PREFIX
with a
functional subclass label, producing values like "lipid::phospholipid".
Members
PHOSPHOLIPID : str A phospholipid molecule. GLYCOLIPID : str A glycolipid molecule. STEROL : str A sterol molecule. EICOSANOID : str An eicosanoid molecule.
Examples:
Source code in qspy\functionaltags.py
METABOLITE
Bases: Enum
Functional tag definitions for metabolite-based monomer classes.
This enum provides standardized semantic tags for common metabolite roles
in quantitative systems pharmacology models. Each member is constructed
using the prefixer
utility to combine the METABOLITE_PREFIX
with a
functional subclass label, producing values like "metabolite::substrate".
Members
SUBSTRATE : str A substrate molecule in a metabolic reaction. PRODUCT : str A product molecule in a metabolic reaction. COFACTOR : str A cofactor required for enzyme activity.
Examples:
Source code in qspy\functionaltags.py
NANOPARTICLE
Bases: Enum
Functional tag definitions for nanoparticle-based monomer classes.
This enum provides standardized semantic tags for common nanoparticle roles
in quantitative systems pharmacology models. Each member is constructed
using the prefixer
utility to combine the NANOPARTICLE_PREFIX
with a
functional subclass label, producing values like "nanoparticle::imaging".
Members
DRUG_DELIVERY : str Nanoparticle for drug delivery. THERMAL : str Photothermal nanoparticle. IMAGING : str Nanoparticle for imaging. SENSING : str Nanoparticle for sensing. THERANOSTIC : str Theranostic nanoparticle.
Examples:
Source code in qspy\functionaltags.py
PROTEIN
Bases: Enum
Functional tag definitions for protein-based monomer classes.
This enum provides standardized semantic tags for common protein roles
in quantitative systems pharmacology models. Each member is constructed
using the prefixer
utility to combine the PROTEIN_PREFIX
with a
functional subclass label, producing values like "protein::ligand".
These tags are used in monomer definitions to support validation, introspection, and expressive annotation of biological roles.
Members
LIGAND : str A signaling molecule that binds to a receptor. RECEPTOR : str A membrane or intracellular protein that receives ligand signals. KINASE : str An enzyme that phosphorylates other molecules. PHOSPHATASE : str An enzyme that removes phosphate groups from molecules. ADAPTOR : str A scaffold protein facilitating complex formation without enzymatic activity. TRANSCRIPTION_FACTOR : str A nuclear protein that regulates gene transcription. ENZYME : str A general-purpose catalytic protein. ANTIBODY : str An immunoglobulin capable of specific antigen binding. RECEPTOR_DECOY : str A non-signaling receptor mimic that competes with signaling receptors.
Examples:
Source code in qspy\functionaltags.py
RNA
Bases: Enum
Functional tag definitions for RNA-based monomer classes.
This enum provides standardized semantic tags for common RNA roles
in quantitative systems pharmacology models. Each member is constructed
using the prefixer
utility to combine the RNA_PREFIX
with a
functional subclass label, producing values like "rna::micro".
Members
MESSENGER : str Messenger RNA (mRNA). MICRO : str Micro RNA (miRNA). SMALL_INTERFERING : str Small interfering RNA (siRNA). LONG_NONCODING : str Long non-coding RNA (lncRNA).
Examples:
Source code in qspy\functionaltags.py
prefixer(function, prefix, sep=TAG_SEP)
Constructs a canonical functional tag string by joining a class prefix and function label using the specified separator.
This function is used to generate standardized semantic tag strings (e.g., "protein::ligand") for labeling model components in a consistent, machine-readable format.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
function
|
str
|
The functional or subclass label (e.g., "ligand"). |
required |
prefix
|
str
|
The class or category label to prefix the function with (e.g., "protein"). |
required |
sep
|
str
|
Separator string used to join the prefix and function
(default is |
TAG_SEP
|
Returns:
Type | Description |
---|---|
str
|
Combined class/function string (e.g., "protein::ligand"). |
Examples:
Source code in qspy\functionaltags.py
qspy.validation.metadata
QSPy Model Metadata Tracking and Export
This module provides utilities for capturing, tracking, and exporting model metadata in QSPy workflows. It includes environment capture, model hashing, and TOML export for reproducibility and provenance tracking.
Classes:
Name | Description |
---|---|
QSPyBench : MicroBench-based class for capturing Python and host environment info. |
|
ModelMetadataTracker : Tracks model metadata, environment, and provides export/load utilities. |
|
Examples:
>>> tracker = ModelMetadataTracker(version="1.0", author="Alice", export_toml=True)
>>> tracker.metadata["model_name"]
'MyModel'
>>> ModelMetadataTracker.load_metadata_toml("MyModel__Alice__abcd1234__2024-07-01.toml")
ModelMetadataTracker
Tracks and exports QSPy model metadata, including environment and hash.
On initialization, captures model version, author, user, timestamp, hash, and environment metadata. Optionally exports metadata to TOML.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
version
|
str
|
Model version string (default "0.1.0"). |
'0.1.0'
|
author
|
str
|
Author name (default: current user). |
None
|
export_toml
|
bool
|
If True, export metadata to TOML on creation (default: False). |
False
|
capture_conda_env
|
bool
|
If True, capture the active conda environment name (default: False). |
False
|
Attributes:
Name | Type | Description |
---|---|---|
model |
Model
|
The active PySB model instance. |
version |
str
|
Model version. |
author |
str
|
Author name. |
current_user |
str
|
Username of the current user. |
timestamp |
str
|
ISO timestamp of metadata creation. |
hash |
str
|
SHA256 hash of model rules and parameters. |
env_metadata |
dict
|
Captured environment metadata. |
metadata |
dict
|
Full metadata dictionary for export. |
Methods:
Name | Description |
---|---|
compute_model_hash |
Compute a hash from model rules and parameters. |
capture_environment |
Capture execution environment metadata. |
export_metadata_toml |
Export metadata to a TOML file. |
load_metadata_toml |
Load metadata from a TOML file. |
Examples:
>>> tracker = ModelMetadataTracker(version="1.0", author="Alice", export_toml=True)
>>> tracker.metadata["model_name"]
'MyModel'
Source code in qspy\validation\metadata.py
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 |
|
__init__(version='0.1.0', author=None, export_toml=False, capture_conda_env=False)
Initialize the ModelMetadataTracker.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
version
|
str
|
Model version string (default "0.1.0"). |
'0.1.0'
|
author
|
str
|
Author name (default: current user). |
None
|
export_toml
|
bool
|
If True, export metadata to TOML on creation (default: False). |
False
|
capture_conda_env
|
bool
|
If True, capture the active conda environment name (default: False). |
False
|
Raises:
Type | Description |
---|---|
RuntimeError
|
If no model is found in the current SelfExporter context. |
Source code in qspy\validation\metadata.py
capture_environment()
Capture execution environment via microbench.
Returns:
Type | Description |
---|---|
dict
|
Dictionary of captured environment metadata. |
Source code in qspy\validation\metadata.py
compute_model_hash()
Create a hash from model definition (rules + parameters).
Returns:
Type | Description |
---|---|
str
|
SHA256 hash of the model's rules and parameters. |
Source code in qspy\validation\metadata.py
export_metadata_toml(path=None, use_metadata_dir=True)
Export metadata to a TOML file with autogenerated filename if none is provided.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path
|
str or Path
|
Output path for the TOML file. If None, an autogenerated filename is used. |
None
|
use_metadata_dir
|
bool
|
If True, use the configured METADATA_DIR for output (default: True). |
True
|
Returns:
Type | Description |
---|---|
None
|
|
Source code in qspy\validation\metadata.py
load_metadata_toml(path)
staticmethod
Load model metadata from a TOML file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path
|
str or Path
|
Path to the TOML metadata file. |
required |
Returns:
Type | Description |
---|---|
dict
|
Loaded metadata dictionary. |
Raises:
Type | Description |
---|---|
Exception
|
If loading fails. |
Source code in qspy\validation\metadata.py
QSPyBench
Bases: MicroBench
, MBPythonVersion
, MBHostInfo
MicroBench-based class for capturing Python and host environment information.
Captures versions of key scientific libraries and host metadata for reproducibility.
Attributes:
Name | Type | Description |
---|---|---|
capture_versions |
tuple
|
Tuple of modules to capture version info for (qspy, numpy, scipy, sympy, pysb, pysb.pkpd, pysb.units, mergram). |
Source code in qspy\validation\metadata.py
qspy.validation.modelchecker
QSPy ModelChecker Utilities
This module provides the ModelChecker class for validating PySB/QSPy models. It checks for unused or zero-valued parameters, unused monomers, missing initial conditions, dangling bonds, unit consistency, and other common modeling issues. Warnings are logged and also issued as Python warnings for user visibility.
Classes:
Name | Description |
---|---|
ModelChecker : Performs a suite of checks on a PySB/QSPy model for common issues. |
|
Examples:
ModelChecker
Performs a suite of checks on a PySB/QSPy model for common modeling issues.
Checks include: - Unused monomers - Unused parameters - Zero-valued parameters - Missing initial conditions - Dangling/reused bonds - Unit consistency - (Optional) unbound sites, overdefined rules, unreferenced expressions
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model
|
Model
|
The model to check. If None, uses the current SelfExporter.default_model. |
None
|
logger_name
|
str
|
Name of the logger to use (default: LOGGER_NAME). |
LOGGER_NAME
|
Attributes:
Name | Type | Description |
---|---|---|
model |
Model
|
The model being checked. |
logger |
Logger
|
Logger for outputting warnings and info. |
Source code in qspy\validation\modelchecker.py
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 |
|
__init__(model=None, logger_name=LOGGER_NAME)
Initialize the ModelChecker.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model
|
Model
|
The model to check. If None, uses the current SelfExporter.default_model. |
None
|
logger_name
|
str
|
Name of the logger to use. |
LOGGER_NAME
|
Source code in qspy\validation\modelchecker.py
check()
Run all model checks.
Returns:
Type | Description |
---|---|
None
|
|
Source code in qspy\validation\modelchecker.py
check_dangling_reused_bonds()
Check for dangling or reused bonds in all rules.
Returns:
Type | Description |
---|---|
None
|
|
Source code in qspy\validation\modelchecker.py
check_equations_generation()
Run the generate_equations
function on the model and capture and report any errors.
Returns:
Type | Description |
---|---|
None
|
|
Source code in qspy\validation\modelchecker.py
check_missing_initial_conditions()
Check for monomers missing initial conditions.
Logs and warns about monomers that do not have initial conditions defined.
Returns:
Type | Description |
---|---|
None
|
|
Source code in qspy\validation\modelchecker.py
check_overdefined_rules()
Check for rules that define the same reaction more than once.
Logs and warns about overdefined rules.
Returns:
Type | Description |
---|---|
None
|
|
Source code in qspy\validation\modelchecker.py
check_unbound_sites()
Check for sites that never participate in bonds.
Logs and warns about unbound sites.
Returns:
Type | Description |
---|---|
None
|
|
Source code in qspy\validation\modelchecker.py
check_units()
check_unreferenced_expressions()
Check for expressions that are not referenced by any rule or observable.
Logs and warns about unreferenced expressions.
Returns:
Type | Description |
---|---|
None
|
|
Source code in qspy\validation\modelchecker.py
check_unused_monomers()
Check for monomers that are not used in any rules.
Logs and warns about unused monomers.
Returns:
Type | Description |
---|---|
None
|
|
Source code in qspy\validation\modelchecker.py
check_unused_parameters()
Check for parameters that are not used in rules, initials, or expressions.
Logs and warns about unused parameters.
Returns:
Type | Description |
---|---|
None
|
|
Source code in qspy\validation\modelchecker.py
check_zero_valued_parameters()
Check for parameters with a value of zero.
Logs and warns about zero-valued parameters.
Returns:
Type | Description |
---|---|
None
|
|
Source code in qspy\validation\modelchecker.py
qspy.utils.diagrams
QSPy Model Diagram Generation Utilities
This module provides utilities for generating flowchart-style diagrams of QSPy/PySB models. It leverages mergram and pyvipr to visualize model structure, including compartments, species, and reactions, and can export diagrams as Mermaid, Markdown, or HTML blocks.
Classes:
Name | Description |
---|---|
ModelMermaidDiagrammer : Generates and exports flowchart diagrams for a given model. |
|
Examples:
>>> from qspy.diagrams import ModelDiagram
>>> diagram = ModelDiagram(model)
>>> print(diagram.markdown_block)
>>> diagram.write_mermaid_file("model_flowchart.mmd")
ModelMermaidDiagrammer
Generates a Mermaid flowchart diagram of a QSPy/PySB model.
This class builds a flowchart representation of the model, including compartments, species, and reactions, and provides export options for Mermaid, Markdown, and HTML.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model
|
Model
|
The model to visualize. If None, uses the current SelfExporter.default_model. |
None
|
output_dir
|
str or Path
|
Directory to write diagram files (default: METADATA_DIR). |
METADATA_DIR
|
Attributes:
Name | Type | Description |
---|---|---|
model |
Model
|
The model being visualized. |
flowchart |
Flowchart
|
The generated flowchart object. |
static_viz |
PysbStaticViz
|
Static visualization helper for the model. |
has_compartments |
bool
|
Whether the model contains compartments. |
output_dir |
Path
|
Directory for output files. |
Methods:
Name | Description |
---|---|
write_mermaid_file |
Write the flowchart to a Mermaid file. |
markdown_block |
Return the flowchart as a Markdown block. |
html_block |
Return the flowchart as an HTML block. |
Source code in qspy\utils\diagrams.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 |
|
html_block
property
Return the flowchart as an HTML block.
Returns:
Type | Description |
---|---|
str
|
HTML representation of the flowchart. |
markdown_block
property
Return the flowchart as a Markdown block.
Returns:
Type | Description |
---|---|
str
|
Markdown representation of the flowchart. |
__init__(model=None, output_dir=METADATA_DIR)
Initialize the ModelMermaidDiagrammer.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model
|
Model
|
The model to visualize. If None, uses the current SelfExporter.default_model. |
None
|
output_dir
|
str or Path
|
Directory to write diagram files (default: METADATA_DIR). |
METADATA_DIR
|
Source code in qspy\utils\diagrams.py
write_mermaid_file(file_path)
Write the flowchart to a Mermaid file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_path
|
str or Path
|
Path to the output Mermaid (.mmd) file. |
required |
Returns:
Type | Description |
---|---|
None
|
|
Source code in qspy\utils\diagrams.py
qspy.utils.logging
QSPy Logging Utilities
This module provides logging utilities for QSPy, including logger setup, event decorators, metadata redaction, and context entry/exit logging. It ensures consistent, structured, and optionally redacted logging for QSPy workflows.
Functions:
Name | Description |
---|---|
setup_qspy_logger : Set up the QSPy logger with rotating file handler. |
|
ensure_qspy_logging : Ensure the QSPy logger is initialized. |
|
log_event : Decorator for logging function entry, exit, arguments, and results. |
|
redact_sensitive : Recursively redact sensitive fields in a dictionary. |
|
log_model_metadata : Log model metadata in a structured, optionally redacted format. |
|
log_context_entry_exit : Decorator for logging context manager entry/exit. |
|
Examples:
ensure_qspy_logging()
Ensure the QSPy logger is initialized.
Returns:
Type | Description |
---|---|
None
|
|
log_context_entry_exit(logger_name=LOGGER_NAME, log_duration=True, track_attr=None)
Decorator for logging context manager entry and exit, with optional duration and tracking.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
logger_name
|
str
|
Name of the logger to use (default: LOGGER_NAME). |
LOGGER_NAME
|
log_duration
|
bool
|
If True, log the duration of the context (default: True). |
True
|
track_attr
|
str or None
|
If provided, track additions to this model attribute (e.g., 'rules'). |
None
|
Returns:
Type | Description |
---|---|
function
|
Decorated context manager method. |
Source code in qspy\utils\logging.py
log_event(logger_name=LOGGER_NAME, log_args=False, log_result=False, static_method=False)
Decorator for logging function entry, exit, arguments, and results.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
logger_name
|
str
|
Name of the logger to use (default: LOGGER_NAME). |
LOGGER_NAME
|
log_args
|
bool
|
If True, log function arguments (default: False). |
False
|
log_result
|
bool
|
If True, log function result (default: False). |
False
|
static_method
|
bool
|
If True, skip the first argument (for static methods). |
False
|
Returns:
Type | Description |
---|---|
function
|
Decorated function with logging. |
Source code in qspy\utils\logging.py
log_model_metadata(metadata, logger_name=LOGGER_NAME, level=logging.INFO, redact=True)
Log QSPy model metadata in structured format, with optional redaction.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
metadata
|
dict
|
The metadata dictionary to log. |
required |
logger_name
|
str
|
Name of the logger. |
LOGGER_NAME
|
level
|
int
|
Logging level. |
INFO
|
redact
|
bool
|
If True, redact sensitive fields (default: True). |
True
|
Returns:
Type | Description |
---|---|
None
|
|
Source code in qspy\utils\logging.py
redact_sensitive(data)
Recursively redact sensitive fields in a dictionary or list.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
dict or list or object
|
The data structure to redact. |
required |
Returns:
Type | Description |
---|---|
object
|
The redacted data structure. |
Source code in qspy\utils\logging.py
setup_qspy_logger(log_path=LOG_PATH, max_bytes=1000000, backup_count=5, level=logging.INFO)
Set up the QSPy logger with a rotating file handler.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
log_path
|
str or Path
|
Path to the log file (default: LOG_PATH). |
LOG_PATH
|
max_bytes
|
int
|
Maximum size of a log file before rotation (default: 1,000,000). |
1000000
|
backup_count
|
int
|
Number of backup log files to keep (default: 5). |
5
|
level
|
int
|
Logging level (default: logging.INFO). |
INFO
|
Returns:
Type | Description |
---|---|
Logger
|
The configured QSPy logger. |
Source code in qspy\utils\logging.py
Experimental Features
qspy.experimental.infix_macros
QSPy experimental infix macros for expressive model syntax.
Provides infix-style macro objects for binding, elimination, and equilibrium interactions: - binds: infix macro for reversible binding reactions - eliminated: infix macro for elimination reactions - equilibrates: infix macro for reversible state transitions
These macros enable expressive model code such as: species binds target & (k_f, k_r) species eliminated compartment & k_deg state1 equilibrates state2 & (k_f, k_r)
InfixMacro
Bases: ABC
Abstract base class for infix-style macros in QSPy.
This class provides a structure for creating infix-style macros that can be used
in a way that more closely resembles specifying a biological action.
Adapted from Infix
class example at: https://discuss.python.org/t/infix-function-in-python/41820/2
Source code in qspy\experimental\infix_macros.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
|
__and__(at)
Execute the macro logic using the & operator.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
at
|
any
|
Additional argument for the macro. |
required |
Returns:
Type | Description |
---|---|
any
|
The result of the macro operation. |
Source code in qspy\experimental\infix_macros.py
__init__(lhs=None, rhs=None)
Initialize the infix macro with optional left and right sides.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
lhs
|
any
|
The left-hand side of the infix operation. |
None
|
rhs
|
any
|
The right-hand side of the infix operation. |
None
|
Source code in qspy\experimental\infix_macros.py
__mul__(rhs)
Capture the right-hand side operand for the infix macro.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
rhs
|
any
|
The right-hand side operand. |
required |
Returns:
Type | Description |
---|---|
InfixMacro
|
The same instance with rhs set. |
Source code in qspy\experimental\infix_macros.py
__rmul__(lhs)
Capture the left-hand side operand for the infix macro.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
lhs
|
any
|
The left-hand side operand. |
required |
Returns:
Type | Description |
---|---|
InfixMacro
|
The same instance with lhs set. |
Source code in qspy\experimental\infix_macros.py
execute_macro(lhs, rhs, at)
abstractmethod
Abstract method to execute the macro logic.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
lhs
|
any
|
The left-hand side operand. |
required |
rhs
|
any
|
The right-hand side operand. |
required |
at
|
any
|
Additional argument for the macro. |
required |
Returns:
Type | Description |
---|---|
any
|
The result of the macro operation. |
Source code in qspy\experimental\infix_macros.py
parse_pattern(pattern)
staticmethod
Parse the monomer pattern to extract relevant information.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pattern
|
MonomerPattern or ComplexPattern
|
The pattern to parse. |
required |
Returns:
Type | Description |
---|---|
tuple
|
A tuple containing the monomer, binding site, state, and compartment. |
Source code in qspy\experimental\infix_macros.py
qspy.experimental.functional_monomers
QSPy experimental functional monomers subpackage.
Provides base classes, mixins, and macros for building and manipulating functional monomers, including support for binding, synthesis, degradation, and protein-specific behaviors.
qspy.experimental.functional_monomers.protein
Functional monomer protein classes and mixins for QSPy experimental API.
Provides: - TurnoverMixin: mixin for synthesis and degradation reactions. - Ligand: class for ligand monomers with binding functionality. - Receptor: class for receptor monomers with orthosteric/allosteric binding and activation.
Ligand
Bases: BindMixin
, FunctionalMonomer
Class representing a ligand monomer with binding functionality.
Source code in qspy\experimental\functional_monomers\protein.py
binding_site
property
Return the binding site for this ligand.
Returns:
Type | Description |
---|---|
str
|
The name of the binding site. |
binds_to(receptor, r_site, k_f, k_r, compartment=None)
Create a reversible binding reaction between this ligand and a receptor.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
receptor
|
Receptor
|
The receptor to bind. |
required |
r_site
|
str
|
The binding site on the receptor. |
required |
k_f
|
float or Parameter
|
Forward rate constant. |
required |
k_r
|
float or Parameter
|
Reverse rate constant. |
required |
compartment
|
Compartment or None
|
Compartment for the reaction (default: None). |
None
|
Returns:
Type | Description |
---|---|
ComponentSet
|
PySB ComponentSet for the binding reaction. |
Source code in qspy\experimental\functional_monomers\protein.py
concertedly_activates(receptor, k_f, k_r, compartment=None)
Create a concerted activation reaction for a receptor by this ligand.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
receptor
|
Receptor
|
The receptor to activate. |
required |
k_f
|
float or Parameter
|
Forward rate constant. |
required |
k_r
|
float or Parameter
|
Reverse rate constant. |
required |
compartment
|
Compartment or None
|
Compartment for the reaction (default: None). |
None
|
Returns:
Type | Description |
---|---|
ComponentSet
|
PySB ComponentSet for the concerted activation reaction. |
Source code in qspy\experimental\functional_monomers\protein.py
Receptor
Bases: BindMixin
, TurnoverMixin
, FunctionalMonomer
Class representing a receptor monomer with orthosteric/allosteric binding and activation.
Source code in qspy\experimental\functional_monomers\protein.py
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 |
|
active
property
Return the active state dictionary.
Returns:
Type | Description |
---|---|
dict
|
Dictionary representing the active state. |
allosteric_site
property
Return the allosteric binding site.
Returns:
Type | Description |
---|---|
str
|
Name of the allosteric site. |
binding_sites
property
Return the orthosteric and allosteric binding sites.
Returns:
Type | Description |
---|---|
list
|
List of binding site names. |
inactive
property
Return the inactive state dictionary.
Returns:
Type | Description |
---|---|
dict
|
Dictionary representing the inactive state. |
orthosteric_site
property
Return the orthosteric binding site.
Returns:
Type | Description |
---|---|
str
|
Name of the orthosteric site. |
bound_by(ligand, k_f, k_r, location='orthosteric', compartment=None)
Create a reversible binding reaction at the specified site.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ligand
|
Ligand
|
The ligand to bind. |
required |
k_f
|
float or Parameter
|
Forward rate constant. |
required |
k_r
|
float or Parameter
|
Reverse rate constant. |
required |
location
|
str
|
"orthosteric" or "allosteric" (default: "orthosteric"). |
'orthosteric'
|
compartment
|
Compartment or None
|
Compartment for the reaction (default: None). |
None
|
Returns:
Type | Description |
---|---|
ComponentSet
|
PySB ComponentSet for the binding reaction. |
Source code in qspy\experimental\functional_monomers\protein.py
concertedly_activated_by(ligand, k_f, k_r, compartment=None)
Create a concerted activation reaction for this receptor by a ligand.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ligand
|
Ligand
|
The ligand to activate this receptor. |
required |
k_f
|
float or Parameter
|
Forward rate constant. |
required |
k_r
|
float or Parameter
|
Reverse rate constant. |
required |
compartment
|
Compartment or None
|
Compartment for the reaction (default: None). |
None
|
Returns:
Type | Description |
---|---|
ComponentSet
|
PySB ComponentSet for the concerted activation reaction. |
Source code in qspy\experimental\functional_monomers\protein.py
TurnoverMixin
Bases: DegradeMixin
, SynthesizeMixin
Mixin class providing a turnover() method for synthesis and degradation reactions.
Source code in qspy\experimental\functional_monomers\protein.py
turnover(k_syn, k_deg, compartment=None)
Create synthesis and degradation reactions for this monomer.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
k_syn
|
float or Parameter
|
Synthesis rate constant. |
required |
k_deg
|
float or Parameter
|
Degradation rate constant. |
required |
compartment
|
Compartment or None
|
Compartment for the reactions (default: None). |
None
|
Returns:
Type | Description |
---|---|
ComponentSet
|
Combined PySB ComponentSet for synthesis and degradation. |
Source code in qspy\experimental\functional_monomers\protein.py
qspy.experimental.functional_monomers.base
FunctionalMonomer base classes and mixins for QSPy experimental functional monomer API.
Provides: - FunctionalMonomer: base class for monomers with functional tags and base states. - BindMixin: mixin for binding macro methods. - SynthesizeMixin: mixin for synthesis macro methods. - DegradeMixin: mixin for degradation macro methods.
BindMixin
Mixin class providing a binds() method for binding reactions.
Source code in qspy\experimental\functional_monomers\base.py
binds(site, other, other_site, k_f, k_r, compartment=None)
Create a reversible binding reaction between this monomer and another.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
site
|
str
|
Binding site on this monomer. |
required |
other
|
Monomer, MonomerPattern, or FunctionalMonomer
|
The other monomer or pattern to bind. |
required |
other_site
|
str
|
Binding site on the other monomer. |
required |
k_f
|
float or Parameter
|
Forward rate constant. |
required |
k_r
|
float or Parameter
|
Reverse rate constant. |
required |
compartment
|
Compartment or None
|
Compartment for the reaction (default: None). |
None
|
Returns:
Type | Description |
---|---|
ComponentSet
|
PySB ComponentSet for the binding reaction. |
Source code in qspy\experimental\functional_monomers\base.py
DegradeMixin
Mixin class providing a degraded() method for degradation reactions.
Source code in qspy\experimental\functional_monomers\base.py
degraded(state, k_deg, compartment=None)
Create a degradation reaction for this monomer in a given state.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
state
|
dict
|
State assignment for the monomer. |
required |
k_deg
|
float or Parameter
|
Degradation rate constant. |
required |
compartment
|
Compartment or None
|
Compartment for the reaction (default: None). |
None
|
Returns:
Type | Description |
---|---|
ComponentSet
|
PySB ComponentSet for the degradation reaction. |
Source code in qspy\experimental\functional_monomers\base.py
FunctionalMonomer
Bases: Monomer
Base class for functional monomers in QSPy.
Adds support for binding sites, site states, functional tags, and a base state.
Source code in qspy\experimental\functional_monomers\base.py
base_state
property
Dictionary of base state values for this monomer.
Returns:
Type | Description |
---|---|
dict
|
Dictionary of base state assignments. |
binding_sites
property
List of binding sites for this monomer.
Returns:
Type | Description |
---|---|
list
|
List of binding site names. |
states
property
Dictionary of site states for this monomer.
Returns:
Type | Description |
---|---|
dict
|
Dictionary mapping site names to possible states. |
__init__(name)
Initialize a FunctionalMonomer.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
Name of the monomer. |
required |
Source code in qspy\experimental\functional_monomers\base.py
SynthesizeMixin
Mixin class providing a synthesized() method for synthesis reactions.
Source code in qspy\experimental\functional_monomers\base.py
synthesized(k_syn, compartment=None)
Create a synthesis reaction for this monomer.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
k_syn
|
float or Parameter
|
Synthesis rate constant. |
required |
compartment
|
Compartment or None
|
Compartment for the reaction (default: None). |
None
|
Returns:
Type | Description |
---|---|
ComponentSet
|
PySB ComponentSet for the synthesis reaction. |
Source code in qspy\experimental\functional_monomers\base.py
qspy.experimental.functional_monomers.macros
Functional monomer macros for QSPy experimental API.
Provides: - activate_concerted: macro for concerted activation of a receptor by a ligand.
activate_concerted(ligand, l_site, receptor, r_site, inactive_state, active_state, k_list, compartment=None)
Generate a concerted activation reaction for a receptor by a ligand.
This macro creates a reversible binding rule where a ligand binds to a receptor, and the receptor transitions from an inactive state to an active state as part of the binding event.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ligand
|
Monomer or MonomerPattern
|
The ligand species or pattern. |
required |
l_site
|
str
|
The binding site on the ligand. |
required |
receptor
|
Monomer or MonomerPattern
|
The receptor species or pattern. |
required |
r_site
|
str
|
The binding site on the receptor. |
required |
inactive_state
|
dict
|
Dictionary specifying the inactive state of the receptor. |
required |
active_state
|
dict
|
Dictionary specifying the active state of the receptor. |
required |
k_list
|
list
|
List of rate constants [k_f, k_r] for forward and reverse reactions. |
required |
compartment
|
Compartment or None
|
The compartment in which the reaction occurs (default: None). |
None
|
Returns:
Type | Description |
---|---|
ComponentSet
|
The generated components, including the reversible activation Rule. |
Examples:
Concerted activation of a receptor by a ligand::
Model()
Monomer('Ligand', ['b'])
Monomer('Receptor', ['b', 'state'], {'state': ['inactive', 'active']})
activate_concerted(
Ligand, 'b', Receptor, 'b',
{'state': 'inactive'}, {'state': 'active'},
[1e-3, 1e-3]
)