Example #1
0
def get_residues(pdb_fn, restraints, verbose):
    residues = set()
    for h in restraints:
        a = h[0]
        b = h[1]
        a = a[0] + ':' + a[1:]
        residues.add(a)  # A19
        b = b[0] + ':' + b[1:]
        residues.add(b)
    # set(['A:41', 'A:9', 'A:10', 'A:16'])

    selection = ','.join(residues)
    selection_parsed = select_pdb_fragment(selection,
                                           separator=",",
                                           splitting="[,:;]")

    residues = parse_pdb(pdb_fn, selection_parsed)

    # get mb
    for r in residues:
        if residues[r].has_key('N9'):  # A,G
            residues[r]['mb'] = residues[r]['N9'] - (
                (residues[r]['N9'] - residues[r]['C6']) / 2)
        else:  # A,G
            residues[r]['mb'] = residues[r]['N1'] - (
                (residues[r]['N1'] - residues[r]['C4']) / 2)
    for r in residues:
        #print 'mb for ' + str(r) + ' is ' + residues[r]['mb']
        print ' mb for ', str(r), residues[r]['mb']
    return residues
Example #2
0
def get_residues(pdb_fn, restraints, verbose):
    """
    """
    residues = set()
    for h in restraints:
        a = h[0]
        b = h[1]
        a = a[0] + ':' + a[1:]
        residues.add(a)  # A19
        b = b[0] + ':' + b[1:]
        residues.add(b)
    # set(['A:41', 'A:9', 'A:10', 'A:16'])

    selection = ','.join(residues)
    selection_parsed = select_pdb_fragment(selection,
                                           separator=",",
                                           splitting="[,:;]")

    residues = parse_pdb(pdb_fn, selection_parsed)

    # get mb
    for r in residues:
        if 'N9' in residues[r]:  # A,G
            residues[r]['mb'] = residues[r]['N9'] - (
                (residues[r]['N9'] - residues[r]['C6']) / 2)
        else:  # A,G
            residues[r]['mb'] = residues[r]['N1'] - (
                (residues[r]['N1'] - residues[r]['C4']) / 2)
    for r in residues:
        if verbose:
            logger.info(' '.join(['mb for ', str(r), str(residues[r]['mb'])]))
    return residues
Example #3
0
    optparser.add_option("-v", "--verbose",
                      action="store_true", dest="verbose", default=False,
                      help="verbose")

    (opts, args)=optparser.parse_args()

    if len(sys.argv) == 1:
        print optparser.format_help() #prints help if no arguments
        sys.exit(1)

    input_files = args[:] # opts.input_dir
    rmsds_fn = opts.rmsds_fn
    target_fn = opts.target_fn
    method = opts.method
    print ' method:', method
    target_selection = select_pdb_fragment(opts.target_selection)
    model_selection = select_pdb_fragment(opts.model_selection)
    if target_selection:
        if opts.verbose:
            print '  target_selection: #', opts.target_selection, target_selection
            ts = target_selection
            print ts
            resides_in_total = 0
            for i in target_selection:
                print i, len(ts[i]) # chain string, a list of residues
                resides_in_total += len(ts[i])
            print 'in total:', resides_in_total
    if model_selection:
        if opts.verbose:
            print '  model_selection:  ', len(model_selection), opts.model_selection, model_selection
            resides_in_total = 0
def edit_pdb(args):
    """Edit. The function can take `A:3-21>A:1-19` or even syntax like this
    `A:3-21>A:1-19,B:22-32>B:20-30` and will do a editing.
    The output is printed, line by line. Only ATOM lines are edited!"""
    ## open a new file
    s = StrucFile(args.file)
    if not args.no_hr:
        add_header()
        print 'HEADER --edit ' + args.edit

    ## --edit 'A:3-21>A:1-19,B:22-32>B:20-30'
    if args.edit.find(',') > -1:
        # more than one edits
        edits = args.edit.split(',')  # ['A:3-21>A:1-19', 'B:22-32>B:20-30']
        selects = []
        for e in edits:
            selection_from, selection_to = select_pdb_fragment(
                e.split('>')[0]), select_pdb_fragment(e.split('>')[1])
            if len(selection_to) != len(selection_from):
                raise Exception('len(selection_to) != len(selection_from)')
            selects.append([selection_from, selection_to])
        print edits
    else:
        # one edit
        e = args.edit
        selection_from, selection_to = select_pdb_fragment(
            e.split('>')[0]), select_pdb_fragment(e.split('>')[1])
        if len(selection_to) != len(selection_from):
            raise Exception('len(selection_to) != len(selection_from)')
        selects = [[selection_from, selection_to]]

    ## go ever all edits: ['A:3-21>A:1-19','B:22-32>B:20-30']
    for l in s.lines:
        if l.startswith('ATOM'):
            # get chain and resi
            chain = l[21:22].strip()
            resi = int(l[22:26].strip())

            if_selected_dont_print = False
            # for selections
            for select in selects:
                selection_from, selection_to = select
                if selection_from.has_key(chain):
                    if resi in selection_from[chain]:
                        # [1,2,3] mapping from [4,5,10], you want to know how to map 1
                        # 1 is [0] element of first list, so you have to index first list
                        # to get 0, with this 0 you can get 4 out of second list [4,5,10][0] -> 4
                        nl = list(l)
                        chain_new = selection_to.keys()[
                            0]  # chain form second list
                        nl[21] = chain_new  # new chain
                        index = selection_from[chain].index(
                            int(resi))  # get index of 1
                        resi_new = str(selection_to[chain_new][index]).rjust(
                            4)  # 'A' [1,2,3] -> '  1'
                        nl[22:26] = resi_new
                        nl = ''.join(nl)
                        if_selected_dont_print = True
                        print nl
            if not if_selected_dont_print:
                print l
        else:  # if not atom
            print l
Example #5
0
        s.get_simrna_ready(args.renumber_residues)
        print s.get_text()

    if args.renumber_residues:
        s = StrucFile(args.file)
        s.remove_hydrogen()
        s.remove_ion()
        s.remove_water()
        s.get_simrna_ready(args.renumber_residues)
        s.renum_atoms()
        if not args.no_hr:
            add_header()
        print s.get_text()

    if args.delete:
        selection = select_pdb_fragment(args.delete)
        s = StrucFile(args.file)
        if not args.no_hr:
            add_header()
            print 'HEADER --delete ' + args.delete #' '.join(str(selection))
        for l in s.lines:
            if l.startswith('ATOM'):
                chain = l[21]
                resi = int(l[23:26].strip())
                if selection.has_key(chain):
                    if resi in selection[chain]:
                        continue  # print chain, resi
                print l

    if args.edit:
        selection_from, selection_to = select_pdb_fragment(args.edit.split('>')[0]), select_pdb_fragment(args.edit.split('>')[1])