Change B-factors
Problem description
It is a common practice to change the B-factors of a PDB to store information about atoms or residues to be used by other programs. In particular, values in the B-factor column can be easily used to colour residues with PyMOL or Chimera.
We cannot simply assign a new value to the B
field of a PDBAtom
because this type is immutable. Instead, MIToS provides the change_b_factor
function to create a new atom with a different B-factor value. When used on a PDBResidue
, it changes the B-factor of all atoms by default. The mutating variant change_b_factor!
performs the update in place.
In a PDB file, B-factors are stored from column 61 to 66. Therefore, new values should be formatted using at most six characters, normally with two decimal digits. The change_b_factor
and change_b_factor!
functions will take care of this and throw an error if that is not possible.
MIToS solution
For this example we are going to use the small heat shock protein AgsA from Salmonella typhimurium (PDB code: 4ZJ9) available in MIToS docs data:
using MIToS
pdbfile = abspath(pathof(MIToS), "..", "..", "docs", "data", "4zj9.pdb")
First, we need to read the PDB file using the MIToS.PDB
module:
using MIToS.PDB
pdb_residues = read_file(pdbfile, PDBFile)
For this example, we are going to replace the B-factor of a residue's atoms with the residue hydrophobicity according to the hydrophobicity scale of Kyte and Doolittle used by Chimera:
hydrophobicity = Dict(
"ILE" => 4.5,
"VAL" => 4.2,
"LEU" => 3.8,
"PHE" => 2.8,
"CYS" => 2.5,
"MET" => 1.9,
"ALA" => 1.8,
"GLY" => -0.4,
"THR" => -0.7,
"SER" => -0.8,
"TRP" => -0.9,
"TYR" => -1.3,
"PRO" => -1.6,
"HIS" => -3.2,
"GLU" => -3.5,
"GLN" => -3.5,
"ASP" => -3.5,
"ASN" => -3.5,
"LYS" => -3.9,
"ARG" => -4.5,
)
using MIToS.PDB
Now, we can use the change_b_factor!
function on each residue to change the B-factor of all its atoms. Some PDB files contain residues or other molecules not present in the hydrophobicity dictionary, so we check for the residue name before applying the change:
for res in pdb_residues
name = res.id.name
if haskey(hydrophobicity, name)
change_b_factor!(res, hydrophobicity[name])
end
end
Finally, we can save the changed residues in a new PDB file.
write_file("4zj9_hydrophobicity.pdb", pdb_residues, PDBFile)
Discussion
Here, we have focused on changing the B-factor field of a PDBAtom
. In case you want to change atom coordinates, it is better to use the change_coordinates
function from the PDB module of MIToS. For other fields you can rely on the Setfield package.
MIToS atoms and residues generally store the string present in the input file without surrounding spaces. You can use the Format
module to create these strings and strip
to get rid of the spaces. You can see the PDB format description to know what is the format of the expected string or see the MIToS PDB print_file source code to get an idea.
This page was generated using Literate.jl.