Package Biskit :: Package Dock :: Module ComplexEvolvingList
[hide private]
[frames] | no frames]

Source Code for Module Biskit.Dock.ComplexEvolvingList

  1  ## Automatically adapted for numpy.oldnumeric Mar 26, 2007 by alter_code1.py 
  2   
  3  ## 
  4  ## Biskit, a toolkit for the manipulation of macromolecular structures 
  5  ## Copyright (C) 2004-2006 Raik Gruenberg & Johan Leckner 
  6  ## 
  7  ## This program is free software; you can redistribute it and/or 
  8  ## modify it under the terms of the GNU General Public License as 
  9  ## published by the Free Software Foundation; either version 2 of the 
 10  ## License, or any later version. 
 11  ## 
 12  ## This program is distributed in the hope that it will be useful, 
 13  ## but WITHOUT ANY WARRANTY; without even the implied warranty of 
 14  ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 
 15  ## General Public License for more details. 
 16  ## 
 17  ## You find a copy of the GNU General Public License in the file 
 18  ## license.txt along with this program; if not, write to the Free 
 19  ## Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 
 20  ## 
 21  ## 
 22  ## last $Author: graik $ 
 23  ## last $Date: 2007/03/26 18:40:42 $ 
 24  ## $Revision: 2.10 $ 
 25   
 26  """ 
 27  List of ComplexEvolving instances. 
 28  """ 
 29   
 30  from Biskit.Dock.ComplexList import ComplexList, ComplexListError 
 31  from Biskit.Dock.ComplexEvolving import ComplexEvolving 
 32  import numpy.oldnumeric as N 
 33   
34 -class ComplexEvolvingList( ComplexList ):
35 """ 36 List of ComplexEvolving instances. 37 Used for organising, sorting, and filtering Complexes during refinement. 38 39 @todo: implement plotting functions for evolving Complexes 40 @todo: right now normal Complexes are tolerated 41 @todo: adapt model management 42 @see: L{Dock.ComplexEvolving} 43 """ 44
45 - def __init__(self, lst=[] ):
46 """ 47 @param lst: list of Complexes 48 @type lst: [ComplexEvolving] 49 50 @raise ComplexListError: if list contains non-Complex item. 51 """ 52 ComplexList.__init__( self, lst )
53 54
55 - def version( self ):
56 """ 57 Version of Dock.Complex 58 59 @return: version of class 60 @rtype: str 61 """ 62 return 'ComplexEvolvingList $Revision: 2.10 $'
63 64
65 - def checkType( self, v ):
66 """ 67 Make sure v is a ComplexEvolving 68 69 @param v: any 70 @type v: any 71 72 @raise ComplexListError: if list contains non-Complex item. 73 """ 74 if not isinstance(v, ComplexEvolving): 75 raise ComplexListError( 76 str( v ) + " not allowed. ComplexList requires "+ 77 str(ComplexEvolving))
78 79
80 - def allVersionList( self ):
81 """ 82 Get all versions of each Complex as a seperate Complex instance. 83 84 @return: ComplexList of normal Complex instances 85 @rtype: ComplexList 86 """ 87 r = ComplexList() 88 89 for c in self: 90 try: 91 r += c.toList() 92 except: 93 r += [ c ] 94 95 return r
96 97
98 - def toComplexList( self, version=-1 ):
99 """ 100 Get a ComplexList that contains only a single version of each Complex. 101 102 @param version: version in history, -1 == last [-1] (default: -1) 103 @type version: int 104 105 @return: ComplexList 106 @rtype: ComplexList 107 """ 108 return ComplexList( [ c[ version ] for c in self ] )
109 110
111 - def toList( self, version=None ):
112 """ 113 Get a simple python list of Complexes. If version==None, the list 114 contains ComplexEvolving instances with all versions, otherwise 115 the list contains Complex instances representing a single version. 116 117 @param version: version in history, -1 == last, None == all 118 (default: None) 119 @type version: int 120 121 @return: python list of Complexes 122 @rtype: [ Complex ] 123 """ 124 if version is None: 125 return ComplexList.toList( self ) 126 127 return [ c[ version ] for c in self ]
128 129
130 - def valuesOf( self, infoKey, version=None, default=None, 131 indices=None, unique=0 ):
132 """ 133 Get all values of a certain info record of all or some Complexes. 134 135 @param infoKey: key for info dict 136 @type infoKey: str 137 @param version: index in history or None (=current) (default: None) 138 @type version: int 139 @param default: default value if infoKey is not found (default: None) 140 @type default: any 141 @param indices: list of int OR None(=all), indices of Complexes 142 (default: None) 143 @type indices: [int] OR None 144 @param unique: report each value only once (set union), (default: 0) 145 @type unique: 1|0 146 147 @return: list of values 148 @rtype: [any] 149 """ 150 l = self 151 if indices != None: 152 l = N.take( l, indices ) 153 154 if not unique: 155 if version is None: 156 return [ c.get(infoKey, default) for c in l ] 157 return [ c[version].get( infoKey, default) for c in l ] 158 159 r = [] 160 for c in l: 161 if version is not None: 162 c = c[ version ] 163 164 if c.info.get(infoKey, default) not in r: 165 r += [ c.info.get( infoKey ) ] 166 167 return r
168 169 170 ############# 171 ## TESTING 172 ############# 173 import Biskit.test as BT 174
175 -class Test(BT.BiskitTest):
176 """Test case""" 177
178 - def test_ComplexEvolvingList(self):
179 """Dock.ComplexEvolvingList test""" 180 181 import Biskit.tools as t 182 from Biskit.Dock import ComplexEvolving 183 from Biskit.Dock import ComplexEvolvingList 184 185 ## original complex 186 cl = t.Load( t.testRoot() + "/dock/hex/complexes.cl" ) 187 188 ## first evolution step 189 c = ComplexEvolving( cl[0].rec(), cl[0].lig(), cl[0], 190 info={'comment':'test1'}) 191 192 ## second evolution step 193 c = ComplexEvolving( c.rec(), c.lig(), c, 194 info={'comment':'test2'}) 195 196 ## create an evolving complex list 197 cl = ComplexEvolvingList( [c, c] ) 198 199 if self.local: 200 ## last version of all complexes in list 201 print cl.valuesOf('comment') 202 203 ## version 1 204 print cl.valuesOf('comment', version=1) 205 206 ## the first complex in the list 207 print cl[0].valuesOf('comment') 208 209 globals().update( locals() ) 210 211 self.assertEqual( (cl.valuesOf('comment'), cl[0].valuesOf('comment')), 212 (['test2', 'test2'], [None, 'test1', 'test2']) )
213 214 if __name__ == '__main__': 215 216 BT.localTest() 217