Skip to content

Commit f9bf384

Browse files
committed
Print assembly ID if we have it
Don't use id(asmb) in Python error message, as that won't the help the user identify the assembly. Use the mmCIF ID instead if it has one.
1 parent 8fe6475 commit f9bf384

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

ihm/dumper.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1802,6 +1802,8 @@ class _AssemblyChecker:
18021802
def __init__(self):
18031803
# Map from Assembly id to set of Asym ids
18041804
self._asmb_asyms = {}
1805+
# Map from Assembly id to Assembly object
1806+
self._asmb_from_id = {}
18051807

18061808
# Map from Assembly id to set of all represented Asym ids (in models)
18071809
self._asmb_model_asyms = {}
@@ -1812,6 +1814,7 @@ def add_model_asyms(self, model, seen_asym_ids):
18121814
# If this is the first time we've seen this assembly, get its
18131815
# declared set of asym IDs
18141816
if id(asmb) not in self._asmb_asyms:
1817+
self._asmb_from_id[id(asmb)] = asmb
18151818
asyms = frozenset(x._id for x in asmb if hasattr(x, 'entity'))
18161819
self._asmb_asyms[id(asmb)] = asyms
18171820
# Add asym IDs from model
@@ -1827,9 +1830,12 @@ def get_extra_asyms():
18271830
for asmb_id, asyms in self._asmb_asyms.items():
18281831
extra = asyms - self._asmb_model_asyms[asmb_id]
18291832
if extra:
1833+
asmb = self._asmb_from_id[asmb_id]
1834+
asmb_id = ("ID %s" % asmb._id
1835+
if hasattr(asmb, '_id') else asmb)
18301836
yield asmb_id, ", ".join(sorted(extra))
18311837

1832-
err = "; ".join("assembly ID %s, asym IDs %s" % extra
1838+
err = "; ".join("%s, asym IDs %s" % extra
18331839
for extra in get_extra_asyms())
18341840
if err:
18351841
raise ValueError(

test/test_dumper.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2817,6 +2817,7 @@ def test_model_dumper_assembly_asym_check(self):
28172817
_get_dumper_output(dumper, system)
28182818
self.assertIn("reference asym IDs that don't have coordinates",
28192819
str(cm.exception))
2820+
self.assertIn("ID 99, asym IDs X", str(cm.exception))
28202821
# Should work though if checks are disabled
28212822
_ = _get_dumper_output(dumper, system, check=False)
28222823

0 commit comments

Comments
 (0)