Skip to content

Commit ce8ece9

Browse files
committed
Always return ModelRepresentative object
If there is no user-provided representative model, auto-generate a ModelRepresentative object that wraps the selected model. Relates #174.
1 parent 707d46d commit ce8ece9

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

ihm/__init__.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,9 @@ def _all_models(self):
271271
def get_representative_model(self):
272272
"""Get a single :class:`~model.ModelRepresentative` that best
273273
represents the entire System. If no representatives have been
274-
provided, the :class:`~model.Model` containing the most chains
274+
provided, an auto-generated :class:`~model.ModelRepresentative`
275+
(with ``selection_criteria`` of ``auto``), wrapping the
276+
:class:`~model.Model` containing the most chains,
275277
is returned instead."""
276278
repmodel = None
277279
repmodel_chains = -1
@@ -287,7 +289,10 @@ def get_representative_model(self):
287289
if repmodel is None:
288290
raise ValueError("No models")
289291
else:
290-
return repmodel
292+
import ihm.model
293+
m = ihm.model.ModelRepresentative(repmodel, 'medoid')
294+
m._selection_criteria = 'auto'
295+
return m
291296

292297
def update_locations_in_repositories(self, repos):
293298
"""Update all :class:`~ihm.location.Location` objects in the system

test/test_main.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1434,8 +1434,10 @@ def test_get_representative_model(self):
14341434
s.state_groups.append(ihm.model.StateGroup([state]))
14351435

14361436
# m2 contains two chains to m1's one, so it should be selected
1437-
# by default
1438-
self.assertIs(s.get_representative_model(), m2)
1437+
# by default (as an auto-generated model)
1438+
r = s.get_representative_model()
1439+
self.assertIs(r.model, m2)
1440+
self.assertEqual(r.selection_criteria, 'auto')
14391441

14401442
# If we explicitly denote m1 as the representative, it should
14411443
# be returned instead

0 commit comments

Comments
 (0)