Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

auto-detect same entity for non-ligands #251

Merged
merged 2 commits into from
Dec 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 17 additions & 10 deletions chai_lab/data/io/cif_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ def get_chains_metadata(
token_res_names = context.token_res_names_to_string

asym_id2asym_unit = {}
entity_key2ihm_entity = {}

for asym_id, entity_type in context.asym_id2entity_type.items():
assert asym_id != 0, "zero is padding for asym_id"
Expand All @@ -96,27 +97,33 @@ def get_chains_metadata(
any_token_in_resi = residue_indices.new_zeros([max_res + 1]) - 99

any_token_in_resi[residue_indices] = torch.arange(
len(residue_indices),
dtype=residue_indices.dtype,
device=residue_indices.device,
len(residue_indices), dtype=any_token_in_resi.dtype
)

assert any_token_in_resi.min() >= 0

sequence = [chain_token_res_names[i] for i in any_token_in_resi]

chain_id_str = _get_chain_letter(asym_id)
if entity_type == EntityType.LIGAND.value:
entity_key = (entity_type, asym_id) # each ligand = separate entity.
else:
entity_key = (entity_type, *sequence)

asym_id2asym_unit[asym_id] = AsymUnit(
entity=Entity(
asym_entity_name = asymid2entity_name[asym_id]
if entity_key not in entity_key2ihm_entity:
entity_key2ihm_entity[entity_key] = Entity(
# sequence is a list of ChemComponents for aminoacids/bases
sequence=[
_to_chem_component(resi, entity_type, asym_id) for resi in sequence
],
description=asymid2entity_name[asym_id],
),
details=f"Chain {chain_id_str}",
id=chain_id_str,
# will be named same as first among replicas
description=f"Entity {asym_entity_name}",
)

asym_id2asym_unit[asym_id] = AsymUnit(
entity=entity_key2ihm_entity[entity_key],
details=f"Chain {asym_entity_name}",
id=asym_entity_name,
)

return asym_id2asym_unit
Expand Down
Loading