ControlStream

class openpkpd.parser.control_stream.ControlStream(source_text, records=<factory>, source_path=None)[source]

Bases: object

Top-level parsed representation of a NONMEM control stream.

Parameters:
  • source_text (str)

  • records (list[BaseRecord])

  • source_path (str | None)

source_text: str
records: list[BaseRecord]
source_path: str | None = None
get(record_type)[source]

Return the first record of the given type, or None.

Return type:

BaseRecord | None

Parameters:

record_type (str)

get_all(record_type)[source]

Return all records of the given type.

Return type:

list[BaseRecord]

Parameters:

record_type (str)

get_typed(record_type, cls)[source]

Type-safe accessor returning a specific record class.

Return type:

Optional[TypeVar(T, bound= BaseRecord)]

Parameters:
get_all_typed(record_type, cls)[source]

Type-safe accessor returning a list of specific record class.

Return type:

list[TypeVar(T, bound= BaseRecord)]

Parameters:
property problem: ProblemRecord | None
property data: DataRecord | None
property input: InputRecord | None
property subroutines: SubroutinesRecord | None
property pk: PKRecord | None
property des: DESRecord | None
property error: ErrorRecord | None
property pred: PredRecord | None
property theta_records: list[ThetaRecord]
property omega_records: list[OmegaRecord]
property sigma_records: list[SigmaRecord]
property simulation: SimulationRecord | None
property mixture: MixtureRecord | None
property prior_record: PriorRecord | None
property thetap_record: ThetaPRecord | None
property thetapv_record: ThetaPVRecord | None
property omegap_record: OmegaPRecord | None
property omegapd_record: OmegaPDRecord | None
property sigmap_record: SigmaPRecord | None
property sigmapd_record: SigmaPDRecord | None
property estimation_records: list[EstimationRecord]
property covariance: CovarianceRecord | None
property table_records: list[TableRecord]
classmethod from_file(path)[source]

Load and parse a NONMEM control stream from a file.

Return type:

ControlStream

Parameters:

path (str)

classmethod from_string(text)[source]

Parse a NONMEM control stream from a string.

Return type:

ControlStream

Parameters:

text (str)

to_dict()[source]

Serialize to a plain dict for debugging.

Return type:

dict[str, Any]

to_string()[source]

Serialize the entire control stream to NONMEM .ctl text.

Each record is rendered via its to_string() method. Structured records (THETA, OMEGA, SIGMA, ESTIMATION, …) reconstruct from their parsed attributes so programmatic modifications are preserved. All other records reproduce their original raw_text.

Return type:

str

write(path)[source]

Write the control stream to path.

Creates parent directories if they do not exist.

Return type:

None

Parameters:

path (str)

__init__(source_text, records=<factory>, source_path=None)
Parameters:
  • source_text (str)

  • records (list[BaseRecord])

  • source_path (str | None)

Return type:

None