How to modify B-factor column of a PDB file with Bio3D?

Issue #891 new
Gundala Viswanath created an issue

Is there a way we can assign the B-factor values of specific chain and residue number?

I have this PDB file, which contains chain A and B.
And I want to create a new PDB file with B-factor assigned to chain B.
This is a text file that lists all residue numbers of chain B and its new B-factors.

#Res chain resno B-fact
GLY B   1   63
LYS B   2   64
MET B   3    2
SER B   4   22
SER B   5   51
TYR B   6   61
ALA B   7   78
PHE B   8   80
PHE B   9   16
VAL B   10  30
GLN B   11  77
THR B   12  84
CYS B   13  34
ARG B   14  80
GLU B   15  28
GLU B   16  55
HIS B   17  36
LYS B   18  95
LYS B   19  92
LYS B   20  72
HIS B   21  51
PRO B   22  40
ASP B   23  20
ALA B   24  39
SER B   25  13
VAL B   26  64
ASN B   27  91
PHE B   28  24
SER B   29  11
GLU B   30  48
PHE B   31  14
SER B   32  100
LYS B   33  14
LYS B   34  61

Is there a way to do it with Bio3D?

At the end of the day, I want to use Pymol to color-scale the residue based on the B-factor.

Thanks and hope to hear from you again.

G.V.

Comments (6)

  1. Xinqiu Yao

    Yes, you can pass the b-factor to the b= argument of write.pdb(). Note that if the length of the b-factor vector is equal to the number of residues while the pdb you are writing has all the atoms, you must expand the b-factor to match pdb using vec2resno(). For example,

    # Suppose b-factor is 'b' and its length is the number of residues
    # Suppose pdb has all the atoms.
    
    # Expand the b-factor to match pdb
    # Note that this is optional. If your pdb has only C-alpha, you don't need to expand.
    b2 <- vec2resno(b, pdb$atom$resno)
    
    # write pdb with the b-factor column replaced by b2
    write.pdb(pdb, b=b2, file="new.pdb")
    
  2. Log in to comment