IMP logo
IMP Reference Guide  2.21.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 ArgumentParser
9 
10 
11 def parse_args():
12  desc = """
13 Build the parameters files for MultiFit.
14 
15 Notice: If you have negative numbers as input, add -- as the first parameter,
16 so that the numbers are not treated as options."""
17 
18  p = ArgumentParser(description=desc)
19  p.add_argument("-i", "--asmb_input", dest="asmb_input",
20  default="asmb.input",
21  help="the name of the MultiFit input file. The default "
22  "filename is asmb.input")
23  p.add_argument("-m", "--model", dest="model", default="asmb.model",
24  help="the base filename of the solutions output by "
25  "MultiFit (.X.pdb, where X is the solution number, "
26  "is suffixed to create each output file name). "
27  "The default filename is asmb.model")
28  p.add_argument("-a", "--anchor_dir", dest="anchor_dir", default="./",
29  help="the name of the directory to store anchor points. "
30  "The default is ./")
31  p.add_argument("-f", "--fit_dir", dest="fit_dir", default="./",
32  help="the name of the directory to store fitting "
33  "solutions. The default is ./")
34  p.add_argument("asmb_name",
35  help="name of the assembly (used as the prefix for "
36  "several MultiFit files)")
37  p.add_argument("subunit_file",
38  help="file containing a list of subunit PDB file names")
39  p.add_argument("coarse_level", type=int,
40  help="level of coarse graining (number of residues "
41  "per anchor)")
42  p.add_argument("density", help="density map file name")
43  p.add_argument("resolution", type=float,
44  help="density map resolution, in angstroms")
45  p.add_argument("spacing", type=float,
46  help="density map voxel spacing, in angstroms")
47  p.add_argument("threshold", type=float,
48  help="the threshold of the density map, used for "
49  "PCA matching")
50  p.add_argument("origin_x", type=float,
51  help="density map origin X coordinate")
52  p.add_argument("origin_y", type=float,
53  help="density map origin Y coordinate")
54  p.add_argument("origin_z", type=float,
55  help="density map origin Z coordinate")
56  return p.parse_args()
57 
58 
59 def get_density_data(name, density_fn, resolution, spacing, threshold,
60  origin, anchor_dir_name, fit_dir_name):
62  sd.set_was_used(True)
63  msg = sd.get_density_header_line()
64  msg += (density_fn + "|" + str(resolution) + "|" + str(spacing) + "|"
65  + str(threshold) + "|" + str(origin[0]) + "|" + str(origin[1])
66  + "|" + str(origin[2]))
67  msg += "|" + anchor_dir_name + name + "_em_coarse_anchors.txt|" + \
68  anchor_dir_name + name + "_em_coarse_anchors_FINE.txt|"
69  msg += anchor_dir_name + name + "_em_fine_anchors.txt|" + \
70  anchor_dir_name + name + "_em_fine_anchors_FINE.txt|\n"
71  return msg
72 
73 
74 def get_protein_data(
75  pdb_list,
76  coarse_level,
77  anchor_dir_name,
78  fit_dir_name,
79  fit_fn_header,
80  add_reference_fn):
82  sd.set_was_used(True)
83  msg = sd.get_component_header_line()
84  mdl = IMP.Model()
85  with open(pdb_list) as fh:
86  for i, fnn in enumerate(fh):
87  name = fnn[:-1].split()[0]
88  fn = fnn[:-1].split()[1]
89  surface_fn = fnn[:-1].split()[1] + ".ms"
90  # TODO - add the number of copies data
91  mh = IMP.atom.read_pdb(fn, mdl)
92  num_anchors = len(IMP.atom.get_by_type(
93  mh, IMP.atom.RESIDUE_TYPE)) // coarse_level
94  msg += name + "|" + fn + "|" + surface_fn + "|" + \
95  anchor_dir_name + name + "_anchors.txt|" + \
96  str(num_anchors) + "|"
97  msg += anchor_dir_name + name + "_fine_anchors.txt|" + \
98  str(len(IMP.atom.get_by_type(mh, IMP.atom.RESIDUE_TYPE)))
99  msg += "|" + fit_dir_name + name + fit_fn_header + "|"
100  if add_reference_fn:
101  msg = msg + fn + "|\n"
102  else:
103  msg = msg + "|\n"
104  return msg
105 
106 
107 def create_alignment_param_file(asmb_name, coarse_level):
108  # TODO - make load_atomic and rigid parameters
109  shutil.copy(IMP.multifit.get_data_path("atomic.alignment.param"),
110  asmb_name + ".alignment.param")
111  shutil.copy(IMP.multifit.get_data_path("atomic.alignment.param.refined"),
112  asmb_name + ".alignment.param.refined")
113 
114 
115 def create_assembly_input_file(
116  pdb_list, coarse_level, anchor_dir, fit_dir, asmb_name,
117  density_map_fn, resolution, spacing, threshold,
118  origin,
119  asmb_input_fn,
120  fit_fn_header="_fitting.txt",
121  add_reference_fn=False):
122 
123  msg = ""
124  msg = msg + get_protein_data(
125  pdb_list,
126  coarse_level,
127  anchor_dir,
128  fit_dir,
129  fit_fn_header,
130  add_reference_fn)
131  msg = msg + get_density_data(
132  asmb_name, density_map_fn, resolution, spacing,
133  threshold, origin, anchor_dir, fit_dir)
134  f = open(asmb_input_fn, "w")
135  f.write(msg)
136  f.close()
137  # refinement assembly input
138  msg = ""
139  msg = msg + get_protein_data(
140  pdb_list,
141  coarse_level,
142  anchor_dir,
143  fit_dir,
144  fit_fn_header + ".refined",
145  add_reference_fn)
146  msg = msg + get_density_data(
147  asmb_name, density_map_fn, resolution, spacing,
148  threshold, origin, anchor_dir, fit_dir)
149  f = open(asmb_input_fn + ".refined", "w")
150  f.write(msg)
151  f.close()
152 
153 
154 def main():
155  args = parse_args()
156  asmb_name = args.asmb_name
157  pdb_list = args.subunit_file
158  coarse_level = args.coarse_level
159  anchor_dir = args.anchor_dir
160  fit_dir = args.fit_dir
161  if not anchor_dir[-1] == "/":
162  anchor_dir += "/"
163  if not fit_dir[-1] == "/":
164  fit_dir += "/"
165 
166  density_map_fn = args.density
167  resolution = args.resolution
168  spacing = args.spacing
169  threshold = args.threshold
170  origin = [args.origin_x, args.origin_y, args.origin_z]
171  create_assembly_input_file(
172  pdb_list, coarse_level, anchor_dir, fit_dir, asmb_name,
173  density_map_fn, resolution, spacing, threshold,
174  origin, args.asmb_input)
175 
176  create_alignment_param_file(asmb_name, coarse_level)
177 
178 
179 if __name__ == "__main__":
180  main()
void read_pdb(TextInput input, int model, Hierarchy h)
Class for storing model, its restraints, constraints, and particles.
Definition: Model.h:86
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.