Beispiel #1
0
    def build4LevelsTree(self, subst_chain, atomlines):
        """
        Function to build a 4 level hierarchy Protein-Chain-Residue-Atom.

        """
        self.mol = Protein()
        self.mol.allAtoms = AtomSet()
        self.mol.atmNum = {}
        self.mol.parser = self
        if self.mol.name == 'NoName':
            self.mol.name = os.path.basename(
                os.path.splitext(self.filename)[0])
        self.mol.curChain = Chain()
        self.mol.curRes = Residue()
        self.mol.levels = [Protein, Chain, Residue, Atom]
        i = 1
        for atmline in atomlines:
            if len(atmline) >= 10:
                status = string.split(atmline[9], '|')
            else:
                status = None
            if len(atmline) == 8:
                tmp = [atmline[5][:5], atmline[5][5:]]
                atmline[5] = tmp[0]
                atmline.insert(6, tmp[1])

            if status and status[0] == 'WATER':
                chainID = 'W'
                atmline[7] = 'HOH' + str(i)
                subst_chain[atmline[7]] = chainID
                i = i + 1

            if subst_chain == {}:
                chainID = 'default'

            elif not subst_chain.has_key(atmline[7]):
                if subst_chain.has_key('****'):
                    try:
                        chainID = subst_chain[atmline[7]]
                    except:
                        chainID = 'default'
                else:
                    chainID = 'default'

            elif type(subst_chain[atmline[7]]) is types.StringType:
                # that is to say that only chains has this substructure name.
                chainID = subst_chain[atmline[7]]

            elif type(subst_chain[atmline[7]]) is types.ListType:
                # That is to say that several chains have the same substructure.
                chainID = subst_chain[atmline[7]][0]
                subst_chain[atmline[7]] = subst_chain[atmline[7]].remove(
                    chainID)

            if chainID != self.mol.curChain.id:
                if not self.mol.chains.id or not chainID in self.mol.chains.id:
                    self.mol.curChain = Chain(chainID, self.mol, top=self.mol)
                else:
                    self.mol.curChain = self.mol.chains.get(chainID)[0]

            if len(atmline) < 7:
                # test if the atmline has a res name and resseq:
                resName = 'RES'
                resSeq = '1'
            else:
                resName = atmline[7][:3]
                resSeq = atmline[7][3:]

            if resSeq != self.mol.curRes.number or \
               resName != self.mol.curRes.type:
                # check if this residue already exists
                na = string.strip(resName) + string.strip(resSeq)
                res = self.mol.curChain.get(na)
                if res:
                    self.mol.curRes = res[0]
                else:
                    self.mol.curRes = Residue(resName,
                                              resSeq,
                                              '',
                                              self.mol.curChain,
                                              top=self.mol)
            name = atmline[1]
            if name == 'CA': self.mol.curRes.hasCA = 1
            if name == 'O': self.mol.curRes.hasO = 2
            atom = Atom(name,
                        self.mol.curRes,
                        top=self.mol,
                        chemicalElement=string.split(atmline[5], '.')[0])
            #atom.element = atmline[5][0]
            atom.element = atom.chemElem
            atom.number = int(atmline[0])
            self.mol.atmNum[atom.number] = atom
            atom._coords = [[
                float(atmline[2]),
                float(atmline[3]),
                float(atmline[4])
            ]]
            if len(atmline) >= 9:
                atom._charges['mol2'] = float(atmline[8])
                atom.chargeSet = 'mol2'
#            atom.conformation = 0
            atom.hetatm = 0
            #Add a data member containing a list of string describing
            # the Sybyl status bis of the atoms.
            atom.status = status
            #add altname so buildBondsByDist doesn't croak
            atom.altname = None
            self.mol.allAtoms.append(atom)
        delattr(self.mol, 'curRes')
        delattr(self.mol, 'curChain')
    def build4LevelsTree(self, subst_chain, atomlines):
        """
        Function to build a 4 level hierarchy Protein-Chain-Residue-Atom.

        """
        self.mol= Protein()
        self.mol.allAtoms = AtomSet()
        self.mol.atmNum = {}
        self.mol.parser = self
        if self.mol.name == 'NoName':
            self.mol.name = os.path.basename(os.path.splitext
                                             (self.filename)[0])
        self.mol.curChain = Chain()
        self.mol.curRes = Residue()
        self.mol.levels = [Protein, Chain, Residue, Atom]
        i = 1
        for atmline in atomlines:
            if len(atmline)>= 10:
                status = string.split(atmline[9], '|')
            else: status = None
            if len(atmline) == 8:
                tmp = [atmline[5][:5], atmline[5][5:]]
                atmline[5] = tmp[0]
                atmline.insert(6, tmp[1])

            if status and status[0]=='WATER':
                chainID = 'W'
                atmline[7] = 'HOH'+str(i)
                subst_chain[atmline[7]] = chainID
                i = i+1

            if subst_chain == {}:
                chainID = 'default'

            elif not subst_chain.has_key(atmline[7]):
                if subst_chain.has_key('****'):
                    try:
                        chainID = subst_chain[atmline[7]]
                    except:
                        chainID = 'default'
                else:
                    chainID = 'default'

            elif type(subst_chain[atmline[7]]) is types.StringType:
                # that is to say that only chains has this substructure name.
                chainID = subst_chain[atmline[7]]

            elif type(subst_chain[atmline[7]]) is types.ListType:
                # That is to say that several chains have the same substructure.
                 chainID = subst_chain[atmline[7]][0]
                 subst_chain[atmline[7]] = subst_chain[atmline[7]].remove(chainID)
                 
            if chainID != self.mol.curChain.id:
                if not self.mol.chains.id or not chainID in self.mol.chains.id:
                    self.mol.curChain = Chain(chainID, self.mol,
                                          top = self.mol)
                else:
                    self.mol.curChain = self.mol.chains.get(chainID)[0]

            if len(atmline)<7:
                # test if the atmline has a res name and resseq:
                resName = 'RES'
                resSeq = '1'
            else:
                resName = atmline[7][:3]
                resSeq = atmline[7][3:]

            if resSeq != self.mol.curRes.number or \
               resName != self.mol.curRes.type:
                # check if this residue already exists
                na = string.strip(resName) + string.strip(resSeq)
                res = self.mol.curChain.get( na )
                if res:
                    self.mol.curRes = res[0]
                else:
                    self.mol.curRes = Residue(resName, resSeq, '',
                                              self.mol.curChain,
                                              top = self.mol)
            name = atmline[1]
            if name == 'CA': self.mol.curRes.hasCA = 1
            if name == 'O' : self.mol.curRes.hasO = 2
            atom = Atom(name, self.mol.curRes, top = self.mol,
            chemicalElement = string.split(atmline[5], '.')[0])
            #atom.element = atmline[5][0]
            atom.element = atom.chemElem
            atom.number = int(atmline[0])
            self.mol.atmNum[atom.number] = atom
            atom._coords = [ [float(atmline[2]), float(atmline[3]),
                              float(atmline[4]) ] ]
            if len(atmline)>=9:                
                atom._charges['mol2'] = float(atmline[8])
                atom.chargeSet = 'mol2'
#            atom.conformation = 0
            atom.hetatm = 0
            #Add a data member containing a list of string describing
            # the Sybyl status bis of the atoms.
            atom.status = status
            #add altname so buildBondsByDist doesn't croak
            atom.altname = None
            self.mol.allAtoms.append(atom)
        delattr(self.mol, 'curRes')
        delattr(self.mol, 'curChain')
Beispiel #3
0
    def build3LevelsTree(self, atomlines):
        """ Function to build a 3 levels hierarchy Molecule-substructure-atoms."""

        self.mol = Protein()
        self.mol.allAtoms = AtomSet()
        self.mol.atmNum = {}
        self.mol.parser = self
        if self.mol.name == 'NoName':
            self.mol.name = os.path.basename(
                os.path.splitext(self.filename)[0])
        self.mol.children = ResidueSet([])
        self.mol.childrenName = 'residues'
        self.mol.childrenSetClass = ResidueSet
        self.mol.elementType = Residue
        self.mol.curRes = Residue()
        self.mol.curRes.hasCA = 0
        self.mol.curRes.hasO = 0

        self.mol.levels = [Protein, Residue, Atom]
        for atmline in atomlines:
            if len(atmline) >= 10:
                status = string.split(atmline[9], '|')
            else:
                status = None
            resName = atmline[7][:3]
            resSeq = atmline[7][3:]
            if resSeq != self.mol.curRes.number or \
               resName != self.mol.curRes.type:
                # check if this residue already exists
                na = string.strip(resName) + string.strip(resSeq)
                res = self.mol.get(na)
                if res:
                    self.mol.curRes = res[0]
                else:
                    self.mol.curRes = Residue(resName,
                                              resSeq,
                                              '',
                                              self.mol,
                                              top=self.mol)
            name = atmline[1]
            if name == 'CA': self.mol.curRes.hasCA = 1
            if name == 'O': self.mol.curRes.hasO = 2
            atom = Atom(name,
                        self.mol.curRes,
                        top=self.mol,
                        chemicalElement=string.split(atmline[5], '.')[0])
            #atom.element = atmline[5][0]
            atom.element = atom.chemElem
            atom.number = int(atmline[0])
            self.mol.atmNum[atom.number] = atom
            atom._coords = [[
                float(atmline[2]),
                float(atmline[3]),
                float(atmline[4])
            ]]
            atom._charges['mol2'] = float(atmline[8])
            atom.chargeSet = mol2
            #            atom.conformation = 0
            atom.hetatm = 0
            #Add a data member containing a list of string describing
            # the Sybyl status bis of the atoms.
            atom.status = status
            #add altname so buildBondsByDist doesn't croak
            atom.altname = None
            self.mol.allAtoms.append(atom)

        self.mol.residues = self.mol.children
        assert hasattr(self.mol, 'chains')
        delattr(self.mol, 'chains')
        delattr(self.mol, 'curRes')
    def build3LevelsTree(self,atomlines):
        """ Function to build a 3 levels hierarchy Molecule-substructure-atoms."""

        self.mol= Protein()
        self.mol.allAtoms = AtomSet()
        self.mol.atmNum = {}
        self.mol.parser = self
        if self.mol.name == 'NoName':
            self.mol.name = os.path.basename(os.path.splitext
                                             (self.filename)[0])
        self.mol.children = ResidueSet([])
        self.mol.childrenName = 'residues'
        self.mol.childrenSetClass = ResidueSet
        self.mol.elementType = Residue
        self.mol.curRes = Residue()
        self.mol.curRes.hasCA = 0
        self.mol.curRes.hasO = 0
        
        self.mol.levels = [Protein, Residue, Atom]
        for atmline in atomlines:
            if len(atmline)>= 10:
                status = string.split(atmline[9], '|')
            else:
                status = None
            resName = atmline[7][:3]
            resSeq = atmline[7][3:]
            if resSeq != self.mol.curRes.number or \
               resName != self.mol.curRes.type:
                # check if this residue already exists
                na = string.strip(resName) + string.strip(resSeq)
                res = self.mol.get(na)
                if res:
                    self.mol.curRes = res[0]
                else:
                    self.mol.curRes = Residue(resName, resSeq, '',
                                              self.mol,
                                              top = self.mol)
            name = atmline[1]
            if name == 'CA': self.mol.curRes.hasCA = 1
            if name == 'O' : self.mol.curRes.hasO = 2
            atom = Atom(name, self.mol.curRes, top = self.mol,
            chemicalElement = string.split(atmline[5], '.')[0])
            #atom.element = atmline[5][0]
            atom.element = atom.chemElem
            atom.number = int(atmline[0])
            self.mol.atmNum[atom.number] = atom
            atom._coords = [ [float(atmline[2]), float(atmline[3]),
                              float(atmline[4]) ] ]
            atom._charges['mol2'] = float(atmline[8])
            atom.chargeSet = mol2
#            atom.conformation = 0
            atom.hetatm = 0
            #Add a data member containing a list of string describing
            # the Sybyl status bis of the atoms.
            atom.status = status 
            #add altname so buildBondsByDist doesn't croak
            atom.altname = None
            self.mol.allAtoms.append(atom)
            
        self.mol.residues = self.mol.children
        assert hasattr(self.mol, 'chains')
        delattr(self.mol, 'chains')
        delattr(self.mol, 'curRes')