Example #1
0
 def write_correlInput(self, **kwargs):
     kwargs = lowerKeys(kwargs)
     header = kwargs.get('header', [])
     #
     print self.anlPathname
     if self.anlPathname is None:
         raise IOError("No directory specified.")
     mkdir(self.anlPathname)
     #
     for i, group in enumerate(grouper(self.nativeContacts, 100)):
         String = self.get_correlInputHeader(header)
         String.append('! anl :: write')
         for j, contact in enumerate(group):
             String.append('open unit %03d write card name %s/natq%02d%02d.anl' % (j+100, self.anlPathname, i, j))
         String.append('')
         String.append('correl maxtimesteps %d maxatom %d maxseries %d' % (self.correlArrayLength, 1000, len(group)))
         for j, contact in enumerate(group):
             String.append('enter n%03d bond bynum %d bynum %d geometry' % (j, contact.i.atomNum, contact.j.atomNum))
         String.append('traj firstu 10 nunit 1 begin %d stop %d skip %d select all end' % (self.correlStart, self.correlStop, self.correlSkip))
         String.append('')
         for j, contact in enumerate(group):
             String.append('write n%03d card unit %03d' % (j, j+100))
             String.append('* Contact %02d%02d: between cgAtoms %s and %s' % (i, j, contact.i.addr, contact.j.addr))
             String.append('* Native Contact - Interaction between %s and %s' % (contact.i.prmString, contact.j.prmString))
             String.append('*')
             String.append('')
         String.append('end')
         String.append('')
         String.append('rewind unit 10')
         String.append('')
         String.append('stop')
         String = '\n'.join(String)
         # Write file
         self.inpFilename = '%s/natq%02d.inp' % (self.inpPathname, i)
         print '%s' % self.inpFilename
         write_to = open(self.inpFilename, 'w')
         write_to.write(String)
         write_to.close()
Example #2
0
 def fset(self, value):
     self._outPathname = self.expandPath(value)
     mkdir(self._outPathname)
Example #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