IMP  2.0.1
The Integrative Modeling Platform
cnmultifit/param.py
1 #!/usr/bin/env python
2 
3 __doc__ = "Generate a suitable parameter file for build_models."
4 
5 import IMP.multifit
6 from optparse import OptionParser
7 
8 def usage():
9  usage = """%prog [options] <cyclic symmetry degree>
10  <monomer PDB file> <density map> <resolution> <spacing>
11  <density threshold> <origin X> <origin Y> <origin Z>
12 
13 A script that builds the parameters file for symmetric MultiFit.
14 
15 Notice: If you have negative numbers as input, add -- as the first parameter,
16 so that the numbers are not treated as options."""
17 
18  parser = OptionParser(usage)
19  parser.add_option("-o", "--out", dest="out",default="multifit.output",
20  metavar="FILE",
21  help="the name of the MultiFit output file. The default "
22  "filename is multifit.output")
23  parser.add_option("-i", "--med", dest="med", metavar="FILE", default="",
24  help="Print intermediate results to the named file.")
25  parser.add_option("-p", "--params", dest="params",default="multifit.param",
26  help="the name of the MultiFit parameters file. The "
27  "default filename is multifit.params")
28  parser.add_option("-m", "--model", dest="model",default="asmb.model",
29  help="the base filename of the solutions output by "
30  "MultiFit (.X.pdb, where X is the solution number, "
31  "is suffixed to create each output file name). "
32  "The default filename is asmb.model")
33  parser.add_option("-n", "--numsols", dest="numsols",default=10, type="int",
34  help="the number of solutions(fits) to report; "
35  "default 10")
36  (options, args) = parser.parse_args()
37  if len(args) != 9:
38  parser.error("incorrect number of arguments")
39  return options, args
40 
41 def get_files_data(monomer_fn, intermediate_fn, output_fn, model_fn):
42  monomer_ms_fn=monomer_fn+".ms"
43  msg="[files]\n"
44  msg+="monomer = "+monomer_fn+"\n"
45  msg+="surface = "+monomer_ms_fn+"\n"
46  msg+="prot_lib = "+ IMP.multifit.get_data_path("chem.lib") + "\n"
47  msg += "output = "+output_fn+"\n"
48  msg += "model = "+model_fn+"\n"
49  if intermediate_fn != "":
50  msg += "intermediate = "+intermediate_fn+"\n"
51  return msg
52 
53  return msg
54 
55 def get_symmetry_data(cn_units,dn_units):
56  msg="\n[symmetry]\n"
57  msg+="; Cyclic symmetry (trimer=3, tetramer=4, etc.)\n"
58  msg+="cn = "+str(cn_units)+"\n"
59  msg+="; Dihedral symmetry\n"
60  msg+="dn = "+str(dn_units)+"\n"
61  return msg
62 
63 def get_scoring_data(liberal=True):
64  if liberal:
65  penetration = "-10.0"
66  else:
67  penetration = "-5.0"
68  msg="""
69 [scoring]
70 ; the ratio of the low scoring transforms to be removed
71 small_interface_ratio = 0.1
72 ; maximal allowed penetration between molecule surfaces
73 max_penetration = %s
74 ; normal score threshold
75 threshold = 0.5
76 ; scoring weights for ranges [-5.0,-3.6], [-3.6,-2.2], [-2.2,-1.0],
77 ; [-1.0,1.0], [1.0-up] respectively
78 weight1 = -8
79 weight2 = -4
80 weight3 = 0
81 weight4 = 1
82 weight5 = 0
83 """ % penetration
84  return msg
85 
86 def get_density_data(density_map_fn,resolution,spacing,
87  threshold,pca_matching_thr,origin):
88  msg="""
89 [density]
90 ; the density map in MRC format
91 map = %s
92 ; the resolution of the density map in A
93 resolution = %s
94 ; the voxel spacing of the density in A
95 spacing = %s
96 ; the origin of the map
97 origin_x = %s
98 origin_y = %s
99 origin_z = %s
100 ; the threshold of the density map, used for PCA matching
101 threshold = %s
102 ; corresponding principal components whose eigenvalues differ in less than
103 ; pca_matching_threshold are considered to be a match
104 pca_matching_threshold = %s
105 """ % (density_map_fn, resolution, spacing, origin[0], origin[1], origin[2],
106  threshold, pca_matching_thr)
107  return msg
108 
109 def get_clustering_data():
110  msg="""
111 [clustering]
112 ; angle in degrees
113 axis_angle_threshold = 18
114 min_size = 1
115 ; distance between centers of mass
116 distance = 2.0
117 """
118  return msg
119 
120 def get_base_data():
121  msg = """
122 [base]
123 min_distance = 5.0
124 max_distance = 50.0
125 """
126  return msg
127 
128 def get_grid_data():
129  msg = """
130 [grid]
131 step = 0.5
132 max_distance = 6.0
133 volume_radius = 6.0
134 """
135  return msg
136 
137 def get_surface_data():
138  msg="""
139 [surface]
140 ; threshold for surface pruning, i.e. no 2 points with distance below this
141 ; value are left for matching
142 threshold = 1.5
143 """
144  return msg
145 
146 def get_fitting_data(num_sols):
147  msg="""
148 [fitting]
149 ; number of solutions to fit
150 solutions = %d
151 """ % num_sols
152  return msg
153 
154 def main():
155  options,args = usage()
156  cn_units = int(args[0])
157  dn_units = 1
158 
159  liberal=False #TODO - make a parameter
160  unit_pdb_fn = args[1]
161  density_map_fn = args[2]
162  resolution=float(args[3])
163  spacing=args[4]
164  threshold=args[5]
165  origin=args[6:]
166  if resolution>15:
167  pca_matching_thr=15
168  else:
169  pca_matching_thr=resolution*0.75
170  params_fn=options.params
171  intermediate_fn=options.med
172  log_fn="multifit.log"
173  output_fn=options.out
174  model_fn=options.model
175  f=open(params_fn,"w")
176  f.write(get_files_data(unit_pdb_fn, intermediate_fn, output_fn, model_fn))
177  f.write(get_symmetry_data(cn_units,dn_units))
178  f.write(get_scoring_data(liberal))
179  f.write(get_density_data(density_map_fn,resolution,spacing,threshold,
180  pca_matching_thr,origin))
181  f.write("\n\n; ####### Advanced Parameters #######\n")
182  f.write(get_clustering_data())
183  f.write(get_base_data())
184  f.write(get_grid_data())
185  f.write(get_surface_data())
186  f.write(get_fitting_data(options.numsols))
187  f.close()
188 
189 if __name__ == "__main__":
190  main()