How can I embed ICM within a Python script?

43 views
Skip to first unread message

Andrew Orry

unread,
Feb 7, 2025, 8:36:29 PM2/7/25
to MolSoft ICM Knowledge Base

Q. How can I embed ICM within a Python script?

A: You can use the os.system command in Python to call ICM from within your script. Below is an example:

#python script

import os
os.system("$ICMHOME/icm64 <your_icm_command>")

Replace <your_icm_command> with the specific ICM command you want to execute.

For example below we automatically setup a docking project using _dockBatch and run the screening using _dockScan inside a python script

#python script

import os
pocket_residues = "377,385,399,400,402,420,448,455,501"
myDockProj = "D_1xbb_nolig"
os.system("$ICMHOME/icm64 $ICMHOME/_dockBatch 1xbb_nolig.pdb pocket=a_a/" + pocket_residues + " proj=D_1xbb_nolig")
os.system("$ICMHOME/icm64 $ICMHOME/_dockScan " + myDockProj + " input=myDB_8.sdf output=myDB_8_results.sdf")

Ruben

unread,
Feb 8, 2025, 8:15:06 PM2/8/25
to MolSoft ICM Knowledge Base
Just to add to this, it is better to prepare a script outside and run it, them read the output back to python to continue. 
 
1. prepare a script, say this one in file /tmp/test.icm
>>> cat /tmp/test.icm
l_commands = l_info = no
read pdb "1crn"
printf " N of residues in '%s' is  %d\n", Name(a_A full) [1], Nof(a_A/ )
quit

2. Run the python script and with the ICM script inside
Python 2.7.5 (default, Nov  6 2016, 00:28:07)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-11)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.system("/pro/icm/icms/icm64 -s /tmp/test.icm")
 N of residues in 'a_1crn.a' is  46
0
>>>. ^D



Reply all
Reply to author
Forward
0 new messages