# [Chimera-users] Scripting Question

Helmick, Harrison Dale Brent hhelmick at purdue.edu
Fri Jul 31 16:05:05 PDT 2020

Eric,

Hey thank you so much for sending this over, this is a great little bit of code!
If I were to want to run and save a new file per frame, how would I do that? I didn't put a ton of time into exploring it today, working on a code to loop through the files I got and show which helices are degrading first, but my initial attempts for the % helix code you sent over wouldn't write to individual files. Here is what I had tried.

from chimera import runCommand as rc
from chimera import openModels, Molecule

outf = open("r'path\to\output\<FRAME>helix.txt", "w")
m = openModels.list(modelTypes=[Molecule])[0]
for i, cs in enumerate(m.coordSets):
m.activeCoordSet = cs
numHelix = 0
for r in m.residues:
if r.isHelix:
numHelix += 1
print>>outf, "frame %d, %.1f%% helix" % (I, numHelix * 100.0 / len(m.residues))
outf.close()

My issue on it is that the <FRAME> built in command from writesel did not translate into the python shell. When I tried to run my helix extraction to get the information about which helices were disappearing first I used:

from chimera import runCommand as rc

rc('ksdssp')
rc('sel helix')
rc('writesel (r'path\to\output\<FRAME>helix.txt')

but then this said that the <FRAME> (or maybe the writesel) command won't work in the python per script editor, so I used it in the chimera command per script piece and it worked great to get a new file per frame.
I also played around with things like:

#append list of % for all frames
outf = open(r'path\to\output\<FRAME>helix.txt','a')

#wirte new file for each frame
rc('writesel (r'path\to\output\%helix.txt')

But that also did not work.
Basically, I haven't been able to get the writing a new file per frame work in the the python shell yet.

Thank you,

Harrison

________________________________
From: Eric Pettersen <pett at cgl.ucsf.edu>
Sent: Thursday, July 30, 2020 7:44 PM
To: Helmick, Harrison Dale Brent <hhelmick at purdue.edu>
Cc: chimera-users at cgl.ucsf.edu <chimera-users at cgl.ucsf.edu>
Subject: Re: [Chimera-users] Scripting Question

Hi Harrison,
Elaine covered the writesel issue.  Sounds like you are proficient with Python, so here's a short script that writes the percentage of residues that are helix each frame to a file:

outf = open("/Users/myself/location/helix_percent.txt", "w")
from chimera import openModels, Molecule
m = openModels.list(modelTypes=[Molecule])[0]
for i, cs in enumerate(m.coordSets):
m.activeCoordSet = cs
numHelix = 0
for r in m.residues:
if r.isHelix:
numHelix += 1
print>>outf, "frame %d, %.1f%% helix" % (I, numHelix * 100.0 / len(m.residues))
outf.close()

You can use Chimera's Python shell (Tools→General Controls→IDLE) to nose around, use dir() on things to find attributes, and to try things out.  Feel free to ask more questions if needed.

--Eric

Eric Pettersen
UCSF Computer Graphics Lab

On Jul 30, 2020, at 10:07 AM, Helmick, Harrison Dale Brent <hhelmick at purdue.edu<mailto:hhelmick at purdue.edu>> wrote:

To the Chimera Team,

Hello, my name is Harrison Helmick, and I am a PhD student in Purdue University's department of food science. I hope that you all are doing well.
I am interested in developing more relationships between bioinformatic models and end use properties of foods, helping us understand and predict characteristics like emulsification, gelling, denaturation, etc.
I have been using Chimera to run molecular dynamic simulations, as well as analyze the protein structures and compare those to experimental properties. I'd like to see if there are predictable functional differences based on intermediate steps of denaturation of common seed storage proteins used in food. I have found Chimera to be super interesting and helpful in terms of my learning so far.
One of the characteristics I'd like to quantify is the change in secondary structure over the course of denaturation. I would like to have a script that returns the number of residues that are identified as the basic secondary structures so that I can graph the relative proportion of these structures of the course of the simulation. I'd also like to see which helices and strands are being degraded first, and I will compare that to their relative surface accessibility.
The way I have gone about this is to use the Chimera command per frame scripts KSDSSP, sel hex, and writesel to attempt to generate files for each frame. With a short python code, we could loop over the files to see which residue numbers disappear first and the progression of the destruction of helices, strands, etc. I haven't been able to get the dynamic file writing to work though, so I always write over the original file instead of saving it as a new one.
While I could probably figure out the dynamic file writing, this seems inefficient, and I was wondering if you all had a better script this process.

Thank you,

​--
Harrison Helmick
Kokini Lab, Purdue University
Philip E. Nelson Hall of Food Science
745 Agriculture Mall Dr.
West Lafayette, IN 47907-2009

_______________________________________________
Chimera-users mailing list: Chimera-users at cgl.ucsf.edu<mailto:Chimera-users at cgl.ucsf.edu>
Manage subscription: https://plato.cgl.ucsf.edu/mailman/listinfo/chimera-users

-------------- next part --------------
An HTML attachment was scrubbed...