mopac2000lite.exe 振動計算出力を振動ベクトル&アニメーションに変換(Xmol で表示)

2002.11 zhou 作成

注意:対応するMopacの バージョン Mopac2000lite.exe (unix)

動作環境:

Windows

コンパイラー:

VisualC++6


    ソース

    /*
    * Function@ create file.xyz (CARTESIAN COORDINATES), file-vec-vibnum.xyz(vibration vector), file-anm-vibnum.xyz, 
    *                  file-dip.xmgr(T-DIPOLE intensity ), file-inf.xmgr(infrared ray intensity ) 
    *                  file-vib-intensity.xmgr(vibration intensity)
    * 
    * Author@   zhou 2002/11  ?simple is the best
    * Copyright@  riron
    * Comman prompt input filename(don't write ".out") , total carbon atoms number, vib number(option)
    * Compiler@   !!!visualC6(windows)!!!// but not on flex
    */
    
    #include<stdio.h>
    #include<stdlib.h>
    #include<math.h>
    #include<malloc.h>
    #include<string.h>
    #include<direct.h>
    
    #define PI 3.141592654
    #define SIZE 1024
    
    typedef struct tag_XYZ
    {
        char atom[8];
        double x;
        double y;
        double z;
    }XYZ, *PXYZ;
    void debug(int CN, int VN, PXYZ *vec, PXYZ xyz);
    void printvector(char *filename,int CN, int VN, double amp, int vibrationnum, PXYZ *vec, PXYZ xyz);
    void printanimation(char *filename,int CN, int VN, double amp, int vibrationnum, PXYZ *vec, PXYZ xyz);
    void main(int argc,char *argv[])
    {
      int CN;             //total carbon atoms number      
      int VN;             //total vibration number           
      double amp;          //amplitude ratio 
        int vibrationnum;   //out put vibration number 
      int i,j,k,l,skip,block,surplus;
        int dummyint,dummyint1, dummyint2, dummyint3;
    
        PXYZ *vec;
        PXYZ xyz;              //nanotube cartesian cordination
    
      FILE *fp1;
      FILE *fp2;
        char filename[64];
        char filesrc[64];
        char filexyz[64];
        char tempstr[256];
        char dummystr[256];
    
    
      i=j=k=l=CN=0;
        ///////////get parameter form COMAND/////////
      printf("Input filename(don't write '.out')\n");
      scanf("%s",filename);
    
      printf("Input total carbon atoms number\n");
      scanf("%d",&CN);
    
      printf("Input amplitude ratio  (double) \n");
      scanf("%lf",&amp);
    
      VN=CN*3-6;
        surplus = VN%8;
        block = VN/8;
    
      printf("Input vibration number (1-%d) ",VN);
      scanf("%d",&vibrationnum);
    
        /////////// memory Allocation /////////
        if((xyz=(PXYZ)malloc(CN*sizeof(XYZ)))==NULL)
        {
            free(xyz);
            printf(" not enough memory.\n");
            exit(0);
        }
    
        if((vec=(PXYZ*)malloc(VN*sizeof(PXYZ)))==NULL)
        {
            free(vec);
            printf(" not enough memory.\n");
            exit(0);
        }
    
        for(i=0; i<VN; i++)
        {
          if((vec[i]=(PXYZ)malloc(CN*sizeof(XYZ)))==NULL)
          {
            while((--i)>=0)
            {
                free(vec[i]);
            }
            printf("at i= %d not enough memory.\n", i);
            exit(0);
          }
        }
    
        //open file.out
      strcpy(filesrc, filename);
      strcat(filesrc, ".out");
      if((fp1=fopen(filesrc,"r"))==NULL)
        {
        printf("Can't open %s\n",filesrc);
        exit(0);
      }
    
      if((fp2=fopen("temp","w"))==NULL)
        {
        printf("Can't open %s\n","temp");
        exit(0);
      }
    
    
    //////////////////////////get X Y Z  from file.out/////////////////////////
    //          CARTESIAN COORDINATES 
    //
    //    NO.       ATOM         X         Y         Z
    //
    //     1         C        3.1845    1.4234    0.0000
    //     2         C       -0.3697    3.4685    0.0000
    ////////////////////////////////////////////////////////////////////////////
    
      while(fscanf(fp1,"%s",tempstr)!=EOF)
        {
            if(strcmp(tempstr,"CARTESIAN") == 0)
            {
                break; //printf("%s", tempstr);
            }
        }
    
        //4 lines ++
        for(i = 0; i < 4; i++)
        {
            fgets(dummystr, 256, fp1); //printf("dummystr : %s\n", dummystr);
        }
    
        for(i = 0; i < CN; i++)
        {
          fscanf(fp1,"%d%s%lf%lf%lf",&dummyint, xyz[i].atom, &xyz[i].x, &xyz[i].y,&xyz[i].z);
          //printf("%3d%2s%10.4lf%10.4lf%10.4lf\n",dummyint, xyz[i].atom, xyz[i].x, xyz[i].y,xyz[i].z);
        }
    
    ///////////get VIB X Y Z VECTOR  from file.out/////////////////////////////
    //   Root No.     1       2       3       4       5       6       7       8
    //
    //              1E2'    1E2'    1E1'    1E1'    1A"     1E1"    1E1"    2E2' 
    //
    //              121.7   121.7   196.6   196.6   201.4   221.2   221.2   225.5
    //
    //          1 -0.0029  0.0143 -0.0041 -0.0022  0.0040  0.0067  0.0021 -0.0161
    //          2 -0.0092  0.0027 -0.0007  0.0056 -0.0090  0.0024 -0.0055 -0.0051
    ////////////////////////////////////////////////////////////////////////////
      while(fscanf(fp1,"%s",tempstr)!=EOF)
        {
            if(strcmp(tempstr,"Root") == 0)
            {
                break; //printf("%s", tempstr);
            }
        }
    
        //6 lines ++
        //for(j = 0; j < block; j++)
        for(j = 0; j < block; j++)
        {
            //fprintf(fp2,"((((((((( block num is %d)))))))))))\n", j);
    
            if(j == 0)
                skip = 6;
            else
                skip = 8;
    
            for(i = 0; i < skip; i++)
            {
                fgets(dummystr, 256, fp1); //printf("dummystr : %s\n", dummystr);
            }
    
            for(i = 0; i < CN; i++)
            {
                fscanf(fp1,"%d%lf%lf%lf%lf%lf%lf%lf%lf"
                , &dummyint1, &vec[8*j+0][i].x, &vec[8*j+1][i].x, &vec[8*j+2][i].x
                , &vec[8*j+3][i].x, &vec[8*j+4][i].x, &vec[8*j+5][i].x, &vec[8*j+6][i].x, &vec[8*j+7][i].x);
    
                fscanf(fp1,"%d%lf%lf%lf%lf%lf%lf%lf%lf"
                , &dummyint2, &vec[8*j+0][i].y, &vec[8*j+1][i].y, &vec[8*j+2][i].y
                , &vec[8*j+3][i].y, &vec[8*j+4][i].y, &vec[8*j+5][i].y, &vec[8*j+6][i].y, &vec[8*j+7][i].y);
    
                fscanf(fp1,"%d%lf%lf%lf%lf%lf%lf%lf%lf"
                , &dummyint3, &vec[8*j+0][i].z, &vec[8*j+1][i].z, &vec[8*j+2][i].z
                , &vec[8*j+3][i].z, &vec[8*j+4][i].z, &vec[8*j+5][i].z, &vec[8*j+6][i].z, &vec[8*j+7][i].z);
                /////write to temp/////
                /*
                fprintf(fp2,"%3d%10.4lf%10.4lf%10.4lf%10.4lf%10.4lf%10.4lf%10.4lf%10.4lf \n"
                , dummyint1, vec[8*j+0][i].x, vec[8*j+1][i].x, vec[8*j+2][i].x
                , vec[8*j+3][i].x, vec[8*j+4][i].x, vec[8*j+5][i].x, vec[8*j+6][i].x, vec[8*j+7][i].x);
    
                fprintf(fp2,"%3d%10.4lf%10.4lf%10.4lf%10.4lf%10.4lf%10.4lf%10.4lf%10.4lf \n"
                , dummyint2, vec[8*j+0][i].y, vec[8*j+1][i].y, vec[8*j+2][i].y
                , vec[8*j+3][i].y, vec[8*j+4][i].y, vec[8*j+5][i].y, vec[8*j+6][i].y, vec[8*j+7][i].y);
    
                fprintf(fp2,"%3d%10.4lf%10.4lf%10.4lf%10.4lf%10.4lf%10.4lf%10.4lf%10.4lf \n"
                , dummyint3, vec[8*j+0][i].z, vec[8*j+1][i].z, vec[8*j+2][i].z
                , vec[8*j+3][i].z, vec[8*j+4][i].z, vec[8*j+5][i].z, vec[8*j+6][i].z, vec[8*j+7][i].z);
                */
            }
        }
    
    ///////////get last block of VIB X Y Z VECTOR  from file.out////
    //     Root No.   321     322     323     324
    //                                          
    //           31E1"   31E1"   33E1'   33E1' 
    //                                          
    //           1809.4  1809.4  1812.6  1812.6
    //                                          
    //          1 -0.0030 -0.0001  0.0015 -0.0020
    //          2  0.0067 -0.0017 -0.0054  0.0036
    ////////////////////////////////////////////////////////////////
        if(surplus > 0)
        {
            //skip  lines
            if(block == 0)
                skip = 6;
            else
                skip = 8;
            for(i = 0; i < skip; i++)
            {
                fgets(dummystr, 256, fp1); //printf("dummystr : %s\n", dummystr);
            }
            for(i = 0; i < CN; i++)
            {
                fscanf(fp1,"%d" , &dummyint1);
                for(j = 0; j < surplus; j++)
                {
                    fscanf(fp1,"%lf", &vec[8*block+j][i].x);
                }
                fscanf(fp1,"%d" , &dummyint1);
                for(j = 0; j < surplus; j++)
                {
                    fscanf(fp1,"%lf", &vec[8*block+j][i].y);
                }
                fscanf(fp1,"%d" , &dummyint1);
                for(j = 0; j < surplus; j++)
                {
                    fscanf(fp1,"%lf", &vec[8*block+j][i].z);
                }
            }
        }
    
        fclose(fp1);
        fclose(fp2);
    
        //debug(CN, VN, vec, xyz);
        printanimation(filename,CN, VN, amp, vibrationnum, vec, xyz);
        printvector(filename,CN, VN, amp, vibrationnum, vec, xyz);
    
        free(xyz);
        for(i=0; i<VN; i++)
        {
            free(vec[i]);
        }
        free(vec);
    }
    
    void printvector(char *filename,int CN, int VN, double amp, int vibrationnum, PXYZ *vec, PXYZ xyz)
    {
        int i, j, k;
        FILE *fp;
        char filestr[128];
        char tempstr[64];
        char *dirstr = "vector";
        char *dirstr1 = "vector\\";
        char c = '\n';
    
        //output
        if(mkdir(dirstr) == 0)
        {
            printf("directory %s has been created", dirstr);
        }
        for(i = 0; i < VN; i++)
        {
            //open file
            strcpy(filestr, dirstr1);
            strcat(filestr, filename);
            sprintf(tempstr, "-vec-%d.xyz", i+1);
            strcat(filestr, tempstr);
    
            if((fp=fopen(filestr,"w"))==NULL)
            {
                printf("Can't open %s\n",filestr);
                fcloseall();
                exit(0);
            }
            fprintf(fp,"         %d\n\n",CN);
            for(j=0;j<CN;j++)
            {
                fprintf(fp,"%s   %9.6f",   xyz[j].atom, xyz[j].x );
                fprintf(fp,"   %9.6f"  ,                xyz[j].y );
                fprintf(fp,"   %9.6f",                  xyz[j].z );
    
                fprintf(fp,"   %9.6f",                  vec[i][j].x * amp * 10);
                fprintf(fp,"   %9.6f"  ,                vec[i][j].y * amp * 10);
                fprintf(fp,"   %9.6f\n",                vec[i][j].z * amp * 10);
            }
    
            fclose(fp);
        }
        system("dir vector\\ ");
    }
    void printanimation(char *filename,int CN, int VN, double amp, int vibrationnum, PXYZ *vec, PXYZ xyz)
    {
        int i, j, k;
        FILE *fp;
        char filestr[128];
        char tempstr[64];
        char *dirstr = "animation";
        char *dirstr1 = "animation\\";
        char c = '\n';
    
        //output
        if(mkdir(dirstr) == 0)
        {
            printf("directory %s has been created", dirstr);
        }
        for(i = 0; i < VN; i++)
        {
            //open file
            strcpy(filestr, dirstr1);
            strcat(filestr, filename);
            sprintf(tempstr, "-anm-%d.xyz", i+1);
            strcat(filestr, tempstr);
    
            if((fp=fopen(filestr,"w"))==NULL)
            {
                printf("Can't open %s\n",filestr);
                fcloseall();
                exit(0);
            }
            for(k=0;k<12;k++)
            {
                fprintf(fp,"         %d\n\n",CN);
                for(j=0;j<CN;j++)
                {
                    fprintf(fp,"%s   %9.6f",   xyz[j].atom, xyz[j].x + vec[i][j].x *amp*sin((double)(PI/6*k)));
                    fprintf(fp,"   %9.6f"  ,                xyz[j].y + vec[i][j].y *amp*sin((double)(PI/6*k)));
                    fprintf(fp,"   %9.6f\n",                xyz[j].z + vec[i][j].z *amp*sin((double)(PI/6*k)));
                }
            }
    
            fclose(fp);
        }
        system("dir animation\\ ");
    }
    void debug(int CN, int VN, PXYZ *vec, PXYZ xyz)
    {
        int i, j;
        FILE *fp;
        char *filestr = "debugtest";
        char c = '\n';
    
      if((fp=fopen(filestr,"w"))==NULL)
        {
        printf("Can't open %s\n",filestr);
        exit(0);
      }
    
        for(i = 0; i < VN; i++)
        {
                fprintf(fp, "------------- wave num %d -------------\n", i);
            for(j = 0; j < CN; j++)
            {
                fprintf(fp, "%8.4f ", vec[i][j].x);
                fprintf(fp, "%8.4f ", vec[i][j].y);
                fprintf(fp, "%8.4f \n", vec[i][j].z);
            }
        }
        fclose(fp);
    
    
    }
    


      コメントまたはアドバイスなどがあれば以下のアドレスへどうぞ。
      rsaito@ee.uec.ac.jp