<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<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);">
Hi Shubham,</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);">
Assuming your model is already assigned to a variable, you shouldn't actually have to import
<i>any</i> module for that task. If you don't have your model yet, you can do it in a few ways:</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);">
# If it's not already open</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
from chimerax.open_command.cmd import provider_open</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
m = provider_open(session, ['path/to/file.cif'])[0]</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);">
# If it's the only model open</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
from chimerax.atomic import AtomicStructure</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
m = session.models.list(type=AtomicStructure)[0]</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);">
If you have multiple models open, you'll need some slightly more involved code to work out which one is yours (e.g. based on model name). Anyway, moving on... once you have the model handle as m, then you can get the IDs of all polymeric chains as simply:<br>
<br>
chain_ids = m.chains.chain_ids</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);">
If instead you want <b>all</b> chain_ids, including any used solely for ligands/water:</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);">
chain_ids = m.residues.unique_chain_ids</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);">
Best,</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Tristan</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 Shubham Devesh Ramgoolam via ChimeraX-users <chimerax-users@cgl.ucsf.edu><br>
<b>Sent:</b> 15 May 2022 18:55<br>
<b>To:</b> chimerax-users@cgl.ucsf.edu <chimerax-users@cgl.ucsf.edu><br>
<b>Subject:</b> [chimerax-users] Python code for obtaining chain information</font>
<div> </div>
</div>
<style>
<!--
@font-face
{font-family:"Cambria Math"}
@font-face
{font-family:Calibri}
p.x_MsoNormal, li.x_MsoNormal, div.x_MsoNormal
{margin:0in;
font-size:11.0pt;
font-family:"Calibri",sans-serif}
a:link, span.x_MsoHyperlink
{color:blue;
text-decoration:underline}
.x_MsoChpDefault
{}
@page WordSection1
{margin:1.0in 1.0in 1.0in 1.0in}
div.x_WordSection1
{}
-->
</style>
<div lang="EN-US" link="blue" vlink="#954F72" style="word-wrap:break-word">
<div class="x_WordSection1">
<p class="x_MsoNormal">Hi,</p>
<p class="x_MsoNormal">I hope you are doing well.</p>
<p class="x_MsoNormal">I have a python script in which I need generate a list of all the chains present in a structure: e.g [A,B]</p>
<p class="x_MsoNormal">However, I do not know which module to import in order to write a code for this.</p>
<p class="x_MsoNormal"> </p>
<p class="x_MsoNormal">Regards,</p>
<p class="x_MsoNormal">Shubham</p>
<p class="x_MsoNormal"> </p>
<p class="x_MsoNormal">Sent from <a href="https://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgo.microsoft.com%2Ffwlink%2F%3FLinkId%3D550986&data=05%7C01%7Ctic20%40universityofcambridgecloud.onmicrosoft.com%7Cbbad1c776bec489e2b9208da369cf46e%7C49a50445bdfa4b79ade3547b4f3986e9%7C0%7C0%7C637882345470023062%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000%7C%7C%7C&sdata=ubrajKQcD5u9E5Aqu3RQJ7TqkDq5otEY4rRoLt9SMIU%3D&reserved=0" originalsrc="https://go.microsoft.com/fwlink/?LinkId=550986" shash="ju2qmd5ztIputzmtT+oe8K49UTthoKmOZtUfj0OxyaFx3rOP/Z3pqGU9wGlKBDaq2SvcU4vCr6WYOfjoSXscxkdFHlWBH0GPcCO2cRylpZFAVPoNQ2f7vI/YJ6K6in5GbiGAcTRedx7Gt+70VKEYWGgGsVWn25YKMCnKDE2kLL0=">
Mail</a> for Windows</p>
<p class="x_MsoNormal"> </p>
</div>
</div>
</body>
</html>