IMP logo
IMP Reference Guide  2.8.0
The Integrative Modeling Platform
segment.py
1 #!/usr/bin/env python
2 
3 __doc__ = "Anchor graph segmentation of a density map."
4 
5 import IMP.multifit
6 import IMP.em
7 from IMP import OptionParser
8 
9 
10 def parse_args():
11  usage = """%prog [options] <density.mrc> <number of clusters>
12  <density threshold> <output.pdb>
13 
14 Segments all voxels in the given density map, above the given threshold,
15 into the given number of clusters, and links between neighboring ones.
16 
17 The cluster centers are written out into a single output PDB file, each
18 as a single CA atom.
19 """
20  parser = OptionParser(usage)
21  parser.add_option("--apix", type="float", default=None,
22  help="map spacing, in angstroms/pix (default: read "
23  "from MRC file)")
24  parser.add_option("-x", "--x", type="float", default=None,
25  help="X origin of the density map")
26  parser.add_option("-y", "--y", type="float", default=None,
27  help="Y origin of the density map")
28  parser.add_option("-z", "--z", type="float", default=None,
29  help="Z origin of the density map")
30  parser.add_option("--cmm", type="str", default="",
31  help="write results in CMM format")
32  parser.add_option("--seg", type="str", default="",
33  help="write out each cluster as an MRC file called "
34  "<seg>_.mrc, and write load_segmentation.cmd file "
35  "to easily load all segments into Chimera")
36  parser.add_option("--txt", type="str", default="",
37  help="write anchor points file in text format")
38  options, args = parser.parse_args()
39 
40  if len(args) != 4:
41  parser.error("incorrect number of arguments")
42  return options, args
43 
44 
45 def main():
46  opts, args = parse_args()
47  asmb_fn, num_cluster, threshold, output = args
48  num_cluster = int(num_cluster)
49  threshold = float(threshold)
50  dmap = IMP.em.read_map(asmb_fn, IMP.em.MRCReaderWriter())
51  if opts.apix is None:
52  opts.apix = dmap.get_spacing()
53  else:
54  dmap.update_voxel_size(opts.apix)
55  v = dmap.get_origin()
56  if opts.x is None:
57  opts.x = v[0]
58  if opts.y is None:
59  opts.y = v[1]
60  if opts.z is None:
61  opts.z = v[2]
62  dmap.set_origin(opts.x, opts.y, opts.z)
63  dmap.set_was_used(True)
64  IMP.multifit.get_segmentation(dmap, opts.apix, threshold, num_cluster,
65  output, opts.cmm, opts.seg, opts.txt)
66 
67 if __name__ == "__main__":
68  main()
Fitting atomic structures into a cryo-electron microscopy density map.
Basic utilities for handling cryo-electron microscopy 3D density maps.
void get_segmentation(em::DensityMap *dmap, double apix, double density_threshold, int num_means, const std::string pdb_filename, const std::string cmm_filename, const std::string seg_filename, const std::string txt_filename)
Segment a density map using the anchor graph.