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