# Executing PyMOL from a Shell script

I'm trying to execute pymol from a shell script (and it is not working). I'm not executing the script on PyMOL but even if I do this, it doesn't work neither. However, if instead of a script the commands are manually written in PyMOL, everything goes well.

Here is the code:

#!/bin/bash
pwd
echo 'fetch 1OYT
remove resn HOH
h_add elem O or elem N
select ligand, resn FSN
' > scriptt.pml
pymol scriptt.pml


One of the problems, you will see, is that PyMOL does not remove the water molecules. Another issue is that the program does not exit. Do you have any idea what's going on there?

• What program does not exist? What errors are you getting? Is pymol in your PATH? I have no experience with pymol, are you sure remove resn HOH is the right command to remove water? Apr 5 '19 at 17:11
• @terdon the post reads 'exit', not 'exist'. And the same commands typed in the program interface, works fine...
– user4378
Apr 5 '19 at 17:23
• I'm thought Pymol does hydrate and and remove water. I dunno about the command line, but there's options in the GUI
– M__
Apr 5 '19 at 17:37

Your shell script is fine, and works as expected. The reason it hangs is that you aren't telling PyMol to exit after running your script, so it's still running and waiting for the next command. Just add a quit at the end and it should work:

#!/bin/bash
pwd
echo 'fetch 1OYT
remove resn HOH
h_add elem O or elem N
select ligand, resn FSN
select prot, 1OYT and not ligand,
save lig.pdb, ligand
save prot.pdb, prot
quit
' > scriptt.pml
pymol scriptt.pml
obabel prot.pdb -xr -O prot.pdbqt
obabel lig.pdb -O lig.pdbqt
echo 'babel conversion is finished'