Skip to content

Commit 39d9e60

Browse files
authored
Update biomolecule.py (#95)
1 parent 24ae4a2 commit 39d9e60

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

alphafold3_pytorch/common/biomolecule.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ def get_unique_res_atom_names(
307307

308308
@typecheck
309309
def _from_mmcif_object(
310-
mmcif_object: mmcif_parsing.MmcifObject, chain_id: Optional[str] = None
310+
mmcif_object: mmcif_parsing.MmcifObject, chain_ids: Optional[Set[str]] = None,
311311
) -> Biomolecule:
312312
"""Takes a Biopython structure/model mmCIF object and creates a `Biomolecule` instance.
313313
@@ -323,7 +323,7 @@ def _from_mmcif_object(
323323
can cause numerous downstream parsing errors.
324324
325325
:param mmcif_object: The parsed Biopython structure/model mmCIF object.
326-
:param chain_id: If chain_id is specified (e.g. A), then only that chain is parsed.
326+
:param chain_ids: If chain_ids are specified (e.g. A), then only these chains are parsed.
327327
Otherwise all chains are parsed.
328328
329329
:return: A new `Biomolecule` created from the structure/model mmCIF object contents.
@@ -354,12 +354,12 @@ def _from_mmcif_object(
354354
residue_chem_comp_details = set()
355355
atom_mask = []
356356
residue_index = []
357-
chain_ids = []
357+
chain_idx = []
358358
b_factors = []
359359
author_cri_to_new_cri = {}
360360

361361
for chain in model:
362-
if exists(chain_id) and chain.id != chain_id:
362+
if exists(chain_ids) and chain.id not in chain_ids:
363363
continue
364364
for res_index, res in enumerate(chain):
365365
if res.id[2] != " ":
@@ -431,7 +431,7 @@ def _from_mmcif_object(
431431
)
432432
atom_mask.append(mask)
433433
residue_index.append(res_index + 1)
434-
chain_ids.append(chain.id)
434+
chain_idx.append(chain.id)
435435
b_factors.append(res_b_factors)
436436
author_cri_to_new_cri[(chain.id, res.resname, res.id[1])] = (
437437
chain.id,
@@ -475,7 +475,7 @@ def _from_mmcif_object(
475475
atom_positions.append(pos)
476476
atom_mask.append(mask)
477477
residue_index.append(res_index + 1)
478-
chain_ids.append(chain.id)
478+
chain_idx.append(chain.id)
479479
b_factors.append(res_b_factors)
480480

481481
author_cri_to_new_cri[(chain.id, res.resname, res.id[1])] = (
@@ -500,9 +500,9 @@ def _from_mmcif_object(
500500
residue_chem_comp_details.add(res_chem_comp_details)
501501

502502
# Chain IDs are usually characters so map these to ints.
503-
unique_chain_ids = np.unique(chain_ids)
503+
unique_chain_ids = np.unique(chain_idx)
504504
chain_id_mapping = {cid: n for n, cid in enumerate(unique_chain_ids)}
505-
chain_index = np.array([chain_id_mapping[cid] for cid in chain_ids])
505+
chain_index = np.array([chain_id_mapping[cid] for cid in chain_idx])
506506

507507
# Construct a mapping from an integer entity ID to integer chain IDs.
508508
entity_to_chain = {
@@ -528,7 +528,7 @@ def _from_mmcif_object(
528528
atom_mask=np.array(atom_mask),
529529
residue_index=np.array(residue_index),
530530
chain_index=chain_index,
531-
chain_id=np.array(chain_ids),
531+
chain_id=np.array(chain_idx),
532532
b_factors=np.array(b_factors),
533533
chemid=np.array(chemid),
534534
chemtype=np.array(chemtype),
@@ -543,15 +543,15 @@ def _from_mmcif_object(
543543

544544

545545
@typecheck
546-
def from_mmcif_string(mmcif_str: str, file_id: str, chain_id: Optional[str] = None) -> Biomolecule:
546+
def from_mmcif_string(mmcif_str: str, file_id: str, chain_ids: Optional[Set[str]] = None) -> Biomolecule:
547547
"""Takes a mmCIF string and constructs a `Biomolecule` object.
548548
549549
WARNING: All non-standard residue types will be converted into UNK. All
550550
non-standard atoms will be ignored.
551551
552552
:param mmcif_str: The contents of the mmCIF file.
553553
:param file_id: The file ID (usually the PDB ID) to be used in the mmCIF.
554-
:param chain_id: If chain_id is specified (e.g. A), then only that chain is parsed.
554+
:param chain_ids: If chain_ids are specified (e.g. A), then only these chains are parsed.
555555
Otherwise all chains are parsed.
556556
557557
:return: A new `Biomolecule` parsed from the mmCIF contents.
@@ -566,7 +566,7 @@ def from_mmcif_string(mmcif_str: str, file_id: str, chain_id: Optional[str] = No
566566
if parsing_result.mmcif_object is None:
567567
raise list(parsing_result.errors.values())[0]
568568

569-
return _from_mmcif_object(parsing_result.mmcif_object, chain_id=chain_id)
569+
return _from_mmcif_object(parsing_result.mmcif_object, chain_ids=chain_ids)
570570

571571

572572
@typecheck

0 commit comments

Comments
 (0)