Пример #1
0
class PerlGenPDBParser:
    """
    Parse a PDB file generated by and return a Chain object.
    """
    def __init__(self, filename):
        assert (isinstance(filename, str))
        self.__chain = self.__current_residue = None
        self._parse_coordinates(open(filename).readlines())

    def get_chain(self):
        return self.__chain

    def _parse_coordinates(self, lines):
        self.__chain = Chain(lines[0].split()[4])

        for i in range(len(lines)):
            items = lines[i].split()

            atom_serial_num = int(items[1])
            atom_name = items[2]
            element = lines[i][13]
            residue_name = items[3]
            residue_serial_num = int(items[5])
            coords = array([items[6], items[7], items[8]], 'f')

            if self.__current_residue is None or self.__current_residue.sequence_number(
            ) != residue_serial_num:
                self.__current_residue = Residue(residue_serial_num,
                                                 residue_name)
                self.__chain.add_residue(self.__current_residue)

            self.__current_residue.add_atom(
                Atom(atom_serial_num, atom_name, coords, element))
Пример #2
0
class PerlGenPDBParser:
    """
    Parse a PDB file generated by and return a Chain object.
    """

    def __init__(self, filename):
        assert(isinstance(filename, str))
        self.__chain = self.__current_residue = None
        self._parse_coordinates(open(filename).readlines())

    def get_chain(self):
        return self.__chain

    def _parse_coordinates(self, lines):
        self.__chain = Chain(lines[0].split()[4])

        for i in range(len(lines)):
            items = lines[i].split()

            atom_serial_num = int(items[1])
            atom_name = items[2]
            element = lines[i][13]
            residue_name = items[3]
            residue_serial_num = int(items[5])
            coords =  array([items[6], items[7], items[8]], 'f')
            
            if self.__current_residue is None or self.__current_residue.sequence_number() != residue_serial_num:
                self.__current_residue = Residue(residue_serial_num, residue_name)
                self.__chain.add_residue(self.__current_residue)

            self.__current_residue.add_atom(Atom(atom_serial_num, atom_name, coords, element))
Пример #3
0
    def _parse_coordinates(self, lines):
        self.__chain = Chain(lines[0].split()[4])

        for i in range(len(lines)):
            items = lines[i].split()

            atom_serial_num = int(items[1])
            atom_name = items[2]
            element = lines[i][13]
            residue_name = items[3]
            residue_serial_num = int(items[5])
            coords = array([items[6], items[7], items[8]], 'f')

            if self.__current_residue is None or self.__current_residue.sequence_number(
            ) != residue_serial_num:
                self.__current_residue = Residue(residue_serial_num,
                                                 residue_name)
                self.__chain.add_residue(self.__current_residue)

            self.__current_residue.add_atom(
                Atom(atom_serial_num, atom_name, coords, element))
Пример #4
0
    def _parse_coordinates(self, lines):
        self.__chain = Chain(lines[0].split()[4])

        for i in range(len(lines)):
            items = lines[i].split()

            atom_serial_num = int(items[1])
            atom_name = items[2]
            element = lines[i][13]
            residue_name = items[3]
            residue_serial_num = int(items[5])
            coords =  array([items[6], items[7], items[8]], 'f')
            
            if self.__current_residue is None or self.__current_residue.sequence_number() != residue_serial_num:
                self.__current_residue = Residue(residue_serial_num, residue_name)
                self.__chain.add_residue(self.__current_residue)

            self.__current_residue.add_atom(Atom(atom_serial_num, atom_name, coords, element))
Пример #5
0
    def init_residue(self, resname, field, resseq, icode):
        """
        Initiate a new Residue object.

        Arguments:
        o resname - string, e.g. "ASN"
        o field - hetero flag, "W" for waters, "H" for
            hetero residues, otherwise blank.
        o resseq - int, sequence identifier
        o icode - string, insertion code
        """
        if field == "H":
            # The hetero field consists of H_ + the residue name (e.g. H_FUC)
            field = "H_" + resname
        res_id = (field, resseq, icode)

        if field == " ":
            if self.current_chain.has_residue_with_id(res_id):
                # There already is a residue with the id (field, resseq, icode).
                # This only makes sense in the case of a point mutation.
                warnings.warn(
                    "WARNING: Residue ('%s', %i, '%s') "
                    "redefined at line %i." %
                    (field, resseq, icode, self.line_counter),
                    PDBConstructionWarning)
                duplicate_residue = self.current_chain.residues(res_id)
                if duplicate_residue.is_disordered() == 2:
                    # The residue in the chain is a DisorderedResidue object.
                    # So just add the last Residue object.
                    if duplicate_residue.has_residue_with_name(resname):
                        # The residue was already made
                        self.current_residue = duplicate_residue
                        duplicate_residue.set_main_disorder_identifier(resname)
                    else:
                        # Make a new residue and add it to the already
                        # present DisorderedResidue
                        new_residue = Residue(res_id, resname, self.segid)
                        duplicate_residue.add_residue(new_residue)
                        self.current_residue = duplicate_residue
                        return
                else:
                    # Make a new DisorderedResidue object and put all
                    # the Residue objects with the id (field, resseq, icode) in it.
                    # These residues each should have non-blank altlocs for all their atoms.
                    # If not, the PDB file probably contains an error.
                    if not self._is_completely_disordered(duplicate_residue):
                        # if this exception is ignored, a residue will be missing
                        self.current_residue = None
                        raise PDBConstructionException(\
                            "Blank altlocs in duplicate residue %s ('%s', %i, '%s')" \
                            % (resname, field, resseq, icode))
                    self.current_chain.remove_residue_with_id(res_id)
                    new_residue = Residue(res_id, resname, self.segid)
                    disordered_residue = DisorderedResidue(res_id)
                    self.current_chain.add_residue(disordered_residue)
                    disordered_residue.add_residue(duplicate_residue)
                    disordered_residue.add_residue(new_residue)
                    self.current_residue = disordered_residue
                    return
        residue = Residue(res_id, resname, self.segid)
        self.current_chain.add_residue(residue)
        self.current_residue = residue