image thumbnail

read and write PDB files using matlab

version 1.0.0.0 (5.04 KB) by Evan
These two programs accept and output a variety of PDB file-formatted data

964 Downloads

Updated 05 Aug 2013

View License

Both programs use data structures to store information about PDBs. I find these programs useful both for dealing with PDBs and visualizing 3D point information

-- example usage: plot the atoms of 3IJU.pdb --

PDBdata = pdb2mat('3IJU.pdb'); % read in data from PDB file
plot3(PDBdata.X, PDBdata.Y, PDBdata.Z, '.'); % make a 3D plot of data

-- example usage: translate the atoms of 3IJU.pdb by 10 angstroms in x direction --

PDBdata = pdb2mat('3IJU.pdb'); % read in data from PDB file
PDBdata.X = PDBdata.X + 10; % translate coordinates
PDBdata.outfile = '3IJU_tran10angXdir.pdb'; % update file name
mat2pdb(PDBdata); % output data in PDB format

-- example usage: make a PDB with 30 atoms in random places within a 10 angstrom box --
data.X = rand(1,20)*10;
data.Y = rand(1,20)*10;
data.Z = rand(1,20)*10;
mat2pdb(data)

%% -- pdb2mat.m --
%
% It's function is simple: give it a PDB file and out comes a
% matlab-friendly data structure. In cumbersomely large PDB's (such as those that
% include solvent), this can shave off a good amount of time relative to
% many programs. Unfortunately there is no easy way to hasten the slowest
% step, which is turning strings into doubles.
%

%% -- mat2PDB.m --
%
% this function creates a PDB from coordinate data. Represent all inputs as
% a structure field for it to be read. The output format is as given in
% online documentation (as of July 2012 when writing this program)
% http://www.wwpdb.org/documentation/format33/sect9.html#ATOM

To speed up the program, comment out any lines for data not being used. Commenting one line that converts numeric data speeds the program up by roughly 7-8%.

example usage : this plots the atoms of 3IJU.pdb

atoms = fastPDBRead('3IJU.pdb')
plot3(atoms.X, atoms.Y, atoms.Z, '.');

Cite As

Evan (2021). read and write PDB files using matlab (https://www.mathworks.com/matlabcentral/fileexchange/42957-read-and-write-pdb-files-using-matlab), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2010a
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!