// Routine associated with PDB pull down menu
#if 0 
 General procedure for adding options to the pullright cascade buttons:
  1. add line like:    monoff = XmStringCreateLocalized ("ON ");
  2. Add this option to each pullright:
        sc.pullright[1] = XmVaCreateSimplePulldownMenu (pdbmenu,
            "pullright", 0 ,pdbsub_cb0,XmVaCHECKBUTTON, monoff,NULL, NULL, NULL,
             XmVaCHECKBUTTON, msideonoff, NULL, NULL, NULL,
             XmVaCHECKBUTTON,catrace, NULL, NULL, NULL,
             NULL);
  3.  Free string  XmStringFree (monoff);
  4.  Add call back to :
     void  setsub(int item_no,int subnum,maiddatafile& maidfile)
        switch(item_no){
       case(0): // Turn pdb on/off
         maidfile.pdb[subnum].onoff  = -maidfile.pdb[subnum].onoff ;
         break;
  5. Set initial values and checkbox for this option
        maidfile.pdb[i].sideonoff =1; // Default - turn on side chains,connect all atoms
        // Turn on check box for pdb (button0) and side chain(button1)
        if (widget = XtNameToWidget (sc.pullright[i], buttonname[0]))
            XtVaSetValues (widget, XmNset, True, NULL);
 or    if (widget = XtNameToWidget (pdbmenu,"button_9")) //DEFAULT:  Turn on check box for label on/off button
            XtVaSetValues (widget, XmNset, True, NULL);
Where "button_9 is the 10th button in in pdbmenu - (0,1,2......,9)
Note: if change # of pdb's etc, must change this button number 
#endif

#include "drawwindow.h"  // also calls global.h
#include "screen.h"
#include "pdbmenu.h"
#include "menu.h"
#include "math.h"
#include "peptide.h"
#include "fittopdb.h"
#include "pdbtolev.h"
#include "assignseq.h"
#include "trace.h"
#include "bone.h"
#include "contour.h"
#include "combine.h"

void  center_input_dialog(Widget w);  // Input menu for putting in residue number want to
extern struct maiddatafile maidfile;//Global variable - I do not know how to pass to menus
extern struct screenvalue  sc;
extern struct geometry geo;
extern struct pepfit fit[NFIT];
extern struct rotomer rot[30];
extern struct griddata map[NMAPS]; // all the map (denfile),contour data associated with map
extern int fitnum[NFIT];
extern struct pickpdb picked;
extern Widget toplevel;
extern FILE *fpout; // = stdout or logfile, depending whether batch or screen version

float fpdbradius[10]= { 5.0,7.5, 10.0,12.5,15,17.5,20};

char buttonname[MAXPDB][10] ={"button_0","button_1","button_2","button_3",
            "button_4","button_5","button_6","button_7","button_8",
             "button_9"
};

void  setsub(int item_no,int subnum,maiddatafile& maidfile)
{
   int iside = maidfile.pdb[subnum].sideonoff;
   Widget widget;
   switch(item_no){
      case(0): // Turn pdb on/off
         maidfile.pdb[subnum].onoff  = -maidfile.pdb[subnum].onoff ;
         break;
      case(1):// Turn side chain on/off - but always turn Ca trace off
         switch(iside){
          case(2): // This case should never occur because when Ca trace on, sidechain off
            iside = -1;//Turn off side also so must Change side on/off check box setting
            if (widget = XtNameToWidget (sc.pullright[subnum], buttonname[2]))
                XtVaSetValues (widget, XmNset, False, NULL);             
            break;
          case(1):
            iside = -1;//Turn off side also so must Change side on/off check box setting
            break;
          case(-1):
            iside = 1;
            break;
          case(-2):
            iside = 1;
            if (widget = XtNameToWidget (sc.pullright[subnum], buttonname[2]))
                XtVaSetValues (widget, XmNset, False, NULL);             
            break;
         } // switch iside
         break;
      case(2): //Turn Ca trace on/off - Note- always turn side chain off if Ca trace on
         switch(iside){
          case(2):// This case should never occur because when Ca trace on, sidechain off
            iside = -1;//Turn off side also so must Change side on/off check box setting
            if (widget = XtNameToWidget (sc.pullright[subnum], buttonname[1]))
                XtVaSetValues (widget, XmNset, False, NULL);             
            break;
          case(1):
            iside = -2;//Turn off side also so must Change side on/off check box setting
            if (widget = XtNameToWidget (sc.pullright[subnum], buttonname[1]))
                XtVaSetValues (widget, XmNset, False, NULL);             
           break;
          case(-1):
            iside = -2;
            break;
          case(-2):
            iside = -1;
            break;
         } // switch iside
         break;
    } // switch item_no
    maidfile.pdb[subnum].sideonoff = iside;
}


void setcolor(int item_no,pdbfile& pdb1)
// Set all segments of given pdb the same  MAIN color
{
  int i;
  switch(item_no){
    case 0:
       for(i=0;i<=2;i++)  // set the 0 segment
          pdb1.maincolor[0][i]= bluev[i];
       break;
    case 1: 
       for(i=0;i<=2;i++) 
          pdb1.maincolor[0][i]= redv[i];
       break;
    case 2: 
       for(i=0;i<=2;i++) 
          pdb1.maincolor[0][i]= lightbluev[i];
       break;
    case 3: 
       for(i=0;i<=2;i++) 
          pdb1.maincolor[0][i]= yellowv[i];
       break;
    case 4: 
       for(i=0;i<=2;i++) 
          pdb1.maincolor[0][i]= pinkv[i];
       break;
    case 5: 
       for(i=0;i<=2;i++) 
          pdb1.maincolor[0][i]= cyanv[i];
       break;
    case 6: 
       for(i=0;i<=2;i++) 
          pdb1.maincolor[0][i]= magentav[i];
       break;
    case 7: 
       for(i=0;i<=2;i++) 
          pdb1.maincolor[0][i]= greenv[i];
       break;
    case 8: 
       for(i=0;i<=2;i++) 
          pdb1.maincolor[0][i]= whitev[i];
       break;
    case 9: 
       for(i=0;i<=2;i++) 
          pdb1.maincolor[0][i]= blackv[i];
       break;
  }
  for(int is=1;is<pdb1.resdat[0][0][0];is++){ //set all segments = 0 segment
    for(i=0;i<=2;i++) 
       pdb1.maincolor[is][i]=pdb1.maincolor[0][i];
  }
printf("color[0] = %f\n",pdb1.maincolor[0][0]); 
}

void setscolor(int item_no,pdbfile& pdb1)
// Set all segments of given pdb the same  SIDE color
{
  int i;
  switch(item_no){
    case 0:
       for(i=0;i<=2;i++)  // set the 0 segment
          pdb1.sidecolor[0][i]= bluev[i];
       break;
    case 1: 
       for(i=0;i<=2;i++) 
          pdb1.sidecolor[0][i]= redv[i];
       break;
    case 2: 
       for(i=0;i<=2;i++) 
          pdb1.sidecolor[0][i]= lightbluev[i];
       break;
    case 3: 
       for(i=0;i<=2;i++) 
          pdb1.sidecolor[0][i]= yellowv[i];
       break;
    case 4: 
       for(i=0;i<=2;i++) 
          pdb1.sidecolor[0][i]= pinkv[i];
       break;
    case 5: 
       for(i=0;i<=2;i++) 
          pdb1.sidecolor[0][i]= cyanv[i];
       break;
    case 6: 
       for(i=0;i<=2;i++) 
          pdb1.sidecolor[0][i]= magentav[i];
       break;
    case 7: 
       for(i=0;i<=2;i++) 
          pdb1.sidecolor[0][i]= greenv[i];
       break;
    case 8: 
       for(i=0;i<=2;i++) 
          pdb1.sidecolor[0][i]= whitev[i];
       break;
    case 9: 
       for(i=0;i<=2;i++) 
          pdb1.sidecolor[0][i]= blackv[i];
       break;
  }
  for(int is=1;is<pdb1.resdat[0][0][0];is++){ //set all segments = 0 segment
    for(i=0;i<=2;i++) 
       pdb1.sidecolor[is][i]=pdb1.sidecolor[0][i];
  }
}

void mcolor_cb0(Widget widget,XtPointer client_data,XtPointer  call_data)
{
    int item_no = (int) client_data;
printf("in mcolor_cb0  item_no = %d\n",item_no);
    setcolor(item_no,maidfile.pdb[1]);
}
void mcolor_cb1(Widget widget,XtPointer client_data,XtPointer  call_data)
{
    int item_no = (int) client_data;
    setcolor(item_no,maidfile.pdb[2]);
}
void mcolor_cb2(Widget widget,XtPointer client_data,XtPointer  call_data)
{
    int item_no = (int) client_data;
    setcolor(item_no,maidfile.pdb[3]);
}
void mcolor_cb3(Widget widget,XtPointer client_data,XtPointer  call_data)
{
    int item_no = (int) client_data;
    setcolor(item_no,maidfile.pdb[4]);
}
void mcolor_cb4(Widget widget,XtPointer client_data,XtPointer  call_data)
{
    int item_no = (int) client_data;
    setcolor(item_no,maidfile.pdb[5]);
}
void mcolor_cb5(Widget widget,XtPointer client_data,XtPointer  call_data)
{
    int item_no = (int) client_data;
    setcolor(item_no,maidfile.pdb[6]);
}
void mcolor_cb6(Widget widget,XtPointer client_data,XtPointer  call_data)
{
    int item_no = (int) client_data;
    setcolor(item_no,maidfile.pdb[7]);
}
void mcolor_cb7(Widget widget,XtPointer client_data,XtPointer  call_data)
{
    int item_no = (int) client_data;
    setcolor(item_no,maidfile.pdb[8]);
}
void mcolor_cb8(Widget widget,XtPointer client_data,XtPointer  call_data)
{
    int item_no = (int) client_data;
    setcolor(item_no,maidfile.pdb[9]);
}

void scolor_cb0(Widget widget,XtPointer client_data,XtPointer  call_data)
{
    int item_no = (int) client_data;
printf("in scolor_cb0  item_no = %d\n",item_no);
    setscolor(item_no,maidfile.pdb[1]);
}
void scolor_cb1(Widget widget,XtPointer client_data,XtPointer  call_data)
{
    int item_no = (int) client_data;
    setscolor(item_no,maidfile.pdb[2]);
}
void scolor_cb2(Widget widget,XtPointer client_data,XtPointer  call_data)
{
    int item_no = (int) client_data;
    setscolor(item_no,maidfile.pdb[3]);
}
void scolor_cb3(Widget widget,XtPointer client_data,XtPointer  call_data)
{
    int item_no = (int) client_data;
    setscolor(item_no,maidfile.pdb[4]);
}
void scolor_cb4(Widget widget,XtPointer client_data,XtPointer  call_data)
{
    int item_no = (int) client_data;
    setscolor(item_no,maidfile.pdb[5]);
}
void scolor_cb5(Widget widget,XtPointer client_data,XtPointer  call_data)
{
    int item_no = (int) client_data;
    setscolor(item_no,maidfile.pdb[6]);
}
void scolor_cb6(Widget widget,XtPointer client_data,XtPointer  call_data)
{
    int item_no = (int) client_data;
    setscolor(item_no,maidfile.pdb[7]);
}
void scolor_cb7(Widget widget,XtPointer client_data,XtPointer  call_data)
{
    int item_no = (int) client_data;
    setscolor(item_no,maidfile.pdb[8]);
}
void scolor_cb8(Widget widget,XtPointer client_data,XtPointer  call_data)
{
    int item_no = (int) client_data;
    setscolor(item_no,maidfile.pdb[9]);
}


    
void pdbrad_cb(Widget widget,XtPointer client_data,XtPointer  call_data)
{
    int item_no = (int) client_data;
    sc.pdbradius2 = sqr(fpdbradius[item_no]);  // Default pdb radius squared
}   

void pdbsub_cb0(Widget widget,XtPointer client_data,XtPointer  call_data)
{
    int item_no = (int) client_data;
    int subnum = 1;
    setsub(item_no,subnum,maidfile);
}
void pdbsub_cb1(Widget widget,XtPointer client_data,XtPointer  call_data)
{
    int item_no = (int) client_data;
    int subnum = 2;
    setsub(item_no,subnum,maidfile);
}
void pdbsub_cb2(Widget widget,XtPointer client_data,XtPointer  call_data)
{
    int item_no = (int) client_data;
    int subnum = 3;
    setsub(item_no,subnum,maidfile);
}
void pdbsub_cb3(Widget widget,XtPointer client_data,XtPointer  call_data)
{
    int item_no = (int) client_data;
    int subnum = 4;
    setsub(item_no,subnum,maidfile);
}
void pdbsub_cb4(Widget widget,XtPointer client_data,XtPointer  call_data)
{
    int item_no = (int) client_data;
    int subnum = 5;
    setsub(item_no,subnum,maidfile);
}
void pdbsub_cb5(Widget widget,XtPointer client_data,XtPointer  call_data)
{
    int item_no = (int) client_data;
    int subnum = 6;
    setsub(item_no,subnum,maidfile);
}
void pdbsub_cb6(Widget widget,XtPointer client_data,XtPointer  call_data)
{
    int item_no = (int) client_data;
    int subnum = 7;
    setsub(item_no,subnum,maidfile);
}
void pdbsub_cb7(Widget widget,XtPointer client_data,XtPointer  call_data)
{
    int item_no = (int) client_data;
    int subnum = 8;
    setsub(item_no,subnum,maidfile);
}
void pdbsub_cb8(Widget widget,XtPointer client_data,XtPointer  call_data)
{
    int item_no = (int) client_data;
    int subnum = 9;
    setsub(item_no,subnum,maidfile);
}
    
Widget  pdbmenu; // Global since needed in pdb_cb


void pdb_cb(Widget widget,XtPointer client_data,XtPointer  call_data)
{
    int item_no = (int) client_data;
    Widget widget2;
    int ip,ipon,count;
    char savpdb[300],savpdb0[300],pdbnum[5];

    printf("pdb_cb item_no = %d called \n",item_no);
    if(item_no==9)// labale on/off check button
       sc.printres = -sc.printres;
    else if(item_no==10){// reset residue label name array
      for(int ip=1;ip<=maidfile.npdb;ip++) // each pdb file
         maidfile.pdb[ip].pickres[0].num=0;
    }
    else if(item_no==11)// Center Pick On/off button
         sc.centerres = -sc.centerres;
    else if(item_no==12)// Center Input Dialog menu
         center_input_dialog(toplevel);
    else if(item_no==13){// Window about last picked
         sc.pdbwindow = - sc.pdbwindow;
printf("pdbwindow = %d\n",sc.pdbwindow);
         if(sc.pdbwindow ==1){
            sc.centerres = 1;  // Also center on picked res
            if (widget2 = XtNameToWidget (pdbmenu,"button_11")) //DEFAULT:  Turn off check box for centerpick button
                XtVaSetValues (widget2, XmNset, True, NULL);
         }
         else{
            sc.centerres = -1;  // Also center on picked res
            if (widget2 = XtNameToWidget (pdbmenu,"button_11")) //DEFAULT:  Turn off check box for centerpick button
                XtVaSetValues (widget2, XmNset,False, NULL);
         }
    }
    else if(item_no==15){// Make fit from ONE displayed pdb
printf("Picked writepdb\n");
       count=0;
       for(ip=1;ip<=maidfile.npdb;ip++) // Count number of pdb's displayed
         if(maidfile.pdb[ip].onoff==1){ // if turned on
            ipon = ip;
            count = count+1;
       }
       if(count>1){
          errormessage(toplevel,"ERROR: ONLY ONE PDB CAN BE DISPLAYED");
          goto quitrout;
       }
#if 1
       else{
          writepdbtofit(geo,fit,fitnum,maidfile.pdb[ipon].name); 
       }
#endif
    } // item 15
    else if(item_no==16){// Turn on/off refineresidue
       if(sc.refinepdbside < 0)
          sc.refinepdbside = 1;
       else// sc.refinepdbside >0
          sc.refinepdbside = -1 ;
    }
    else if(item_no==17){// Refine all side chains
      refineallpdbside(map[1], geo,rot,maidfile.pdb[1]);
    }
    else if(item_no==18){// Save displayed pdbs (lev format) as a pdbfile
      strcpy(savpdb0,"newpdb");
      for(ip=1;ip<=maidfile.npdb;ip++){ // each pdb file
         if(maidfile.pdb[ip].onoff==1){ // if turned on
           itoa(ip,pdbnum);
           strcpy(savpdb,savpdb0);
           strcat(savpdb,pdbnum);
           strcat(savpdb,".pdb");
           writelevtopdb(maidfile.pdb[ip],savpdb);
         }
       }
       errormessage(toplevel,"Displayed pdb's were saved to files 'newpdb#.pdb'");
    }
    else if(item_no==19){// rotate pdb
      rotatepdb(maidfile.pdb[1],"pdbrot");
      errormessage(toplevel,"pdb[1] was saved in file pdbrot");
    }
    quitrout:;    
}

void pdbpulldown(Widget menubar)
{
    char  pdbstr[MAXPDB][10],ch[10];
    Widget widget,radpullright,colorpullright[10];
    XmString xmpdb[MAXPDB],labonoff,resetlab,windowpick,radius[10],setradius;
    XmString  monoff,msideonoff,catrace,centerpick,inputcen,rotatepdb;
    XmString  maincolor,sidecolor,colorv[20],makefit,refineside,savepdb,refineallside;
    for(int i=1;i<MAXPDB;i++){
       strcpy(pdbstr[i],"PDB");
       sprintf(ch,"%d",i);
       strcat(pdbstr[i],ch);
       strcat(pdbstr[i],"...");
       xmpdb[i] = XmStringCreateLocalized (pdbstr[i]);
    }
    labonoff = XmStringCreateLocalized ("Label On/Off");    
    resetlab = XmStringCreateLocalized ("Delete All Labels");
    centerpick = XmStringCreateLocalized ("Center Picked On/Off");
    inputcen = XmStringCreateLocalized ("Center Input Residue");
    windowpick = XmStringCreateLocalized ("Window on Next Picked");
    makefit = XmStringCreateLocalized ("Make Fit from Displayed PDB");
    refineside = XmStringCreateLocalized ("Refine Picked Residue");
    refineallside = XmStringCreateLocalized ("Refine All Side Chains");
    savepdb = XmStringCreateLocalized ("Save Modified PDB");
    rotatepdb = XmStringCreateLocalized ("Rotate PDB");
   radius[0] = XmStringCreateLocalized ("5");
   radius[1] = XmStringCreateLocalized ("7.5");
   radius[2] = XmStringCreateLocalized ("10 (Default)");
   radius[3] = XmStringCreateLocalized ("12.5 ");
   radius[4] = XmStringCreateLocalized ("15");
   radius[5] = XmStringCreateLocalized ("17.5");
   radius[6] = XmStringCreateLocalized ("20.0");
   setradius = XmStringCreateLocalized("Window Radius (Ang)");
    pdbmenu=XmVaCreateSimplePulldownMenu (menubar, "pdb_menu", 1, pdb_cb,
        XmVaCASCADEBUTTON, xmpdb[1],'W',
        XmVaCASCADEBUTTON, xmpdb[2],'W',
        XmVaCASCADEBUTTON, xmpdb[3],'W',
        XmVaCASCADEBUTTON, xmpdb[4],'W',
        XmVaCASCADEBUTTON, xmpdb[5],'W',
        XmVaCASCADEBUTTON, xmpdb[6],'W',
        XmVaCASCADEBUTTON, xmpdb[7],'W',
        XmVaCASCADEBUTTON, xmpdb[8],'W',
        XmVaCASCADEBUTTON, xmpdb[9],'W', // must be < MAXPDB
        XmVaCHECKBUTTON,labonoff,NULL, NULL, NULL,  // button_9
        XmVaPUSHBUTTON,resetlab, 'R', NULL, NULL, // button_10
        XmVaCHECKBUTTON,centerpick,NULL, NULL, NULL,  // button_11
        XmVaPUSHBUTTON,inputcen, 'R', NULL, NULL, // button_12
        XmVaCHECKBUTTON,windowpick,NULL, NULL, NULL,  // button_13
        XmVaCASCADEBUTTON,setradius,NULL,// button_14
        XmVaPUSHBUTTON,makefit, 'M', NULL, NULL, // button_15
        XmVaCHECKBUTTON,refineside,NULL, NULL, NULL,  // button_16
        XmVaPUSHBUTTON,refineallside,NULL, NULL, NULL,  // button_17
        XmVaPUSHBUTTON,savepdb,NULL, NULL, NULL,  // button_18
        XmVaPUSHBUTTON,rotatepdb,NULL, NULL, NULL,  // button_19
        NULL);

    monoff = XmStringCreateLocalized ("ON ");
    msideonoff = XmStringCreateLocalized ("SIDE ON");
    catrace = XmStringCreateLocalized ("Ca TRACE");
    maincolor = XmStringCreateLocalized ("MAIN COLOR");
    sidecolor = XmStringCreateLocalized ("SIDE COLOR");
   colorv[0]=  XmStringCreateLocalized("Blue");
   colorv[1]=  XmStringCreateLocalized("Red");
   colorv[2]=  XmStringCreateLocalized("Lightblue");
   colorv[3]=  XmStringCreateLocalized("Yellow (Default)");
   colorv[4]=  XmStringCreateLocalized("Pink");
   colorv[5]=  XmStringCreateLocalized("Cyan");
   colorv[6]=  XmStringCreateLocalized("Magenta");
   colorv[7]=  XmStringCreateLocalized("Green");
   colorv[8]=  XmStringCreateLocalized("White");
   colorv[9]=  XmStringCreateLocalized("Black");
    if (widget = XtNameToWidget (pdbmenu,"button_9")) //DEFAULT:  Turn on check box for label on/off button
            XtVaSetValues (widget, XmNset, True, NULL);
    if (widget = XtNameToWidget (pdbmenu,"button_11")) //DEFAULT:  Turn off check box for centerpick button
            XtVaSetValues (widget, XmNset, False, NULL);
    if (widget = XtNameToWidget (pdbmenu,"button_13")) //DEFAULT:  Turn off check box for window button
            XtVaSetValues (widget, XmNset, False, NULL);
    if (widget = XtNameToWidget (pdbmenu,"button_15")) //DEFAULT:  Turn off check box for window button
            XtVaSetValues (widget, XmNset, False, NULL);
#if 0
    for(i=1;i<MAXPDB;i++){
       sc.pullright[i] = XmVaCreateSimplePulldownMenu (pdbmenu,
            "pullright", i-1 ,pdbsub_cb0,
             XmVaCHECKBUTTON, monoff,NULL, NULL, NULL,
             XmVaCHECKBUTTON, msideonoff, NULL, NULL, NULL,
             NULL);
    }
#endif
   sc.pullright[1] = XmVaCreateSimplePulldownMenu (pdbmenu,
            "pullright", 0 ,pdbsub_cb0,XmVaCHECKBUTTON, monoff,NULL, NULL, NULL,
             XmVaCHECKBUTTON, msideonoff, NULL, NULL, NULL,
             XmVaCHECKBUTTON,catrace, NULL, NULL, NULL,
             XmVaCASCADEBUTTON,maincolor,NULL,
             XmVaCASCADEBUTTON,sidecolor,NULL,
             NULL);
   sc.pullright[2] = XmVaCreateSimplePulldownMenu (pdbmenu,
            "pullright", 1 ,pdbsub_cb1,XmVaCHECKBUTTON, monoff,NULL, NULL, NULL,
             XmVaCHECKBUTTON, msideonoff, NULL, NULL, NULL,
             XmVaCHECKBUTTON,catrace, NULL, NULL, NULL,
             XmVaCASCADEBUTTON,maincolor,NULL,
             XmVaCASCADEBUTTON,sidecolor,NULL,
             NULL);
   sc.pullright[3] = XmVaCreateSimplePulldownMenu (pdbmenu,
            "pullright", 2 ,pdbsub_cb2,XmVaCHECKBUTTON, monoff,NULL, NULL, NULL,
             XmVaCHECKBUTTON, msideonoff, NULL, NULL, NULL,
             XmVaCHECKBUTTON,catrace, NULL, NULL, NULL,
             XmVaCASCADEBUTTON,maincolor,NULL,
             XmVaCASCADEBUTTON,sidecolor,NULL,
             NULL);
   sc.pullright[4] = XmVaCreateSimplePulldownMenu (pdbmenu,
            "pullright", 3 ,pdbsub_cb3,XmVaCHECKBUTTON, monoff,NULL, NULL, NULL,
             XmVaCHECKBUTTON, msideonoff, NULL, NULL, NULL,
             XmVaCHECKBUTTON,catrace, NULL, NULL, NULL,
             XmVaCASCADEBUTTON,maincolor,NULL,
             XmVaCASCADEBUTTON,sidecolor,NULL,
             NULL);
   sc.pullright[5] = XmVaCreateSimplePulldownMenu (pdbmenu,
            "pullright",4 ,pdbsub_cb4,XmVaCHECKBUTTON, monoff,NULL, NULL, NULL,
             XmVaCHECKBUTTON, msideonoff, NULL, NULL, NULL,
             XmVaCHECKBUTTON,catrace, NULL, NULL, NULL,
             XmVaCASCADEBUTTON,maincolor,NULL,
             XmVaCASCADEBUTTON,sidecolor,NULL,
             NULL);
   sc.pullright[6] = XmVaCreateSimplePulldownMenu (pdbmenu,
            "pullright",5 ,pdbsub_cb5,XmVaCHECKBUTTON, monoff,NULL, NULL, NULL,
             XmVaCHECKBUTTON, msideonoff, NULL, NULL, NULL,
             XmVaCHECKBUTTON,catrace, NULL, NULL, NULL,
             XmVaCASCADEBUTTON,maincolor,NULL,
             XmVaCASCADEBUTTON,sidecolor,NULL,
             NULL);
   sc.pullright[7] = XmVaCreateSimplePulldownMenu (pdbmenu,
            "pullright",6 ,pdbsub_cb6,XmVaCHECKBUTTON, monoff,NULL, NULL, NULL,
             XmVaCHECKBUTTON, msideonoff, NULL, NULL, NULL,
             XmVaCHECKBUTTON,catrace, NULL, NULL, NULL,
             XmVaCASCADEBUTTON,maincolor,NULL,
             XmVaCASCADEBUTTON,sidecolor,NULL,
             NULL);
   sc.pullright[8] = XmVaCreateSimplePulldownMenu (pdbmenu,
            "pullright",7 ,pdbsub_cb7,XmVaCHECKBUTTON, monoff,NULL, NULL, NULL,
             XmVaCHECKBUTTON, msideonoff, NULL, NULL, NULL,
             XmVaCHECKBUTTON,catrace, NULL, NULL, NULL,
             XmVaCASCADEBUTTON,maincolor,NULL,
             XmVaCASCADEBUTTON,sidecolor,NULL,
             NULL);
   sc.pullright[9] = XmVaCreateSimplePulldownMenu (pdbmenu,
            "pullright",8 ,pdbsub_cb8,XmVaCHECKBUTTON, monoff,NULL, NULL, NULL,
             XmVaCHECKBUTTON, msideonoff, NULL, NULL, NULL,
             XmVaCHECKBUTTON,catrace, NULL, NULL, NULL,
             XmVaCASCADEBUTTON,maincolor,NULL,
             XmVaCASCADEBUTTON,sidecolor,NULL,
             NULL);
   radpullright=XmVaCreateSimplePulldownMenu (pdbmenu,
            "rpullright", 14 ,pdbrad_cb,
             XmVaRADIOBUTTON,radius[0],NULL, NULL, NULL,
             XmVaRADIOBUTTON,radius[1],NULL, NULL, NULL,
             XmVaRADIOBUTTON,radius[2],NULL, NULL, NULL,
             XmVaRADIOBUTTON,radius[3],NULL, NULL, NULL,
             XmVaRADIOBUTTON,radius[4],NULL, NULL, NULL,
             XmVaRADIOBUTTON,radius[5],NULL, NULL, NULL,
             XmVaRADIOBUTTON,radius[6],NULL, NULL, NULL,
             XmNradioBehavior, True,     /* RowColumn resources to enforce */
             XmNradioAlwaysOne, True,    /* radio behavior in Menu */
             NULL);   

   colorpullright[1]=XmVaCreateSimplePulldownMenu (sc.pullright[1],
            "rpullright", 3 ,mcolor_cb0,
             XmVaRADIOBUTTON,colorv[0],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[1],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[2],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[3],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[4],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[5],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[6],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[7],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[8],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[9],NULL, NULL, NULL,
             XmNradioBehavior, True,     /* RowColumn resources to enforce */
             XmNradioAlwaysOne, True,    /* radio behavior in Menu */
             NULL);   
   colorpullright[2]=XmVaCreateSimplePulldownMenu (sc.pullright[2],
            "rpullright", 3 ,mcolor_cb1,
             XmVaRADIOBUTTON,colorv[0],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[1],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[2],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[3],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[4],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[5],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[6],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[7],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[8],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[9],NULL, NULL, NULL,
             XmNradioBehavior, True,     /* RowColumn resources to enforce */
             XmNradioAlwaysOne, True,    /* radio behavior in Menu */
             NULL);   

   colorpullright[3]=XmVaCreateSimplePulldownMenu (sc.pullright[3],
            "rpullright", 3 ,mcolor_cb2,
             XmVaRADIOBUTTON,colorv[0],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[1],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[2],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[3],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[4],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[5],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[6],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[7],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[8],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[9],NULL, NULL, NULL,
             XmNradioBehavior, True,     /* RowColumn resources to enforce */
             XmNradioAlwaysOne, True,    /* radio behavior in Menu */
             NULL);   
   colorpullright[4]=XmVaCreateSimplePulldownMenu (sc.pullright[4],
            "rpullright", 3 ,mcolor_cb3,
             XmVaRADIOBUTTON,colorv[0],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[1],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[2],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[3],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[4],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[5],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[6],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[7],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[8],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[9],NULL, NULL, NULL,
             XmNradioBehavior, True,     /* RowColumn resources to enforce */
             XmNradioAlwaysOne, True,    /* radio behavior in Menu */
             NULL);   
   colorpullright[5]=XmVaCreateSimplePulldownMenu (sc.pullright[5],
            "rpullright", 3 ,mcolor_cb4,
             XmVaRADIOBUTTON,colorv[0],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[1],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[2],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[3],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[4],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[5],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[6],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[7],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[8],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[9],NULL, NULL, NULL,
             XmNradioBehavior, True,     /* RowColumn resources to enforce */
             XmNradioAlwaysOne, True,    /* radio behavior in Menu */
             NULL);   
   colorpullright[6]=XmVaCreateSimplePulldownMenu (sc.pullright[6],
            "rpullright", 3 ,mcolor_cb5,
             XmVaRADIOBUTTON,colorv[0],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[1],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[2],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[3],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[4],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[5],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[6],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[7],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[8],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[9],NULL, NULL, NULL,
             XmNradioBehavior, True,     /* RowColumn resources to enforce */
             XmNradioAlwaysOne, True,    /* radio behavior in Menu */
             NULL);   
   colorpullright[7]=XmVaCreateSimplePulldownMenu (sc.pullright[7],
            "rpullright", 3 ,mcolor_cb6,
             XmVaRADIOBUTTON,colorv[0],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[1],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[2],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[3],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[4],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[5],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[6],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[7],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[8],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[9],NULL, NULL, NULL,
             XmNradioBehavior, True,     /* RowColumn resources to enforce */
             XmNradioAlwaysOne, True,    /* radio behavior in Menu */
             NULL);   
   colorpullright[8]=XmVaCreateSimplePulldownMenu (sc.pullright[8],
            "rpullright", 3 ,mcolor_cb7,
             XmVaRADIOBUTTON,colorv[0],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[1],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[2],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[3],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[4],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[5],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[6],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[7],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[8],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[9],NULL, NULL, NULL,
             XmNradioBehavior, True,     /* RowColumn resources to enforce */
             XmNradioAlwaysOne, True,    /* radio behavior in Menu */
             NULL);   
   colorpullright[9]=XmVaCreateSimplePulldownMenu (sc.pullright[9],
            "rpullright", 3 ,mcolor_cb8,
             XmVaRADIOBUTTON,colorv[0],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[1],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[2],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[3],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[4],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[5],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[6],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[7],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[8],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[9],NULL, NULL, NULL,
             XmNradioBehavior, True,     /* RowColumn resources to enforce */
             XmNradioAlwaysOne, True,    /* radio behavior in Menu */
             NULL);   
    for(i=1;i<MAXPDB;i++){ // set default values for main color = yellow     
        if (widget = XtNameToWidget (colorpullright[i], "button_3")) 
                XtVaSetValues (widget, XmNset,True, NULL);
    }
   colorpullright[1]=XmVaCreateSimplePulldownMenu (sc.pullright[1],
            "rpullright", 4 ,scolor_cb0,
             XmVaRADIOBUTTON,colorv[0],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[1],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[2],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[3],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[4],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[5],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[6],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[7],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[8],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[9],NULL, NULL, NULL,
             XmNradioBehavior, True,     /* RowColumn resources to enforce */
             XmNradioAlwaysOne, True,    /* radio behavior in Menu */
             NULL);   
   colorpullright[2]=XmVaCreateSimplePulldownMenu (sc.pullright[2],
            "rpullright", 4 ,scolor_cb1,
             XmVaRADIOBUTTON,colorv[0],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[1],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[2],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[3],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[4],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[5],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[6],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[7],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[8],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[9],NULL, NULL, NULL,
             XmNradioBehavior, True,     /* RowColumn resources to enforce */
             XmNradioAlwaysOne, True,    /* radio behavior in Menu */
             NULL);   

   colorpullright[3]=XmVaCreateSimplePulldownMenu (sc.pullright[3],
            "rpullright", 4 ,scolor_cb2,
             XmVaRADIOBUTTON,colorv[0],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[1],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[2],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[3],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[4],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[5],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[6],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[7],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[8],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[9],NULL, NULL, NULL,
             XmNradioBehavior, True,     /* RowColumn resources to enforce */
             XmNradioAlwaysOne, True,    /* radio behavior in Menu */
             NULL);   
   colorpullright[4]=XmVaCreateSimplePulldownMenu (sc.pullright[4],
            "rpullright", 4 ,scolor_cb3,
             XmVaRADIOBUTTON,colorv[0],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[1],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[2],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[3],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[4],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[5],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[6],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[7],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[8],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[9],NULL, NULL, NULL,
             XmNradioBehavior, True,     /* RowColumn resources to enforce */
             XmNradioAlwaysOne, True,    /* radio behavior in Menu */
             NULL);   
   colorpullright[5]=XmVaCreateSimplePulldownMenu (sc.pullright[5],
            "rpullright", 4 ,scolor_cb4,
             XmVaRADIOBUTTON,colorv[0],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[1],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[2],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[3],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[4],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[5],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[6],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[7],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[8],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[9],NULL, NULL, NULL,
             XmNradioBehavior, True,     /* RowColumn resources to enforce */
             XmNradioAlwaysOne, True,    /* radio behavior in Menu */
             NULL);   
   colorpullright[6]=XmVaCreateSimplePulldownMenu (sc.pullright[6],
            "rpullright", 4 ,scolor_cb5,
             XmVaRADIOBUTTON,colorv[0],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[1],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[2],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[3],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[4],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[5],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[6],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[7],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[8],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[9],NULL, NULL, NULL,
             XmNradioBehavior, True,     /* RowColumn resources to enforce */
             XmNradioAlwaysOne, True,    /* radio behavior in Menu */
             NULL);   
   colorpullright[7]=XmVaCreateSimplePulldownMenu (sc.pullright[7],
            "rpullright", 4 ,scolor_cb6,
             XmVaRADIOBUTTON,colorv[0],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[1],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[2],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[3],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[4],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[5],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[6],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[7],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[8],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[9],NULL, NULL, NULL,
             XmNradioBehavior, True,     /* RowColumn resources to enforce */
             XmNradioAlwaysOne, True,    /* radio behavior in Menu */
             NULL);   
   colorpullright[8]=XmVaCreateSimplePulldownMenu (sc.pullright[8],
            "rpullright", 4 ,scolor_cb7,
             XmVaRADIOBUTTON,colorv[0],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[1],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[2],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[3],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[4],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[5],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[6],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[7],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[8],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[9],NULL, NULL, NULL,
             XmNradioBehavior, True,     /* RowColumn resources to enforce */
             XmNradioAlwaysOne, True,    /* radio behavior in Menu */
             NULL);   
   colorpullright[9]=XmVaCreateSimplePulldownMenu (sc.pullright[9],
            "rpullright", 4 ,scolor_cb8,
             XmVaRADIOBUTTON,colorv[0],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[1],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[2],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[3],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[4],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[5],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[6],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[7],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[8],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[9],NULL, NULL, NULL,
             XmNradioBehavior, True,     /* RowColumn resources to enforce */
             XmNradioAlwaysOne, True,    /* radio behavior in Menu */
             NULL);   
    for(i=1;i<MAXPDB;i++){ // set default values for side color = light blue     
        if (widget = XtNameToWidget (colorpullright[i], "button_2")) 
                XtVaSetValues (widget, XmNset,True, NULL);
    }
    for(i=1;i<MAXPDB;i++){ // Turn off sensitivitivity  - look pale
       XtSetSensitive(sc.pullright[i],0);
    }
   if (widget = XtNameToWidget (radpullright, "button_2"))
                XtVaSetValues (widget, XmNset,True, NULL);             
    XmStringFree (monoff);
    XmStringFree (msideonoff);
    XmStringFree (catrace);
    XmStringFree (labonoff);
    XmStringFree (resetlab);
    XmStringFree (centerpick);
    XmStringFree (inputcen);
    XmStringFree (makefit);
    XmStringFree (windowpick);
    XmStringFree (savepdb);
    XmStringFree (refineside);
    XmStringFree (refineallside);
    XmStringFree (rotatepdb);
    for(i=1;i<MAXPDB;i++)
       XmStringFree (xmpdb[i]);
    for(i=0;i<=6;i++)
       XmStringFree (radius[i]);
    for(i=0;i<=9;i++)
       XmStringFree (colorv[i]);
    XmStringFree( setradius); 
    XmStringFree(maincolor);
}
#if 1
/* Copied from "New" under "File" menu -  
   General procedure for inputing several items in dialog menu:
   1) Define  extern  struct st ss;
   2) Include menu.h  and use the routines clear_pushed, close_dialog, activate_cb etc
          from menu.c++
   3) Set  ss.num= # of separate entries in dialog
   4) Only call back that needs to be redefined in the OK call back, for rest use routine in menu.c++
       Use the struct ss and routines
*/
extern  struct st ss;  // Define before in menu.c++



static void center_ok_pushed(Widget w,XtPointer  client_data,XtPointer  call_data)
/*
 NEW on 9dec98 - if residues are not numbered consequatively from 1, must
    run through pdb to find the number that corresponds to character # of residue
 FOR NOW: Assume only one segment per pdb
 On input  ss.w[0] = resn, and if more than one pdb, ss.w[1] = pdbnum
*/
{
    printf(" OK pushed\n");
    char* text[5];
    int resn,segn,pdbn,pnum;
    
    segn = 0;  // Default  USE FIRST SEGMENT
         
#if 0
    for(int i = 0;i< ss.num;i++){
        text[i] =   XmTextFieldGetString (ss.w[i]); 
        ii[i] = atoi(text[i]);
printf(" ii = %d\n",ii[i]);
    }
#endif
#if 1 // new version
    for(int i = 0;i< ss.num;i++){
        text[i] =   XmTextFieldGetString (ss.w[i]);
printf(" text[%d] = %s\n",i,text[i]); 
    }
    segn = atoi(text[1]);
    if(segn==0) // value returned if text[1]==null - Default
       segn=segn;
    else
       segn = segn-1;  // segments run from 0,1....
    pdbn = atoi(text[2]); // pdbnum
    if(pdbn==0) // value returned if text[1]==null - Default
       pdbn = 1;
printf("segn = %d  pdbn = %d\n",segn,pdbn);
 
    for(i=1;i<=maidfile.pdb[pdbn].resdat[segn+1][0][0];i++) { 
       if(strcmp(text[0],maidfile.pdb[pdbn].resnumch[segn][i])== 0){
          resn =i;
          goto quiti;
       }
    }
// If reach here - ERROR no such residue  - set residue = default = 1
    fprintf(fpout,"ERROR: no residue has number character = %s\n",text[0]);
    resn = 1; // default
    quiti:;
printf("pdbn = %d   resn = %d\n",pdbn,resn);
#endif
    Widget shell = (Widget) client_data;
    XtDestroyWidget (shell);
    pnum=  ++maidfile.pdb[pdbn].pickres[0].num;// Add this residue to residue label list
    if(pnum>PDBLABEL-5)
         errormessage(toplevel,"You are near allowed limit of pdb labels.. 'Delete Label' and continue");
    maidfile.pdb[pdbn].pickres[pnum].seg = segn;
    maidfile.pdb[pdbn].pickres[pnum].num = resn;
    for(i=0;i<=2;i++)
         sc.centerpos[i] = maidfile.pdb[pdbn].mainch[segn][resn][1][i];
    if(sc.pdbwindow==1){ // Then window about centerpos
          findpdbwind();
          findbonewind();
          sc.windowselect =1;
    }
    else if (sc.pdbwindow !=1)
           sc.windowselect = -1;
    for(i=1;i<= maidfile.nden;i++){ // contour about input fit
            if(map[i].contonoff ==1)
                contourmap(map[i],sc.centerpos);
            sc.drawcontour = 1; // Turn on drawing of contour
    } 
}

void  center_input_dialog(Widget w)  // Input menu for putting in residue number want to
   // center on - 
   //Default values - if only one pdb or one segment - then use it
{
    Widget dialog, rc;
    char tempstr[50],tempch[5];
    XmString string;
    Arg args[5];
    int n = 0;
    static ActionAreaItem action_items[] = {
        { "OK",     center_ok_pushed,     NULL          },
        { "Clear",  clear_pushed,  NULL          },
        { "Cancel", close_dialog,  NULL          },
        { "Help",   help,          "Help Button" },
    };
    /* Create a TemplateDialog that will contain the control area
     * and the action area buttons for the dialog
     */ 
    string = XmStringCreateLocalized ("Dialog Shell");
    XtSetArg (args[n], XmNdialogTitle, string); n++;
    XtSetArg (args[n], XmNautoUnmanage, False); n++;
    dialog = XmCreateTemplateDialog (toplevel, "dialog", args, n);
    XmStringFree (string);

    /* now that the dialog is created, set the Cancel button's
     * client data, so close_dialog() will know what to destroy.
     */
    action_items[0].data=action_items[2].data = (XtPointer) dialog;

    /* create the control area which contains a
     * Label gadget and a TextField widget.
     */
//    ss.num=2; // the number of data entries spaces
    rc = XtVaCreateWidget ("control_area", 
        xmRowColumnWidgetClass, dialog, NULL);
    ss.num = 1;
    string = XmStringCreateLocalized ("ENTER RESIDUE NUMBER:");
    XtVaCreateManagedWidget ("label", xmLabelGadgetClass, rc,
        XmNlabelString,    string,
        NULL);
    XmStringFree (string);
    ss.w[0] = XtVaCreateManagedWidget ("text-field",xmTextFieldWidgetClass, rc, NULL);
    ss.num = 2;
    string = XmStringCreateLocalized ("ENTER SEGMENT NUMBER 1,2,.. (DEFAULT = 1):");
    XtVaCreateManagedWidget ("label", xmLabelGadgetClass, rc,
        XmNlabelString,    string,
        NULL);
    XmStringFree (string);
    ss.w[1] = XtVaCreateManagedWidget ("text-field",xmTextFieldWidgetClass, rc, NULL);
    if(maidfile.npdb > 1){
      ss.num = 3;
      strcpy(tempstr,"ENTER PDB NUMBER:");
      for(int i = 1;i<=maidfile.npdb;i++){
         if(i!=1)
           strcat(tempstr," or ");
         itoa(i,tempch);
         strcat(tempstr,tempch);
      }
      string = XmStringCreateLocalized (tempstr);
      XtVaCreateManagedWidget ("label", xmLabelGadgetClass, rc,
        XmNlabelString,    string,
        NULL);
      XmStringFree (string);
      ss.w[2] = XtVaCreateManagedWidget ("text-field",
           xmTextFieldWidgetClass, rc, NULL);
    }
 
    /* RowColumn is full -- now manage */
    XtManageChild (rc);
  
    /* Create the action area. */
    CreateActionArea (dialog, action_items, XtNumber (action_items));

    /* callback for Return in TextField.  Use dialog as client data */
//    XtAddCallback (ss.w[0], XmNactivateCallback, activate_cb, dialog);

    XtManageChild (dialog);
    XtPopup (XtParent (dialog), XtGrabNone);
    glClearColor(backcolv[0],backcolv[1],backcolv[2],0);//background color :red, green, blue, and alpha = black
}
#endif
