Exemplo n.º 1
0
    def update_elements(self):
        """Insert a new dropdown list for the element"""
        #
        # Get the group type
        #
        elements = None
        group_type = self.group_type_box.getcurselection()[0]
        import Protool

        if group_type == "Residues":
            P = Protool.structureIO()
            P.parsepdb(self.pdblines)
            residues = P.residues.keys()
            residues.sort()
            elements = []
            for res in residues:
                elements.append("%s %s" % (res, P.resname(res)))
        elif group_type == "Atoms":
            P = Protool.structureIO()
            P.parsepdb(self.pdblines)
            atoms = P.atoms.keys()
            for res in P.residues.keys():
                resname = P.resname(res)
                if self.AAdefs.has_key(resname):
                    defatoms = self.AAdefs[resname]["atoms"]
                    # print defatoms
                    for defatom, coord, dummy in defatoms:
                        atom_name = "%s:%s" % (res, defatom)
                        if not P.atoms.has_key(atom_name):
                            atoms.append(atom_name)
                            # print 'Adding',atom_name
            atoms.sort()
            elements = []
            for at in atoms:
                elements.append(at)
        elif group_type == "Titratable groups":
            P = Protool.structureIO()
            P.parsepdb(self.pdblines)
            P.get_titratable_groups()
            titgrps = P.titratable_groups.keys()
            titgrps.sort()
            elements = []
            for res in titgrps:
                for titgrp in P.titratable_groups[res]:
                    name = "%s %s" % (res, titgrp["name"])
                    elements.append(name)
        else:
            print "Unkown group type", group_type
        #
        # Make the new dropdown list
        #
        if elements:
            self.group_elements_box.setlist(elements)
        return
Exemplo n.º 2
0
 def update_elements(self):
     """Insert a new dropdown list for the element"""
     #
     # Get the group type
     #
     elements = None
     group_type = self.group_type_box.getcurselection()[0]
     import Protool
     if group_type == 'Residues':
         P = Protool.structureIO()
         P.parsepdb(self.pdblines)
         residues = P.residues.keys()
         residues.sort()
         elements = []
         for res in residues:
             elements.append('%s %s' % (res, P.resname(res)))
     elif group_type == 'Atoms':
         P = Protool.structureIO()
         P.parsepdb(self.pdblines)
         atoms = P.atoms.keys()
         for res in P.residues.keys():
             resname = P.resname(res)
             if self.AAdefs.has_key(resname):
                 defatoms = self.AAdefs[resname]['atoms']
                 #print defatoms
                 for defatom, coord, dummy in defatoms:
                     atom_name = '%s:%s' % (res, defatom)
                     if not P.atoms.has_key(atom_name):
                         atoms.append(atom_name)
                         #print 'Adding',atom_name
         atoms.sort()
         elements = []
         for at in atoms:
             elements.append(at)
     elif group_type == 'Titratable groups':
         P = Protool.structureIO()
         P.parsepdb(self.pdblines)
         P.get_titratable_groups()
         titgrps = P.titratable_groups.keys()
         titgrps.sort()
         elements = []
         for res in titgrps:
             for titgrp in P.titratable_groups[res]:
                 name = '%s %s' % (res, titgrp['name'])
                 elements.append(name)
     else:
         print 'Unkown group type', group_type
     #
     # Make the new dropdown list
     #
     if elements:
         self.group_elements_box.setlist(elements)
     return
Exemplo n.º 3
0
def Model_Mutations_old(pdbfile,
                        mol2files,
                        mutations,
                        max_overlap=0.5,
                        return_score=False):
    """Model a number of mutations in a pdbfile when one or more ligands are present"""
    #
    # Initialise mutate routines
    #
    MUT = Mutate(max_bump=max_overlap)
    #
    # Read PDB file
    #
    import Protool
    P = Protool.structureIO()
    P.readpdb(pdbfile)
    P.remove_all_hydrogens()
    #
    # Read mol2 file
    #
    L = Protool.ligand(P)
    for mol2file in mol2files:
        print "Added %s with tag 'LIGAND'" % mol2file
        L.readmol2(mol2file, tag='LIGAND')
    #
    # Pass combined pdb file to mutate routines and mutate
    #
    MUT.new_PDB(P)
    import pKa.pKD_tools as pKD_tools
    total_bump = 0.0
    #
    # Model
    #
    for mutation in mutations:
        #
        # Get info
        #
        resid = pKD_tools.get_resid_from_mut(mutation)
        newres = pKD_tools.get_newrestyp_from_mut(mutation)
        oldres = pKD_tools.get_oldrestyp_from_mut(mutation)
        bump_score = MUT.mutate(resid, newres, orgtype=oldres)
        if bump_score is None or bump_score is False or bump_score > max_overlap:
            print 'Cannot model this set of mutations - too many bumps'
            return False, 20.0
        print 'Bump score for %s: %5.3f' % (mutation, bump_score)
        total_bump = total_bump + bump_score
    print 'Total bump score for all mutations: %5.3f' % (bump_score)
    if return_score:
        return MUT, bump_score
    return MUT
Exemplo n.º 4
0
def convert_classic_to_PEAT(operations):
    """Convert a set of classic mutations to a set of PEAT operations
    The classic operations are in the format: A12G+R45V etc."""
    #
    # Do a quick sanity check
    #
    for junk in ['?','unknown','empty']:
        if operations.lower().find(junk)!=-1:
            return False
    #
    # Deal with the operations
    #
    sp=operations.split('+')
    import Protool, string
    P=Protool.structureIO()
    POP=[]
    for op in sp:
        if op=='wt':
            continue
        old=op[0]
        new=op[-1]
        number=int(op[1:-1])
        try:
            POP.append('%s:%s:%s:%s' %('',string.zfill(number,P.length_of_residue_numbers),P.one_to_three[old],P.one_to_three[new]))
        except KeyError:
            return False
    return string.join(POP,'+')
Exemplo n.º 5
0
 def __init__(self):
     import Protool
     self.PI = Protool.structureIO()
     self.aas = self.PI.trueaminoacids.keys()
     self.PI.readpdb('test.pdb')
     #
     import FFF.FFFcontrol as FFFC
     import os, sys
     scriptdir = os.path.split(os.path.abspath(__file__))[0]
     FFFdir = os.path.split(scriptdir)[0]
     Rotamerlib = FFFC.Rotamer_class(
         os.path.join(FFFdir, 'parameters/small_lib'))
     self.FFF = FFFC.FFF()
     self.FFF.read_pdb('test.pdb')
     #self.Model=FFFC.pKa_class(self.FFF,Rotamerlib,os.path.join(FFFdir,'parameters'))
     self.Model = FFFC.model_class(self.FFF, Rotamerlib,
                                   os.path.join(FFFdir, 'parameters'))
     #
     # Test mutations
     #
     self.mutate_test()
     #self.Model.repair_all()
     #
     # Build all hydrogens - standard protonation state
     #
     #self.Model.build_hydrogens()
     #self.FFF.write_pqr('2lzt.pqr.pdb')
     return
Exemplo n.º 6
0
def get_net_charge(pdbfile,HIS):
    """Get the net charge within 20 A of the HIS"""
    import Protool
    X=Protool.structureIO()
    X.readpdb(pdbfile)
    close=[]
    HIS_ND1='%s:ND1' %HIS
    HIS_NE2='%s:NE2' %HIS
    for residue in X.residues.keys():
        for atom in X.residues[residue]:
            #print atom
            mdist=min(X.dist(HIS_ND1,atom),X.dist(HIS_NE2,atom))
            if mdist<50.0:
                close.append(residue)
                break
            elif mdist>355.0:
                break
    # Got all close residues, now count charge
    charge=0.0
    nc={'ASP':-1,'GLU':-1,'LYS':+1,'ARG':+1,'HIS':+1}
    close.sort()
    print close
    for res in close:
        restype=X.resname(res)
        if nc.has_key(restype):
            charge=charge+nc[restype]
            print res,restype,nc[restype],charge
    print 'Net charge',charge
    return charge
Exemplo n.º 7
0
def read_sequences(pdbfiles, newfiles):
    #
    # Load all the PDB files and Make sure that the sequences are ok
    #
    align = {}
    allseqs = {}
    print 'Reading pdb files and extracting sequences'
    import Protool
    for pdb in pdbfiles:
        pdbfile = newfiles[pdb]
        X = Protool.structureIO_fast()
        print 'Reading: %s' % pdbfile
        X.readpdb(pdbfile)
        X.RemoveALT()
        s_keys = X.residues.keys()
        s_keys.sort()
        #
        # Construct a special list for the sequence
        #
        newlist = []
        for s in s_keys:
            if X.three_to_one.has_key(X.resname(s)):
                newlist.append([s, X.three_to_one[X.resname(s)]])
        align[pdb] = newlist[:]
        allseqs[pdb] = X.Seq2Pir(None, pdb)
    return align, allseqs
Exemplo n.º 8
0
 def checkMutation(self, DB, name, ref=None, X=None):
     """Check mutations based on ref sequence and current mutant
        sequence, should be triggered whenever ref protein is altered so 
        that the mutation codes are updated."""
     prot = DB.get(name)
     if prot.aaseq == None:
         return
     if ref == None:
         ref = self.DB.meta.refprotein            
     refseq = self.AAList2String(DB.get(ref).aaseq)        
     if prot.aaseq == None:
         return
     #get mutations from sequence
     seq = self.AAList2String(prot.aaseq)       
     if seq == refseq:
         return
         
     #get alignment for pdb seq and AA from DNA seq    
     import PEATSA.Core as Core
     if X == None:
         #we need to also provide the ref structure
         import Protool
         X=Protool.structureIO()
         X.parsepdb(DB.get(ref).Structure)
     print X 
     mset = Core.Data.mutationSetFromSequencesAndStructure(refseq, seq, X)
     #prot.Mutations = '+'.join(mset.mutationCodes())
     prot.Mutations = mset.codeString(X)
     return
Exemplo n.º 9
0
    def checkMutation(self, DB, name, ref=None, X=None):
        """Check mutations based on ref sequence and current mutant
           sequence, should be triggered whenever ref protein is altered so 
           that the mutation codes are updated."""
        prot = DB.get(name)
        if prot.aaseq == None:
            return
        if ref == None:
            ref = self.DB.meta.refprotein
        refseq = self.AAList2String(DB.get(ref).aaseq)
        if prot.aaseq == None:
            return
        #get mutations from sequence
        seq = self.AAList2String(prot.aaseq)
        if seq == refseq:
            return

        #get alignment for pdb seq and AA from DNA seq
        import PEATSA.Core as Core
        if X == None:
            #we need to also provide the ref structure
            import Protool
            X = Protool.structureIO()
            X.parsepdb(DB.get(ref).Structure)
        print X
        mset = Core.Data.mutationSetFromSequencesAndStructure(refseq, seq, X)
        #prot.Mutations = '+'.join(mset.mutationCodes())
        prot.Mutations = mset.codeString(X)
        return
Exemplo n.º 10
0
    def setSequencesfromMutationCodes(self, DB=None, callback=None, selected=None):
        """Set the aa sequence using wt ref aa and mutation code
           Assumes mutation code is consistent with ref aa seq"""

        if DB == None:
            return
        proteins = DB.getRecs()
        refprot = DB.meta.refprotein
        refseq = DB[refprot].aaseq
        refaa = self.AAList2String(refseq)
        refpdb = DB[refprot].Structure
        #Create protool oinstance for ref pdb
        import Protool
        Xref = Protool.structureIO()
        Xref.parsepdb(refpdb)        
        for protein in selected:
            rec = DB.get(protein)
            if rec.hasStructure() == 'available':
                continue                
            print 'Protein:', protein            
            #if no sequence try create one from mutation code
            if rec.aaseq == None and rec.Mutations != None:               
                print 'no sequence, using mutation code and ref protein seq'                 
                import PEATSA.Core as Core
                print 'Record has mutation code %s' %rec.Mutations
                mutationSet = Core.Data.MutationSet(rec.Mutations)
                Xref.Remove_All_NonAminoAcids()
                refaa = Core.Data.GetChainSequences(Xref)['A']
                #print refaa
                mutseq = mutationSet.applyToSequence(refaa, id='A', offset=None, pdb=Xref)                 
                rec.aaseq = self.string2AAseq(mutseq)                
        
        return
Exemplo n.º 11
0
def convert_classic_to_PEAT(operations):
    """Convert a set of classic mutations to a set of PEAT operations
    The classic operations are in the format: A12G+R45V etc."""
    #
    # Do a quick sanity check
    #
    for junk in ['?', 'unknown', 'empty']:
        if operations.lower().find(junk) != -1:
            return False
    #
    # Deal with the operations
    #
    sp = operations.split('+')
    import Protool, string
    P = Protool.structureIO()
    POP = []
    for op in sp:
        if op == 'wt':
            continue
        old = op[0]
        new = op[-1]
        number = int(op[1:-1])
        try:
            POP.append('%s:%s:%s:%s' %
                       ('', string.zfill(number, P.length_of_residue_numbers),
                        P.one_to_three[old], P.one_to_three[new]))
        except KeyError:
            return False
    return string.join(POP, '+')
Exemplo n.º 12
0
def read_sequences(pdbfiles,newfiles):
    #
    # Load all the PDB files and Make sure that the sequences are ok
    #
    align={}
    allseqs={}
    print 'Reading pdb files and extracting sequences'
    import Protool
    for pdb in pdbfiles:
        pdbfile=newfiles[pdb]
        X=Protool.structureIO_fast()
        print 'Reading: %s' %pdbfile
        X.readpdb(pdbfile)
        X.RemoveALT()
        s_keys=X.residues.keys()
        s_keys.sort()
        #
        # Construct a special list for the sequence
        #
        newlist=[]
        for s in s_keys:
            if X.three_to_one.has_key(X.resname(s)):
                newlist.append([s,X.three_to_one[X.resname(s)]])
        align[pdb]=newlist[:]
        allseqs[pdb]=X.Seq2Pir(None,pdb)
    return align,allseqs
Exemplo n.º 13
0
 def __init__(self):
     import Protool
     self.PI=Protool.structureIO()
     self.aas=self.PI.trueaminoacids.keys()
     self.PI.readpdb('test.pdb')
     #
     import FFF.FFFcontrol as FFFC
     import os, sys
     scriptdir=os.path.split(os.path.abspath(__file__))[0]
     FFFdir=os.path.split(scriptdir)[0]
     Rotamerlib=FFFC.Rotamer_class(os.path.join(FFFdir,'parameters/small_lib'))
     self.FFF=FFFC.FFF()
     self.FFF.read_pdb('test.pdb')
     #self.Model=FFFC.pKa_class(self.FFF,Rotamerlib,os.path.join(FFFdir,'parameters'))
     self.Model=FFFC.model_class(self.FFF,Rotamerlib,os.path.join(FFFdir,'parameters'))
     #
     # Test mutations
     #
     self.mutate_test()
     #self.Model.repair_all()
     #
     # Build all hydrogens - standard protonation state
     #
     #self.Model.build_hydrogens()
     #self.FFF.write_pqr('2lzt.pqr.pdb')
     return
Exemplo n.º 14
0
def Model_Mutations_old(pdbfile,mol2files,mutations,max_overlap=0.5,return_score=False):
    """Model a number of mutations in a pdbfile when one or more ligands are present"""
    #
    # Initialise mutate routines
    #
    MUT=Mutate(max_bump=max_overlap)
    #
    # Read PDB file
    #
    import Protool
    P=Protool.structureIO()
    P.readpdb(pdbfile)
    P.remove_all_hydrogens()
    #
    # Read mol2 file
    #
    L=Protool.ligand(P)
    for mol2file in mol2files:
        print "Added %s with tag 'LIGAND'" %mol2file
        L.readmol2(mol2file,tag='LIGAND')
    #
    # Pass combined pdb file to mutate routines and mutate
    #
    MUT.new_PDB(P)
    import pKa.pKD_tools as pKD_tools
    total_bump=0.0
    #
    # Model
    #
    for mutation in mutations:
        #
        # Get info
        #
        resid=pKD_tools.get_resid_from_mut(mutation)
        newres=pKD_tools.get_newrestyp_from_mut(mutation)
        oldres=pKD_tools.get_oldrestyp_from_mut(mutation)
        bump_score=MUT.mutate(resid,newres,orgtype=oldres)
        if bump_score is None or bump_score is False or bump_score>max_overlap:
            print 'Cannot model this set of mutations - too many bumps'
            return False,20.0
        print 'Bump score for %s: %5.3f' %(mutation,bump_score)
        total_bump=total_bump+bump_score
    print 'Total bump score for all mutations: %5.3f' %(bump_score)
    if return_score:
        return MUT,bump_score
    return MUT
Exemplo n.º 15
0
    def remALT(self,pdbfile, environment): 
        import Protool

        x = Protool.structureIO()
        x.readpdb('%s.pdb' % (pdbfile))
        x.RemoveALT()
        x.writepdb('%s.pdb' % (pdbfile), dont_write_HETATMS=1)
        environment.output('Removed alternate residues')
Exemplo n.º 16
0
    def remALT(self,pdbfile): 
        import Protool

        x = Protool.structureIO()
        x.readpdb('%s.pdb' % (pdbfile))
        x.RemoveALT()
        x.writepdb('%s.pdb' % (pdbfile), dont_write_HETATMS=1)
        print 'Removed alternate residues'
Exemplo n.º 17
0
 def load_groups(self):
     #
     # Get all the titratable groups in the pdb file
     #
     import Protool
     P=Protool.structureIO()
     P.readpdb(self.params['pdb'])
     self.groups=P.get_titratable_groups()
     return
Exemplo n.º 18
0
 def load_groups(self):
     #
     # Get all the titratable groups in the pdb file
     #
     import Protool
     P = Protool.structureIO()
     P.readpdb(self.params['pdb'])
     self.groups = P.get_titratable_groups()
     return
Exemplo n.º 19
0
def findSequenceDifferences(child_sequence, parent_sequence,full_parent_sequence,ignoreCterm=False):
    """
    # Find all amino acid differences between child_sequence and parent_sequence
    Child sequence and parent sequence must be aligned and in 1-letter format:
    child_sequence, parent_sequence: AAADEFFG
    full parent sequence is a Protool.sequence object
    """
    #
    # Loop over the sequences - changes are record from parent -> child
    #
    import string
    operations=[]
    import Protool
    PI=Protool.structureIO()
    #
    Cterm_add=0
    insert_num=0
    full_parent_count=0
    #for count in range(len(record_sequence)):
    #    parent_aa=parent_sequence[count]
    #    child_aa=record_sequence[count]
    for parent_aa,child_aa in zip(parent_sequence,child_sequence):
        #
        #print parent_aa,child_aa
        if parent_aa!=child_aa:
            
            # Find the PDB file residue number
            if full_parent_count>=len(full_parent_sequence):
                # If we have an insertion at the Cterm
                aa_identifier=full_parent_sequence[-1][0]
                if ignoreCterm:
                    continue
            else:
                aa_identifier=full_parent_sequence[full_parent_count][0]
            #if aa_identifier[-1]==':':
            #    aa_identifier=aa_identifier[:-1]
            #
            # Convert to 3letter format
            #
            if parent_aa!='-':
                full_parent_count=full_parent_count+1
                parent_aa=PI.one_to_three[parent_aa]
            if child_aa!='-':
                child_aa=PI.one_to_three[child_aa]
            if parent_aa=='-':
                operations.append('insert%d:%s:%s' %(insert_num,aa_identifier,child_aa))
                insert_num=insert_num+1
            elif child_aa=='-':
                insert_num=0
                operations.append('delete:%s:%s' %(aa_identifier,parent_aa))
            else:
                insert_num=0
                operations.append('%s:%s:%s' %(aa_identifier,parent_aa,child_aa))
        else:
            full_parent_count=full_parent_count+1
    return operations
Exemplo n.º 20
0
    def remALT(self, pdb):
        '''Removes alternative residues from the working pdb. Replaces the working pdb.'''

        import Protool

        x = Protool.structureIO()
        x.readpdb('%s.pdb' % (pdb))
        x.RemoveALT()
        x.writepdb('%s.pdb' % (pdb), dont_write_HETATMS=1)
        print "[ProteinComplexTool] Alternative Residues removed."
Exemplo n.º 21
0
def matrix():
    import os
    dirs=os.listdir('data')
    xs=[]
    ys=[]
    for dir in dirs:
        print 'Processing %s' %dir
        #
        # find the PDB file
        #
        realdir=os.path.join(os.getcwd(),'data',dir)
        files=os.listdir(realdir)
        for file in files:
            realfile=os.path.join(realdir,file)
            if file[-4:]=='.pdb':
                import pKa.pKaTool.pKaIO
                X=pKa.pKaTool.pKaIO.pKaIO(realfile)
                X.assess_status()
                if X.calculation_completed==1:
                    #
                    # Hurra, the calc is complete. Load the matrix
                    #
                    PBEmatrix=X.read_matrix()
                    #
                    # Now calculate the same matrix with Protool
                    #
                    P=Protool.structureIO()
                    P.readpdb(realfile)
                    P.get_titratable_groups()
                    dist_matrix=P.Calculate_matrix(8)
                    #
                    # Plot it
                    #
                    x=[]
                    y=[]
                    for group1 in PBEmatrix.keys():
                        for group2 in PBEmatrix.keys():
                            PBE_ene=PBEmatrix[group1][group2][0]
                            try:
                                new_ene=dist_matrix[group1][group2]
                            except:
                                continue
                            #
                            # Load the values, distances in x, PBE_ene in y
                            #
                            if new_ene and PBE_ene:
                                x.append(abs(new_ene))
                                y.append(abs(PBE_ene))
                    #
                    # Append these result to the big arrays
                    #
                    ys.append(y)
                    xs.append(x)
    plotit(xs,ys,'Matrix',dirs)
    return
Exemplo n.º 22
0
def CleanPDB2PQR(inputFile, outputFile, forceField="amber", removeWater=True, removeLigand=True, removeAltLoc=True, addHydrogens=True, correct=True):

	'''Cleans a PDB by using PDB2PQR
	
	See CleanPDB for argument details

	Note: With pdb2pqr you cannot remove-water or ligands.
		
	Errors: 
		Raises an exception if the inputFile is not a valid PDB file.'''

	import Protool

	try:
		command = 'pdb2pqr --chain --ff=%s' % (forceField)

		if removeWater == True:
			print >>sys.stderr, 'Warn: Currently PDB2PQR does not remove waters from pdb files'

		if removeLigand == True:
			print >>sys.stderr, 'Warn: Currently PDB2PQR can not be used to remove heterogens from PDB files'

		if addHydrogens == False:
			print >>sys.stderr, 'Warn: Turning of Hydrogen addition with PDB2PQR automatically turns of rotamer correction'
			command = command + " --clean "
		else:
			if correct == False:
				command = command + " --nodebump "

		#Protool ignores altlocs so we can use it to remove them 
		#Do this first as Protool as when protool reads then writes a pdb2pqr cleaned file 
		#it raises an error on reading it again 
		if removeAltLoc is True:
			pdb = Protool.structureIO()
			pdb.readpdb(inputFile)
			pdb.writepdb(outputFile)

			inputFile = outputFile

		command = command + ' %s %s' % (inputFile, outputFile)
		print 'Using: ', command

		process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
		stdout, stderr = process.communicate()

		if process.returncode != 0:
			raise ProteinDesignToolException, 'Error using pdb2pqr to clean pdb file %s' % inputFile
		
	except BaseException, data:
		print 'Encountered an exception cleaning pdb %s' % inputFile
		if stdout is not None:
			print 'PDB2PQR output follows:'
			print stdout
		
		raise 			
Exemplo n.º 23
0
 def addPDBFile(self, DB=None, name=None, pdbfile=None,
                    pdbdata=None, pdbname=None, gui=True):
     """Add a PDB file to the record given as argument"""
     import os, tkMessageBox
     if pdbdata == None and pdbfile == None:
         savedir=os.getcwd()
         global PDB_code
         pdbfile=tkFileDialog.askopenfilename(defaultextension='.pdb',
                                      initialdir=savedir,
                                      filetypes=[("PDB file","*.pdb"),
                                                 ("PDB file","*.brk"),
                                                 ("All files","*.*")])
         if not pdbfile:
             return
     if pdbfile:    
         pdbname = os.path.basename(pdbfile)
     import Protool
     self.X=Protool.structureIO()
     # Extracting PDB_code from pdbfile
     if pdbdata != None: 
         self.X.readpdb(data=pdbdata)
     elif os.path.isfile(pdbfile):
         PDB_code=pdbfile.split('/').pop().split('.')[0]
         # Try to read it using Protool    
         try:
             self.X.readpdb(filename=pdbfile)
         except:
             tkMessageBox.showwarning('Error reading PDB file',
                                      'I could not read the PDB file. This probably means that the PDB file is corrupt in some way.')
             return
         
     AlignmentMap = None    
     if gui==True:
         if tkMessageBox.askyesno('Reset AA Seq?',
                                  'Do you want to reset the amino acid Sequence?'):      
             AlignmentMap = self.checkPDBSequence(name)               
         
     #store it    
     DB.storePDB(name, self.X, AlignmentMap)
     if hasattr(DB.meta,'refprotein'):                
         ref = DB.meta.refprotein
         #if this is the reference protein remodel mutations and rewrite mut codes   
         if name == ref:
             print name, ref
             print 'rechecking mutation codes, ref prot structure has changed'                
             #get new mutation codes
             import PEATSA.Core as Core
             for p in DB.getRecs():
                 self.checkMutation(DB, p, ref, self.X)
             #self.checkModels(DB)
             
     #add the original pdb name
     DB.data[name]['pdbname'] = pdbname
     return
Exemplo n.º 24
0
    def remALT(self,pdb): 
        
        '''Removes alternative residues from the working pdb. Replaces the working pdb.'''
        
        import Protool

        x = Protool.structureIO()
        x.readpdb('%s.pdb' % (pdb))
        x.RemoveALT()
        x.writepdb('%s.pdb' % (pdb), dont_write_HETATMS=1)
        print "[ProteinComplexTool] Alternative Residues removed."
Exemplo n.º 25
0
def pir2Protool(sequence):
    """ Reformats a regular one-letter sequence (e.g. 'ASDDE') to
        the protool type sequence ( [[':0001','ALA'], [':0002','SER'] ...)
    """
    import Protool, string
    X = Protool.structureIO()
    list = []
    number = 1
    for letter in sequence:
        list.append([':' + string.zfill(number, 4), X.one_to_three[letter]])
        number = number + 1
    return list
Exemplo n.º 26
0
 def get_sequences(self):
     """Extract all sequences from the PDB files"""
     import Protool
     for calc in self.multcalcs.keys():
         X = Protool.structureIO()
         X.parsepdb(self.multcalcs[calc]['pdblines'])
         self.multcalcs[calc]['sequence'] = X.sequence[:]
         aa1 = ''
         for number, restype in self.multcalcs[calc]['sequence']:
             aa1 = aa1 + self.aas[restype]
         self.multcalcs[calc]['aa1seq'] = aa1
     return
Exemplo n.º 27
0
 def get_sequences(self):
     """Extract all sequences from the PDB files"""
     import Protool
     for calc in self.multcalcs.keys():
         X=Protool.structureIO()
         X.parsepdb(self.multcalcs[calc]['pdblines'])
         self.multcalcs[calc]['sequence']=X.sequence[:]
         aa1=''
         for number,restype in self.multcalcs[calc]['sequence']:
             aa1=aa1+self.aas[restype]
         self.multcalcs[calc]['aa1seq']=aa1
     return
Exemplo n.º 28
0
def pir2Protool(sequence):
    """ Reformats a regular one-letter sequence (e.g. 'ASDDE') to
        the protool type sequence ( [[':0001','ALA'], [':0002','SER'] ...)
    """
    import Protool, string
    X=Protool.structureIO()
    list=[]
    number=1
    for letter in sequence:
        list.append([':'+string.zfill(number,4),X.one_to_three[letter]])
        number=number+1
    return list
Exemplo n.º 29
0
 def load_PDB(self):
     """Load a PDB file"""
     import tkFileDialog, os
     filename=tkFileDialog.askopenfilename(defaultextension='.pdb',
                                           initialdir=os.getcwd(),
                                           parent=self.Dcontrol,
                                           filetypes=[("PDB file","*.pdb"),
                                                      ("All files","*.*")])
     if filename:
         import Protool
         self.P=Protool.structureIO()
         self.P.readpdb(filename)
     return
Exemplo n.º 30
0
def cubescanplot(options):
    """Read a cubescan output file and show the results"""
    fd=open(options.cubescanfile)
    import pickle
    data=pickle.load(fd)
    fd.close()
    #
    cubegrid=data[0]
    scanresults=data[1]
    #
    # Instantiate scoring class
    #
    SC=score_class(options)
    #
    # Score the ghosts from each cubescan
    #
    scores=[]
    for cube in sorted(scanresults.keys()):
        calc_ghosts=scanresults[cube]
        xs,ys,experrors,satisfied=SC.score_ghosts(calc_ghosts)
        rmsd=RMSD(xs,ys,experrors)
        scores.append([rmsd,cube])
        #import pylab
        #pylab.errorbar(xs,ys,xerr=experrors,fmt='ro')
        #pylab.plot(xs,xs,'g-')
        #pylab.xlabel('Experimental dCS')
        #pylab.ylabel('Calculated dCS')
        #pylab.title('Cubescan of cube %4d, atom: %s, RMSD: %5.3f' %(cube,options.atom,rmsd))
        #pylab.savefig('Cubescan_%d.png' %(cube))
        #pylab.clf()
    rmsds=[]
    scores.sort()
    import Protool
    P=Protool.structureIO()
    P.readpdb('2LZT_H.pdb')
    count=0
    for rmsd,cube in scores[:25]:
        print '%4d, rmsd: %5.2f' %(cube,rmsd)
        center=cubegrid[cube]['coord']
        P.add_atom('X:%4d:CS' %(count+1000),
                 atomnumber=0,atomname='CS',
                 chainid='X',residuename='CSS',residuenumber='999',
                 xcoord=center[0],ycoord=center[1],zcoord=center[2],update=1,BFACTOR=None,OCCUPANCY=None,CHARGE=None,RADIUS=None,tag=None,accept_duplicate=False)
        count=count+1
        rmsds.append(rmsd)
    P.writepdb('cubescan.pdb')
    import pylab
    pylab.hist(rmsds)
    pylab.savefig('Cubescanhist.png')
    return
Exemplo n.º 31
0
def background():
    """Find correlation between background interaction energy and number of hbonds"""
    import os
    dirs=os.listdir('data')
    xs=[]
    ys=[]
    count=0
    #dirs=['1bli']
    for dir in dirs:
        print 'Processing %s' %dir
        #
        # find the PDB file
        #
        realdir=os.path.join(os.getcwd(),'data',dir)
        files=os.listdir(realdir)
        for file in files:
            realfile=os.path.join(realdir,file)
            if file[-4:]=='.pdb':
                import pKaTool.pKaIO
                X=pKaTool.pKaIO.pKaIO(realfile)
                X.assess_status()
                if X.calculation_completed==1:
                    #
                    # Hurra, the calc is complete. Load the desolvation energies
                    #
                    PBEbackground=X.read_backgr()
                    #
                    # Now calculate the desolvation energies with Protool
                    #
                    P=Protool.structureIO()
                    P.readpdb(realfile)
                    P.get_titratable_groups()
                    P.calculate_background()
                    #
                    #
                    x=[]
                    y=[]
                    residues= PBEbackground.keys()
                    residues.sort()
                    for residue in residues:
                        if P.background.has_key(residue) and PBEbackground[residue]<19.0:
                            x.append(P.background[residue])
                            #x.append(count)
                            count=count+1
                            y.append(PBEbackground[residue])
                            print '%12s %5.2f %5.2f' %(residue,P.background[residue],PBEbackground[residue])
                    xs.append(x)
                    ys.append(y)
    plotit(xs,ys,'Background',dirs)
    return
Exemplo n.º 32
0
def check_mutation_syntax(operations,sequence=None):
    """Check the syntax of an operation string and check that the residue is present in the sequence"""
    single=get_single_operations(operations)
    for op in single:
        resid=get_resid_from_mut(op)
        new=get_newrestyp_from_mut(op)
        old=get_oldrestyp_from_mut(op)
        import Protool
        X=Protool.structureIO()
        if not X.aminoacids.has_key(old) or not X.aminoacids.has_key(new):
            raise Exception('New or old residue is not an amino acid: %s' %op)
        if sequence:
            if not [resid,old] in sequence:
                raise Exception('Original sequence does not contain this residue: %s:%s' %(resid,old))
    return combine_operations(single)
Exemplo n.º 33
0
def CleanWHATIF(inputFile, outputFile, removeWater=True, removeLigand=True, removeAltLoc=True, addHydrogens=True, correct=True):

	'''Cleans a PDB using WHAT-IF		

	Errors: 
		Raises an exception if the inputFile is not a valid PDB file.'''

	import pKarun.WI_tools, Protool
	
	#First try to load the pdb using protool.
	#If its not valid 
	try:
		pdb = Protool.structureIO()
		pdb.readpdb(inputFile)
	except Exception, data:	
		raise Exceptions.FileFormatError, 'Format of specified PDB file %s not valid.\nUnderlying error - %s' % (inputFile, data)
Exemplo n.º 34
0
    def load_PDB(self):
        """Load a PDB file"""
        import tkFileDialog, os

        filename = tkFileDialog.askopenfilename(
            defaultextension=".pdb",
            initialdir=os.getcwd(),
            parent=self.Dcontrol,
            filetypes=[("PDB file", "*.pdb"), ("All files", "*.*")],
        )
        if filename:
            import Protool

            self.P = Protool.structureIO()
            self.P.readpdb(filename)
        return
Exemplo n.º 35
0
	def protoolStructure(self):
	
		'''Returns a protool structure instance initialised using the structure data stored in the database'''
		
		import tempfile, Protool
		
		structureData = self.structure()
		temp = tempfile.NamedTemporaryFile()
		temp.write(structureData)
		temp.flush()

		try:
			object = Protool.structureIO()
			object.readpdb(temp.name)
		except Exception, data:	
			raise Exceptions.FileFormatError, 'Format of stored PDB file for job %s not valid.\nUnderlying error - %s' % (self.identification, data)
Exemplo n.º 36
0
def convert_PEAT_to_classic(operations):
    operations=get_single_operations(operations)
    newops=[]
    import string, Protool
    PI=Protool.structure()
    for operation in operations:
        resid=get_resid_from_mut(operation)
        old=PI.three_to_one[get_oldrestyp_from_mut(operation)]
        new=PI.three_to_one[get_newrestyp_from_mut(operation)]
        resnum=get_resnum_from_mut(operation)
        resnum=string.lstrip(resnum,'0')
        classic='%s%s%s' %(old,resnum.strip(),new)
        newops.append(classic)

    classicops=string.join(newops,'+')
    return classicops
Exemplo n.º 37
0
def convert_PEAT_to_classic(operations):
    operations = get_single_operations(operations)
    newops = []
    import string, Protool
    PI = Protool.structure()
    for operation in operations:
        resid = get_resid_from_mut(operation)
        old = PI.three_to_one[get_oldrestyp_from_mut(operation)]
        new = PI.three_to_one[get_newrestyp_from_mut(operation)]
        resnum = get_resnum_from_mut(operation)
        resnum = string.lstrip(resnum, '0')
        classic = '%s%s%s' % (old, resnum.strip(), new)
        newops.append(classic)

    classicops = string.join(newops, '+')
    return classicops
Exemplo n.º 38
0
    def __init__(self, pdbfiles):
        """Calculate a score for sequence-local contacts"""
        import Protool

        self.X = Protool.structure()

        for pdbfile in pdbfiles:
            xs = []
            ys = []
            labels = []
            count = 0
            PI = self.get_PDB(pdbfile)
            seq = PI.PirSeq(PI.sequence)
            window = 4 * [None]
            residues = 4 * [None]
            for residue, type in PI.sequence[:3]:
                window.append(type)
                residues.append(residue)
            for residue, type in PI.sequence[3:]:

                window.append(type)
                window = window[1:]
                #
                residues.append(residue)
                residues = residues[1:]
                # print window
                if window[3] in ["ASP", "GLU"]:  # ,'LYS','HIS','ARG']:
                    # print window
                    score = self.score_window(window)
                    print residues[3], window[3], score
                    xs.append(count)
                    labels.append(residues[3] + ":%s" % window[3])
                    ys.append(score)
                    count = count + 1
            #
            # Plot a bar chart
            #
            import pylab

            pylab.bar(xs, ys)
            import numpy

            xs = numpy.array(xs)
            pylab.xticks(xs + 0.5, labels, rotation="vertical", size="x-small")
            pylab.title("dpKa values")
            pylab.show()
        return
Exemplo n.º 39
0
    def get_PDB(self, name):
        """Get a PDB chain given as <PDBID><chainname>"""
        import Protool

        X = Protool.structureIO()
        import os

        #
        # If this is a local file that exists, then we use that
        #
        if os.path.isfile(name):
            X.readpdb(name)
            return X
        else:
            CID = name[-1]
            name = name[:-1]
            pdbfile = os.path.join(PDBdir, name + ".pdb")
            if not os.path.isfile(pdbfile):
                print "Getting %s from the PDB" % (os.path.split(pdbfile)[-1])
                import Protool.PDBServices as PS

                PDB = PS.PDBServices()
                lines = PDB.getPDB(name)
                if len(lines) < 100:
                    import string

                    raise Exception("PDB file not found: %s" % (string.join(lines)))
                X.parsepdb(lines)
                X.writepdb(pdbfile)
            else:
                X.readpdb(pdbfile)
        X.RemoveALT()  # Removes alternative atoms
        X.Remove_All_NonAminoAcids()  # Deletes all ligands and waters
        #
        # Keep only the chain we are interested in
        #
        for residue in X.residues:
            thisCID = X.chainid(residue)
            if CID == "_" and thisCID == "":
                pass
            elif CID != "_" and thisCID == CID:
                pass
            else:
                X.remove_residue(residue)
        X.Update()
        return X
Exemplo n.º 40
0
def check_mutation_syntax(operations, sequence=None):
    """Check the syntax of an operation string and check that the residue is present in the sequence"""
    single = get_single_operations(operations)
    for op in single:
        resid = get_resid_from_mut(op)
        new = get_newrestyp_from_mut(op)
        old = get_oldrestyp_from_mut(op)
        import Protool
        X = Protool.structureIO()
        if not X.aminoacids.has_key(old) or not X.aminoacids.has_key(new):
            raise Exception('New or old residue is not an amino acid: %s' % op)
        if sequence:
            if not [resid, old] in sequence:
                raise Exception(
                    'Original sequence does not contain this residue: %s:%s' %
                    (resid, old))
    return combine_operations(single)
Exemplo n.º 41
0
    def __init__(self, pdbfiles):
        """Calculate a score for sequence-local contacts"""
        import Protool
        self.X = Protool.structure()

        for pdbfile in pdbfiles:
            xs = []
            ys = []
            labels = []
            count = 0
            PI = self.get_PDB(pdbfile)
            seq = PI.PirSeq(PI.sequence)
            window = 4 * [None]
            residues = 4 * [None]
            for residue, type in PI.sequence[:3]:
                window.append(type)
                residues.append(residue)
            for residue, type in PI.sequence[3:]:

                window.append(type)
                window = window[1:]
                #
                residues.append(residue)
                residues = residues[1:]
                #print window
                if window[3] in ['ASP', 'GLU']:  #,'LYS','HIS','ARG']:
                    #print window
                    score = self.score_window(window)
                    print residues[3], window[3], score
                    xs.append(count)
                    labels.append(residues[3] + ':%s' % window[3])
                    ys.append(score)
                    count = count + 1
            #
            # Plot a bar chart
            #
            import pylab
            pylab.bar(xs, ys)
            import numpy
            xs = numpy.array(xs)
            pylab.xticks(xs + 0.5, labels, rotation='vertical', size='x-small')
            pylab.title('dpKa values')
            pylab.show()
        return
Exemplo n.º 42
0
 def get_PDB(self, name):
     """Get a PDB chain given as <PDBID><chainname>"""
     import Protool
     X = Protool.structureIO()
     import os
     #
     # If this is a local file that exists, then we use that
     #
     if os.path.isfile(name):
         X.readpdb(name)
         return X
     else:
         CID = name[-1]
         name = name[:-1]
         pdbfile = os.path.join(PDBdir, name + '.pdb')
         if not os.path.isfile(pdbfile):
             print 'Getting %s from the PDB' % (os.path.split(pdbfile)[-1])
             import Protool.PDBServices as PS
             PDB = PS.PDBServices()
             lines = PDB.getPDB(name)
             if len(lines) < 100:
                 import string
                 raise Exception('PDB file not found: %s' %
                                 (string.join(lines)))
             X.parsepdb(lines)
             X.writepdb(pdbfile)
         else:
             X.readpdb(pdbfile)
     X.RemoveALT()  # Removes alternative atoms
     X.Remove_All_NonAminoAcids()  # Deletes all ligands and waters
     #
     # Keep only the chain we are interested in
     #
     for residue in X.residues:
         thisCID = X.chainid(residue)
         if CID == '_' and thisCID == '':
             pass
         elif CID != '_' and thisCID == CID:
             pass
         else:
             X.remove_residue(residue)
     X.Update()
     return X
Exemplo n.º 43
0
def desolvation():
    """Find correlation between desolvation and acc"""
    import os
    dirs=os.listdir('data')
    xs=[]
    ys=[]
    for dir in dirs:
        print 'Processing %s' %dir
        #
        # find the PDB file
        #
        realdir=os.path.join(os.getcwd(),'data',dir)
        files=os.listdir(realdir)
        for file in files:
            realfile=os.path.join(realdir,file)
            if file[-4:]=='.pdb':
                import pKa.pKaTool.pKaIO
                X=pKa.pKaTool.pKaIO.pKaIO(realfile)
                X.assess_status()
                if X.calculation_completed==1:
                    #
                    # Hurra, the calc is complete. Load the desolvation energies
                    #
                    PBEdesolv=X.read_desolv()
                    #
                    # Now calculate the desolvation energies with Protool
                    #
                    P=Protool.structureIO()
                    P.readpdb(realfile)
                    P.get_titratable_groups()
                    P.calculate_desolvation()
                    #
                    #
                    x=[]
                    y=[]
                    for residue in PBEdesolv.keys():
                        if P.desolv.has_key(residue):
                            x.append(P.desolv[residue])
                            y.append(PBEdesolv[residue])
                    xs.append(x)
                    ys.append(y)
    plotit(xs,ys,'Desolvation',dirs)
    return
Exemplo n.º 44
0
def readpdb(structure,CID):
    """Get a PDBID from the PDB website and read it into Protool"""
    print 'Getting PDBID:chain %s:%s from the PDB website' %(structure,CID)
    PDBID=structure
    pdblines=PDB.getPDB(PDBID)
    print 'Reading the PDB into Protool'
    import Protool
    X=Protool.structureIO()
    X.parsepdb(pdblines)
    # 
    # Delete all residues except the ones in the chain we need
    #
    chains=X.chains.keys()
    for chain in chains:
        if chain!=CID:
            print 'Deleting chain',chain
            for res in X.chains[chain]:
                X.Delete_residue(res,update=False)
    X.Update()
    return X
Exemplo n.º 45
0
def readpdb(structure, CID):
    """Get a PDBID from the PDB website and read it into Protool"""
    print 'Getting PDBID:chain %s:%s from the PDB website' % (structure, CID)
    PDBID = structure
    pdblines = PDB.getPDB(PDBID)
    print 'Reading the PDB into Protool'
    import Protool
    X = Protool.structureIO()
    X.parsepdb(pdblines)
    #
    # Delete all residues except the ones in the chain we need
    #
    chains = X.chains.keys()
    for chain in chains:
        if chain != CID:
            print 'Deleting chain', chain
            for res in X.chains[chain]:
                X.Delete_residue(res, update=False)
    X.Update()
    return X
Exemplo n.º 46
0
    def __init__(self, PDB, csvfile, exp_pKa_file, options):
        """Load the PDB file and load the experimental data"""
        self.options = options
        import Protool

        self.PI = Protool.structureIO()
        self.PI.readpdb(PDB)
        self.TGs = self.PI.get_titratable_groups()
        #
        # Read the experimental data
        #
        stab_data = self.read_stability(csvfile)
        #
        # Read the pKa values
        #
        pKa_values = self.read_pKa_values(exp_pKa_file)
        #
        # Should we test the predictions?
        #
        if options.test:
            # self.test_charge()
            self.test_pHstab(pKa_values, stab_data)
        elif options.plotdata:
            self.plot_all_curves(stab_data)
            return
        #
        # Do the fitting
        #
        if options.singlefits:
            pKa_values = self.singlefits(stab_data, pKa_values)
            # print 'Now fitting all unfolded pKa values'
            # print
            # self.fit_pKa_values(stab_data,pKa_values)
        elif options.doublemuts:
            self.doublemuts(stab_data, pKa_values)
        else:
            #
            # Just fit the full pH-stability profile
            #
            self.fit_pKa_values(stab_data, pKa_values)
        return
Exemplo n.º 47
0
 def __init__(self, PDB, csvfile, exp_pKa_file, options):
     """Load the PDB file and load the experimental data"""
     self.options = options
     import Protool
     self.PI = Protool.structureIO()
     self.PI.readpdb(PDB)
     self.TGs = self.PI.get_titratable_groups()
     #
     # Read the experimental data
     #
     stab_data = self.read_stability(csvfile)
     #
     # Read the pKa values
     #
     pKa_values = self.read_pKa_values(exp_pKa_file)
     #
     # Should we test the predictions?
     #
     if options.test:
         #self.test_charge()
         self.test_pHstab(pKa_values, stab_data)
     elif options.plotdata:
         self.plot_all_curves(stab_data)
         return
     #
     # Do the fitting
     #
     if options.singlefits:
         pKa_values = self.singlefits(stab_data, pKa_values)
         #print 'Now fitting all unfolded pKa values'
         #print
         #self.fit_pKa_values(stab_data,pKa_values)
     elif options.doublemuts:
         self.doublemuts(stab_data, pKa_values)
     else:
         #
         # Just fit the full pH-stability profile
         #
         self.fit_pKa_values(stab_data, pKa_values)
     return
Exemplo n.º 48
0
    def setSequencesfromMutationCodes(self,
                                      DB=None,
                                      callback=None,
                                      selected=None):
        """Set the aa sequence using wt ref aa and mutation code
           Assumes mutation code is consistent with ref aa seq"""

        if DB == None:
            return
        proteins = DB.getRecs()
        refprot = DB.meta.refprotein
        refseq = DB[refprot].aaseq
        refaa = self.AAList2String(refseq)
        refpdb = DB[refprot].Structure
        #Create protool oinstance for ref pdb
        import Protool
        Xref = Protool.structureIO()
        Xref.parsepdb(refpdb)
        for protein in selected:
            rec = DB.get(protein)
            if rec.hasStructure() == 'available':
                continue
            print 'Protein:', protein
            #if no sequence try create one from mutation code
            if rec.aaseq == None and rec.Mutations != None:
                print 'no sequence, using mutation code and ref protein seq'
                import PEATSA.Core as Core
                print 'Record has mutation code %s' % rec.Mutations
                mutationSet = Core.Data.MutationSet(rec.Mutations)
                Xref.Remove_All_NonAminoAcids()
                refaa = Core.Data.GetChainSequences(Xref)['A']
                #print refaa
                mutseq = mutationSet.applyToSequence(refaa,
                                                     id='A',
                                                     offset=None,
                                                     pdb=Xref)
                rec.aaseq = self.string2AAseq(mutseq)

        return
Exemplo n.º 49
0
def CleanWHATIF(inputFile,
                outputFile,
                removeWater=True,
                removeLigand=True,
                removeAltLoc=True,
                addHydrogens=True,
                correct=True):
    '''Cleans a PDB using WHAT-IF		

	Errors: 
		Raises an exception if the inputFile is not a valid PDB file.'''

    import pKarun.WI_tools, Protool

    #First try to load the pdb using protool.
    #If its not valid
    try:
        pdb = Protool.structureIO()
        pdb.readpdb(inputFile)
    except Exception, data:
        raise Exceptions.FileFormatError, 'Format of specified PDB file %s not valid.\nUnderlying error - %s' % (
            inputFile, data)
Exemplo n.º 50
0
def Protool2pir(sequence):
    """ Reformats a protool style sequence to a regular one-letter sequence"""
    import Protool
    X = Protool.structureIO()
    seq = ''
    #
    # Get rid of final stop codon
    #
    if sequence[-1][1] == '***':
        sequence = sequence[:-1]
    ignored = {}
    for aa in sequence:
        if aa[1]:
            #
            # Ignore water
            #
            if not X.three_to_one.has_key(aa[1]):
                ignored[aa[1]] = 1
            else:
                seq = seq + X.three_to_one[aa[1]]
        else:
            seq = seq + '-'
    return seq, ignored
Exemplo n.º 51
0
 def pdb2pka_sugelm(self):
     """Explore all possible mutations and calculate a phimap for each using pdb2pka (APBS)"""
     import Protool
     P = Protool.structureIO()
     P.readpdb(self.pdbfile)
     P.RemoveALT()
     #import Protool.mutate
     #MUT=Protool.mutate.Mutate(P)
     #
     # Construct arrays
     #
     import pKD_dict
     self.data = pKD_dict.pKD_dict()
     self.atom_data = pKD_dict.pKD_dict()
     #
     # Create dir for mutant PDB files
     #
     import os
     mutdir = os.path.join(self.topdir, self.pdbfile + '.pdbs')
     if not os.path.isdir(mutdir):
         os.mkdir(mutdir)
     #
     # Loop over all residues
     #
     residues = P.residues.keys()
     residues.sort()
     for residue in residues:
         orgres = P.resname(residue)
         print 'Calculating for %s %s' % (residue, P.resname(residue))
         #
         # If neutral mutate to Asp, Glu, Lys, Arg, His
         #
         targets = []
         for res in ['ARG', 'LYS', 'HIS', 'ASP', 'GLU']:
             if P.resname(residue) != res:
                 targets.append(res)
         #if orgres=='GLU':
         #    targets.append('GLN')
         #elif orgres=='ASP':
         #    targets.append('ASN')
         #elif orgres=='HIS':
         #    targets.append('PHE')
         #elif orgres=='ARG' or P.resname(residue)=='LYS':
         #    targets.append('MET')
         #
         # Target identified. Now model each
         #
         for target in targets:
             import pKD_tools
             resid = pKD_tools.get_resid_from_res(residue)
             orgres = P.resname(residue)
             filename = os.path.join(
                 mutdir, '%s:%s:%s.pdb' % (residue, orgres, target))
             mutation = '%s:%s:%s' % (residue, orgres, target)
             if not os.path.isfile(filename):
                 import Design_pKa_help
                 Design_pKa_help.make_mutation(self.pdbfile, mutation)
             NP = Protool.structureIO()
             NP.readpdb(filename)
             NP.writepdb(filename, TER=None)
             #
             # Calculate the interaction energies
             #
             protein, routines, forcefield, apbs_setup, lig_titgrps = pdb2pka.pre_init(
                 pdbfilename=filename, ff='parse', ligand=None, verbose=1)
             mypkaRoutines = pdb2pka.pKaRoutines(protein, routines,
                                                 forcefield, apbs_setup)
             #
             # Find our group
             #
             sp = residue.split(':')
             chainid = sp[0]
             resnum = int(sp[1])
             mypkaRoutines.findTitratableGroups()
             this_pKa = None
             for pKa in mypkaRoutines.pKas:
                 print pKa.residue.resSeq, resnum
                 print pKa.residue.chainID, chainid
                 print pKa.residue.name, target
                 print pKa.pKaGroup.name, target
                 print '--------------'
                 print 'ChainID', pKa.residue.chainID
                 if pKa.residue.resSeq == resnum and pKa.residue.chainID == chainid and pKa.residue.name == target and pKa.pKaGroup.name == target:
                     #print 'Found group',pKa.residue.resSeq,pKa.pKaGroup.name
                     this_pKa = pKa
                     break
             if not this_pKa:
                 raise Exception, 'Could not find inserted titratable group'
             mypkaRoutines.get_interaction_energies_setup(this_pKa,
                                                          mode='pKD')
             matrix = mypkaRoutines.matrix
             #
             # Dig the interaction energies out of the pdb2pka array
             #
             for titration1 in matrix[this_pKa].keys():
                 for state1 in matrix[this_pKa][titration1].keys():
                     grp_sub = matrix[this_pKa][titration1][state1]
                     if mypkaRoutines.is_charged(this_pKa, titration1,
                                                 state1):
                         for pKa2 in grp_sub.keys():
                             import string
                             chainID2 = pKa.residue.chainID
                             resid2 = '%s:%s' % (
                                 chainID2,
                                 string.zfill(pKa2.residue.resSeq, 4))
                             for titration2 in grp_sub[pKa2].keys():
                                 for state2 in grp_sub[pKa2][
                                         titration2].keys():
                                     if mypkaRoutines.is_charged(
                                             pKa2, titration2, state2):
                                         #
                                         # Both states are charged, so now we can pull the
                                         # interaction energies out
                                         #
                                         if not self.data.has_key(mutation):
                                             self.data[mutation] = {}
                                         self.data[mutation][
                                             resid2] = grp_sub[pKa2][
                                                 titration2][state2]
                                         #
                                         # Get the potentials at all atoms too
                                         #
                                         all_pots = mypkaRoutines.all_potentials[
                                             this_pKa][titration1][state1]
                                         sub_all_pots = all_pots[pKa2][
                                             titration2][state2]
                                         for atom in sub_all_pots.keys():
                                             resid = mutation
                                             import pKD_tools
                                             resid2 = pKD_tools.get_resid_from_res(
                                                 atom)
                                             atomname = atom.split(':')[
                                                 -1]  #atom.name
                                             if atomname[
                                                     0] == 'H' or atomname in [
                                                         'N', 'C', 'O'
                                                     ]:
                                                 continue  # Skip all H atoms and all non-CA backbone atoms to save memory
                                             if not self.atom_data.has_key(
                                                     resid):
                                                 self.atom_data[resid] = {}
                                             if not self.atom_data[
                                                     resid].has_key(resid2):
                                                 self.atom_data[resid][
                                                     resid2] = {}
                                             self.atom_data[resid][resid2][
                                                 atomname] = abs(
                                                     sub_all_pots[atom])
     return self.data, self.atom_data
Exemplo n.º 52
0
def main():
    #
    # Parse the arguments
    #
    import sys, string
    defaults = get_defaults()
    #
    args = string.join(sys.argv[1:])
    args = string.split(args, '-')
    for arg in args:
        split = string.split(string.strip(arg))
        if split == []:
            continue
        parm_name = split[0]
        if not defaults.has_key(parm_name):
            raise 'Unknown parameter: ', parm_name
        #
        # Deal with T/F
        #
        if len(split) == 1:
            if defaults[parm_name][1] == 'T/F':
                if defaults[parm_name][0]:
                    defaults[parm_name][0] = None
                else:
                    defaults[parm_name][0] = 1
        #
        # Deal with all the other cases
        #
        elif len(split) == 2:
            if defaults[parm_name][1] == 'number':
                defaults[parm_name][0] = string.atof(split[1])
            else:
                defaults[parm_name][0] = split[1]
        else:
            raise 'Incorrect usage'
    #
    # Reformat
    #
    params = {}
    for key in defaults.keys():
        params[key] = defaults[key][0]
    #
    # Load the file and design the primer
    #
    if not params['seq']:
        usage()
    seq_file = params['seq']
    new_AA = params['mutation'][-1]
    AA_number = int(params['mutation'][1:-1])

    S = DNA_sequence.sequence()
    DNA_seq = S.readpir(seq_file)
    Tm_desired = params['Tm']
    find_restriction_site = 1
    if params['no_restriction_site']:
        find_restriction_site = None
    #
    # Do it!
    #
    import Protool
    X = Protool.structureIO()
    new_AA = X.threetoone[new_AA]
    #
    # Call the function for designing primers
    #
    new_enzymes, primers_results_dict, enzymes_that_already_cut, primer_starting_position, comb_on_Tm = exhaustive_research(
        DNA_seq,
        AA_number,
        new_AA,
        Tm_desired,
        find_restriction_site,
        enzyme_list=None)
    megaprimer_dict = megaprimer(DNA_seq, Tm_desired=65)
    return
Exemplo n.º 53
0
        #
        apbs_inputfile = igen.printInput()
        #
        # Run APBS
        #
        import apbs
        self.APBS = apbs.runAPBS()
        self.potentials = self.APBS.runAPBS(protein, apbs_inputfile)
        self.APBS.cleanup()
        self.APBS = None
        return


if __name__ == '__main__':
    import Protool
    P = Protool.structureIO()
    P.readpdb('lysmgm2_apo.pdb')
    # Build hydrogens
    import Protool.hydrogens
    H = Protool.hydrogens.Hydrogens(P)
    H.build_all_HNs()
    #
    # Assign charges
    #
    import Protool.assign_parameters
    PQR = Protool.assign_parameters.assign_parameters(P)
    PQR.clear_all_charges_and_radii()
    PQR.set_all_radii()
    #
    # Try loading a ligand
    #
Exemplo n.º 54
0
def Model_Mutations(pdbfile,
                    mol2files,
                    mutations,
                    max_overlap=0.5,
                    max_totalbump=1.0,
                    return_score=False,
                    store_mutation_operations=False):
    """Model a number of mutations in a pdbfile when one or more ligands are present"""
    #
    # Check for stupidity
    #
    if max_overlap > max_totalbump:
        max_totalbump = max_overlap
        print 'Adjusted total bump cutoff to %5.2f' % max_totalbump
    #
    # Read PDB file
    #
    import Protool
    P = Protool.structureIO()
    P.readpdb(pdbfile)
    P.remove_all_hydrogens()
    #
    # Read mol2 file
    #
    L = Protool.ligand(P)
    for mol2file in mol2files:
        print "Added %s with tag 'LIGAND'" % mol2file
        L.readmol2(mol2file, tag='LIGAND')
    #
    # Get the pdb lines
    #
    pdblines = P.writepdb('junk.pdb', nowrite=True)
    #
    # Pass the lines to FFF
    #
    import FFF.FFFcontrol
    myFFF = FFF.FFFcontrol.FFF()
    myFFF.parse_lines(pdblines)
    #myFFF.soup_stat()
    Model = FFF.FFFcontrol.model_class(myFFF, Rotamerlib, FFFaadef_dir)
    #
    # Store the wild type PDB file
    #
    if store_mutation_operations:
        wt_lines = myFFF.make_pdblines('PDB')
    #
    import pKa.pKD_tools as pKD_tools
    total_bump = 0.0
    for mutation in mutations:
        resid = pKD_tools.get_resid_from_mut(mutation)
        chainid = resid.split(':')[0]
        resid = resid.split(':')[1]
        #
        # Get rid of the leading zeros
        #
        done = False
        while not done:
            if resid[0] == '0' and len(resid) > 1:
                resid = resid[1:]
            else:
                done = True
        #
        newres = pKD_tools.get_newrestyp_from_mut(mutation)
        oldres = pKD_tools.get_oldrestyp_from_mut(mutation)
        opttype = 3  # Rotamer library
        energies = Model.Mutate(chainid, resid, newres, opttype, max_overlap)
        bump_score = energies[0]
        Sum = energies[1]
        Coulomb = energies[2]
        #
        total_bump = total_bump + bump_score
        print 'Bump score: %5.2f, total bump: %5.2f' % (bump_score, total_bump)
        if bump_score > max_overlap or total_bump > max_totalbump:
            print 'Cannot model this set of mutations - too many bumps'
            if return_score:
                return False, total_bump
            else:
                return False
        print 'Bump score for %s: %5.3f' % (mutation, bump_score)
    print 'Total bump score for all mutations: %5.3f' % (total_bump)

    class FFF_fix:
        def __init__(self, FFF):
            self.PI = FFF
            return

    #
    # Create the instance
    #
    FFF_instance = FFF_fix(myFFF)
    #
    # Keep track of the changes that were made to the PDB file
    #
    if store_mutation_operations:
        mut_lines = FFF_instance.PI.make_pdblines('PDB')
        import Protool
        WT = Protool.structureIO()
        WT.parsepdb(wt_lines)
        wt_atoms = sorted(WT.atoms.keys())
        #
        MUT = Protool.structureIO()
        MUT.parsepdb(mut_lines)
        #
        mut_atoms = sorted(MUT.atoms.keys())
        wt_count = 0
        mutcount = 0

        def coord_diff(atom1, atom2):
            diff = 0.0
            for coord in ['X', 'Y', 'Z']:
                diff = diff + abs(atom1[coord] - atom2[coord])
            return diff

        operations = []
        for atom in wt_atoms:
            if not atom in mut_atoms:
                operations.append(['delete', atom, WT.atoms[atom]])
            elif coord_diff(WT.atoms[atom], MUT.atoms[atom]) > 0.1:
                operations.append(['delete', atom, WT.atoms[atom]])
                operations.append(['add', atom, MUT.atoms[atom]])
            else:
                pass
        for atom in mut_atoms:
            if not atom in wt_atoms:
                operations.append(['add', atom, MUT.atoms[atom]])
        #
        # Store these in FFF_fix
        #
        FFF_instance.mutate_operations = operations[:]
    #
    # Return the info
    #
    if (return_score):
        return FFF_instance, total_bump
    return FFF_instance
Exemplo n.º 55
0
def test_function(options):
    """Model a mutation, or test the function"""
    if not options.test_modelling:
        import os
        mutations = options.mutations
        pdbfile = options.pdbfile
        if not os.path.isfile(pdbfile):
            raise Exception('PDB file not found: %s' % pdbfile)
        MUT, bs = Model_Mutations(
            pdbfile, [],
            mutations,
            return_score=True,
            max_overlap=options.bump,
            max_totalbump=options.totalbump,
            store_mutation_operations=options.store_operations)
        if MUT:
            MUT.PI.writepdb(options.outfile)
        else:
            print 'Cannot model mutations'
        return
    else:
        #
        # Test the modelling of PDB files by FFF and compare it to Protool
        #
        import Protool
        X = Protool.structureIO()
        X.readpdb(options.pdbfile)
        res = X.residues.keys()
        res.sort()
        aas = X.trueaminoacids.keys()
        x = []
        y = []
        import random
        bettermodel = []
        while len(x) < 2000:
            resi = random.choice(res)
            aa = random.choice(aas)
            mutation = '%s:%s:%s' % (resi, X.resname(resi), aa)
            print 'Calculating for %s' % mutation
            oldscore = None
            newscore = None
            for function in ['Model_Mutations', 'Model_Mutations_old']:
                import os
                resultfile = os.path.join(os.getcwd(),
                                          'scores/' + mutation + str(function))
                if not os.path.isfile(resultfile):
                    M, score = eval(function)(options.pdbfile, [], [mutation],
                                              return_score=True)
                    fd = open(resultfile, 'w')
                    import pickle
                    A = score
                    pickle.dump(A, fd)
                    fd.close()
                else:
                    import pickle
                    fd = open(resultfile)
                    score = pickle.load(fd)
                    fd.close()
                #
                # Assign scores to the right variables
                #
                if resultfile[-4:] == '_old':
                    oldscore = score
                else:
                    newscore = score
            if oldscore > 10:
                bettermodel.append(newscore)
                continue
            x.append(oldscore)
            y.append(newscore)

        print 'In %d cases FFF was able to construct a model where Protool was not' % len(
            bettermodel)
        print bettermodel
        import pylab
        pylab.scatter(x, y)
        pylab.show()
    return
Exemplo n.º 56
0
    if options.partner1 is None:
        print 'Stability results for the first partner must be provided'
        run = False

    if options.partner2 is None:
        print 'Stability results for the second partner must be provided'
        run = False

    if not run:

        sys.exit(1)

    complex = Core.Matrix.matrixFromCSVFile(options.complex)
    partner1 = Core.Matrix.matrixFromCSVFile(options.partner1)
    partner2 = Core.Matrix.matrixFromCSVFile(options.partner2)
    pdb = Protool.structureIO()
    pdb.readpdb(options.protein)

    combined = zip(complex.mutations, complex.total)
    print 'Data found for %d mutants of the complex' % len(combined)

    interactionEnergies = []
    for element in combined:
        set = Core.Data.MutationSet(code=element[0])
        code = "+".join(set.reducedMutationCodes(pdb))

        values = []

        if MutationsInPartner(code, partner1):
            data = partner1.dataForMutation(code)
            values.append(data[-1])
Exemplo n.º 57
0
def main(options, args):
    """Extract mutations from a multiple sequence alignment"""
    import PEATDB.sequence_alignment as SA
    if not options.fasta:
        alignment = SA.read_clustal_aln_file(args[0])
    else:
        alignment = SA.read_fasta_aln_file(args[0])
    print sorted(alignment.keys())

    HEWL_seq = alignment[options.wt]

    fd = open('mutations.txt', 'w')
    fd2 = open('frequencies.csv', 'w')

    aas = convert.keys()
    aas.sort()
    import string
    fd2.write('WT Residue number, %s\n' % (string.join(aas, ',')))
    #
    real_pos = 0
    lines = []
    PDB_mutations = {}
    #
    for position in range(0, len(HEWL_seq)):
        res_observed = {}
        if HEWL_seq[position] == '-':
            continue
        real_pos = real_pos + 1
        #print 'Now looking at position',real_pos
        for seq in alignment.keys():
            res_pos = alignment[seq][position]
            if not res_observed.has_key(res_pos):
                res_observed[res_pos] = 0
            res_observed[res_pos] = res_observed[res_pos] + 1
        #
        # Calculate frequencies of observation
        #
        total = sum(res_observed.values())
        text = '%3d' % real_pos
        #print res_observed.keys()
        for aa in aas:
            if res_observed.has_key(aa):
                text = text + ',%5.1f' % (float(res_observed[aa]) / total *
                                          100.0)
            else:
                text = text + ',%5.1f' % (0)
        fd2.write(text + '\n')
        #
        # -----
        #
        lines += ['%3d   %d\n' % (real_pos, len(res_observed.keys()))]
        for mut in res_observed.keys():
            if mut == '-':
                continue
            if mut == HEWL_seq[position]:
                continue
            #
            org_res = HEWL_seq[position]
            new_res = mut
            import string
            if org_res == 'X' or new_res == 'X':
                continue
            #
            # Within the PDB file?
            #
            if real_pos < options.start_aa or real_pos > options.end_aa:
                pass
            else:
                PDB_residue = '%s:%s' % (options.CID,
                                         string.zfill(
                                             real_pos + options.offset -
                                             options.noffset, 4))
                if not PDB_mutations.has_key(PDB_residue):
                    PDB_mutations[PDB_residue] = []
                PDB_mutations[PDB_residue].append(convert[new_res])
                muttext = '%s:%s:%s:%s' % (
                    options.CID,
                    string.zfill(real_pos + options.offset - options.noffset,
                                 4), convert[org_res], convert[new_res])
                fd.write('%s,%s\n' % (muttext, muttext))
                #print muttext
    fd.close()
    fd2.close()
    #
    # Read PDB file?
    #
    if options.pdbfile:
        import Protool
        PI = Protool.structureIO()
        PI.readpdb(options.pdbfile)
    #
    # Plot the figure?
    #
    if options.plotfigure:
        xs = []
        ys = []
        zs = []
        for residue in sorted(PDB_mutations.keys()):
            resnum = int(residue.split(':')[1])
            xs.append(resnum)
            ys.append(len(PDB_mutations[residue]))
            zs.append(PI.dist(options.atom, residue + ':CA'))
        import pylab
        pylab.plot(zs, ys, 'ro')
        pylab.xlabel('Distance from %s' % (options.atom))
        pylab.ylabel('Number of mutations')
        pylab.show()
    return
Exemplo n.º 58
0
def main(options, args):
    """Start the calculations"""
    import os, shutil
    top = os.getcwd()
    #
    # Read the filelist
    #
    if args[0] != 'all':
        fd = open(args[0])
        files = fd.readlines()
        fd.close()
    else:
        files = os.listdir(top)
    #
    # -------------------------------------
    #
    # Loop over all files and do the task
    #
    for filename in sorted(files):
        #
        # clean filename
        #
        if filename[0] == '#':
            continue
        if filename[-4:] != '.pdb':
            continue
        import string
        filename = string.strip(filename)
        filename = filename.split()[0]
        if filename[0] == '#':
            continue
        #
        # If we have a file then create a dir
        #
        if options.filestructure == 'files':
            if filename[-4:] == '.pdb':
                dirname = filename[:-4]
            else:
                dirname = filename + '_dir'
            if not os.path.isdir(dirname):
                os.mkdir(dirname)
            #
            # copy the pdb file to the dir
            #
            shutil.copy(filename, dirname)
        else:
            dirname = filename
        #
        # Make the dirname absolute
        #
        dirname = os.path.join(top, dirname)
        #
        # Change dir to the calc dir
        #
        os.chdir(dirname)
        #
        # Delete TOPOLOGY.H and DELRAD.DAT + DELCRG.DAT if they exist
        #
        import shutil
        copyfiles = ['DELRAD.DAT', 'DELCRG.DAT', 'TOPOLOGY.H']
        for copyfile in copyfiles:
            if os.path.lexists(os.path.join(dirname, copyfile)):
                os.unlink(os.path.join(dirname, copyfile))
        #
        # Find the pdb file
        #
        pdbfile = False
        searchnames = [filename, filename + '.pdb']
        for sname in searchnames:
            rname = os.path.join(dirname, sname)
            if os.path.isfile(rname):
                pdbfile = rname
                break
        if not pdbfile:
            raise Exception('Could not find PDB file in %s' % os.getcwd())
        #
        # EM + MD?
        #
        if options.EM:
            #corall(pdbfile)
            class options:
                def __init__(otherself):
                    otherself.type = 'pKa'
                    otherself.pdbfile = pdbfile
                    otherself.clean = False
                    return

            Goptions = options()
            #
            import GromacsEM
            pdblines = GromacsEM.EMone(Goptions)
            import Protool
            PI = Protool.structureIO()
            PI.parsepdb(pdblines)
            PI.Remove_All_NonAminoAcids()  # Make sure all waters are removed
            pdbfile = pdbfile + 'test'
            PI.writepdb(pdbfile)
            corall(pdbfile)  # Do final corall
            stop

        #
        # Should we do a corall?
        #
        if options.corall:
            corall(pdbfile)
        #
        # Copy the DEL* files and TOPOLOGY.H
        #
        for copyfile in copyfiles:
            shutil.copy(os.path.join(top, copyfile),
                        os.path.join(dirname, copyfile))
        #
        # Instantiate pKarun
        #
        PM = pKarun_base.pKamisc()
        params = PM.parse_parameterlist(['-dbcrit 1000'], skip2first=False)
        print params
        X = pKarun_base.pKarun(os.getcwd(), pdbfile, params)
        #
        # Carry out the tasks
        #
        if options.tasks == 'titration':
            print 'Runing solvepka in ', os.getcwd()
            X.solvepka()
        elif options.tasks == 'desolv':
            X.desolv()
        elif options.tasks == 'backgr':
            X.backgr()
        elif options.tasks == 'matrix':
            X.matrix()
        elif options.tasks == 'all':
            print 'Running all'
            print options.tasks
            X.all()
        #
        # Change dir back
        #
        os.chdir(top)
        print 'Back in ', os.getcwd()
        import sys
        sys.stdout.flush()