IMP  2.0.1
The Integrative Modeling Platform
map2pca.py
1 #!/usr/bin/env python
2 
3 import IMP.em
4 
5 def main():
6  IMP.base.set_log_level(IMP.base.SILENT)
7  usage = """%prog [options] <in_density> <density threshold> <out_pca.cmm>
8 
9 Calculates the map principal components and writes them in cmm format.
10 The 3D points participating in the PCA calculation are the centers of voxels
11 with density above the input threshold."""
12  parser = IMP.OptionParser(usage=usage, imp_module=IMP.em)
13  parser.add_option("-p", "--apix", dest="apix",
14  help="voxel size")
15  (options, args) = parser.parse_args()
16  if len(args) != 3:
17  parser.error("incorrect number of arguments")
18  in_map_fn=args[0]
19  threshold = float(args[1])
20  out_pca_fn=args[2]
21  dmap=IMP.em.read_map(in_map_fn)
22  if options.apix:
23  dmap.update_voxel_size(float(options.apix))
24  dens_vecs = IMP.em.density2vectors(dmap,threshold)
25  dens_pca = IMP.algebra.get_principal_components(dens_vecs)
26  f=open(out_pca_fn,"w")
27  IMP.em.write_pca_cmm(dens_pca, f)
28  f.close()
29 
30 if __name__ == "__main__":
31  main()