Esempio n. 1
0
def pdbMutator(pdb,residue,mutation,chain=None,run_charmm=True):
    """
    Standardize a pdb file: remove HETATM and ANISOU entries, renumber atoms,
    take only a particular chain, remove alternate conformations.
    """

    # grab header
    header = [l for l in pdb if l[0:6] not in pdb_clean.COORD_RECORDS and
                                l[0:6] not in pdb_clean.DEPRECATED_RECORDS]

    # Grab coordinates 
    coord = [l for l in pdb if l[0:6] == "ATOM  "]
    if pdb_clean.pdbCheck(coord):
        err = "There are no ATOM entries in this pdb file!" 
        raise MutatorError(err)

    coord, original_aa = mutateResidue(coord,residue,mutation,chain)
    mutation_string = "%s%i%s" % (AA3_TO_AA1[original_aa],residue,
                                  AA3_TO_AA1[mutation])
    
    # Set up log
    log = ["REMARK  %s introduced by pdb_mutator ([email protected])\n" % \
           mutation_string]
    log_fmt = "REMARK   - %s\n"
    log.append(log_fmt % ("Process time: %s" % time.asctime()))
    if chain == None:
        log.append(log_fmt % ("Mutation introduced on all chains"))
    else:
        log.append(log_fmt % ("Mutation introduced on chain %s" % chain))
    
    # Add missing atoms using CHARMM
    if run_charmm:
        print log_fmt % "Adding mutated side chain using CHARMM",
        seqres = [l for l in header if l[0:6] == "SEQRES"]
        coord = pdb_clean.addMissingAtoms(coord,seqres)
        log.append(log_fmt % "Mutated sidechain built with CHARMM")
    
    # Renumber atoms from 1
    coord = pdb_atom_renumber.pdbAtomRenumber(coord)
    log.append(log_fmt % "Renumbered atoms from 1")
    print log[-1],

    # Standardize atom-type on far right pdb column
    coord = ["%s           %s  \n" % (c[:66],c[13]) for c in coord]
    log.append(log_fmt % "Atom types were standardized.")
    print log[-1],
    
    # Final check
    if pdb_clean.pdbCheck(coord):
        err = "Unknown error occured and pdb has been mangled!"
        raise MutatorError(err)

    # Return processed pdb file.
    out_pdb = []
    out_pdb.extend(log)
    out_pdb.extend(header)
    out_pdb.extend(coord)

    return out_pdb, mutation_string
Esempio n. 2
0
def pdbClean(pdb,pdb_id="temp",chains="all",renumber_residues=False,
             keep_temp=False,fix_atoms=True,num_steps=500):
    """
    Standardize a pdb file:
        - Remove waters, ligands, and other HETATMS
        - Convert modified residues (i.e. Se-Met) to the normal residue
        - Remove alternate conformations (taking first in pdb file)
        - Find and remove residues with missing backbone atoms
        - 
        - Take only the specified chain
        - Renumber residues from 1
    """

    # Set up log
    log = ["REMARK  PDB processed using pdb_clean.py ([email protected])\n"]
    log_fmt = "REMARK   - %s\n"
    log.append(log_fmt % ("Process time: %s" % time.asctime()))

    # Check pdb files for Brookhaven-added error warnings (CAVEAT and OBSLTE)
    error = [l for l in pdb if l[0:6] in ERROR_RECORDS]
    if len(error) != 0:
        err = "PDB might have problem!\n" + "".join(error)
        raise PdbCleanError(err)

    # Grab pdb header, excluding coordinates and deprecated records.
    header = [l for l in pdb if l[0:6] not in COORD_RECORDS]
    
    # Convert non-standard amino acids to standard ones
    coord = [l for l in pdb if l[0:6] in COORD_RECORDS]
    coord, header, converted = convertModifiedAA(coord,header)
    if len(converted) != 0:
        log.append(log_fmt % "Modified amino acids converted.")
        print log[-1],
        log.extend(converted)
    if pdbCheck(coord):
        err = "Modified amino acid converter removed all atoms!  Mangled pdb!"
        raise PdbCleanError(err)

    # Strip all entries in COORD_RECORDS except ATOM
    coord = [l for l in coord if l[0:6] == "ATOM  "]
    if pdbCheck(coord):
        err = "There are no ATOM entries in this pdb file!" 
        raise PdbCleanError(err)
    else:
        log.append(log_fmt % "HETATM entries removed.")
        print log[-1],

    # Grab only the chain we want, if specified 
    if chains != "all":
        coord = [l for l in coord if l[21] in chains]
        log.append(log_fmt % ("Took only chain %r." % chains))
        print log[-1],
        if pdbCheck(coord):
            err = "Chain filter (%r) removed all atoms in pdb file!" % chains
            raise PdbCleanError(err)

    # Strip alternate conformations 
    coord, skipped = stripACS(coord)
    if len(skipped) != 0:
        log.append(log_fmt % "Alternate conformations were removed.")
        print log[-1],
        log.extend(skipped)
    if pdbCheck(coord):
        err = "ACS stripper removed all atoms!  Mangled pdb file."
        raise PdbCleanError(err)

    # Check for missing backbone atoms; these residues are deleted
    coord, removed = backboneCheck(coord)
    if len(removed) != 0:
        log.append(log_fmt % "Residues with missing backbone atoms removed.")
        print log[-1],
        log.extend(removed)
    if pdbCheck(coord):
        err = "Backbone checker removed all atoms!  Mangled pdb file."
        raise PdbCleanError(err)
    
    # Add missing atoms using CHARMM
    print log_fmt % "Adding heavy atoms using CHARMM.",
    seqres = [l for l in header if l[0:6] == "SEQRES"]
    coord = addMissingAtoms(coord,seqres,keep_temp,renumber_residues,pdb_id,
                            fix_atoms,num_steps)
    log.append(log_fmt % "Missing heavy atoms were added with CHARMM.")
    
    # Renumber residues if requested
    if renumber_residues:
        log.append(log_fmt % "Residues renumbered from one.")
        print log[-1],
        
    # Renumber atoms from 1
    coord = pdb_atom_renumber.pdbAtomRenumber(coord)
    log.append(log_fmt % "Renumbered atoms from 1")
    print log[-1],

    # Standardize atom-type on far right pdb column
    coord = ["%s           %s  \n" % (c[:66],c[13]) for c in coord]
    log.append(log_fmt % "Atom types were standardized.")
    print log[-1],
    
    # Final check
    if pdbCheck(coord):
        err = "Unknown error occured and pdb has been mangled!"
        raise PdbCleanError(err)

    log = ["%-79s\n" % (l.strip()) for l in log]
    try:
        remark_pos = [l[0:6] for l in header].index("REMARK")
    except ValueError:
        remark_pos = 0

    # Return processed pdb file, placing log after preliminary remarks.
    out_pdb = []
    out_pdb.extend(header)
    out_pdb.extend(log)
    out_pdb.extend(coord)

    return out_pdb
Esempio n. 3
0
def pdbMutator(pdb, residue, mutation, chain=None, run_charmm=True):
    """
    Standardize a pdb file: remove HETATM and ANISOU entries, renumber atoms,
    take only a particular chain, remove alternate conformations.
    """

    # grab header
    header = [
        l for l in pdb if l[0:6] not in pdb_clean.COORD_RECORDS
        and l[0:6] not in pdb_clean.DEPRECATED_RECORDS
    ]

    # Grab coordinates
    coord = [l for l in pdb if l[0:6] == "ATOM  "]
    if pdb_clean.pdbCheck(coord):
        err = "There are no ATOM entries in this pdb file!"
        raise MutatorError(err)

    coord, original_aa = mutateResidue(coord, residue, mutation, chain)
    mutation_string = "%s%i%s" % (AA3_TO_AA1[original_aa], residue,
                                  AA3_TO_AA1[mutation])

    # Set up log
    log = ["REMARK  %s introduced by pdb_mutator ([email protected])\n" % \
           mutation_string]
    log_fmt = "REMARK   - %s\n"
    log.append(log_fmt % ("Process time: %s" % time.asctime()))
    if chain == None:
        log.append(log_fmt % ("Mutation introduced on all chains"))
    else:
        log.append(log_fmt % ("Mutation introduced on chain %s" % chain))

    # Add missing atoms using CHARMM
    if run_charmm:
        print log_fmt % "Adding mutated side chain using CHARMM",
        seqres = [l for l in header if l[0:6] == "SEQRES"]
        coord = pdb_clean.addMissingAtoms(coord, seqres)
        log.append(log_fmt % "Mutated sidechain built with CHARMM")

    # Renumber atoms from 1
    coord = pdb_atom_renumber.pdbAtomRenumber(coord)
    log.append(log_fmt % "Renumbered atoms from 1")
    print log[-1],

    # Standardize atom-type on far right pdb column
    coord = ["%s           %s  \n" % (c[:66], c[13]) for c in coord]
    log.append(log_fmt % "Atom types were standardized.")
    print log[-1],

    # Final check
    if pdb_clean.pdbCheck(coord):
        err = "Unknown error occured and pdb has been mangled!"
        raise MutatorError(err)

    # Return processed pdb file.
    out_pdb = []
    out_pdb.extend(log)
    out_pdb.extend(header)
    out_pdb.extend(coord)

    return out_pdb, mutation_string
Esempio n. 4
0
def pdbClean(pdb,
             pdb_id="temp",
             chains="all",
             renumber_residues=False,
             keep_temp=False,
             fix_atoms=True,
             num_steps=500):
    """
    Standardize a pdb file:
        - Remove waters, ligands, and other HETATMS
        - Convert modified residues (i.e. Se-Met) to the normal residue
        - Remove alternate conformations (taking first in pdb file)
        - Find and remove residues with missing backbone atoms
        - 
        - Take only the specified chain
        - Renumber residues from 1
    """

    # Set up log
    log = ["REMARK  PDB processed using pdb_clean.py ([email protected])\n"]
    log_fmt = "REMARK   - %s\n"
    log.append(log_fmt % ("Process time: %s" % time.asctime()))

    # Check pdb files for Brookhaven-added error warnings (CAVEAT and OBSLTE)
    error = [l for l in pdb if l[0:6] in ERROR_RECORDS]
    if len(error) != 0:
        err = "PDB might have problem!\n" + "".join(error)
        raise PdbCleanError(err)

    # Grab pdb header, excluding coordinates and deprecated records.
    header = [l for l in pdb if l[0:6] not in COORD_RECORDS]

    # Convert non-standard amino acids to standard ones
    coord = [l for l in pdb if l[0:6] in COORD_RECORDS]
    coord, header, converted = convertModifiedAA(coord, header)
    if len(converted) != 0:
        log.append(log_fmt % "Modified amino acids converted.")
        print log[-1],
        log.extend(converted)
    if pdbCheck(coord):
        err = "Modified amino acid converter removed all atoms!  Mangled pdb!"
        raise PdbCleanError(err)

    # Strip all entries in COORD_RECORDS except ATOM
    coord = [l for l in coord if l[0:6] == "ATOM  "]
    if pdbCheck(coord):
        err = "There are no ATOM entries in this pdb file!"
        raise PdbCleanError(err)
    else:
        log.append(log_fmt % "HETATM entries removed.")
        print log[-1],

    # Grab only the chain we want, if specified
    if chains != "all":
        coord = [l for l in coord if l[21] in chains]
        log.append(log_fmt % ("Took only chain %r." % chains))
        print log[-1],
        if pdbCheck(coord):
            err = "Chain filter (%r) removed all atoms in pdb file!" % chains
            raise PdbCleanError(err)

    # Strip alternate conformations
    coord, skipped = stripACS(coord)
    if len(skipped) != 0:
        log.append(log_fmt % "Alternate conformations were removed.")
        print log[-1],
        log.extend(skipped)
    if pdbCheck(coord):
        err = "ACS stripper removed all atoms!  Mangled pdb file."
        raise PdbCleanError(err)

    # Check for missing backbone atoms; these residues are deleted
    coord, removed = backboneCheck(coord)
    if len(removed) != 0:
        log.append(log_fmt % "Residues with missing backbone atoms removed.")
        print log[-1],
        log.extend(removed)
    if pdbCheck(coord):
        err = "Backbone checker removed all atoms!  Mangled pdb file."
        raise PdbCleanError(err)

    # Add missing atoms using CHARMM
    print log_fmt % "Adding heavy atoms using CHARMM.",
    seqres = [l for l in header if l[0:6] == "SEQRES"]
    coord = addMissingAtoms(coord, seqres, keep_temp, renumber_residues,
                            pdb_id, fix_atoms, num_steps)
    log.append(log_fmt % "Missing heavy atoms were added with CHARMM.")

    # Renumber residues if requested
    if renumber_residues:
        log.append(log_fmt % "Residues renumbered from one.")
        print log[-1],

    # Renumber atoms from 1
    coord = pdb_atom_renumber.pdbAtomRenumber(coord)
    log.append(log_fmt % "Renumbered atoms from 1")
    print log[-1],

    # Standardize atom-type on far right pdb column
    coord = ["%s           %s  \n" % (c[:66], c[13]) for c in coord]
    log.append(log_fmt % "Atom types were standardized.")
    print log[-1],

    # Final check
    if pdbCheck(coord):
        err = "Unknown error occured and pdb has been mangled!"
        raise PdbCleanError(err)

    log = ["%-79s\n" % (l.strip()) for l in log]
    try:
        remark_pos = [l[0:6] for l in header].index("REMARK")
    except ValueError:
        remark_pos = 0

    # Return processed pdb file, placing log after preliminary remarks.
    out_pdb = []
    out_pdb.extend(header)
    out_pdb.extend(log)
    out_pdb.extend(coord)

    return out_pdb