在GaussView中建立自己的模型面板

  • strict warning: Non-static method view::load() should not be called statically in /home/vasp/wwwroot/drupal-6.33/sites/all/modules/views/views.module on line 906.
  • strict warning: Declaration of views_handler_argument::init() should be compatible with views_handler::init(&$view, $options) in /home/vasp/wwwroot/drupal-6.33/sites/all/modules/views/handlers/views_handler_argument.inc on line 744.
  • strict warning: Declaration of views_plugin_row::options_validate() should be compatible with views_plugin::options_validate(&$form, &$form_state) in /home/vasp/wwwroot/drupal-6.33/sites/all/modules/views/plugins/views_plugin_row.inc on line 134.
  • strict warning: Declaration of views_plugin_row::options_submit() should be compatible with views_plugin::options_submit(&$form, &$form_state) in /home/vasp/wwwroot/drupal-6.33/sites/all/modules/views/plugins/views_plugin_row.inc on line 134.
软件名称: 
GaussView

GaussView3.x版本中有五個模型面板(見下圖),分別是元素模型、環結構模型、R基模型、生物分子模型和自定義模型。

 

GaussViewGaussView
點擊上圖所示的每個模型的按鈕,就會彈出一個模型面板(見下圖),上面列出各種GaussView自帶的模型,點擊某個模型,你就能在窗口中添加該分子片斷。

 

GaussViewGaussView
 

然而畢竟GaussView自帶的模型種類和數目有限,因此GaussView提供了自定義模型按鈕(即上述第五個)。其添加自定義分子模型的方法很簡單,下面以立方烷為例說明:

首先, 用GaussView打開立方烷分子的文件。

然后,點擊自定義模型按鈕打開自定義面板(見下圖),填入該模型的名稱、標題以及按鈕提示文字。最后點擊“Save”按鈕保存。

GaussViewGaussView

 

這時你會發現,在GaussView的安裝路徑的根目錄下會出現一個“customfrag.ftb”文件和一個“fragment”目錄。前者記錄了自定義模型面板的當前設置,如本例:

# Custom Fragment Table

# Format: name buttontext fragment

#

nItems = 1 defaultItem = -1

"cubane" "cubane" "cubane.frg"

而“fragment”目錄下的文件中則記錄了剛才新建的分子結構的名稱信息、笛卡爾坐標、激活原子以及鍵連方式。如本例的“cubane.frg”文件:

cubane

16

6         0.7794436767        -0.7794436767         0.7794436767 HOT

6        -0.7794436767         0.7794436767        -0.7794436767

1         1.4035876191        -1.4035876191         1.4035876191

1        -1.4035876191         1.4035876191        -1.4035876191

6         0.7794436767        -0.7794436767        -0.7794436767

6         0.7794436767         0.7794436767         0.7794436767

6        -0.7794436767        -0.7794436767         0.7794436767

6        -0.7794436767         0.7794436767         0.7794436767

6        -0.7794436767        -0.7794436767        -0.7794436767

6         0.7794436767         0.7794436767        -0.7794436767

1         1.4035876191        -1.4035876191        -1.4035876191

1         1.4035876191         1.4035876191         1.4035876191

1        -1.4035876191        -1.4035876191         1.4035876191

1        -1.4035876191         1.4035876191         1.4035876191

1        -1.4035876191        -1.4035876191        -1.4035876191

1         1.4035876191         1.4035876191        -1.4035876191

20

1 3 1

1 5 1

1 6 1

1 7 1

2 4 1

2 8 1

2 9 1

2 10 1

5 9 1

5 10 1

5 11 1

6 8 1

6 10 1

6 12 1

7 8 1

7 9 1

7 13 1

8 14 1

9 15 1

10 16 1

 

然而,GaussView的這個自定義模型面板也有其不足之處:

1.    不能像其他模型面板那樣擁有直觀的圖形化的模型按鈕。

2.    無法將自定義分類。

 

為了彌補上述不足,下面就向大家介紹一下如何在其他固有面板中添加自定義的模型。為簡單和清楚起見,我們以向環結構面板中添加立方烷模型為例。

1.       利用自定義模型面板添加立方烷模型,其方法在上面我已經介紹了。

2.       然后,將上述的“cubane.frg”文件拷貝到GaussView安裝目錄下的“data\rings\fragments”子目錄中。

3.       用文本編輯器打開“data\rings”子目錄中的rings.ftb文件,作如下修改:

(1)    將“nItems = ”后面數字增加1,本例中改為“nItems = 37”

(2)    在文件末尾新添一行,內容如下:

"cubane"            cubane.xbm     cubane.frg                   6   0

注意最后兩個數字“6 0”表示新建的按鈕在面板的第7行第1列(以0開始計數)。

4.       最后,我們需要做的是為我們的模型制作按鈕圖片。下面我要詳細講講。

GaussView中模型面板中的按鈕圖片大小是65*65像素,格式是xbm圖片。Xbm是一種比較古老的圖片格式,用過去的IE瀏覽器可以打開。但SP2以后版本的IE瀏覽器則不再支持xbm圖片了,因為xbm格式缺乏錯誤檢查,會產生安全漏洞。不過,有些圖形軟件是支持xbm圖片的轉換的。好了,言歸正傳,還是來說說怎么為我們的立方烷結構做模型圖片吧。

首先用ChemDraw畫好立方烷結構,幸好,ChemDraw自帶有立方烷模型,一切都是現成的。然后將它保存成bmp格式的“cubane.bmp”文件。用畫圖板將“cubane.bmp”文件大小調整為65*65像素。

然后,用bmp2xbm程序(原程序見文末附錄)將“cubane.bmp”文件轉成“cubane.xbm”文件。bmp2xbm程序是我利用別人的程序稍作修改的,使用方法很簡單,在DOS下使用命令:

bmp2xbm cubane.bmp

5.       將cubane.xbm復制到目錄下,退出并重啟GaussView。

 

這時,打開環結構模型面板,你就會看到多處一個立方烷的按鈕了,如下圖所示:

 

GaussViewGaussView

 

 

附:bmp2xbm源代碼(C語言):

 

/****************************************************

**   bmp2xbm.c                                     **

**        Windows Bitmap -> X Bitmap converter     **

**   version 1.22  copyright SAKAMOTO Hirokazu     **

**        Last update 2001/08/24                   **

**   Modified by yangwang2008@gmail.com 07/01/31   **

****************************************************/

 

#include

#include

#include

#include

#include

 

#define THRESHOLD 128

 

long biny(char *cin, int len)

{

    int i;

    long p,j;

    p=0;

    j=1;

    for(i=0; i

    return p;

}

 

int write_image(char *outfname, const char *img, int xs, int ys)

{

    int y,x,i,px;

    FILE *fp;

    unsigned char moji;

    const char *p;

   

    fp = fopen(outfname,"w");

    if(fp==NULL){

           printf("cannot open outfile.\n");

           return -1;

    }

   

    i = strlen(outfname);

    if(i<=0) return -2;

    while(outfname[i]!='.' && i>0) i--;

    if(i!=0) outfname[i]='\0';

    else{ printf("outfilename \"%s\" non *.xbm",outfname); return -1; }

   

    fprintf(fp,"#define %s_width %d\n",outfname,xs);

    fprintf(fp,"#define %s_height %d\n",outfname,ys);

    fprintf(fp,"static unsigned char %s_bits[] = {",outfname);

   

    px=12;

    for(y=0;y

           for(x=0;x

                  if(px==12){

                         fputs("\n  ",fp);

                         px=0;

                  }

                  p = img+xs*y+x;

                  moji=0;

                  for(i=x+7

                  fprintf(fp," 0x%02x,",moji);

           }

    }

   

    fseek(fp,-1,SEEK_CUR);

    fputs("};\n",fp);

    fclose(fp);

    return 0;

}

 

int main(int argc,char **argv)

{

    int i,j,xs,ys,l,k,t,x,y;

    int cut=THRESHOLD, var=0, block=0, sha=0, sham=0, dist=0, opp=0;

    char infname[256]="", outfname[256]="", c, cin[20];

    char *uimg;

    int mos=0, set;

    int *wimg, *wp;

    float r=0.30f, g=0.59f, b=0.11f;

    int ir=77, ig=151, ib=28;

    FILE *fp;

   

    if(argc==1 || !strcmp(argv[1],"-h")){

           puts( "Usage: bmp2xbm infilename(*.bmp) [outfilename(*.xbm)]\n" );

           return 0;

    }

   

    strcpy(infname,&argv[1][0]);      

    sscanf(infname,"%[^.]",outfname);

    strcat(outfname,".xbm");

    if(sham==0) sham=sha;

   

    if(r!=0.30f || g!=0.59f || b!=0.11f){

           ir = (int)(r*256);

           ig = (int)(g*256);

           ib = (int)(b*256);

    }

   

    //file open

    fp=fopen(infname,"rb");

    if(fp==NULL){

           printf("Inputfile cannot open !\n");

           return 0;

    }

    //read bmp

    for(i=0;i<2;i++) cin[i]=fgetc(fp);

    if(!(cin[0]=='B' && cin[1]=='M')){

           printf("Non WinBmp\n");

           return 0;

    }

    for(i=0;i<12;i++) fgetc(fp);

    for(i=0;i<4;i++) cin[i]=fgetc(fp);

    t=biny(cin,1);

    if(t==12){//OS2 encode

           for(i=0;i<2;i++) cin[i]=fgetc(fp);

           xs=biny(cin,2);

           for(i=0;i<2;i++) cin[i]=fgetc(fp);

           ys=biny(cin,2);

           for(i=0;i<4;i++) fgetc(fp);

    }

    else if(t==40){//RGB encode

           for(i=0;i<4;i++) cin[i]=fgetc(fp);

           xs=biny(cin,2);

           for(i=0;i<4;i++) cin[i]=fgetc(fp);

           ys=biny(cin,2);

           for(i=0;i<28;i++) fgetc(fp);

    }

    else{

           printf("I don't read %s...\n",infname);

           return 0;

    }

   

    wimg = (int *)malloc(sizeof(int)*xs*ys);

    srand(time(NULL));

   

    // BMP

    //decode RGB//

    l = xs & 0x03;

    for(j=ys-1; j>=0; j--){

           wp = wimg+xs*j;

           for(i=0; i

                  c=fgetc(fp); *wp = (c&0xff)*ib;

                  c=fgetc(fp); *wp += (c&0xff)*ig;

                  c=fgetc(fp); *wp += (c&0xff)*ir;

                  *wp >>= 8;

                 

                  if(var)     *wp += (rand()%(var+1)) - (var>>1);

                  if(i==xs-1) for(k=0;k

           }

    }

    fclose(fp);

   

    if(sha){

           int *rimg;

           rimg = (int *)malloc(sizeof(int)*xs*ys);

           memset(rimg, 0, sizeof(int)*xs*ys);

          

           for(j=1; j

                  for(i=1; i

                         wp = wimg+xs*j+i;

                         t=0;

                         for(y=-1; y<=1; y++){

                                for(x=-1; x<=1; x++){

                                       t += *(wp+xs*y+x);

                                }

                         }

                         *(rimg+xs*j+i) = abs(t - (*wp)*9) * sha;

                  }

           }

          

           if(dist>0){

                  wp = wimg;

                  wimg = rimg;

                  rimg = wp;

           }

           else if(sham) for(i=0;i

           free(rimg);

    }

   

    if(mos>0){

           for(j=0; j

                  for(i=0; i

                         wp = wimg + xs*j + i;

                         set=0;

                         t=0;

                         for(y=0; y

                                if(j+y>=ys) break;

                                for(x=0; x

                                       if(i+x>=xs) break;

                                       t += *(wp+xs*y+x);

                                       set++;

                                }

                         }

                         t /= set;

                         for(y=0; y

                                if(j+y>=ys) break;

                                for(x=0; x

                                       if(i+x>=xs) break;

                                       *(wp+xs*y+x) = t;

                                }

                         }

                  }

           }

    }

   

    if(cut!=THRESHOLD){

           for(i=0,wp=wimg; i

                  *wp -= cut - THRESHOLD;

           }

    }

   

    // 0--255

    for(i=0,wp=wimg; i

           if(*wp>0xFF) *wp=0xFF;

           else if(*wp<0) *wp=0;

    }

   

    // BMP

    if(opp==0){

           for(i=0,wp=wimg; i

                  *wp = 0xFF - *wp;

           }

    }

   

    uimg = (char *)malloc(sizeof(char)*xs*ys);

    memset(uimg, 0, sizeof(char)*xs*ys);

   

    for(i=0;i

           if(wimg[i]>=THRESHOLD){

                  uimg[i]=1;

           }

    }

   

    free(wimg);

   

    if(block>0){

           char *up;

           for(j=0,k=0;j

                  for(i=0,l=k;i

                         for(y=0;y

                                if(j+y>=ys) break;

                                for(x=0;x

                                       if(i+x>=xs) break;

                                       if(l&1){

                                              up = uimg+xs*(j+y)+i+x;

                                              *up = 1 - *up;

                                       }

                                }

                         }

                  }

           }

    }

   

    // XBM

    i = write_image(outfname, uimg, xs, ys);

    if(i<0) printf("ERROR Lv %d\n", i);

   

    free(uimg);

   

    return 0;

}

 

/* EOF */