IMP  2.1.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 def parse_args():
10  usage = """%prog [options] <density.mrc> <number of clusters>
11  <density threshold> <output.pdb>
12 
13 Segments all voxels in the given density map, above the given threshold,
14 into the given number of clusters, and links between neighboring ones.
15 
16 The cluster centers are written out into a single output PDB file, each
17 as a single CA atom.
18 """
19  parser = OptionParser(usage)
20  parser.add_option("--apix", type="float", default=None,
21  help="map spacing, in angstroms/pix (default: read "
22  "from MRC file)")
23  parser.add_option("-x", "--x", type="float", default=None,
24  help="X origin of the density map")
25  parser.add_option("-y", "--y", type="float", default=None,
26  help="Y origin of the density map")
27  parser.add_option("-z", "--z", type="float", default=None,
28  help="Z origin of the density map")
29  parser.add_option("--cmm", type="str", default="",
30  help="write results in CMM format")
31  parser.add_option("--seg", type="str", default="",
32  help="write out each cluster as an MRC file called "
33  "<seg>_.mrc, and write load_segmentation.cmd file "
34  "to easily load all segments into Chimera")
35  parser.add_option("--txt", type="str", default="",
36  help="write anchor points file in text format")
37  options, args = parser.parse_args()
38 
39  if len(args) != 4:
40  parser.error("incorrect number of arguments")
41  return options, args
42 
43 
44 def main():
45  opts, args = parse_args()
46  asmb_fn, num_cluster, threshold, output = args
47  num_cluster = int(num_cluster)
48  threshold = float(threshold)
49  dmap = IMP.em.read_map(asmb_fn, IMP.em.MRCReaderWriter())
50  if opts.apix is None:
51  opts.apix = dmap.get_spacing()
52  else:
53  dmap.update_voxel_size(opts.apix)
54  v = dmap.get_origin()
55  if opts.x is None:
56  opts.x = v[0]
57  if opts.y is None:
58  opts.y = v[1]
59  if opts.z is None:
60  opts.z = v[2]
61  dmap.set_origin(opts.x, opts.y, opts.z)
62  dmap.set_was_used(True)
63  IMP.multifit.get_segmentation(dmap, opts.apix, threshold, num_cluster,
64  output, opts.cmm, opts.seg, opts.txt)
65 
66 if __name__=="__main__":
67  main()
See IMP.multifit for more information.
See IMP.em for more information.
Definition: CoarseCC.h:23
DensityMap * read_map(std::string filename)
IMP::kernel::OptionParser OptionParser
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.