IMP logo
IMP Reference Guide  2.6.0
The Integrative Modeling Platform
multifit/param.py
1 #!/usr/bin/env python
2 from __future__ import division
3 
4 __doc__ = 'Build initial parameters files.'
5 
6 import shutil
7 import IMP.multifit
8 from IMP import OptionParser
9 
10 
11 def parse_args():
12  usage = """%prog [options] <assembly name> <subunits file>
13  <coarse level> <density map> <resolution> <spacing> <density threshold>
14  <origin X> <origin Y> <origin Z>
15 
16 Build the parameters files for MultiFit.
17 
18 Notice: If you have negative numbers as input, add -- as the first parameter,
19 so that the numbers are not treated as options."""
20 
21  parser = OptionParser(usage)
22  parser.add_option("-i", "--asmb_input", dest="asmb_input",
23  default="asmb.input",
24  help="the name of the MultiFit input file. The default "
25  "filename is asmb.input")
26  parser.add_option("-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  parser.add_option("-a", "--anchor_dir", dest="anchor_dir", default="./",
32  help="the name of the directory to store anchor points. "
33  "The default is ./")
34  parser.add_option("-f", "--fit_dir", dest="fit_dir", default="./",
35  help="the name of the directory to store fitting "
36  "solutions. The default is ./")
37  (options, args) = parser.parse_args()
38  if len(args) < 10:
39  parser.error("incorrect number of arguments")
40  return options, args
41 
42 
43 def get_density_data(name, density_fn, resolution, spacing, threshold,
44  origin, anchor_dir_name, fit_dir_name):
46  sd.set_was_used(True)
47  msg = sd.get_density_header_line()
48  msg += density_fn + "|" + str(resolution) + "|" + str(spacing) + "|" + str(
49  threshold) + "|" + str(origin[0]) + "|" + str(origin[1]) + "|" + str(origin[2])
50  msg += "|" + anchor_dir_name + name + "_em_coarse_anchors.txt|" + \
51  anchor_dir_name + name + "_em_coarse_anchors_FINE.txt|"
52  msg += anchor_dir_name + name + "_em_fine_anchors.txt|" + \
53  anchor_dir_name + name + "_em_fine_anchors_FINE.txt|\n"
54  return msg
55 
56 
57 def get_protein_data(
58  pdb_list,
59  coarse_level,
60  anchor_dir_name,
61  fit_dir_name,
62  fit_fn_header,
63  add_reference_fn):
65  sd.set_was_used(True)
66  msg = sd.get_component_header_line()
67  mdl = IMP.Model()
68  with open(pdb_list) as fh:
69  for i, fnn in enumerate(fh):
70  name = fnn[:-1].split()[0]
71  fn = fnn[:-1].split()[1]
72  surface_fn = fnn[:-1].split()[1] + ".ms"
73  # TODO - add the number of copies data
74  mh = IMP.atom.read_pdb(fn, mdl)
75  num_anchors = len(IMP.atom.get_by_type(mh,
76  IMP.atom.RESIDUE_TYPE)) // coarse_level
77  msg += name + "|" + fn + "|" + surface_fn + "|" + \
78  anchor_dir_name + name + "_anchors.txt|" + \
79  str(num_anchors) + "|"
80  msg += anchor_dir_name + name + "_fine_anchors.txt|" + \
81  str(len(IMP.atom.get_by_type(mh, IMP.atom.RESIDUE_TYPE)))
82  msg += "|" + fit_dir_name + name + fit_fn_header + "|"
83  if add_reference_fn:
84  msg = msg + fn + "|\n"
85  else:
86  msg = msg + "|\n"
87  return msg
88 
89 
90 def create_alignment_param_file(asmb_name, coarse_level):
91  # TODO - make load_atomic and rigid parameters
92  shutil.copy(IMP.multifit.get_data_path("atomic.alignment.param"),
93  asmb_name + ".alignment.param")
94  shutil.copy(IMP.multifit.get_data_path("atomic.alignment.param.refined"),
95  asmb_name + ".alignment.param.refined")
96 
97 
98 def create_assembly_input_file(
99  pdb_list, coarse_level, anchor_dir, fit_dir, asmb_name,
100  density_map_fn, resolution, spacing, threshold,
101  origin,
102  asmb_input_fn,
103  fit_fn_header="_fitting.txt",
104  add_reference_fn=False):
105 
106  msg = ""
107  msg = msg + get_protein_data(
108  pdb_list,
109  coarse_level,
110  anchor_dir,
111  fit_dir,
112  fit_fn_header,
113  add_reference_fn)
114  msg = msg + get_density_data(
115  asmb_name, density_map_fn, resolution, spacing,
116  threshold, origin, anchor_dir, fit_dir)
117  f = open(asmb_input_fn, "w")
118  f.write(msg)
119  f.close()
120  # refinement assembly input
121  msg = ""
122  msg = msg + get_protein_data(
123  pdb_list,
124  coarse_level,
125  anchor_dir,
126  fit_dir,
127  fit_fn_header + ".refined",
128  add_reference_fn)
129  msg = msg + get_density_data(
130  asmb_name, density_map_fn, resolution, spacing,
131  threshold, origin, anchor_dir, fit_dir)
132  f = open(asmb_input_fn + ".refined", "w")
133  f.write(msg)
134  f.close()
135 
136 
137 def main():
138  options, args = parse_args()
139  asmb_name = args[0]
140  pdb_list = args[1]
141  coarse_level = int(args[2])
142  anchor_dir = options.anchor_dir
143  fit_dir = options.fit_dir
144  if not anchor_dir[-1] == "/":
145  anchor_dir += "/"
146  if not fit_dir[-1] == "/":
147  fit_dir += "/"
148 
149  density_map_fn = args[3]
150  resolution = float(args[4])
151  spacing = args[5]
152  threshold = args[6]
153  origin = [float(args[7]), float(args[8]), float(args[9])]
154  create_assembly_input_file(
155  pdb_list, coarse_level, anchor_dir, fit_dir, asmb_name,
156  density_map_fn, resolution, spacing, threshold,
157  origin, options.asmb_input)
158 
159  create_alignment_param_file(asmb_name, coarse_level)
160 
161 
162 if __name__ == "__main__":
163  main()
void read_pdb(TextInput input, int model, Hierarchy h)
Class for storing model, its restraints, constraints, and particles.
Definition: Model.h:72
Fitting atomic structures into a cryo-electron microscopy density map.
Holds header data for optimization.
Definition: SettingsData.h:135
std::string get_data_path(std::string file_name)
Return the full path to one of this module's data files.