<html><head><meta http-equiv="Content-Type" content="text/html charset=iso-8859-1"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><div>On Oct 8, 2013, at 9:39 AM, Moses Adenaike <<a href="mailto:adenaike@sas.upenn.edu">adenaike@sas.upenn.edu</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div dir="ltr">Hello there!<div> I am trying to write a python script for chimera to rotate one molecule then translate another molecule to the right. I can get the code to work when I say use select 0 and model 1. But I want to define functions Rotate and Translate and be able to parse an integer value for the model numbers:</div>
<div><br></div><div>Example</div><div>def Rotate (0) where 0 would be the value of a variable called model inetger then later the function would have the code</div><div>runCommand("move x -1 model #modelinteger") but when I try to compile chimera says model integer is not defined.</div>
<div>I define it outside the function as modelinteger=0 but still the same error message shows.</div><div><br></div><div>Basically how do I get chimera to understand that my variable modelinteger is indeed an integer?</div></div></blockquote><br></div><div>Hi Moses,</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>You need to get the value of your variable into the string being sent to runCommand. As you've discovered, just putting the name of the variable doesn't do that -- it's just treated as literal text. Here's two ways:</div><div><br></div><div>runCommand("move x -1 model #" + str(modelinteger))</div><div><br></div><div>--or--</div><div><br></div><div>runCommand("move x -1 model #%d" % modelinteger)</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>The latter is doing string formatting/interpolation, and is described in more detail here: <a href="http://docs.python.org/2.7/library/stdtypes.html#string-formatting-operations">http://docs.python.org/2.7/library/stdtypes.html#string-formatting-operations</a></div><div><br></div><div>--Eric</div><br><div apple-content-edited="true">
<span class="Apple-style-span" style="border-collapse: separate; border-spacing: 0px 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 16px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: auto; -khtml-text-decorations-in-effect: none; text-indent: 0px; -apple-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><p style="margin: 0.0px 0.0px 0.0px 0.0px"><font face="Helvetica" size="5" style="font: 16.0px Helvetica"><span class="Apple-converted-space"> <span class="Apple-converted-space"> </span></span>Eric Pettersen</font></p><p style="margin: 0.0px 0.0px 0.0px 0.0px"><font face="Helvetica" size="5" style="font: 16.0px Helvetica"><span class="Apple-converted-space"> <span class="Apple-converted-space"> </span></span>UCSF Computer Graphics Lab</font></p><p style="margin: 0.0px 0.0px 0.0px 0.0px"><font face="Helvetica" size="5" style="font: 16.0px Helvetica"><span class="Apple-converted-space"> </span><a href="http://www.cgl.ucsf.edu">http://www.cgl.ucsf.edu</a></font></p><br class="Apple-interchange-newline"></span>
</div>
<br></body></html>