Beispiel #1
0
    def change_name(self, new_name):
        """
        Changes the residues name.
        to a new name (as a long abbreviation if modified)
        """
        if new_name not in alphabet:
            new_name = alphabet.get_short_original(ANY_RESIDUE).long_abbrev
        aentry = alphabet[new_name]
        self.resname = aentry.pdb_abbrev
        self.long_abbrev = aentry.long_abbrev

        if new_name in STANDARD_BASES:
            # standard base
            self.modified = False
            self.id = (' ', self.id[1], self.id[2])
        elif aentry.original_base.upper() in "X":
            # unknown residues --> water, ions.
            self.modified = False
        else:
            # modified base
            self.modified = True
            self.id = ('H_' + aentry.pdb_abbrev, self.id[1], self.id[2])
            if aentry.pdb_abbrev == 'UNK':
                abbrev = '0' * (3 - len(aentry.new_abbrev)) + aentry.new_abbrev
                self.resname = abbrev
                self.id = ('H_' + abbrev, self.id[1], self.id[2])

        self._clear_caches()
Beispiel #2
0
    def __init__(self, pdb_residue, alphabet_entry=None, new_atoms=True):
        """
        Arguments:
        - residue as a Bio.PDB.Residue instance
        - optional: AlphabetEntry instance, if it is not given, the residue
                    is identified using BaseRecognizer (slow)
        """
        Residue.__init__(self, pdb_residue.id, pdb_residue.resname, '    ')
        self.number = pdb_residue.id[1]
        self.disordered = pdb_residue.disordered
        self.has_double_coord = self.__check_double_coord(pdb_residue)
        self.modified = None
        self.long_abbrev = None
        if alphabet_entry:
            abbrev = alphabet_entry.long_abbrev
        else:
            try:
                abbrev = self.br.identify_resi(pdb_residue)
            except BaseRecognitionError:
                abbrev = alphabet.get_short_original(ANY_RESIDUE)
        self.change_name(abbrev)

        self.identifier = str(self.id[1]).strip() + self.id[2].strip()
        self.__create_atoms(pdb_residue, new_atoms)

        # caches for H-bond calculation --> faster
        self._donors = None
        self._acceptors = None
        self._donor_hydrogens = {}
Beispiel #3
0
def validate_alphabet(alpha):
    """Checks residue names."""
    if alphabet.has_key(str(alpha)):
        return alphabet[str(alpha)].long_abbrev
    else:
        try:
            return alphabet.get_short_original(str(alpha)).long_abbrev
        except AlphabetError:
            pass
    raise ParameterError("Bad parameter: '%s' must be a valid residue name."%str(alpha))
 def set_sequence(self, seq):
     """
     Parses the sequence from a string 
     and produces a list of AlphabetEntries.
     """
     if type(seq) == str:
         x = 0
         while x < len(seq):
             if seq[x] == ' ':
                 raise SequenceError(
                     'Sequence %s should not contain whitespace characters'
                     % seq)
             elif seq[x] == '0':
                 if RE_NEW_NOMENCLATURE.match(seq[x:(x + 4)]):
                     if seq[x + 3] in SPECIAL_ABBREVS:
                         new_abbrev = seq[x + 3]
                     elif seq[x + 1] == '0':
                         new_abbrev = seq[x + 2:(x + 4)]
                     else:
                         new_abbrev = seq[x + 1:(x + 4)]
                     self.seq_alphabet_list.append(
                         alphabet.get_new_original(new_abbrev))
                     x += 4
                 else:
                     raise SequenceError(
                         'Some irregularities in sequence: %s' %
                         seq[x:(x + 4)])
             else:
                 self.seq_alphabet_list.append(
                     alphabet.get_short_original(seq[x]))
                 x += 1
     elif type(seq) == list:
         self.seq_alphabet_list = seq
     else:
         raise SequenceError(
             'Bad argument type. Sequence instance takes string or list of alphabet_entities'
         )