The installation of TRIMrpc on the Daylight server enables the GUI client to call standalone programs on the chemical server, pass them lists as arguments, and capture returned values. For example, a C program on the chemical server might be used to generate a unique SMILES or insert Thor DataTrees into a Thor database. It is likely that all of the programs in the Daylight contrib directory could be run remotely from the DataAspects GUI.
There are three steps to create remote procedure calls:
{
/*
client_insert_tdt.pl
Objective: To convert a SMILES into a unique SMILES.
Actions:
1. Use TRIMrpc to connect to server_insert_tdt.pl on the chemical server.
2. Send three arguments:
- db_exec,
-'unique',
- SMILES from the GUI display wrapped into a list.
3. Server_insert_tdt.pl executes system call to run unique_smile.c
and pass it the source SMILES. Unique_smile.c returns two lines:
a. USMILES
b. Formula, MW
3. These values are written to their corresponding application fields.
...Pat McGreevy, 18 Jul 98
*/
list smiles_list;
list temp_list;
smiles_list= list_open("4000",1,"SMILES");
list_mod(smiles_list,1,"'"^^p.smiles_d^^"'");
if (trap({
status("Wait...Connecting to ChemServer");
connect(3,"net:server_insert_tdt@141.236.20.11!vtxhost.trm");
status("Connected to ChemServer");
})){
bell();
status("Failed to connect to ChemServer");
connect(0);
break;
}
if (exec_sql("unique",smiles_list)){
bell();
status("Server_insert_tdt.run has failed.");
}
else{
temp_list= list_open("select results",1000);
if (list_rows(temp_list)==2){
list_view(temp_list,0);
}
else
list_view(temp_list,0);
}
}
{
/*
client_insert_tdt.pl
Objective: To create a TDT from the window list, write it to file, copy it
to Chemserver, and call server_insert_tdt.pl. The server_insert_pl
program will load the TDT file into THOR and return a message.
Actions:
1. Create a TDT list.
2. Connect to vtxhost.trm running on Chemserver.
3. Execute 'server_insert_tdt.run and pass it the TDT list.
Parameters:
parm.0 db_exec (see trim.h).
parm.1 server_insert_tdt.pl - name of trim/pl program on server.
parm.2 filename of TDT. Filename is wrno.tdt (000001.tdt).
...Pat McGreevy, 2 Apr 98
*/
list temp_list;
list tdt_list;
status("Wait...Connecting to ChemDB");
cursor_wait(true);
/* create, load and file Thor Data Tree */
tdt_list= list_open("4006",100,"TDT" ); /* create list w/ 1 field, 4006 bytes */
if (!enter.smile_d || !enter.wrno_d){ /* check that wrno & SMILE have values */
bell();
status("Enter both WRNO and SMILES before creating a TDT");
break;
}
list_mod(tdt_list,1,"$SMI<" ^^p.smile_d^^">"); /* load list in TDT format */
list_mod(tdt_list,1,"$WRNO<" ^^p.wrno_d^^">");
list_mod(tdt_list,1,"AMW<" ^^p.mw^^">");
list_mod(tdt_list,1,"F<" ^^p.mf^^">");
if (enter.cas)
list_mod(tdt_list,1,"$CAS<"^^p.cas^^">");
/*list_mod(tdt_list,1,"REM");*/
list_mod(tdt_list,1,"|");
if (trap({
connect(2,"net:server_insert_tdt@"^^G.thorserver^^"!vtxhost.trm");
status("Connected to ChemDB");
})){
bell();
status("Failed to connect to ETCHEM");
connect(0);
break;
}
if (exec_sql("load",tdt_list)){
bell();
prompt("Server_insert_tdt.run has failed.");
}
else{
temp_list= list_open("select results",1000);
if(list_rows(temp_list)==2){
list_seek(temp_list,1);
status(list_curr(temp_list,0));
}
else
list_view(temp_list,0);
}
connect(0); /* reset connection to 0, etcis */
cursor_wait(false);
}
Notes from Paul follow:
unique_smile was not in the shell's PATH so the system() call failed. I moved
unique_smile to /usr1/trim/bin and it should work for you now. To check the
path, env | fgrep PATH
All better now. Look at server_insert_tdt.pl. I had to mess with the shell file redirection because unique_smile.c uses stderr. I also had to put in a exit(0) at the end otherwise the rc value from system() was random.
{
/******************************************************************************
* Copyright (C) DataAspects, Inc. 1998
* Module Name = server_insert_tdt
* Description = Load Thor data created on GUI Client into
* THOR chemical database on a server.
* Parameters = parm.0 - action (=db_exec)
* parm.1 - subaction (='load')
* parm.2 - data (='TDT')
*
* Actions:
* 1. Client creates a TDT and uploads it to a ChemServer.
* 2. Client connects to server_insert_tdt via TRIMrpc.
* 3. server_insert_tdt executes a system call that performs the following:
* -- runs a batch program called load_cis which is passed the TDT data
* as a file (=fn1). Load_cis() writes a 'success' or 'error' message
* to a second file (=fn2").
* 4. The system() command returns true if there was an error, otherwise
* false.
* ...Pat McGreevy, 18 Jul 98
******************************************************************************/
char fn1[128],fn2[128];
int rc;
list ll;
if (parm.0 == db_exec) {
if (parm.1 == "load") {
fn1 = tmpnam();
fn2 = tmpnam();
list_file(parm.2,fn1,"a");
rc = system("load_cis "^^fn1^^" "^^fn2);
delete(fn1);
return(rc);
}
else if (parm.1 == "unique") {
fn2 = tmpnam();
rc = system("unique_smile "^^list_curr(parm.2,0)^^" 1>"^^fn2^^" 2>&1");
return(rc);
}
}
else if (parm.0 == db_open) {
if (parm.1 == "select results") {
ll = list_open(fn2,10);
delete(fn2);
return(ll);
}
}
return(1);
}