Skip to main content

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

Release files for pdbUtils 2024.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for pdbUtils 2024.0.2
File Interpreter ABI Platform
pdbUtils-2024.0.2-py3-none-any.whl Python 3 none any Details

Release files / pdbUtils-2024.0.2-py3-none-any.whl

Download URL pdbUtils-2024.0.2-py3-none-any.whl
Size 4.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5c3b678fc4046befa4476048d93b3cf0cbc7ead5dc6d444ba18ce6aa2cc1c1a2
BLAKE2b-256 checksum
How to use checksums
2dc0cb26ec6ad5cc58a1672229b6290466e5d4da89c1e418085da133143e53d1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.12.2

Release history Release notifications | RSS feed

This release

2024.0.2 This release

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page