[chimerax-users] Get atom from selection string in script

Eric Pettersen pett at cgl.ucsf.edu
Mon Oct 31 10:25:45 PDT 2022


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 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 @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 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/20221031/14454721/attachment.html>


More information about the ChimeraX-users mailing list