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