예제 #1
0
파일: model.py 프로젝트: dishawang/pmx
    def __readPDBTER(self, fname=None, pdbline=None, bNoNewID=True):
        if pdbline:
            l = pdbline.split('\n')
        else:
            l = open(fname, 'r').readlines()

        chainIDstring = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnoprstuvwxyz123456789'
        bNewChain = True
        chainID = ' '
        prevID = ' '
        prevResID = 0
        usedChainIDs = ''
        atomcount = 1
        for line in l:
            if 'TER' in line:
                bNewChain = True
            if (line[:4] == 'ATOM') or (line[:6] == 'HETATM'):
                a = Atom().readPDBString(line, origID=atomcount)
                atomcount += 1
                #		if (a.chain_id != prevID) and (a.chain_id != ' '): # identify chain change by ID (when no TER is there)
                if (a.chain_id != prevID
                    ):  # identify chain change by ID (when no TER is there)
                    bNewChain = True
                if (a.resnr != prevResID):
                    try:
                        if a.resnr != prevResID + 1:
                            bNewChain = True
                    except TypeError:
                        bNewChain = False
                prevID = a.chain_id
                prevResID = a.resnr
                if bNewChain == True:
                    if (a.chain_id == ' ') or (a.chain_id == chainID):
                        # find a new chain id
                        bFound = False
                        while bFound == False:
                            foo = chainIDstring[0]
                            chainIDstring = chainIDstring.lstrip(
                                chainIDstring[0])
                            if foo not in usedChainIDs:
                                bFound = True
                                usedChainIDs = usedChainIDs + foo
                                chainID = foo
                                if bNoNewID == True:
                                    chainID = "pmx" + foo
                    else:
                        chainID = a.chain_id
                        usedChainIDs = usedChainIDs + chainID
                a.chain_id = chainID
                self.atoms.append(a)
                bNewChain = False
            if line[:6] == 'CRYST1':
                self.box = _p.box_from_cryst1(line)
        self.make_chains()
        self.make_residues()
        self.unity = 'A'
        return self
예제 #2
0
파일: model.py 프로젝트: milafternoon/pmx
 def __readPDB(self, fname=None, pdbline=None):
     if pdbline:
         l = pdbline.split('\n')
     else:
         l = open(fname, 'r').readlines()
     for line in l:
         if line[:4]=='ATOM' or \
            line[:6]=='HETATM':
             a = Atom().readPDBString(line)
             self.atoms.append(a)
         if line[:6] == 'CRYST1':
             self.box = _p.box_from_cryst1(line)
     self.make_chains()
     self.make_residues()
     self.unity = 'A'
     return self
예제 #3
0
파일: model.py 프로젝트: esguerra/pmx
 def __readPDB(self,fname=None, pdbline=None):
     if pdbline:
         l = pdbline.split('\n')
     else:
         l = open(fname,'r').readlines()
     for line in l:
         if line[:4]=='ATOM' or \
            line[:6]=='HETATM':
             a = Atom().readPDBString(line)
             self.atoms.append(a)
         if line[:6] == 'CRYST1':
             self.box = _p.box_from_cryst1( line )
     self.make_chains()
     self.make_residues()
     self.unity  = 'A'
     return self
예제 #4
0
파일: model.py 프로젝트: milafternoon/pmx
    def __readPDBTER(self,
                     fname=None,
                     pdbline=None,
                     bNoNewID=True,
                     bPDBGAP=False):
        if pdbline:
            l = pdbline.split('\n')
        else:
            l = open(fname, 'r').readlines()

        chainIDstring = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnoprstuvwxyz123456789'
        bNewChain = True
        chainID = ' '
        prevID = ' '
        prevAtomName = ' '
        prevResID = 0
        prevResName = ' '
        usedChainIDs = []
        atomcount = 1
        prevCatom = None

        for line in l:
            if 'TER' in line:
                bNewChain = True
            if (line[:4] == 'ATOM') or (line[:6] == 'HETATM'):
                a = Atom().readPDBString(line, origID=atomcount)
                atomcount += 1
                #		if (a.chain_id != prevID) and (a.chain_id != ' '): # identify chain change by ID (when no TER is there)
                if (a.chain_id != prevID
                    ):  # identify chain change by ID (when no TER is there)
                    bNewChain = True
                if (self.__check_if_gap(prevCatom, a) == True
                        and bPDBGAP == True):
                    bNewChain = True
                if (a.resnr != prevResID):
                    try:
                        if a.resnr != prevResID + 1:
                            bNewChain = True
                        if (prevAtomName
                                == 'OC2') or (prevAtomName
                                              == 'OXT') or (prevAtomName
                                                            == 'OT2'):
                            bNewChain = True
                        if (prevAtomName == 'HH33') and (
                            (prevResName == 'NME') or (prevResName == 'NAC') or
                            (prevResName == 'CT3')):  # NME cap
                            bNewChain = True
                    except TypeError:
                        bNewChain = False
                prevID = a.chain_id
                prevResID = a.resnr
                prevAtomName = a.name
                prevResName = a.resname
                if a.name == 'C':
                    prevCatom = a
                if bNewChain == True:
                    if (a.chain_id == ' ') or (a.chain_id == chainID) or (
                            a.chain_id in usedChainIDs):
                        #print a.chain_id,a,chainID,usedChainIDs
                        # find a new chain id
                        bFound = False
                        while bFound == False:
                            foo = chainIDstring[0]
                            chainIDstring = chainIDstring.lstrip(
                                chainIDstring[0])
                            if foo not in usedChainIDs:
                                bFound = True
                                chainID = foo
                                if bNoNewID == True:
                                    chainID = "pmx" + foo
                                usedChainIDs.append(chainID)
                    else:
                        chainID = a.chain_id
                        usedChainIDs.append(chainID)
                a.chain_id = chainID
                self.atoms.append(a)
                bNewChain = False
            if line[:6] == 'CRYST1':
                self.box = _p.box_from_cryst1(line)

        ##### now fix chain IDs that have been newly created #####
        newChainDict = {}
        chainIDstring = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnoprstuvwxyz123456789'
        for a in self.atoms:
            # chain with a new ID
            if 'pmx' in a.chain_id:
                # this ID has already been encountered
                if a.chain_id in newChainDict.keys():
                    a.chain_id = newChainDict[a.chain_id]
                # ID not yet encountered
                else:
                    # find a suitable ID
                    bFound = False
                    while bFound == False:
                        foo = chainIDstring[0]
                        chainIDstring = chainIDstring.lstrip(chainIDstring[0])
                        # found
                        if foo not in usedChainIDs:
                            bFound = True
                            usedChainIDs.append(foo)
                            newChainDict[a.chain_id] = foo
                            a.chain_id = foo

        self.make_chains()
        self.make_residues()
        self.unity = 'A'
        return self