示例#1
0
def rexHist(iterable, title, write=False, imgFilePath=None):
    """
    `iterable`  *string         # An iterable of the CHARMM .out files
    `title`     string          # The title of the plot.
    `write`     [`False`,`"svg"`,`"png"`]   # The plot's output format,
                                            # False won't write a file.
    `imgFilePath` string        # The plot's file path, defaults
                                # to `$cwd/default_title`.
    """
    fileList = list(iterable)
    fileList = map(expandPath, fileList)
    tempArray = []
    for fileName in fileList:
        print 'Processing %s...' % fileName
        filePointer = open(fileName)
        rawData = getProp(filePointer, 'averener', 'avertemp')
        tempArray.append(np.array(rawData['avertemp']).mean()) # Calc Temp
        histData = np.histogram(rawData['averener'], 20, new=True)
        pyplot.plot(histData[1][1:],histData[0],label=os.path.basename(fileName))
    pyplot.legend( ['%3dK' % tempArray[i] for i in xrange(len(fileList))]
                ,loc=0, ncol=2)
    pyplot.xlabel(r'$Energy\ (kcal\ mol^{-1})$')
    pyplot.ylabel(r'$Frequency$')
    pyplot.title(r'%s' % title)
    if write:
        if imgFilePath is None:
            imgFilePath = '%s/%s.%s' % (os.path.dirname(fileList[0]), title,
                                        write)
        else:
            imgFilePath = expandPath(imgFilePath)
        pyplot.savefig(imgFilePath, format=write)
    else:
        pyplot.show()
示例#2
0
文件: inp.py 项目: jo-sm/charmminglib
 def fset(self, value):
     value = expandPath(value)
     if not exists(value):
         raise IOError("No such file or directory: '%s'" % value)
     self._pdbFilename = value
示例#3
0
def parse(pdbFilename, **kwargs):
    """
    Parse a *.pdb* plain text file into its constituent chains and segments, and
    print one CHARMM formatted *.pdb* file per chain/segment combination.

    *kwarg defaults are listed first*

    **kwargs:**
        | ``informat``      ['auto', 'pdborg', 'charmm'] # 'auto' -> detects input formatting
        | ``outformat``     ['charmm', 'pdborg', 'auto'] # 'auto' -> same as input formatting
        | ``outpath``       ['auto', user_specified_path] # 'auto' -> same as pdbFilename path
        | ``fix_chainid``   [True, False]
        | ``autofix``       [True, False]
        | ``modelnum``      ['auto', 0, 1, 2, ...] # 'auto' -> uses the first model found
        | ``pickleme``      [False, True] # pickles the PDBFile object for later use
        | ``verbose``       [False, True]
        | ``old_resid``     [False, True]

    >>> parse('~/pychm/1yjp/1yjp.pdb',outpath='~',pickleme=True)
    """
    # kwargs
    kwargs = lowerKeys(kwargs)
    inFormat = kwargs.get('informat', 'auto')
    outFormat = kwargs.get('outformat', 'charmm')
    outPath = kwargs.get('outpath', 'auto')
    fix_chainid = kwargs.get('fix_chainid', True)
    autoFix = kwargs.get('autofix', True)
    modelNum = kwargs.get('modelnum', 'auto')
    pickleMe = kwargs.get('pickleme', False)
    verbose = kwargs.get('verbose', False)
    old_resid = kwargs.get('old_resid', False)
    # Repackage the PDBFile kwargs, make pdbFile object
    pdbFileArgs = {'informat':inFormat, 'fix_chainid':fix_chainid,
                'autofix':autoFix, 'verbose':verbose}
    pdb = PDBFile(pdbFilename, **pdbFileArgs)
    if verbose:
        print '%s: Output formatting set to `%s`' % (pdb.code, outFormat)
    # Get model number...
    if modelNum == 'auto':
        thisMol = pdb.iter_models().next()
    else:
        thisMol = pdb[modelNum]
    if verbose:
        print '%s: Loading `%s`' % (pdb.code, thisMol.name)
    # Determine explicit output Path
    if outPath == 'auto':
        outPath = pdb.path
    else:
        outPath = expandPath(outPath)
    mkdir(outPath)
    if verbose:
        print '%s: Output path set to `%s`' % (pdb.code, outPath)
    # Do Work
    thisMol.parse()
    if verbose:
        print '%s: Parsing `%s`' % (pdb.code, thisMol.name)
    # Write CHARMMing style output.
    segDict = {'nuc':'nuc', 'pro':'pro', 'good':'goodhet', 'bad':'het',
            'dna':'dna', 'rna':'rna'}
    stdoutList = []
    # Write pdb files
    writeArgs = {'outformat':outFormat, 'ter':True, 'end':False,
                'old_resid':old_resid}
    for seg in thisMol.iter_seg():
        stdoutList.append('%s-%s' % (seg.chainid, segDict[seg.segType]))
        name = '%s/new_%s-%s-%s.pdb' % (outPath, thisMol.code, seg.chainid,
                                        segDict[seg.segType])
        if verbose:
            print '%s: Writing output to file `%s`' % (pdb.code, name)
        seg.write(filename=name, **writeArgs)
    # Write pickle (chk) file
    if pickleMe:
        pickleFilename = '%s/%s.chk' % (outPath, pdb.code)
        pickleFile = open(pickleFilename,'w')
        dump(pdb,pickleFile)
        pickleFile.close()
        if verbose:
            print '%s: Writing pickle to file `%s`' % (pdb.code, pickleFilename)
    if verbose:
        print '\n\nEnd of verbosity\n\n'
    # To STDOUT
    print 'natom=%d' % len(thisMol)
    print 'nwarn=%d' % len(thisMol.warnings)
    if thisMol.warnings:
        print 'warnings=%r' % thisMol.warnings
    print 'seg=%r' % stdoutList
示例#4
0
文件: crd.py 项目: jo-sm/charmminglib
 def fset(self, value):
     self._filename = expandPath(value)
示例#5
0
 def __init__(self, filename, **kwargs):
     super(BaseCHARMMFile, self).__init__()
     self.filename = expandPath(filename)
     self.header = []
     self.body = []
示例#6
0
    def write(self, filename, **kwargs):
        """
        Writes a file containing the molecular information contained in
        :class:`BaseStruct` object.

        **kwargs:**
            | ``outformat``     ["charmm","pdborg","debug","xdebug","crd","xcrd","mol2"]
            | ``old_chainid``   [False,True]
            | ``old_segType``   [False,True]
            | ``old_resid``     [False,True]
            | ``old_atomNum``   [False,True]
            | ``ter``           [False,True]
            | ``end``           True if `outformat` in ["pdborg","charmm"]
            | ``append``        [False,True]

        >>> thisSeg.write('~/1yjp.pdb',outformat='charmm',old_resid=True)
        """
        # kwargs
        kwargs = lowerKeys(kwargs)
        outFormat = kwargs.get('outformat', 'charmm')
        end = kwargs.get('end', None)
        ter = kwargs.get('ter', None)
        append = kwargs.get('append', False)
       
        #
        filename = expandPath(filename)
        writeMe = []
        if outFormat in ['pdborg', 'charmm']:
            for atom in self:
                writeMe.append(atom.Print(**kwargs))
                if ter is None:
                    ter = True
                if end is None:
                    end = True
        elif outFormat == 'mol2':
            header = kwargs.get('header', None)
            bonds  = kwargs.get('bonds', None)

            writeMe.append('@<TRIPOS>MOLECULE')
            if header:
                for line in header:
                    writeMe.append(line)
            writeMe.append('')

            writeMe.append('@<TRIPOS>ATOM')
            for atom in self:    
                writeMe.append(atom.Print(**kwargs))
            writeMe.append('')

            writeMe.append('@<TRIPOS>BOND')
            if bonds:
                for bond in bonds:
                    writeMe.append(bond.writeOut())
            writeMe.append('')

        elif outFormat in ['debug', 'xdebug']:
            for atom in self:
                writeMe.append(atom.Print(**kwargs))
        elif outFormat in ['crd', 'cor', 'card', 'short', 'shortcard',
                        'xcrd', 'xcor', 'xcard', 'long', 'longcard']:
            writeMe.append('*')
            writeMe.append('   %d' % len(self))
            for atom in self:
                writeMe.append(atom.Print(**kwargs))
        # TER/END
        if ter:
            writeMe.append('TER')
        if end:
            writeMe.append('END\n')
        # Write file
        writeMe = '\n'.join(writeMe)
        if append:
            writeTo = open(filename,'a')
        else:
            writeTo = open(filename,'w')
        writeTo.write(writeMe)
        writeTo.close()