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