Rosetta
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
input.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/input.py
10 ## @brief general input 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 
20 #Tkinter Imports
21 import tkFileDialog
22 import tkMessageBox
23 import tkSimpleDialog
24 from Tkinter import Listbox
25 
26 #Toolkit Imports
27 import interfaces
28 from app.pyrosetta_toolkit.window_main import global_variables
29 
31  """
32  Loads a Folder through the tk File Dialog. Uses and Sets current directory.
33  """
34 
35  dir_name = tkFileDialog.askdirectory(initialdir=global_variables.current_directory, title='Pick a directory')
36 
37  if not dir_name:
38  return None
39  print dir_name
40  global_variables.current_directory = dir_name
41  return dir_name
42 
44  """
45  Loads a File through the tk File Dialog. Uses and Sets current directory.
46  """
47  filename = tkFileDialog.askopenfilename(initialdir=global_variables.current_directory, title='Pick a file')
48  if not filename:
49  return
50  filename = self.fixFilename(filename)
51  global_variables.current_directory = os.path.dirname(filename)
52  print filename
53  return filename
54 
55 def fixFilename(file):
56  """
57  Rosetta cannot use spaces in the filename...
58  """
59 
60  x=file.split()
61  if len(x) > 1:
62  newFile = x[0]
63  for i in range (1, len(x)):
64  newFile = newFile + "\ " + x[i]
65  return newFile
66  else:
67  return file
68 
69 
71  """
72  Returns a list of PDB files within a directory.
73  check_button_ck if it returns the full path..
74  """
75 
76  directorylist =os.listdir(dir)
77  directorylist = list(directorylist) #May already be a list, but I forget.
78  for Files in directorylist:
79  if re.search(".pdb", Files):
80  pass
81  else:
82  directorylist.remove(Files)
83  return directorylist
84 
85 def add_constraints_to_pose_and_scorefunction(pose, score, default_weight = 1.0, constraint_types = False, constraint_file=False):
86  """
87  Adds constraint from file to pose and score. Sets all constraint_types to 1.0.
88  Can pass an array of constraint_types.
89  """
90  if pose.total_residue()==0:
91  print "Please load a pose."
92  return ""
93  if not constraint_types:
94  constraint_types = [atom_pair_constraint, angle_constraint, dihedral_constraint, coordinate_constraint, constant_constraint]
95 
96  if not constraint_file:
97  constraint_file = tkFileDialog.askopenfilename(initialdir=global_variables.current_directory, title = "Open Constraint File")
98  if not constraint_file:return
99  global_variables.current_directory = os.path.dirname(constraint_file)
100  print "Setting constraints to pose and scorefunction at default weight of 1.0 if not already set. "
101  setup = ConstraintSetMover()
102  setup.constraint_file(constraint_file)
103  setup.apply(pose)
104 
105  for constraint in constraint_types:
106  if score.get_weight(constraint)==0:
107  score.set_weight(constraint, default_weight)
108  return constraint_file
109 
110 def get_residuetypeset_from_path_array(param_path_array, loaded_path_array):
111  """
112  Returns ResidueTypeSet from an array of paths.
113  """
114 
115  #So that there are no duplicates.
116  params = dict()
117  for p in param_path_array:
118  #Only add to unique dictionary if path is not in loaded_path_array
119  try:
120  ind = loaded_path_array.index(p)
121  except ValueError:
122  params[p]=0
123  loaded_path_array.append(p)
124  if not params: return
125  params_paths = utility.vector1_string()
126  params_paths.extend(list(params.keys()))
127  residuetypeset = generate_nonstandard_residue_set(params_paths)
128  print "Nonstandard residue type set loaded."
129  return residuetypeset, loaded_path_array
Fstring::size_type len(Fstring const &s)
Length.
Definition: Fstring.hh:2207