<html><head><base href="x-msg://69/"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><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-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; "><div lang="FR-BE" link="blue" vlink="purple"><div class="WordSection1" style="page: WordSection1; "><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></body></html>