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.2-py3-none-any.whl (4.4 kB view details)

Uploaded Python 3

File details

Details for the file pdbUtils-2024.0.2-py3-none-any.whl.

File metadata

  • Download URL: pdbUtils-2024.0.2-py3-none-any.whl
  • Upload date:
  • Size: 4.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.2

File hashes

Hashes for pdbUtils-2024.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 5c3b678fc4046befa4476048d93b3cf0cbc7ead5dc6d444ba18ce6aa2cc1c1a2
MD5 0f39ae2d53cc88d42a56c43991e794ce
BLAKE2b-256 2dc0cb26ec6ad5cc58a1672229b6290466e5d4da89c1e418085da133143e53d1

See more details on using hashes here.

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