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