Rosetta
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
output.py
Go to the documentation of this file.
1 #!/usr/bin/python
2 
3 # (c) Copyright Rosetta Commons Member Institutions.
4 # (c) This file is part of the Rosetta software suite and is made available under license.
5 # (c) The Rosetta software is developed by the contributing members of the Rosetta Commons.
6 # (c) For more information, see http://www.rosettacommons.org. Questions about this can be
7 # (c) addressed to University of Washington UW TechTransfer, email: license@u.washington.edu.
8 
9 ## @file /GUIs/pyrosetta_toolkit/modules/tools/output.py
10 ## @brief general output functions for the toolkit
11 ## @author Jared Adolf-Bryfogle (jadolfbr@gmail.com)
12 
13 #Rosetta Imports
14 from rosetta import *
15 
16 #Python Imports
17 import os
18 import re
19 import tarfile
20 import multiprocessing
21 from multiprocessing import Process
22 import time
23 
24 #Tkinter Imports
25 import tkFileDialog
26 import tkMessageBox
27 import tkSimpleDialog
28 from Tkinter import Listbox
29 
30 #Toolkit Imports
31 import sequence
32 import loops
34 from app.pyrosetta_toolkit.modules.tools import loops as loop_tools
35 from app.pyrosetta_toolkit.window_main import global_variables
36 from app.pyrosetta_toolkit.modules.definitions import restype_definitions
37 from collections import defaultdict
38 
39 def dumpPDB(p, native_pose, filepath, score, overwrite=False):
40  """
41  Dumps the pose using the Py Job Distributor
42  """
43  if not overwrite:
44  jd=PyJobDistributor(filepath, 100000, score); #This number is high so that it outputs a pose even if one with the name already exists...
45  #native_pose = Pose()
46  #pose_from_pdb(native_pose, infile)
47  jd.native_pose=native_pose
48  jd.output_decoy(p)
49  os.remove(jd.current_name+".in_progress")
50  else:
51  print "Removing .fasc + .pdb with same output name."
52 
53  if os.path.exists(filepath+".fasc"):
54  os.remove(filepath+".fasc")
55  if os.path.exists(filepath+"_1.pdb"):
56  os.remove(filepath+"_1.pdb")
57  native_pose.dump_pdb(filepath+"_1.pdb")
58  output_scorefile(p, filepath, filepath+"_1.pdb", filepath+".fasc", score, 1, native_pose)
59 
60  print "Pose written to "+os.path.dirname(filepath)
61 
62 def showPose(p, observer):
63 
64  if not p.total_residue():
65  print "\n No pose loaded...\n"
66  return
67  #self.obs.add_observer(p)
68  score = create_score_function_ws_patch('standard', 'score12')
69  print score(p)
70  observer.apply(p)
71  #self.obs.send_energy(p)
72  #self.obs.remove_observer(p)
73  #obs.pymol.apply(p)
74  return p
75 
76 def save_loop_file(p, regions, ask_info=True, outfilename=False):
77  """
78  Saves a Rosetta Loop file. Also asks to discard residues or not.
79  Migrate to use Regions.
80  """
81  if not p.total_residue():
82  print "\n No pose loaded...\n"
83  return
84 
85  if not regions:
86  print "\n No loops to save...\n"
87  return
88 
89 
90  if ask_info:
91 
92  ask_cut_points = tkMessageBox.askyesno(message="Define Cutpoints?", default=tkMessageBox.NO)
93 
94  discard_loops = tkMessageBox.askyesno(message = "Discard Phi/Psi and build using ideal bond lengths and angles?")
95  else:
96  ask_cut_points = False
97  discard_loops = True
98  if not outfilename:
99  outfilename = tkFileDialog.asksaveasfilename(initialdir = global_variables.current_directory, title="Output loop file to...")
100  if not outfilename: return
101  global_variables.current_directory=os.path.dirname(outfilename)
102 
103  FILE = open(outfilename, 'w')
104  for region in regions:
105 
106  start = region.get_rosetta_start(p)
107  end = region.get_rosetta_end(p)
108  #This asks the user for each loop what he/she would like to do in terms of cutpoints. Default= somewhere near the middle.
109  if ask_cut_points:
110  cutpoint_known = False
111 
112  while not cutpoint_known:
113  cut = tkSimpleDialog.askstring(title="cutpoint", prompt="Cutpoint for Loop (#, default, 0 for random) " +loop_string, initialvalue="default")
114  if cut== "default":
115  cut = (end - start)/2
116  cut = start+cut
117  cutpoint_known=True
118  elif cut =="0":
119  cut=0
120  cutpoint_known=True
121  else:
122  if ((int(cut) < start) | (int(cut) > end)):
123  tkMessageBox.showerror(message="Invalid CutPoint!")
124  cut = int(cut)
125  cutpoint_known=False
126  else:
127  cut = (end - start)/2
128  cut = start+cut
129  FILE.write("LOOP"+" "+repr(start)+" "+repr(end)+" "+repr(cut)+" 0 "+repr(int(discard_loops))+"\n")
130 
131  FILE.close()
132  print "\nLoop File written...\n"
133  return
134 
136  if isinstance(obj, basestring):
137  return obj.strip()
138  elif isinstance(obj, list):
139  return [clean_whitespace(o) for o in obj]
140  elif isinstance(obj, tuple):
141  return tuple(clean_whitespace(o) for o in obj)
142  elif isinstance(obj, dict):
143  return dict((k, clean_whitespace(v)) for (k,v) in obj.items())
144  else:
145  return obj
146 
147 def save_basic_resfile(p, outname=None):
148  """
149  Saves an empty resfile, numbered by PDB with NATRO designation
150  If outname is not given, will ask where to save.
151  """
152  if not p.total_residue():
153  print "\n No pose loaded...\n"
154  return
155 
156  ResDic = dict()
157  if not outname:
158  outname = tkFileDialog.asksaveasfilename(initialdir = global_variables.current_directory, title="Output resfile to...")
159  if not outname: return
160  global_variables.current_directory=os.path.dirname(outname)
161 
162  save_resfile_w_designdic(p, ResDic, outname)
163 
164 def save_resfile_w_designdic(p, ResDic, filename):
165  """
166  Saves a resifile, readable by PyRosetta and Rosetta.
167  ResDic can be empty.
168  ResDic is [string pdbNum:pdbChain]:[array name:three_letter:one_letter string]
169  If NC - ResDic should be [string pdbNum:pdbChain]:[array 'NC':residue string]
170  """
171  if not p.total_residue():
172  print "\n No pose loaded...\n"
173  return
174 
175  tot = p.total_residue()
176  FILE = open(filename, 'w')
177  FILE.write(" start\n")
178  for i in range(1, tot+1):
179  chain = p.pdb_info().chain(i)
180  chainStr = chain.rjust(3)
181  pdbNum = p.pdb_info().number(i)
182  pdbStr = str(pdbNum).rjust(4)
183  res = repr(pdbNum) + ":" +chain
184  #res - string pdbNum:chain
185  if res in ResDic:
186  x = ""
187  print res
188  for residue_string in ResDic[res]:
189  print residue_string
190  if residue_string == "NATRO":
191  line = pdbStr + chainStr + " NATRO"+"\n"
192  elif residue_string == "NATAA":
193  line = pdbStr + chainStr + " NATAA"+ "\n"
194  elif residue_string == "ALLAA":
195  line = pdbStr + chainStr + " ALLAA" + "\n"
196  elif residue_string.split(":")[0]=="NC":
197  type = residue_string.split(":")[1]+" "
198  x = x+" NC "+type
199  #Looks like for each NC you need NC designation.
200  line = pdbStr + chainStr + x + "\n";
201  else:
202  residuesAll = residue_string.split(":")
203  x = x + residuesAll[2]
204  line = pdbStr + chainStr + " PIKAA " + x + "\n"; #Just gets rewritten if more residues to add
205  FILE.write(line)
206  else:
207  #If residue not found in Resdic, give NATRO
208  line = pdbStr + chainStr + " NATRO" + "\n"
209  FILE.write(line)
210  FILE.close()
211  print "\nRes File written....\n"
212 
213 def createSeqFile(p, newList):
214  """
215  Used in conversion to output scwrl sequence file.
216  """
217  if not p.total_residue():
218  print "\n No pose loaded...\n"
219  return
220 
221  seq = p.sequence()
222  seq = seq.lower()
223 
224  #This is to seperate the string so that we can change the elements of each part.
225  seqList = []
226  for x in seq:
227  seqList.append(x)
228 
229  for list in newList:
230  for res in list:
231  seqList[res-1]=seqList[res-1].upper()
232 
233  seq = ""
234  for res in seqList:
235  seq = seq+res
236 
237  print seq
238  return seq
239 
240 
241 def saveSeqFile(p, fileout=None, loops_as_strings=None):
242  """
243  Saves a scwrl seq file. Needs to be more robust to account for all Seths changes ( some NCAA, carbohydrates) when it is eventually released.
244  Needs to migrate to use region class.
245  """
246  if not p.total_residue():
247  print "\n No pose loaded...\n"
248  return
249  if not fileout:
250  fileout = tkFileDialog.asksaveasfilename(initialdir=global_variables.current_directory)
251  if not fileout:return
252  global_variables.current_directory = os.path.dirname(fileout)
253  newList = loop_tools.loopArea(p, loops_as_strings)
254  seq = createSeqFile(p, newList)
255  FILE = open(fileout, 'w')
256  FILE.write(seq+"\n")
257  FILE.close()
258  print "Seq file saved.."
259  return
260 
261 
262 def save_basic_blueprint(p, output=True, outfilename=None):
263  """
264  Saves a basic blueprint file to be manually edited.
265  If output is false, returns a string of the file for manipulation.
266  If outfilename is not given, will ask where to save.
267  """
268  if not p.total_residue():
269  print "\n No pose loaded...\n"
270  return
271 
272  out_string = ""
273  define = restype_definitions.definitions()
274  seq = p.sequence()
275  for i in range(1, p.total_residue()+1):
276  pdb_num = p.pdb_info().number(i)
277  single_letter_code = seq[i-1]
278  out_string = out_string+repr(pdb_num)+" "+single_letter_code+" . NATRO\n"
279 
280  if output:
281  if not outfilename:
282  outfilename = tkFileDialog.asksaveasfilename(initialdir = global_variables.current_directory)
283  if not outfilename:return
284  global_variables.current_directory=os.path.dirname(outfilename)
285 
286  FILE = open(outfilename, 'w')
287  FILE.write(out_string)
288  FILE.close()
289  print "\nBlueprint Saved...\n"
290  else:
291  return out_string
292 
293 ############PDBLIST TOOLS##########################
294 def make_PDBLIST(directory=""):
295  """
296  Makes a list of PDB's from a directory. Does not walk directory.
297  Later realize could have used find command...
298  """
299  if directory=="":
300  directory = tkFileDialog.askdirectory(title = "Choose directory with PDB files", initialdir = global_variables.current_directory)
301  if not directory: return
302  global_variables.current_directory=directory
303 
304  contains = tkSimpleDialog.askstring(title="Contains...", prompt="Separate mutliple match criteria by a coma...", initialvalue=".pdb")
305  containsSP = contains.split(",")
306  FILES = os.listdir(directory)
307 
308  filenum=1
309  if len(FILES)<=1:
310  print "No PDBs found. Returning."
311  return
312 
313  matches = []
314  for name in FILES:
315  match = True; #Assumes true. If
316  for pattern in containsSP:
317  pattern = pattern.strip()
318  if re.search(pattern, name) and (re.search("\._", name)== None) and (re.search("~", name)== None):#This shows how stupid python/linux can be...:
319  continue
320  else:
321  match=False
322  continue
323 
324  if match:
325  print "File "+repr(filenum)+": "+name
326  p = os.path.join(directory, name)
327  filenum+=1
328  matches.append(p)
329 
330  if matches:
331  NEWFILE = open(directory+"/PDBLIST.txt", 'w')
332  for match in matches:
333  NEWFILE.write(match+"\n")
334  NEWFILE.close()
335  print "File saved as 'PDBLIST.txt' in directory specified."
336  return directory+"/PDBLIST.txt"
337  else:
338  print "No matches found.."
339  return None
340 
341 def make_PDBLIST_recursively(directory=""):
342  if directory=="":
343  directory = tkFileDialog.askdirectory(initialdir = global_variables.current_directory)
344  if not directory: return
345  global_variables.current_directory=directory
346 
347  contains = tkSimpleDialog.askstring(title="Contains...", prompt="Separate mutliple match criteria by a coma...", initialvalue=".pdb,")
348  NEWFILE = open(directory+"/PDBLIST_RECURSIVE.txt", 'w')
349  filenum = 1
350  containsSP = contains.split(",")
351  matches = []
352  for root, dirs, files in os.walk(directory, topdown=True):
353  #print "Root" + root
354  for f in files:
355  match = True; #Assumes true. If
356  for pattern in containsSP:
357  pattern = pattern.strip()
358  if re.search(pattern, f) and (re.search("\._", f)== None) and (re.search("~", f)== None):#This shows how stupid python/linux can be...:
359  continue
360  else:
361  match=False
362  continue
363 
364  if match:
365  print "File "+repr(filenum)+":"+f
366  p = os.path.join(root, f)
367  matches.append(p)
368  filenum+=1
369 
370  if matches:
371  NEWFILE = open(directory+"/PDBLIST.txt", 'w')
372  for match in matches:
373  NEWFILE.write(match+"\n")
374  NEWFILE.close()
375  print "File saved as 'PDBLIST.txt' in directory specified."
376  return directory+"/PDBLIST.txt"
377  else:
378  print "No matches found.."
379  return None
380 
382  """
383  Adds each PDB info excluding header information into an SQLITE3 Database. The module for this is modules/PDB.py.
384  Needs to be basename as querying with '/' in a string doesn't seem to work.
385  """
386 
387  if not pdblist_path:
388  print "Please choose PDBList..."
389  return
390  structID = tkSimpleDialog.askstring(title="structID", prompt="These entries will have a structID of...", initialvalue="na")
391  PDBLIST = open(pdblist_path, 'r')
392  dbname = os.path.dirname(pdblist_path)+"/DATABASE.db"
393  print dbname
394  DB = SQLPDB("", "", "", False, dbname)
395  i = 1
396  for filepath in PDBLIST:
397  pdbID = os.path.basename(filepath).split(".")[0]
398  pdbID = filepath
399  DB.set_basic_options(pdbID, i, structID)
400  filepath = filepath.strip()
401  DB.read_pdb_into_database_flat(filepath, False, False)
402  i+=1
403  DB.db.close()
404  print "Database written to PDBLIST directory"
405 
407  dbfilename = tkFileDialog.askopenfilename(initialdir = global_variables.current_directory, title = "Database filename")
408  if not dbfilename: return
409  global_variables.current_directory = os.path.dirname(dbfilename)
410 
411  pdbID = tkSimpleDialog.askstring(title = "pdbID", prompt="Please enter the pdbID/filepath you wish to extract")
412  if not pdbID: return
413 
414  pdbdb = PDB_database(dbfilename)
415  print "Database Opened"
416  table = pdbdb.scrub("pdb")
417  pdbdb.query_pdbID(table, pdbID)
418  outname = tkFileDialog.asksaveasfilename(initialdir = global_variables.current_directory)
419  if not outname: return
420  global_variables.current_directory = os.path.dirname(outname)
421 
422  pdbdb.set_output_DIR(os.path.dirname(outname))
423  pdbdb.save_cur_as_pdb(os.path.basename(outname))
424 
425 def extract_pdbs_from_sqlite3db(pdblist_path):
426  dbfilename = tkFileDialog.askopenfilename(initialdir = global_variables.current_directory, title = "Database filename")
427  if not dbfilename: return
428  global_variables.current_directory = os.path.dirname(dbfilename)
429  pdbdb = PDB_database(dbfilename)
430  print "Database Opened"
431  outdir = tkFileDialog.askdirectory(initialdir = global_variables.current_directory, title= "Choose output directory")
432  global_variables.current_directory = outdir
433 
434  keep_original_filename = tkMessageBox.askyesno(title="Keep Original Filename?", message="Add numerical designation to filename to keep from overwriting same PDBs in list?", default=tkMessageBox.NO)
435  strucID = tkSimpleDialog.askstring(title="strucID", prompt="Extract entries with structID of...", initialvalue="na")
436  PDBLIST = open(pdblist_path, 'r')
437  pdbdb.set_output_DIR(outdir)
438  filenum = 1
439  table = pdbdb.scrub("pdb")
440  for pdbID in PDBLIST:
441  pdbdb.query_pdbID_and_strucID(table, os.path.basename(pdbID), strucID)
442  newname = os.path.basename(pdbID)
443  if not keep_original_filename: newname = newname+"_"+repr(filenum)
444  print "Saving "+ newname
445  pdbdb.save_cur_as_pdb(newname)
446  pdbdb._reset_cursor()
447  filenum+=1
448 
449  print "Finished..."
450  PDBLIST.close()
451 
452 def rescore_single_pdb(path, scorefunction, manager_dict):
453  """
454  Used by score_PDBList for multiprocessing rescoring of decoy structures.
455  Only speed up if PDBs are large.
456  """
457  p = Pose()
458  try:
459  pose_from_pdb(p, path)
460 
461  except PyRosettaException:
462  print "Cannot Load "+path+ " Try using -ignore_unrecognized_residues in options window..."
463  return
464 
465  #Extra measure of protection to make sure we get to the end of the function.
466  if p.total_residue()>0:
467  print "Loaded PDB"
468  score = scorefunction(p)
469  manager_dict[path]=score
470  else:
471  return
472 
473 def score_PDBLIST(pdblist_path, score, processors, output_class = None):
474  """
475  Outputs a simple pdb vs score for simple analysis.
476  if pdblist_path=False, a dialog box opens.
477  will grab the number of processors from output_class (processor StringVar variable) and attempt multiprocessing rescoring of all PDBs.
478  """
479 
480  if not pdblist_path:
481  pdblist_path = tkFileDialog.askopenfilename(initialdir = global_variables.current_directory, title = "PDBLIST")
482  if not pdblist_path: return
483  global_variables.current_directory = os.path.dirname(pdblist_path)
484  PDBLIST = open(pdblist_path, 'r')
485  else:
486  PDBLIST = open(pdblist_path, 'r')
487  SCORED_PDBLIST = open(os.path.dirname(pdblist_path)+"/SCORED_PDBLIST.txt", 'w')
488 
489  if processors==1:
490  for path in PDBLIST:
491  path = path.strip()
492  print path
493  p = Pose()
494  try:
495  pose_from_pdb(p, path)
496  except PyRosettaException:
497  print "Cannot Load "+path+ " Try using -ignore_unrecognized_residues in options window..."
498  continue
499  e = score(p)
500  SCORED_PDBLIST.write(path+"\t%.3f\n"%e)
501  print "\nComplete. File written to SCORED_PDBLIST.txt\n"
502  PDBLIST.close()
503  SCORED_PDBLIST.close()
504 
505  #Multiprocessing - Slower for extremely small PDBs, great for large ones.
506  else:
507  if output_class:
508  output_class.terminal_output.set(1)
509  manager = multiprocessing.Manager()
510  result_map = manager.dict(); #[path]:[score]
511  workers = []
512  i=1
513  for line in PDBLIST:
514  line = line.strip()
515  if not os.path.exists(line):
516  print "Could not find "+line
517  print "Skipping"
518  continue
519  result_map[line]="NA"
520  worker = Process(name = line, target=rescore_single_pdb, args=(line, score, result_map))
521  workers.append(worker)
522  i+=1
523  total_allowed_jobs = processors
524  print "Total allowed jobs: "+repr(total_allowed_jobs)
525  total_running_jobs = 0
526  job_complete=False
527 
528  #Run the protocol
529  while not job_complete:
530 
531 
532  time.sleep(1)
533  for worker in workers:
534  if worker.is_alive():
535  pass
536  #There is no code for worker hasn't started yet that I can figure out. So, something else needs to check it!
537  elif result_map[worker.name]!="NA":
538  if worker.exitcode!=0:
539  print "%s.exitcode = %s" %(worker.name, worker.exitcode)
540 
541  workers.pop(workers.index(worker)); #If the job is done, pop it.
542  total_running_jobs-=1
543  print "Total running jobs: "+repr(total_running_jobs)
544  print "Total workers waiting: "+repr(len(workers)-total_running_jobs)
545 
546  if len(workers)==0:
547  job_complete=True
548  break
549 
550  if total_running_jobs<total_allowed_jobs:
551  for worker in workers:
552  if not worker.is_alive():
553  print "Starting Worker"
554  try:
555  worker.start()
556  except AssertionError:
557  continue
558  print "Total running jobs: "+repr(total_running_jobs)
559  print "Total workers waiting: "+repr(len(workers)-total_running_jobs)
560  total_running_jobs+=1
561  if total_running_jobs>=total_allowed_jobs: break
562 
563  if total_running_jobs==0:
564  job_complete=True
565 
566  d = defaultdict()
567 
568  #Convert Multiprocessing dictionary to regular one so it can be sorted
569  for path in result_map.keys():
570  d[path] = result_map[path]
571 
572  for path in sorted(d, key=d.get):
573  e = d[path]
574  print path+"\t%.3f\n"%e
575  SCORED_PDBLIST.write(path+"\t%.3f\n"%e)
576 
577  print "\nComplete. File written to "+os.path.dirname(pdblist_path)+"/SCORED_PDBLIST.txt\n"
578  if output_class:
579  output_class.terminal_output.set(0)
580  SCORED_PDBLIST.close()
581 
582  return os.path.dirname(pdblist_path)+"/SCORED_PDBLIST.txt"
583 
584 #### FASTA OUTPUT ####
585 
586 def save_FASTA(pose, base_name, outfilename = None, regions = None ):
587  """
588  If outfilename is False, will ask for a directory using current_directory.
589  If loops_as_strings is given, output FASTA of loops. Base_name is used as label >base_name (region) for fasta
590  Uses Pyrosetta...
591  """
592  if not pose.total_residue():
593  print "\n No pose loaded...\n"
594  return
595 
596  if not outfilename:
597  outfilename = tkFileDialog.asksaveasfilename(initialdir = global_variables.current_directory, title="Output FASTA to...")
598  if not outfilename: return
599  global_variables.current_directory = os.path.dirname(outfilename)
600  OUTFILE = open(outfilename, 'w')
601  if regions:
602  region_array = regions.get_regions()
603  for region in region_array:
604  if not region.region_exists(pose):continue
605  else:
606  seq = region.get_sequence(pose)
607  header = ">"+base_name+" "+region.get_region_string_with_all_residues(pose)
608  OUTFILE.write(header+"\n")
609  OUTFILE.write(seq+"\n")
610  else:
611  seq = pose.sequence()
612  OUTFILE.write(">"+base_name+"\n")
613  OUTFILE.write(seq+"\n")
614  OUTFILE.close()
615  print "FASTA written."
616  return
617 
618 def save_FASTA_PDBLIST(pdblist_path, outfilename=None, regions=None):
619  """
620  If outfilename is False, will ask for a filename
621  Goes through each member of PDBLIST
622  Uses pyrosetta to get sequence.
623  """
624  if not outfilename:
625  outfilename = tkFileDialog.asksaveasfilename(initialdir = global_variables.current_directory, title="Output FASTA to...")
626  if not outfilename:return
627  global_variables.current_directory = os.path.dirname(outfilename)
628 
629  OUTFILE = open(outfilename, 'w')
630  PDBLIST = open(pdblist_path, 'r')
631  i = 1
632  for pdbpath in PDBLIST:
633  pdbpath = pdbpath.strip()
634  if not pdbpath: continue
635 
636  pdb = os.path.basename(pdbpath)
637  pdbID = pdb.split(".")[0]
638  print pdbID
639  pose = Pose()
640  region_array = regions.get_regions()
641  try:
642  pose_from_pdb(pose, pdbpath)
643  except PyRosettaException:
644  print "Could not load.. "+pdbID+"..continueing.."
645  continue
646  if regions:
647  for region in region_array:
648  #if not region.region_exists(pose):continue
649  seq = region.get_sequence(pose)
650 
651 
652  header = ">"+repr(i)+"_"+os.path.basename(pdbpath)+" "+region.get_region_string_with_all_residues(pose)
653  print header
654  print seq
655  OUTFILE.write(header+"\n")
656  OUTFILE.write(seq+"\n\n")
657  else:
658  seq=pose.sequence()
659  OUTFILE.write(">"+pdbID+" "+pdbpath+"\n")
660  OUTFILE.write(seq+"\n")
661  i+1
662 
663  PDBLIST.close()
664  OUTFILE.close()
665  print "Fasta written..."
666  return
667 
668 
669 def exportPDBSCORE(score):
670  """
671  Exports a list of scores.
672  """
673 
674  PDBLIST = tkFileDialog.askopenfile(title = "PDBLIST", initialdir = global_variables.current_directory)
675  OUTFILE = tkFileDialog.asksaveasfile(title = "Save As...", initialdir = global_variables.current_directory)
676 
677  if PDBLIST == None or OUTFILE==None:
678  return
679 
680  for PDBPath in PDBLIST:
681  PDBPath = PDBPath.strip()
682 
683  p = Pose()
684  pose_from_pdb(p, PDBPath)
685  SCORE = score(p)
686  print SCORE
687  OUTFILE.write(PDBPath+":%.3f"%SCORE+"\n")
688  print "\nComplete\n"
689  PDBLIST.close()
690  OUTFILE.close()
691 
693  """
694  Uses molfile to params in pyrosetta bindings to convert.
695  Maybe should be converted to a window for more options.
696  """
697 
698  print "Using molfile_to_params.py script located in pyrosetta/toolbox/molfile2params written by Ian W Davis. For more options, please use script."
699  script_path = os.environ["PYROSETTA"]+"/toolbox/molfile2params/molfile_to_params.py"
700 
701  if not os.path.exists(script_path):
702  print "Untarring script"
703  extract_path = os.environ["PYROSETTA"]+"/toolbox"
704  tar_path = extract_path+"/molfile2params.tar.gz"
705 
706  if tarfile.is_tarfile(tar_path):
707  tfile = tarfile.open(tar_path)
708  tfile.extractall(extract_path)
709  else:
710  print "Could not extract tar file."
711  return
712 
713  mdl_file = tkFileDialog.askopenfilename(initialdir = global_variables.current_directory, title = "Open MDL, MOL, MOL2, or SDF file")
714  if not mdl_file:return
715  global_variables.current_directory=os.path.dirname(mdl_file)
716 
717  output_kinemage = tkMessageBox.askyesno(title = "kinemage", message="Output kinemage file for ligand visualization?")
718 
719  options = " "+mdl_file+" "
720  if output_kinemage:
721  options = options+"-k "
722 
723  outdir = os.path.dirname(mdl_file)+"/"+os.path.basename(mdl_file).split(".")[0]
724  if not os.path.exists(outdir): os.mkdir(outdir)
725 
726  prefix = outdir+"/"+os.path.basename(mdl_file).split(".")[0]
727 
728  options = options +"-c --clobber "+"-p "+prefix
729 
730  print "Running molfile_to_params with these options: "+options
731  os.system("python "+script_path+options)
732  print "Parameters generated. Output directed to: "+outdir
733 
734  return
735 
736 def save_param_path_list(array_of_paths, outfilename=False):
737  """
738  Saves a file of paths.
739  """
740  if not array_of_paths:
741  print "No extra params enabled."
742  return
743  if not outfilename:
744  outfilename = tkFileDialog.asksaveasfilename(initialdir = global_variables.current_directory, title="Output Parm pathList to...")
745  if not outfilename:return
746  global_variables.current_directory = os.path.dirname(outfilename)
747  FILE = open(outfilename, 'w')
748  d = dict()
749  #Uniqify the output
750  for path in array_of_paths:d[path]=0
751 
752  for path in d:
753  FILE.write(path+"\n")
754  FILE.close()
def save_FASTA
FASTA OUTPUT ####.
Definition: output.py:586
def make_PDBLIST
PDBLIST TOOLS##########################.
Definition: output.py:294
Fstring::size_type len(Fstring const &s)
Length.
Definition: Fstring.hh:2207
utility::vector1< std::string > split(const std::string &s)
split given std::string using ' ' symbol.
Definition: string_util.cc:59
def output_scorefile
Definition: __init__.py:617
bool open(utility::io::izstream &db_stream, std::string const &db_file, bool warn)
Open a database file on a provided stream.
Definition: open.cc:55
Fstring rjust(Fstring const &s)
Right-Justified Copy.
Definition: Fstring.hh:2413