Skip to main content

A small python module that can parse PDB files as pandas DataFrames.

Project description

pdbUtils

Usage

This is a small python module that can parse PDB files as pandas DataFrames.

PDB formatting can be all over the place depending on how they have been created. PdbUtils has been written such that it tolerates all sorts of weird stuff when reading a PDB file, but writes PDB files strictly according to PDB formatting rules: https://www.cgl.ucsf.edu/chimera/docs/UsersGuide/tutorials/pdbintro.html

You can load a pdb file as a DataFrame by:

from pdbUtils import pdbUtils

myPdbFile = "/path/to/your/pdb.pdb"

pdbDf = pdbUtils.pdb2df(myPdbFile)

Once loaded as a DataFrame, you can modiy and interrogate it to your heart's content. You can access each column of your new DataFrame using the following column names:

print(pdbDf["ATOM"])            ## string "ATOM" or "HETATM"
print(pdbDf["ATOM_ID"])         ## int atom number 
print(pdbDf["ATOM_NAME"])       ## string atom name (eg. "OG")
print(pdbDf["RES_NAME"])        ## string residue name (eg. "SER")
print(pdbDf["CHAIN_ID"])        ## chain identifier (eg. "B")
print(pdbDf["RES_ID"])          ## string residue number (eg. "131")
print(pdbDf["X"])               ## float X coordinate
print(pdbDf["Y"])               ## float Y coordinate
print(pdbDf["Z"])               ## float Z coordinate
print(pdbDf["OCCUPANCY"])       ## float occupancy (usually 1.00 or 0.00)
print(pdbDf["BETAFACTOR"])      ## float betafactor or pLDDT if it's a structural prediction
print(pdbDf["ELEMENT"])         ## string element (eg. "O")

When you want to write back to a PDB file:

outPdbFile = "/path/to/your/pdb_new.pdb"
pdbUtils.pdb2df(pdbDf, outPdbFile)

I have also added the function to read AutoDock PDBQT files in the same manner:

import pdbUtils

myPdbqtFile = "/path/to/your/pdbqt.pdbqt"

pdbDf = pdbUtils.pdbqt2df(myPdbFile)

Installation

pip install pdbUtils

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

pdbUtils-2024.0.1-py3-none-any.whl (4.4 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page