<html><body><div id="zimbraEditorContainer" style="font-family: arial, helvetica, sans-serif; font-size: 12pt; color: #000000" class="20"><div>Hi Tom! </div><div><br data-mce-bogus="1"></div><div>Thank you so much for your help, especially with the command allowing a residue range that's perfect =D</div><div><br data-mce-bogus="1"></div><div>Best regards,</div><div>Thibault.</div><div><br></div><hr id="zwchr" data-marker="__DIVIDER__"><div data-marker="__HEADERS__"><b>De: </b>"Tom Goddard" <goddard@sonic.net><br><b>À: </b>"Thibault TUBIANA" <thibault.tubiana@i2bc.paris-saclay.fr><br><b>Cc: </b>"chimerax-users" <ChimeraX-users@cgl.ucsf.edu><br><b>Envoyé: </b>Lundi 31 Octobre 2022 18:29:27<br><b>Objet: </b>Re: [chimerax-users] Get atom from selection string in script<br></div><div><br></div><div data-marker="__QUOTED_TEXT__">Hi Thibault,<div class=""><br class=""></div><div class=""> I suggest you make your command syntax like this</div><div class=""><br class=""></div><div class=""><span class="Apple-tab-span" style="white-space:pre"> </span>copyTorsion #1:78 to #2</div><div class=""><br class=""></div><div class="">This will be a more familiar way of specifying command arguments in ChimeraX. Also it is easy to get the torsion angle and set it using the residue "psi" angle. Here is a modified version of your code. It allows specifying multiple residues also ("copytor #1:55-65 to #2").</div><div class=""><br class=""></div><div class=""> Tom</div><div class=""><br class=""></div><div class=""><div class=""><br class=""></div><div class="">def copy_torsion(session, residues, to_structure):</div><div class=""> for residue in residues:</div><div class=""> res_num = residue.number</div><div class=""> cmd = f"torsion {to_structure.atomspec}:{res_num}@n,ca,c:{res_num+1}@n {residue.psi}"</div><div class=""> from chimerax.core.commands import run</div><div class=""> run(session, cmd)</div><div class=""> </div><div class="">def register_command(logger):</div><div class=""> from chimerax.core.commands import CmdDesc, register</div><div class=""> from chimerax.atomic import ResiduesArg, AtomicStructureArg</div><div class=""> desc = CmdDesc(required = [ ('residues', ResiduesArg) ],</div><div class=""> keyword = [ ('to_structure', AtomicStructureArg) ],</div><div class=""> required_arguments = ['to_structure'],</div><div class=""> synopsis='Copy torsion angle')</div><div class=""> register('copytorsion', desc, copy_torsion, logger=logger)</div><div class=""><br class=""></div><div class="">register_command(session.logger)</div></div><div class=""><br class=""></div><div class=""><br class=""><div><br class=""><blockquote class=""><div class="">On Oct 31, 2022, at 6:52 AM, Thibault TUBIANA via ChimeraX-users <<a href="mailto:chimerax-users@cgl.ucsf.edu" class="" target="_blank">chimerax-users@cgl.ucsf.edu</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class=""><div style="font-family: arial, helvetica, sans-serif; font-size: 12pt;" class=""><div class="">Hi!</div><div class=""><br class=""></div><div class="">I would like to create a function to copy the torsion angle from a model to another one.</div><div class="">The function would take in argument the model ID of the reference and target model (<int>) and the residue id (<int>).</div><div class="">I looked a bit at the scripts available in <a href="https://rbvi.github.io/chimerax-recipes/" class="" target="_blank">https://rbvi.github.io/chimerax-recipes/</a> to have an idea of how to add function in ChimeraX, but I'm currently stuck at "how to get the list of atoms from a selection string ?".</div><div class=""><br class=""></div><div class="">Here's my current script </div><div class=""><hr class=""></div><div class=""><div class=""><span style="font-family: "courier new", courier, monaco, monospace, sans-serif;" class="">from chimerax.core.commands import run</span></div><div class=""><br class=""></div><div class=""><span style="font-family: "courier new", courier, monaco, monospace, sans-serif;" class=""> </span></div><div class=""><span style="font-family: "courier new", courier, monaco, monospace, sans-serif;" class="">def copy_torsion(session, model1, model2, residue):</span></div><div class=""><span style="font-family: "courier new", courier, monaco, monospace, sans-serif;" class=""> selection = f"torsion #{model2}:{residue}@n,ca,c:{residue+1}@n"</span></div><div class=""><span style="font-family: "courier new", courier, monaco, monospace, sans-serif;" class=""> from chimerax.atomic import AtomsArg</span></div><div class=""><span style="font-family: "courier new", courier, monaco, monospace, sans-serif;" class=""> </span></div><div class=""><span style="font-family: "courier new", courier, monaco, monospace, sans-serif;" class=""> atoms = AtomsArg(selection) </span></div><div class=""><span style="font-family: "courier new", courier, monaco, monospace, sans-serif;" class=""> </span></div><div class=""><span style="font-family: "courier new", courier, monaco, monospace, sans-serif;" class=""> from chimerax.geometry import dihedral </span></div><div class=""><span style="font-family: "courier new", courier, monaco, monospace, sans-serif;" class=""> cur_torsion = dihedral([*a.scene_coord for a in atoms])</span></div><div class=""><span style="font-family: "courier new", courier, monaco, monospace, sans-serif;" class=""> </span></div><div class=""><span style="font-family: "courier new", courier, monaco, monospace, sans-serif;" class=""> torsion=run(session, f"torsion #{model1}:{residue}@n,ca,c:{residue+1}@n {cur_torsion}")</span></div><div class=""><span style="font-family: "courier new", courier, monaco, monospace, sans-serif;" class=""> </span></div><div class=""><span style="font-family: "courier new", courier, monaco, monospace, sans-serif;" class=""> </span></div><div class=""><span style="font-family: "courier new", courier, monaco, monospace, sans-serif;" class="">def register_command(logger):</span></div><div class=""><span style="font-family: "courier new", courier, monaco, monospace, sans-serif;" class=""> from chimerax.core.commands import CmdDesc, register, FloatArg, IntArg, BoolArg, Color8Arg, StringArg</span></div><div class=""><span style="font-family: "courier new", courier, monaco, monospace, sans-serif;" class=""> from chimerax.atomic import AtomsArg</span></div><div class=""><span style="font-family: "courier new", courier, monaco, monospace, sans-serif;" class=""> desc = CmdDesc(required = [</span></div><div class=""><span style="font-family: "courier new", courier, monaco, monospace, sans-serif;" class=""> ('model1', IntArg),</span></div><div class=""><span style="font-family: "courier new", courier, monaco, monospace, sans-serif;" class=""> ('model2', IntArg),</span></div><div class=""><span style="font-family: "courier new", courier, monaco, monospace, sans-serif;" class=""> ('residue', IntArg),</span></div><div class=""><span style="font-family: "courier new", courier, monaco, monospace, sans-serif;" class=""> ],</span></div><div class=""><span style="font-family: "courier new", courier, monaco, monospace, sans-serif;" class=""> synopsis='Copy torsion angle')</span></div><div class=""><span style="font-family: "courier new", courier, monaco, monospace, sans-serif;" class=""> register('copyTorsion', desc, copy_torsion, logger=logger)</span></div><div class=""><span style="font-family: "courier new", courier, monaco, monospace, sans-serif;" class=""> </span><div style="font-family: arial, helvetica, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); text-decoration-thickness: initial;" class=""><br class=""></div><div style="font-family: arial, helvetica, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); text-decoration-thickness: initial;" class=""><span style="font-family: "courier new", courier, monaco, monospace, sans-serif;" class="">register_command(session)</span></div><span style="font-family: "courier new", courier, monaco, monospace, sans-serif;" class=""> </span></div><div class=""><hr class=""></div><div class="">Thank you for your help :)</div><div class=""><br class="">Best regards,</div><div class="">Thibault.</div></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><div class="">--<br class="">Thibault Tubiana, PhD</div><div class="">Postdoctoral Fellow @<a href="https://www.i2bc.paris-saclay.fr/equipe-interactions-and-assembly-mechanisms-of-proteins-and-peptides/" target="_blank" class="">IMAPP</a><br class=""></div><div class=""><div class=""><span style="font-size: 12pt;" class="">Institute for integrative biology of the cell (<a href="https://www.i2bc.paris-saclay.fr/" target="_blank" class="">I2BC</a>) - CNRS UMR 9198</span><br class=""></div><div class="">CEA Saclay, 91191 Gif sur Yvette - Bât 532 pce 34</div><div class="">Web Site: <a href="http://www.tubiana.me/" target="_blank" class="">http://www.tubiana.me/</a><br class=""></div></div><div class=""><br class=""></div></div></div></div>_______________________________________________<br class="">ChimeraX-users mailing list<br class=""><a href="mailto:ChimeraX-users@cgl.ucsf.edu" class="" target="_blank">ChimeraX-users@cgl.ucsf.edu</a><br class="">Manage subscription:<br class="">https://www.rbvi.ucsf.edu/mailman/listinfo/chimerax-users<br class=""></div></blockquote></div><br class=""></div><br></div></div></body></html>