55
55
from biotite .structure .io .pdbx .cif import CIFBlock , CIFFile
56
56
from biotite .structure .io .pdbx .component import MaskValue
57
57
from biotite .structure .io .pdbx .encoding import StringArrayEncoding
58
+ from biotite .structure .repair import create_continuous_res_ids
58
59
from biotite .structure .residues import (
59
60
get_residue_count ,
60
61
get_residue_positions ,
@@ -496,12 +497,6 @@ def _fill_annotations(array, atom_site, extra_fields, use_author_fields):
496
497
atom_site , f"{ prefix } _asym_id" , f"{ alt_prefix } _asym_id"
497
498
).as_array (str ),
498
499
)
499
- array .set_annotation (
500
- "res_id" ,
501
- _get_or_fallback (
502
- atom_site , f"{ prefix } _seq_id" , f"{ alt_prefix } _seq_id"
503
- ).as_array (int , - 1 ),
504
- )
505
500
array .set_annotation ("ins_code" , atom_site ["pdbx_PDB_ins_code" ].as_array (str , "" ))
506
501
array .set_annotation (
507
502
"res_name" ,
@@ -518,6 +513,22 @@ def _fill_annotations(array, atom_site, extra_fields, use_author_fields):
518
513
)
519
514
array .set_annotation ("element" , atom_site ["type_symbol" ].as_array (str ))
520
515
516
+ # Special handling for `res_id`, as the `label_seq_id` is equal (`.`) for all
517
+ # hetero residues, which makes distinguishing subsequent residues from another
518
+ # difficult (https://github.com/biotite-dev/biotite/issues/553)
519
+ res_id = _get_or_fallback (
520
+ atom_site , f"{ prefix } _seq_id" , f"{ alt_prefix } _seq_id"
521
+ ).as_array (int , - 1 )
522
+ if not use_author_fields and "auth_seq_id" in atom_site :
523
+ # Therefore, the `auth_seq_id` is still used to determine residue starts
524
+ # in `create_continuous_res_ids()`, even if `use_author_fields = False`.
525
+ res_id_for_residue_starts = atom_site ["auth_seq_id" ].as_array (int , - 1 )
526
+ array .set_annotation ("res_id" , res_id_for_residue_starts )
527
+ fallback_res_ids = create_continuous_res_ids (array )
528
+ array .set_annotation ("res_id" , np .where (res_id == - 1 , fallback_res_ids , res_id ))
529
+ else :
530
+ array .set_annotation ("res_id" , res_id )
531
+
521
532
if "atom_id" in extra_fields :
522
533
if "id" in atom_site :
523
534
array .set_annotation ("atom_id" , atom_site ["id" ].as_array (int ))
0 commit comments