<html dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style id="owaParaStyle" type="text/css">P {margin-top:0;margin-bottom:0;}</style>
</head>
<body ocsi="0" fpstyle="1" style="word-wrap:break-word">
<div style="direction: ltr;font-family: Tahoma;color: #000000;font-size: 10pt;">Hi Eric,<br>
<br>
Thank you very much, I didn't expect an (almost) ready to use script.<br>
I only change the loop, the one with enumerate didn't work. But now it works perfectly. This is the script I use :<br>
<br>
# the script assumes you've already opened the trajectory in Chimera <br>
from chimera import openModels, Molecule <br>
<br>
# we assume the trajectory is the only open model <br>
traj = openModels.list(modelTypes=[Molecule])[0] <br>
<br>
# load all the frames <br>
traj.loadAllFrames() <br>
<br>
# open the output file (change as desired) <br>
import os.path <br>
f = open(os.path.expanduser('~/Documents/hbonds.txt'), "w") <br>
<br>
# get the functions and parameters we need for finding H-bonds <br>
from FindHBond import findHBonds, recDistSlop, recAngleSlop <br>
<br>
# loop through the coordinate sets (frames) <br>
c = traj.coordSets <br>
for frame in range(len(c)): <br>
traj.activeCoordSet = c[frame+1] <br>
# find and print the number of H-bonds, and cache which atoms <br>
# are donors/acceptors, so they're not computed each frame <br>
print>>f, "Frame", frame+1, len(findHBonds([traj], distSlop=recDistSlop, angleSlop=recAngleSlop, cacheDA=True))
<br>
<br>
# close/flush the output file <br>
f.close()<br>
<br>
I have an additional question : what's the way to restrict the residues to search for hbond donors & acceptors with python commands?<br>
<br>
Jérémie<br>
<div style="font-family: Times New Roman; color: #000000; font-size: 16px">
<hr tabindex="-1">
<div style="direction: ltr;" id="divRpF810145"><font color="#000000" face="Tahoma" size="2"><b>De :</b> Eric Pettersen [pett@cgl.ucsf.edu]<br>
<b>Envoyé :</b> samedi 23 avril 2016 2:29<br>
<b>À :</b> Jérémie KNOOPS [531802]<br>
<b>Cc :</b> chimera-users@cgl.ucsf.edu<br>
<b>Objet :</b> Re: [Chimera-users] HBond on every frames of a large trajectory<br>
</font><br>
</div>
<div></div>
<div>
<div>
<div>On Apr 22, 2016, at 9:30 AM, Jérémie KNOOPS [531802] wrote:</div>
<br class="Apple-interchange-newline">
<blockquote type="cite"><span class="Apple-style-span" style="border-collapse:separate; font-family:Helvetica; font-style:normal; font-variant:normal; font-weight:normal; letter-spacing:normal; line-height:normal; orphans:2; text-indent:0px; text-transform:none; white-space:normal; widows:2; word-spacing:0px; font-size:medium">
<div lang="FR-BE">
<div class="WordSection1" style="">
<div style="margin-top:0cm; margin-right:0cm; margin-left:0cm; margin-bottom:0.0001pt; font-size:11pt; font-family:Calibri,sans-serif">
<span lang="EN-US">Hi,<br>
<br>
What is the easiest and fastest way to get the number of H bonds on every frame of a large trajectory (>10 000 frames) and print it to a file?<span class="Apple-converted-space"> </span><br>
The hbonds command does not seem to work with the perframe command and displaying the whole trajectory to run a per-frame script is quite slow.</span></div>
</div>
</div>
</span></blockquote>
</div>
<div><br>
</div>
<div>Hi Jérémie,</div>
<div><span class="Apple-tab-span" style="white-space:pre"></span>To do this efficiently, we need to use a Python script. In the script the important things to avoid are: 1) a redraw for every trajectory frame, and 2) creating and destroying graphics objects
representing the H-bonds every frame. This means we are going to avoid using the handy-but-non-efficient runCommand() Python call, which typically causes a redraw, and we are going to call the functions underlying the FindHBonds tool, in order to find the
h-bonded pairs without creating pseudobonds and so on. We will also step through the coordinate sets (frames) in Python.</div>
<div><span class="Apple-tab-span" style="white-space:pre"></span>Here's a script:</div>
<div><br>
</div>
<div># the script assumes you've already opened the trajectory in Chimera</div>
<div>from chimera import openModels, Molecule</div>
<div><br>
</div>
<div># we assume the trajectory is the only open model</div>
<div>traj = openModels.list(modelTypes=[Molecule])[0]</div>
<div><br>
</div>
<div># load all the frames</div>
<div>traj.loadAllFrames()</div>
<div><br>
</div>
<div># open the output file (change as desired)</div>
<div>import os.path</div>
<div>f = open(os.path.expanduser("~/hbonds.out"), "w")</div>
<div><br>
</div>
<div># get the functions and parameters we need for finding H-bonds</div>
<div>from FindHBond import findHBonds, recDistSlop, recAngleSlop</div>
<div><br>
</div>
<div># loop through the coordinate sets (frames)</div>
<div>for i, cs in enumerate(traj.coordSets):</div>
<div><span class="Apple-tab-span" style="white-space:pre"></span>traj.activeCoordSet = cs</div>
<div><span class="Apple-tab-span" style="white-space:pre"></span># find and print the number of H-bonds, and cache which atoms</div>
<div><span class="Apple-tab-span" style="white-space:pre"></span># are donors/acceptors, so they're not computed each frame</div>
<div><span class="Apple-tab-span" style="white-space:pre"></span>print>>f, "Frame", i+1, len(findHBonds([traj], distSlop=recDistSlop,</div>
<div><span class="Apple-tab-span" style="white-space:pre"></span>angleSlop=recAngleSlop, cacheDA=True))</div>
<div><br>
</div>
<div># close/flush the output file</div>
<div>f.close()</div>
<div><br>
</div>
<div>Put the above in a file whose name ends in ".py" and open it in Chimera (after opening your trajectory) and it should write the number of hydrogens bonds for each frame to a file named "hbonds.out" in your home directory. I didn't test it but I'm fairly
certain the logic is correct. I'm also pretty sure the syntax is correct, thought it's more possible I missed a parenthesis or quote somewhere. If you know Python it should be easy to fix any such errors . Otherwise, let me know the error and I'll provide
a fix.</div>
<div><br>
</div>
<div>--Eric</div>
<div><br>
</div>
<div><span class="Apple-tab-span" style="white-space:pre"></span>Eric Pettersen</div>
<div><span class="Apple-tab-span" style="white-space:pre"></span>UCSF Computer Graphics Lab</div>
<div><br>
</div>
<div><br>
</div>
</div>
</div>
</div>
</body>
</html>