Skip to content

Commit

Permalink
Warn, not fail, on nonsequential fragments
Browse files Browse the repository at this point in the history
Follow existing PMI behavior when we encounter
non-sequential fragments - that is, pretend they
cover their entire sequence without gaps. Emit
a warning to make the user aware.
  • Loading branch information
benmwebb committed Aug 8, 2024
1 parent 5a0f54c commit 8cdb99d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
8 changes: 5 additions & 3 deletions modules/mmcif/pyext/src/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import ihm.reference
import operator
import inspect
import warnings


# Map from IMP ResidueType to ihm ChemComp
Expand Down Expand Up @@ -52,9 +53,10 @@ def get_molecule(h):
def _check_sequential(fragment, resinds):
for i in range(1, len(resinds)):
if resinds[i - 1] + 1 != resinds[i]:
raise ValueError(
"%s: non-sequential residue indices are not supported"
% str(fragment))
warnings.warn(
"%s: non-sequential residue indices; mmCIF bead will cover "
"indices [%d-%d]"
% (str(fragment), resinds[0], resinds[-1]))


def _get_all_state_provenance(state_h, top_h, types):
Expand Down
11 changes: 9 additions & 2 deletions modules/mmcif/test/test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,13 +379,20 @@ def test_coordinate_handler_get_structure_particles(self):
self.assertIsInstance(ps[1], IMP.atom.Atom)
self.assertIsInstance(ps[2], IMP.atom.Fragment)

# Non-sequential fragments are not supported
def test_coordinate_handler_get_structure_particles_nonseq(self):
"""Test get_structure_particles() with non-sequential fragment"""
m = IMP.Model()
top = IMP.atom.Hierarchy.setup_particle(IMP.Particle(m))
frag = IMP.atom.Fragment.setup_particle(IMP.Particle(m), [5, 6, 7, 9])
IMP.core.XYZR.setup_particle(
frag, IMP.algebra.Sphere3D(IMP.algebra.Vector3D(1, 2, 3), 4))
IMP.atom.Mass.setup_particle(frag, 1.0)
top.add_child(frag)
self.assertRaises(ValueError, ch.get_structure_particles, top)
ch = IMP.mmcif.data._CoordinateHandler(None, None)
with self.assertWarns(UserWarning):
ps = ch.get_structure_particles(top)
self.assertEqual(len(ps), 1)
self.assertIsInstance(ps[0], IMP.atom.Fragment)

def test_coordinate_handler_add_chain(self):
"""Test CoordinateHandler.add_chain()"""
Expand Down

0 comments on commit 8cdb99d

Please sign in to comment.