[chimerax-users] Get atom from selection string in script
Thibault TUBIANA
thibault.tubiana at i2bc.paris-saclay.fr
Wed Nov 2 01:43:37 PDT 2022
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 at sonic.net>
À: "Thibault TUBIANA" <thibault.tubiana at i2bc.paris-saclay.fr>
Cc: "chimerax-users" <ChimeraX-users at 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 at cgl.ucsf.edu | chimerax-users at 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 @ [ https://www.i2bc.paris-saclay.fr/equipe-interactions-and-assembly-mechanisms-of-proteins-and-peptides/ | IMAPP ]
Institute for integrative biology of the cell ( [ https://www.i2bc.paris-saclay.fr/ | I2BC ] ) - 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
[ mailto:ChimeraX-users at cgl.ucsf.edu | ChimeraX-users at cgl.ucsf.edu ]
Manage subscription:
https://www.rbvi.ucsf.edu/mailman/listinfo/chimerax-users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.rbvi.ucsf.edu/pipermail/chimerax-users/attachments/20221102/0559915d/attachment.html>
More information about the ChimeraX-users
mailing list