Skip to content

Commit

Permalink
Pass clone representation to ProtocolOutput
Browse files Browse the repository at this point in the history
If we clone a subunit, pass the original
representation to ProtocolOutput again so it
is also cloned in the mmCIF output.
  • Loading branch information
benmwebb committed Aug 24, 2023
1 parent e8357fd commit d853308
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 1 deletion.
19 changes: 18 additions & 1 deletion pyext/src/topology/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,8 @@ def build(self, **kwargs):
mol._build_protocol_output()
for mol in reversed(self.molecules[molname]):
mol.build(protocol_output=False, **kwargs)
for mol in self.molecules[molname]:
mol._finalize_build()
self.built = True
return self.hier

Expand Down Expand Up @@ -795,6 +797,17 @@ def _build_protocol_output(self):
asym_name=self._name_with_copy,
alphabet=self.alphabet)

def _finalize_build(self):
# For clones, pass the representation of the original molecule
# to ProtocolOutput
if self.mol_to_clone:
rephandler = _RepresentationHandler(
self._name_with_copy, list(self._all_protocol_output()),
self.mol_to_clone._pdb_elements)
for res in self.mol_to_clone.residues:
if res.hier:
rephandler(res)

def build(self, protocol_output=True):
"""Create all parts of the IMP hierarchy
including Atoms, Residues, and Fragments/Representations and,
Expand Down Expand Up @@ -883,7 +896,11 @@ def build(self, protocol_output=True):
# otherwise just store what you found
new_hier = IMP.atom.Hierarchy(new_p)
res.hier = new_hier
rephandler(res)
# Clones will be handled in _finalize_build() instead
# (can't handle them here as the parent of the clone
# isn't built yet)
if self.mol_to_clone is None:
rephandler(res)
else:
res.hier = None
self._represented = IMP.pmi.tools.OrderedSet(
Expand Down
57 changes: 57 additions & 0 deletions test/test_mmcif.py
Original file line number Diff line number Diff line change
Expand Up @@ -2048,6 +2048,63 @@ def test_model_repr_dump_rigid(self):
1 1 1 Nup84 A 1 sphere 1 rigid by-residue . .
2 1 1 Nup84 A 2 sphere . flexible by-feature 1 .
#
""")

def test_model_repr_dump_clone(self):
"""Test ModelRepresentationDumper with clones"""
m = IMP.Model()
s = IMP.pmi.topology.System(m)
po = IMP.pmi.mmcif.ProtocolOutput()
s.add_protocol_output(po)
state = s.create_state()
nup84 = state.create_molecule("Nup84", "MELS", "A")
nup84.add_structure(self.get_input_file_name('test.nup84.pdb'), 'A')
nup84.add_representation(nup84.get_atomic_residues(), resolutions=[1])
nup84.add_representation(nup84.get_non_atomic_residues(),
resolutions=[10])
clone = nup84.create_clone("B")
_ = s.build()
dof = IMP.pmi.dof.DegreesOfFreedom(m)
dof.create_rigid_body(nup84.get_atomic_residues())
fh = StringIO()
w = ihm.format.CifWriter(fh)
self.assign_entity_asym_ids(po.system)
self.assign_range_ids(po.system)
# Need this to assign starting model details
ihm.dumper._StartingModelDumper().finalize(po.system)
d = ihm.dumper._ModelRepresentationDumper()
d.finalize(po.system)
d.dump(po.system, w)
r, = po.system.orphan_representations
self.assertEqual([f.asym_unit.seq_id_range for f in r],
[(1, 2), (3, 4), (1, 2), (3, 4)])
out = fh.getvalue()
self.assertEqual(out, """#
loop_
_ihm_model_representation.id
_ihm_model_representation.name
_ihm_model_representation.details
1 'Default representation' .
#
#
loop_
_ihm_model_representation_details.id
_ihm_model_representation_details.representation_id
_ihm_model_representation_details.entity_id
_ihm_model_representation_details.entity_description
_ihm_model_representation_details.entity_asym_id
_ihm_model_representation_details.entity_poly_segment_id
_ihm_model_representation_details.model_object_primitive
_ihm_model_representation_details.starting_model_id
_ihm_model_representation_details.model_mode
_ihm_model_representation_details.model_granularity
_ihm_model_representation_details.model_object_count
_ihm_model_representation_details.description
1 1 1 Nup84 A 1 sphere 1 rigid by-residue . .
2 1 1 Nup84 A 2 sphere . flexible by-feature 1 .
3 1 1 Nup84 B 1 sphere 2 rigid by-residue . .
4 1 1 Nup84 B 2 sphere . flexible by-feature 1 .
#
""")

def test_flush(self):
Expand Down

0 comments on commit d853308

Please sign in to comment.