Assigning pre-calculated attribute to B-factor column of pdb
Hi all, Is there an easy way to assign a pre-calculated attribute (for example, ramachandran probability) to the b-factor (or occupancy) column of a pdb file using chimera? I’d like to do this so I can color a pdb by ramachandran probability (or other custom attributes, e.g map-model correlation) and use it as a guide while rebuilding in Coot (which has options for coloring by b-factor or occupancy, but no other capacity for custom coloring of molecules). Best, Oliver.
Hi Oliver, If you don't get any better suggestions/offers, and if having the same value for all atoms in a given residue is acceptable, below is an ancient, dirty perl script that might do the trick for you. - Mark =========== Script: ========== #!/usr/bin/perl # # Number2TempFactInPDB.pl # USAGE: Number2TempFactInPDB.pl pdbfile temperaturefile > out_file.pdb # # Takes a standard PDB file and a tab (or space)-delimeted text file of the form: # Res# Value (value range = 0 to 100.0) # and for each residue, inserts the value into the temperature (B)-factor # column of the PDB file, sending the result to standard output # # the information can then be used to color code a molecular image in most # molec. graphics programs # # 12/31/02 mg $PDBfile = $ARGV[0]; $TempFile = $ARGV[1]; open(TEMPFILE, $TempFile) or die "can't open Temperature file"; while(<TEMPFILE>) { @line = split; $Temper{$line[0]} = $line[1]; } close(TEMPFILE); open(PDBFILE, $PDBfile) or die "can't open PDB file"; while(<PDBFILE>) { $line = $_; @modified_line = readAtomLine($line); if (($modified_line[0] ne "ATOM ")) { print $line; next } $resnum = $modified_line[8]; $modified_line[14] = $Temper{$resnum}; printAtomLine(@modified_line); } close(PDBFILE); # Functions below: #call as: @output_string = readAtomLine(input_line_as_string); sub readAtomLine { $OuT[0] = substr $_[0], 0, 6; #atom 1-6 $OuT[1] = int(substr $_[0], 6, 5); #atom serial number 7-11 $OuT[2] = substr $_[0], 7, 1; #??? $OuT[3] = substr $_[0], 12, 4; #atom name 13-16 $OuT[4] = substr $_[0], 16, 1; #alt loc indicator 17 $OuT[5] = substr $_[0], 17, 3; #res name 18-20 $OuT[6] = substr $_[0], 20, 1; #??? 21 $OuT[7] = substr $_[0], 21, 1; #chain ID 22 $OuT[8] = int(substr $_[0], 22, 4); #res seq number 23-26 $OuT[9] = substr $_[0], 26, 4; #icode for insert of residues 27 + $OuT[10] = substr $_[0], 30, 8; #X 8.3 31-38 $OuT[11] = substr $_[0], 38, 8; #Y 8.3 39-46 $OuT[12] = substr $_[0], 46, 8; #Z 8.3 47-54 $OuT[13] = substr $_[0], 54, 6; # Occupancy 6.2 55-60 $OuT[14] = substr $_[0], 60, 6; # B-factor 6.2 61-66 $OuT[15] = substr $_[0], 66, 10;# Element right-justif (2) 77-78 $OuT[16] = substr $_[0], 76, 2; # Element right-justif (2) 77-78 $OuT[17] = substr $_[0], 78, 2; # Charge (right-just string(2) 79-80 return @OuT; } sub printAtomLine { printf("%-6s%5d%1s%4s%1s%3s%1s%1s%4d%4s%8.3f%8.3f%8.3f%6.2f%6.2f%10s%2s%2s\n", @_); } ========== end of script ======== ________________________________________ From: chimera-users-bounces@cgl.ucsf.edu [chimera-users-bounces@cgl.ucsf.edu] on behalf of Oliver Clarke [olibclarke@gmail.com] Sent: Tuesday, August 26, 2014 11:52 AM To: chimera-users@cgl.ucsf.edu Subject: [Chimera-users] Assigning pre-calculated attribute to B-factor column of pdb Hi all, Is there an easy way to assign a pre-calculated attribute (for example, ramachandran probability) to the b-factor (or occupancy) column of a pdb file using chimera? I’d like to do this so I can color a pdb by ramachandran probability (or other custom attributes, e.g map-model correlation) and use it as a guide while rebuilding in Coot (which has options for coloring by b-factor or occupancy, but no other capacity for custom coloring of molecules). Best, Oliver. _______________________________________________ Chimera-users mailing list Chimera-users@cgl.ucsf.edu http://plato.cgl.ucsf.edu/mailman/listinfo/chimera-users
Hi Oliver, In general, you wouldn't need to overwrite B-factor in Chimera. You can easily define a custom attribute, that is, assign any set of values that you like to atoms or residues. Your custom attribute can be rendered (color, worm fatness), used as a selection criterion, etc. just like other existing attributes. However, I see you want it as B-factor for use in Coot… more on that below… If you want to zero out the bfactor values for solvent, ligands, ions (that will not have Ramachandran values to overwrite them), might as well zero out everything first, such as with the command: setattr a bfactor 0 @* <http://www.rbvi.ucsf.edu/chimera/docs/UsersGuide/midas/setattr.html> If you were going to create some arbitrary custom attribute, this is done by making an "attribute defintion file" and reading it in with Define Attribute (in menu under Tools… Structure Analysis) or the command "defattr." The file is a simple text format, and there are examples: <http://www.rbvi.ucsf.edu/chimera/docs/ContributedSoftware/defineattrib/defineattrib.html#attrfile> The file could indicate attribute name "bfactor" to overwrite the existing values, as mentioned in this previous post: <http://plato.cgl.ucsf.edu/pipermail/chimera-users/2013-December/009488.html> Actually, the Ramachandran tool already creates an attribute. If you choose the "Ramachandran plot…" function on the right side of the Model Panel, then get a plot, there is an "Assign Residue Probabilities" button that creates a residue attribute named "ramaProb". Or, you can use the "ramachandran" command with the "assign" keyword to do the same thing. <http://www.rbvi.ucsf.edu/chimera/docs/ContributedSoftware/ramachandran/ramachandran.html> <http://www.rbvi.ucsf.edu/chimera/docs/UsersGuide/midas/ramachandran.html> You can write out the ramaProb values in the needed format, then manually edit the top two lines of the file to change the name to "bfactor" and the recipient level to "atoms" and read it back in with Define Attribute or command "defattr". To write out the values, open Render by Attribute (in menu under Tools… Structure Analysis) and then in that tool's menu, choose "File… Save Attributes" to save the attribute of "residues" named "ramaProb". (First I tried reassignment using the Attribute Calculator tool instead of writing/reading a file, but currently Chimera doesn't allow overwriting "bfactor" by that more direct route.) THEN, you can write a PDB file with the altered bfactor values. I hope this helps, Elaine ---------- Elaine C. Meng, Ph.D. UCSF Computer Graphics Lab (Chimera team) and Babbitt Lab Department of Pharmaceutical Chemistry University of California, San Francisco On Aug 26, 2014, at 8:52 AM, Oliver Clarke <olibclarke@gmail.com> wrote:
Hi all,
Is there an easy way to assign a pre-calculated attribute (for example, ramachandran probability) to the b-factor (or occupancy) column of a pdb file using chimera?
I’d like to do this so I can color a pdb by ramachandran probability (or other custom attributes, e.g map-model correlation) and use it as a guide while rebuilding in Coot (which has options for coloring by b-factor or occupancy, but no other capacity for custom coloring of molecules).
Best, Oliver.
Thanks to both Elaine and Mark for the quick replies! Elaine, that works very well, thank you. Would it be possible in some future version to have an option to replace the b-factor column with a custom attribute directly (or via a command), to make this process quicker and avoid having to write out, edit and read in the attribute file? I find this handy for highlighting particular problem regions in coot or other programs that can color by b-factor (I could envision doing the same thing for the overlap attribute of find clashes, or some sort of rotamer probability attribute, for example). Cheers, Oliver. On Aug 26, 2014, at 12:58 PM, Elaine Meng <meng@cgl.ucsf.edu> wrote:
Hi Oliver, In general, you wouldn't need to overwrite B-factor in Chimera. You can easily define a custom attribute, that is, assign any set of values that you like to atoms or residues. Your custom attribute can be rendered (color, worm fatness), used as a selection criterion, etc. just like other existing attributes. However, I see you want it as B-factor for use in Coot… more on that below…
If you want to zero out the bfactor values for solvent, ligands, ions (that will not have Ramachandran values to overwrite them), might as well zero out everything first, such as with the command: setattr a bfactor 0 @* <http://www.rbvi.ucsf.edu/chimera/docs/UsersGuide/midas/setattr.html>
If you were going to create some arbitrary custom attribute, this is done by making an "attribute defintion file" and reading it in with Define Attribute (in menu under Tools… Structure Analysis) or the command "defattr." The file is a simple text format, and there are examples: <http://www.rbvi.ucsf.edu/chimera/docs/ContributedSoftware/defineattrib/defineattrib.html#attrfile>
The file could indicate attribute name "bfactor" to overwrite the existing values, as mentioned in this previous post: <http://plato.cgl.ucsf.edu/pipermail/chimera-users/2013-December/009488.html>
Actually, the Ramachandran tool already creates an attribute. If you choose the "Ramachandran plot…" function on the right side of the Model Panel, then get a plot, there is an "Assign Residue Probabilities" button that creates a residue attribute named "ramaProb". Or, you can use the "ramachandran" command with the "assign" keyword to do the same thing. <http://www.rbvi.ucsf.edu/chimera/docs/ContributedSoftware/ramachandran/ramachandran.html> <http://www.rbvi.ucsf.edu/chimera/docs/UsersGuide/midas/ramachandran.html>
You can write out the ramaProb values in the needed format, then manually edit the top two lines of the file to change the name to "bfactor" and the recipient level to "atoms" and read it back in with Define Attribute or command "defattr". To write out the values, open Render by Attribute (in menu under Tools… Structure Analysis) and then in that tool's menu, choose "File… Save Attributes" to save the attribute of "residues" named "ramaProb".
(First I tried reassignment using the Attribute Calculator tool instead of writing/reading a file, but currently Chimera doesn't allow overwriting "bfactor" by that more direct route.)
THEN, you can write a PDB file with the altered bfactor values.
I hope this helps, Elaine ---------- Elaine C. Meng, Ph.D. UCSF Computer Graphics Lab (Chimera team) and Babbitt Lab Department of Pharmaceutical Chemistry University of California, San Francisco
On Aug 26, 2014, at 8:52 AM, Oliver Clarke <olibclarke@gmail.com> wrote:
Hi all,
Is there an easy way to assign a pre-calculated attribute (for example, ramachandran probability) to the b-factor (or occupancy) column of a pdb file using chimera?
I’d like to do this so I can color a pdb by ramachandran probability (or other custom attributes, e.g map-model correlation) and use it as a guide while rebuilding in Coot (which has options for coloring by b-factor or occupancy, but no other capacity for custom coloring of molecules).
Best, Oliver.
Hi Oliver, The more direct way I tried used Attribute Calculator (in menu under Tools.. Structure Analysis) to calculate attribute "bfactor" for "atoms" using the formula: residue.ramaProb (after assignment using Ramachandran). It currently generates an error, which seems buglike. I could create a new atom attribute with that formula, but not overwrite "bfactor". We'll look into that . Best, Elaine On Aug 26, 2014, at 10:17 AM, Oliver Clarke <olibclarke@gmail.com> wrote:
Thanks to both Elaine and Mark for the quick replies!
Elaine, that works very well, thank you. Would it be possible in some future version to have an option to replace the b-factor column with a custom attribute directly (or via a command), to make this process quicker and avoid having to write out, edit and read in the attribute file?
I find this handy for highlighting particular problem regions in coot or other programs that can color by b-factor (I could envision doing the same thing for the overlap attribute of find clashes, or some sort of rotamer probability attribute, for example).
Cheers, Oliver.
On Aug 26, 2014, at 10:27 AM, Elaine Meng <meng@cgl.ucsf.edu> wrote:
Hi Oliver, The more direct way I tried used Attribute Calculator (in menu under Tools.. Structure Analysis) to calculate attribute "bfactor" for "atoms" using the formula:
residue.ramaProb
(after assignment using Ramachandran). It currently generates an error, which seems buglike. I could create a new atom attribute with that formula, but not overwrite "bfactor". We'll look into that .
The problem here is that bfactors must be numeric, but some residues have a ramaProb of "None" (e.g. they are terminal residues or non-peptides and lack either a phi or a psi). You can assign such residues a ramaProb of -1.0 with this command: setattr r ramaProb -1.0 :/^ramaProb You could then use the Attribute Calculator to assign the ramaProbs to the bfactors. --Eric Eric Pettersen UCSF Computer Graphics Lab http://www.cgl.ucsf.edu
That works well, thanks Eric. Is there any way to reassign the ramaProbs to the bfactor column on the command line, without using the attribute calculator? That way I can set the whole sequence of commands as an alias. Cheers, Oliver. On Aug 26, 2014, at 1:45 PM, Eric Pettersen <pett@cgl.ucsf.edu> wrote:
On Aug 26, 2014, at 10:27 AM, Elaine Meng <meng@cgl.ucsf.edu> wrote:
Hi Oliver, The more direct way I tried used Attribute Calculator (in menu under Tools.. Structure Analysis) to calculate attribute "bfactor" for "atoms" using the formula:
residue.ramaProb
(after assignment using Ramachandran). It currently generates an error, which seems buglike. I could create a new atom attribute with that formula, but not overwrite "bfactor". We'll look into that .
The problem here is that bfactors must be numeric, but some residues have a ramaProb of "None" (e.g. they are terminal residues or non-peptides and lack either a phi or a psi). You can assign such residues a ramaProb of -1.0 with this command:
setattr r ramaProb -1.0 :/^ramaProb
You could then use the Attribute Calculator to assign the ramaProbs to the bfactors.
--Eric
Eric Pettersen UCSF Computer Graphics Lab http://www.cgl.ucsf.edu
There isn't a Chimera command implementation of Attribute Calculator, sorry! Elaine On Aug 26, 2014, at 11:28 AM, Oliver Clarke <olibclarke@gmail.com> wrote:
That works well, thanks Eric. Is there any way to reassign the ramaProbs to the bfactor column on the command line, without using the attribute calculator? That way I can set the whole sequence of commands as an alias.
Cheers, Oliver. On Aug 26, 2014, at 1:45 PM, Eric Pettersen <pett@cgl.ucsf.edu> wrote:
On Aug 26, 2014, at 10:27 AM, Elaine Meng <meng@cgl.ucsf.edu> wrote:
Hi Oliver, The more direct way I tried used Attribute Calculator (in menu under Tools.. Structure Analysis) to calculate attribute "bfactor" for "atoms" using the formula:
residue.ramaProb
(after assignment using Ramachandran). It currently generates an error, which seems buglike. I could create a new atom attribute with that formula, but not overwrite "bfactor". We'll look into that .
The problem here is that bfactors must be numeric, but some residues have a ramaProb of "None" (e.g. they are terminal residues or non-peptides and lack either a phi or a psi). You can assign such residues a ramaProb of -1.0 with this command:
setattr r ramaProb -1.0 :/^ramaProb
You could then use the Attribute Calculator to assign the ramaProbs to the bfactors.
--Eric
Eric Pettersen UCSF Computer Graphics Lab http://www.cgl.ucsf.edu
_______________________________________________ Chimera-users mailing list Chimera-users@cgl.ucsf.edu http://plato.cgl.ucsf.edu/mailman/listinfo/chimera-users
As Elaine says, there is no command equivalent. However, a tiny Python script will do it: from chimera import openModels, Molecule for m in openModels.list(modelTypes=[Molecule]): for a in m.atoms: a.bfactor = a.residue.ramaProb If you put the above in a file ending in '.py', you can open it in Chimera with the "open" command to run it and therefore can just put that open command in your script/alias. Indentation is important in Python, so preserve the indentation when you create the .py file. --Eric On Aug 26, 2014, at 11:33 AM, Elaine Meng <meng@cgl.ucsf.edu> wrote:
There isn't a Chimera command implementation of Attribute Calculator, sorry!
Elaine
On Aug 26, 2014, at 11:28 AM, Oliver Clarke <olibclarke@gmail.com> wrote:
That works well, thanks Eric. Is there any way to reassign the ramaProbs to the bfactor column on the command line, without using the attribute calculator? That way I can set the whole sequence of commands as an alias.
Cheers, Oliver. On Aug 26, 2014, at 1:45 PM, Eric Pettersen <pett@cgl.ucsf.edu> wrote:
On Aug 26, 2014, at 10:27 AM, Elaine Meng <meng@cgl.ucsf.edu> wrote:
Hi Oliver, The more direct way I tried used Attribute Calculator (in menu under Tools.. Structure Analysis) to calculate attribute "bfactor" for "atoms" using the formula:
residue.ramaProb
(after assignment using Ramachandran). It currently generates an error, which seems buglike. I could create a new atom attribute with that formula, but not overwrite "bfactor". We'll look into that .
The problem here is that bfactors must be numeric, but some residues have a ramaProb of "None" (e.g. they are terminal residues or non-peptides and lack either a phi or a psi). You can assign such residues a ramaProb of -1.0 with this command:
setattr r ramaProb -1.0 :/^ramaProb
You could then use the Attribute Calculator to assign the ramaProbs to the bfactors.
--Eric
Eric Pettersen UCSF Computer Graphics Lab http://www.cgl.ucsf.edu
_______________________________________________ Chimera-users mailing list Chimera-users@cgl.ucsf.edu http://plato.cgl.ucsf.edu/mailman/listinfo/chimera-users
_______________________________________________ Chimera-users mailing list Chimera-users@cgl.ucsf.edu http://plato.cgl.ucsf.edu/mailman/listinfo/chimera-users
Thanks Eric, that works perfectly! Now I use the following alias in my startup file: alias ^rama2bfac ramachandran assign $1 ; setattr r ramaProb 1.0 :/^ramaProb ; open ~/Dropbox/chimera_startup/b_fac2rama.py and it does exactly what I want. Thanks! OIiver On Aug 26, 2014, at 2:39 PM, Eric Pettersen <pett@cgl.ucsf.edu> wrote:
from chimera import openModels, Molecule for m in openModels.list(modelTypes=[Molecule]): for a in m.atoms: a.bfactor = a.residue.ramaProb
I've changed the Attribute Calculator so that assigning non-numeric values to bfactor (and occupancy) no longer generates an error. They are counted as "unable to calculate" errors and the atom attribute value left unchanged. This means you need to use the setattr command to set a default value for all atom bfactor (or occupancy) attributes before using the Attribute Calculator, or else you might get a mixture of old bfactor values and the newly computed attribute values. Conrad On 8/26/2014 10:45 AM, Eric Pettersen wrote:
On Aug 26, 2014, at 10:27 AM, Elaine Meng <meng@cgl.ucsf.edu <mailto:meng@cgl.ucsf.edu>> wrote:
Hi Oliver, The more direct way I tried used Attribute Calculator (in menu under Tools.. Structure Analysis) to calculate attribute "bfactor" for "atoms" using the formula:
residue.ramaProb
(after assignment using Ramachandran). It currently generates an error, which seems buglike. I could create a new atom attribute with that formula, but not overwrite "bfactor". We'll look into that .
The problem here is that bfactors /must/ be numeric, but some residues have a ramaProb of "None" (e.g. they are terminal residues or non-peptides and lack either a phi or a psi). You can assign such residues a ramaProb of -1.0 with this command:
setattr r ramaProb -1.0 :/^ramaProb
You could then use the Attribute Calculator to assign the ramaProbs to the bfactors.
--Eric
Eric Pettersen
UCSF Computer Graphics Lab
_______________________________________________ Chimera-users mailing list Chimera-users@cgl.ucsf.edu http://plato.cgl.ucsf.edu/mailman/listinfo/chimera-users
participants (5)
-
Conrad Huang
-
Elaine Meng
-
Eric Pettersen
-
Mark Girvin
-
Oliver Clarke