declaring an integer to be used for the model and select command

Hello there! 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: Example def Rotate (0) where 0 would be the value of a variable called model inetger then later the function would have the code runCommand("move x -1 model #modelinteger") but when I try to compile chimera says model integer is not defined. I define it outside the function as modelinteger=0 but still the same error message shows. Basically how do I get chimera to understand that my variable modelinteger is indeed an integer?

If you include your Python code that does not work in your question we would surely have an answer. But it is impossible to say what the problem is with just your description. Tom On Oct 8, 2013, at 9:39 AM, Moses Adenaike wrote:
Hello there! 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:
Example def Rotate (0) where 0 would be the value of a variable called model inetger then later the function would have the code runCommand("move x -1 model #modelinteger") but when I try to compile chimera says model integer is not defined. I define it outside the function as modelinteger=0 but still the same error message shows.
Basically how do I get chimera to understand that my variable modelinteger is indeed an integer?
_______________________________________________ Chimera-dev mailing list Chimera-dev@cgl.ucsf.edu http://plato.cgl.ucsf.edu/mailman/listinfo/chimera-dev

On Oct 8, 2013, at 9:39 AM, Moses Adenaike <adenaike@sas.upenn.edu> wrote:
Hello there! 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:
Example def Rotate (0) where 0 would be the value of a variable called model inetger then later the function would have the code runCommand("move x -1 model #modelinteger") but when I try to compile chimera says model integer is not defined. I define it outside the function as modelinteger=0 but still the same error message shows.
Basically how do I get chimera to understand that my variable modelinteger is indeed an integer?
Hi Moses, 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: runCommand("move x -1 model #" + str(modelinteger)) --or-- runCommand("move x -1 model #%d" % modelinteger) The latter is doing string formatting/interpolation, and is described in more detail here: http://docs.python.org/2.7/library/stdtypes.html#string-formatting-operation... --Eric Eric Pettersen UCSF Computer Graphics Lab http://www.cgl.ucsf.edu
participants (3)
-
Eric Pettersen
-
Moses Adenaike
-
Tom Goddard