Пример #1
0
def n_atoms(gro_in):
    if (type(gro_in) == str):
        if (not ot.checkfile(os.getcwd(), gro_in)):
            print('ERROR (n_atoms): checkfile() failed for args \"'+os.getcwd()+\
                  '\" and \"'+gro_in+'\"')
            sys.exit(1)
        gro_mem = gio.put_grofile_in_memory(gro_in)
        nat = int(gro_mem[1][0])
        del gro_mem
        return nat
    elif (type(gro_in) == list):
        nat_list = []
        for file in gro_in:
            if (not ot.checkfile(os.getcwd(), file)):
                print('ERROR (n_atoms): checkfile() failed for args \"'+os.getcwd()+\
                      '\" and \"'+file+'\"')
                sys.exit(1)
            gro_mem = gio.put_grofile_in_memory(file)
            nat = int(gro_mem[1][0])
            del gro_mem
            nat_list.append(nat)
        return nat_list
Пример #2
0
def to_gro(pdb_in):
    if (type(pdb_in) == str):
        if (not ot.checkfile(os.getcwd(), pdb_in)):
            print('ERROR (to_gro): checkfile() failed for args \"'+os.getcwd()+\
                  '\" and \"'+pdb_in+'\"')
            sys.exit(1)
        gro_out = re.sub('.pdb', '.gro', pdb_in)
        ifacelist = ['-f ' + pdb_in, '-o ' + gro_out]
        gmx.g_editconf(ifacelist, log='editconf.err')
        del ifacelist
        return gro_out
    elif (type(pdb_in) == list):
        gro_out_list = []
        for file in pdb_in:
            if (not ot.checkfile(os.getcwd(), file)):
                print('ERROR (to_gro): checkfile() failed for args \"'+os.getcwd()+\
                      '\" and \"'+file+'\"')
                sys.exit(1)
            gro_out = re.sub('.pdb', '.gro', file)
            ifacelist = ['-f ' + file, '-o ' + gro_out]
            gmx.g_editconf(ifacelist, log='editconf.err')
            del ifacelist
            gro_out_list.append(gro_out)
        return gro_out_list
Пример #3
0
def do_fg2cg(pdbfile, pair):

    pdbase = pdbfile.split('.pdb')[0]

    # file parsing and conversion
    ListChains = []
    if (ot.checkfile(os.getcwd(), pdbfile)):
        splitpdb = 1
        ListChains = env.a2f.run(pdbfile, splitpdb)
    else:
        print('ERROR: checkfile() failed for args \"'+os.getcwd()+\
              '\" and \"'+pdbfile+'\"')
        sys.exit(1)

    # First make CG structures of AA chains:
    FastaLs = []
    for file in os.listdir(os.getcwd()):
        if (re.search('fasta', file)):
            FastaLs.append(file)
    DictIsChainAA = {}
    for c in ListChains:
        IsAA = False
        for file in FastaLs:
            if (re.search('_' + c + '.[0-9].fasta', file)):
                IsAA = True
        if (IsAA):
            DictIsChainAA[c] = 'AASequence'
        else:
            DictIsChainAA[c] = 'NonProtein'
    PdbLs = []
    for file in os.listdir(os.getcwd()):
        if (re.search('[0-9].pdb', file)):
            PdbLs.append(file)
            os.system('ls -lfh ' + file)
    print("Found pdb files", PdbLs)

    FgStructFiles = []
    CgStructFiles = []
    FgFastaFiles = []
    FgDsspFiles = []
    FgSsdFiles = []
    CgItpFiles = []
    for key, value in DictIsChainAA.items():  # Changed iteritems() to items()
        if (value == 'AASequence'):
            FgPdbs = []
            CgPdbs = []
            FgFastas = []
            FgDssps = []
            FgSsds = []
            CgItps = []
            for file in PdbLs:
                if (re.search('_' + key + '.[0-9].pdb', file)):
                    FgPdbs.append(file)
                    FgFastas.append(re.sub('.pdb', '.fasta', file))
            FgStructFiles.extend(FgPdbs)
            FgFastaFiles.extend(FgFastas)
            for file in FgPdbs:
                CgPdbs.extend(finegrained2coarsegrained([file]))
                FgDssps.extend(pdbt.pdb2dssp([file]))
            for file in FgDssps:
                FgSsds.extend(dssp2ssd([file]))
            DictFastaSsd = {}
            for file in FgSsds:
                FastaFile = re.sub('.ssd', '.fasta', file)
                DictFastaSsd[FastaFile] = file
                CgItps.extend(to_itp(DictFastaSsd))
            CgStructFiles.extend(CgPdbs)
            FgDsspFiles.extend(FgDssps)
            FgSsdFiles.extend(FgSsds)
            CgItpFiles.extend(CgItps)
        elif (value == 'NonProtein'):
            FgPdbs = []
            CgPdbs = []
            CgItps = []
            for file in PdbLs:
                if (re.search('_' + key + '.[0-9].pdb', file)):
                    FgPdbs.append(file)
                    CgPdbs.append(Fg2Cg_NonProtein(file))
    # print(FgStructFiles
    # print(CgStructFiles
    # print(FgFastaFiles
    # print(FgDsspFiles
    # print(FgSsdFiles
    # print(CgItpFiles

    fgpair = pdbt.merge_pdbs(pdbase, pair)
    fastapair = pdbt.merge_fastas(pdbase, pair)
    for i in fgpair:
        if (not ot.checkfile(os.getcwd(), i)):
            print('ERROR: checkfile() failed for args \"'+os.getcwd()+\
              '\" and \"'+i+'\"')
            sys.exit(1)
    cgpair = finegrained2coarsegrained(fgpair)
    dssppair = pdbt.pdb2dssp(fgpair)
    for i in dssppair:
        if (not ot.checkfile(os.getcwd(), i)):
            print('ERROR: checkfile() failed for args \"'+os.getcwd()+\
              '\" and \"'+i+'\"')
            sys.exit(1)
    ssdpair = dssp2ssd(dssppair)
    itppair = []
    if (len(ssdpair) == len(fastapair)):
        fastassddict = {}
        i = 0
        for fasta in fastapair:
            fastassddict[fasta] = ssdpair[i]
            i += 1
        for fasta in fastassddict.keys():  # Changed iterkeys() to keys()
            if (not ot.checkfile(os.getcwd(), fasta)):
                print('ERROR: checkfile() failed for args \"'+os.getcwd()+\
                  '\" and \"'+fasta+'\"')
                sys.exit(1)
        for ssd in fastassddict.values():  # Changed itervalues() to values()
            if (not ot.checkfile(os.getcwd(), ssd)):
                print('ERROR: checkfile() failed for args \"'+os.getcwd()+\
                  '\" and \"'+ssd+'\"')
                sys.exit(1)
        itppair = to_itp(fastassddict)
        # check if order of fastapair == order of itppair
        # since dictionary order can be different from list order
        for i in range(len(itppair)):
            itpname = itppair[i]
            itpbase = itpname.split('.')[0]
            itpext = itpname.split('.')[1]
            fastaname = fastapair[i]
            fastabase = fastaname.split('.')[0]
            if (not re.match(fastabase, itpbase)):
                itppair[i] = fastabase + '.' + itpext
    else:
        print('ERROR: len(ssdpair)!=len(fastapair)')
        sys.exit(1)

    gro_cgpair = gio.to_gro(cgpair)
    nat_cgpair = st.n_atoms(gro_cgpair)
    nrs_cgpair = st.n_residues(gro_cgpair)

    cggro_merged = pdbase + '_cg.gro'
    gio.merge_gro(cggro_merged, gro_cgpair, nat_cgpair, nrs_cgpair)

    # make indexfile
    ifacelist = ['-f ' + cggro_merged, '-o ' + 'tmp.ndx']
    gmx.g_make_ndx(ifacelist, stdin=['q'], log='make_ndx.err')
    del ifacelist
    ngroups = st.ngroups_in_ndx('tmp.ndx')
    os.remove('tmp.ndx')
    cgndx_merged = re.sub('.gro', '.ndx', cggro_merged)
    ifacelist = ['-f ' + cggro_merged, '-o ' + cgndx_merged]
    gmx.g_make_ndx(ifacelist,
                   stdin=gmx.gen_ndxUIlist(ngroups, gro_cgpair, nat_cgpair),
                   log='make_ndx.err')
    del ifacelist

    # stabilize the tertiary structure:
    cg_stable_itppair = stabilize_tertiary_structure(cggro_merged,
                                                     cgndx_merged, itppair,
                                                     'backbone', nat_cgpair)

    return cggro_merged, cgndx_merged, cg_stable_itppair, \
           gro_cgpair, nat_cgpair, fgpair