4 * author: frank.zirkelbach@physik.uni-augsburg.de
11 #include <sys/types.h>
18 int get_line(int fd,char *line,int max) {
25 if(count==max) return count;
26 ret=read(fd,line+count,1);
27 if(ret<=0) return ret;
28 if(line[count]=='\n') {
29 memset(line+count,0,max-count-1);
38 printf("usage: tXYZp -X,Y,Z <angle> -X,Y,Z <angle> ...\n");
41 int b_transform(char rtype,double angle,double cosangle,double sinangle,
42 double o[3][3],double t[3][3]) {
50 t[i][1]=cosangle*o[i][1]+sinangle*o[i][2];
51 t[i][2]=cosangle*o[i][2]-sinangle*o[i][1];
56 t[i][0]=cosangle*o[i][0]+sinangle*o[i][2];
58 t[i][2]=cosangle*o[i][2]-sinangle*o[i][0];
63 t[i][0]=cosangle*o[i][0]+sinangle*o[i][1];
64 t[i][1]=cosangle*o[i][1]-sinangle*o[i][0];
72 printf("Transformed (%c - %f) basis:\n",rtype,angle);
73 printf(" b1: (%f, %f, %f)\n",t[0][0],t[0][1],t[0][2]);
74 printf(" b2: (%f, %f, %f)\n",t[1][0],t[1][1],t[1][2]);
75 printf(" b3: (%f, %f, %f)\n",t[2][0],t[2][1],t[2][2]);
80 int a_transform(char rtype,double angle,double cosangle,double sinangle,
81 double o[3],double t[3]) {
86 t[1]=cosangle*o[1]-sinangle*o[2];
87 t[2]=cosangle*o[2]+sinangle*o[1];
90 t[0]=cosangle*o[0]-sinangle*o[2];
92 t[2]=cosangle*o[2]+sinangle*o[0];
95 t[0]=cosangle*o[0]-sinangle*o[1];
96 t[1]=cosangle*o[1]+sinangle*o[0];
106 int main(int argc,char **argv) {
119 /* basis in cartesian coordinates */
122 /* transformed basis */
128 memset(angle,0,sizeof(double)*3);
129 memset(rtype,0,sizeof(char)*3);
132 for(i=1;i<argc;i++) {
133 if(argv[i][0]=='-') {
138 rtype[count]=argv[i][1];
139 angle[count]=atof(argv[++i])/180.0*M_PI;
153 printf("\nOperations: ");
156 cosangle[i]=cos(angle[i]);
157 sinangle[i]=sin(angle[i]);
158 printf("%c %f (%d) | ",rtype[i],angle[i]/M_PI*180.0,i);
163 posr=open("POSCAR",O_RDONLY);
165 perror("open POSCAR (read) file\n");
169 snprintf(file,255,"POSCAR.");
172 snprintf(file,255,"%s%c%f",file,rtype[i],angle[i]);
174 poso=open(file,O_WRONLY|O_CREAT);
176 perror("open POSCAR (write) file\n");
181 cnt=get_line(posr,buf,256);
186 cnt=get_line(posr,buf,256);
190 // basis in cartesian coordinates
192 cnt=get_line(posr,buf,256);
195 wptr=strtok(buf," ");
197 wptr=strtok(NULL," ");
203 printf(" b1: (%f, %f, %f)\n",b[0][0],b[0][1],b[0][2]);
204 printf(" b2: (%f, %f, %f)\n",b[1][0],b[1][1],b[1][2]);
205 printf(" b3: (%f, %f, %f)\n",b[2][0],b[2][1],b[2][2]);
211 // B needs to get transformed into B' = ABA^-1
212 // => total: ABA^-1A = AB
213 // => reverse sequence of transformations!
214 for(i=count-1;i>-1;i--) {
217 b_transform(rtype[i],angle[i],
218 cosangle[i],sinangle[i],
221 b_transform(rtype[i],angle[i],
222 cosangle[i],sinangle[i],
228 dprintf(poso," %f %f %f\n",
229 tb[0][i][0],tb[0][i][1],tb[0][i][2]);
232 cnt=get_line(posr,buf,256);
237 cnt=get_line(posr,buf,256);
242 cnt=get_line(posr,buf,256);
247 cnt=get_line(posr,buf,256);
250 wptr=strtok(buf," ");
252 wptr=strtok(NULL," ");
254 wptr=strtok(NULL," ");
257 wptr=strtok(NULL," ");
259 wptr=strtok(NULL," ");
261 wptr=strtok(NULL," ");
269 a_transform(rtype[i],angle[i],
270 cosangle[i],sinangle[i],
275 dprintf(poso," %f %f %f %c %c %c\n",x[0],x[1],x[2],t1,t2,t3);