[chimerax-users] no gui mode and redirecting output of some commands

Shubham Devesh Ramgoolam sdramgoolam at uwaterloo.ca
Thu May 12 20:29:24 PDT 2022


Ok. Thanks again for the help Eric.

Shubham

________________________________
From: Eric Pettersen <pett at cgl.ucsf.edu>
Sent: May 12, 2022 9:22 PM
To: Shubham Devesh Ramgoolam <sdramgoolam at uwaterloo.ca>
Cc: ChimeraX Users Help <chimerax-users at cgl.ucsf.edu>
Subject: Re: [chimerax-users] no gui mode and redirecting output of some commands

Hi Shubham,
I’m not the Windows expert on the team but I believe that is correct.  Windows enforces a distinction between “command line” and “graphical user interface” programs, so in this case you should use the command-line version, namely ChimeraX-console.

—Eric

On May 12, 2022, at 3:41 AM, Shubham Devesh Ramgoolam via ChimeraX-users <chimerax-users at cgl.ucsf.edu<mailto:chimerax-users at cgl.ucsf.edu>> wrote:

Hi Eric,

Thank you so much for your input. I think I found the issue:

The script works when disabling gui if I use chimera-console to execute it from terminal.
So, the following works: ChimeraX-console --nogui --script myscript.py
And this one does not work: ChimeraX --nogui -script myscript.py

Is this how it is supposed to be?

Shubham.


Sent from Mail<https://go.microsoft.com/fwlink/?LinkId=550986> for Windows

From: Eric Pettersen<mailto:pett at cgl.ucsf.edu>
Sent: Wednesday, May 11, 2022 22:44
To: Shubham Devesh Ramgoolam<mailto:sdramgoolam at uwaterloo.ca>
Cc: ChimeraX Users Help<mailto:chimerax-users at cgl.ucsf.edu>
Subject: Re: [chimerax-users] no gui mode and redirecting output of some commands

Hi Shubham,
That script works fine on my Mac (with file paths adjusted and using 1EBT from the PDB).  It's possible you are getting errors from the script that you are not seeing because output is not going to the terminal/console.  Try running the script with the ChimeraX-console executable instead of the ChimeraX executable and see if that gives you any more information.

--Eric


On May 10, 2022, at 10:19 PM, Shubham Devesh Ramgoolam via ChimeraX-users <chimerax-users at cgl.ucsf.edu<mailto:chimerax-users at cgl.ucsf.edu>> wrote:

Hi Eric,

Thank you for your reply.

I have implemented the change as requested in my python script but I am still facing the same issue: Script works in gui mode but not in nogui mode(no text file made).

I have tried running the script in the RC build(May 5, 2022), latest production release (Dec 8, 2021), and the daily build (built on May 10, 2022) but to no avail.

Here is my script:

from chimerax.core.commands import run
from chimerax.atomic import selected_residues


run(session, "open C:\\Users\\Shubham\\Desktop\\PDB_Script\\1ebt.pdb")
run(session, "sel aromatic & protein")
with open("C:\\Users\\Shubham\\Desktop\\arom_list.txt", "w") as f:
    for r in selected_residues(session):
        print(r,file=f)


I also faced the same issue when writing the output of the command distance (between two centroids) to a text file: Script works in gui mode but not in nogui mode(no text file made).
Here is my script for that:

from chimerax.core.commands import run

run(session, "open C:\\Users\\Shubham\\Desktop\\PDB_Script\\1ebt.pdb")
run (session, 'define centroid /A:14 & aromatic-ring radius 0.3 color yellow mass false name C1')
run (session, 'define centroid /A:21 & aromatic-ring radius 0.3 color yellow mass false name C2')
file = open('C:\\Users\\Shubham\\Desktop\\distance.txt', 'w+')
dist = run(session, 'distance @c1 @c2')
file.write(str(dist))
file.close()

Regards,
Shubham


Sent from Mail<https://go.microsoft.com/fwlink/?LinkId=550986> for Windows

From: Eric Pettersen<mailto:pett at cgl.ucsf.edu>
Sent: Tuesday, May 10, 2022 22:00
To: Shubham Devesh Ramgoolam<mailto:sdramgoolam at uwaterloo.ca>
Cc: chimerax-users at cgl.ucsf.edu<mailto:chimerax-users at cgl.ucsf.edu>
Subject: Re: [chimerax-users] no gui mode and redirecting output of some commands

Hi Shubham,
It seems like a deficiency of the 'info' command that it can't put the information directly into a file.  We will look into rectifying that -- and yes, the problem is that the Log does not exist in nogui mode.  However, since you are using a Python script for this (rather than a Chimera command script), you can save the information directly to a file yourself.
Replace:

run(session, "info residue sel")
run(session, "log save aromatic_list.html")

with:

from chimerax.atomic import selected_residues
with open("where-I-want-to-save.txt", "w") as f:
for r in selected_residues(session):
print(r, file=f)

You can do similar things with distances and angles because the commands return the distance/angle values, e.g.:

d = run(session, "distance atom1 atom2")
write/append d to a file

--Eric

Eric Pettersen
UCSF Computer Graphics Lab




On May 10, 2022, at 3:29 AM, Shubham Devesh Ramgoolam via ChimeraX-users <chimerax-users at cgl.ucsf.edu<mailto:chimerax-users at cgl.ucsf.edu>> wrote:

Hi,
I hope you are doing well.
I have a python script (myscript.py) as follows:

from chimerax.core.commands import run
import os
os.chdir("C:\\Users\\Shubham\\Desktop")
run(session, "open C:\\Users\\Shubham\\Desktop\\PDB_Script\\1ebt.pdb")   # location of my pdb file
run(session, "sel aromatic & protein")
run(session, "log clear")
run (session, "info residue sel")
run(session, "log save aromatic_list.html")

I am using the following prompt for calling chimerax from command prompt:
Gui enabled:   chimerax --script C:\\Users\\Shubham\\Desktop\\myscript.py
Gui disabled:   chimerax --nogui --script C:\\Users\\Shubham\\Desktop\\myscript.py

With gui mode enabled, the html file, aromatic_list.html, is created.
However, when disabling gui, nothing is created.

I suspect this is because I am relying on the log which may not be functional when gui is disabled?
Is there a way of redirecting the output of certain commands (e.g info, distance, angle) to a desired text file when disabling gui?
I tried with sys.stdout but it did not work (empty text files were created.).

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


_______________________________________________
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


_______________________________________________
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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.rbvi.ucsf.edu/pipermail/chimerax-users/attachments/20220513/b02a0e21/attachment.html>


More information about the ChimeraX-users mailing list