
Hi, I am interested in performing the same actions several times on several different structures. For example: open a file, select the histidines, delete them, save and close. Is IDLE the right tool for that? I opened the python shell (Tools-> General Controls-> IDLE) but could not open files or manipulate them using the shell. I have no knowledge in python. What is the best way to write scripts to execute commands repeatedly? If IDLE is the tool, how can use it to do that? Is there a written source for that? Do I need to master python first? Many thanks, Ben

Hi Ben, IDLE is basically for interactive debugging or discovery of information in the Python layer (the latter via the help() function). For what you want to do you either want to write a Chimera-command script (.cmd suffix) or a Python script (.py suffix). Either kind can be run by opening the script with File...Open or the "open" command or by supplying the filename as an argument on the Chimera startup command line (the latter typically used more in Linux or IRIX environments). If what you want to do is no more complicated than what you outlined, you can get away with using a Chimera-command script. In particular you can use the "alias" command to construct a compound command that takes arguments. For example: alias ^process open $1.pdb; sel :HIS; del sel; write 0 $1.mod.pdb; close 0 creates an alias named "process" that if you execute it as "process 1gcn" will open the file 1gcn.pdb, select the histidines, delete the selected atoms, write the result to a file named 1gcn.mod.pdb, and then close the opened model. Aliases are saved in sessions and can be made available at startup. See the documention for the alias command for details on that. So you might make a command file like this: alias ^process open $1.pdb; sel :HIS; del sel; write 0 $1.mod.pdb; close 0 process 1gcn process 3fx2 process 1www ... You would have to use Python if you needed to loop through a range of values in your script, or only execute certain commands if some condition was true, or do something for which there is no equivalent Chimera command. We having some basic information for getting started in the Chimera Programmer's Guide: http://www.cgl.ucsf.edu/ chimera/docs/ProgrammersGuide/index.html The programmer documentation isn't nearly as extensive as the user documentation, so feel to ask questions -- either here or on the chimera-dev mailing list. --Eric Eric Pettersen UCSF Computer Graphics Lab http://www.cgl.ucsf.edu On Feb 6, 2008, at 12:41 PM, Ben Keshet wrote:
Hi,
I am interested in performing the same actions several times on several different structures. For example: open a file, select the histidines, delete them, save and close. Is IDLE the right tool for that? I opened the python shell (Tools-> General Controls-> IDLE) but could not open files or manipulate them using the shell. I have no knowledge in python. What is the best way to write scripts to execute commands repeatedly? If IDLE is the tool, how can use it to do that? Is there a written source for that? Do I need to master python first?
Many thanks,
Ben
_______________________________________________ Chimera-users mailing list Chimera-users@cgl.ucsf.edu http://www.cgl.ucsf.edu/mailman/listinfo/chimera-users

Hi Eric, Thanks for the detailed answer. I think the .cmd script will be sufficient for my purpose, however I was unable to write it correctly. What I want to do is slightly more complex than I outlined - I need to: open a mol2 structure, select certain residues (say select: 69-70), save the selected residues as a mol2 file, and select different residues and save them several more times. The .cmd looks something like that: alias ^process open $1.mol2; sel : 69-70; write selected 0 $1.his_CEGI.mol2; process p2 However, I was unable to create a proper mol2 file (I tried different options but my guess is that I have a syntax error). In some cases I was able to write out a file, but it was never a proper mol2 file. Alternatively, I tried: alias ^process open $1.mol2; sel : 69-70; select invert; del sel; write 0 $1.his_CEGI.mol2; process p2 which generated p2.his_CEGI.mol2, but the file could not be viewed with Chimera, and when inspected it looked different (no charge column and extra 3 columns: 1.00, 0.00, atom name). The whole script should be able to save mol2 files of several subsequences of several different structures. I would appreciate if you could help me identify what missing in the script. On a related note, the name of my structures have an underline in them (_), I noticed that Chimera puts a space instead. How do I make Chimera read, for example, p2_3.mol2 as it is (and not as p2 3.mol2)? Thanks a lot for you help, ben _____ From: Eric Pettersen [mailto:pett@cgl.ucsf.edu] Sent: Wednesday, February 06, 2008 5:34 PM To: Ben Keshet Cc: Chimera-users@cgl.ucsf.edu Subject: Re: [Chimera-users] using IDLE Hi Ben, IDLE is basically for interactive debugging or discovery of information in the Python layer (the latter via the help() function). For what you want to do you either want to write a Chimera-command script (.cmd suffix) or a Python script (.py suffix). Either kind can be run by opening the script with File...Open or the "open" command or by supplying the filename as an argument on the Chimera startup command line (the latter typically used more in Linux or IRIX environments). If what you want to do is no more complicated than what you outlined, you can get away with using a Chimera-command script. In particular you can use the "alias" command to construct a compound command that takes arguments. For example: alias ^process open $1.pdb; sel :HIS; del sel; write 0 $1.mod.pdb; close 0 creates an alias named "process" that if you execute it as "process 1gcn" will open the file 1gcn.pdb, select the histidines, delete the selected atoms, write the result to a file named 1gcn.mod.pdb, and then close the opened model. Aliases are saved in sessions and can be made available at startup. See the documention for the alias command for details on that. So you might make a command file like this: alias ^process open $1.pdb; sel :HIS; del sel; write 0 $1.mod.pdb; close 0 process 1gcn process 3fx2 process 1www ... You would have to use Python if you needed to loop through a range of values in your script, or only execute certain commands if some condition was true, or do something for which there is no equivalent Chimera command. We having some basic information for getting started in the Chimera Programmer's Guide: http://www.cgl.ucsf.edu/chimera/docs/ProgrammersGuide/index.html The programmer documentation isn't nearly as extensive as the user documentation, so feel to ask questions -- either here or on the chimera-dev mailing list. --Eric Eric Pettersen UCSF Computer Graphics Lab http://www.cgl.ucsf.edu On Feb 6, 2008, at 12:41 PM, Ben Keshet wrote: Hi, I am interested in performing the same actions several times on several different structures. For example: open a file, select the histidines, delete them, save and close. Is IDLE the right tool for that? I opened the python shell (Tools-> General Controls-> IDLE) but could not open files or manipulate them using the shell. I have no knowledge in python. What is the best way to write scripts to execute commands repeatedly? If IDLE is the tool, how can use it to do that? Is there a written source for that? Do I need to master python first? Many thanks, Ben _______________________________________________ Chimera-users mailing list Chimera-users@cgl.ucsf.edu http://www.cgl.ucsf.edu/mailman/listinfo/chimera-users

Hi Ben, When creating a script or alias, the first thing is to try all the commands individually rather than generating the whole thing at once and then wondering which one has not performed as expected. It looks like you had a space after the colon, which would not select anything. For example, I have a file ala12.mol2, so I tried the following commands: open ala12.mol2 (it was in the same directory in which I started Chimera) sel :2-6 write selected 0 ala12.stuff.mol2 I could see the selection command selected something, and then I could look in the output file, which did indeed contain those residues. Having validated the process, I can then try alias ^dostuff open $1.mol2; sel :2-6; write selected 0 $1.stuff.mol2 dostuff ala12 This does not address your underscore issue; I haven't experimented with that yet, but you may need to rename your inputs at least for now. I hope this helps, Elaine ----- Elaine C. Meng, Ph.D. meng@cgl.ucsf.edu UCSF Computer Graphics Lab and Babbitt Lab Department of Pharmaceutical Chemistry University of California, San Francisco http://www.cgl.ucsf.edu/home/meng/index.html On Feb 7, 2008, at 9:32 AM, Ben Keshet wrote:
Hi Eric,
Thanks for the detailed answer. I think the .cmd script will be sufficient for my purpose, however I was unable to write it correctly. What I want to do is slightly more complex than I outlined – I need to: open a mol2 structure, select certain residues (say select: 69-70), save the selected residues as a mol2 file, and select different residues and save them several more times. The .cmd looks something like that:
alias ^process open $1.mol2; sel : 69-70; write selected 0 $1.his_CEGI.mol2;
process p2
However, I was unable to create a proper mol2 file (I tried different options but my guess is that I have a syntax error). In some cases I was able to write out a file, but it was never a proper mol2 file. Alternatively, I tried:
alias ^process open $1.mol2; sel : 69-70; select invert; del sel; write 0 $1.his_CEGI.mol2;
process p2
which generated p2.his_CEGI.mol2, but the file could not be viewed with Chimera, and when inspected it looked different (no charge column and extra 3 columns: 1.00, 0.00, atom name). The whole script should be able to save mol2 files of several subsequences of several different structures. I would appreciate if you could help me identify what missing in the script.
On a related note, the name of my structures have an underline in them (_), I noticed that Chimera puts a space instead. How do I make Chimera read, for example, p2_3.mol2 as it is (and not as p2 3.mol2)?
Thanks a lot for you help,
ben

Hi Ben, reading more carefully what you wanted to do, it sounds like you don't want the alias to include "open" if you are just going to write out several different parts of the same input file. It sounds like you want something more like open input.mol2 alias ^getparts sel $1; write selected 0 $2.mol2 getparts :2-4 out1 getparts :4,8-10 out2 getparts :his,arg out3 ... there are a lot of different ways to do just about everything, however, and that is just one variant! For example, the alias could open the input file if it also closed it at the end (otherwise you'd get a lot of copies of the same thing opened in Chimera). Elaine On Feb 7, 2008, at 9:32 AM, Ben Keshet wrote:
Hi Eric,
Thanks for the detailed answer. I think the .cmd script will be sufficient for my purpose, however I was unable to write it correctly. What I want to do is slightly more complex than I outlined – I need to: open a mol2 structure, select certain residues (say select: 69-70), save the selected residues as a mol2 file, and select different residues and save them several more times. The .cmd looks something like that:
alias ^process open $1.mol2; sel : 69-70; write selected 0 $1.his_CEGI.mol2;
process p2

Me again! Just noticed you also omitted "format mol2" from the "write" command. The default format is PDB (even if you name it *.mol2). In my experiments I was concentrating on what atoms were there rather than the output format. Anyway, each command has a man page that describes its options and defaults. If you type the command "help [full-command-name]" it will show that command's man page, for example: help write and each individual command page links back to the index of all commands. Hopefully no more postscripts on this message... Elaine

Hi again... Thanks for getting back so quickly, and sorry to bother you again. I tried to use the format mol2 before but I get an error. I think that I am missing something very basic - I saw the man page (http://www.cgl.ucsf.edu/chimera/docs/UsersGuide/midas/write.html) And I tried the command: "write format mol2 selected 0 his.mol2" and different variations of that, and I always get an error: "format is not a model number". What am I doing wrong? Could you please write the command to save a selection as mol2? Thanks, -ben -----Original Message----- From: Elaine Meng [mailto:meng@cgl.ucsf.edu] Sent: Thursday, February 07, 2008 1:30 PM To: Ben Keshet Cc: chimera BB Subject: Re: [Chimera-users] using IDLE Me again! Just noticed you also omitted "format mol2" from the "write" command. The default format is PDB (even if you name it *.mol2). In my experiments I was concentrating on what atoms were there rather than the output format. Anyway, each command has a man page that describes its options and defaults. If you type the command "help [full-command-name]" it will show that command's man page, for example: help write and each individual command page links back to the index of all commands. Hopefully no more postscripts on this message... Elaine

Hi Ben, Your command is exactly right - I just tried it - but you must be using an old version of Chimera. The advantage of using the documentation included with your download (opened from the Chimera Help menu or with the "help" command) is that it should be fairly synchronized with the software and will not confuse you with options that do not exist in what you have! In this case, however, you can just get a newer version of Chimera (see below) and it will work. The pages under http://www.cgl.ucsf.edu/chimera/docs/UsersGuide/ are "development documentation," which I am constantly changing as Chimera changes. It will generally have newer things than your downloaded software. The pages under http://www.cgl.ucsf.edu/chimera/current/docs/ UsersGuide/ are documentation for the most recent production release (currently Nov 2007) and I see the format option to "write" was present at that time. Thus if you get the Nov 2007 production release: http://www.cgl.ucsf.edu/chimera/download.html#production you should be all set to write mol2 files from the command line. There are also much newer "daily builds" although they are essentially untested and exist mainly to provide access to the very latest developments. Best, Elaine ----- Elaine C. Meng, Ph.D. meng@cgl.ucsf.edu UCSF Computer Graphics Lab and Babbitt Lab Department of Pharmaceutical Chemistry University of California, San Francisco http://www.cgl.ucsf.edu/home/meng/index.html On Feb 7, 2008, at 11:32 AM, Ben Keshet wrote:
Hi again...
Thanks for getting back so quickly, and sorry to bother you again. I tried to use the format mol2 before but I get an error. I think that I am missing something very basic - I saw the man page (http://www.cgl.ucsf.edu/chimera/docs/UsersGuide/midas/write.html)
And I tried the command: "write format mol2 selected 0 his.mol2" and different variations of that, and I always get an error: "format is not a model number".
What am I doing wrong? Could you please write the command to save a selection as mol2?
Thanks, -ben
participants (3)
-
Ben Keshet
-
Elaine Meng
-
Eric Pettersen