wnprpc Python module


Classes:

The wnprpc Python module defines two Python classes that facilitate the access to the XML/RPC server in Wit!P:

wnpRPCconnection(host=host, port=portnumber, tag=wnp_rpc_tag):
This class may be used to establish a connection to a running Wit!P XML/RPC sever listening at http://host:portnumber/RPC2, where host (string, default: "localhost") is the hostname on which the XML/RPC server is running, portnumber (integer, default: None) is the TCP/IP port on which the server is listening for incoming procedure calls, and tag (string, default: "") is a string which must match the value of the environment variable WNP_RPC_TAG in the XML/RPC server process.

wnpRPCserver(graphics=withGraphics, ports=listOfPortnumbers, wait=maxTimeToWait):
The wnpRPCserver class creates a new Wit!P session and connects to it through XML/RPC. withGraphics (boolean, default: False) is a flag which may be used to request a Wit!P session with graphics. listOfPortnumbers (list of integers, default: None) is a list of TCP/IP port numbers.  The XML/RPC server will pick from this list the first number that is not already bound to a service. If such a number cannot be found in the list, the Wit!P session will not be started.


Methods:

The wnpRPCconnection and wnpRPCserver share the following methods:

cmd(command) :
The string command is sent to the Wit!P session for execution. The string may consist of multiple lines, separated by line-feed characters. The method returns a triple status, prompt, responseText, where status (integer) is the number of error that occured during the execution of the Wit!P commands in command, prompt is the prompt issued by the Wit!P command parser at the end of the execution, and responseText is a list of messages issued by Wit!P during the execution of the commands.

loadMolTypes(name=name, type=type, data=molecule):
The string molecule is sent to the Wit!P session, which will parse and convert it to a top level molecule /name, using the appropriate parser according to the specified type. Recognized types are "mol", "mol2", "cif"," pdb", "xpdb", "shelx", "mmod", "diana", "par", "maccs", and "csd". For types "maccs" and "csd" only the first molecule in molecule will be loaded. The method returns a status, prompt, responseText (c.f. cmd method).

getenv(variable):
Retrieves the definition of the environment varible from the Wit!P session's process environment. The method returns string. If variable is not defined, the method will return "" .

getprompt():
Retrieves the currennt prompt string from the Wit!P session. May be used to check state of Wit!P's command parser before sending commands cmd method.

Additional methods:
loadData(data), freeData(), loadPDB(name, data=data) left undocumented, since their functionalities have been superseeded by loadMolTypes.


Examples:

Note: the scripts in these examples assume that the wnprpc.py Python module is found in the PYTHONPATH, and that the witnotp command is found in PATH. The standard location for wnprpc.py is the directory that holds the 'witnotp' shell script.

A.Widmer, NIBR/CPC/CSG-SB