Exemplo n.º 1
0
    def parm2pdb(self, f_parm, f_crd, f_out, aatm=0):
        """
        Use ambpdb to build PDB from parm and crd.

        @param f_parm: existing parm file
        @type  f_parm: str
        @param f_crd: existing crd file
        @type  f_crd: str
        @param f_out: target file name for PDB
        @type  f_out: str

        @return: f_out, target file name for PDB
        @rtype: str

        @raise AmberError: if ambpdb fail
        """
        ##         cmd = '%s -p %s -aatm < %s > %s' % \
        args = '-p %s %s' % (f_parm, '-aatm' * aatm)

        x = Executor('ambpdb',
                     args,
                     f_in=f_crd,
                     f_out=f_out,
                     log=self.log,
                     verbose=1,
                     catch_err=1)

        output, error, status = x.run()

        if not os.path.exists(f_out):
            raise AmberError, 'ambpdb failed.'

        return f_out
Exemplo n.º 2
0
def main(options):

    ##     ## get extra options from external file
    ##     if options.has_key('x'):
    ##         options.update( _parseExternalOptions( options['x'] ) )

    fname = options['i']  # input pdb file
    outPath = options['o']

    chainMask = options.get('cmask', None)
    if chainMask: chainMask = toIntList(chainMask)

    try:
        if options.has_key('h'):
            fheader = options['h']
        else:
            fheader = options['t'] + '/head.inp'
        if options.has_key('s'):
            fsegment = options['s']
        else:
            fsegment = options['t'] + '/segment.inp'
        if options.has_key('e'):
            ftail = options['e']
        else:
            ftail = options['t'] + '/end.inp'
    except:
        errWriteln(
            "You have to specify either all three template files or\n" +
            "(option -t) a folder that contains head.inp, segment.inp, end.inp.\n"
            +
            "If both -t and -h, -s, or -e are present, files specified with\n"
            + "-h, -s, -e are preferred.")

    ## check that input pdb file name (stripped of its path and extension)
    ## is at least 5 characters long and starts with a number
    ## Prompt user for renaming of the file.
    name = stripFilename(fname)

    ## the filename is OK, but it has the same name as used for the
    ## XPLOR output therefore we append _original to the input file
    if toInt(name[0]) == None or len(name) == 4:
        print "##### NOTE: ######"
        print "The pdb file name you gave is OK, but exactly"
        print "the same name will be used for the output from"
        print "the XPLOR script. Therefore '_original' will be"
        print "appended to the input pdb file you gave."
        base, ext = absfile(fname).split('.')
        new_fname = base + '_original.' + ext

        os.rename(fname, new_fname)
        fname = new_fname

    if toInt(name[0]) == None or len(name) < 4:
        print "##### WARNING: ######"
        print "The pdb file name you gave is either shorter "
        print "than 4 characters or it doesn't start with a number."
        print "This will cause the X-PLOR job to fail"
        msg = "Do you want to rename the file (Y/N)?"

        if upper(raw_input(msg)) == 'Y':
            new_name = upper(raw_input("Give a new filname:"))

            ## check that the new name is OK
            if toInt(new_name[0]) == None or len(new_name) < 4:
                raise StandardError, \
                      'You gave an incorrect new filename. Exiting'

            ## create link
            else:
                new_file = '%s/%s.%s' % (os.path.dirname(
                    absfile(fname)), new_name, fname.split('.')[-1])
                os.link(fname, new_file)
                print 'Link from %s to %s created sucessfully'\
                      %(absfile(fname), new_file)
                fname = new_file

    ## switch on Amber specialities ?
    amber = options.has_key('a')

    ## cap N- and C-term of chain breaks?
    capBreaks = options.has_key('cap')

    cleaner = ChainCleaner(
        ChainSeparator(fname,
                       outPath,
                       int(options['c']),
                       capBreaks=capBreaks,
                       chainMask=chainMask))

    # initialize with output path and base file name for generate.inp file
    xplorer = Xplor(outPath,
                    cleaner,
                    fheader,
                    fsegment,
                    ftail,
                    amber,
                    extras=options)

    xplorer.generateInp()

    ## run X-Plor
    if options.has_key('exe'):

        out, error, returncode = Executor(
            'xplor',
            strict=0,
            f_in=xplorer.cleaner.pdbname + "_generate.inp",
            f_out=xplorer.cleaner.pdbname + '_generate.log').run()
    ## Show structure in pymol
    if options.has_key('view'):

        pm = Pymoler()
        mname = pm.addPdb(xplorer.outname + '.pdb')
        pm.add('select xray-wat, segi 1XWW')
        pm.add('select added-wat, segi 1WWW')
        pm.add('select hydrogens, elem H')
        pm.add('hide everything, xray-wat OR added-wat OR hydrogens')
        pm.add('select none')

        colors = [hex2rgb(c, str) for c in hexColors(len(xplorer.chains))]

        i = 0
        for c in xplorer.chains:
            print colors[i], c.segment_id
            pm.add('set_color col_%i, %s' % (i, colors[i]))
            pm.add('color col_%i, segi %s and elem c' % (i, c.segment_id))
            i += 1

        pm.add('zoom all')
        pm.show()