<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1256">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Amith,</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
The "run" function can return a value depending on the command that is executed. For the distance command, the distance is returned as a floating-point number. If I'm understanding what you're trying to do, this should work (I have not tested this):</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<span style="font-family: Consolas, Courier, monospace;">import os</span>
<div><span style="font-family: Consolas, Courier, monospace;">from chimerax.core.commands import run as rc</span></div>
<div><br>
</div>
<div><br>
</div>
<div><span style="font-family: Consolas, Courier, monospace;">target_folder = '/wynton/home/jacobson/avranga1008/Documents/0-combo'</span></div>
<div><span style="font-family: Consolas, Courier, monospace;">os.chdir(target_folder)</span></div>
<div><span style="font-family: Consolas, Courier, monospace;">home = os.getcwd()</span></div>
<div><span style="font-family: Consolas, Courier, monospace;">xp_distance_file = os.path.join(home,'xp-distance.log')</span></div>
<div><span style="font-family: Consolas, Courier, monospace;">xp_distance_obj = open(xp_distance_file, "w")</span></div>
<div><br>
</div>
<div><span style="font-family: Consolas, Courier, monospace;">for f in os.listdir():</span></div>
<div><span style="font-family: Consolas, Courier, monospace;"> if f.endswith('.mae'):</span></div>
<div><span style="font-family: Consolas, Courier, monospace;"> print(f'working on {f}')</span></div>
<div><span style="font-family: Consolas, Courier, monospace;"> rc(session, "open " + f)</span></div>
<div><span style="font-family: Consolas, Courier, monospace;"> rc(session, "measure center #1.1 & ligand mark true")</span></div>
<div><span style="font-family: Consolas, Courier, monospace;"> rc(session, "measure center #1.1 :310,335,728,759 mark true")</span></div>
<div><span style="font-family: Consolas, Courier, monospace;"> # grab distance<br>
</span></div>
<div><span style="font-family: Consolas, Courier, monospace;"> dist = rc(session, "distance #2 #3")</span></div>
<div><span style="font-family: Consolas, Courier, monospace;"> rc(session, "close")</span></div>
<div><span style="font-family: Consolas, Courier, monospace;"> xp_distance_obj.write("%s %.2f" % (f, dist))</span></div>
<div><br>
</div>
<div><span style="font-family: Consolas, Courier, monospace;">xp_distance_obj.close()</span></div>
<div><br>
</div>
<span style="font-family: Consolas, Courier, monospace;">exit()</span></div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
Best,
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Tony<br>
</div>
<div id="appendonsend"></div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> ChimeraX-users <chimerax-users-bounces@cgl.ucsf.edu> on behalf of Rangarajan, Amith via ChimeraX-users <chimerax-users@cgl.ucsf.edu><br>
<b>Sent:</b> Saturday, February 12, 2022 9:26 AM<br>
<b>To:</b> ChimeraX Users Help <ChimeraX-users@cgl.ucsf.edu><br>
<b>Subject:</b> Re: [chimerax-users] python script for measuring distance</font>
<div> </div>
</div>
<style>
<!--
.x_pfptBannerTableMSO
{padding:0px 12px 5px 12px;
width:100%;
border-radius:4px;
border-top:4px solid #90a4ae;
background-color:#D0D8DC}
.x_pfptTitleMSO
{color:#000000!important;
font-family:'Arial',sans-serif!important;
font-weight:bold!important;
font-size:14px!important}
.x_pfptSubtitleMSO
{font-size:12px!important;
font-family:'Arial',sans-serif!important}
.x_pfptButtonMSO
{padding:7.5px;
text-decoration:none;
font-family:'Arial',sans-serif!important;
font-size:14px;
line-height:40px;
border-radius:2px}
.x_pfptPrimaryButtonMSO
{border:1.5px solid #666666;
color:#000000}
.x_pfptBanner
{margin:15px 14px 30px 14px;
padding:8px 16px 8px 16px;
border-radius:4px;
min-width:200px;
background-color:#D0D8DC;
border-top:4px solid #90a4ae}
.x_pfptBannerTitle
{color:#000000;
font-family:'Arial',sans-serif;
font-size:14px;
font-weight:bold;
line-height:18px;
display:block}
.x_pfptBannerSubtitle
{color:#000000;
font-weight:normal;
font-family:'Arial',sans-serif;
font-size:12px;
line-height:18px;
margin-top:2px;
display:block}
.x_pfptButton
{display:inline-block;
font-family:'Arial',sans-serif;
font-size:14px;
font-weight:normal;
border-radius:2px;
padding:7.5px 16px;
margin:3px 0 3px 16px;
white-space:nowrap;
width:fit-content}
.x_pfptPrimaryButton
{border:1px solid #666666}
.x_pfptMessageContainer
{display:inline-block;
margin:0px 0px 1px 0px;
max-width:600px}
.x_pfptButtonGroup
{float:right;
margin:0px 0px 0px 16px;
text-align:right;
width:fit-content}
.x_pfptPreheader
{display:none!important;
visibility:hidden;
font-size:1px;
line-height:1px;
max-height:0px;
max-width:0px;
opacity:0;
overflow:hidden}
-->
</style><style type="text/css" style="display:none">
<!--
p
{margin-top:0;
margin-bottom:0}
-->
</style>
<div dir="ltr"><font color="BA0C2F">[EXTERNAL SENDER - PROCEED CAUTIOUSLY]</font><br>
<br>
<div><span class="x_pfptPreheader" style="display:none!important; visibility:hidden; font-size:1px; color:#ffffff; line-height:1px; max-height:0px; max-width:0px; opacity:0; overflow:hidden">Hello everyone, Please see my script below: import os import sys from
chimerax.core.commands import run as rc target_folder = '/wynton/home/jacobson/avranga1008/Documents/0-combo' os.chdir(target_folder) home =os.getcwd() ž ž ž ž ž ž ž ž ž ž ž ž ž ž ž ž ž ž
</span><span style="display:none!important; visibility:hidden; font-size:1px; color:#ffffff; line-height:1px; max-height:0px; max-width:0px; opacity:0; overflow:hidden">ZjQcmQRYFpfptBannerStart</span>
<div dir="ltr" lang="en" class="x_pfptBanner" style="margin:16px 0px 16px 0px; padding:8px 16px 8px 16px; border-radius:4px; min-width:200px; background-color:#D0D8DC; border-top:4px solid #90a4ae">
<div class="x_pfptMessageContainer" style="display:inline-block; margin:0px 0px 1px 0px; max-width:600px">
<div class="x_pfptBannerTitle" style="color:#000000!important; font-family:'Arial',sans-serif!important; font-weight:bold!important; font-size:14px!important; line-height:18px; display:block">
This Message Is From an External Sender </div>
<div class="x_pfptBannerSubtitle" style="color:#000000!important; font-weight:normal!important; font-family:'Arial',sans-serif!important; font-size:12px!important; line-height:18px; margin-top:2px; display:block">
This message came from outside your organization. </div>
</div>
</div>
<div style="display:none!important; visibility:hidden; font-size:1px; color:#ffffff; line-height:1px; max-height:0px; max-width:0px; opacity:0; overflow:hidden">
ZjQcmQRYFpfptBannerEnd</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0); background-color:rgb(255,255,255)">
Hello everyone,</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0); background-color:rgb(255,255,255)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0); background-color:rgb(255,255,255)">
Please see my script below:</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0); background-color:rgb(255,255,255)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0); background-color:rgb(255,255,255)">
import os
<div>import sys</div>
<div>from chimerax.core.commands import run as rc</div>
<div>target_folder = '/wynton/home/jacobson/avranga1008/Documents/0-combo'</div>
<div>os.chdir(target_folder)</div>
<div>home =os.getcwd()</div>
<div>all = os.listdir()</div>
<div>xp_distance_file = os.path.join(home,'xp-distance.log')</div>
<div>print_to_screen = sys.stdout</div>
<div>mae_files =[]</div>
<div>for f in all:</div>
<div> if f.endswith('.mae'):</div>
<div> mae_files.append(f)</div>
<div> print(f'working on {f}')</div>
<div> sys.stdout = open(xp_distance_file,'a')</div>
<div> rc(session,"open " + f)</div>
<div> rc(session,"measure center #1.1 & ligand mark true")</div>
<div> rc(session,"measure center #1.1 :310,335,728,759 mark true")</div>
<div> rc(session,"distance #2 #3")</div>
<div> rc(session,"close")</div>
<div> sys.stdout = print_to_screen</div>
<div>print(f'completed writing xp-distance values to {xp_distance_file} ; now moving to next loop')</div>
<div>for f in mae_files:</div>
<div> line = f + '\n'</div>
<div> open('file_list.txt','a').write(line)</div>
<div>print("loop is complete")</div>
exit()<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0); background-color:rgb(255,255,255)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0); background-color:rgb(255,255,255)">
I am curently using stdout to write the distance values to a file .I am currently running it on command line</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0); background-color:rgb(255,255,255)">
</div>
<img class="x_w-326 x_h-28" size="3867" style="margin:0px; max-width:100%; color:rgb(0,0,0)" data-outlook-trace="F:2|T:2" src="cid:68afa919-1a35-470f-808c-242e97c85957">
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0); background-color:rgb(255,255,255)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0); background-color:rgb(255,255,255)">
it seems like a round about way to do it. The output file has lot of special characters and it takes a bit of effort using regex to extract the values.</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0); background-color:rgb(255,255,255)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0); background-color:rgb(255,255,255)">
I think there might be some logger in chimerax which can do this or some other better way to write results to a file , but i am not able to find it. </div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0); background-color:rgb(255,255,255)">
#############</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0); background-color:rgb(255,255,255)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0); background-color:rgb(255,255,255)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0); background-color:rgb(255,255,255)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0); background-color:rgb(255,255,255)">
please let me know your suggestions on improving this code.</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0); background-color:rgb(255,255,255)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0); background-color:rgb(255,255,255)">
thanks,</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0); background-color:rgb(255,255,255)">
amith</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0); background-color:rgb(255,255,255)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0); background-color:rgb(255,255,255)">
<br>
</div>
</div>
</div>
</body>
</html>