How to execute a py script on PyMOL?

In Pymol, you can make your own script. There is two kind of scripts :

  • .py: it’s a python script that allows to add a new function in pymol.
    to import a py script on pymol write the command line:

  • .pml: it’s a pymol script where you put all pymol command. each lines will be executed one after the other.
    To run it on pymol write the command line:


    Be careful with that, it’s very useful but sometimes, when a command take a while (like fetch command) the next one can be executed.

I will explain how to use (and not create) python script on pymol (.py ones).

Usualy when you find a python pymol script, the author specify the command line. If not :

  • open the .py script and on the top of the file, see if there is a help comment like:
    Pymol python script to add a function to color atoms by residues.
    syntaxe in Pymol :
    color_by_resname selection

    Here you can see a syntaxe example « color_by_resname selection ». Just write this line on pymol terminal and remplace « selection » by your selection (all, resname ALA, chain A…).

  • Search a ligne like « cmd.extend(…..) » (usualy at the end of file). Example :

    the first argument is the name of the function in pymol, the second one is the python function.

So if we take this script example which color amino acids according a color-blind color (download link bellow):

color_by_resname all

[wpdm_file id=4]

Taggé , , .Mettre en favori le Permaliens.

Laisser un commentaire

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *


Ce site utilise Akismet pour réduire les indésirables. En savoir plus sur comment les données de vos commentaires sont utilisées.