示例#1
0
def main():
    """
    Function to call if run from command line.
    """

    from helper import cmdline

    cmdline.initializeParser(__description__, __date__)
    cmdline.addOption(short_flag="c",
                      long_flag="collapse_repeat",
                      action="store_true",
                      default=True,
                      help="Collapse repeated molecule names")

    file_list, options = cmdline.parseCommandLine()

    out = []
    for pdb_file in file_list:

        f = open(pdb_file, 'r')
        pdb = f.readlines()
        f.close()

        olig_output = pdbOligomer(pdb, options.collapse_repeat)

        pdb_id = pdb_file[:pdb_file.index(".pdb")]
        pdb_id = os.path.split(pdb_id)[-1]

        out.append("%s\t%s" % (pdb_id, olig_output))

    out = ["%i\t%s\n" % (i, l) for i, l in enumerate(out)]
    out.insert(0, "\tpdb\tcompounds\tchains\tWYSIWYG\n")

    print "".join(out)
def main():
    """
    Function to call if this is called from command line.
    """

    from helper import cmdline

    # Parse command line
    cmdline.initializeParser(__description__, __date__)
    cmdline.addOption(short_flag="r",
                      long_flag="renumber-het",
                      action="store_false",
                      default=True,
                      help="include hetatm entries in the renumbering.")

    file_list, options = cmdline.parseCommandLine()

    for pdb_file in file_list:

        # Read in the pdb file
        f = open(pdb_file, 'r')
        pdb = f.readlines()
        f.close()

        out = pdbAtomRenumber(pdb, options.renumber_het)
        if len(file_list) == 1:
            print "".join(out)
        else:
            out_file = "%s_renum.pdb" % pdb_file[:-4]
            g = open(out_file, 'w')
            g.writelines(out)
            g.close()
def main():
    """
    Main function, if called from command line.
    """

    from helper import cmdline

    # Parse command line
    cmdline.initializeParser(__description__,__date__)
    cmdline.addOption(short_flag="c",
                      long_flag="cutoff",
                      action="store",
                      default=4,
                      help="cutoff for disulfide bonds",
                      nargs=1,
                      type=float)
    

    file_list, options = cmdline.parseCommandLine()

    for pdb_file in file_list:

        f = open(pdb_file,'r')
        pdb = f.readlines()
        f.close()

        free_cys, disulfide_bonds = pdbDisulfide(pdb,options.cutoff)

        out = ["<<%s>>\nFree Cys:        " % pdb_file]
        out.extend(["%s, " % c.strip() for c in free_cys])
        out.append("\nDisulfide Bonds: ")
        out.extend(["%s, " % d.strip() for d in disulfide_bonds])

        print "".join(out)
示例#4
0
def main():
    """
    Function to call if run from command line.
    """

    from helper import cmdline

    cmdline.initializeParser(__description__, __date__)
    cmdline.addOption(short_flag="s",
                      long_flag="skip_boring",
                      action="store_true",
                      default=False,
                      help="Ignore boring ligands (from BORING_LIGANDS list)")

    file_list, options = cmdline.parseCommandLine()

    out = []
    for pdb_file in file_list:

        f = open(pdb_file, 'r')
        pdb = f.readlines()
        f.close()

        pdb_id = pdb_file[:pdb_file.index(".pdb")]
        pdb_id = os.path.split(pdb_id)[-1]

        ligand_out = pdbLigand(pdb, options.skip_boring)

        out.append("%s\t%s" % (pdb_id, ligand_out))

    out = ["%i\t%s\n" % (i, l) for i, l in enumerate(out)]

    print "".join(out)
示例#5
0
def main():
    """
    Function to call if run from command line.
    """

    from helper import cmdline

    
    cmdline.initializeParser(__description__,__date__)
    cmdline.addOption(short_flag="s",
                          long_flag="skip_boring",
                          action="store_true",
                          default=False,
                    help="Ignore boring ligands (from BORING_LIGANDS list)")

    file_list, options = cmdline.parseCommandLine()

    out = []
    for pdb_file in file_list:
        
        f = open(pdb_file,'r')
        pdb = f.readlines()
        f.close()

        pdb_id = pdb_file[:pdb_file.index(".pdb")]
        pdb_id = os.path.split(pdb_id)[-1] 
        
        ligand_out = pdbLigand(pdb,options.skip_boring)

        out.append("%s\t%s" % (pdb_id,ligand_out))

    out = ["%i\t%s\n" % (i,l) for i, l in enumerate(out)]

    print "".join(out)
示例#6
0
def main():
    """
    Function to call if run from command line.
    """

    from helper import cmdline

    
    cmdline.initializeParser(__description__,__date__)
    cmdline.addOption(short_flag="s",
                          long_flag="some_option",
                          action="store",
                          default=None,
                          help="Set some option",
                          nargs=1,
                          type=int)


    file_list, options = cmdline.parseCommandLine()

    for pdb_file in file_list:
        
        f = open(pdb_file,'r')
        pdb = f.readlines()
        f.close()

        pdbTemplate(pdb)
示例#7
0
def main():
    """
    Main function, if called from command line.
    """

    from helper import cmdline

    # Parse command line
    cmdline.initializeParser(__description__, __date__)
    cmdline.addOption(short_flag="c",
                      long_flag="cutoff",
                      action="store",
                      default=4,
                      help="cutoff for disulfide bonds",
                      nargs=1,
                      type=float)

    file_list, options = cmdline.parseCommandLine()

    for pdb_file in file_list:

        f = open(pdb_file, 'r')
        pdb = f.readlines()
        f.close()

        free_cys, disulfide_bonds = pdbDisulfide(pdb, options.cutoff)

        out = ["<<%s>>\nFree Cys:        " % pdb_file]
        out.extend(["%s, " % c.strip() for c in free_cys])
        out.append("\nDisulfide Bonds: ")
        out.extend(["%s, " % d.strip() for d in disulfide_bonds])

        print "".join(out)
示例#8
0
def main():
    """
    Creates directories in output_dir for each pdb file in input_dir and copies
    pdb files into respective directories.
    """

    from helper import cmdline

    cmdline.initializeParser(__description__,__date__)
    cmdline.addOption(short_flag="o",
                      long_flag="output",
                      action="store",
                      default=".",
                      help="output directory",
                      nargs=1,
                      type=str)
    file_list, options = cmdline.parseCommandLine()
    
    if not os.path.isdir(options.output):
        err = "Output directory \"%s\" does not exist!" % options.output
        raise cmdline.parser.error(err)

    for pdb_file in file_list:
        
        short_pdb = os.path.split(pdb_file)[-1][:-4]

        # Create the directory if it does not already exist
        dir = os.path.join(options.output,short_pdb)
        if not os.path.isdir(dir):
            os.mkdir(dir)

        # Copy the pdb into its directory
        shutil.copy(pdb_file,dir)
示例#9
0
def main():
    """
    Function to call if run from command line.
    """

    from helper import cmdline

    cmdline.initializeParser(__description__, __date__)
    cmdline.addOption(short_flag="s",
                      long_flag="some_option",
                      action="store",
                      default=None,
                      help="Set some option",
                      nargs=1,
                      type=int)

    file_list, options = cmdline.parseCommandLine()

    for pdb_file in file_list:

        f = open(pdb_file, 'r')
        pdb = f.readlines()
        f.close()

        pdbTemplate(pdb)
示例#10
0
def main():
    """
    Function to call if run from command line.
    """

    from helper import cmdline

    cmdline.initializeParser(__description__, __date__)

    file_list, options = cmdline.parseCommandLine()

    out = []
    for pdb_file in file_list:

        f = open(pdb_file, 'r')
        pdb = f.readlines()
        f.close()

        exp_data = pdbExperiment(pdb)

        pdb_id = pdb_file[:pdb_file.index(".pdb")]
        pdb_id = os.path.split(pdb_id)[-1]

        out.append("%30s%s" % (pdb_id, exp_data))

    out = ["%10i%s\n" % (i, x) for i, x in enumerate(out)]
    out.insert(
        0, "%10s%30s%48s%40s%5s%10s%10s%10s\n" %
        (" ", "pdb", "protein", "organism", "exp", "res", "r_value", "r_free"))

    print "".join(out)
示例#11
0
def main():
    """
    Call if this is called from the command line.
    """

    cmdline.initializeParser(__description__, __date__)

    file_list, options = cmdline.parseCommandLine()

    out = []
    for pdb_file in file_list:

        # Read in input file
        f = open(pdb_file, "r")
        pdb = f.readlines()
        f.close()

        # Calculate torsion angles and secondary structure
        dihedrals, labels = pdbTorsion(pdb)

        # Print out results in pretty fashion
        short_pdb = os.path.split(pdb_file)[-1][:-4]
        for i in range(len(dihedrals)):
            out.append(
                '%30s%4s "%5s"%10.2F%10.2F\n'
                % (short_pdb, labels[i][0], labels[i][1], dihedrals[i][0], dihedrals[i][1])
            )

    out = ["%10i%s" % (i, x) for i, x in enumerate(out)]

    header = "%10s%30s%4s%8s%10s%10s\n" % (" ", "pdb", "aa", "res", "phi", "psi")
    out.insert(0, header)
    print "".join(out)
示例#12
0
def main():
    """
    Function to call if run from command line.
    """

    from helper import cmdline

    
    cmdline.initializeParser(__description__,__date__)

    file_list, options = cmdline.parseCommandLine()

    out = []
    for pdb_file in file_list:
        
        f = open(pdb_file,'r')
        pdb = f.readlines()
        f.close()

        exp_data = pdbExperiment(pdb)
        
        pdb_id = pdb_file[:pdb_file.index(".pdb")]
        pdb_id = os.path.split(pdb_id)[-1] 

        out.append("%30s%s" % (pdb_id,exp_data))

    out = ["%10i%s\n" % (i,x) for i, x in enumerate(out)]
    out.insert(0,"%10s%30s%48s%40s%5s%10s%10s%10s\n" % (" ","pdb","protein",
               "organism","exp","res","r_value","r_free"))
    
    print "".join(out)
示例#13
0
def main():
    """
    Function to call if run from command line.
    """

    import os
    from helper import cmdline

    cmdline.initializeParser(__description__, __date__)
    cmdline.addOption(short_flag="p",
                      long_flag="probe",
                      action="store",
                      default=1.4,
                      help="Water probe radius",
                      nargs=1,
                      type=float)

    file_list, options = cmdline.parseCommandLine()

    for pdb_file in file_list:

        f = open(pdb_file, 'r')
        pdb = f.readlines()
        f.close()

        neighbors = pdbWaterContact(pdb, options.probe)

        residues = neighbors.keys()
        residues.sort()

        for r in residues:
            print "\"%5s\"%10i" % (r, len(neighbors[r]))
def main():
    """
    Function to call if this is called from command line.
    """

    from helper import cmdline

    # Parse command line
    cmdline.initializeParser(__description__,__date__)
    cmdline.addOption(short_flag="r",
                      long_flag="renumber-het",
                      action="store_false",
                      default=True,
                      help="include hetatm entries in the renumbering.")

    file_list, options = cmdline.parseCommandLine()

    for pdb_file in file_list:
    
        # Read in the pdb file
        f = open(pdb_file,'r')
        pdb = f.readlines()
        f.close()

        out = pdbAtomRenumber(pdb,options.renumber_het)
        if len(file_list) == 1:
            print "".join(out)
        else:
            out_file = "%s_renum.pdb" % pdb_file[:-4]
            g = open(out_file,'w')
            g.writelines(out)
            g.close()
示例#15
0
def main():
    """
    Function to call if this is called from command line.
    """

    from helper import cmdline

    # Parse command line
    cmdline.initializeParser(__description__,__date__)

    file_list, options = cmdline.parseCommandLine()

    for pdb_file in file_list:
    
        # Read in the pdb file
        f = open(pdb_file,'r')
        pdb = f.readlines()
        f.close()

        out = pdbAtomRenumber(pdb)
        if len(file_list) == 1:
            print "".join(out)
        else:
            out_file = "%s_renum.pdb" % pdb_file[:-4]
            g = open(out_file,'w')
            g.writelines(out)
            g.close()
示例#16
0
def main():
    """
    Function to call if this is called from command line.
    """

    from helper import cmdline

    # Parse command line
    cmdline.initializeParser(__description__, __date__)

    file_list, options = cmdline.parseCommandLine()

    for pdb_file in file_list:

        # Read in the pdb file
        f = open(pdb_file, 'r')
        pdb = f.readlines()
        f.close()

        out = pdbAtomRenumber(pdb)
        if len(file_list) == 1:
            print "".join(out)
        else:
            out_file = "%s_renum.pdb" % pdb_file[:-4]
            g = open(out_file, 'w')
            g.writelines(out)
            g.close()
示例#17
0
def main():
    """
    If called from command line...
    """

    from helper import cmdline

    # Parse command line
    cmdline.initializeParser(__description__,__date__)
    cmdline.addOption(short_flag="c",
                      long_flag="coord",
                      action="store_true",
                      default=False,
                      help="write out PDB file with re-centered ASU")
    file_list, options = cmdline.parseCommandLine()

    for pdb_file in file_list:

        # Load in pdb file
        f = open(pdb_file,'r')
        pdb = f.readlines()
        f.close()

        translation, pdb_out = pdbCenterasu(pdb, options.coord)
        print "%s %s" % (pdb_file, tuple(translation.ravel()))
        # If the user wants re-centered PDB files, write them out
        if options.coord:
            out_file = "%s_asucenter.pdb" % pdb_file[:-4]
            g = open(out_file,'w')
            g.writelines(pdb_out)
            g.close()
示例#18
0
def main():
    """
    Call if this is called from the command line.
    """

    cmdline.initializeParser(__description__, __date__)

    file_list, options = cmdline.parseCommandLine()

    out = []
    for pdb_file in file_list:

        # Read in input file
        f = open(pdb_file, 'r')
        pdb = f.readlines()
        f.close()

        # Calculate torsion angles and secondary structure
        dihedrals, labels = pdbTorsion(pdb)

        # Print out results in pretty fashion
        short_pdb = os.path.split(pdb_file)[-1][:-4]
        for i in range(len(dihedrals)):
            out.append("%30s%4s \"%s\"%10.2F%10.2F\n" %\
                       (short_pdb,labels[i][:3],labels[i][4:],
                        dihedrals[i][0],dihedrals[i][1]))

    out = ["%10i%s" % (i, x) for i, x in enumerate(out)]

    header = "%10s%30s%4s%8s%10s%10s\n" % (" ", "pdb", "aa", "res", "phi",
                                           "psi")
    out.insert(0, header)
    print "".join(out)
def main():
    """
    Function to call if run from command line.
    """

    import os
    from helper import cmdline

    
    cmdline.initializeParser(__description__,__date__)
    cmdline.addOption(short_flag="p",
                          long_flag="probe",
                          action="store",
                          default=1.4,
                          help="Water probe radius",
                          nargs=1,
                          type=float)


    file_list, options = cmdline.parseCommandLine()

    for pdb_file in file_list:
        
        f = open(pdb_file,'r')
        pdb = f.readlines()
        f.close()

        neighbors = pdbWaterContact(pdb,options.probe)

        residues = neighbors.keys()
        residues.sort()

        for r in residues:
            print "\"%5s\"%10i" % (r,len(neighbors[r]))
示例#20
0
def main():
    """
    Function to call if run from command line.
    """

    from helper import cmdline

    cmdline.initializeParser(__description__,__date__)
    cmdline.addOption(short_flag="a",
                          long_flag="addH",
                          action="store_true",
                          default=False,
                          help="Add hydrogens automatically if missing.")


    file_list, options = cmdline.parseCommandLine()

    out = []
    for pdb_file in file_list:
        
        f = open(pdb_file,'r')
        pdb = f.readlines()
        f.close()

        short_pdb = os.path.split(pdb_file)[-1][:-4]

        # See if the file is in the proper (wacky) UHBD format
        ca = [l for l in pdb if l[0:4] == "ATOM" and l[12:15] == "CA "]
        if len(ca) == 0:

            # If not in the correct format, try to add hydrogens
            print "%s does not appear to have polar hydrogens!" % pdb_file
            if options.addH:
                
                import pdb_addH

                print "Attempting to add hydrogens with pdb_addH.py"
                try:
                    pdb = pdb_addH.pdbAddH(pdb,pdb_id=pdb_file[:-4])
       
                    g = open("%sH.pdb" % pdb_file[:-4],"w")
                    g.writelines(pdb)
                    g.close() 

                except pdb_addH.PdbAddHError, (strerror):
                    print "Addition of hydrogens failed for %s" % file
                    print strerror
                    sys.exit()
            else:
                print "Please add hydrogens to the file using pdb_addH.py"
                sys.exit()

        # Calculate the dipole moment and write out
        try:
            moment = pdbMoment(pdb)
        except PdbMomentError, (strerror):
            print "Problem with %s" % pdb_file
            print strerror
            sys.exit()
def main():
    """
    Takes command line arguments and calls distFilter
    """

    from helper import cmdline
   
    # Parse command line
    cmdline.initializeParser(__description__,__date__)
    cmdline.addOption(short_flag="r",
                      long_flag="residue",
                      action="store",
                      default=None,
                      help="residue for comparison (REQUIRED).")
    cmdline.addOption(short_flag="c",
                      long_flag="column_input",
                      action="store",
                      default=[60,66,"    NA"],
                      help="X Y SELECT; take lines in which column " + \
                           "defined by line[X:Y] matches SELECT",
                      nargs=3)
    cmdline.addOption(short_flag="a",
                      long_flag="atom",
                      default="N",
                      action="store",
                      help="Atom type to compare")
    file_list, options = cmdline.parseCommandLine()
    
    # Make sure that a residue is specified
    if options.residue == None:
        err = "Residue must be specified with -r flag!"
        cmdline.parser.error(err)

    # Make sure arguments are sane
    try:
        residue = int(options.residue)
        column = [int(options.column_input[0]),int(options.column_input[1])]
        select = options.column_input[2]
        atom = options.atom
    except ValueError:
        err = "Mangled arguments!"
        cmdline.parser.error(err)

    # Run script for all files in file_list
    for pdb_file in file_list:
 
        # Read in pdb file
        f = open(pdb_file,'r')
        pdb = f.readlines()
        f.close()

        # Perform analysis
        dist = distFilter(pdb,residue,atom,column,select)

        # dump output to stdout
        out = ["%10i%10.3F\n" % (i,d) for i, d in enumerate(dist)]
        out.insert(0,"%10s%10s\n" % (" ","dist"))
        print "".join(out)
示例#22
0
def main():
    """
    Takes command line arguments and calls distFilter
    """

    from helper import cmdline

    # Parse command line
    cmdline.initializeParser(__description__, __date__)
    cmdline.addOption(short_flag="r",
                      long_flag="residue",
                      action="store",
                      default=None,
                      help="residue for comparison (REQUIRED).")
    cmdline.addOption(short_flag="c",
                      long_flag="column_input",
                      action="store",
                      default=[60,66,"    NA"],
                      help="X Y SELECT; take lines in which column " + \
                           "defined by line[X:Y] matches SELECT",
                      nargs=3)
    cmdline.addOption(short_flag="a",
                      long_flag="atom",
                      default="N",
                      action="store",
                      help="Atom type to compare")
    file_list, options = cmdline.parseCommandLine()

    # Make sure that a residue is specified
    if options.residue == None:
        err = "Residue must be specified with -r flag!"
        cmdline.parser.error(err)

    # Make sure arguments are sane
    try:
        residue = int(options.residue)
        column = [int(options.column_input[0]), int(options.column_input[1])]
        select = options.column_input[2]
        atom = options.atom
    except ValueError:
        err = "Mangled arguments!"
        cmdline.parser.error(err)

    # Run script for all files in file_list
    for pdb_file in file_list:

        # Read in pdb file
        f = open(pdb_file, 'r')
        pdb = f.readlines()
        f.close()

        # Perform analysis
        dist = distFilter(pdb, residue, atom, column, select)

        # dump output to stdout
        out = ["%10i%10.3F\n" % (i, d) for i, d in enumerate(dist)]
        out.insert(0, "%10s%10s\n" % (" ", "dist"))
        print "".join(out)
示例#23
0
def main():
    """
    Call if program called from command line.
    """

    from helper import cmdline
   
    # Parse command line
    cmdline.initializeParser(__description__,__date__)
    cmdline.addOption(short_flag="d",
                          long_flag="data_input",
                          action="store",
                          default=None,
                          help="FILE X Y; data from FILE columns X and Y",
                          nargs=3)
    cmdline.addOption(short_flag="a",
                          long_flag="abs_value",
                          default=False,
                          action="store_true",
                          help="Take absolute value of data in data file")
    cmdline.addOption(short_flag="s",
                      long_flag="set_value",
                      default=20.0,
                      action="store",
                      help="Single value to set the b-factors to.",
                      nargs=1,
                      type=float)

    file_list, options = cmdline.parseCommandLine()

    for pdb_file in file_list:
        # Read in file
        f = open(pdb_file,'r')
        pdb = f.readlines()
        f.close()
    
        # If a data file is specified, take the values from it and place in 
        # data_dict.  Otherwise, set all residues to 20.0
        if options.data_input != None:
       
            # Finish processing command line options
            file = options.data_input[0]
            col1 = int(options.data_input[1])
            col2 = int(options.data_input[2])
            if options.abs_value:
                abs_value = True
            else:
                abs_value = False

            data_dict = loadDataFile(file,col1,col2,abs_value)
        else:
            ca_list = [l for l in pdb if l[0:4] == "ATOM" and l[13:16] == "CA "]
            data_dict = dict([(ca[22:26].strip(),options.set_value)
                              for ca in ca_list])

        out = pdbBfactor(pdb,data_dict)

        print "".join(out)
示例#24
0
def main():
    """
    Function to call if run from command line.
    """

    from helper import cmdline

    cmdline.initializeParser(__description__, __date__)
    cmdline.addOption(short_flag="a",
                      long_flag="addH",
                      action="store_true",
                      default=False,
                      help="Add hydrogens automatically if missing.")

    file_list, options = cmdline.parseCommandLine()

    out = []
    for pdb_file in file_list:

        f = open(pdb_file, 'r')
        pdb = f.readlines()
        f.close()

        short_pdb = os.path.split(pdb_file)[-1][:-4]

        # See if the file is in the proper (wacky) UHBD format
        ca = [l for l in pdb if l[0:4] == "ATOM" and l[12:15] == "CA "]
        if len(ca) == 0:

            # If not in the correct format, try to add hydrogens
            print "%s does not appear to have polar hydrogens!" % pdb_file
            if options.addH:

                import pdb_addH

                print "Attempting to add hydrogens with pdb_addH.py"
                try:
                    pdb = pdb_addH.pdbAddH(pdb, pdb_id=pdb_file[:-4])

                    g = open("%sH.pdb" % pdb_file[:-4], "w")
                    g.writelines(pdb)
                    g.close()

                except pdb_addH.PdbAddHError, (strerror):
                    print "Addition of hydrogens failed for %s" % file
                    print strerror
                    sys.exit()
            else:
                print "Please add hydrogens to the file using pdb_addH.py"
                sys.exit()

        # Calculate the dipole moment and write out
        try:
            moment = pdbMoment(pdb)
        except PdbMomentError, (strerror):
            print "Problem with %s" % pdb_file
            print strerror
            sys.exit()
示例#25
0
def main():
    """
    Function to call if run from command line.
    """

    from helper import cmdline
    import pdb_splitnmr

    
    cmdline.initializeParser(__description__,__date__)
    cmdline.addOption(short_flag="r",
                      long_flag="resname",
                      action="store",
                      default="TRP",
                      help="look for contacts near specified resname",
                      nargs=1)
    cmdline.addOption(short_flag="n",
                      long_flag="resnum",
                      action="store",
                      default=None,
                      help="look for contacts near specified residue number",
                      nargs=1)
    cmdline.addOption(short_flag="d",
                      long_flag="distance",
                      action="store",
                      default=3.5,
                      help="distance cutoff for calling contacts",
                      nargs=1,
                      type=float)

    file_list, options = cmdline.parseCommandLine()

    if options.resnum != None:
        target_type = "resnum"
        target = int(options.resnum)
    else:
        target_type = "resname"
        target = options.resname


    out = []
    for pdb_file in file_list:
        
        f = open(pdb_file,'r')
        pdb = f.readlines()
        f.close()

        # Only take the first NMR model
        models = pdb_splitnmr.splitNMR(pdb)
        if len(models) > 0:
            pdb = models[0]

        tmp_out = pdbContacting(pdb,target,options.distance,target_type)

        out.extend(["%s\t%s" % (pdb_file[:-4],t) for t in tmp_out])

    return out
示例#26
0
def main():
    """
    Function to call if run from command line.
    """

    from helper import cmdline
    import pdb_splitnmr

    cmdline.initializeParser(__description__, __date__)
    cmdline.addOption(short_flag="r",
                      long_flag="resname",
                      action="store",
                      default="TRP",
                      help="look for contacts near specified resname",
                      nargs=1)
    cmdline.addOption(short_flag="n",
                      long_flag="resnum",
                      action="store",
                      default=None,
                      help="look for contacts near specified residue number",
                      nargs=1)
    cmdline.addOption(short_flag="d",
                      long_flag="distance",
                      action="store",
                      default=3.5,
                      help="distance cutoff for calling contacts",
                      nargs=1,
                      type=float)

    file_list, options = cmdline.parseCommandLine()

    if options.resnum != None:
        target_type = "resnum"
        target = int(options.resnum)
    else:
        target_type = "resname"
        target = options.resname

    out = []
    for pdb_file in file_list:

        f = open(pdb_file, 'r')
        pdb = f.readlines()
        f.close()

        # Only take the first NMR model
        models = pdb_splitnmr.splitNMR(pdb)
        if len(models) > 0:
            pdb = models[0]

        tmp_out = pdbContacting(pdb, target, options.distance, target_type)

        out.extend(["%s\t%s" % (pdb_file[:-4], t) for t in tmp_out])

    return out
示例#27
0
def main():
    """
    Function to call if run from command line.
    """

    from helper import cmdline

    
    cmdline.initializeParser(__description__,__date__)
    cmdline.addOption(short_flag="s",
                          long_flag="step",
                          action="store",
                          default=0.1,
                          help="Histogram step",
                          nargs=1,
                          type=float)


    file_list, options = cmdline.parseCommandLine()

    histogram = [[] for i in range(3)]
    for pdb_file in file_list:
        
        f = open(pdb_file,'r')
        pdb = f.readlines()
        f.close()

        tmp_hist = pdbIonDist(pdb,options.step)

        # If the new histogram is longer than the total histogram, expand the 
        # total histogram to take the new data
        if len(tmp_hist[0]) > len(histogram[0]):
            diff = len(tmp_hist[0]) - len(histogram[0])
            for i in xrange(3):
                histogram[i].extend([0 for j in xrange(diff)])

        # Take data from temporary histogram and append to total histogram
        for i in xrange(len(tmp_hist[0])):
            for j in xrange(3):
                histogram[j][i] += tmp_hist[j][i]

    # Create pretty output
    out = ["%10s%10s%10s%10s%10s\n" % (" ","dist","a-a","a-b","b-b")]
    for i in xrange(len(histogram[0])):
        step = options.step*i
        out.append("%10i%10.3F%10i%10i%10i\n" %
                   (i,step,histogram[0][i],histogram[1][i],histogram[2][i]))


    print "".join(out)
示例#28
0
def main():
    """
    If called from command line.
    """

    import sys
    from helper import cmdline

    # Parse command line
    cmdline.initializeParser(__description__, __date__)
    cmdline.addOption(short_flag="c",
                      long_flag="chain",
                      action="store",
                      default="all",
                      help="chain to select (separte mulitiple by commas)",
                      nargs=1,
                      type=str)
    cmdline.addOption(short_flag="r",
                      long_flag="residues",
                      default=[0, 0],
                      action="store",
                      help="residues to select",
                      nargs=2,
                      type=int)

    file_list, options = cmdline.parseCommandLine()

    for pdb_file in file_list:

        # Attempt to strip .pdb extension
        try:
            pdb_id = pdb_file[:pdb_file.index(".pdb")]
        except IndexError:
            pdb_id = pdb_file

        # Read file
        f = open(pdb_file, 'r')
        pdb = f.readlines()
        f.close()

        # Pop out subset
        pdb, chain, residues = pdbSubset(pdb, options.chain, options.residues)

        # Write to file
        out_file = "%s_%s_%i-%i.pdb" % (pdb_id, chain, residues[0],
                                        residues[1])
        g = open(out_file, 'w')
        g.writelines(pdb)
        g.close()
示例#29
0
def main():
    """
    Function to call if run from command line.
    """

    from helper import cmdline

    cmdline.initializeParser(__description__, __date__)
    cmdline.addOption(short_flag="s",
                      long_flag="step",
                      action="store",
                      default=0.1,
                      help="Histogram step",
                      nargs=1,
                      type=float)

    file_list, options = cmdline.parseCommandLine()

    histogram = [[] for i in range(3)]
    for pdb_file in file_list:

        f = open(pdb_file, 'r')
        pdb = f.readlines()
        f.close()

        tmp_hist = pdbIonDist(pdb, options.step)

        # If the new histogram is longer than the total histogram, expand the
        # total histogram to take the new data
        if len(tmp_hist[0]) > len(histogram[0]):
            diff = len(tmp_hist[0]) - len(histogram[0])
            for i in xrange(3):
                histogram[i].extend([0 for j in xrange(diff)])

        # Take data from temporary histogram and append to total histogram
        for i in xrange(len(tmp_hist[0])):
            for j in xrange(3):
                histogram[j][i] += tmp_hist[j][i]

    # Create pretty output
    out = ["%10s%10s%10s%10s%10s\n" % (" ", "dist", "a-a", "a-b", "b-b")]
    for i in xrange(len(histogram[0])):
        step = options.step * i
        out.append(
            "%10i%10.3F%10i%10i%10i\n" %
            (i, step, histogram[0][i], histogram[1][i], histogram[2][i]))

    print "".join(out)
示例#30
0
def main():
    """
    If called from command line.
    """

    import sys
    from helper import cmdline
   
    # Parse command line
    cmdline.initializeParser(__description__,__date__)
    cmdline.addOption(short_flag="c",
                          long_flag="chain",
                          action="store",
                          default="all",
                          help="chain to select (separte mulitiple by commas)",
                          nargs=1,
                          type=str)
    cmdline.addOption(short_flag="r",
                          long_flag="residues",
                          default=[0,0],
                          action="store",
                          help="residues to select",
                          nargs=2,
                          type=int)

    file_list, options = cmdline.parseCommandLine()

    for pdb_file in file_list:

        # Attempt to strip .pdb extension
        try:
            pdb_id = pdb_file[:pdb_file.index(".pdb")]
        except IndexError:
            pdb_id = pdb_file

        # Read file
        f = open(pdb_file,'r')
        pdb = f.readlines()
        f.close()

        # Pop out subset
        pdb, chain, residues = pdbSubset(pdb,options.chain,options.residues)
      
        # Write to file 
        out_file = "%s_%s_%i-%i.pdb" % (pdb_id,chain,residues[0],residues[1])
        g = open(out_file,'w')
        g.writelines(pdb)
        g.close()
示例#31
0
def main():
    """
    If called from command line...
    """

    from helper import cmdline

    # Parse command line
    cmdline.initializeParser(__description__,__date__)
    cmdline.addOption(short_flag="c",
                      long_flag="coord",
                      action="store_true",
                      default=False,
                      help="write out re-centered coordinates")
    cmdline.addOption(short_flag="m",
                      long_flag="mass",
                      action="store_false",
                      default=True,
                      help="weight atoms by their mass")
    cmdline.addOption(short_flag="a",
                      long_flag="hetatm",
                      action="store_true",
                      default=False,
                      help="include hetatms in center of mass calc")
    

    file_list, options = cmdline.parseCommandLine()
   
    for pdb_file in file_list:

        # Load in pdb file
        f = open(pdb_file,'r')
        pdb = f.readlines()
        f.close()

        center, pdb_out = pdbCentermass(pdb,options.coord,options.hetatm,
                                        options.mass)
        print "%s %s" % (pdb_file,"".join(center))

        # If the user wants re-centered coordinates, write them out
        if options.coord:
            out_file = "%s_center.pdb" % pdb_file[:-4]
            g = open(out_file,'w')
            g.writelines(pdb_out)
            g.close()
示例#32
0
def main():
    """
    If called from command line...
    """

    from helper import cmdline

    # Parse command line
    cmdline.initializeParser(__description__,__date__)
    cmdline.addOption(short_flag="c",
                      long_flag="coord",
                      action="store_true",
                      default=False,
                      help="write out re-centered coordinates")
    cmdline.addOption(short_flag="m",
                      long_flag="mass",
                      action="store_false",
                      default=True,
                      help="weight atoms by their mass")
    cmdline.addOption(short_flag="a",
                      long_flag="hetatm",
                      action="store_true",
                      default=False,
                      help="include hetatms in center of mass calc")
    

    file_list, options = cmdline.parseCommandLine()
   
    for pdb_file in file_list:

        # Load in pdb file
        f = open(pdb_file,'r')
        pdb = f.readlines()
        f.close()

        center, pdb_out = pdbCentermass(pdb,options.coord,options.hetatm,
                                        options.mass)
        print "%s %s" % (pdb_file,"".join(center))

        # If the user wants re-centered coordinates, write them out
        if options.coord:
            out_file = "%s_center.pdb" % pdb_file[:-4]
            g = open(out_file,'w')
            g.writelines(pdb_out)
            g.close()
示例#33
0
def main():
    """
    Function to call if called from the command line.
    """

    from helper import cmdline

    # Parse command line
    cmdline.initializeParser(__description__,__date__)
    cmdline.addOption(short_flag="a",
                      long_flag="align-out",
                      action="store_true",
                      default=False,
                      help="write out residue alignment file.")
    cmdline.addOption(short_flag="s",
                      long_flag="start-res",
                      action="store",
                      type=int,
                      default=None,
                      help="Start at residues s")
    
    file_list, options = cmdline.parseCommandLine()

    for pdb_file in file_list:
        
        f = open(pdb_file,'r')
        pdb = f.readlines()
        f.close()

        pdb_out, alignment = pdbResidueRenumber(pdb,options.start_res)

        short_pdb = os.path.split(pdb_file)[-1][:-4]
        g = open("%s_res-renum.pdb" % short_pdb,"w")
        g.writelines(pdb_out)
        g.close()

        if options.align_out:
            print "Residue alignment written out."

            alignment.insert(0,"#%s" % pdb_out[0])
            g = open("%s_res-algn.out" % short_pdb,'w')
            g.writelines(alignment)
            g.close()
def main():
    """
    Function to call if run from command line.
    """

    from helper import cmdline

    
    cmdline.initializeParser(__description__,__date__)
    cmdline.addOption(short_flag="c",
                          long_flag="ca_only",
                          action="store_true",
                          default=False,
                          help="Use only CA atoms")
    cmdline.addOption(short_flag="d",
                          long_flag="distance",
                          action="store",
                          default=3.5,
                          help="Distance cutoff to identify close contacts.",
                          nargs=1,
                          type=float)

    file_list, options = cmdline.parseCommandLine()

    for pdb_file in file_list:
        
        f = open(pdb_file,'r')
        pdb = f.readlines()
        f.close()

        output = pdbCloseContacts(pdb,options.ca_only,options.distance)

        out = []
        out.append("# Close contacts for %s using a %.3f distance cutoff.\n" % (pdb_file,options.distance))
        out.append("%10s%16s%16s%12s\n" % (" ","atom1","atom2","dist"))
        for i, o in enumerate(output):
            out.append("%10i \"%s\" \"%s\"%12.3f\n" % (i,o[0],o[1],o[2]))
    
        g = open("%s.close_contacts" % pdb_file,"w")
        g.writelines(out)
        g.close()
示例#35
0
def main():
    """
    Function to execute if called from command line.
    """

    import sys
    from helper import cmdline

    # Parse command line
    cmdline.initializeParser(__description__, __date__)
    cmdline.addOption(short_flag="c",
                      long_flag="chain",
                      action="store",
                      default="all",
                      help="chain to select",
                      nargs=1,
                      type=str)
    cmdline.addOption(short_flag="a",
                      long_flag="atomseq",
                      action="store_true",
                      default=False,
                      help="use ATOM sequence, not SEQRES")

    file_list, options = cmdline.parseCommandLine()

    # Extract sequence data
    for pdb_file in file_list:

        pdb_id = os.path.split(pdb_file)[-1][:-4]

        f = open(pdb_file, 'r')
        pdb = f.readlines()
        f.close()

        seq = pdbSeq2Fasta(pdb, pdb_id, options.chain, options.atomseq)

        file_mfasta = pdb_id + ".fasta"
        #print(seq)
        f = open(file_mfasta, 'w')
        f.write(seq)
        f.close()
示例#36
0
def main():
    """
    Function to call if run from command line.
    """

    from helper import cmdline

    cmdline.initializeParser(__description__, __date__)
    cmdline.addOption(short_flag="c",
                      long_flag="ca_only",
                      action="store_true",
                      default=False,
                      help="Use only CA atoms")
    cmdline.addOption(short_flag="d",
                      long_flag="distance",
                      action="store",
                      default=3.5,
                      help="Distance cutoff to identify close contacts.",
                      nargs=1,
                      type=float)

    file_list, options = cmdline.parseCommandLine()

    for pdb_file in file_list:

        f = open(pdb_file, 'r')
        pdb = f.readlines()
        f.close()

        output = pdbCloseContacts(pdb, options.ca_only, options.distance)

        out = []
        out.append("# Close contacts for %s using a %.3f distance cutoff.\n" %
                   (pdb_file, options.distance))
        out.append("%10s%16s%16s%12s\n" % (" ", "atom1", "atom2", "dist"))
        for i, o in enumerate(output):
            out.append("%10i \"%s\" \"%s\"%12.3f\n" % (i, o[0], o[1], o[2]))

        g = open("%s.close_contacts" % pdb_file, "w")
        g.writelines(out)
        g.close()
示例#37
0
def main():
    """
    Function to call if run from commmand line.
    """

    from helper import cmdline
    cmdline.initializeParser(__description__,__date__)
    file_list, options = cmdline.parseCommandLine()
    
    for pdb_file in file_list:

        f = open(pdb_file,'r')
        pdb = f.readlines()
        f.close()

        models = splitNMR(pdb)
        
        short_pdb = os.path.split(pdb_file)[-1][:-4]
        for index, model in enumerate(models):
            g = open("%s_%i.pdb" % (short_pdb,index),"w")
            g.writelines(model)
            g.close()
示例#38
0
def main():
    """
    Function to call if run from commmand line.
    """

    from helper import cmdline
    cmdline.initializeParser(__description__, __date__)
    file_list, options = cmdline.parseCommandLine()

    for pdb_file in file_list:

        f = open(pdb_file, 'r')
        pdb = f.readlines()
        f.close()

        models = splitNMR(pdb)

        short_pdb = os.path.split(pdb_file)[-1][:-4]
        for index, model in enumerate(models):
            g = open("%s_%i.pdb" % (short_pdb, index), "w")
            g.writelines(model)
            g.close()
示例#39
0
def main():
    """
    Function to execute if called from command line.
    """

    import sys
    from helper import cmdline

    # Parse command line
    cmdline.initializeParser(__description__,__date__)
    cmdline.addOption(short_flag="c",
                      long_flag="chain",
                      action="store",
                      default="all",
                      help="chain to select",
                      nargs=1,
                      type=str)
    cmdline.addOption(short_flag="a",
                      long_flag="atomseq",
                      action="store_true",
                      default=False,
                      help="use ATOM sequence, not SEQRES")
    

    file_list, options = cmdline.parseCommandLine()

    # Extract sequence data
    for pdb_file in file_list:
    
        pdb_id = os.path.split(pdb_file)[-1][:-4]
        
        f = open(pdb_file,'r')
        pdb = f.readlines()
        f.close()
        
        seq = pdbSeq2Fasta(pdb,pdb_id,options.chain,options.atomseq)

        print seq
示例#40
0
def main():
    """
    Main function to run if script is called from the command line.
    """

    from helper import cmdline
   
    # Parse command line
    cmdline.initializeParser(__description__,__date__)
    cmdline.addOption(short_flag="o",
                          long_flag="offset",
                          action="store",
                          default=0,
                          help="offset; num atoms to offset",
                          nargs=1,
                          type=int)
    file_list, options = cmdline.parseCommandLine()
    offset = options.offset


    # Offset pdb files in file_list
    out_files = []
    for f in file_list:
        out_files.append(pdbOffset(f,offset))

    # If it is a single file, dump to command line.  If it is a directory,
    # write each file to r%s % file.  
    if len(out_files) == 1:
        print out_files[0]
    else:
        for i, f in enumerate(file_list):
            out_name = list(os.path.split(f))
            out_name[1] = out_name[1][:-4]
            out_name = os.path.join(out_name[0],"%s_offset.pdb" % out_name[1])
            g = open(out_name,'w')
            g.write(out_files[i])
            g.close()
示例#41
0
def main():
    """
    Function to call if run from command line.
    """

    from helper import cmdline

    
    cmdline.initializeParser(__description__,__date__)
    cmdline.addOption(short_flag="c",
                          long_flag="collapse_repeat",
                          action="store_true",
                          default=True,
                          help="Collapse repeated molecule names")


    file_list, options = cmdline.parseCommandLine()

    out = []
    for pdb_file in file_list:
        
        f = open(pdb_file,'r')
        pdb = f.readlines()
        f.close()

        olig_output = pdbOligomer(pdb,options.collapse_repeat)
        
        pdb_id = pdb_file[:pdb_file.index(".pdb")]
        pdb_id = os.path.split(pdb_id)[-1] 

        out.append("%s\t%s" % (pdb_id,olig_output))

    out = ["%i\t%s\n" % (i,l) for i, l in enumerate(out)]
    out.insert(0,"\tpdb\tcompounds\tchains\tWYSIWYG\n")

    print "".join(out)
def main():
    """
    Function to call if called from the command line.
    """

    from helper import cmdline

    # Parse command line
    cmdline.initializeParser(__description__,__date__)
    cmdline.addOption(short_flag="a",
                      long_flag="align-out",
                      action="store_true",
                      default=False,
                      help="write out residue alignment file.")
    cmdline.addOption(short_flag="s",
                      long_flag="start-res",
                      action="store",
                      type=int,
                      default=None,
                      help="Make the first residue in the file have s")
    cmdline.addOption(short_flag="r",
                      long_flag="renumber-het",
                      action="store_false",
                      default=True,
                      help="include hetatm entries in the renumbering.")
    cmdline.addOption(short_flag="g",
                      long_flag="remove-gaps",
                      action="store_true",
                      default=False,
                      help="make the sequence numbering continuous (remove gaps)")
    cmdline.addOption(short_flag="c",
                      long_flag="chain",
                      action="store",
                      type=str,
                      default=None,
                      help="only renumber this chain")

    
    file_list, options = cmdline.parseCommandLine()

    for pdb_file in file_list:
        
        f = open(pdb_file,'r')
        pdb = f.readlines()
        f.close()

        pdb_out, alignment = pdbResidueRenumber(pdb,options.start_res,
                                                options.renumber_het,
                                                options.remove_gaps,
                                                options.chain)

        short_pdb = os.path.split(pdb_file)[-1][:-4]
        g = open("%s_res-renum.pdb" % short_pdb,"w")
        g.writelines(pdb_out)
        g.close()

        if options.align_out:
            print "Residue alignment written out."

            alignment.insert(0,"#%s" % pdb_out[0])
            g = open("%s_res-algn.out" % short_pdb,'w')
            g.writelines(alignment)
            g.close()
示例#43
0
def main():
    """
    Function to call if called from the command line.
    """

    from helper import cmdline

    # Parse command line
    cmdline.initializeParser(__description__, __date__)
    cmdline.addOption(short_flag="a",
                      long_flag="align-out",
                      action="store_true",
                      default=False,
                      help="write out residue alignment file.")
    cmdline.addOption(short_flag="s",
                      long_flag="start-res",
                      action="store",
                      type=int,
                      default=None,
                      help="Make the first residue in the file have s")
    cmdline.addOption(short_flag="r",
                      long_flag="renumber-het",
                      action="store_true",
                      default=True,
                      help="include hetatm entries in the renumbering.")
    cmdline.addOption(
        short_flag="g",
        long_flag="remove-gaps",
        action="store_true",
        default=False,
        help="make the sequence numbering continuous (remove gaps)")
    cmdline.addOption(short_flag="c",
                      long_flag="chain",
                      action="store",
                      type=str,
                      default=None,
                      help="only renumber this chain")

    file_list, options = cmdline.parseCommandLine()

    for pdb_file in file_list:

        f = open(pdb_file, 'r')
        pdb = f.readlines()
        f.close()

        pdb_out, alignment = pdbResidueRenumber(pdb, options.start_res,
                                                options.renumber_het,
                                                options.remove_gaps,
                                                options.chain)

        short_pdb = os.path.split(pdb_file)[-1][:-4]
        g = open("%s_res-renum.pdb" % short_pdb, "w")
        g.writelines(pdb_out)
        g.close()

        if options.align_out:
            print "Residue alignment written out."

            alignment.insert(0, "#%s" % pdb_out[0])
            g = open("%s_res-algn.out" % short_pdb, 'w')
            g.writelines(alignment)
            g.close()
示例#44
0
def main():
    """
    Function to call if run from command line.
    """

    from helper import cmdline

    
    cmdline.initializeParser(__description__,__date__)
    cmdline.addOption(short_flag="a",
                          long_flag="all",
                          action="store_true",
                          default=False,
                          help="Use all atoms (not just CA)")
    cmdline.addOption(short_flag="d",
                          long_flag="difference",
                          action="store",
                          default=None,
                          help="Take difference between two contact maps. " +\
                               "DIFFERENCE is a pdb file",
                          nargs=1,
                          type=str)


    file_list, options = cmdline.parseCommandLine()

    # If we are calculating a difference map, calculate this first.
    if options.difference != None:
        if not os.path.isfile(options.difference):
            print "\"%s\" is not a file!" % options.difference
            sys.exit()
        
        f = open(options.difference,'r')
        pdb = f.readlines()
        f.close()

        to_compare = pdbContact(pdb,options.all)


    for pdb_file in file_list:
        
        f = open(pdb_file,'r')
        pdb = f.readlines()
        f.close()

        dist = pdbContact(pdb,options.all)

        # Make sure the difference and main pdbs have the same number of atoms
        if options.difference != None:
            if len(dist) != len(to_compare):
                print "\"%s\" and \"%s\" do not have same number of atoms!" % \
                    (pdb_file,options.difference)
                sys.exit()

        # Write output
        out = []
        out.append("# Distance contact map for \"%s\".\n" % pdb_file)
        if options.difference != None:
            out.append("# Difference map to \"%s\".\n" % options.difference)
            out.append("#%9s%10s%10s%10s%10s%10s%10s\n" % 
                       ("atom1","atom2","d12","d12_r","dd12","mean","d/m"))
        else:
            out.append("#%9s%10s%10s\n" %  ("atom1","atom2","d12"))
                        
        for i in range(len(dist)):
            for j in range(len(dist)):
                out.append("%10i%10i%10.3F" % (i,j,dist[i][j]))

                if options.difference != None:
                    d = dist[i][j] - to_compare[i][j]
                    mean = (dist[i][j] + to_compare[i][j])/2.
                    if mean != 0:
                        d_m = d/mean
                    else:
                        d_m = 0

                    out.append("%10.3F%10.3F%10.3F%10.3F\n" % 
                               (to_compare[i][j],d,mean,d_m))
                else:
                    out.append("\n")
                               
            out.append("\n")
        out = "".join(out)
                
        short_pdb = os.path.split(pdb_file)[-1][:-4]
        g = open("%s_contact.txt" % short_pdb,'w')
        g.write(out)
        g.close()
示例#45
0
def main():
    """
    If called from the command line, execute this.
    """

    from helper import cmdline

    # Parse command line
    cmdline.initializeParser(__description__, __date__)
    cmdline.addOption(short_flag="a",
                      long_flag="atomseq",
                      action="store_true",
                      default=False,
                      help="use ATOM sequence, not SEQRES")
    cmdline.addOption(short_flag="f",
                      long_flag="freq",
                      action="store_true",
                      default=False,
                      help="write out amino acid frequencies")
    cmdline.addOption(short_flag="c",
                      long_flag="chain",
                      action="store",
                      default="all",
                      help="chain to analyze",
                      nargs=1,
                      type=str)

    file_list, options = cmdline.parseCommandLine()

    out = []
    for pdb_index, pdb_file in enumerate(file_list):

        # Read in pdb file
        f = open(pdb_file, 'r')
        pdb = f.readlines()
        f.close()

        # Calculate simple properties about protein charge
        try:
            count_dict, mw, pI, seq_type = pdbParam(pdb,
                                                    chain=options.chain,
                                                    use_atoms=options.atomseq)
        except PdbParamError, (strerror):
            print "Error processing file \"%s\":" % pdb_file
            print "%s" % (strerror)
            sys.exit()

        aa_list = count_dict.keys()
        aa_list.sort()

        # Calculate fraction ionizable
        total = float(sum(count_dict.values()))
        titr_aa_list = [aa for aa in aa_list if aa in PKA_DICT.keys()]
        titr_total = float(sum([count_dict[aa] for aa in titr_aa_list]))

        fx_titr = titr_total / total

        # Calculate the apparent charge
        acid = sum([count_dict[aa] for aa in ["ASP", "GLU"]])
        base = sum([count_dict[aa] for aa in ["HIS", "LYS", "ARG"]])
        app_charge = base - acid

        # Print to output in pretty way
        short_pdb = os.path.split(pdb_file)[-1][:-4]
        out.append("%30s%10s%10i%10.2F%10.2F%10i\n" %
                   (short_pdb, seq_type.strip(), mw, pI, fx_titr, app_charge))

        # Write out amino acid frequencies if requested
        if options.freq:

            total_freq = dict([(aa, count_dict[aa] / total) for aa in aa_list])
            titr_freq = dict([(aa, count_dict[aa] / titr_total)
                              for aa in titr_aa_list])

            freq_out = [
                5 * "%10s" % (" ", "aacid", "counts", "fx_total", "fx_titr")
            ]
            freq_out.append("\n")
            for aa_index, aa in enumerate(aa_list):
                if aa in titr_aa_list:
                    freq_out.append("%10i%10s%10i%10.2F%10.2F\n" %
                                    (aa_index, aa, count_dict[aa], 100 *
                                     total_freq[aa], 100 * titr_freq[aa]))
                else:
                    freq_out.append("%10i%10s%10i%10.2F%10s\n" %
                                    (aa_index, aa, count_dict[aa],
                                     100 * total_freq[aa], "NA"))

            g = open("%s_freq.txt" % (pdb_file[:-4]), "w")
            g.writelines(freq_out)
            g.close()
示例#46
0
def main():
    """
    Function to call if run from command line.
    """

    from helper import cmdline

    cmdline.initializeParser(__description__,__date__)
    cmdline.addOption(short_flag="p",
                      long_flag="probe_radius",
                      action="store",
                      default=1.4,
                      help="specify probe radius (A)",
                      nargs=1,
                      type=float)
    cmdline.addOption(short_flag="z",
                      long_flag="z_sample",
                      action="store",
                      default=0.05,
                      help="fraction of atom radius to sample on z",
                      nargs=1,
                      type=float)
    cmdline.addOption(short_flag="v",
                      long_flag="vdw_file",
                      action="store",
                      default=None,
                      help="specify custom vdw file",
                      nargs=1,
                      type=str)
    cmdline.addOption(short_flag="d",
                      long_flag="standard_dir",
                      action="store",
                      default=None,
                      help="specify location of custom standards directory",
                      nargs=1,
                      type=str)
    cmdline.addOption(short_flag="k",
                      long_flag="keep_temp",
                      action="store_true",
                      default=False,
                      help="keep temporary files")

    file_list, options = cmdline.parseCommandLine()

    print "Generating standards."
    standards = readStandards(options.standard_dir,options.probe_radius,
                              options.z_sample,options.vdw_file)

    for pdb_file in file_list:
        
        out = pdbSASA(pdb_file,options.probe_radius,options.z_sample,
                      options.vdw_file,options.keep_temp,standards)
        out = ["%10i%s" % (i,x) for i, x in enumerate(out)]

        out.insert(0,"%10s%10s%10s%12s%10s%10s\n" % \
                   (" ","atom","type","residue","abs","fract"))
        
        header = ["# Custom standards: %s\n" % options.standard_dir,
                  "# Custom radii file: %s\n" % options.vdw_file,
                  "# Probe radius: %.2F\n" % options.probe_radius,
                  "# Z-sampling: %.2F\n" % options.z_sample]
        out.insert(0,"".join(header))

              
        out_file = "%s_sasa.txt" % pdb_file[:-4]
        f = open(out_file,'w')
        f.writelines(out)
        f.close() 
示例#47
0
def main():
    """
    To be called if module run from command line.
    """

    from helper import cmdline
    
    # Parse command line
    cmdline.initializeParser(__description__,__date__)
    cmdline.addOption(short_flag="c",
                      long_flag="chain",
                      action="store",
                      default=None,
                      help="CHAIN to mutate",
                      nargs=1)
    cmdline.addOption(short_flag="r",
                      long_flag="residue",
                      action="store",
                      type="int",
                      default=None,
                      help="Residue to mutate (REQUIRED)",
                      nargs=1)
    cmdline.addOption(short_flag="m",
                      long_flag="mutation",
                      action="store",
                      default=None,
                      help="Three-letter name of mutation (REQUIRED)",
                      nargs=1)
    cmdline.addOption(short_flag="s",
                      long_flag="simple",
                      action="store_true",
                      default=False,
                      help="No atoms beyond CB added (i.e. no CHARMM)")
                      
    
 
    file_list, options = cmdline.parseCommandLine()    
    
    # Parse command line options
    
    if options.residue == None:
        err = "Residue (-r) argument is required!"
        raise cmdline.parser.error(err)
    else:
        residue = options.residue
        
    if options.mutation == None:
        err = "Mutation (-m) argument is required!"
        raise cmdline.parser.error(err)
    else:
        mutation = options.mutation
    
    chain = options.chain
    run_charmm = not options.simple   

    for file in file_list:

        f = open(file,'r')
        pdb = f.readlines()
        f.close()
        
        print "Loading %s" % file
        pdb_id = file[:-4]
        pdb, mutation_string = pdbMutator(pdb,residue,mutation,chain,
                                          run_charmm)
    
        out_file = "%s_%s.pdb" % (pdb_id,mutation_string)
        g = open(out_file,"w")
        g.writelines(pdb)
        g.close()

        print "Mutated pdb written to %s" % out_file
示例#48
0
def main():
    """
    Call if program called from command line.
    """
   
    # Parse command line
    cmdline.initializeParser(__description__,__date__)
    cmdline.addOption(short_flag="t",
                      long_flag="his_tautomers",
                      action="store",
                      default=None,
                      help="File containing his tautomers to use",
                      nargs=1)
    cmdline.addOption(short_flag="k",
                      long_flag="keep_temp",
                      action="store_true",
                      default=False,
                      help="Keep temporary files")
    cmdline.addOption(short_flag="f",
                      long_flag="full",
                      action="store_true",
                      default=False,
                      help="Add hydrogens for UHBD full calculation")
    cmdline.addOption(short_flag="b",
                      long_flag="hbond",
                      action="store",
                      default=None,
                      help="Write out hbonds to file",
                      nargs=1,
                      type=str)
    cmdline.addOption(short_flag="u",
                      long_flag="uhbd_style",
                      action="store_true",
                      default=False,
                      help="Write out in non-standard uhbd format")
    cmdline.addOption(short_flag="s",
                      long_flag="skip",
                      action="store_true",
                      default=True,
                      help="skip messed up pdb files")
    
 
    file_list, options = cmdline.parseCommandLine()    
    
    # Deal with his_tautomers file
    if options.his_tautomers != None:
    
        # Read in as a standard ascii file.
        his_types = cmdline.readFile(options.his_tautomers)
        try:
            his_types = [int(h) for h in his_types]
        
            # Make sure that entries are valid
            check = [h == 1 or h == 2 for h in his_types]
            if False in check:
                raise ValueError
        except ValueError:
            err = "His tautomer file can contain only 1's (HISB) and 2's (HISA)"
            cmdline.parser.error(err)
    else:
        his_types = None

    # Decide whether to keep temp files and how to format output
    keep_temp = options.keep_temp
    uhbd_style = options.uhbd_style
    hbond = options.hbond

    # Decide whether to add "full" hydrogens.
    if options.full:
        calc_type = "full"
    else:
        calc_type = "single"

    # Add hydrogens for every file in file_list
    file_list.sort()
    for file in file_list:
        pdb_id = os.path.split(file)[-1][:-4]
        out_file = "%sH.pdb" % pdb_id

        print "%s --> %s" % (file,out_file)

        # Load in file
        f = open(file,'r')
        pdb = f.readlines()
        f.close()
        
        # Add hydrogens
        try:
            pdb_out = pdbAddH(pdb,pdb_id,uhbd_style=uhbd_style,
                              his_types=his_types,
                              keep_temp=keep_temp,
                              calc_type=calc_type,
                              hbond=hbond)
        except PdbAddHError, (strerror):
            err = "Addition of hydrogens failed for %s\n" % file
            err += "Problem was with CHARMM\n.%s" % strerror
            print err

            if options.skip:
                print "CHARMM output written to error.log"
                g = open("error.log","a")
                g.write(err)
                g.write("charmm.out copied below\n%s\n" % (79*"-"))                

                h = open("charmm.out",'r')
                charmm_out = h.readlines()
                h.close()

                g.writelines(charmm_out)
                g.write("\n\n")
                g.close()

                continue
            else:
                sys.exit()

        # Dump to output file
        g = open(out_file,'w')
        g.writelines(pdb_out)
        g.close()
示例#49
0
def main():
    """
    Call if program executed from command line.
    """

    from helper import cmdline

    # Parse command line
    cmdline.initializeParser(__description__,__date__)
    cmdline.addOption(short_flag="d",
                      long_flag="dist",
                      action="store",
                      default=10.0,
                      help="distance cutoff for neighbors",
                      nargs=1,
                      type=float)
    cmdline.addOption(short_flag="s",
                      long_flag="seq",
                      action="store",
                      default=4,
                      help="minimum sequence separation between neighbors",
                      nargs=1,
                      type=int)
    cmdline.addOption(short_flag="r",
                      long_flag="residue",
                      action="store",
                      default=None,
                      help="only calculate neighbors for residue (i.e. LYS)",
                      nargs=1,
                      type=str)
    cmdline.addOption(short_flag="a",
                      long_flag="atom",
                      action="store",
                      default=None,
                      help="only calculate neighbors to an atom (i.e. CA)",
                      nargs=1,
                      type=str)
    cmdline.addOption(short_flag="e",
                      long_flag="everything",
                      action="store_true",
                      default=False,
                      help="find number of CB neighbors for all atoms in pdb")
    

    file_list, options = cmdline.parseCommandLine()

    out = []
    for pdb_file in file_list:
    
        f = open(pdb_file,'r')
        pdb = f.readlines()
        f.close()

        residue_list, num_neighbors = pdbNeighbors(pdb,options.dist,options.seq,
                                                   options.residue,options.atom,
                                                   options.everything)

        short_pdb = os.path.split(pdb_file)[-1][:-4]
        for i in range(len(residue_list)):
            out.append("%30s%17s%10i\n" % (short_pdb,residue_list[i],
                                           num_neighbors[i]))

    out = ["%10i%s" % (i,x) for i, x in enumerate(out)]
    out.insert(0,"%10s%30s%17s%10s\n" % (" ","pdb","residue","cb_neigh"))
    out.insert(0,"# Dist cutoff: %.2F\n# Seq cutoff:  %i\n" %
               (options.dist,options.seq))

    print "".join(out)
示例#50
0
def main():
    """
    To be called if module run from command line.
    """

    from helper import cmdline

    # Parse command line
    cmdline.initializeParser(__description__, __date__)
    cmdline.addOption(short_flag="c",
                      long_flag="chains",
                      action="store",
                      default=None,
                      help="File containing chains to take",
                      nargs=1)
    cmdline.addOption(short_flag="o",
                      long_flag="out_suffix",
                      action="store",
                      default="clean",
                      help="suffix to append to output pdb",
                      nargs=1)
    cmdline.addOption(short_flag="r",
                      long_flag="renumber_residues",
                      action="store_true",
                      default=False,
                      help="Renumber residues from 1")
    cmdline.addOption(short_flag="k",
                      long_flag="keep_temp",
                      action="store_true",
                      default=False,
                      help="Keep temporary files")
    cmdline.addOption(short_flag="s",
                      long_flag="skip",
                      action="store_true",
                      default=True,
                      help="skip messed up pdb files")
    cmdline.addOption(short_flag="f",
                      long_flag="fix_atoms",
                      action="store_false",
                      default=True,
                      help="fix atoms in original file")
    cmdline.addOption(short_flag="n",
                      long_flag="num_steps",
                      action="store",
                      default=500,
                      help="number of minimization steps",
                      nargs=1)

    file_list, options = cmdline.parseCommandLine()

    # Parse command line options
    if options.chains == None:
        chains = "all"
    else:
        chains = cmdline.readFile(options.chains)

    suffix = options.out_suffix
    renumber_residues = options.renumber_residues
    keep_temp = options.keep_temp
    fix_atoms = options.fix_atoms
    num_steps = options.num_steps

    for pdb_file in file_list:

        f = open(pdb_file, 'r')
        pdb = f.readlines()
        f.close()

        print "Loading %s" % pdb_file
        pdb_id = pdb_file[:-4]

        try:
            pdb = pdbClean(pdb, pdb_id, chains, renumber_residues, keep_temp,
                           fix_atoms, num_steps)
        except PdbCleanError, (strerror):
            err = "Error cleaning \"%s\"\n%s\n" % (pdb_file, strerror)
            print err,

            if options.skip:
                g = open("error.log", "a")
                g.write(err)
                g.close()
                continue
            else:
                sys.exit()

        out_file = "%s_%s.pdb" % (pdb_id, suffix)
        g = open(out_file, "w")
        g.writelines(pdb)
        g.close()

        print "Cleaned pdb written to %s" % out_file
示例#51
0
def main():
    """
    If called from command line, calculate energy and print to standard out.
    """

    from helper import cmdline

    # Parse command line
    cmdline.initializeParser(__description__, __date__)
    cmdline.addOption(short_flag="d",
                      long_flag="dielec_const",
                      action="store",
                      default=40.0,
                      help="dielectric constant",
                      nargs=1,
                      type=float)
    cmdline.addOption(short_flag="i",
                      long_flag="ionic_str",
                      default=100,
                      action="store",
                      help="ionic strength (mM)",
                      type=float)
    cmdline.addOption(short_flag="p",
                      long_flag="pH",
                      default=7.0,
                      action="store",
                      help="pH",
                      type=float)
    cmdline.addOption(short_flag="T",
                      long_flag="temperature",
                      default=298.0,
                      action="store",
                      help="temperature (K)",
                      type=float)
    cmdline.addOption(short_flag="t",
                      long_flag="titrate",
                      default=(None, None),
                      action="store",
                      help="titrate a variable",
                      type=str,
                      nargs=2)

    file_list, options = cmdline.parseCommandLine()

    # create dictionary of option values where values are in lists
    value_dict = dict([(k, [options.__dict__[k]])
                       for k in options.__dict__.keys() if k != "titrate"])

    # Deal with whether the user has specified a text file containing values
    # over which to titrate.
    if options.titrate != (None, None):
        available_options = value_dict.keys()

        # Make sure that the specified option can titrate and the file exists.
        titration = options.titrate[0]
        data_file = options.titrate[1]
        if titration in available_options:
            if os.path.isfile(data_file):
                f = open(data_file, 'r')
                titr_data = f.readlines()
                f.close()

                # Strip comments and blank lines, then re-join all lines
                titr_data = [
                    l for l in titr_data if l[0] != "#" and l.strip() != ""
                ]
                titr_data = "".join(titr_data)

                # Parse file
                try:
                    titr = [float(x) for x in titr_data.split()]
                    value_dict[titration] = titr[:]

                # Do some basic error checking
                except ValueError:
                    print "Data file \"%s\" has mangled data!" % data_file
                    sys.exit()

                if len(titr) == 0:
                    print "Data file \"%s\" is empty!" % data_file
                    sys.exit()
            else:
                print "Data file \"%s\" does not exist!" % data_file
                sys.exit()
        else:
            print "\"%s\" cannot be titrated!" % titration
            print "Available titrations:"
            for option in available_options:
                print "\t%s" % option
            sys.exit()

    out = [
        "%10s%30s%10s%10s%10s%10s%10s\n" %
        (" ", "pdb", "ep", "ion_str", "pH", "T", "dG")
    ]
    counter = 0
    for pdb_file in file_list:

        # Read in coordinates
        coord, pKa, charge = readPDB(pdb_file)
        short_pdb = os.path.split(pdb_file)[-1][:-4]

        # Determine electrostatic energy, titrating over all relavent variables
        for temperature in value_dict["temperature"]:
            for pH in value_dict["pH"]:
                for ionic_str in value_dict["ionic_str"]:
                    for dielec in value_dict["dielec_const"]:

                        energy = pdbCoulomb(coord, pKa, charge, dielec,
                                            ionic_str, pH, temperature)

                        # Write out results
                        out.append("%10i%30s%10.3F%10.3F%10.3F%10.3F%10.3F\n" %
                                   (counter, short_pdb, dielec, ionic_str, pH,
                                    temperature, energy))
                        counter += 1

    print "".join(out)
示例#52
0
def main():
    """
    Function to call if run from command line.
    """

    from helper import cmdline

    cmdline.initializeParser(__description__,__date__)
    cmdline.addOption(short_flag="w",
                      long_flag="wij_file",
                      action="store",
                      default=None,
                      help="Specify a pre-generated wij file",
                      nargs=1,
                      type=str)
    cmdline.addOption(short_flag="p",
                      long_flag="protein_dielec",
                      action="store",
                      default=4.,
                      help="Protein dielectric constant",
                      nargs=1,
                      type=float)
    cmdline.addOption(short_flag="s",
                      long_flag="solvent_dielec",
                      action="store",
                      default=78.5,
                      help="Solvent dielectric constant",
                      nargs=1,
                      type=float)
    cmdline.addOption(short_flag="b",
                      long_flag="ion_radius",
                      action="store",
                      default=2.,
                      help="Radius of ion (angstroms)",
                      nargs=1,
                      type=float)
    cmdline.addOption(short_flag="r",
                      long_flag="protein_radius",
                      action="store",
                      default=18.,
                      help="Radius of protein (angstroms)",
                      nargs=1,
                      type=float)
    cmdline.addOption(short_flag="d",
                      long_flag="depth",
                      action="store",
                      default=0.,
                      help="Depth of sidechain burial (angstroms)",
                      nargs=1,
                      type=float)
    cmdline.addOption(short_flag="T",
                      long_flag="temperature",
                      action="store",
                      default=298.16,
                      help="Temperature (Kelvin)",
                      nargs=1,
                      type=float)
    cmdline.addOption(short_flag="i",
                      long_flag="ionic_strengths",
                      action="store",
                      default=None,
                      help="File with set of ionic strengths (M)",
                      nargs=1,
                      type=str)
    cmdline.addOption(short_flag="k",
                      long_flag="keep_temp",
                      action="store_true",
                      default=False,
                      help="Keep temporary files")

    file_list, options = cmdline.parseCommandLine()

    
    # Generate wij file with all ij potentials
    if options.wij_file != None:
        wij_file = options.wij_file
        if not os.path.isfile(wij_file):
            err = "Specified wij file \"%s\" does not exist!" % wij_file
            raise  SATKError(err)
    else:

        # If a file with ionic strengths is specified, use it.
        if options.ionic_strengths != None:
            if not os.path.isile(ionic_strengths):
                err = "Ionic strengths file \"%s\" could not be found!" % \
                    options.ionic_strengths
            
            f = open(ionic_strengths,'r')
            lines = f.readlines()
            f.close()

            salt_list = []
            lines = [l for l in lines if l[0] != "#" and l.strip() != ""]
            for line in lines:
                salt_list.extend([float(entry) for entry in line])
            salt_list.sort()

        else:
            salt_list = [0.001,0.005,0.01,0.05,0.1,0.5,1.0]


        # Create wij file using the command line options specified
        wij_file = "wij.wij"
        runMkwij(wij_file,Dint=options.protein_dielec,
                          Dsolv=options.solvent_dielec,
                          T=options.temperature,
                          a=options.ion_radius+options.protein_radius,
                          b=options.protein_radius,
                          g=options.depth,
                          salts=salt_list)


    # Run satk on all files in file_list
    for pdb_file in file_list:

        pdb_tuple = os.path.split(pdb_file)
        if pdb_tuple[0] != "":
            shutil.copy(pdb_file,pdb_tuple[1])

        pdb_file = pdb_tuple[1]

        pdbSatk(pdb_file,wij_file=wij_file,keep_temp=options.keep_temp)
示例#53
0
def main():
    """
    To be called if module run from command line.
    """

    from helper import cmdline

    # Parse command line
    cmdline.initializeParser(__description__, __date__)
    cmdline.addOption(short_flag="c",
                      long_flag="chain",
                      action="store",
                      default=None,
                      help="CHAIN to mutate",
                      nargs=1)
    cmdline.addOption(short_flag="r",
                      long_flag="residue",
                      action="store",
                      type="int",
                      default=None,
                      help="Residue to mutate (REQUIRED)",
                      nargs=1)
    cmdline.addOption(short_flag="m",
                      long_flag="mutation",
                      action="store",
                      default=None,
                      help="Three-letter name of mutation (REQUIRED)",
                      nargs=1)
    cmdline.addOption(short_flag="s",
                      long_flag="simple",
                      action="store_true",
                      default=False,
                      help="No atoms beyond CB added (i.e. no CHARMM)")

    file_list, options = cmdline.parseCommandLine()

    # Parse command line options

    if options.residue == None:
        err = "Residue (-r) argument is required!"
        raise cmdline.parser.error(err)
    else:
        residue = options.residue

    if options.mutation == None:
        err = "Mutation (-m) argument is required!"
        raise cmdline.parser.error(err)
    else:
        mutation = options.mutation

    chain = options.chain
    run_charmm = not options.simple

    for file in file_list:

        f = open(file, 'r')
        pdb = f.readlines()
        f.close()

        print "Loading %s" % file
        pdb_id = file[:-4]
        pdb, mutation_string = pdbMutator(pdb, residue, mutation, chain,
                                          run_charmm)

        out_file = "%s_%s.pdb" % (pdb_id, mutation_string)
        g = open(out_file, "w")
        g.writelines(pdb)
        g.close()

        print "Mutated pdb written to %s" % out_file
示例#54
0
def main():
    """
    To be called if module run from command line.
    """

    from helper import cmdline
    
    # Parse command line
    cmdline.initializeParser(__description__,__date__)
    cmdline.addOption(short_flag="c",
                      long_flag="chains",
                      action="store",
                      default=None,
                      help="File containing chains to take",
                      nargs=1)
    cmdline.addOption(short_flag="o",
                      long_flag="out_suffix",
                      action="store",
                      default="clean",
                      help="suffix to append to output pdb",
                      nargs=1)
    cmdline.addOption(short_flag="r",
                      long_flag="renumber_residues",
                      action="store_true",
                      default=False,
                      help="Renumber residues from 1")
    cmdline.addOption(short_flag="k",
                      long_flag="keep_temp",
                      action="store_true",
                      default=False,
                      help="Keep temporary files")
    cmdline.addOption(short_flag="s",
                      long_flag="skip",
                      action="store_true",
                      default=True,
                      help="skip messed up pdb files")
    cmdline.addOption(short_flag="f",
                      long_flag="fix_atoms",
                      action="store_false",
                      default=True,
                      help="fix atoms in original file")   
    cmdline.addOption(short_flag="n",
                      long_flag="num_steps",
                      action="store",
                      default=500,
                      help="number of minimization steps",
                      nargs=1)

 
    file_list, options = cmdline.parseCommandLine()    
   
    # Parse command line options
    if options.chains == None:
        chains = "all"
    else:
        chains = cmdline.readFile(options.chains)
    
    suffix = options.out_suffix
    renumber_residues = options.renumber_residues
    keep_temp = options.keep_temp
    fix_atoms = options.fix_atoms 
    num_steps = options.num_steps   
 
    for pdb_file in file_list:

        f = open(pdb_file,'r')
        pdb = f.readlines()
        f.close()
        
        print "Loading %s" % pdb_file
        pdb_id = pdb_file[:-4]

        try:
            pdb = pdbClean(pdb,pdb_id,chains,renumber_residues,keep_temp,
                           fix_atoms,num_steps)
        except PdbCleanError, (strerror):
            err = "Error cleaning \"%s\"\n%s\n" % (pdb_file,strerror)
            print err,

            if options.skip:
                g = open("error.log","a")
                g.write(err)
                g.close()
                continue
            else:
                sys.exit()

        out_file = "%s_%s.pdb" % (pdb_id,suffix)
        g = open(out_file,"w")
        g.writelines(pdb)
        g.close()

        print "Cleaned pdb written to %s" % out_file