Get atom from selection string in script
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.
Hi Thibault, It seems to me that what your copy_torsion() function really wants is just two residues. I'd have your command register just a ResiduesArg (from chimerax.atomic) and have your function take just 'session' and 'residues' args. The function could check if len(residues) == 2 if you wanted. You would copy the psi angle from the second residue to the first with residues[0].psi = residues[1].psi. Phi/omega would work the same way. What you would then type to your command would be something like "copyTorsion #1:231 #2:231".
--Eric
Eric Pettersen UCSF Computer Graphics Lab
On Oct 31, 2022, at 6:52 AM, Thibault TUBIANA via ChimeraX-users 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.
-- Thibault Tubiana, PhD Postdoctoral Fellow @IMAPP https://www.i2bc.paris-saclay.fr/equipe-interactions-and-assembly-mechanisms-of-proteins-and-peptides/ Institute for integrative biology of the cell (I2BC https://www.i2bc.paris-saclay.fr/) - CNRS UMR 9198 CEA Saclay, 91191 Gif sur Yvette - Bât 532 pce 34 Web Site: http://www.tubiana.me/ http://www.tubiana.me/
ChimeraX-users mailing list ChimeraX-users@cgl.ucsf.edu Manage subscription: https://www.rbvi.ucsf.edu/mailman/listinfo/chimerax-users
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 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.
-- Thibault Tubiana, PhD Postdoctoral Fellow @IMAPP https://www.i2bc.paris-saclay.fr/equipe-interactions-and-assembly-mechanisms-of-proteins-and-peptides/ Institute for integrative biology of the cell (I2BC https://www.i2bc.paris-saclay.fr/) - CNRS UMR 9198 CEA Saclay, 91191 Gif sur Yvette - Bât 532 pce 34 Web Site: http://www.tubiana.me/ http://www.tubiana.me/
ChimeraX-users mailing list ChimeraX-users@cgl.ucsf.edu Manage subscription: https://www.rbvi.ucsf.edu/mailman/listinfo/chimerax-users
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.
participants (3)
-
Eric Pettersen
-
Thibault TUBIANA
-
Tom Goddard