def prody_fetch(opt): """Fetch PDB files from PDB FTP server.""" import prody pdblist = opt.pdb listfn = opt.listfn if listfn: if os.path.isfile(listfn): inp = prody.openFile(listfn) for line in inp: line = line.strip() for s in line.split(','): for pdb in s.split(): if len(pdb) == 4: pdblist.append(pdb) inp.close() else: opt.subparser.error("No such file: '{0:s}'".format(listfn)) prody.fetchPDB(pdblist, opt.folder, compressed=opt.gzip, copy=True)
def prody_anm(opt): """Perform ANM calculations based on command line arguments.""" outdir = opt.outdir if not os.path.isdir(outdir): opt.subparser.error('{0:s} is not a valid path'.format(outdir)) import numpy as np import prody LOGGER = prody.LOGGER pdb = opt.pdb prefix = opt.prefix cutoff, gamma = opt.cutoff, opt.gamma, nmodes, selstr, model = opt.nmodes, opt.select, opt.model pdb = prody.parsePDB(pdb, model=model) if prefix == '_anm': prefix = pdb.getTitle() + '_anm' select = pdb.select(selstr) if select is None: opt.subparser('Selection "{0:s}" do not match any atoms.' .format(selstr)) LOGGER.info('{0:d} atoms will be used for ANM calculations.' .format(len(select))) anm = prody.ANM(pdb.getTitle()) anm.buildHessian(select, cutoff, gamma) anm.calcModes(nmodes) LOGGER.info('Writing numerical output.') if opt.npz: prody.saveModel(anm) prody.writeNMD(os.path.join(outdir, prefix + '.nmd'), anm, select) outall = opt.all delim, ext, format = opt.delim, opt.ext, opt.numformat if outall or opt.eigen: prody.writeArray(os.path.join(outdir, prefix + '_evectors'+ext), anm.getArray(), delimiter=delim, format=format) prody.writeArray(os.path.join(outdir, prefix + '_evalues'+ext), anm.getEigenvalues(), delimiter=delim, format=format) if outall or opt.beta: fout = prody.openFile(prefix + '_beta.txt', 'w', folder=outdir) fout.write('{0[0]:1s} {0[1]:4s} {0[2]:4s} {0[3]:5s} {0[4]:5s}\n' .format(['C', 'RES', '####', 'Exp.', 'The.'])) for data in zip(select.getChids(), select.getResnames(), select.getResnums(), select.getBetas(), prody.calcTempFactors(anm, select)): fout.write('{0[0]:1s} {0[1]:4s} {0[2]:4d} {0[3]:5.2f} {0[4]:5.2f}\n' .format(data)) fout.close() if outall or opt.covar: prody.writeArray(os.path.join(outdir, prefix + '_covariance'+ext), anm.getCovariance(), delimiter=delim, format=format) if outall or opt.ccorr: prody.writeArray(os.path.join(outdir, prefix + '_cross-correlations' + ext), prody.calcCrossCorr(anm), delimiter=delim, format=format) if outall or opt.hessian: prody.writeArray(os.path.join(outdir, prefix + '_hessian'+ext), anm.getHessian(), delimiter=delim, format=format) if outall or opt.kirchhoff: prody.writeArray(os.path.join(outdir, prefix + '_kirchhoff'+ext), anm.getKirchhoff(), delimiter=delim, format=format) if outall or opt.sqflucts: prody.writeArray(os.path.join(outdir, prefix + '_sqflucts'+ext), prody.calcSqFlucts(anm), delimiter=delim, format=format) figall, cc, sf, bf, cm = opt.figures, opt.cc, opt.sf, opt.bf, opt.cm if figall or cc or sf or bf or cm: try: import matplotlib.pyplot as plt except ImportError: LOGGER.warning('Matplotlib could not be imported. ' 'Figures are not saved.') else: LOGGER.info('Saving graphical output.') format, width, height, dpi = \ opt.figformat, opt.width, opt.height, opt.dpi format = format.lower() if figall or cc: plt.figure(figsize=(width, height)) prody.showCrossCorr(anm) plt.savefig(os.path.join(outdir, prefix + '_cc.'+format), dpi=dpi, format=format) plt.close('all') if figall or cm: plt.figure(figsize=(width, height)) prody.showContactMap(anm) plt.savefig(os.path.join(outdir, prefix + '_cm.'+format), dpi=dpi, format=format) plt.close('all') if figall or sf: plt.figure(figsize=(width, height)) prody.showSqFlucts(anm) plt.savefig(os.path.join(outdir, prefix + '_sf.'+format), dpi=dpi, format=format) plt.close('all') if figall or bf: plt.figure(figsize=(width, height)) bexp = select.getBetas() bcal = prody.calcTempFactors(anm, select) plt.plot(bexp, label='Experimental') plt.plot(bcal, label=('Theoretical (R={0:.2f})' .format(np.corrcoef(bcal, bexp)[0,1]))) plt.legend(prop={'size': 10}) plt.xlabel('Node index') plt.ylabel('Experimental B-factors') plt.title(pdb.getTitle() + ' B-factors') plt.savefig(os.path.join(outdir, prefix + '_bf.'+format), dpi=dpi, format=format) plt.close('all')