Dear Yarrow, The problem in your script is the `if __name__ == "__main__"` clause.
When the script is run using `pymol -cqk test.py`, __name__ refers to the string "pymol". The following script fetches a structure from the PDB and saves a PNG image. Run it using `pymol -cqk test.py -- <PDB-ID>`. (The flag -k prevents loading pymolrc and plugins.) ```python from pymol import cmd def main(pdb_id: str) -> None: print(f"Loading PDB-ID {pdb_id.upper()}") cmd.fetch(pdb_id) png_file_name = f"{pdb_id}.png" print(f"Writting image to {png_file_name}") cmd.png(png_file_name) if __name__ == "pymol": import sys pdb_id = sys.argv[1] main(pdb_id) ``` Best regards, Karl On 06.01.2025, at 18:04, Florian Nachon <mailingl...@nachon.net> wrote: Hello, It is much easier than that. Make a pymol script, for example, test.pml: # load 3gbn.pdb select Selection1, resi 80:115 save Selection1.cif, Selection1 quit # then run it with the -c option : pymol test.pml -c If you want to pass an argument, like the filename of a pdb file to be directly opened, then use the -cp option. Florian On 9 Dec 2024, at 22:38, Yarrow Madrona <yarrowmadr...@gmail.com> wrote: I'm trying to run pymol in batch mode without launching the window. I am running PyMOL 3.1.1. Here is my code for an example script (test.py). I'm trying to run before running the real script. In the command line I enter: pymol -cq test.py from pymol import cmd import time def main(): print("Starting PyMOL batch processing...") cmd.load("3gbn.pdb") do_stuff() print("Loaded 3gbn.pdb") time.sleep(25) # Ensure commands are processed cmd.quit() if __name__ == "__main_": main() I don't get any output. If I type: pymol -c test.py It appears that pymol starts and closes: <image.png> Any help on how to run a python script with pymol in batch without opening the GUI would be appreciated. Yarrow _______________________________________________ PyMOL-users mailing list Archives: http://www.mail-archive.com/pymol-users@lists.sourceforge.net Unsubscribe: https://sourceforge.net/projects/pymol/lists/pymol-users/unsubscribe _______________________________________________ PyMOL-users mailing list Archives: http://www.mail-archive.com/pymol-users@lists.sourceforge.net Unsubscribe: https://sourceforge.net/projects/pymol/lists/pymol-users/unsubscribe
_______________________________________________ PyMOL-users mailing list Archives: http://www.mail-archive.com/pymol-users@lists.sourceforge.net Unsubscribe: https://sourceforge.net/projects/pymol/lists/pymol-users/unsubscribe