[chimerax-users] Executing a script in chimerax python shell for an interactive session
Eric Pettersen
pett at cgl.ucsf.edu
Tue May 24 09:55:09 PDT 2022
Hi Shubham,
As far as I know, there is no way to get the Shell tool to start up with a script executing in it. I think what you need to do is have the script do all the heavy lifting. For one thing, it can get the path of the session file with code like this:
from chimera.ui.open_save import OpenDialogWithMessage
dialog = OpenDialogWithMessage(message="Choose the session file containing the structure to be analyzed", caption="Open Session")
session_format = session.data_formats["ChimeraX session"]
dialog.setNameFilter(session.data_formats.qt_file_filter(session_format))
paths = dialog.selectedFiles()
if not paths:
# user cancelled dialog
from chimerax.core.errors import CancelOperation
raise CancelOperation("script cancelled by user")
session_path = paths[0]
# probably use an "open" command to open the session
You would do a similar thing for the residues text file, except you probably would skip the setNameFilter() call since there is no particular suffix you are looking for.
So the tricky part is getting residue-pair choices from the user interactively. In an ideal world you would use Qt to create a dialog with a list of residue pairs in it, and clicking on an item in the list would visualize the pair. That's the approach I would use since I am familiar with Qt, but if you aren't then that's a pretty big learning curve for what you want to accomplish. Nonetheless, if that's what you'd like to do, just let me know and I'll provide some pointers.
Alternatively, a simpler approach is to leverage the fact that ChimeraX supports special HTML links that execute commands. So you would write out an HTML file with a link for every residue pair and the user could click on links to visualize the corresponding pair. The file would have a bunch of lines like:
<a href="cxcmd:sel :14,27; view sel">Residues 14 and 27</a>
or whatever commands you wanted to execute when the link is clicked, plus any other HTML you wanted to put in it. You would then just use the "open" command to open the HTML file and it will show up in a window.
--Eric
Eric Pettersen
UCSF Computer Graphics Lab
> On May 22, 2022, at 10:51 PM, Shubham Devesh Ramgoolam via ChimeraX-users <chimerax-users at cgl.ucsf.edu> wrote:
>
> Hi all,
> I hope you are doing well.
> I have a python script that allows the user to visualize specific residue pairs.
> Here is an overview of how the script functions:
> Ask the user to input the path of a .cxs file (created previously) and a text file containing the pairs to be visualized
> Print the names of the pairs along a uniquely assigned number
> Ask the user to input a number in order to visualize the pair assigned to it
>
> To run the script currently, I have to do the following: i)Open chimerax ii)Show the shell iii) Call the script from the shell
>
> Now, is it possible to include some codes in the script that would allow me to just open chimerax, click on File -> Open -> this script, and then the shell would show up and the execution would continue there?
>
> Right now, if I ran the script using File -> Open -> this script, I would get this error:
> Traceback (most recent call last):
> File "C:/Users/Shubham/Desktop/this_script.py", line 8, in
> session_path = input('Enter file (.cxs) to be visualized with path: \n')
> RuntimeError: input(): lost sys.stdin
>
> Regards,
> Shubham
>
> Sent from Mail <https://go.microsoft.com/fwlink/?LinkId=550986> for Windows
>
> _______________________________________________
> ChimeraX-users mailing list
> ChimeraX-users at cgl.ucsf.edu <mailto:ChimeraX-users at cgl.ucsf.edu>
> Manage subscription:
> https://www.rbvi.ucsf.edu/mailman/listinfo/chimerax-users <https://www.rbvi.ucsf.edu/mailman/listinfo/chimerax-users>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.rbvi.ucsf.edu/pipermail/chimerax-users/attachments/20220524/97d80570/attachment.html>
More information about the ChimeraX-users
mailing list