Introduction to the
gOpenMol
programming interface


gOpenMol uses extensively the Tcl/Tk library. It is not very easy to extend the Tcl/Tk (in gOpenMol) without touching the original source code. However, because gOpenmol uses the Tcl interface it is possible to use the DSO (Dynamic Shared Object) approach to include new features into the program without "touching" the source code of the distributed (binary) module, at the Tcl level. Please have a look at the DSO man pages of your Unix/Windows systems.

The DSO modules are loaded during program execution time and allow thus new program features to be included..

EXAMPLE:

The following small piece of code introduces a new command "test" into the Tcl command interpreter. When the "test" command is executed one gets the words "Hello World" displayed.

The program Test_Init introduces the command command "test" to the interpreter and lulTest is called when the command test is executed.


/*
This code is based on the tcl-command language
Leif Laaksonen Center for Scientific Computing 1995, 1996
*/
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <tcl.h>

/* commands */
int lulTest(ClientData , Tcl_Interp *, int , char **);

/* external */

extern Tcl_Interp *lulGetTclInterp(void); /* get the tcl interp pointer */

/* ........ */


/*********************************************************************/
int Test_Init()
/*********************************************************************/
{
int code;
Tcl_Interp *Interp;

Interp = lulGetTclInterp();

/* test */
Tcl_CreateCommand(Interp,"test",lulTest,(ClientData)NULL,
(Tcl_CmdDeleteProc *)NULL);
return(TCL_OK);
}
/*********************************************************************/
int lulTest(ClientData clientdata , Tcl_Interp *interp,
int argc , char *argv[])
/*********************************************************************/
{
printf("Hello World\n");
exit(0);
}


This file is compiled using the command:

cc -c test.c
ld -shared test.o -o test.so

Now we have a module called test.so which can be loaded into gOpenMol.

The module will be include into gOpenMol using the Tcl command:

load ./test.so test

Executing now the command (inside gOpenmol) test gives you "Hello World". Easy, isn't it?

This was a very simple example but more extensive will be presented.