IMP logo
IMP Reference Guide  2.5.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  return msg
58 
59 
60 def get_symmetry_data(cn_units, dn_units):
61  msg = "\n[symmetry]\n"
62  msg += "; Cyclic symmetry (trimer=3, tetramer=4, etc.)\n"
63  msg += "cn = " + str(cn_units) + "\n"
64  msg += "; Dihedral symmetry\n"
65  msg += "dn = " + str(dn_units) + "\n"
66  return msg
67 
68 
69 def get_scoring_data(liberal=True):
70  if liberal:
71  penetration = "-10.0"
72  else:
73  penetration = "-5.0"
74  msg = """
75 [scoring]
76 ; the ratio of the low scoring transforms to be removed
77 small_interface_ratio = 0.1
78 ; maximal allowed penetration between molecule surfaces
79 max_penetration = %s
80 ; normal score threshold
81 threshold = 0.5
82 ; scoring weights for ranges [-5.0,-3.6], [-3.6,-2.2], [-2.2,-1.0],
83 ; [-1.0,1.0], [1.0-up] respectively
84 weight1 = -8
85 weight2 = -4
86 weight3 = 0
87 weight4 = 1
88 weight5 = 0
89 """ % penetration
90  return msg
91 
92 
93 def get_density_data(density_map_fn, resolution, spacing,
94  threshold, pca_matching_thr, origin):
95  msg = """
96 [density]
97 ; the density map in MRC format
98 map = %s
99 ; the resolution of the density map in A
100 resolution = %s
101 ; the voxel spacing of the density in A
102 spacing = %s
103 ; the origin of the map
104 origin_x = %s
105 origin_y = %s
106 origin_z = %s
107 ; the threshold of the density map, used for PCA matching
108 threshold = %s
109 ; corresponding principal components whose eigenvalues differ in less than
110 ; pca_matching_threshold are considered to be a match
111 pca_matching_threshold = %s
112 """ % (density_map_fn, resolution, spacing, origin[0], origin[1], origin[2],
113  threshold, pca_matching_thr)
114  return msg
115 
116 
117 def get_clustering_data():
118  msg = """
119 [clustering]
120 ; angle in degrees
121 axis_angle_threshold = 18
122 min_size = 1
123 ; distance between centers of mass
124 distance = 2.0
125 """
126  return msg
127 
128 
129 def get_base_data():
130  msg = """
131 [base]
132 min_distance = 5.0
133 max_distance = 50.0
134 """
135  return msg
136 
137 
138 def get_grid_data():
139  msg = """
140 [grid]
141 step = 0.5
142 max_distance = 6.0
143 volume_radius = 6.0
144 """
145  return msg
146 
147 
148 def get_surface_data():
149  msg = """
150 [surface]
151 ; threshold for surface pruning, i.e. no 2 points with distance below this
152 ; value are left for matching
153 threshold = 1.5
154 """
155  return msg
156 
157 
158 def get_fitting_data(num_sols):
159  msg = """
160 [fitting]
161 ; number of solutions to fit
162 solutions = %d
163 """ % num_sols
164  return msg
165 
166 
167 def main():
168  options, args = usage()
169  cn_units = int(args[0])
170  dn_units = 1
171 
172  liberal = False # TODO - make a parameter
173  unit_pdb_fn = args[1]
174  density_map_fn = args[2]
175  resolution = float(args[3])
176  spacing = args[4]
177  threshold = args[5]
178  origin = args[6:]
179  if resolution > 15:
180  pca_matching_thr = 15
181  else:
182  pca_matching_thr = resolution * 0.75
183  params_fn = options.params
184  intermediate_fn = options.med
185  log_fn = "multifit.log"
186  output_fn = options.out
187  model_fn = options.model
188  f = open(params_fn, "w")
189  f.write(get_files_data(unit_pdb_fn, intermediate_fn, output_fn, model_fn))
190  f.write(get_symmetry_data(cn_units, dn_units))
191  f.write(get_scoring_data(liberal))
192  f.write(get_density_data(density_map_fn, resolution, spacing, threshold,
193  pca_matching_thr, origin))
194  f.write("\n\n; ####### Advanced Parameters #######\n")
195  f.write(get_clustering_data())
196  f.write(get_base_data())
197  f.write(get_grid_data())
198  f.write(get_surface_data())
199  f.write(get_fitting_data(options.numsols))
200  f.close()
201 
202 if __name__ == "__main__":
203  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.