[Chimera-users] Scripting Question
Eric Pettersen
pett at cgl.ucsf.edu
Mon Aug 3 13:43:20 PDT 2020
Hi Harrison,
The script I send is designed to be placed in a .py file and run directly (after you've created that trajectory of course). You run it simply by opening the .py file with the "open" command or File→Open. The script creates one file, with one line per frame indicting the helix percentage for that frame. It was meant as a jumping off point for writing whatever kind of analysis script you ultimately want.
Your modified version has a couple of misconceptions/problems. One is the "<FRAME>" is only defined within the MD Movie's dialog's Per-Frame scripting dialog, and only for Chimera-command scripts, not Python scripts (for Python scripts within that dialog it's "mdInfo['frame']"). The script I sent is not designed to run within the MD Movie dialog, so neither of those is relevant. If you really want one file per frame instead of a single combined file, you would need to move the open() (and close()) calls into the loop and base the file name off the 'i' variable.
--Eric
> On Jul 31, 2020, at 4:05 PM, Helmick, Harrison Dale Brent <hhelmick at purdue.edu> wrote:
>
> 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
>> Graduate Research Assistant, Ross Fellowship
>> 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 <https://plato.cgl.ucsf.edu/mailman/listinfo/chimera-users>
> _______________________________________________
> 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 <https://plato.cgl.ucsf.edu/mailman/listinfo/chimera-users>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://plato.cgl.ucsf.edu/pipermail/chimera-users/attachments/20200803/2bcd0cf3/attachment-0001.html>
More information about the Chimera-users
mailing list