Ejemplo n.º 1
0
    def writeVecStartStopToPDBFile(self,
                                   mainNegCentroid=[],
                                   outputPDBname='Dshift-vectors.pdb',
                                   weightedVectors=[]):

        # write located density shift vector start and stop
        # xyz positions to a pdb file so that they can then be
        # visualised in pymol (or otherwise). 'densMapObj' is
        # taken from readAtomMap.py (self.densmap).

        from classHolder import singlePDB
        from PDBFileManipulation import writePDBline

        vecStart = self.densMapObj.abc2xyz(
            asymIndices=mainNegCentroid[:3], fracInput=True)

        # append vector positions to a pdb file if it exists
        lineCount = 0
        if os.path.isfile(outputPDBname):
            try:
                with open(outputPDBname) as f:
                    i = -1
                    for i, l in enumerate(f):
                        pass
                lineCount = i + 1
            except IOError:
                pass

        vectorPDBfile = open(outputPDBname, 'a')

        atmIDparts = self.atmId.split('-')

        vecPosAsAtom = singlePDB(
            atomnum=lineCount, residuenum=atmIDparts[1],
            atomtype=atmIDparts[3], basetype='V0',
            chaintype=atmIDparts[0], X_coord=vecStart[0],
            Y_coord=vecStart[1], Z_coord=vecStart[2])

        pdbLine = writePDBline(vecPosAsAtom, 1)
        vectorPDBfile.write(pdbLine + '\n')

        for i, vec in enumerate(weightedVectors):
            vecEnd = self.densMapObj.abc2xyz(
                asymIndices=np.array(mainNegCentroid[:3]) + vec,
                fracInput=True)

            vecPosAsAtom = singlePDB(
                atomnum=lineCount + i + 1, residuenum=atmIDparts[1],
                atomtype=atmIDparts[3], basetype='V' + str(i+1),
                chaintype=atmIDparts[0], X_coord=vecEnd[0],
                Y_coord=vecEnd[1], Z_coord=vecEnd[2])

            pdbLine = writePDBline(vecPosAsAtom, 1)
            vectorPDBfile.write(pdbLine + '\n')

        vectorPDBfile.close()
Ejemplo n.º 2
0
def PDBtoList(pdbfilename,PDBarray):
    # this function inputs a pdb file name and returns an list of pdb objects, 
    # organised following the StructurePDB class
    
    pdbin = open(str(pdbfilename), "r")
    lines = pdbin.readlines()
    print 'Reading PDB file and converting to list of objects'
    for line in lines:
        if ('ATOM' in str(line[0:6])) or ('HETATM' in str(line[0:6])):
            y               = singlePDB(StructurePDB)
            y.atomnum       = int(line[6:11].strip())
            y.atomtype      = str(line[12:16].strip())
            y.basetype      = str(line[17:20].strip())                       
            y.chaintype     = str(line[21])                     
            y.residuenum    = int(line[22:26].strip())             
            y.X_coord       = float(line[30:38].strip())                       
            y.Y_coord       = float(line[38:46].strip())                                             
            y.Z_coord       = float(line[46:54].strip())                                                 
            y.Occupancy     = str(line[54:60].strip())                                                    
            y.Bfactor       = float(line[60:66].strip())
            y.atomID        = str(line[76:78].strip())  
            y.atomOrHetatm  = str(line[0:6].strip())
            PDBarray.append(y)
        else: 
            pass
    pdbin.close()
    return PDBarray
Ejemplo n.º 3
0
    def writeVecStartStopToPDBFile(
        self, mainNegCentroid=[], outputPDBname="Dshift-vectors.pdb", densMapObj=[], weightedVectors=[]
    ):

        # write located density shift vector start and stop xyz positions
        # to a pdb file so that they can then be visualised in pymol (or otherwise).
        # 'densMapObj' is taken from readAtomMap.py (self.densmap).

        from classHolder import singlePDB
        from PDBFileManipulation import writePDBline

        vecStart = densMapObj.abc2xyz(asymIndices=mainNegCentroid[:3], fracInput=True)

        # append vector positions to a pdb file if it exists
        lineCount = 0
        if os.path.isfile(outputPDBname):
            try:
                with open(outputPDBname) as f:
                    i = -1
                    for i, l in enumerate(f):
                        pass
                lineCount = i + 1
            except IOError:
                pass

        vectorPDBfile = open(outputPDBname, "a")

        atmIDparts = self.atmId.split("-")

        vecPosAsAtom = singlePDB(
            atomnum=lineCount,
            residuenum=atmIDparts[1],
            atomtype=atmIDparts[3],
            basetype="V0",
            chaintype=atmIDparts[0],
            X_coord=vecStart[0],
            Y_coord=vecStart[1],
            Z_coord=vecStart[2],
        )

        pdbLine = writePDBline(vecPosAsAtom, 1)
        vectorPDBfile.write(pdbLine + "\n")

        for i, vec in enumerate(weightedVectors):
            vecEnd = densMapObj.abc2xyz(asymIndices=np.array(mainNegCentroid[:3]) + vec, fracInput=True)

            # NOTE THAT PYMOL ARROWS SHOULD BE OF THE FORM BELOW
            # print 'cgo_arrow [{}],[{}],hlength=0.25,radius=0.05,hradius=0.075'.
            # format(','.join([str(round(v,2)) for v in vecStart]),','.join([str(round(v,2)) for v in vecEnd]))

            vecPosAsAtom = singlePDB(
                atomnum=lineCount + i + 1,
                residuenum=atmIDparts[1],
                atomtype=atmIDparts[3],
                basetype="V" + str(i + 1),
                chaintype=atmIDparts[0],
                X_coord=vecEnd[0],
                Y_coord=vecEnd[1],
                Z_coord=vecEnd[2],
            )

            pdbLine = writePDBline(vecPosAsAtom, 1)
            vectorPDBfile.write(pdbLine + "\n")

        vectorPDBfile.close()