<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
{font-family:Helvetica;
panose-1:2 11 5 4 2 2 2 2 2 4;}
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
font-size:11.0pt;
font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
span.apple-converted-space
{mso-style-name:apple-converted-space;}
.MsoChpDefault
{mso-style-type:export-only;}
@page WordSection1
{size:8.5in 11.0in;
margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
{page:WordSection1;}
--></style>
</head>
<body lang="EN-US" link="blue" vlink="#954F72" style="word-wrap:break-word">
<div class="WordSection1">
<p class="MsoNormal">Hi Eric,</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Thank you for your reply.</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">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).</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">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.</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Here is my script:</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">from chimerax.core.commands import run</p>
<p class="MsoNormal">from chimerax.atomic import selected_residues</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">run(session, "open C:\\Users\\Shubham\\Desktop\\PDB_Script\\1ebt.pdb")
</p>
<p class="MsoNormal">run(session, "sel aromatic & protein") </p>
<p class="MsoNormal">with open("C:\\Users\\Shubham\\Desktop\\arom_list.txt", "w") as f:</p>
<p class="MsoNormal"> for r in selected_residues(session):</p>
<p class="MsoNormal"> print(r,file=f)</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">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).
</p>
<p class="MsoNormal">Here is my script for that:</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">from chimerax.core.commands import run</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">run(session, "open C:\\Users\\Shubham\\Desktop\\PDB_Script\\1ebt.pdb")
<o:p></o:p></p>
<p class="MsoNormal">run (session, 'define centroid /A:14 & aromatic-ring radius 0.3 color yellow mass false name C1')</p>
<p class="MsoNormal">run (session, 'define centroid /A:21 & aromatic-ring radius 0.3 color yellow mass false name C2')</p>
<p class="MsoNormal">file = open('C:\\Users\\Shubham\\Desktop\\distance.txt', 'w+')</p>
<p class="MsoNormal">dist = run(session, 'distance @c1 @c2')</p>
<p class="MsoNormal">file.write(str(dist))</p>
<p class="MsoNormal">file.close()</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Regards,</p>
<p class="MsoNormal">Shubham</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Sent from <a href="https://go.microsoft.com/fwlink/?LinkId=550986">
Mail</a> for Windows</p>
<p class="MsoNormal"><o:p> </o:p></p>
<div style="mso-element:para-border-div;border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal" style="border:none;padding:0in"><b>From: </b><a href="mailto:pett@cgl.ucsf.edu">Eric Pettersen</a><br>
<b>Sent: </b>Tuesday, May 10, 2022 22:00<br>
<b>To: </b><a href="mailto:sdramgoolam@uwaterloo.ca">Shubham Devesh Ramgoolam</a><br>
<b>Cc: </b><a href="mailto:chimerax-users@cgl.ucsf.edu">chimerax-users@cgl.ucsf.edu</a><br>
<b>Subject: </b>Re: [chimerax-users] no gui mode and redirecting output of some commands</p>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Hi Shubham,<o:p></o:p></p>
<div>
<p class="MsoNormal">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.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">Replace:<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">run(session, "info residue sel")<br>
run(session, "log save aromatic_list.html")<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">with:<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">from chimerax.atomic import selected_residues<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">with open("where-I-want-to-save.txt", "w") as f:<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">for r in selected_residues(session):<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">print(r, file=f)<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">You can do similar things with distances and angles because the commands return the distance/angle values,
<i>e.g.</i>:<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">d = run(session, "distance <i>atom1 atom2</i>")<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><i>write/append d to a file</i><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<div>
<p class="MsoNormal">--Eric<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">Eric Pettersen<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">UCSF Computer Graphics Lab<o:p></o:p></p>
</div>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<div>
<p class="MsoNormal"><br>
<br>
<o:p></o:p></p>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<div>
<p class="MsoNormal">On May 10, 2022, at 3:29 AM, Shubham Devesh Ramgoolam via ChimeraX-users <<a href="mailto:chimerax-users@cgl.ucsf.edu">chimerax-users@cgl.ucsf.edu</a>> wrote:<o:p></o:p></p>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<div>
<p class="MsoNormal">Hi,<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">I hope you are doing well.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">I have a python script (myscript.py) as follows:<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">from chimerax.core.commands import run<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">import os<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">os.chdir("C:\\Users\\Shubham\\Desktop")<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">run(session, "open C:\\Users\\Shubham\\Desktop\\PDB_Script\\1ebt.pdb") # location of my pdb file<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">run(session, "sel aromatic & protein") <o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">run(session, "log clear")<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">run (session, "info residue sel")<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">run(session, "log save aromatic_list.html")<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">I am using the following prompt for calling chimerax from command prompt:<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">Gui enabled: chimerax --script C:\\Users\\Shubham\\Desktop\\myscript.py<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">Gui disabled: chimerax --nogui --script C:\\Users\\Shubham\\Desktop\\myscript.py<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">With gui mode enabled, the html file, aromatic_list.html, is created.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">However, when disabling gui, nothing is created.<span class="apple-converted-space"> </span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">I suspect this is because I am relying on the log which may not be functional when gui is disabled?<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">Is there a way of redirecting the output of certain commands (e.g info, distance, angle) to a desired text file when disabling gui?<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">I tried with sys.stdout but it did not work (empty text files were created.).<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">Regards,<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">Shubham<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">Sent from<span class="apple-converted-space"> </span><a href="https://go.microsoft.com/fwlink/?LinkId=550986">Mail</a><span class="apple-converted-space"> </span>for Windows<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Helvetica",sans-serif">_______________________________________________<br>
ChimeraX-users mailing list<br>
</span><a href="mailto:ChimeraX-users@cgl.ucsf.edu"><span style="font-size:9.0pt;font-family:"Helvetica",sans-serif">ChimeraX-users@cgl.ucsf.edu</span></a><span style="font-size:9.0pt;font-family:"Helvetica",sans-serif"><br>
Manage subscription:<br>
</span><a href="https://www.rbvi.ucsf.edu/mailman/listinfo/chimerax-users"><span style="font-size:9.0pt;font-family:"Helvetica",sans-serif">https://www.rbvi.ucsf.edu/mailman/listinfo/chimerax-users</span></a><o:p></o:p></p>
</div>
</blockquote>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</body>
</html>