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