def isConverged(TrajDir, PdbName, TempSet = 300, OutFile = None): if OutFile is None: OutFile = os.path.abspath('./rmsd_convergence.png') import cgprotein as lib, measure as m TempFile = os.path.join(TrajDir, 'temps.txt') Temps = np.loadtxt(TempFile) Ind = np.argmin(abs(Temps - TempSet)) TrajTemp = Temps[Ind] Traj = os.path.join(TrajDir, 'prot_%s.%3.2f.lammpstrj.gz' % (PdbName, TrajTemp)) NativePdb = parseNative(PdbName) LammpsREMDLog = os.path.join(TrajDir, 'prot_%slammps.log' % PdbName) calc = lib.Compute(TrajFn = Traj, NativePdb = NativePdb, Temp = TrajTemp) rmsd = calc.RMSD_frame() avgrmsd = rmsd.mean() stdrmsd = np.std(rmsd, ddof = 1) avgerr = stdrmsd / avgrmsd avgerr *= 100. m.NBins = 50 ; m.NBlocks = 4 ; m.Normalize = True rmsdhist = m.makeHist(rmsd) Walk = np.loadtxt(LammpsREMDLog, skiprows = 3)[:, 1:] fig = plt.figure(facecolor = 'w', edgecolor = 'w', figsize = (8, 4)) ax1 = fig.add_subplot(2,2,1) ax2 = fig.add_subplot(2,2,2) ax3 = fig.add_subplot(2,2,3) ax1.plot(rmsd, lw = 1, color = 'blue', label = 'fluct from mean = %3.2f %%' % avgerr) ax1.axhline(avgrmsd, ls = '--', color = 'black', lw = 2) ax1.legend(loc = 'best') ax2.errorbar(rmsdhist[0], rmsdhist[1], yerr = rmsdhist[2], color = 'black', lw = 2, marker = 'o', markersize = 5) ax2.set_xlabel(r'$RMSD (\AA)$') ; ax2.set_ylabel('distribution') for i, T in enumerate(Temps): x = Walk[:,i] y = np.array([Temps[int(k)] for k in x]) m.NBins = len(Temps) ; m.NBlocks = 1; m.Normalize = False walkhist = m.makeHist(y) ax3.plot(walkhist[0], walkhist[1], lw = 2, label = 'Replica: %d' % i) ax3.legend(loc = 'best', fontsize = 5) ax3.set_xlabel('Temp (K)') ; ax3.set_ylabel('distribution') fig.tight_layout() plt.savefig(OutFile) return
else: TempSet = None TrajFn = None # output locations OutPrefix = os.path.join(OutDir, Prefix) if not os.path.isdir(OutDir): os.system('mkdir -p %s' % OutDir) print '\n' print 'ANALYZING POLYPEPTIDE' print '=====================' # compute object print '\nCreating Compute object' calc = lib.Compute(NativePdb=NativePdb, TrajFn=TrajFn, Temp=TempSet, Prefix=OutPrefix) # replica object print '\nCreating Replica object' rep = lib.Replica(NativePdb=NativePdb, TrajPrefix=TrajPrefix, Prefix=OutPrefix, TempSet=TempSet, OrderParams=['U', 'Rg', 'RMSD', 'HScore', 'BScore'], NStepsProd=NStepsProd, NStepsSwap=NStepsSwap, WriteFreq=WriteFreq) def Cluster():
# extract AA and CG paths print 'Setting ouput locations' AAPrefix = OutPrefix + '_AA' CGPrefix = OutPrefix + '_CG' OutDir = os.path.dirname(OutPrefix) if not os.path.isdir(OutDir): os.mkdir(OutDir) # nativepdb w.r.t all calculations are done NativePdb = os.path.expanduser('~/Go/%s_AA/topclust.pdb' % polymer) if not os.path.isfile(NativePdb): raise IOError('AA top cluster struct missing.') # global compute and replica objects for AA and CG print 'Creating global Compute objects for AA and CG' c_AA = lib.Compute(NativePdb = NativePdb, Prefix = AAPrefix) c_CG = lib.Compute(NativePdb = NativePdb, Prefix = CGPrefix) # global replica objects for AA print 'Creating global Replica objects for AA' fAA = utils.parseAA(polymer) if not fAA['hasReplica']: print 'Error: Not enough data to create AA Replica object' r_AA = None else: r_AA = lib.Replica(NativePdb = NativePdb, Prefix = AAPrefix, TrajPrefix = os.path.join(fAA['MasterDir'], 'Lammps', polymer)) # global replica objects for CG print 'Creating global Replica objects for CG' fCG = utils.parseCG(polymer)
TempSet = float(sys.argv[5]) hasPseudoGLY = int(sys.argv[6]) if len(sys.argv) > 6 else False # get Traj if not os.path.isdir(OutDir): os.system('mkdir -p %s' % OutDir) OutPrefix = os.path.join(OutDir, Prefix) TrajPrefix = os.path.join(TrajDir, Prefix) TrajFn = FMT['TRAJ'] % (TrajPrefix, TempSet) # fancy intro 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)
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) pmf = -np.log(ramahist) pmf = pmf.clip(min = -5, max = 5) # get cluster contact maps NativeCM, TrajCM = calc.CompareContactMap() # get fraction of native contacts
#!/usr/bin/env python import numpy as np import utils, cgprotein polymers = ['ala15', 'leu15', 'val15'] for p in polymers: dict_AA = utils.parseAA(PolyPrefix = p) nativepdb = dict_AA['Pdb'] trajfn = dict_AA['Traj'] Temp = dict_AA['Temp'] calc = cgprotein.Compute(NativePdb = nativepdb, TrajFn = trajfn, Temp = Temp, Prefix = p) nativeco, cohist = calc.CompareCO() avgco = np.sum(cohist[0] * cohist[1]) / np.sum(cohist[1]) print 'Polymer: %s, Native CO: %g, TrajAvg CO: %g' % (p, nativeco, avgco)