IMP logo
IMP Reference Guide  2.11.0
The Integrative Modeling Platform
mmcif/metadata.py
1 """@namespace IMP.mmcif.metadata
2 
3  Classes to extract metadata for various input files.
4 """
5 
6 import os
7 import ihm.dataset
8 import ihm.location
9 import ihm.metadata
10 
11 
12 class _GMMParser(ihm.metadata.Parser):
13  """Extract metadata from an EM density GMM file."""
14 
15  def parse_file(self, filename):
16  """Extract metadata from `filename`.
17  @return a dict with key `dataset` pointing to the GMM file and
18  `number_of_gaussians` to the number of GMMs (or None)"""
19  l = ihm.location.InputFileLocation(filename,
20  details="Electron microscopy density map, "
21  "represented as a Gaussian Mixture Model (GMM)")
22  # A 3DEM restraint's dataset ID uniquely defines the mmCIF restraint, so
23  # we need to allow duplicates
24  l._allow_duplicates = True
25  d = ihm.dataset.EMDensityDataset(l)
26  ret = {'dataset':d, 'number_of_gaussians':None}
27 
28  with open(filename) as fh:
29  for line in fh:
30  if line.startswith('# data_fn: '):
31  p = ihm.metadata.MRCParser()
32  fn = line[11:].rstrip('\r\n')
33  dataset = p.parse_file(os.path.join(
34  os.path.dirname(filename), fn))['dataset']
35  ret['dataset'].parents.append(dataset)
36  elif line.startswith('# ncenters: '):
37  ret['number_of_gaussians'] = int(line[12:])
38  return ret