1 """@namespace IMP.mmcif.metadata
3 Classes to extract metadata for various input files.
12 class _GMMParser(ihm.metadata.Parser):
13 """Extract metadata from an EM density GMM file."""
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 loc = ihm.location.InputFileLocation(
20 filename, details=
"Electron microscopy density map, "
21 "represented as a Gaussian Mixture Model (GMM)")
24 loc._allow_duplicates =
True
25 d = ihm.dataset.EMDensityDataset(loc)
26 ret = {
'dataset': d,
'number_of_gaussians':
None}
28 with open(filename)
as 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:])