1 """@namespace IMP.mmcif.restraint
2 @brief Map IMP restraints to mmCIF categories
8 def _parse_restraint_info(info):
9 """Convert RestraintInfo object to Python dict"""
13 info.set_was_used(
True)
14 for typ
in (
'int',
'float',
'string',
'filename',
'floats',
'filenames'):
15 for i
in range(getattr(info,
'get_number_of_' + typ)()):
16 key = getattr(info,
'get_%s_key' % typ)(i)
17 value = getattr(info,
'get_%s_value' % typ)(i)
22 class _GaussianEMRestraint(ihm.restraint.EM3DRestraint):
23 """Handle an IMP.isd.GaussianEMRestraint"""
25 def __init__(self, imp_restraint, info, modeled_assembly):
26 self._imp_restraint = imp_restraint
27 p = IMP.mmcif.metadata._GMMParser()
28 r = p.parse_file(info[
'filename'])
29 super(_GaussianEMRestraint, self).__init__(
31 assembly=modeled_assembly,
32 number_of_gaussians=r[
'number_of_gaussians'],
33 fitting_method=
'Gaussian mixture model')
35 def add_model_fit(self, model):
36 info = _parse_restraint_info(self._imp_restraint.get_dynamic_info())
37 self.fits[model] = ihm.restraint.EM3DRestraintFit(
38 cross_correlation_coefficient=info[
'cross correlation'])
41 class _RestraintMapper(object):
42 """Map IMP restraints to mmCIF objects"""
43 def __init__(self, system):
44 self._typemap = {
"IMP.isd.GaussianEMRestraint": _GaussianEMRestraint}
47 def handle(self, r, model, modeled_assembly):
48 """Handle an individual IMP restraint.
49 @return a wrapped version of the restraint if it is handled in
50 mmCIF, otherwise None."""
51 info = _parse_restraint_info(r.get_static_info())
52 if 'type' in info
and info[
'type']
in self._typemap:
53 r = self._typemap[info[
'type']](r, info, modeled_assembly)
54 r.add_model_fit(model)