Hi Tom!
Thank you so much for your help, especially with the command allowing a residue range that's perfect =D
Best regards, Thibault.
De: "Tom Goddard" goddard@sonic.net À: "Thibault TUBIANA" thibault.tubiana@i2bc.paris-saclay.fr Cc: "chimerax-users" ChimeraX-users@cgl.ucsf.edu Envoyé: Lundi 31 Octobre 2022 18:29:27 Objet: Re: [chimerax-users] Get atom from selection string in script
Hi Thibault,
I suggest you make your command syntax like this
copyTorsion #1:78 to #2
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").
Tom
def copy_torsion(session, residues, to_structure): for residue in residues: res_num = residue.number cmd = f"torsion {to_structure.atomspec}:{res_num}@n,ca,c:{res_num+1}@n {residue.psi}" from chimerax.core.commands import run run(session, cmd) def register_command(logger): from chimerax.core.commands import CmdDesc, register from chimerax.atomic import ResiduesArg, AtomicStructureArg desc = CmdDesc(required = [ ('residues', ResiduesArg) ], keyword = [ ('to_structure', AtomicStructureArg) ], required_arguments = ['to_structure'], synopsis='Copy torsion angle') register('copytorsion', desc, copy_torsion, logger=logger)
register_command(session.logger)
On Oct 31, 2022, at 6:52 AM, Thibault TUBIANA via ChimeraX-users < [ mailto:chimerax-users@cgl.ucsf.edu | chimerax-users@cgl.ucsf.edu ] > wrote:
Hi!
I would like to create a function to copy the torsion angle from a model to another one. The function would take in argument the model ID of the reference and target model (<int>) and the residue id (<int>). I looked a bit at the scripts available in [ https://rbvi.github.io/chimerax-recipes/ | https://rbvi.github.io/chimerax-recipes/ ] 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 ?".
Here's my current script
from chimerax.core.commands import run
def copy_torsion(session, model1, model2, residue): selection = f"torsion #{model2}:{residue}@n,ca,c:{residue+1}@n" from chimerax.atomic import AtomsArg atoms = AtomsArg(selection) from chimerax.geometry import dihedral cur_torsion = dihedral([*a.scene_coord for a in atoms]) torsion=run(session, f"torsion #{model1}:{residue}@n,ca,c:{residue+1}@n {cur_torsion}") def register_command(logger): from chimerax.core.commands import CmdDesc, register, FloatArg, IntArg, BoolArg, Color8Arg, StringArg from chimerax.atomic import AtomsArg desc = CmdDesc(required = [ ('model1', IntArg), ('model2', IntArg), ('residue', IntArg), ], synopsis='Copy torsion angle') register('copyTorsion', desc, copy_torsion, logger=logger)
register_command(session)
Thank you for your help :)
Best regards, Thibault.