Functions¶
Auto-generated from docstrings. Only the public API of each package (what's exported via its __init__.py) is shown.
pandora.ingestion
¶
fetch_list_mmcif(entry_ids, provider, output_dir, source_uri=None, fetch_options=None)
¶
Fetch a list of raw mmCIF files from a provider URL, write them to output_dir, return provenance for each.
Calls fetch_mmcif() once per entry ID. If
fetch_options.allow_partial is True, entries that fail to fetch
(RuntimeError or ValueError) are skipped instead of aborting
the whole batch.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entry_ids
|
list[str]
|
The PDB/PDBe entry identifiers to fetch. |
required |
provider
|
str
|
One of "pdbe" or "pdb", used to build the download
URL when |
required |
source_uri
|
str | None
|
A URL/path template overriding |
None
|
output_dir
|
Path
|
Directory to write the downloaded (or cached) files into; created if missing. |
required |
fetch_options
|
FetchOptions | None
|
Caching/decompression options, including
|
None
|
Returns:
| Type | Description |
|---|---|
list[IngestionProvenance]
|
A list of |
list[IngestionProvenance]
|
entry, in the same order as |
list[IngestionProvenance]
|
omitted when |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
RuntimeError
|
If a fetch fails and |
Source code in pandora/ingestion/mmcif.py
fetch_mmcif(entry_id, provider, source_uri, output_dir, fetch_options=None)
¶
Fetch a raw mmCIF file from a provider URL, write it to output_dir, return provenance.
Resolves the download URL from source_uri or from provider
("pdbe"/"pdb"), reuses a cached file when one is fresh (per
fetch_options), otherwise downloads it, optionally decompresses
it, and writes it to output_dir.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entry_id
|
str
|
The PDB/PDBe entry identifier (e.g. "1abc"). |
required |
provider
|
str
|
One of "pdbe" or "pdb", used to build the download
URL when |
required |
source_uri
|
str | None
|
An explicit URL to fetch from, overriding
|
required |
output_dir
|
Path
|
Directory to write the downloaded (or cached) file into; created if missing. |
required |
fetch_options
|
FetchOptions | None
|
Caching/decompression options. Defaults
to |
None
|
Returns:
| Type | Description |
|---|---|
IngestionProvenance
|
|
IngestionProvenance
|
retrieval timestamp, whether the result came from cache, and |
IngestionProvenance
|
the entry's own revision date where the provider exposes one. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
RuntimeError
|
If the HTTP request fails, or the response cannot be decompressed/decoded. |
Source code in pandora/ingestion/mmcif.py
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 | |
ingest_local_mmcif(path, source_uri=None)
¶
Describe an already-downloaded mmCIF file as provenance, without fetching or copying anything.
For a file that arrived via some external bulk source — a local
rsync mirror of PDB, an archived dated snapshot, a lab file server —
rather than fetch_mmcif(). Pandora has no bulk-download step of its
own; this just lets such a file's origin be recorded the same way a
live fetch's is, so it can still be attached to a ProvenanceBundle.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
Path to the existing mmCIF file on disk. Not modified or copied. |
required |
source_uri
|
str | None
|
A label for where this file came from (e.g.
"pdb_snapshot_2024-01-29"), stored verbatim. Defaults to
|
None
|
Returns:
| Type | Description |
|---|---|
IngestionProvenance
|
|
IngestionProvenance
|
(this isn't Pandora's own fetch cache), the file's own mtime as |
IngestionProvenance
|
|
IngestionProvenance
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in pandora/ingestion/mmcif.py
load_policy(path)
¶
Load a canonicalisationPolicy from a YAML file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Path to the policy YAML file. |
required |
Returns:
| Type | Description |
|---|---|
canonicalisationPolicy
|
The parsed, validated |
Source code in pandora/ingestion/policy.py
search_pdbe(query, rows=100, start=0)
¶
Search PDBe's Solr-based search API for matching entry ids.
query is a raw Solr/Lucene query string, passed through verbatim as
the q parameter — Pandora doesn't validate or translate it. See
https://www.ebi.ac.uk/pdbe/api/doc/search.html for the query syntax
and the full list of searchable fields. The returned ids feed
directly into fetch_mmcif/fetch_list_mmcif with
provider="pdbe".
Unlike RCSB's search API, PDBe's Solr endpoint doesn't reject a malformed query — an unparseable clause is silently dropped rather than erroring, which can make a typo'd query match far more than intended. Sanity-check the returned count against what you expect.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
str
|
A Solr query string, e.g. |
required |
rows
|
int
|
Maximum number of ids to return in this page. |
100
|
start
|
int
|
Offset into the full result set, for paging through more
than |
0
|
Returns:
| Type | Description |
|---|---|
list[str]
|
Matching PDB ids, lowercase (PDBe's own convention), deduplicated |
list[str]
|
— PDBe's Solr index can list the same id more than once (e.g. one |
list[str]
|
row per assembly/entity). Empty list if nothing matches. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If the request fails. |
Source code in pandora/ingestion/search.py
search_rcsb(query, return_type='entry', rows=100, start=0)
¶
Search RCSB's Search API for matching entry ids.
query is RCSB's own query tree, passed through verbatim — Pandora
doesn't validate or translate it. See
https://search.rcsb.org/#search-api for the query language
(terminal/group nodes, services, attributes, operators) and
https://search.rcsb.org/rcsbsearch/v2/metadata/schema for the full
list of searchable attributes. The returned ids feed directly into
fetch_mmcif/fetch_list_mmcif with provider="pdb".
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
dict
|
An RCSB query tree, e.g. |
required |
return_type
|
str
|
What kind of id to return — "entry" for PDB entry ids (the default), or one of RCSB's other result types ("polymer_entity", "assembly", ...). |
'entry'
|
rows
|
int
|
Maximum number of ids to return in this page. |
100
|
start
|
int
|
Offset into the full result set, for paging through more
than |
0
|
Returns:
| Type | Description |
|---|---|
list[str]
|
Matching identifiers, in RCSB's own casing (e.g. "104M"). Empty |
list[str]
|
list if nothing matches. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If the request fails, including a malformed query — RCSB validates the query tree server-side and returns its own error message on a bad attribute/operator. |
Source code in pandora/ingestion/search.py
pandora.parsing
¶
mmcif_to_structure(path_to_mmcif, model_num=1)
¶
Convert raw mmCIF text to a Structure (mmCIF data model).
Parses the mmCIF file with gemmi, selects the requested model
(falling back to the first model with a warning if not found),
and extracts entities, atoms, asym units, connections, assemblies,
and secondary structure into Pandora's typed Structure schema.
Any other mmCIF categories are preserved verbatim in Structure.raw.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path_to_mmcif
|
str
|
Path to the mmCIF file on disk. |
required |
model_num
|
int
|
Which model number to select from a multi-model entry. |
1
|
Returns:
| Type | Description |
|---|---|
tuple[Structure | None, DiagnosticBundle, ResultStatus]
|
A tuple of:
- The parsed |
Source code in pandora/parsing/mmcif.py
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 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 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 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 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 | |
pandora.canonicalisation
¶
canonicalise_structure(structure, policy)
¶
Convert a parsed structure into a canonical structure.
Applies modified-residue mapping, chain ID normalization, assembly normalization, missing-data handling, altloc resolution, residue renumbering, entity normalization, and ligand filtering, in that order, according to the given policy. Each step records its mapping (for reversibility) and, if the step's strategy deviates from "preserve", appends a transform label to the returned provenance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
structure
|
Structure
|
The parsed input structure to canonicalise. |
required |
policy
|
canonicalisationPolicy
|
The canonicalisation policy whose rules govern each normalization step. |
required |
Returns:
| Type | Description |
|---|---|
tuple[Structure, CanonicalMappings, canonicalisationProvenance]
|
A tuple of:
- The canonicalised |
Source code in pandora/canonicalisation/canonicalise.py
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 | |
filter_ligands(atoms, asym_units, entities, rules, diagnostics, entry_id)
¶
Filter non-polymer ligands/waters/ions out of atoms/asym_units per the ligand rules.
Categorizes each non-polymer asym unit as water, ion (by keyword
match on the entity description), or other non-polymer ligand, and
keeps or drops it according to rules.keep_waters/keep_ions/
keep_nonpolymer_ligands. With rules.strategy="annotate_only",
every non-polymer asym unit is dropped from the returned atoms/
asym_units (but recorded as a diagnostic) rather than selectively
kept.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
atoms
|
list[AtomSiteRecord]
|
The structure's atom records. |
required |
asym_units
|
list[AsymRecord]
|
The structure's asym unit records. |
required |
entities
|
list[EntityRecord]
|
The structure's entity records, used to classify each asym unit's entity type and description. |
required |
rules
|
LigandRules
|
The |
required |
diagnostics
|
DiagnosticBundle
|
Bundle to append a warning to for each asym unit
excluded under |
required |
entry_id
|
str
|
The structure's entry id, attached to any diagnostics raised. |
required |
Returns:
| Type | Description |
|---|---|
list[AtomSiteRecord]
|
|
list[AsymRecord]
|
removed; polymer atoms/asym units are always kept. |
Source code in pandora/canonicalisation/ligands.py
pandora.metadata
¶
annotate_ligand_contacts(structure, distance_cutoff=4.0, include_waters=False)
¶
Compute polymer residues near non-polymer atoms within a cutoff.
Groups HETATM records into ligands (by asym/auth_seq/comp id) and,
for each ligand, finds polymer residues with at least one atom
within distance_cutoff angstroms of a ligand atom.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
structure
|
Structure
|
The structure to scan for ligand contacts. |
required |
distance_cutoff
|
float
|
Contact distance in angstroms. |
4.0
|
include_waters
|
bool
|
If True, treat water residues as ligands too. |
False
|
Returns:
| Type | Description |
|---|---|
AnnotationLayer
|
An |
AnnotationLayer
|
holds the cutoff/flags used and, per ligand, the contacting |
AnnotationLayer
|
polymer residues with their nearest distance. |
Source code in pandora/annotations/entry.py
annotate_pairwise_sequence_identity(left, right)
¶
Compute a simple ungapped sequence identity between two entries.
Compares every polymer entity in left against every polymer
entity in right with a position-wise (ungapped, no alignment)
identity, then reports the best-scoring pair.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
left
|
Structure
|
The first structure to compare. |
required |
right
|
Structure
|
The second structure to compare. |
required |
Returns:
| Type | Description |
|---|---|
AnnotationLayer
|
An |
AnnotationLayer
|
|
AnnotationLayer
|
pair, and every entity-pair comparison. |
Source code in pandora/annotations/pairwise.py
annotate_structure_counts(structure)
¶
Compute simple per-entry counts from the canonical structure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
structure
|
Structure
|
The canonical structure to summarize. |
required |
Returns:
| Type | Description |
|---|---|
AnnotationLayer
|
An |
AnnotationLayer
|
holds atom/residue/asym/entity/assembly/connection counts, |
AnnotationLayer
|
secondary-structure record counts, entity-type and atom-group |
AnnotationLayer
|
breakdowns, and the altloc atom count. |
Source code in pandora/annotations/entry.py
collect_metadata(structure)
¶
Collect the basic source-backed metadata supported by Pandora today.
Runs every pandora.metadata.mmcif.extract_* function against the
structure and assembles the results into one record.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
structure
|
Structure
|
The parsed structure to collect metadata from. |
required |
Returns:
| Type | Description |
|---|---|
MetadataRecord
|
A |
MetadataRecord
|
ligand, and UniProt-mapping metadata, plus the sorted list of |
MetadataRecord
|
raw mmCIF category names present in the structure. |
Source code in pandora/metadata/collect.py
extract_entity_metadata(structure)
¶
Extract entity-level descriptions, sequences, and chain membership.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
structure
|
Structure
|
The parsed structure to extract entity metadata from. |
required |
Returns:
| Type | Description |
|---|---|
list[EntityMetadataRecord]
|
An |
list[EntityMetadataRecord]
|
fields (EC number, mutation, fragment), polymer sequence data, |
list[EntityMetadataRecord]
|
and the chain (asym) ids belonging to that entity. |
Source code in pandora/metadata/mmcif.py
extract_entry_metadata(structure)
¶
Extract entry-level source-backed metadata from the parsed structure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
structure
|
Structure
|
The parsed structure to extract metadata from. |
required |
Returns:
| Type | Description |
|---|---|
EntryMetadataRecord
|
An |
EntryMetadataRecord
|
citation details (title, DOI, PubMed id). |
Source code in pandora/metadata/mmcif.py
extract_ligand_metadata(structure, include_waters=False)
¶
Extract non-polymer ligand metadata from mmCIF categories.
Reads _pdbx_entity_nonpoly (joined with _chem_comp for name and
formula) for one record per distinct (entity, ligand) pair. Falls
back to deriving ligand records from HETATM records in
structure.atoms when neither category is present.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
structure
|
Structure
|
The parsed structure to extract ligands from. |
required |
include_waters
|
bool
|
If True, include water molecules as ligands. |
False
|
Returns:
| Type | Description |
|---|---|
list[LigandMetadataRecord]
|
A |
Source code in pandora/metadata/mmcif.py
extract_metadata(structure, category, keys=None)
¶
Compatibility wrapper around extract_metadata_category().
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
structure
|
Structure
|
The parsed structure to read raw categories from. |
required |
category
|
str
|
The mmCIF category name (e.g. "_entity"). |
required |
keys
|
Iterable[str] | None
|
If given, restrict each row to these column names; otherwise return every column present in the category. |
None
|
Returns:
| Type | Description |
|---|---|
list[RawRow]
|
A list of rows, each a mapping from column name to its |
list[RawRow]
|
(already null-normalized) string value. |
Source code in pandora/metadata/mmcif.py
extract_metadata_category(structure, category, columns=None)
¶
Return raw mmCIF rows for one category.
This is the escape hatch for metadata that Pandora has not promoted to a typed schema yet.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
structure
|
Structure
|
The parsed structure to read raw categories from. |
required |
category
|
str
|
The mmCIF category name (e.g. "_entity"). |
required |
columns
|
Iterable[str] | None
|
If given, restrict each row to these column names
(missing columns come back as |
None
|
Returns:
| Type | Description |
|---|---|
list[RawRow]
|
A list of rows, each a mapping from column name to its |
list[RawRow]
|
(already null-normalized) string value. |
Source code in pandora/metadata/mmcif.py
extract_quality(structure)
¶
Extract experimental quality metrics reported in mmCIF.
Reads the _exptl, _refine, _reflns and
_em_3d_reconstruction categories for the experimental method,
resolution, R-work/R-free, Rsym/Rmerge, reflection counts, and mean
B-factor. Resolution comes from _refine, falling back to
_em_3d_reconstruction (cryo-EM).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
structure
|
Structure
|
The parsed structure to extract quality data from. |
required |
Returns:
| Type | Description |
|---|---|
QualityRecord | None
|
A |
QualityRecord | None
|
|
QualityRecord | None
|
structure. |
Source code in pandora/metadata/mmcif.py
extract_taxonomies(structure)
¶
Extract source organism and expression host metadata.
Reads the _entity_src_gen, _entity_src_nat, and
_pdbx_entity_src_syn mmCIF categories, covering genetically
manipulated, naturally isolated, and synthetic sources
respectively.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
structure
|
Structure
|
The parsed structure to extract taxonomies from. |
required |
Returns:
| Type | Description |
|---|---|
list[TaxonomyRecord]
|
A |
list[TaxonomyRecord]
|
(generated, then natural, then synthetic sources). |
Source code in pandora/metadata/mmcif.py
extract_taxonomy(structure)
¶
Return the first taxonomy record, if present.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
structure
|
Structure
|
The parsed structure to extract taxonomy from. |
required |
Returns:
| Type | Description |
|---|---|
TaxonomyRecord | None
|
The first |
TaxonomyRecord | None
|
|
Source code in pandora/metadata/mmcif.py
extract_uniprot_mappings(structure)
¶
Extract UniProt/SIFTS mappings reported in the mmCIF file.
Reads _struct_ref/_struct_ref_seq and
_pdbx_sifts_unp_segments, deduplicating mappings that describe
the same entity/asym/accession/range.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
structure
|
Structure
|
The parsed structure to extract mappings from. |
required |
Returns:
| Type | Description |
|---|---|
list[UniProtMappingRecord]
|
A |
list[UniProtMappingRecord]
|
across both source categories. |
Source code in pandora/metadata/mmcif.py
pandora.annotations
¶
annotate_chain_interfaces(structure, distance_cutoff=4.0, atom_set='heavy', polymer_types=None)
¶
Compute polymer chain pairs with residues in contact within a cutoff.
For each pair of polymer chains, finds residue pairs (one per chain)
with at least one pair of selected atoms within distance_cutoff
angstroms. Chain pairs whose bounding boxes are further apart than
the cutoff are skipped without comparing atoms.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
structure
|
Structure
|
The structure to scan for chain-chain contacts. |
required |
distance_cutoff
|
float
|
Contact distance in angstroms. |
4.0
|
atom_set
|
ContactAtomSet
|
Which atoms count: "all", "heavy" (every atom except H/D), "backbone" (protein N/CA/C/O, nucleic-acid O5'/C5'/C4'/C3'/O3'), or "ca". |
'heavy'
|
polymer_types
|
list[str] | None
|
Keep only chains whose entity polymer type (e.g. "polypeptide(L)") is listed. None keeps every polymer chain; an empty list keeps none. |
None
|
Returns:
| Type | Description |
|---|---|
AnnotationLayer
|
An |
AnnotationLayer
|
holds the settings used and, per chain pair in contact, the |
AnnotationLayer
|
contacting residue ids on each side and the residue pairs. |
Raises:
| Type | Description |
|---|---|
ValueError
|
|
TypeError
|
|
Source code in pandora/annotations/entry.py
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 | |
annotate_ligand_contacts(structure, distance_cutoff=4.0, include_waters=False)
¶
Compute polymer residues near non-polymer atoms within a cutoff.
Groups HETATM records into ligands (by asym/auth_seq/comp id) and,
for each ligand, finds polymer residues with at least one atom
within distance_cutoff angstroms of a ligand atom.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
structure
|
Structure
|
The structure to scan for ligand contacts. |
required |
distance_cutoff
|
float
|
Contact distance in angstroms. |
4.0
|
include_waters
|
bool
|
If True, treat water residues as ligands too. |
False
|
Returns:
| Type | Description |
|---|---|
AnnotationLayer
|
An |
AnnotationLayer
|
holds the cutoff/flags used and, per ligand, the contacting |
AnnotationLayer
|
polymer residues with their nearest distance. |
Source code in pandora/annotations/entry.py
annotate_pairwise_sequence_identity(left, right)
¶
Compute a simple ungapped sequence identity between two entries.
Compares every polymer entity in left against every polymer
entity in right with a position-wise (ungapped, no alignment)
identity, then reports the best-scoring pair.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
left
|
Structure
|
The first structure to compare. |
required |
right
|
Structure
|
The second structure to compare. |
required |
Returns:
| Type | Description |
|---|---|
AnnotationLayer
|
An |
AnnotationLayer
|
|
AnnotationLayer
|
pair, and every entity-pair comparison. |
Source code in pandora/annotations/pairwise.py
annotate_structure_counts(structure)
¶
Compute simple per-entry counts from the canonical structure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
structure
|
Structure
|
The canonical structure to summarize. |
required |
Returns:
| Type | Description |
|---|---|
AnnotationLayer
|
An |
AnnotationLayer
|
holds atom/residue/asym/entity/assembly/connection counts, |
AnnotationLayer
|
secondary-structure record counts, entity-type and atom-group |
AnnotationLayer
|
breakdowns, and the altloc atom count. |
Source code in pandora/annotations/entry.py
pandora.datasets
¶
chain_completeness(structure, definition='incomplete_backbone')
¶
Count the missing residues of each polymer chain against SEQRES.
SEQRES is _entity_poly_seq; a residue lines up with it by
label_seq_id. A chain that has no SEQRES, or whose residues don't
line up (for example after renumbering), gets no record and a
NO_SEQRES or SEQRES_MISMATCH warning instead.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
structure
|
Structure
|
The structure to measure. Its |
required |
definition
|
MissingResidueDefinition
|
|
'incomplete_backbone'
|
Returns:
| Type | Description |
|---|---|
list[ChainCompleteness]
|
|
DiagnosticBundle
|
polymer chain, and a warning per chain that could not be |
tuple[list[ChainCompleteness], DiagnosticBundle]
|
measured. |
Source code in pandora/datasets/completeness.py
curate_structure(structure, metadata, policy)
¶
Apply quality, organism, and content rules to one structure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
structure
|
Structure
|
The canonical structure to curate. |
required |
metadata
|
MetadataRecord | None
|
The structure's |
required |
policy
|
DatasetCurationPolicy
|
The curation policy governing every rule applied. |
required |
Returns:
| Type | Description |
|---|---|
Structure | None
|
|
list[ExclusionRecord]
|
is kept, |
CurationProvenance
|
failing chains removed, and |
tuple[Structure | None, list[ExclusionRecord], CurationProvenance]
|
removed chain. When the entry is excluded, |
tuple[Structure | None, list[ExclusionRecord], CurationProvenance]
|
is None and the last record in |
tuple[Structure | None, list[ExclusionRecord], CurationProvenance]
|
|
tuple[Structure | None, list[ExclusionRecord], CurationProvenance]
|
when) is always populated. Removing chains or ligands also |
tuple[Structure | None, list[ExclusionRecord], CurationProvenance]
|
removes the |
tuple[Structure | None, list[ExclusionRecord], CurationProvenance]
|
residues by id; they are listed in |
tuple[Structure | None, list[ExclusionRecord], CurationProvenance]
|
|
Source code in pandora/datasets/curation.py
deduplicate_structures(structures, rules)
¶
Remove structures sharing the same Structure.entry_id.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
structures
|
list[Structure]
|
Structures to deduplicate, in order. The first occurrence of each duplicate entry_id is kept. |
required |
rules
|
DeduplicationRules
|
Ignored (returns |
required |
Returns:
| Type | Description |
|---|---|
list[Structure]
|
|
list[ExclusionRecord]
|
structures, an |
DeduplicationProvenance
|
structure removed, and a record of how many duplicates were found. |
Source code in pandora/datasets/curation.py
entry_sequences(structures)
¶
One representative sequence per entry: its longest polymer chain.
Chain-keyed sequence similarity (e.g. compute_sequence_similarity on
ChainRecords) returns relationships keyed like "1abc_A", which won't
match entry-keyed item_ids (e.g. for clustering) — this picks one
sequence per entry instead.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
structures
|
dict[str, Structure]
|
Structures keyed by entry_id. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, str]
|
A mapping of entry_id -> sequence, one entry per structure that |
dict[str, str]
|
has at least one polymer chain with a sequence; entries with |
dict[str, str]
|
none are omitted. |
Source code in pandora/datasets/records.py
extract_chain_records(structure)
¶
Build one ChainRecord per polymer chain (asym unit) in structure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
structure
|
Structure
|
The canonical structure to extract chain records from. Non-polymer asym units, and polymer asym units with no atoms, are skipped. |
required |
Returns:
| Type | Description |
|---|---|
list[ChainRecord]
|
A |
list[ChainRecord]
|
entity's polymer record, if any), residue count, and atom count. |
Source code in pandora/datasets/records.py
extract_interface_records(structure, distance_cutoff=DEFAULT_INTERFACE_CUTOFF, atom_set='heavy', polymer_types=None)
¶
Build one InterfaceRecord per polymer chain pair in contact.
Contact detection itself lives in
annotations.entry.annotate_chain_interfaces — this function only
reshapes that annotation layer's output into records.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
structure
|
Structure
|
The canonical structure to extract interface records from. |
required |
distance_cutoff
|
float
|
Contact distance in angstroms. |
DEFAULT_INTERFACE_CUTOFF
|
atom_set
|
ContactAtomSet
|
Which atoms count towards contacts; see
|
'heavy'
|
polymer_types
|
list[str] | None
|
Keep only chains of these entity polymer types; None keeps every polymer chain. |
None
|
Returns:
| Type | Description |
|---|---|
list[InterfaceRecord]
|
An |
list[InterfaceRecord]
|
contact within |
Raises:
| Type | Description |
|---|---|
ValueError
|
|
TypeError
|
|
Source code in pandora/datasets/records.py
extract_residue_records(structure)
¶
Build one ResidueRecord per polymer residue in structure.
Each record carries its full atom list (coordinates, B-factor, etc.) rather than a bare count, so residue-level ML use cases (contact maps, solvent exposure) don't need to go back to the structure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
structure
|
Structure
|
The canonical structure to extract residue records from. Only atoms belonging to polymer asym units are considered. |
required |
Returns:
| Type | Description |
|---|---|
list[ResidueRecord]
|
A |
list[ResidueRecord]
|
then sequence id, each carrying every atom belonging to it. |
Source code in pandora/datasets/records.py
pandora.similarity
¶
chain_item_id(entry_id, chain_id)
¶
Item id for one chain's exported file — pair with
export_chain_mmcif(structure, chain_id, ...) so the id used for
compute_structure_similarity() matches the file it names.
Source code in pandora/similarity/structure.py
cluster_edges(item_ids, edges)
¶
Group item ids into connected-component clusters.
Two items land in the same cluster iff connected through a chain
of edges. Items with no edges form their own singleton cluster, so
every id in item_ids ends up in exactly one cluster. edges is
consumed once and never stored, so it can be a stream.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item_ids
|
list[str]
|
Every item id to place into a cluster. |
required |
edges
|
Iterable[Sequence[Any]]
|
Pairs of item ids, as |
required |
Returns:
| Type | Description |
|---|---|
list[SimilarityCluster]
|
|
ClusteringProvenance
|
smallest member), and the edge and cluster counts. |
tuple[list[SimilarityCluster], ClusteringProvenance]
|
|
Source code in pandora/similarity/clustering.py
cluster_similar_items(item_ids, search, hit_filter, *, interface_residues=None)
¶
Cluster item ids from a search's hit file, filtered by a policy.
Streams search's hit file through hit_filter (iter_edges())
into cluster_edges(); memory is bounded by the number of items,
not hits.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item_ids
|
list[str]
|
Every item id to place into a cluster. |
required |
search
|
SimilaritySearch
|
The search whose hit file to read. |
required |
hit_filter
|
HitFilter
|
Which hit rows become edges. |
required |
interface_residues
|
dict[str, set[int]] | None
|
Item id -> interface residue positions,
needed when |
None
|
Returns:
| Type | Description |
|---|---|
list[SimilarityCluster]
|
|
ClusteringProvenance
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
The filter can't apply to the search, or the hit
file is malformed (see |
Source code in pandora/similarity/clustering.py
compute_sequence_similarity(sequences, hits_path, *, mmseqs_bin='mmseqs', sensitivity=5.7, max_seqs=300, tmp_dir=None, mmseqs_options=None)
¶
All-vs-all sequence similarity via MMseqs2 easy-search.
Writes MMseqs2's hits to hits_path as a TSV with the columns in
HIT_COLUMNS["MMseqs2"] and keeps it there; nothing is loaded into
memory. Read it with iter_edges() / cluster_similar_items().
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sequences
|
dict[str, str] | list[ChainRecord] | str | Path
|
Mapping of item id -> sequence, a list of |
required |
hits_path
|
str | Path
|
Where to write the hit TSV. Parent directories are created. |
required |
mmseqs_bin
|
str
|
Path or name of the MMseqs2 binary. |
'mmseqs'
|
sensitivity
|
float
|
MMseqs2 |
5.7
|
max_seqs
|
int
|
MMseqs2 |
300
|
tmp_dir
|
str | Path | None
|
Working directory for FASTA/temporary files. None = system temp. |
None
|
mmseqs_options
|
list[str] | None
|
Additional options passed to MMseqs2. |
None
|
Returns:
| Type | Description |
|---|---|
SimilaritySearch
|
A |
SimilaritySearch
|
are this function's keyword arguments, so the search can be |
SimilaritySearch
|
re-run with `compute_sequence_similarity(seqs, path, |
SimilaritySearch
|
**search.parameters)`. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
|
ValueError
|
|
CalledProcessError
|
MMseqs2 failed. |
Source code in pandora/similarity/sequence.py
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 | |
compute_structure_similarity(structures, hits_path, *, foldseek_bin='foldseek', sensitivity=9.5, alignment_type=2, max_seqs=1000, exhaustive_search=False, tmp_dir=None, foldseek_options=None)
¶
All-vs-all structural similarity via Foldseek easy-search.
Writes Foldseek's hits to hits_path as a TSV with the columns in
HIT_COLUMNS["Foldseek"] (including qtmscore/ttmscore and the
alignment ranges) and keeps it there; nothing is loaded into
memory. Interface-restricted coverage is computed when reading,
with iter_edges(..., interface_residues=...).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
structures
|
dict[str, str | Path] | str | Path
|
Mapping of item id -> structure file path (PDB/mmCIF, optionally gzipped), or a path to a directory of existing structure files (ids are then Foldseek's own file-derived names). |
required |
hits_path
|
str | Path
|
Where to write the hit TSV. Parent directories are created. |
required |
foldseek_bin
|
str
|
Path or name of the Foldseek binary. |
'foldseek'
|
sensitivity
|
float
|
Foldseek |
9.5
|
alignment_type
|
int
|
Foldseek |
2
|
max_seqs
|
int
|
Foldseek |
1000
|
exhaustive_search
|
bool
|
Pass |
False
|
tmp_dir
|
str | Path | None
|
Working directory for structure/temporary files. None = system temp. |
None
|
foldseek_options
|
list[str] | None
|
Additional options passed to Foldseek. |
None
|
Returns:
| Type | Description |
|---|---|
SimilaritySearch
|
A |
SimilaritySearch
|
are this function's keyword arguments, so the search can be |
SimilaritySearch
|
re-run with `compute_structure_similarity(structures, path, |
SimilaritySearch
|
**search.parameters)`. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
|
CalledProcessError
|
Foldseek failed. |
Source code in pandora/similarity/structure.py
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 | |
interface_residues_from_annotation(structures, interface_layers)
¶
Bridge annotate_chain_interfaces() output into the
interface_residues mapping iter_edges() expects,
for one exported file per chain (export_chain_mmcif()).
Converts each interface's label_asym_id:label_seq_id residue ids to
Foldseek-aligned positions via residue_positions(), so callers never
have to reason about the numbering mismatch between mmCIF's
label_seq_id and Foldseek's own per-file residue order themselves.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
structures
|
dict[str, Structure]
|
|
required |
interface_layers
|
dict[str, AnnotationLayer]
|
|
required |
Returns:
| Type | Description |
|---|---|
dict[str, set[int]]
|
|
dict[str, set[int]]
|
entry per chain that appears in at least one interface. Pass |
dict[str, set[int]]
|
this to |
dict[str, set[int]]
|
|
dict[str, set[int]]
|
|
Source code in pandora/similarity/structure.py
iter_edges(search, hit_filter, *, interface_residues=None)
¶
Stream the hit rows of search that pass hit_filter.
Reads the hit file line by line; memory use does not grow with the
file. Self-hits are skipped, each yielded edge has
source_id < target_id, and a pair is yielded once per passing row
(so possibly more than once).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
search
|
SimilaritySearch
|
The search whose hit file to read. |
required |
hit_filter
|
HitFilter
|
Which rows become edges. |
required |
interface_residues
|
dict[str, set[int]] | None
|
Item id -> 1-indexed interface residue positions in that item's structure file (Foldseek only). When given, each row's interface coverage is computed. |
None
|
Returns:
| Type | Description |
|---|---|
Iterator[Edge]
|
An iterator of |
Raises:
| Type | Description |
|---|---|
ValueError
|
The filter can't apply to this search
( |
FileNotFoundError
|
The hit file doesn't exist (while iterating). |
Source code in pandora/similarity/hits.py
load_similarity_search(hits_path, engine, *, version=None, parameters=None)
¶
Wrap a hit file produced outside Pandora as a SimilaritySearch.
The file must be the tool's TSV with Pandora's fixed
--format-output columns (HIT_COLUMNS[engine]). Only the first
non-empty row is checked here; every row is checked again while
streaming.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hits_path
|
str | Path
|
Path to the existing hit TSV. |
required |
engine
|
str
|
"MMseqs2" or "Foldseek". |
required |
version
|
str | None
|
The tool version that produced the file, if known. |
None
|
parameters
|
dict[str, Any] | None
|
The settings the search was run with, if known. Copied, never aliased. |
None
|
Returns:
| Type | Description |
|---|---|
SimilaritySearch
|
A |
Raises:
| Type | Description |
|---|---|
ValueError
|
|
FileNotFoundError
|
|
Source code in pandora/similarity/hits.py
pair_cluster_keys(pairs, clusters)
¶
Derive a per-side cluster key for each PPI pair from item-level
clusters (e.g. Pinder-style {cluster_id_R, cluster_id_L}).
Each cluster's own lexicographically-smallest component id is used as that cluster's key, so the same item always maps to the same key regardless of clustering order.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pairs
|
list[tuple[str, str]]
|
|
required |
clusters
|
list[SimilarityCluster]
|
Item-level clusters, as returned by
|
required |
Returns:
| Type | Description |
|---|---|
dict[tuple[str, str], tuple[str, str]]
|
|
dict[tuple[str, str], tuple[str, str]]
|
entry per input pair. |
Raises:
| Type | Description |
|---|---|
KeyError
|
A pair references an item id not present in any cluster. |
Source code in pandora/similarity/clustering.py
partition_dataset(clusters, pct_train=0.6, pct_val=0.2, pct_test=0.2, keep_similar_items=True)
¶
Assign cluster members to train/val/test splits.
keep_similar_items=True (default): each cluster goes to a single split (whichever is most under its target share) — the leakage-safe mode. keep_similar_items=False: each cluster's members are divided proportionally across all three splits.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
clusters
|
list[SimilarityCluster]
|
The similarity clusters to assign, as returned by
|
required |
pct_train
|
float
|
Target fraction of items assigned to the train split. |
0.6
|
pct_val
|
float
|
Target fraction of items assigned to the val split. |
0.2
|
pct_test
|
float
|
Target fraction of items assigned to the test split.
|
0.2
|
keep_similar_items
|
bool
|
If True (default), each cluster is assigned whole to a single split (leakage-safe). If False, each cluster's members are divided proportionally across splits. |
True
|
Returns:
| Type | Description |
|---|---|
dict[str, list[str]]
|
|
PartitionProvenance
|
the fractions/mode applied and the resulting split sizes (for |
tuple[dict[str, list[str]], PartitionProvenance]
|
reporting how a dataset's split was built). |
Raises:
| Type | Description |
|---|---|
ValueError
|
|
Source code in pandora/similarity/partition.py
residue_positions(structure, chain_id)
¶
label_seq_id -> 1-indexed position for one chain, in the order
export_chain_mmcif()/structure_to_mmcif() write that chain's
atoms — i.e. the same numbering Foldseek assigns that chain's
residues when it parses the resulting file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
structure
|
Structure
|
The structure to read chain_id's atoms from. |
required |
chain_id
|
str
|
The |
required |
Returns:
| Type | Description |
|---|---|
dict[int, int]
|
One entry per residue that has atoms for this chain in |
dict[int, int]
|
|
dict[int, int]
|
from |
dict[int, int]
|
— it's also absent from the exported file, so there's nothing |
dict[int, int]
|
for Foldseek to number. |
Source code in pandora/similarity/structure.py
pandora.provenance
¶
build_dataset_manifest(*, dataset_id, dataset_name, dataset_version, curation_policy=None, canonicalisation_policy=None, excluded=(), deduplication=None, clustering=None, partition=None, splits=None, structures=())
¶
Assemble a single-file report of how a dataset was constructed.
Aggregates whatever provenance the caller already produced by running the dataset-construction stages — this function does not re-derive, recompute, or validate anything itself. Every argument beyond the dataset identity is optional so the manifest can be built with whichever stages actually ran (e.g. curation without clustering).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset_id
|
str
|
Stable identifier for this dataset build. |
required |
dataset_name
|
str
|
Human-readable name. |
required |
dataset_version
|
str
|
Version of this dataset build. |
required |
curation_policy
|
DatasetCurationPolicy | None
|
The policy passed to |
None
|
canonicalisation_policy
|
canonicalisationPolicy | None
|
The policy passed to
|
None
|
excluded
|
Sequence[ExclusionRecord]
|
|
()
|
deduplication
|
DeduplicationProvenance | None
|
Provenance from |
None
|
clustering
|
ClusteringProvenance | None
|
Provenance from |
None
|
partition
|
PartitionProvenance | None
|
Provenance from |
None
|
splits
|
dict[str, list[str]] | None
|
The split assignment returned by |
None
|
structures
|
Sequence[ProvenanceBundle]
|
A |
()
|
Returns:
| Type | Description |
|---|---|
DatasetManifest
|
A |
DatasetManifest
|
clustering/partition parameters, split assignment, and every |
DatasetManifest
|
retained structure's own provenance in one object. |
Source code in pandora/provenance/manifest.py
build_provenance_bundle(structure, *, ingestion=None, canonicalisation=None, metadata=None, annotations=())
¶
Assemble a ProvenanceBundle for one (canonicalised) structure.
Aggregates whatever provenance the caller already produced by running
the earlier pipeline stages — this function does not re-derive or
fetch anything itself. Every argument is optional so the bundle can be
built at any point in the pipeline (e.g. right after parsing, with
only ingestion set).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
structure
|
Structure
|
The structure to attribute the bundle to. |
required |
ingestion
|
IngestionProvenance | None
|
Provenance from |
None
|
canonicalisation
|
canonicalisationProvenance | None
|
Provenance from |
None
|
metadata
|
MetadataRecord | None
|
The record from |
None
|
annotations
|
Sequence[AnnotationLayer]
|
Any |
()
|
Returns:
| Type | Description |
|---|---|
ProvenanceBundle
|
A |
Source code in pandora/provenance/manifest.py
collect_metadata_provenance(metadata)
¶
Flatten the per-record provenance stamps out of a MetadataRecord.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
metadata
|
MetadataRecord
|
The collected metadata record. |
required |
Returns:
| Type | Description |
|---|---|
list[MetadataProvenance]
|
One |
list[MetadataProvenance]
|
each taxonomy/entity/ligand/UniProt mapping), in record order. |
Source code in pandora/provenance/manifest.py
reproduce_dataset(manifest, output_dir, *, fetch_options=None)
¶
Re-run the pipeline described by a DatasetManifest from scratch.
Re-fetches every structure via its recorded ingestion provenance,
then replays canonicalisation, curation, deduplication, similarity/
clustering, partitioning, and annotation exactly as the manifest
describes them. Every step is optional in the same way it is in
build_dataset_manifest (e.g. no clustering means no similarity
network is (re)computed).
This is a best-effort re-run, not a guaranteed byte-identical rebuild: source data can change upstream, and external similarity tools can drift between versions. The returned manifest is the record of what this run actually produced — diff it against the input manifest to see what changed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
manifest
|
DatasetManifest
|
A |
required |
output_dir
|
str | Path
|
Directory to fetch raw mmCIF files (and, for a Foldseek re-run, write canonicalised structures) into. |
required |
fetch_options
|
FetchOptions | None
|
Passed through to every |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, Structure]
|
|
DatasetManifest
|
structures keyed by entry_id, and a fresh |
tuple[dict[str, Structure], DatasetManifest]
|
describing this run. |
Raises:
| Type | Description |
|---|---|
ValueError
|
A structure's |
Source code in pandora/provenance/reproduce.py
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 | |
pandora.export
¶
export_chain_mmcif(structure, chain_id, path)
¶
Write a single chain (label_asym_id) of a Structure out as its
own mmCIF file.
Keeps only chain_id's atoms and connections; drops raw (verbatim
passthrough categories, e.g. _pdbx_sifts_xref_db, commonly
reference asym ids no longer present once other chains are dropped —
gemmi refuses to re-parse a dangling reference). entities/
asym_units/assemblies/secondary_structure are written
unfiltered, same as structure_to_mmcif — harmless extra rows a
structure-only consumer like Foldseek ignores.
Useful for per-chain structural similarity (e.g. PPI interface
coverage — see pandora.similarity.structure.residue_positions,
which numbers residues to match this file's atom order).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
structure
|
Structure
|
The structure to pull chain_id's atoms from. |
required |
chain_id
|
str
|
The |
required |
path
|
str | Path
|
Destination file path; parent directories are created if missing. |
required |
Returns:
| Type | Description |
|---|---|
Path
|
The resolved |
Source code in pandora/export/mmcif.py
structure_to_mmcif(structure, path)
¶
Write a Structure back out as an mmCIF file.
Rebuilds the standard mmCIF categories from Structure's typed
fields (entity/entity_poly/struct_asym/atom_site/struct_conn/
pdbx_struct_assembly*/struct_conf/struct_sheet_range) and re-emits
every category preserved verbatim in structure.raw.
This is a lossy round-trip: loop ordering, comments, and any field mmCIF supports but Pandora's schema doesn't carry (e.g. anisotropic B-factors) won't survive.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
structure
|
Structure
|
The structure to write out. |
required |
path
|
str | Path
|
Destination file path; parent directories are created if missing. |
required |
Returns:
| Type | Description |
|---|---|
Path
|
The resolved |
Source code in pandora/export/mmcif.py
write_json(model, path)
¶
Write any Pandora pydantic model to disk as pretty-printed JSON.
Covers every stage that returns a single model — canonicalisation provenance/mappings, MetadataRecord, AnnotationLayer, ProvenanceBundle, etc.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
BaseModel
|
The pydantic model instance to write. |
required |
path
|
str | Path
|
Destination file path; parent directories are created if missing. |
required |
Returns:
| Type | Description |
|---|---|
Path
|
The resolved |
Source code in pandora/export/json.py
write_records(records, path)
¶
Write a list of record models (Chain/Residue/InterfaceRecord, ...).
Dispatches on the file suffix
.parquet — columnar, via pandas/pyarrow (the export extra)
.json — a JSON array of the records
.jsonl — one JSON object per line
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
records
|
Sequence[BaseModel]
|
The record models to write; must be non-empty. |
required |
path
|
str | Path
|
Destination file path; its suffix ( |
required |
Returns:
| Type | Description |
|---|---|
Path
|
The resolved |
Raises:
| Type | Description |
|---|---|
ValueError
|
|
RuntimeError
|
|