def main():

    if (len(sys.argv) != 4):  # if no input
        print " (1) pdb file name,"
        print " (1) crd file name,"
        print " (2) output file  "
        return

    pdbfilename = sys.argv[1]
    crdfilename = sys.argv[2]
    output = sys.argv[3]

    #cl = pdb_lib.read_pdb(pdb_file)
    pdb = pdb_lib.read_pdb(pdbfilename)[0]
    size = len(pdb)

    frames = coord_reader(crdfilename, size)

    j = 0
    for f in frames:
        i = 0
        for c in f.cords:
            print "j=", j, "i=", i

            pdb[i].X = c.x
            pdb[i].Y = c.y
            pdb[i].Z = c.z
            i = i + 1
        pdb_lib.output_pdb(pdb, output + "." + str(j) + ".pdb")
        j = j + 1

    return
def main():
    if len(sys.argv) != 5:  # if no input
        print "ERORR: there need to be 4 inputs: pdb inputfilename, bfactorfilename(2 colomn:resname,value)  residuelist, outputfileprefix."
        return

    fileinputpdb = sys.argv[1]
    filebfactor = sys.argv[2]
    res_string = sys.argv[3]
    fileoutput = sys.argv[4]

    splitname = fileinputpdb.split('/')[-1].split('.')
    if len(splitname) != 2:
        print "error pdb file is weird. "
        exit()
    prefix = splitname[0]

    print 'input_pdb =' + fileinputpdb
    print 'sph prefix =' + prefix
    print 'residue string =' + res_string
    print 'output =' + fileoutput

    residlist = []
    res_string_split = res_string.split(',')
    print res_string_split
    #   if len(res_string_split) == 1:
    #       residlist.append(int(res_string_split[0]))
    #   else:
    #print res_string_split
    for s in res_string_split:
        if ('-' in s):
            s_split = s.split('-')
            if (len(s_split) != 2):
                print "something is wrong with residue string."
            else:
                start = int(s_split[0])
                stop = int(s_split[1]) + 1
                for i in range(start, stop):
                    residlist.append(i)
        else:
            residlist.append(int(s))

    for i in range(1, len(residlist)):
        if residlist[i - 1] > residlist[i]:
            print "uhoh. list is not monotonic"
            exit()

    print residlist
    #exit()

    pdblist_chains = pdb.read_pdb(fileinputpdb)
    pdblist = []
    for chain in pdblist_chains:
        pdblist = pdblist + chain
    pdblist_mod = add_bfactors(pdblist, residlist, filebfactor)
    pdb.output_pdb(pdblist_mod, fileoutput + '.pdb')
def main():
    filename = sys.argv[1]
    intval = int(sys.argv[2])
    fileprefix = sys.argv[3]

    pdbchains = pdb_lib.read_pdb(filename)
    count = 1
    for pdbmol in pdbchains:
        renumber_residue_continuous(pdbmol, intval)
        pdb_lib.output_pdb(pdbmol, '%s_%i.pdb' % (fileprefix, count))
        count = count + 1
def main():
    if len(sys.argv) != 4:  # if no input
        print "This function takes as input two pdb files"
        print "read in the low dielectric spheres (pdb1) and the water positions (pdb2)."
        print "calculates distances and writes out a the overlaping atoms from the second file (water positions)"
        print len(sys.argv)
        return

    pdb_file1 = sys.argv[1]
    pdb_file2 = sys.argv[2]
    pdb_out = sys.argv[3]
    print "file 1: " + pdb_file1
    print "file 2: " + pdb_file2

    pdb1 = pdb.read_pdb(pdb_file1)
    pdb2 = pdb.read_pdb(pdb_file2)
    pdb2_close = pdb.cal_dists_close(pdb1, pdb2)
    pdb.output_pdb(pdb2_close, pdb_out)
Пример #5
0
def main():
    if len(sys.argv) != 4:  # if no input
        print(
            "ERORR: there need to be 3 inputs: pdb inputfilename,  residue:atom_list, outputfileprefix."
        )
        print(
            "list is resnum1:atomname1,...,resnum1:atomnamei,...,resnumk,atomnamej,..."
        )
        return

    fileinputpdb = sys.argv[1]
    res_string = sys.argv[2]
    fileoutput = sys.argv[3]

    splitname = fileinputpdb.split('\\')[-1].split('.')
    if len(splitname) != 2:
        print("error pdb file is weird. ")
        exit()
    prefix = splitname[0]

    print('input_pdb =' + fileinputpdb)
    print('sph prefix =' + prefix)
    print('residue string =' + res_string)
    print('output =' + fileoutput)

    residlist = []
    res_string_split = res_string.split(',')
    residlist = res_string_split
    print res_string_split

    pdblist = pdb.read_pdb(fileinputpdb)[0]
    center = centre_of_mass(pdblist, residlist)
    #print ("%6.4f %6.4f %6.4f"%(center[0],center[1],center[2]))
    print(
        "HETATM    1 ZN    ZN A   1    %8.3f%8.3f%8.3f  1.00  0.00          ZN"
        % (center[0], center[1], center[2]))
    fh = open(fileoutput + '_zinc.pdb', 'w')
    fh.write(
        "HETATM    1 ZN    ZN A   1    %8.3f%8.3f%8.3f  1.00  0.00          ZN\n"
        % (center[0], center[1], center[2]))
    fh.close()

    change_name(pdblist, residlist)
    pdb.output_pdb(pdblist, fileoutput + '.pdb')
def main():
    if len(sys.argv) != 5: # if no input
        print "This function takes as input two pdb files, output file name and the value"
        print "read in the ligand (pdb1) and the water positions (pdb2)."
        print "calculates distances and writes out a the overlaping atoms from the second file (water positions)"
        print len(sys.argv)
        return
    
    pdb_file1  = sys.argv[1]
    pdb_file2  = sys.argv[2]
    pdb_out    = sys.argv[3]
    val        = float(sys.argv[4])
    print "file 1: " + pdb_file1
    print "file 2: " + pdb_file2
    print "file out: " + pdb_out
    print "value: " + str(val)

    pdb1 = pdb.read_pdb(pdb_file1)[0]
    pdb2 = pdb.read_pdb(pdb_file2)[0]
    pdb2_close = pdb.cal_dists_close_val(pdb1,pdb2,val**2)
    pdb.output_pdb( pdb2_close, pdb_out) 
Пример #7
0
def convert_sph_to_pdb_and_write(sphs,energies,pdbfilename):

   molname = "CLU"
   chainid = "A"   
   resname = "CLU"
   resnum  = 1
   atomname = "O"

   i = 0
   atoms = []
   for sph in sphs:
      atomnum  = sph.atomnum
      X = sph.X
      Y = sph.Y
      Z = sph.Z
      bfact = energies[i]
      boolhet = False
      atom = pdb_lib.PDB_atom_info(molname, chainid, resname, resnum, atomname, atomnum, X, Y, Z, bfact, boolhet) 
      atoms.append(atom)
      i=i+1
   pdb_lib.output_pdb(atoms,pdbfilename)
Пример #8
0
def run_energy_cal():
    # this function will run amber.

    # cluster.  we start with the frist water. find everything close, then go to the next water not alreay assigned. find everything close, repeat until all are assigned.

    wats = pdb_lib.read_pdb("waters.pdb")
    wat_clus = []
    for i in range(len(wats)):
        wat_clus.append(0)

    clusterheads = []
    cluster = 1
    for i, wat1 in enumerate(wats):
        if wat_clus[
                i] != 0:  # if cluster is already asigned then continue to next water
            continue
        print "water" + str(i) + " is a clusterhead.  "
        clusterheads.append(wat1)
        for j, wat2 in enumerate(wats):
            if wat_clus[
                    j] != 0:  # if cluster is already asigned then continue to next water
                continue
            dist = dist_wat(wat1, wat2)
            #if dist < 3.0:
            if dist < 2.8:
                wat_clus[j] = cluster

        cluster = cluster + 1

    pdb_lib.output_pdb(clusterheads, "waterclusters.pdb")

    # check if there is a tleap input file:
    # if there is not then write a defualt file, if one already exist then use that one.
    # This way someone can perpare the receptor the way they want.
    if not (os.path.isfile("./tleap.in")):
        #os.system('cp rec.pdb rec_ori.pdb'
        file1 = open("tleap.in", 'w')
        file1.write(
            " set default PBradii mbondi2 \n source leaprc.ff14SB \n \n REC = loadpdb rec_ori.pdb \n WAT = loadpdb water1.pdb \n COM = combine {REC WAT} \n saveamberparm REC rec.leap.prm7 rec.leap.rst7 \n saveamberparm COM rec.1wat.leap.prm7 rec.1wat.leap.rst7 \n charge REC \n quit \n"
        )
        file1.close()
    else:
        print "using pre-existing tleap.in"

    # cut -c 24-28 rec_ori.pdb | sort -u | wc -l
    numres = 290

    if not (os.path.isfile("./min.in")):
        file2 = open("min.in", 'w')
        #file2.write(" 01mi.in: equil minimization with Cartesian restraints /n &cntrl /n imin=1, maxcyc=3000, ncyc = 1500, /n ntpr=100, /n ntwr=100000000,  /n ntr=1, /n restraint_wt=100.0, /n restraintmask= ':1-%d & !@H' /n / /n "%(numres))
        file2.write(
            " min.in: minimization with GB \n &cntrl \n imin = 1, maxcyc = 100, ncyc = 50,  ntmin = 1, \n igb=1, \n ntx = 1, ntc = 1, ntf = 1, \n ntb = 0, ntp = 0, \n ntwx = 1000, ntwe = 0, ntpr = 1000, \n cut = 999.9, \n ntr = 1, \n restraintmask = '!@H=', \n restraint_wt = 0.1, \n / \n "
        )
        file2.close()

    #fh = open('waters.pdb','r')
    fh = open('waterclusters.pdb', 'r')
    lines = fh.readlines()
    fh.close()

    fh = open('water1.pdb', 'w')
    fh.write(lines[0])
    fh.close()

    os.system("setenv AMBERHOME = /nfs/soft/amber/amber14")
    os.system("$AMBERHOME/bin/tleap -s -f tleap.in > ! tleap.out")

    # minimize the receptor alone.
    os.system(
        "$AMBERHOME/bin/sander -O -i min.in -o min.out -p rec.leap.prm7 -c rec.leap.rst7 -ref min.rst7 -x min.mdcrd -inf min.info -r min.rst7"
    )

    # loop over all waters, run a minimization on each water in the context of the receptor.
    count = 1
    for line in lines:
        name = "water_" + str(count)
        print "we are minimzing " + name
        fh = open(name + ".pdb", 'w')
        fh.write(line)
        fh.close()
        os.system("python /nfs/home/tbalius/zzz.scripts/add_h_to_wat.py " +
                  name + ".pdb")
        #print "cat rec.leap.rst7 "+name+".pdb.rst7 > "+name+".rst7"
        #os.system("cat rec.leap.rst7 "+name+".pdb.rst7 > "+name+".rst7")
        fh = open('rec.leap.rst7', 'r')
        fh2 = open(name + '.rst7', 'w')
        linecount = 0
        for line in fh:
            if linecount == 1:
                num = int(line.split()[0])
                num = num + 3
                fh2.write('%d\n' % num)
            else:
                fh2.write(line)
            linecount = linecount + 1
        fh.close()
        fh = open(name + ".pdb.rst7", 'r')
        for line in fh:
            fh2.write(line)
        fh.close()
        fh2.close()
        #exit()
        os.system("$AMBERHOME/bin/ambpdb -p rec.1wat.leap.prm7 < " + name +
                  ".rst7 > before_min_" + name + ".pdb")
        os.system("$AMBERHOME/bin/sander -O -i min.in -o min." + name +
                  ".out -p rec.1wat.leap.prm7 -c " + name + ".rst7 -ref " +
                  name + ".rst7 -x min." + name + ".mdcrd -inf min." + name +
                  ".info -r min." + name + ".rst7")
        os.system("$AMBERHOME/bin/ambpdb -p rec.1wat.leap.prm7 < min." + name +
                  ".rst7 > min." + name + ".pdb")
        count = count + 1
Пример #9
0
def cluster_water_pdb(inputfilename, cutoff, outputfilename, denominator):
    bonds = []
    bond_dic = {}
    duplicate = {}
    pdb_ori = pdb_lib.read_pdb(inputfilename)
    pdb_water = []
    pdb_other = []
    for atom in pdb_ori:
        #print atom.resname
        if atom.resname == "HOH":
            pdb_water.append(atom)
        else:
            pdb_other.append(atom)
    numwat = len(pdb_water)
    for i in range(numwat):
        for j in range(i + 1, numwat):
            dist = dist_wat(pdb_water[i], pdb_water[j])
            #print i, j, pdb_water[i].resnum, pdb_water[j].resnum, dist
            if (dist == 0.0):  # discard duplicates
                duplicate[j] = i
            elif (dist < cutoff):
                #bonds.append([i,j, dist])
                bonds.append([i, j])
                print "bond: %d %d %f" % (i, j, dist)
                bond_dic[i] = 1
                bond_dic[j] = 1

    clusters = {}  # what cluster belongs to each atom
    count = 0
    #
    for bond in bonds:
        if bond[0] in clusters:  # if the starting point is in a cluster then put the ending point in that same cluster
            clusters[bond[1]] = clusters[bond[0]]
        elif bond[
                1] in clusters:  # if the ending point is in a cluster then put the starting point in that same cluster
            clusters[bond[0]] = clusters[bond[1]]
        else:  # nether point is in a cluster
            clusters[bond[0]] = count
            clusters[bond[1]] = count
            count = count + 1
    for i in range(numwat):
        if not i in bond_dic and not i in duplicate:
            # then singlton.
            clusters[i] = count
            count = count + 1

    cluster_lists = {}  # list of atoms in each cluster
    print clusters
    for key in clusters.keys():  # key is atom
        print key, clusters[key]
        cluster_lists[clusters[key]] = []  # intialize

    for key in clusters.keys():
        cluster_lists[clusters[key]].append(key)

    cluster_centers = []
    cluster_median = []
    for cluster in cluster_lists:
        X = 0.0
        Y = 0.0
        Z = 0.0
        count = 0
        for atom in cluster_lists[cluster]:
            X = X + pdb_water[atom].X
            Y = Y + pdb_water[atom].Y
            Z = Z + pdb_water[atom].Z
            count = count + 1
        X = X / count
        Y = Y / count
        Z = Z / count

        #alpha = float(count)/float(numwat)
        alpha = float(count) / denominator
        temp_atom_info = pdb_lib.PDB_atom_info('', "A", "HOH", cluster, " O  ",
                                               cluster, X, Y, Z, alpha, False)

        # find median water
        min_val = [-1, 1000]
        for i in range(len(cluster_lists[cluster])):
            dist = dist_wat(temp_atom_info,
                            pdb_water[cluster_lists[cluster][i]])
            if dist < min_val[1]:
                min_val[0] = i
                min_val[1] = dist

        cluster_centers.append(temp_atom_info)
        cluster_median.append(
            pdb_water[cluster_lists[cluster][min_val[0]]])  # g

    pdb_lib.output_pdb(cluster_centers, outputfilename + "_center.pdb")
    pdb_lib.output_pdb(cluster_median, outputfilename + "_median.pdb")
Пример #10
0
    print c.X
    print c.Y
    print c.Z
    new_wat.append(c)
    #count = count+1
    c1 = copy.copy(c)
    new_wat.append(c1)
    count = count + 1
    new_wat[count].atomname = " H1 "  #= line[12:16
    new_wat[count].X = new_wat[count].X + H1[0] - O[0]  #
    new_wat[count].Y = new_wat[count].Y + H1[1] - O[1]  #
    new_wat[count].Z = new_wat[count].Z + H1[2] - O[2]  #
    c2 = copy.copy(c)
    new_wat.append(c2)
    count = count + 1
    new_wat[count].atomname = " H2 "  #= line[12:16
    new_wat[count].X = new_wat[count].X + H2[0] - O[0]  #
    new_wat[count].Y = new_wat[count].Y + H2[1] - O[1]  #
    new_wat[count].Z = new_wat[count].Z + H2[2] - O[2]  #
    fh.write(
        " %11.7f %11.7f %11.7f %11.7f %11.7f %11.7f\n %11.7f %11.7f %11.7f\n" %
        (new_wat[0].X, new_wat[0].Y, new_wat[0].Z, new_wat[1].X, new_wat[1].Y,
         new_wat[1].Z, new_wat[2].X, new_wat[2].Y, new_wat[2].Z))

fh.close()
pdb_lib.output_pdb(new_wat, pdb_file + "_new")

#  len(c)
#  for a in c:
#      print a
def cluster_water_pdb(inputfilename, cutoff, outputfilename, denominator):
    bonds = []
    bond_dic = {}
    duplicate = {}
    pdb_ori = pdb_lib.read_pdb(inputfilename)[0]
    pdb_water = []
    pdb_other = []
    #print inputfilename
    for atom in pdb_ori:
        #print atom.resname
        if atom.resname == "HOH":
            pdb_water.append(atom)
        else:
            pdb_other.append(atom)
    numwat = len(pdb_water)
    print "%s contains %d waters" % (inputfilename, numwat)
    if numwat == 0:
        print "There are zero waters in the file.  If this is not right make sure that there are no TER in the file and re-run. "
    for i in range(numwat):
        for j in range(i + 1, numwat):
            dist = dist_wat(pdb_water[i], pdb_water[j])
            #print i, j, pdb_water[i].resnum, pdb_water[j].resnum, dist
            if (dist == 0.0):  # discard duplicates
                duplicate[j] = i
            elif (dist < cutoff):
                #bonds.append([i,j, dist])
                bonds.append([i, j])
                print "bond: %d %d %f" % (i, j, dist)
                bond_dic[i] = 1
                bond_dic[j] = 1

    clusters = {}  # what cluster belongs to each atom
    count = 0
    #
    for bond in bonds:
        if bond[0] in clusters:  # if the starting point is in a cluster then put the ending point in that same cluster
            clusters[bond[1]] = clusters[bond[0]]
        elif bond[
                1] in clusters:  # if the ending point is in a cluster then put the starting point in that same cluster
            clusters[bond[0]] = clusters[bond[1]]
        else:  # nether point is in a cluster
            clusters[bond[0]] = count
            clusters[bond[1]] = count
            count = count + 1
    for i in range(numwat):
        if not i in bond_dic and not i in duplicate:
            # then singlton.
            clusters[i] = count
            count = count + 1

    cluster_lists = {}  # list of atoms in each cluster
    print clusters
    for key in clusters.keys():  # key is atom
        print key, clusters[key]
        cluster_lists[clusters[key]] = []  # intialize

    for key in clusters.keys():
        cluster_lists[clusters[key]].append(key)

    cluster_centers = []
    cluster_median = []
    for cluster in cluster_lists:
        X = 0.0
        Y = 0.0
        Z = 0.0
        count = 0
        for atom in cluster_lists[cluster]:
            X = X + pdb_water[atom].X
            Y = Y + pdb_water[atom].Y
            Z = Z + pdb_water[atom].Z
            count = count + 1
        X = X / count
        Y = Y / count
        Z = Z / count

        #alpha = float(count)/float(numwat)
        alpha = float(count) / denominator
        temp_atom_info = pdb_lib.PDB_atom_info('', "A", "HOH", cluster, " O  ",
                                               cluster, X, Y, Z, 0.0, alpha,
                                               False)

        # find median water
        min_val = [-1, 1000]
        for i in range(len(cluster_lists[cluster])):
            dist = dist_wat(temp_atom_info,
                            pdb_water[cluster_lists[cluster][i]])
            if dist < min_val[1]:
                #min_val[0] = i  # this index of the cluster member
                min_val[0] = cluster_lists[cluster][
                    i]  # index of the water, simplifies call
                min_val[1] = dist
                pdb_water[cluster_lists[cluster][
                    i]].bfact = temp_atom_info.bfact  # make both report the number of waters/ dem in b column

        cluster_centers.append(temp_atom_info)
        #cluster_median.append(pdb_water[cluster_lists[cluster][min_val[0]]]) # when we saved the index of the cluster instead of index of water
        cluster_median.append(pdb_water[min_val[0]])  #

    pdb_lib.output_pdb(cluster_centers, outputfilename + "_center.pdb")
    pdb_lib.output_pdb(cluster_median, outputfilename + "_median.pdb")