CIF Model
Core types (Rust extension)
cifflow_core
Builder
cifflow.cifmodel.builder
CifBuilder — constructs a CifFile from the CifParserEvents stream.
CifBuilder implements CifParserEvents and is wired directly to the Rust parser:
builder = CifBuilder(on_error=handler.on_error)
version = cifflow_core.parse(source, builder)
cif = builder.result
Semantic errors (empty loop, row-count mismatch) are reported via the on_error callable using error_type='semantic'. In strict mode the builder stops accumulating after the first semantic error; in pad mode it continues and pads incomplete loop rows with '?' placeholders.
Multiline text field values (ValueType.MULTILINE_STRING) are passed through the transformation pipeline (prefix removal + line unfolding) before storage. All other value types are stored as raw strings.
CifBuilder
Implements :class:~cifflow.types.CifParserEvents; accumulates events into a CifFile.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
on_error
|
Callable[[ParseError], None]
|
Called with a :class: |
required |
mode
|
Literal['strict', 'pad']
|
|
'pad'
|
Source code in src/cifflow/cifmodel/builder.py
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 | |
result
property
The CifFile accumulated so far.
on_data_block(name)
Casefold name, emit error on duplicate, and open a new data block.
Source code in src/cifflow/cifmodel/builder.py
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 | |
on_save_frame_start(name)
Casefold name, emit error on duplicate, and open a new save frame.
Source code in src/cifflow/cifmodel/builder.py
168 169 170 171 172 173 174 175 176 177 178 | |
on_save_frame_end()
Close the current save frame and register it with the block.
Source code in src/cifflow/cifmodel/builder.py
180 181 182 183 184 185 186 | |
add_tag(tag_name)
Casefold and register the pending tag name.
Source code in src/cifflow/cifmodel/builder.py
188 189 190 191 192 | |
add_value(value, value_type)
Transform multiline fields; quote bare dots/questions; dispatch the value.
Source code in src/cifflow/cifmodel/builder.py
194 195 196 197 198 199 200 201 202 | |
on_list_start()
Push a new list container onto the nesting stack.
Source code in src/cifflow/cifmodel/builder.py
204 205 206 207 208 | |
on_list_end()
Pop the completed list and dispatch it as a value.
Source code in src/cifflow/cifmodel/builder.py
210 211 212 213 214 215 | |
on_table_start()
Push a new table container onto the nesting stack.
Source code in src/cifflow/cifmodel/builder.py
217 218 219 220 221 | |
on_table_key(key, value_type)
Set the current key on the pending table container.
Source code in src/cifflow/cifmodel/builder.py
223 224 225 226 227 228 229 | |
on_table_end()
Pop the completed table and dispatch it as a value.
Source code in src/cifflow/cifmodel/builder.py
231 232 233 234 235 236 237 | |
on_loop_start(tags)
Initialise loop tracking with casefolded tag names and empty buffers.
Source code in src/cifflow/cifmodel/builder.py
239 240 241 242 243 244 245 246 | |
on_loop_end()
Validate row count; pad in pad mode; commit loop to the namespace.
Source code in src/cifflow/cifmodel/builder.py
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 | |
on_error(error)
Forward the parse error to the registered on_error callback.
Source code in src/cifflow/cifmodel/builder.py
288 289 290 | |
build(source, *, mode='pad')
Parse CIF source text and return a CifFile.
Uses the Rust IR builder directly — no per-token Python callbacks and no intermediate Python dict. Both parser-level and IR-level errors are returned in emission order.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
str
|
Full CIF source text. |
required |
mode
|
Literal['strict', 'pad']
|
Error-handling mode: |
'pad'
|
Returns:
| Type | Description |
|---|---|
tuple[CifFile, list[ParseError]]
|
A |
Source code in src/cifflow/cifmodel/builder.py
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 | |
build_arrow(source, *, mode='pad')
Parse CIF source text and return Arrow RecordBatches.
Each batch covers one logical namespace section: the scalar tags of a block/save frame, or one loop within it. The per-batch schema contains five metadata columns plus one column per tag present in that section.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
str
|
Full CIF source text. |
required |
mode
|
Literal['strict', 'pad']
|
Error-handling mode: |
'pad'
|
Returns:
| Type | Description |
|---|---|
tuple[list, list[ParseError]]
|
A |
Source code in src/cifflow/cifmodel/builder.py
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 | |
build_arrow_file(path, *, mode='pad')
Parse a CIF file from disk and return Arrow RecordBatches.
File I/O is performed entirely in Rust — no Python file objects are created.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Filesystem path to the CIF file. |
required |
mode
|
Literal['strict', 'pad']
|
Error-handling mode: |
'pad'
|
Returns:
| Type | Description |
|---|---|
tuple[list, list[ParseError]]
|
A |
Source code in src/cifflow/cifmodel/builder.py
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 | |
Writer
cifflow.cifmodel.writer
Programmatic CIF construction API.
CifWriter — file-level container; manages blocks and holds the CifFile. BlockWriter — write handle for one CifBlock. SaveFrameWriter — write handle for one CifSaveFrame (base class for BlockWriter).
Usage::
writer = CifWriter(CifVersion.CIF_2_0)
block = writer.add_block("my_block")
block.set_tag("_cell_length_a", "5.0")
cif = writer.build()
SaveFrameWriter
Write handle for one CifSaveFrame; obtained via BlockWriter.add_save_frame or get_save_frame.
Source code in src/cifflow/cifmodel/writer.py
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 | |
tags
property
Ordered list of tag names present in this namespace.
loops
property
Loop definitions as a list of tag-name groups.
get(tag, default=None)
Return the value list for tag, or default if the tag is absent.
Source code in src/cifflow/cifmodel/writer.py
160 161 162 163 164 165 | |
set_tag(tag, value)
Add a new scalar tag with the given value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tag
|
str
|
Fully qualified CIF tag name, e.g. |
required |
value
|
CifInput
|
Scalar value or CIF 2.0 container (list or dict). |
required |
Returns:
| Type | Description |
|---|---|
SaveFrameWriter
|
Returns self for method chaining. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the tag name is not a legal CIF identifier for the current version, or if the tag already exists in this namespace. |
Source code in src/cifflow/cifmodel/writer.py
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 | |
add_loop(columns)
Add a new loop with the given columns.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
columns
|
dict[str, list[CifInput]]
|
Mapping of tag name to value list. All lists must have the same length and no tag may already exist in this namespace. |
required |
Returns:
| Type | Description |
|---|---|
SaveFrameWriter
|
Returns self for method chaining. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in src/cifflow/cifmodel/writer.py
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 | |
add_loop_column(loop_tag, new_tag, values)
Append a new column to an existing loop.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
loop_tag
|
str
|
Any tag already in the target loop (used to identify it).
Raises |
required |
new_tag
|
str
|
Tag name for the new column. |
required |
values
|
list[CifInput]
|
Value list; length must equal the loop's current row count. |
required |
Returns:
| Type | Description |
|---|---|
SaveFrameWriter
|
Returns self for method chaining. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in src/cifflow/cifmodel/writer.py
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 | |
reorder_loop_tags(loop_tag, new_order)
Reorder the columns of an existing loop.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
loop_tag
|
str
|
Any tag already in the target loop (used to identify it).
Raises |
required |
new_order
|
list[str]
|
Complete list of tag names in the desired order; must be a permutation of the loop's current tag list. |
required |
Returns:
| Type | Description |
|---|---|
SaveFrameWriter
|
Returns self for method chaining. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in src/cifflow/cifmodel/writer.py
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 | |
get_loop_tags(loop_tag)
Return a copy of the ordered tag list for the loop containing loop_tag.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
loop_tag
|
str
|
Any tag already in the target loop (used to identify it). |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
Ordered list of tag names in the loop. Raises |
Source code in src/cifflow/cifmodel/writer.py
342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 | |
add_loop_row(loop_tag, row)
Append one row to an existing loop.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
loop_tag
|
str
|
Any tag already in the target loop (used to identify it).
Raises |
required |
row
|
list[CifInput]
|
Ordered list of values matching the loop's tag order. |
required |
Returns:
| Type | Description |
|---|---|
SaveFrameWriter
|
Returns self for method chaining. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in src/cifflow/cifmodel/writer.py
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 | |
reassign_tag(tag, value)
Replace the value(s) of an existing tag.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tag
|
str
|
Tag name to update. |
required |
value
|
'CifInput | list[CifInput]'
|
New value. For loop columns, pass a list of values with the same length as the loop row count. |
required |
Returns:
| Type | Description |
|---|---|
SaveFrameWriter
|
Returns self for method chaining. |
Raises:
| Type | Description |
|---|---|
KeyError
|
If the tag does not exist in this namespace. |
ValueError
|
If the tag is a loop column and |
Source code in src/cifflow/cifmodel/writer.py
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 | |
delete_tag(tag)
Delete a tag; removes it from its loop if it is a loop column.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tag
|
str
|
Tag name to delete. |
required |
Returns:
| Type | Description |
|---|---|
SaveFrameWriter
|
Returns self for method chaining. |
Raises:
| Type | Description |
|---|---|
KeyError
|
If the tag does not exist in this namespace. |
Source code in src/cifflow/cifmodel/writer.py
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 | |
remove_loop_tag(loop_tag, tag_to_remove)
Remove one tag from a loop, deleting the loop entirely if it becomes empty.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
loop_tag
|
str
|
Any tag already in the target loop (used to identify it). |
required |
tag_to_remove
|
str
|
Tag name to remove from the loop. |
required |
Returns:
| Type | Description |
|---|---|
SaveFrameWriter
|
Returns self for method chaining. |
Raises:
| Type | Description |
|---|---|
KeyError
|
If |
Source code in src/cifflow/cifmodel/writer.py
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 | |
BlockWriter
Bases: SaveFrameWriter
Write handle for one CifBlock; obtained via CifWriter.add_block or get_block.
Source code in src/cifflow/cifmodel/writer.py
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 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 | |
save_frames
property
Ordered list of save frame names in this block.
set_tag(tag, value)
Add a new scalar tag; returns BlockWriter for method chaining.
Source code in src/cifflow/cifmodel/writer.py
527 528 529 530 | |
add_loop(columns)
Add a new loop; returns BlockWriter for method chaining.
Source code in src/cifflow/cifmodel/writer.py
532 533 534 535 | |
add_loop_column(loop_tag, new_tag, values)
Append a column to an existing loop; returns BlockWriter for method chaining.
Source code in src/cifflow/cifmodel/writer.py
537 538 539 540 | |
reorder_loop_tags(loop_tag, new_order)
Reorder loop columns; returns BlockWriter for method chaining.
Source code in src/cifflow/cifmodel/writer.py
542 543 544 545 | |
add_loop_row(loop_tag, row)
Append a loop row; returns BlockWriter for method chaining.
Source code in src/cifflow/cifmodel/writer.py
547 548 549 550 | |
reassign_tag(tag, value)
Replace a tag value; returns BlockWriter for method chaining.
Source code in src/cifflow/cifmodel/writer.py
552 553 554 555 | |
delete_tag(tag)
Delete a tag; returns BlockWriter for method chaining.
Source code in src/cifflow/cifmodel/writer.py
557 558 559 560 | |
remove_loop_tag(loop_tag, tag_to_remove)
Remove a loop column; returns BlockWriter for method chaining.
Source code in src/cifflow/cifmodel/writer.py
562 563 564 565 | |
add_save_frame(name)
Add a new save frame to this block and return its writer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Save frame name (without the |
required |
Returns:
| Type | Description |
|---|---|
SaveFrameWriter
|
Writer handle for the new save frame. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in src/cifflow/cifmodel/writer.py
576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 | |
get_save_frame(name, index=0)
Return a writer handle for an existing save frame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Save frame name to look up (case-insensitive). |
required |
index
|
int
|
Which occurrence to return when there are duplicate names; 0-based. |
0
|
Returns:
| Type | Description |
|---|---|
SaveFrameWriter
|
Writer handle for the requested save frame. |
Raises:
| Type | Description |
|---|---|
KeyError
|
If no save frame with that name exists in the block. |
Source code in src/cifflow/cifmodel/writer.py
606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 | |
remove_save_frame(name, *, from_end=False)
Remove one save frame from this block.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Save frame name to remove (case-insensitive). |
required |
from_end
|
bool
|
If |
False
|
Returns:
| Type | Description |
|---|---|
BlockWriter
|
Returns self for method chaining. |
Raises:
| Type | Description |
|---|---|
KeyError
|
If no save frame with that name exists in the block. |
Source code in src/cifflow/cifmodel/writer.py
633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 | |
rename_save_frame(old_name, new_name)
Rename a save frame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
old_name
|
str
|
Current save frame name (case-insensitive). |
required |
new_name
|
str
|
New save frame name. |
required |
Returns:
| Type | Description |
|---|---|
BlockWriter
|
Returns self for method chaining. |
Raises:
| Type | Description |
|---|---|
KeyError
|
If |
ValueError
|
If |
Source code in src/cifflow/cifmodel/writer.py
671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 | |
CifWriter
File-level container for programmatic CIF construction.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
version
|
CifVersion
|
CIF specification version to validate new names and values against. |
required |
cif
|
CifFile | None
|
Existing :class: |
None
|
Source code in src/cifflow/cifmodel/writer.py
714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 | |
version
property
CIF specification version this writer validates new names against.
blocks
property
Ordered list of block names in this CifWriter.
get(name, default=None)
Return the CifBlock for name, or default if the block is absent.
Source code in src/cifflow/cifmodel/writer.py
765 766 767 768 769 | |
add_block(name)
Add a new block to this CifFile and return its writer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Block name (without the |
required |
Returns:
| Type | Description |
|---|---|
BlockWriter
|
Writer handle for the new block. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in src/cifflow/cifmodel/writer.py
773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 | |
get_block(name, index=0)
Return a writer handle for an existing block.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Block name to look up (case-insensitive). |
required |
index
|
int
|
Which occurrence to return when names are duplicated; 0-based. |
0
|
Returns:
| Type | Description |
|---|---|
BlockWriter
|
Writer handle for the requested block. |
Raises:
| Type | Description |
|---|---|
KeyError
|
If no block with that name exists. |
Source code in src/cifflow/cifmodel/writer.py
801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 | |
remove_block(name, *, from_end=False)
Remove one block from this CifFile.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Block name to remove (case-insensitive). |
required |
from_end
|
bool
|
If |
False
|
Returns:
| Type | Description |
|---|---|
CifWriter
|
Returns self for method chaining. |
Raises:
| Type | Description |
|---|---|
KeyError
|
If no block with that name exists. |
Source code in src/cifflow/cifmodel/writer.py
828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 | |
rename_block(old_name, new_name)
Rename a block.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
old_name
|
str
|
Current block name (case-insensitive). |
required |
new_name
|
str
|
New block name. |
required |
Returns:
| Type | Description |
|---|---|
CifWriter
|
Returns self for method chaining. |
Raises:
| Type | Description |
|---|---|
KeyError
|
If |
ValueError
|
If |
Source code in src/cifflow/cifmodel/writer.py
866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 | |
build()
Validate and return the completed CifFile.
Returns:
| Type | Description |
|---|---|
CifFile
|
The constructed CifFile, ready for ingestion or emission. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the file is empty, any loop has unequal column lengths or zero rows, any scalar tag has a value count other than 1, or any tag holds a container value in CIF 1.1 mode. |
Source code in src/cifflow/cifmodel/writer.py
904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 | |
Clean
cifflow.cifmodel.clean
Cleaning API for parser-produced CifFile objects.
clean() removes well-known parse-time artefacts: - orphan error values (_cifflow_error_value synthetic tag) - duplicate blocks, save frames, and scalar tags - loop padding added by CifBuilder in pad mode
Returns a new CifFile (copy=True, default) or mutates in place (copy=False). Every removal produces a CleanWarning — nothing is silently discarded.
CleanWarning
dataclass
Record of one removal action performed by :func:clean.
Attributes:
| Name | Type | Description |
|---|---|---|
category |
str
|
Cleaning step name, e.g. |
block |
str | None
|
Name of the affected block, or |
save_frame |
str | None
|
Name of the affected save frame, or |
message |
str
|
Human-readable description of what was removed. |
Source code in src/cifflow/cifmodel/clean.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | |
clean(cif, *, copy=True, remove_error_values=True, deduplicate_blocks='first', deduplicate_save_frames='first', deduplicate_tags='first', strip_loop_padding=True)
Remove common parse-time artefacts from a CifFile.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cif
|
CifFile
|
The source CifFile to clean. |
required |
copy
|
bool
|
If |
True
|
remove_error_values
|
bool
|
Remove orphan |
True
|
deduplicate_blocks
|
Keep | Literal[False]
|
|
'first'
|
deduplicate_save_frames
|
Keep | Literal[False]
|
|
'first'
|
deduplicate_tags
|
Keep | Literal[False]
|
|
'first'
|
strip_loop_padding
|
bool
|
Remove trailing |
True
|
Returns:
| Type | Description |
|---|---|
tuple[CifFile, list[CleanWarning]]
|
A |
Source code in src/cifflow/cifmodel/clean.py
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 | |