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