def go(self, dict): """ Calculate rmsd values for trajectory and plot them. @param dict: dictionary with path to pdb files as keys @type dict: dict @return: dictionary mapping input:output names @rtype: dict """ d = {} print "working on :", for pdbIn, out in dict.items(): print T.stripFilename( pdbIn ) ## set file name for pickled Structure object dir = os.path.dirname( pdbIn ) if self.params['out'] <> None: dir = self.params['out'] out = dir + '/' + T.stripFilename( pdbIn) + '.model' try: m = PDBModel( pdbIn, skipRes=self.params['skipRes'] ) if self.params['amber']: self.renameAmberRes( m ) self.renameToAmberAtoms( m ) if self.params['sort']: m = m.sort() m.saveAs( out ) except: if self.params.has_key('report') and self.params['report']: f = open( out[:-6] + '.error', 'w' ) f.write( T.lastError() ) f.close() else: T.errWriteln("Error" + T.lastError() ) out = '' d[pdbIn] = out print "Done." return d
def go(self, dict): """ Calculate rmsd values for trajectory and plot them. @param dict: dictionary with path to pdb files as keys @type dict: dict @return: dictionary mapping input:output names @rtype: dict """ d = {} print "working on :", for pdbIn, out in dict.items(): print T.stripFilename(pdbIn) ## set file name for pickled Structure object dir = os.path.dirname(pdbIn) if self.params['out'] <> None: dir = self.params['out'] out = dir + '/' + T.stripFilename(pdbIn) + '.model' try: m = PDBModel(pdbIn, skipRes=self.params['skipRes']) if self.params['amber']: self.renameAmberRes(m) self.renameToAmberAtoms(m) if self.params['sort']: m = m.sort() m.saveAs(out) except: if self.params.has_key('report') and self.params['report']: f = open(out[:-6] + '.error', 'w') f.write(T.lastError()) f.close() else: T.errWriteln("Error" + T.lastError()) out = '' d[pdbIn] = out print "Done." return d
def go( self, dict ): """ Calculate rmsd values for trajectory and plot them. @param dict: dictionary with path to trajectories as values @type dict: dict @return: dictionary with path to trajectories as values @rtype: dict """ for k, f in dict.items(): fout = dirname( f )+'/'+'%s'+ T.stripFilename(f)+'.eps' fshort = dirname( f )[-15:] if self.verbose: print fshort t = self.loadTraj( f ) self.calcRmsd( t ) p = self.plotRmsdRef(t, fshort ) p.write_eps( fout % 'rms_', width="18cm", height="29cm" ) if self.verbose: print "Done" return dict
def go(self, dict): """ Calculate rmsd values for trajectory and plot them. @param dict: dictionary with path to trajectories as values @type dict: dict @return: dictionary with path to trajectories as values @rtype: dict """ for k, f in dict.items(): fout = dirname(f) + '/' + '%s' + T.stripFilename(f) + '.eps' fshort = dirname(f)[-15:] if self.verbose: print fshort t = self.loadTraj(f) self.calcRmsd(t) p = self.plotRmsdRef(t, fshort) p.write_eps(fout % 'rms_', width="18cm", height="29cm") if self.verbose: print "Done" return dict
def addMovie(self, pdb, modName=None): """ Add one or several existing pdb files or Structure objects to one model. Several files will hence end up as single movie (i.e. as frames of a model in PyMol). @param pdb: file name or a list of file names OR PDBModel or list of PDBModels @type pdb: str or [str] OR PDBModel or [PDBModel] @param modName: model name, will show up in PyMol. If 'None' a model name will be created from the source file name and a serial number. @type modName: str OR None @return: the modName of the added model @rtype: str """ if type(pdb) is not list: pdb = [pdb] ## dream up a nice model name if modName is None: if type(pdb[0]) is str: modName = T.stripFilename(pdb[0]) modName = self._getFreeModName(modName, 0) else: modName = self._getFreeModName('models', 0) ## create new empty list if not self.dic.has_key(modName): self.dic[modName] = [] ## create model object for each file and append it to dic for f in pdb: ## create model from Structure or file name model = PymolModel(f, modName) self.dic[modName].append(model) ## add load statement to Pymol script self.add('load ' + model.fname + ',' + modName) return modName
def addMovie( self, pdb, modName=None ): """ Add one or several existing pdb files or Structure objects to one model. Several files will hence end up as single movie (i.e. as frames of a model in PyMol). @param pdb: file name or a list of file names OR PDBModel or list of PDBModels @type pdb: str or [str] OR PDBModel or [PDBModel] @param modName: model name, will show up in PyMol. If 'None' a model name will be created from the source file name and a serial number. @type modName: str OR None @return: the modName of the added model @rtype: str """ if type( pdb ) is not list: pdb = [pdb] ## dream up a nice model name if modName == None: if type( pdb[0]) is str: modName = T.stripFilename( pdb[0] ) modName = self._getFreeModName( modName, 0 ) else: modName = self._getFreeModName( 'models', 0 ) ## create new empty list if not self.dic.has_key( modName ): self.dic[ modName ] = [] ## create model object for each file and append it to dic for f in pdb: ## create model from Structure or file name model = PymolModel( f, modName ) self.dic[ modName ].append( model ) ## add load statement to Pymol script self.add( 'load '+ model.fname + ',' + modName ) return modName
def __collectAll( self, fname, skipRes=None, headPatterns=[] ): """ Parse ATOM/HETATM lines from PDB. Collect coordinates plus dictionaries with the other pdb records of each atom. REMARK, HEADER, etc. lines are ignored. Some changes are made to the dictionary from PDBFile.readline():: - the 'position' entry (with the coordinates) is removed - leading and trailing spaces are removed from 'name' .. - .. but a 'name_original' entry keeps the old name with spaces - a 'type' entry is added. Its value is 'ATOM' or 'HETATM' - a 'after_ter' entry is added. Its value is 1, if atom is preceeded by a 'TER' line, otherwise 0 - empty 'element' entries are filled with the first non-number letter from the atom 'name' @param fname: name of pdb file @type fname: str @param skipRes: list with residue names that should be skipped @type skipRes: list of str @return: tuple of (1) dictionary of profiles and (2) xyz array N x 3 @rtype: ( list, array ) """ xyz = [] aProfs = {} info = {} in_header = True headPatterns = headPatterns or self.RE_REMARKS patterns = [ (key, re.compile(ex)) for key,ex in headPatterns ] for k in bi.PDBModel.PDB_KEYS: aProfs[k] = list() f = open( fname ,'r' ) try: line, i = ('',''), 0 while line[0] <> 'END' and line[0] <> 'ENDMDL': i += 1 try: line = f.readline().split() except ValueError, what: self.log.add('Warning: Error parsing line %i of %s' % (i, T.stripFilename( fname )) ) self.log.add('\tError: '+str(what) ) continue if not line: break ## header handling if in_header and line[0] == 'HEADER': info.update( self._PDBParseFile__parseHeader( line ) ) if in_header and line[0] == 'REMARK': info.update( self._PDBParseFile__parseRemark( line, patterns ) ) ## preserve position of TER records # print line newChain = line[0] == 'TER' if newChain: line = f.readline().split() if (line[0] in ['ATOM','HETATM'] ): if in_header: in_header = False ## switch off HEADER parsing if len(line) == 11: # contains chain name a = {'serial_number': int(line[1]), 'name': line[2], 'alternate': '', 'residue_name': string.strip(line[3]), 'chain_id': string.strip(line[4]), 'residue_number': int(line[5]), 'insertion_code': '', 'position': map(float,line[6:9]), 'occupancy': 1.0, 'temperature_factor': 0.0, 'segment_id': '', 'element': '', 'charge': line[9]} else: # without chain name a = {'serial_number': int(line[1]), 'name': line[2], 'alternate': '', 'residue_name': string.strip(line[3]), 'chain_id': '', 'residue_number': int(line[4]), 'insertion_code': '', 'position': map(float,line[5:8]), 'occupancy': 1.0, 'temperature_factor': 0.0, 'segment_id': '', 'element': '', 'charge': line[8]} # print line # print a if skipRes and a['residue_name'] in skipRes: continue a['name_original'] = a['name'] a['name'] = a['name'].strip() a['type'] = line[0] if newChain: a['after_ter'] = 1 else: a['after_ter'] = 0 if a['element'] == '': a['element'] = self._PDBParseFile__firstLetter( a['name'] ) # print a xyz.append( a['position'] ) del( a['position']) for k, v in a.items(): aProfs[k].append( v ) except: raise PDBParserError("Error parsing file "+fname+": " \ + T.lastError()) try: f.close() except: pass if len( xyz ) == 0: raise PDBParserError("Error parsing file "+fname+": "+ "Couldn't find any atoms.") return aProfs, npy.array( xyz, npy.float64 ), info