def __init__(self, lst=[] ): """ @param lst: list of Complexes @type lst: [ComplexVC] @raise ComplexListError: if list contains non-Complex item. """ ComplexList.__init__( self, lst )
def __init__(self, lst=[]): """ @param lst: list of Complexes @type lst: [ComplexVC] @raise ComplexListError: if list contains non-Complex item. """ ComplexList.__init__(self, lst)
def toComplexList(self, version=-1): """ Get a ComplexList that contains only a single version of each Complex. @param version: version in history, -1 == last [-1] (default: -1) @type version: int @return: ComplexList @rtype: ComplexList """ return ComplexList([c[version] for c in self])
def __init__(self, rec_model, lig_model, com_0=None, ligMatrix=None, info={}): """ Create a new ComplexVC from a previous Complex or ComplexVC and a new set of receptor, ligand conformation and transformation. @param rec_model: PDBModel/XplorModel, receptor conformation @type rec_model: PDBModel @param lig_model: PDBModel/XplorModel, ligand conformation @type lig_model: PDBModel @param com_0: Complex /ComplexVC, previous version(s) of this com @type com_0: Complex OR ComplexVC @param ligMatrix: transformation matrix of ligand versus receptor @type ligMatrix: 4x4 array @param info: info dictionary {'info_key': value, ..}, additional infos @type info: dict """ ProtComplex.__init__(self, rec_model, lig_model, ligMatrix, info) if isinstance(com_0, ComplexVC): ## get history from mother complex ... self.history = com_0.history com_0 = ProtComplex(com_0.rec_model, com_0.lig_model, com_0.ligandMatrix, com_0.info) else: ## ... or create a new history self.history = ComplexList() if com_0 is not None: self.history.append(com_0) ## save only differences between old and new conformations self.rec_model = self.__syncModel(self.rec_model, com_0.rec_model) self.lig_model = self.__syncModel(self.lig_model, com_0.lig_model)
def allVersionList(self): """ Get all versions of each Complex as a seperate Complex instance. @return: ComplexList of normal Complex instances @rtype: ComplexList """ r = ComplexList() for c in self: try: r += c.toList() except: r += [c] return r
def toList(self, version=None): """ Get a simple python list of Complexes. If version==None, the list contains ComplexVC instances with all versions, otherwise the list contains Complex instances representing a single version. @param version: version in history, -1 == last, None == all (default: None) @type version: int @return: python list of Complexes @rtype: [ Complex ] """ if version is None: return ComplexList.toList(self) return [c[version] for c in self]
def toList( self, version=None ): """ Get a simple python list of Complexes. If version==None, the list contains ComplexVC instances with all versions, otherwise the list contains Complex instances representing a single version. @param version: version in history, -1 == last, None == all (default: None) @type version: int @return: python list of Complexes @rtype: [ Complex ] """ if version is None: return ComplexList.toList( self ) return [ c[ version ] for c in self ]
def __init__(self, rec_model, lig_model, com_0=None, ligMatrix=None, info={} ): """ Create a new ComplexVC from a previous Complex or ComplexVC and a new set of receptor, ligand conformation and transformation. @param rec_model: PDBModel/XplorModel, receptor conformation @type rec_model: PDBModel @param lig_model: PDBModel/XplorModel, ligand conformation @type lig_model: PDBModel @param com_0: Complex /ComplexVC, previous version(s) of this com @type com_0: Complex OR ComplexVC @param ligMatrix: transformation matrix of ligand versus receptor @type ligMatrix: 4x4 array @param info: info dictionary {'info_key': value, ..}, additional infos @type info: dict """ ProtComplex.__init__(self, rec_model, lig_model, ligMatrix, info ) if isinstance( com_0, ComplexVC ): ## get history from mother complex ... self.history = com_0.history com_0 = ProtComplex( com_0.rec_model, com_0.lig_model, com_0.ligandMatrix, com_0.info ) else: ## ... or create a new history self.history = ComplexList() if com_0 is not None: self.history.append( com_0 ) ## save only differences between old and new conformations self.rec_model = self.__syncModel( self.rec_model, com_0.rec_model) self.lig_model = self.__syncModel( self.lig_model, com_0.lig_model)
def __init__(self, recDic, ligDic, recPdb=None, ligPdb=None, comPdb=None, out='hex_%s', soln=512, recChainId=None, ligChainId=None, macDock=None, bin='hex', verbose=1): ## use ExeConfig instead of bin=... """ @param recDic: receptor dictionary @type recDic: dict @param ligDic: ligand dictionary @type ligDic: dict @param recPdb: hex-formatted PDB with rec models @type recPdb: str @param ligPdb: hex-formatted PDB with lig models @type ligPdb: str @param comPdb: hex-formatted PDB with com models @type comPdb: str @param soln: number of solutions to keep from HEX (default 512) @type soln: int @param recChainId: force chain IDs only for HEX @type recChainId: [str] @param ligChainId: force chain IDs only for HEX @type ligChainId: [str] @param out: out folder name, will be formatted against date @type out: str @param macDock: force macro docking ON or OFF (default: size decides) @type macDock: 1|0 @param bin: path to HEX binary @type bin: str @param verbose: verbosity level (default: 1) @type verbose: 1|0 """ self.lock = RLock() self.lockMsg = Condition(self.lock) t.ensure(macDock, int, [None]) t.ensure( recDic, dict, ) t.ensure( ligDic, dict, ) self.verbose = verbose self.recDic = recDic self.ligDic = ligDic ## force chain IDs self.recChainId = recChainId self.ligChainId = ligChainId ## create folder if necessary self.out = self.prepareOutFolder(out) self.comPdb = None if comPdb: self.comPdb = t.absfile(comPdb) ## remember which HEX PDB was created for which model self.recHexPdbs = {} self.ligHexPdbs = {} ## remember which macrofile uses which models and which out file self.runDic = {} if recPdb: ## HEX PDB provided externally for k in self.recDic: self.recHexPdbs[k] = t.absfile(recPdb) else: ## HEX PDB has to be created self.recHexPdbs = self.prepareHexPdbs(self.recDic, self.recChainId, 'rec') if ligPdb: for k in self.ligDic: self.ligHexPdbs[k] = t.absfile(recPdb) else: self.ligHexPdbs = self.prepareHexPdbs(self.ligDic, self.ligChainId, 'lig') self.bin = bin self.call_when_done = None self.call_when_failed = None ## remember whether macro dock was used self.macroDock = macDock self.running = [] self.hexDone = 0 self.hexFailed = 0 self.result = ComplexList() self.soln = soln
class ComplexVC( ProtComplex ): """ Complex that keeps track of its previous versions. The object behaves like a normal L{Biskit.Dock.Complex} but encapsulates a L{Biskit.Dock.ComplexList} with older versions/conformations of this Complex. - com[0] gives the very first version, com[1] the second, etc. - com[-1] gives the current version (but as normal Complex, not ComplexVC). - e.g. com[0, 'fnac'] gives the according info value of the first version - e.g. com['fnac'] gives the current info value (as for Dock.Complex) """ def __init__(self, rec_model, lig_model, com_0=None, ligMatrix=None, info={} ): """ Create a new ComplexVC from a previous Complex or ComplexVC and a new set of receptor, ligand conformation and transformation. @param rec_model: PDBModel/XplorModel, receptor conformation @type rec_model: PDBModel @param lig_model: PDBModel/XplorModel, ligand conformation @type lig_model: PDBModel @param com_0: Complex /ComplexVC, previous version(s) of this com @type com_0: Complex OR ComplexVC @param ligMatrix: transformation matrix of ligand versus receptor @type ligMatrix: 4x4 array @param info: info dictionary {'info_key': value, ..}, additional infos @type info: dict """ ProtComplex.__init__(self, rec_model, lig_model, ligMatrix, info ) if isinstance( com_0, ComplexVC ): ## get history from mother complex ... self.history = com_0.history com_0 = ProtComplex( com_0.rec_model, com_0.lig_model, com_0.ligandMatrix, com_0.info ) else: ## ... or create a new history self.history = ComplexList() if com_0 is not None: self.history.append( com_0 ) ## save only differences between old and new conformations self.rec_model = self.__syncModel( self.rec_model, com_0.rec_model) self.lig_model = self.__syncModel( self.lig_model, com_0.lig_model) def __iter__(self): """ __iter__() <==> for k in self """ return iter( self.history + [self] ) def __len__( self ): """ length of self """ return len( self.history ) + 1 def getComplex( self, i, copy=0 ): """ Return one version as Complex. -1 returns a copy of the latest version. By default the info dictionary remains connected but other fields don't. I.e. replacing rec_model in the copy does not affect the original complex. @param i: index in complex history, -1 returns toComplex() @type i: int @param copy: copy info dictionary in case of i==-1 (changes in c.getComplex( -1 ).info will not appear in c.info [0] @type copy: 1|0 @return: complex @rtype: Dock.Complex """ if i == -1: return self.toComplex( copy=copy ) if i >= 0 and i < len( self.history ): return self.history[ i ] return self.toSimpleList()[i] def __getitem__( self, k ): """ Get a Complex OR a info key value for a Complex specified Complex OR info dic value. @param k: tuple OR int OR str @type k: any OR Complex """ if type(k) == tuple: i, key = k[0], k[1] if i == len( self.history ): return self.info[key] return self.getComplex(i).info[key] if isinstance(k, (int, N.integer)): return self.getComplex( k ) return self.info[k] def __syncModel( self, new_model, old_model ): """ Connect new rec or lig model to old one, to minimize storage. @param new_model: PDBModel / XplorModel @type new_model: PDBModel @param old_model: PDBModel / XplorModel @type old_model: PDBModel @return: PDBModel / XplorModel, new model that only keeps changes relative to old, the old model becomes the source of the new, if possible @rtype: PDBModel """ ## try to fix atom order of new_model so that it is identical to old if old_model.equals( new_model ) != [1,1]: i_new, i_old = new_model.compareAtoms( old_model ) if len( i_new ) == len( new_model ): new_model.keep( i_new ) ## create result model that only keeps difference of new and old if old_model.equals( new_model ) == [1,1]: ## stays compatible with XplorModel.__init__ and PDBModel.__init r = old_model.__class__( source=old_model ) r.setXyz( new_model.getXyz() ) ## check for profiles identical to source and adapt 'changed' r.update() if not MU.arrayEqual( r.xyz, old_model.xyz ): r.removeProfile( 'relASA', 'ASA_sc', 'ASA_total', 'ASA_bb' ) return r EHandler.warning( 'ComplexVC: Cannot connect new to old PDBModel.') new_model.disconnect() return new_model def sortHistory( self ): """ Sort by date """ self.history = self.history.sortBy( 'date' ) def toList( self ): """ @return: all historic complexes plus current one as Complex @rtype: ComplexList """ return self.history + [ self.toComplex() ] def toSimpleList( self ): """ @return: all historic complexes plus current one as Complex @rtype: [Complex] """ return self.history.toList() + [ self.toComplex() ] def toComplex( self, copy=0 ): """ Copy of latest version as a normal Complex. @param copy: also disconnect info dict (default: 0) @type copy: 1|0 @return: Complex @rtype: Complex """ r = ProtComplex( self.rec_model, self.lig_model, self.ligandMatrix, self.info ) if not copy: r.info = self.info return r def valuesOf( self, infoKey, default=None ): """ Get info values from all versions of this complex (oldest first). @param infoKey: info dic key @type infoKey: str @param default: default value, if key is not present @type default: any @return: list of values @rtype: [any] """ return [ c.get( infoKey, default ) for c in self ]
class ComplexVC(ProtComplex): """ Complex that keeps track of its previous versions. The object behaves like a normal L{Biskit.Dock.Complex} but encapsulates a L{Biskit.Dock.ComplexList} with older versions/conformations of this Complex. - com[0] gives the very first version, com[1] the second, etc. - com[-1] gives the current version (but as normal Complex, not ComplexVC). - e.g. com[0, 'fnac'] gives the according info value of the first version - e.g. com['fnac'] gives the current info value (as for Dock.Complex) """ def __init__(self, rec_model, lig_model, com_0=None, ligMatrix=None, info={}): """ Create a new ComplexVC from a previous Complex or ComplexVC and a new set of receptor, ligand conformation and transformation. @param rec_model: PDBModel/XplorModel, receptor conformation @type rec_model: PDBModel @param lig_model: PDBModel/XplorModel, ligand conformation @type lig_model: PDBModel @param com_0: Complex /ComplexVC, previous version(s) of this com @type com_0: Complex OR ComplexVC @param ligMatrix: transformation matrix of ligand versus receptor @type ligMatrix: 4x4 array @param info: info dictionary {'info_key': value, ..}, additional infos @type info: dict """ ProtComplex.__init__(self, rec_model, lig_model, ligMatrix, info) if isinstance(com_0, ComplexVC): ## get history from mother complex ... self.history = com_0.history com_0 = ProtComplex(com_0.rec_model, com_0.lig_model, com_0.ligandMatrix, com_0.info) else: ## ... or create a new history self.history = ComplexList() if com_0 is not None: self.history.append(com_0) ## save only differences between old and new conformations self.rec_model = self.__syncModel(self.rec_model, com_0.rec_model) self.lig_model = self.__syncModel(self.lig_model, com_0.lig_model) def __iter__(self): """ __iter__() <==> for k in self """ return iter(self.history + [self]) def __len__(self): """ length of self """ return len(self.history) + 1 def getComplex(self, i, copy=0): """ Return one version as Complex. -1 returns a copy of the latest version. By default the info dictionary remains connected but other fields don't. I.e. replacing rec_model in the copy does not affect the original complex. @param i: index in complex history, -1 returns toComplex() @type i: int @param copy: copy info dictionary in case of i==-1 (changes in c.getComplex( -1 ).info will not appear in c.info [0] @type copy: 1|0 @return: complex @rtype: Dock.Complex """ if i == -1: return self.toComplex(copy=copy) if i >= 0 and i < len(self.history): return self.history[i] return self.toSimpleList()[i] def __getitem__(self, k): """ Get a Complex OR a info key value for a Complex specified Complex OR info dic value. @param k: tuple OR int OR str @type k: any OR Complex """ if type(k) == tuple: i, key = k[0], k[1] if i == len(self.history): return self.info[key] return self.getComplex(i).info[key] if isinstance(k, (int, N.integer)): return self.getComplex(k) return self.info[k] def __syncModel(self, new_model, old_model): """ Connect new rec or lig model to old one, to minimize storage. @param new_model: PDBModel / XplorModel @type new_model: PDBModel @param old_model: PDBModel / XplorModel @type old_model: PDBModel @return: PDBModel / XplorModel, new model that only keeps changes relative to old, the old model becomes the source of the new, if possible @rtype: PDBModel """ ## try to fix atom order of new_model so that it is identical to old if old_model.equals(new_model) != [1, 1]: i_new, i_old = new_model.compareAtoms(old_model) if len(i_new) == len(new_model): new_model.keep(i_new) ## create result model that only keeps difference of new and old if old_model.equals(new_model) == [1, 1]: ## stays compatible with XplorModel.__init__ and PDBModel.__init r = old_model.__class__(source=old_model) r.setXyz(new_model.getXyz()) ## check for profiles identical to source and adapt 'changed' r.update() if not MU.arrayEqual(r.xyz, old_model.xyz): r.removeProfile('relASA', 'ASA_sc', 'ASA_total', 'ASA_bb') return r EHandler.warning('ComplexVC: Cannot connect new to old PDBModel.') new_model.disconnect() return new_model def sortHistory(self): """ Sort by date """ self.history = self.history.sortBy('date') def toList(self): """ @return: all historic complexes plus current one as Complex @rtype: ComplexList """ return self.history + [self.toComplex()] def toSimpleList(self): """ @return: all historic complexes plus current one as Complex @rtype: [Complex] """ return self.history.toList() + [self.toComplex()] def toComplex(self, copy=0): """ Copy of latest version as a normal Complex. @param copy: also disconnect info dict (default: 0) @type copy: 1|0 @return: Complex @rtype: Complex """ r = ProtComplex(self.rec_model, self.lig_model, self.ligandMatrix, self.info) if not copy: r.info = self.info return r def valuesOf(self, infoKey, default=None): """ Get info values from all versions of this complex (oldest first). @param infoKey: info dic key @type infoKey: str @param default: default value, if key is not present @type default: any @return: list of values @rtype: [any] """ return [c.get(infoKey, default) for c in self]