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