Rosetta
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
general_tools.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/general_tools.py
10 ## @brief general 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 math
19 import re
20 from sys import platform
21 from shutil import rmtree
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 from app.pyrosetta_toolkit.modules.Region import Region
32 from app.pyrosetta_toolkit.modules.Region import Regions
33 
34 pwd = os.getcwd()
35 
36 
37 def renameandsave(inFolder, outFolder, outName, contains):
38  """
39  Renames all files in a particular directory recursively from 1 - N. Useful due to some apps not being JD2 compatible!
40  """
41 
42  filenum = 1
43  if contains=="all":
44  contains = ""
45  #print outFolder
46  AllFiles = []
47  for root, dirs, files in os.walk(inFolder, topdown=True):
48  #print "Root" + root
49  for f in files:
50  if re.search(contains, f):
51  print "File_"+repr(filenum)+"_"+f
52  p = os.path.join(root, f)
53  AllFiles.append(p)
54 
55 
56 
57  for f in AllFiles:
58  os.system("cp "+f+" "+outFolder)
59  print f
60  fSP = os.path.split(f)
61  fileSP = fSP[1].split(".")
62  newName = outName+"_"+repr(filenum)+"."+fileSP[1]
63  print newName
64  newPath = os.path.join(outFolder, newName)
65  oldPath = os.path.join(outFolder, fSP[1])
66  os.system("mv "+oldPath+" "+newPath)
67  filenum+=1
68  print "Files Copied.."
69  return
70 
71 
72 def getDist(p, res1, res2, atom1, atom2):
73  """
74  Gets distance between atom one and two of two residues.
75  """
76  xyz1 = p.residue(res1).xyz(atom1)
77  xyz2 = p.residue(res2).xyz(atom2)
78  return getDistGen(xyz1, xyz2)
79 
80 def getDistGen( xyz1, xyz2):
81  """
82  Gets distance bt two coord vectors(list)
83  """
84 
85  #xyz1 is a list with (x, y, z)
86  d = math.sqrt(pow(xyz1[0]-xyz2[0], 2)+pow(xyz1[1]-xyz2[1], 2)+pow(xyz1[2]-xyz2[2], 2))
87  return d
88 
89 def getOS():
90  """
91  Get OS of the particular platform the toolkit is being run on.
92  """
93 
94  plat = sys.platform
95  if re.search("darwin", plat):
96  return "Mac"
97  elif re.search("linux", plat):
98  return "Linux"
99  elif re.search("win", plat):
100  return "Windows"
101  else:
102  print "Platform Not Found"
103  return "error"
104 
105 def loop_string_to_region(loop_string):
106  """
107  Loop string (start:end:chain) conversion to newer Region class.
108  """
109 
110  start = loop_string.split(":")[0]; end = loop_string.split(":")[1]; chain = loop_string.split(":")[2]
111  #Chain
112 
113  if (start == "" and end==""):
114  region = Region(chain.upper(), None, None)
115  #Nter
116  elif start=="":
117  region = Region(chain.upper(), None, int(end))
118  #Cter
119  elif end=="":
120  region = Region(chain.upper(), int(start), None)
121  #Loop
122  else:
123  region = Region(chain.upper(), int(start), int(end))
124 
125  return region
126 
127 def loops_as_strings_to_regions(loops_as_strings):
128  """
129  Loops as strings representation of regions to newer Regions class.
130  """
131  reg = Regions()
132  for loop_string in loops_as_strings:
133  reg.add_region(loop_string_to_region(loop_string))
134 
135  return reg
136 
xyzVector< Real > xyz(Real const &r1, Real const &omega1, Real const &t, Real const &dz1, Real const &delta_omega1, Real const &delta_z1)
Returns the x-, y-, and z-coordinates of a point on a helix given r1, omega1, and t...
Definition: HelixParams.cc:67
utility::vector1< std::string > split(const std::string &s)
split given std::string using ' ' symbol.
Definition: string_util.cc:59
DimensionExpressionPow pow(Dimension const &dim1, Dimension const &dim2)
pow( Dimension, Dimension )