Exemplo n.º 1
0
def RMSD(CompType='traj'):
    oshelf = shelve.open(OutShelf)
    if CompType == 'traj':
        print '\nComputing overall RMSD distribution'
        rmsdhist = calc.QuickRMSD()
        oshelf['rmsd'] = rmsdhist

    if CompType == 'topclust':
        print '\nComputing RMSD from top cluster'
        pNative = cg.ProteinNCOS(NativePdb)
        pClust = cg.ProteinNCOS(oshelf['clustpdb'])
        rmsd = pClust.QuickRMSD(pNative)
        oshelf['rmsd_topclust'] = rmsd
    oshelf.close()
    return
Exemplo n.º 2
0
def PhiPsiErr(ErrType='traj'):
    print 'Calculating Ramachandran plot errors with native struct'
    # get native phi, psi
    pNative = cg.ProteinNCOS(NativePdb)
    Phi_Native, Psi_Native = pNative.GetPhiPsi(RamaType='Generic')
    Phi_Native, Psi_Native = cg.TrimDihedrals(Phi_Native,
                                              Psi_Native,
                                              RamaType='Generic',
                                              ResNums=range(pNative.NRes))
    Err = np.zeros([pNative.NRes - 1], float)

    # errors from top cluster
    if ErrType == 'topclust':
        ClustPdb = FMT['CLUSTPDB'] % (OutPrefix, TempSet)
        if not os.path.isfile(ClustPdb):
            raise IOError('Top cluster for %s missing' % Prefix)
        p = cg.ProteinNCOS(ClustPdb, Model=1)
        PhiErr, PsiErr, Err = pNative.GetPhiPsiDiff(p, RamaType='Generic')
        # remove undefined dihedrals and recompute Err
        PhiErr = PhiErr[1:]
        PsiErr = PsiErr[:-1]
        Err = np.sqrt(PhiErr**2. + PsiErr**2.)

    # errors from entire traj
    if ErrType == 'traj':
        calc.RamaChandran()
        RamaPickle = FMT['RAMA'] % (OutPrefix, TempSet)
        with open(RamaPickle, 'r') as of:
            data = pickle.load(of)
        Phi, Psi, hist = data['Generic']
        for i in range(len(Phi_Native)):
            # per frame phi-psi errors
            this_Phidiff = sim.geom.NearestAngle(Phi_Native[i] - Phi[:, i],
                                                 0.0)
            this_Psidiff = sim.geom.NearestAngle(Psi_Native[i] - Psi[:, i],
                                                 0.0)
            Err[i] = np.mean(
                np.sqrt(this_Phidiff**2 +
                        this_Psidiff**2))  # need to do a np.mean over frames

    oshelf = shelve.open(OutShelf)
    oshelf['ramaprob'] = RamaPickle
    oshelf['ramaerr'] = (Phi_Native, Psi_Native, Err)
    oshelf.close()
    return
Exemplo n.º 3
0
def RamaChandran():
    # ramachandran plots from native
    print '\nGenerating Ramachandran plots from native'
    p = lib.ProteinNCOS(NativePdb)
    Phi, Psi = p.GetPhiPsi()
    picklename = OutPrefix + '_native.rama.pickle'
    with open(picklename, 'w') as of:
        pickle.dump((Phi, Psi), of)
    # ramachandran plots from entire traj
    print '\nRamachandran plots at Temp = %3.2fK' % TempSet
    calc.RamaChandran()
Exemplo n.º 4
0
def PhiPsiErr(ErrType='traj'):
    print '\nCalculating Ramachandran plot errors with native struct'
    # get native phi, psi
    pNative = cg.ProteinNCOS(NativePdb)
    Phi_Native, Psi_Native = pNative.GetPhiPsi()
    Err = np.zeros(len(Phi_Native), float)

    # errors from top cluster
    if ErrType == 'topclust':
        ClustPdb = FMT['CLUSTPDB'] % (OutPrefix, TempSet)
        if not os.path.isfile(ClustPdb):
            raise IOError('Top cluster for %s missing' % Prefix)
        p = cg.ProteinNCOS(ClustPdb, Model=1)
        PhiErr, PsiErr, Err = pNative.GetPhiPsiDiff(p)

    # errors from entire traj
    if ErrType == 'traj':
        calc.RamaChandran()
        RamaPickle = FMT['RAMA'] % (OutPrefix, TempSet)
        with open(RamaPickle, 'r') as of:
            data = pickle.load(of)
        Phi, Psi, hist = data
        for i in range(len(Phi_Native)):
            # per frame phi-psi errors
            this_Phidiff = sim.geom.NearestAngle(Phi_Native[i] - Phi[:, i],
                                                 0.0)
            this_Psidiff = sim.geom.NearestAngle(Psi_Native[i] - Psi[:, i],
                                                 0.0)
            Err[i] = np.mean(
                np.sqrt(this_Phidiff**2 +
                        this_Psidiff**2))  # need to do a np.mean over frames

    oshelf = shelve.open(OutShelf)
    with open(RamaPickle, 'w') as of:
        data = pickle.load(RamaPickle)
    oshelf['ramaprob'] = data
    oshelf['ramaerr'] = (Phi_Native, Psi_Native, Err)
    oshelf.close()
    return
Exemplo n.º 5
0
def makeRamaPlot(TempAA, TempCG):
    print 'RAMACHANDRAN PLOTS'
    print '------------------'
    global c_AA, c_CG
    # parse AA and CG filenames
    fAA = utils.parseAA(polymer, TempSet = TempAA)
    fCG = utils.parseCG(polymer, TempSet = TempCG)
    TempAA = fAA['Temp']
    TempCG = fCG['Temp']
    # get top cluster ramachandran plots
    AAClustPdb = FMT['CLUSTPDB'] % (AAPrefix, fAA['Temp'])
    if not os.path.isfile(AAClustPdb):
        print 'Error: AA top cluster struct missing. Cannot compute top cluster dihderals'
        Phi_AA = None
        Psi_AA = None
    else:
        pAA = lib.ProteinNCOS(AAClustPdb)
        Phi_AA, Psi_AA = pAA.GetPhiPsi()
        Phi_AA, Psi_AA = lib.TrimDihedrals(Phi_AA, Psi_AA, range(pAA.NRes))
    CGClustPdb = FMT['CLUSTPDB'] % (CGPrefix, fCG['Temp'])
    if not os.path.isfile(CGClustPdb):
        print 'Error: CG top cluster struct missing. Cannot compute top cluster dihderals'
        Phi_CG = None
        Psi_CG = None
    else:
        pCG = lib.ProteinNCOS(CGClustPdb)
        Phi_CG, Psi_CG = pCG.GetPhiPsi()
        Phi_CG, Psi_CG = lib.TrimDihedrals(Phi_CG, Psi_CG, range(pCG.NRes))
    # get whole traj based ramachandran plots
    c_AA.Update(TrajFn = fAA['Traj'], Temp = TempAA)
    c_CG.Update(TrajFn = fCG['Traj'], Temp = TempCG)
    c_AA.RamaChandran()
    c_CG.RamaChandran()
    # plot
    AApickle = FMT['RAMA'] % (AAPrefix, TempAA)
    CGpickle = FMT['RAMA'] % (CGPrefix, TempCG)
    with open(AApickle, 'r') as of: phiaa, psiaa, haa = pickle.load(of)['Generic']
    with open(CGpickle, 'r') as of: phicg, psicg, hcg = pickle.load(of)['Generic']
    pmf_AA = -np.log(haa[1])
    pmf_CG = -np.log(hcg[1])
    fig, axes = plt.subplots(nrows = 1, ncols = 2, figsize = (10,7), facecolor = 'w', edgecolor = 'w')
    ax1 = axes.flat[0]
    ax2 = axes.flat[1]
    X1 = rad2deg(haa[0][0]) ; Y1 = rad2deg(haa[0][1])
    X2 = rad2deg(hcg[0][0]) ; Y2 = rad2deg(hcg[0][1])
    im1 = ax1.imshow(np.transpose(pmf_AA), aspect = 'equal', interpolation = 'none', origin = 'lower',
                     cmap = cm.jet, extent = [X1.min(), X1.max(), Y1.min(), Y1.max()])
    im2 = ax2.imshow(np.transpose(pmf_CG), aspect = 'equal', interpolation = 'none', origin = 'lower',
                     cmap = cm.jet, extent = [X2.min(), X2.max(), Y2.min(), Y2.max()])
    #TODO: scatter the top cluster dihedrals on this plot
    fig.colorbar(im1, ax=axes.ravel().tolist(), label = 'pmf (kT)', orientation = 'vertical')
    ax1.set_title('AA : %3.2f K' % TempAA)
    ax2.set_title('CG : %3.2f K' % TempCG)
    for ax in [ax1, ax2]:
        ax.set_xlabel(r'$\phi$')
        ax.set_ylabel(r'$\psi$')
        ax.set_xlim([-190, 190])
        ax.set_ylim([-190, 190])
        ax.axvline(0, ls = '-', lw = 1, color = 'black')
        ax.axhline(0, ls = '-', lw = 1, color = 'black')
    figname = OutPrefix + '.%3.2f.ramaplot.png' % TempAA
    plt.savefig(figname, bbox_inches = 'tight')
Exemplo n.º 6
0
#!/usr/bin/env python

import os, numpy as np
import matplotlib
import matplotlib.pyplot as plt
import cgprotein as lib

pdbname = '1l2y'
gly_dir = os.path.abspath('../native_struct/mapped_pseudoGLY')
nogly_dir = os.path.abspath('../native_struct/mapped')

p_gly = lib.ProteinNCOS(os.path.join(gly_dir, pdbname + '.pdb'), hasPseudoGLY = True)
phi_gly, psi_gly = p_gly.GetPhiPsi()

p_nogly = lib.ProteinNCOS(os.path.join(nogly_dir, pdbname + '.pdb'))
phi_nogly, psi_nogly = p_nogly.GetPhiPsi()

fig = plt.figure(figsize = (10, 5), facecolor = 'w', edgecolor = 'w')
ax1 = fig.add_subplot(1,2,1)
ax2 = fig.add_subplot(1,2,2)
ax1.scatter(phi_gly * (180./np.pi), psi_gly * (180./np.pi), c = 'red', s = 50)
ax2.scatter(phi_nogly * (180./np.pi), psi_nogly * (180./np.pi), c = 'red', s = 50)
ax1.set_title('peptide %s, pseudo gly' % pdbname)
ax2.set_title('peptide %s' % pdbname)
for ax in [ax1, ax2]:
    ax.set_xlabel(r'$\phi$')
    ax.set_ylabel(r'$\psi$')
    ax.axhline(0.0, ls = '-', lw = 2, color = 'black')
    ax.axvline(0.0, ls = '-', lw = 2, color = 'black')
    ax.set_xlim([-180, 180])
    ax.set_ylim([-180, 180])
Exemplo n.º 7
0
print 'ANALYSING MULTI-PROTEIN FOR %s at %3.2f K' % (Prefix, TempSet)
print '----------------------------------------------------------------'

# set up Compute object
print 'Creating Compute object'
calc = cg.Compute(NativePdb = NativePdb, TrajFn = TrajFn, Temp = TempSet, Prefix = OutPrefix, hasPseudoGLY = hasPseudoGLY)

# cluster the room temp traj
print 'Clustering trajectory'
calc.Cluster()

# top-cluster contact analysis
Trj = pickleTraj(TrajFn)
BoxL = Trj.FrameData['BoxL']
ClustPdb = FMT['CLUSTPDB'] % (calc.Prefix, calc.Temp)
p = cg.ProteinNCOS(ClustPdb, Model = 1)

# top cluster contact map
print 'Calculating contact map for top cluster'
cmap, cdist = p.GetResContacts(BoxL = BoxL)
picklename = FMT['RESCONTACTS'] % (calc.Prefix + '_topclust', calc.Temp)
with open(picklename, 'w') as of: pickle.dump(cmap, of)

# top cluster dihedrals
print 'Calculating dihedral angles for top cluster'
Phi, Psi = p.GetPhiPsi(BoxL = BoxL)
picklename = FMT['RAMA'] % (calc.Prefix + '_topclust', calc.Temp)
with open(picklename, 'w') as of: pickle.dump((Phi, Psi), of)

# traj contact map
print 'Calculating contact map from entire trajectory'
Exemplo n.º 8
0
Traj = {'ala_spc': os.path.abspath('../ala_spc_AA/Lammps/ala_spc.300.00.lammpstrj.gz'),
        'ala15': os.path.abspath('../ala15_AA/Lammps/ala15.299.00.lammpstrj.gz'),
        'leu15': os.path.abspath('../leu15_AA/Lammps/leu15_wham.407.00.lammpstrj.gz'),
        'val15': os.path.abspath('../val15_AA/Lammps/val15_wham.367.00.lammpstrj.gz')
       }

Temp = {'ala_spc': 300.0, 'ala15': 299.00, 'leu15': 407.00, 'val15': 367.00}
NativePdb = {'ala_spc': 'ideal_helix.pdb', 'ala15': 'ideal_helix.pdb', 'leu15': 'ideal_helix.pdb', 'val15': hairpin_pdb}

fig = plt.figure(figsize = (22, 15), facecolor = 'w', edgecolor = 'w')
ind = 1
gs = gridspec.GridSpec(3,4)
for i, fftype in enumerate(fftypes):
    print '-------- %s --------' % fftype
    # get native Ramachandran angles
    pNative = cg.ProteinNCOS(NativePdb[fftype])
    PhiNative, PsiNative = pNative.GetPhiPsi(RamaType = 'Generic')
    PhiNative, PsiNative = cg.TrimDihedrals(PhiNative, PsiNative, ResNums = range(NRes))
    PhiNative *= (180 / np.pi)
    PsiNative *= (180 / np.pi)
    
    # create compute object
    calc = cg.Compute(NativePdb = NativePdb[fftype], TrajFn = Traj[fftype], Temp = Temp[fftype], Prefix = fftype)
    
    # get cluster ramachandran angle probabilities
    calc.RamaChandran()
    RamaPickle = utils.FMT['RAMA'] % (fftype, Temp[fftype])
    with open(RamaPickle, 'r') as of: data = pickle.load(of)['Generic']
    (x,y), ramahist, err = data[-1]
    x *= (180 / np.pi)
    y *= (180 / np.pi)
Exemplo n.º 9
0
def Overlay(NativePdb,
            Pdb,
            OutPrefix=None,
            Label='',
            SinglePlot=False,
            hasPseudoGLY=False):
    global doRotate
    if OutPrefix is None: OutPrefix = 'go'
    # parse BBInds
    p_cg = cgprotein.ProteinNCOS(NativePdb, hasPseudoGLY=hasPseudoGLY)
    BBInds = p_cg.GetBBInds()
    # read pdbs
    pNative = protein.ProteinClass(NativePdb)
    p = protein.ProteinClass(Pdb, Model=1)
    # rotate the native pdb
    if doRotate: pNative = RotateProteinClass(pNative)
    # align with rotated native struct (produces weird results with vmd, so let vmd do its own )
    if not Renderer == 'vmd':
        p, pNative = AlignProtein(p, pNative, BBInds)
    # write to first set of tmp pdb files
    tmpNativePdb = os.path.join(os.getcwd(), '%s_tmpnative.pdb' % OutPrefix)
    tmpPdb = os.path.join(os.getcwd(), '%s_tmp.pdb' % OutPrefix)
    pNative.WritePdb(tmpNativePdb)
    p.WritePdb(tmpPdb)
    # now reverse map these pdbs to generate an approximate carbonyl group
    # so that STRIDE can assign secondary structures
    mapNCOS.ReverseMap(CGPdb=tmpNativePdb,
                       Prefix=tmpNativePdb.split('.pdb')[0],
                       hasPseudoGLY=hasPseudoGLY)
    mapNCOS.ReverseMap(CGPdb=tmpPdb,
                       Prefix=tmpPdb.split('.pdb')[0],
                       hasPseudoGLY=hasPseudoGLY)
    # fill dictionary for renderer script
    d = {
        'TMPNATIVEPDB': tmpNativePdb,
        'TMPPDB': tmpPdb,
    }
    # pymol
    if Renderer == 'pymol':
        d['FILENAME'] = OutPrefix + '.png' if not SinglePlot else OutPrefix + '_tmp0.png'
        tmpPml = OutPrefix + '.pml'
        file(tmpPml, 'w').write(s_pymol % d)
        cmdstr1 = '%s -Qc %s' % (PYMOLEXEC, tmpPml)
        os.system(cmdstr1)
        for x in [tmpNativePdb, tmpPdb, tmpPml]:
            os.remove(x)
    # vmd
    elif Renderer == 'vmd':
        d['FILEPREFIX'] = OutPrefix if not SinglePlot else OutPrefix + '_tmp0'
        d['TACHYONEXEC'] = TACHYONEXEC
        tmpTcl = OutPrefix + '.tcl'
        file(tmpTcl, 'w').write(s_vmd % d)
        cmdstr1 = '%s -dispdev text -eofexit -e %s > /dev/null 2>&1' % (
            VMDEXEC, tmpTcl)
        os.system(cmdstr1)
        for x in [tmpNativePdb, tmpPdb, tmpTcl, d['FILEPREFIX']]:
            os.remove(x)
    else:
        print 'ERROR: Renderer not found'
        exit()
    # if single plot with supplied labels is requested (mostly when used from the command line)
    if SinglePlot:
        if not Label:
            rmsd = sim.geom.RMSD(pNative.Pos[BBInds], p.Pos[BBInds])
            print rmsd
            Label = r'$RMSD = %2.2f \AA$' % rmsd
        if Renderer == 'pymol': pic0 = OutPrefix + '_tmp0.png'
        else: pic0 = OutPrefix + '_tmp0.tga'
        pic1 = OutPrefix + '_tmp1.png'
        cmdstr2 = '%s %s -trim -bordercolor white -background white -border 50x50 -quality 100 %s' % (
            IMAGEMAGICKEXEC, pic0, pic1)
        os.system(cmdstr2)
        pic = mpimg.imread(pic1)
        fig = plt.figure(figsize=(5, 5), facecolor='w', edgecolor='w')
        ax = fig.add_subplot(1, 1, 1)
        ax.imshow(pic, aspect='auto')
        #ax.set_title(Label, fontsize = 8)
        ax.set_xticks([])
        ax.set_yticks([])
        ax.set_xticklabels([])
        ax.set_yticklabels([])
        figname = OutPrefix + '.png'
        plt.savefig(figname, bbox_inches='tight')
        for x in [pic0, pic1]:
            os.remove(x)
    return