Protool/structure.py
def writepdb(self,filename,header=None,nowrite=False,dont_write_HETATMS=None,TER=1,pqr=None,style=None):
        """
        # Writes a PDB file from the informations in self.atoms
        """
        #
        # Renumber all atoms first
        #
        self.renumber_atoms()
        #
        # Write the file
        #
        class virtual_file:

            def __init__(self):
                self.lines=[]

            def write(self,text):
                self.lines.append(text)

            def close(self):
                return
        #
        #
        #
        import string, os
        if nowrite:
            fd=virtual_file()
        else:
            fd=open(filename,'w')
        #
        # Continue
        #
        if header:
            fd.write(header)
        #
        # Write the cryst info
        #
        for line in self.cryst:
            fd.write(line+'\n')
        for line in self.orig:
            fd.write(line+'\n')
        for line in self.scale:
            fd.write(line+'\n')
        #
        # Now write atoms
        #
        atoms={}
        for atom in self.atoms.keys():
            atoms[self.atoms[atom]['NUMBER']]=atom
        atomnums=atoms.keys()
        atomnums.sort()
        lastchainid=None
        for atomno in atomnums:
            atom=atoms[atomno]
            if self.atoms[atom].has_key('HETATM'):
                if self.atoms[atom]['HETATM']==1 and dont_write_HETATMS:
                    continue
            atomname=string.ljust(self.atoms[atom]['ATNAME'],4)
            if atomname[0] not in string.digits:
                atomname=' '+atomname[:3]
            if self.atoms[atom].has_key('OCCUPANCY'):
                occupancy='%5.2f' %self.atoms[atom]['OCCUPANCY']
            else:
                occupancy='     '
            #
            # Should we use Autodock or WHAT IF names
            #
            import string
            atomname=string.strip(atomname)
            if style:
                if style.lower()=='autodock':
                    if self.autodock_names.has_key(string.strip(atomname)):
                        atomname=self.autodock_names[string.strip(atomname)]
                elif style.lower()=='whatif':
                    if self.Cterminal(self.resnum(atom)):
                        if atomname=='O':
                            atomname="O'"
                        elif atomname=='OXT':
                            atomname="O''"
            atomname=string.ljust(atomname,4)
            if atomname[0] not in string.digits:
                atomname=' '+atomname[:3]
            #
            # Continue
            #
            if self.atoms[atom].has_key('B-FACTOR'):
                bfactor='%5.2f' %self.atoms[atom]['B-FACTOR']
            else:
                bfactor='     '
            #
            # New Chain?
            #
            if self.atoms[atom]['CHAINID']!=lastchainid and lastchainid:
                fd.write('TER\n')
            lastchainid=self.atoms[atom]['CHAINID']
            if not pqr:
                try:
                    resnum=int(self.atoms[atom]['RESNUM'])
                except:
                    resnum=self.atoms[atom]['RESNUM']
                if type(resnum)==type(3):
                    line='ATOM  %5i %4s %3s %1s%4i    %8.3f%8.3f%8.3f %5s %5s' %(self.atoms[atom]['NUMBER'],atomname,self.atoms[atom]['RESNAME'],self.atoms[atom]['CHAINID'],resnum,self.atoms[atom]['X'],self.atoms[atom]['Y'],self.atoms[atom]['Z'],occupancy,bfactor)
                else:
                    suffix=resnum[-1]
                    resnum=int(resnum[:-1])
                    line='ATOM  %5i %4s %3s %1s%4i%1s   %8.3f%8.3f%8.3f %5s %5s' %(self.atoms[atom]['NUMBER'],atomname,self.atoms[atom]['RESNAME'],self.atoms[atom]['CHAINID'],resnum,suffix,self.atoms[atom]['X'],self.atoms[atom]['Y'],self.atoms[atom]['Z'],occupancy,bfactor)
                
            else:
                charge=self.atoms[atom]['CHARGE']
                radius=self.atoms[atom]['RADIUS']
                line='ATOM  %5i %4s %3s %1s%4i    %8.3f%8.3f%8.3f %5s %5s' %(self.atoms[atom]['NUMBER'],atomname,self.atoms[atom]['RESNAME'],self.atoms[atom]['CHAINID'],string.atoi(self.atoms[atom]['RESNUM']),self.atoms[atom]['X'],self.atoms[atom]['Y'],self.atoms[atom]['Z'],charge,radius)
            #
            # Is there a tag?
            #
            if self.atoms[atom].has_key('tag'):
                line=line+'\t %s' %self.atoms[atom]['tag']
            fd.write(line+'\n')
        if TER:
            fd.write('TER\n')
        fd.close()
        #
        # If no write then we simply return the lines
        #
        if nowrite:
            lines=fd.lines
            return lines
        else:
            return
        return

        # Writes a PDB file from the informations in self.atoms
        
Writes a PDB file from the informations in self.atoms
Writes a PDB file from the informations in self . atoms
def writepdb(self,filename,header=None,nowrite=False,dont_write_HETATMS=None,TER=1,pqr=None,style=None):
         Renumber all atoms first
        self.renumber_atoms()
         Write the file
        class virtual_file:
            def __init__(self):
                self.lines=[]
            def write(self,text):
                self.lines.append(text)
            def close(self):
                return
        import string, os
        if nowrite:
            fd=virtual_file()
        else:
            fd=open(filename,'w')
         Continue
        if header:
            fd.write(header)
         Write the cryst info
        for line in self.cryst:
            fd.write(line+'\n')
        for line in self.orig:
            fd.write(line+'\n')
        for line in self.scale:
            fd.write(line+'\n')
         Now write atoms
        atoms={}
        for atom in self.atoms.keys():
            atoms[self.atoms[atom]['NUMBER']]=atom
        atomnums=atoms.keys()
        atomnums.sort()
        lastchainid=None
        for atomno in atomnums:
            atom=atoms[atomno]
            if self.atoms[atom].has_key('HETATM'):
                if self.atoms[atom]['HETATM']==1 and dont_write_HETATMS:
                    continue
            atomname=string.ljust(self.atoms[atom]['ATNAME'],4)
            if atomname[0] not in string.digits:
                atomname=' '+atomname[:3]
            if self.atoms[atom].has_key('OCCUPANCY'):
                occupancy='%5.2f' %self.atoms[atom]['OCCUPANCY']
            else:
                occupancy='     '
             Should we use Autodock or WHAT IF names
            import string
            atomname=string.strip(atomname)
            if style:
                if style.lower()=='autodock':
                    if self.autodock_names.has_key(string.strip(atomname)):
                        atomname=self.autodock_names[string.strip(atomname)]
                elif style.lower()=='whatif':
                    if self.Cterminal(self.resnum(atom)):
                        if atomname=='O':
                            atomname="O'"
                        elif atomname=='OXT':
                            atomname="O''"
            atomname=string.ljust(atomname,4)
            if atomname[0] not in string.digits:
                atomname=' '+atomname[:3]
             Continue
            if self.atoms[atom].has_key('B-FACTOR'):
                bfactor='%5.2f' %self.atoms[atom]['B-FACTOR']
            else:
                bfactor='     '
             New Chain?
            if self.atoms[atom]['CHAINID']!=lastchainid and lastchainid:
                fd.write('TER\n')
            lastchainid=self.atoms[atom]['CHAINID']
            if not pqr:
                try:
                    resnum=int(self.atoms[atom]['RESNUM'])
                except:
                    resnum=self.atoms[atom]['RESNUM']
                if type(resnum)==type(3):
                    line='ATOM  %5i %4s %3s %1s%4i    %8.3f%8.3f%8.3f %5s %5s' %(self.atoms[atom]['NUMBER'],atomname,self.atoms[atom]['RESNAME'],self.atoms[atom]['CHAINID'],resnum,self.atoms[atom]['X'],self.atoms[atom]['Y'],self.atoms[atom]['Z'],occupancy,bfactor)
                else:
                    suffix=resnum[-1]
                    resnum=int(resnum[:-1])
                    line='ATOM  %5i %4s %3s %1s%4i%1s   %8.3f%8.3f%8.3f %5s %5s' %(self.atoms[atom]['NUMBER'],atomname,self.atoms[atom]['RESNAME'],self.atoms[atom]['CHAINID'],resnum,suffix,self.atoms[atom]['X'],self.atoms[atom]['Y'],self.atoms[atom]['Z'],occupancy,bfactor)
            else:
                charge=self.atoms[atom]['CHARGE']
                radius=self.atoms[atom]['RADIUS']
                line='ATOM  %5i %4s %3s %1s%4i    %8.3f%8.3f%8.3f %5s %5s' %(self.atoms[atom]['NUMBER'],atomname,self.atoms[atom]['RESNAME'],self.atoms[atom]['CHAINID'],string.atoi(self.atoms[atom]['RESNUM']),self.atoms[atom]['X'],self.atoms[atom]['Y'],self.atoms[atom]['Z'],charge,radius)
             Is there a tag?
            if self.atoms[atom].has_key('tag'):
                line=line+'\t %s' %self.atoms[atom]['tag']
            fd.write(line+'\n')
        if TER:
            fd.write('TER\n')
        fd.close()
         If no write then we simply return the lines
        if nowrite:
            lines=fd.lines
            return lines
        else:
            return
        return
def writepdb ( self , filename , header = None , nowrite = False , dont_write_HETATMS = None , TER = 1 , pqr = None , style = None ) : self . renumber_atoms ( ) class virtual_file : def __init__ ( self ) : self . lines = [ ] def write ( self , text ) : self . lines . append ( text ) def close ( self ) : return import string , os if nowrite : fd = virtual_file ( ) else : fd = open ( filename , 'w' ) if header : fd . write ( header ) for line in self . cryst : fd . write ( line + '\n' ) for line in self . orig : fd . write ( line + '\n' ) for line in self . scale : fd . write ( line + '\n' ) atoms = { } for atom in self . atoms . keys ( ) : atoms [ self . atoms [ atom ] [ 'NUMBER' ] ] = atom atomnums = atoms . keys ( ) atomnums . sort ( ) lastchainid = None for atomno in atomnums : atom = atoms [ atomno ] if self . atoms [ atom ] . has_key ( 'HETATM' ) : if self . atoms [ atom ] [ 'HETATM' ] == 1 and dont_write_HETATMS : continue atomname = string . ljust ( self . atoms [ atom ] [ 'ATNAME' ] , 4 ) if atomname [ 0 ] not in string . digits : atomname = ' ' + atomname [ : 3 ] if self . atoms [ atom ] . has_key ( 'OCCUPANCY' ) : occupancy = '%5.2f' % self . atoms [ atom ] [ 'OCCUPANCY' ] else : occupancy = '     ' import string atomname = string . strip ( atomname ) if style : if style . lower ( ) == 'autodock' : if self . autodock_names . has_key ( string . strip ( atomname ) ) : atomname = self . autodock_names [ string . strip ( atomname ) ] elif style . lower ( ) == 'whatif' : if self . Cterminal ( self . resnum ( atom ) ) : if atomname == 'O' : atomname = "O'" elif atomname == 'OXT' : atomname = "O''" atomname = string . ljust ( atomname , 4 ) if atomname [ 0 ] not in string . digits : atomname = ' ' + atomname [ : 3 ] if self . atoms [ atom ] . has_key ( 'B-FACTOR' ) : bfactor = '%5.2f' % self . atoms [ atom ] [ 'B-FACTOR' ] else : bfactor = '     ' if self . atoms [ atom ] [ 'CHAINID' ] != lastchainid and lastchainid : fd . write ( 'TER\n' ) lastchainid = self . atoms [ atom ] [ 'CHAINID' ] if not pqr : try : resnum = int ( self . atoms [ atom ] [ 'RESNUM' ] ) except : resnum = self . atoms [ atom ] [ 'RESNUM' ] if type ( resnum ) == type ( 3 ) : line = 'ATOM  %5i %4s %3s %1s%4i    %8.3f%8.3f%8.3f %5s %5s' % ( self . atoms [ atom ] [ 'NUMBER' ] , atomname , self . atoms [ atom ] [ 'RESNAME' ] , self . atoms [ atom ] [ 'CHAINID' ] , resnum , self . atoms [ atom ] [ 'X' ] , self . atoms [ atom ] [ 'Y' ] , self . atoms [ atom ] [ 'Z' ] , occupancy , bfactor ) else : suffix = resnum [ - 1 ] resnum = int ( resnum [ : - 1 ] ) line = 'ATOM  %5i %4s %3s %1s%4i%1s   %8.3f%8.3f%8.3f %5s %5s' % ( self . atoms [ atom ] [ 'NUMBER' ] , atomname , self . atoms [ atom ] [ 'RESNAME' ] , self . atoms [ atom ] [ 'CHAINID' ] , resnum , suffix , self . atoms [ atom ] [ 'X' ] , self . atoms [ atom ] [ 'Y' ] , self . atoms [ atom ] [ 'Z' ] , occupancy , bfactor ) else : charge = self . atoms [ atom ] [ 'CHARGE' ] radius = self . atoms [ atom ] [ 'RADIUS' ] line = 'ATOM  %5i %4s %3s %1s%4i    %8.3f%8.3f%8.3f %5s %5s' % ( self . atoms [ atom ] [ 'NUMBER' ] , atomname , self . atoms [ atom ] [ 'RESNAME' ] , self . atoms [ atom ] [ 'CHAINID' ] , string . atoi ( self . atoms [ atom ] [ 'RESNUM' ] ) , self . atoms [ atom ] [ 'X' ] , self . atoms [ atom ] [ 'Y' ] , self . atoms [ atom ] [ 'Z' ] , charge , radius ) if self . atoms [ atom ] . has_key ( 'tag' ) : line = line + '\t %s' % self . atoms [ atom ] [ 'tag' ] fd . write ( line + '\n' ) if TER : fd . write ( 'TER\n' ) fd . close ( ) if nowrite : lines = fd . lines return lines else : return return
Writes a PDB file from the informations in self.atoms
Writes a PDB file from the informations in self . atoms
"""
        # Writes a PDB file from the informations in self.atoms
        """ # # Renumber all atoms first # # # Write the file # # # # # # Continue # # # Write the cryst info # # # Now write atoms # # # Should we use Autodock or WHAT IF names # # # Continue # # # New Chain? # # # Is there a tag? # # # If no write then we simply return the lines #
self
filename
header
nowrite
dont_write_HETATMS
TER
pqr
style