wnprpc Example: minimizer
Usage: minimizer atomtypes input [ minimized [ failed ] ]
Description:
Reads molecules from the file 'input'
(SD file), assignes force field atomtypes
('charmm','taff','cornell','gaff'), runs the molecule through Minimax,
and appends minimized structures to the file 'minimzed' (default:
'minimized.sdf'). If Minimax does not run to normal completion, the
molecule will be appended to 'failed' (default: 'failed.sdf'). For each
molecule a one line status report witll be written to stderr.
Line 18:
from
wnprpc import wnpRPCserver
The wnpRPC server class is imported
from the wnprpc Python module.
Lines 49-52:
w=wnpRPCserver(graphics=False,ports=range(19501,19525))
if w.server is None:
print
>>sys.stderr,"failed to start Wit!P RPC serevr"
sys.exit(2)
A Wit!P XML/RPC server object is created, with XML/RPC listening on the
first available port in the range 19501...19525. If w.server is None,
starting the Wit!P sesseion has failed, for whatever reason (e.g.
'witnotp' not found in $PATH, no TCP/IP port available in the requested
range, ...). It is always a good idea to check if the creation of the
Wit!P session was successful.
Lines 55-60:
s,p,R=w.cmd("read maccs %s"%infile)
if not
p.startswith("ReadMaccs>"):
print
>>sys.stderr,"".join(R)
sys.exit(1)
The Wit!P session is aked to start reading the input file ('infile',
filename obtained from the second command line argument). The response
from the Wit!P session is a
status,
prompt,
responseText triple (s, p, R).
After execution of the "read maccs..." command, we expect the prompt
string to start with "ReadMaccs>". If the prompt string does
not meet the expectations, the
responseText
list of text lines is joined into a single text block, sent to
stderr, and the script is terminated with error status 1.
Line 63:
fname="/var/tmp/minim_"+w.getenv("WNP_RPC_TAG").split()[1].replace("/","_")
When the Wit!P session was started, the WNP_RPC_TAG environment
variable was set to a string of the form "WNP/RPC
processID/randomNumber".
This string is unique between Wit!P sessions created in the same
process space with wnpRPCserver . The script uses this string to
generated a unique filename for temporary files created by Minimax in
the Wit!P session.
Lines 66-73:
cmds="""next
modify atom type automatic %s *
done
done
command
minimax ForceField %s run /* %s
exit
"""%(FF[atmtype],atmtype,fname)
A text block of Wit! commands to be executed for each molecule in the
input files is composed using data obtained from the first command line
argument and the unique filename generated in line 63.
Lines 75, 76:
while
True:
s,p,R=w.cmd(cmds)
The script requests execution of the command set up in Lies
66-73 by the Wit!P session.
Lines 79-100:
The first line of the responseText block R in line 76
will contain the title line (conventionally used by the molecule name)
of the next molecule read by read maccs from the input file, or the
string "At end of file", if reading the input file has reached the end
of file, in which case the script will break out of the loop started in
line 75. If the end of file is not reached, the rest of the responseText block R will contain
the report from the automatic atom type assignment and from the Minimax
energy minimization. On normal convergence, the last line will contain
the text "Normal completion", and the Wit!P session will be asked to
save the minimized structure to the file defined by the filename in the
variable "minimized", else the reason for failure is obtained by
looking ath the last two lines of responseText
block R, and the input molecule (paritially minimized, if max. number
of iterations was reached in Minimax) will be written to the file
defined by the variable "failed".
Line 104:
w.cmd("<'|rm
%s.*'"%fname)
An interesting way to ask the Wot!P
session to remove the temporary files it created.
Line 108:
sys.exit(0)
The script has rached normal completion. The Wit!P session will be shut
down automatically, when Python deletes the wnpRPCserver object "w".
There is no need to shut down the Wit!P session explicitly.
Sample output:
AW on camm7 933> minimizer
taff raw.sdf taff.sdf taff_failed.sdf
1amsf_LI1_LI1 Normal completion, converged.
1aods_SAM_LI1_LI1 Normal
completion, converged.
1awih_PLP_INH Normal completion, converged.
1bnmz_PLP_INH Normal completion, converged.
1ccde_LIG_LI1 Normal completion, converged.
1cfuw_NVP Normal completion,
converged.
1dgkf_LI1 Normal completion,
converged.
1dosk_LI1 Normal completion,
converged.
1ednl_ACE_CHE_PRR_ARR Normal completion, converged.
1ejoc_LI1 Normal completion,
converged.
1eowm_SAM Normal completion,
converged.
1euuv_LI1_LI2 Normal completion, converged.
1exbg_LI1_LI1 Normal completion, converged.
1ghpj_LI1 Normal completion,
converged.
1gzlw_LI1 Unknown atom types
1hind_LI1 Normal completion,
converged.
1itro_LFX Normal completion,
converged.
1jaap_INH Normal completion,
converged.
1jabb_GNF_GNF Normal completion, converged.
1jdtp_LI1 Normal completion,
converged.
1jors_LIG Normal completion,
converged.
1jwyf_LI1 Normal completion,
converged.
1kfnx_NVP Normal completion,
converged.
1ktgb_LI1 Unknown atom types
1lsfv_537 Normal completion,
converged.
1lzbf_LI1 Unknown atom types
AW on camm7 941> ls -l raw.sdf taff.sdf taff_failed.sdf
-rw-r----- 1 widmerar camm2 132398 Jul 8 13:19 raw.sdf
-rw-r----- 1 widmerar camm2 117300 Jul 8 15:46 taff.sdf
-rw-r----- 1 widmerar camm2 15098 Jul 8 15:46
taff_failed.sdf
A.Widmer,
NIBR/CPC/CSG-SB