static int Find_si(T_SgInfo *SgInfo) { static const int Tab_si_Vector[] = { 1, 0, 0, 0, /* h */ 0, 1, 0, 1, /* k */ 0, 0, 1, 2, /* l */ 1, 1, 0, 0, /* h+k */ 1, -1, 0, 0, /* h-k */ 0, 1, 1, 1, /* k+l */ 0, 1, -1, 1, /* k-l */ 1, 0, 1, 1, /* h+l */ 1, 0, -1, 1, /* h-l */ 1, 1, 1, 0, /* h+k+l */ 1, 1, -1, 0, /* h+k-l */ 1, -1, 1, 0, /* h-k+l */ -1, 1, 1, 0, /* -h+k+l */ 2, 1, -1, 0, /* 2h+k-l */ 2, -1, 1, 0, /* 2h-k+l */ -1, 2, 1, 0, /* -h+2k+l */ 1, 2, -1, 0, /* h+2k-l */ -1, 1, 2, 0, /* -h+k+2l */ 1, -1, 2, 0 /* h-k+2l */ }; static int nTab_si_Vector = sizeof Tab_si_Vector / sizeof (*Tab_si_Vector) / 4; int deterCCMx_LP, CCMx_PL[9]; int i, itabsiv; int nLoopInv, iLoopInv, n_si_v, i_si_v; int n, m, l; int IsFine; int item[3]; int R_I[9], si_Buf[9]; int iList; T_RTMx *lsmx; const int *tabsiv; if (SgInfo->LatticeInfo->Code != 'P') { deterCCMx_LP = deterRotMx(SgInfo->CCMx_LP); InverseRotMx(SgInfo->CCMx_LP, CCMx_PL); if (deterCCMx_LP < 1) goto ReturnError; } nLoopInv = Sg_nLoopInv(SgInfo); SgInfo->n_si_Vector = n_si_v = 0; for (i = 0; i < 9; i++) SgInfo->si_Vector[i] = 0; for (i = 0; i < 3; i++) { SgInfo->si_Modulus[i] = 1; item[i] = 1; } tabsiv = Tab_si_Vector; for (itabsiv = 0; itabsiv < nTab_si_Vector; itabsiv++, tabsiv += 4) { IsFine = 1; m = -1; for (iList = 0; IsFine && iList < SgInfo->nList; iList++) { lsmx = &SgInfo->ListSeitzMx[iList]; for (iLoopInv = 0; IsFine && iLoopInv < nLoopInv; iLoopInv++) { if (iLoopInv == 0) for (i = 0; i < 9; i++) { if (i % 4) R_I[i] = lsmx->s.R[i]; else R_I[i] = lsmx->s.R[i] - 1; } else for (i = 0; i < 9; i++) { if (i % 4) R_I[i] = -lsmx->s.R[i]; else R_I[i] = -lsmx->s.R[i] - 1; } if (SgInfo->LatticeInfo->Code != 'P') { if (PrimitiveRotMx(SgInfo->CCMx_LP, R_I, CCMx_PL, deterCCMx_LP) < 0) return -1; } for (i = 0; IsFine && i < 3; i++) { n = tabsiv[0] * R_I[i * 3 + 0]; n += tabsiv[1] * R_I[i * 3 + 1]; n += tabsiv[2] * R_I[i * 3 + 2]; n = abs(n); if (n == 1) IsFine = 0; else if (m < 2) m = n; else if (n > 0 && n != m) IsFine = 0; } } } if (IsFine) { #if DEBUG_Find_si fprintf(stdout, "H-Kt %2d %2d %2d %d\n", tabsiv[0], tabsiv[1], tabsiv[2], m); #endif l = tabsiv[3]; while (item[l] > 1) /* just "if", see break's */ { if (m == item[l]) break; if (m == 3 && ( SgInfo->XtalSystem != XS_Trigonal || SgInfo->UniqueDirCode != '=')) break; if (m == 4 && ( SgInfo->XtalSystem == XS_Triclinic || SgInfo->XtalSystem == XS_Monoclinic)) break; if (m == 2) break; /* if (m > 1 || m != 4) break; */ n_si_v--; item[l] = 1; break; } if (item[l] == 1) { if (itabsiv > 12) n_si_v = 0; item[l] = m; SgInfo->si_Modulus[n_si_v] = m; n = n_si_v * 3; for (i = 0; i < 3; i++) SgInfo->si_Vector[n++] = tabsiv[i]; n_si_v++; } } } #if DEBUG_Find_si fprintf(stdout, "H-Kt\n"); #endif if (SgInfo->LatticeInfo->Code != 'P') { #if DEBUG_Find_si for (i = 0; i < n_si_v; i++) fprintf(stdout, "H-Kp %2d %2d %2d %d\n", SgInfo->si_Vector[i * 3 + 0], SgInfo->si_Vector[i * 3 + 1], SgInfo->si_Vector[i * 3 + 2], SgInfo->si_Modulus[i]); fprintf(stdout, "H-Kp\n"); #endif for (i_si_v = 0; i_si_v < n_si_v; i_si_v++) { for (i = 0; i < 3; i++) { si_Buf[i_si_v * 3 + i] = SgInfo->si_Vector[i_si_v * 3 + 0] * CCMx_PL[i * 3 + 0] + SgInfo->si_Vector[i_si_v * 3 + 1] * CCMx_PL[i * 3 + 1] + SgInfo->si_Vector[i_si_v * 3 + 2] * CCMx_PL[i * 3 + 2]; } } for (i = 0; i < i_si_v * 3; i++) { if (si_Buf[i] % deterCCMx_LP) { n = i / 3; n *= 3; fprintf(stdout, " %3d %3d %3d\n", si_Buf[n + 0], si_Buf[n + 1], si_Buf[n + 2]); goto ReturnError; } SgInfo->si_Vector[i] = si_Buf[i] / deterCCMx_LP; } } SgInfo->n_si_Vector = n_si_v; return n_si_v; ReturnError: SetSgError("Internal Error: Find_si()"); return -1; }
static void Simple_hklList(T_SgInfo *SgInfo, int Maxh, int Maxk, int Maxl, int ListSysAbsent) { int h, k, l, iList, restriction, M, n, i; int Minh, Mink, Minl; int uvw[3]; int CCMx_PL[9], deterCCMx_LP = 0, hP, kP, lP; if (SgInfo->LatticeInfo->Code != 'P') { deterCCMx_LP = deterRotMx(SgInfo->CCMx_LP); InverseRotMx(SgInfo->CCMx_LP, CCMx_PL); if (deterCCMx_LP < 1) goto ReturnError; } SetListMin_hkl(SgInfo, Maxk, Maxl, &Minh, &Mink, &Minl); fprintf(stdout, ">Begin hklList\n"); for (h = Minh; h <= Maxh; h++) for (k = Mink; k <= Maxk; k++) for (l = Minl; l <= Maxl; l++) { iList = IsSysAbsent_hkl(SgInfo, h, k, l, &restriction); if (SgError != NULL) return; M = BuildEq_hkl(SgInfo, NULL, h, k, l); if (SgError != NULL) return; if (iList == 0) { if ((iList = IsSuppressed_hkl(SgInfo, Minh, Mink, Minl, Maxk, Maxl, h, k, l)) != 0) n = fprintf(stdout, "# %3d %3d %3d %3d [%d]", h, k, l, M, iList); else n = fprintf(stdout, " %3d %3d %3d %3d", h, k, l, M); if (restriction >= 0) { while (n < 27) { n++; putc(' ', stdout); } n += fprintf(stdout, " %2d/%d", restriction, STBF); } while (n < 34) { n++; putc(' ', stdout); } if (Is_si(SgInfo, h, k, l) == 1) n += fprintf(stdout, " s.i."); while (n < 41) { n++; putc(' ', stdout); } Set_uvw(SgInfo, h, k, l, uvw); for (i = 0; i < SgInfo->n_si_Vector; i++) n += fprintf(stdout, " %3d", uvw[i]); if (SgInfo->LatticeInfo->Code != 'P') { hP = h * CCMx_PL[0] + k * CCMx_PL[3] + l * CCMx_PL[6]; kP = h * CCMx_PL[1] + k * CCMx_PL[4] + l * CCMx_PL[7]; lP = h * CCMx_PL[2] + k * CCMx_PL[5] + l * CCMx_PL[8]; if (hP % deterCCMx_LP || kP % deterCCMx_LP || lP % deterCCMx_LP) goto ReturnError; hP /= deterCCMx_LP; kP /= deterCCMx_LP; lP /= deterCCMx_LP; while (n < 55) { n++; putc(' ', stdout); } n += fprintf(stdout, " P %3d %3d %3d", hP, kP, lP); } putc('\n', stdout); } else if (ListSysAbsent) fprintf(stdout, "# %3d %3d %3d %3d (%d)\n", h, k, l, M, iList); } fprintf(stdout, ">End hklList\n"); return; ReturnError: SetSgError("Internal Error: Simple_hklList()"); return; }
int main (int argc, char *argv[]){ if (argc != 2){ printf("Give a parameter file.\n"); exit(1); } int SpaceGrp; double LatC[6], wl, Lsd, MaxRingRad; char *ParamFN; FILE *fileParam; ParamFN = argv[1]; char aline[1000]; fileParam = fopen(ParamFN,"r"); char *str, dummy[1000]; int LowNr; while (fgets(aline,1000,fileParam)!=NULL){ str = "SpaceGroup "; LowNr = strncmp(aline,str,strlen(str)); if (LowNr==0){ sscanf(aline,"%s %d", dummy, &SpaceGrp); continue; } str = "LatticeConstant "; LowNr = strncmp(aline,str,strlen(str)); if (LowNr==0){ sscanf(aline,"%s %lf %lf %lf %lf %lf %lf", dummy, &LatC[0], &LatC[1], &LatC[2], &LatC[3], &LatC[4], &LatC[5]); continue; } str = "LatticeParameter "; LowNr = strncmp(aline,str,strlen(str)); if (LowNr==0){ sscanf(aline,"%s %lf %lf %lf %lf %lf %lf", dummy, &LatC[0], &LatC[1], &LatC[2], &LatC[3], &LatC[4], &LatC[5]); continue; } str = "Wavelength "; LowNr = strncmp(aline,str,strlen(str)); if (LowNr==0){ sscanf(aline,"%s %lf", dummy, &wl); continue; } str = "Lsd "; LowNr = strncmp(aline,str,strlen(str)); if (LowNr==0){ sscanf(aline,"%s %lf", dummy, &Lsd); continue; } str = "MaxRingRad "; LowNr = strncmp(aline,str,strlen(str)); if (LowNr==0){ sscanf(aline,"%s %lf", dummy, &MaxRingRad); continue; } } printf("%f %f %f %d %f %f %f %f %f %f\n",wl,Lsd,MaxRingRad,SpaceGrp,LatC[0],LatC[1],LatC[2],LatC[3],LatC[4],LatC[5]); int h, k, l, iList, restriction, M, i, j; int Minh, Mink, Minl; int CCMx_PL[9], deterCCMx_LP = 0; double Epsilon = 0.0001; int Families[50000][3]; T_SgInfo *SgInfo; char SgName[200]; int F_Convention='A'; const T_TabSgName *tsgn; printf("Generating hkl's\n"); if((SgInfo = (T_SgInfo *)malloc(sizeof(T_SgInfo)))==NULL){ printf("Unable to allocate SgInfo\n"); printf("Aborting\n"); exit(1); } SgInfo->GenOption = 0; SgInfo->MaxList = 192; if((SgInfo->ListSeitzMx = (T_RTMx*)malloc(SgInfo->MaxList * sizeof(T_RTMx)))==NULL){ printf("Unable to allocate (SgInfo.ListSeitzMx\n"); printf("Aborting\n"); exit(1); } SgInfo->ListRotMxInfo = NULL; InitSgInfo(SgInfo); sprintf(SgName,"%d",SpaceGrp); tsgn = FindTabSgNameEntry(SgName, F_Convention); if (tsgn == NULL){ printf("Error: Unknown Space Group Symbol\n"); printf("Aborting\n"); exit(1); } sprintf(SgName,"%s",tsgn->HallSymbol); SgInfo->TabSgName = tsgn; if (tsgn) SgInfo->GenOption = 1; { int pos_hsym; pos_hsym = ParseHallSymbol(SgName, SgInfo); if (SgError != NULL) { printf("Error: Unknown Space Group Symbol\n"); printf("Aborting\n"); exit(1); } } if(CompleteSgInfo(SgInfo)!=0) { printf("Error in Complete\n"); printf("Aborting\n"); exit(1); } if (SgInfo->LatticeInfo->Code != 'P') { deterCCMx_LP = deterRotMx(SgInfo->CCMx_LP); InverseRotMx(SgInfo->CCMx_LP, CCMx_PL); if (deterCCMx_LP < 1) { printf("deterCMM failed.\n"); return 0; } } int Maxh, Maxk, Maxl; int nrFilled=0; Maxh = 10; Maxk = 10; Maxl = 10; SetListMin_hkl(SgInfo, Maxk, Maxl, &Minh, &Mink, &Minl); printf("Will go from %d to %d in h; %d to %d in k; %d to %d in l.\n",Minh, Maxh, Mink, Maxk, Minl, Maxl); for (h = Minh; h <= Maxh; h++){ for (k = Mink; k <= Maxk; k++){ for (l = Minl; l <= Maxl; l++){ if (h==0 && k==0 && l==0){ continue; } iList = IsSysAbsent_hkl(SgInfo, h, k, l, &restriction); if (SgError != NULL) { printf("IsSysAbsent_hkl failed.\n"); return 0; } if (iList == 0){ if ((iList = IsSuppressed_hkl(SgInfo, Minh, Mink, Minl, Maxk, Maxl, h, k, l)) != 0) {/* Suppressed reflections */ } else { //printf("New plane.\n"); T_Eq_hkl Eq_hkl; M = BuildEq_hkl(SgInfo, &Eq_hkl, h, k, l); if (SgError != NULL){ return 0; } for (i=0;i<Eq_hkl.N;i++){ for (j=-1;j<=1;j+=2){ //printf("%d %d %d\n",Eq_hkl.h[i]*j,Eq_hkl.k[i]*j,Eq_hkl.l[i]*j); Families[nrFilled][0] = Eq_hkl.h[i]*j; Families[nrFilled][1] = Eq_hkl.k[i]*j; Families[nrFilled][2] = Eq_hkl.l[i]*j; nrFilled++; } } } } } } } int AreDuplicates[50000]; double **UniquePlanes; UniquePlanes = allocMatrix(50000,3); for (i=0;i<50000;i++) AreDuplicates[i] = 0; int nrPlanes=0; for (i=0;i<nrFilled-1;i++){ if (AreDuplicates[i] == 1){ continue; } for (j=i+1;j<nrFilled;j++){ if (Families[i][0] == Families[j][0] && Families[i][1] == Families[j][1] && Families[i][2] == Families[j][2] && AreDuplicates[j] == 0){ AreDuplicates[j] = 1; } } UniquePlanes[nrPlanes][0] = (double)Families[i][0]; UniquePlanes[nrPlanes][1] = (double)Families[i][1]; UniquePlanes[nrPlanes][2] = (double)Families[i][2]; nrPlanes++; } double **hkls; hkls = allocMatrix(nrPlanes,12); CorrectHKLsLatC(LatC,UniquePlanes,nrPlanes,hkls); SortFunc(nrPlanes,11,hkls,3,-1); double DsMin = wl/(2*sind((atand(MaxRingRad/Lsd))/2)); for (i=0;i<nrPlanes;i++){ if (hkls[i][3] < DsMin){ nrPlanes = i; break; } } int RingNr = 1; double DsTemp = hkls[0][3]; hkls[0][4] = 1; hkls[0][8] = asind(wl/(2*(hkls[0][3]))); hkls[0][9] = hkls[0][8]*2; hkls[0][10] = Lsd*tand(hkls[0][9]); for (i=1;i<nrPlanes;i++){ if (fabs(hkls[i][3] - DsTemp) < Epsilon){ hkls[i][4] = RingNr; }else{ DsTemp = hkls[i][3]; RingNr++; hkls[i][4] = RingNr; } hkls[i][8] = asind(wl/(2*(hkls[i][3]))); hkls[i][9] = hkls[i][8]*2; hkls[i][10] = Lsd*tand(hkls[i][9]); } char *fn = "hkls.csv"; FILE *fp; fp = fopen(fn,"w"); fprintf(fp,"h k l D-spacing RingNr\n"); for (i=0;i<nrPlanes;i++){ fprintf(fp,"%.0f %.0f %.0f %f %.0f %f %f %f %f %f %f\n",hkls[i][0], hkls[i][1],hkls[i][2],hkls[i][3],hkls[i][4], hkls[i][5],hkls[i][6],hkls[i][7],hkls[i][8], hkls[i][9],hkls[i][10]); } }