]> hackdaworld.org Git - physik/posic.git/blob - vasp_tools/create_lattice.c
count spins ...
[physik/posic.git] / vasp_tools / create_lattice.c
1 /*
2  * create lattice (for usage in vasp POSCAR file)
3  *
4  * author: Frank Zirkelbach <frank.zirkelbach@physik.uni-augsburg.de>
5  *
6  */
7
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <string.h>
11 #include <math.h>
12 #include "../math/math.h"
13
14 /*
15  * lattice types:
16  *
17  * there is fcc/diamond/zincblende only!
18  *
19  * basis:
20  *
21  * 0: <0.5 0.5 0> <0 0.5 0.5> <0.5 0 0.5> contains 2 atoms
22  * 1: <0.5 -0.5 0> <0.5 0.5 0> <0 0 1> contains 4 atoms
23  * 2: <1 0 0> <0 1 0> <0 0 1> contains 8 atoms
24  *
25  * atoms:
26  *
27  * - type 0:
28  *   1st fcc: <0 0 0>
29  *   2nd fcc: <0.25 0.25 0.25>
30  *   -> diag: <0.25 0.25 0.25>
31  *
32  * - type 1:
33  *   1st fcc: <0 0 0> <0.5 0.5 0.5>
34  *   2nd fcc: <0.5 0 0.25> <1.0 or 0.0 0.5 0.75>
35      -> diag: <0.5 0 0.25>
36  *
37  * - type 2:
38  *   1st fcc: <0 0 0> <0.5 0.5 0> <0.5 0 0.5> <0 0.5 0.5>
39  *   2nd fcc: <0.25 0.25 0.25> <0.75 0.75 0.25> <0.75 0.25 0.75>
40  *            <0.25 0.75 0.75>
41  *   -> diag: <0.25 0.25 0.25>
42  *
43  */
44
45 int main(int argc,char **argv) {
46
47         int i,j,k,l,cnt,estimated;
48         int x,y,z;
49         t_3dvec basis[3];
50         t_3dvec o[3];
51         t_3dvec dia;
52         t_3dvec r,h;
53         char type,fccdia,foa,fixstr[6];
54
55         if(argc<6) {
56                 printf("usage: %s type fcc/dia lx ly lz\n",argv[0]);
57                 printf("  basis types: 0, 1, 2 (see code)\n");
58                 printf("  fcc/dia: 0=fcc, 1=dia\n");
59                 printf(" optional: foa (fix outer atoms)\n");
60                 return -1;
61         }
62
63         type=argv[1][0];
64         fccdia=argv[2][0];
65
66         x=atoi(argv[3]);
67         y=atoi(argv[4]);
68         z=atoi(argv[5]);
69
70         foa=0;
71         if(argc==7)
72                 foa=1;
73
74         dia.x=0.25;
75         dia.y=0.25;
76         dia.z=0.25;
77
78         if(type=='1') {
79                 dia.x=0.0;
80                 dia.y=0.5;
81                 dia.z=0.25;
82         }
83
84         memset(basis,0,3*sizeof(t_3dvec));
85         memset(o,0,3*sizeof(t_3dvec));
86
87         if(type=='0') {
88                 basis[0].x=0.5;
89                 basis[0].y=0.5;
90                 basis[1].y=0.5;
91                 basis[1].z=0.5;
92                 basis[2].x=0.5;
93                 basis[2].z=0.5;
94         }
95
96         if(type=='1') {
97                 basis[0].x=0.5;
98                 basis[0].y=-0.5;
99                 basis[1].x=0.5;
100                 basis[1].y=0.5;
101                 basis[2].z=1.0;
102                 o[0].x=0.5;
103                 o[0].y=0.5;
104                 o[0].z=0.5;
105         }
106
107         if(type=='2') {
108                 basis[0].x=1.0;
109                 basis[1].y=1.0;
110                 basis[2].z=1.0;
111                 o[0].x=0.5;
112                 o[0].y=0.5;
113                 o[1].x=0.5;
114                 o[1].z=0.5;
115                 o[2].y=0.5;
116                 o[2].z=0.5;
117         }
118
119         cnt=0;
120
121         estimated=1;
122         if(fccdia=='1') estimated*=2;
123         if(type=='1') estimated*=2;
124         if(type=='2') estimated*=4;
125         estimated*=x*y*z;
126
127         // print POSCAR 'header'
128
129         printf("cubic diamond\n");
130         printf(" 5.429\n");
131
132         v3_scale(&h,&basis[0],x);
133         printf(" %.5f %.5f %.5f\n",h.x,h.y,h.z);
134         v3_scale(&h,&basis[1],y);
135         printf(" %.5f %.5f %.5f\n",h.x,h.y,h.z);
136         v3_scale(&h,&basis[2],z);
137         printf(" %.5f %.5f %.5f\n",h.x,h.y,h.z);
138
139         printf(" %d\n",estimated);
140         printf("selective dynamics\n");
141         printf("direct\n");
142
143         // now print the coordinates
144         
145         for(i=0;i<x;i++) {
146                 for(j=0;j<y;j++) {
147                         for(k=0;k<z;k++) {
148
149         // first atom (all types)
150         r.x=i;
151         r.y=j;
152         r.z=k;
153
154         strcpy(fixstr,"T T T");
155         if(((r.x==0)||(r.y==0)||(r.z==0))&foa)
156                 strcpy(fixstr,"F F F");
157         printf(" %.5f %.5f %.5f %s\n",r.x/x,r.y/y,r.z/z,fixstr);
158         cnt+=1;
159
160         // second atom (type 1)
161         if(type=='1') {
162                 v3_add(&h,&r,&(o[0]));
163                 strcpy(fixstr,"T T T");
164                 if(((h.x==0)||(h.y==0)||(h.z==0))&foa)
165                         strcpy(fixstr,"F F F");
166                 printf(" %.5f %.5f %.5f T T T\n",h.x/x,h.y/y,h.z/z);
167                 cnt+=1;
168         }
169
170         // face centered atoms (type 2)
171         if(type=='2') {
172                 for(l=0;l<3;l++) {
173                         v3_add(&h,&r,&(o[l]));
174                         strcpy(fixstr,"T T T");
175                         if(((h.x==0)||(h.y==0)||(h.z==0))&foa)
176                                 strcpy(fixstr,"F F F");
177                         printf(" %.5f %.5f %.5f T T T\n",h.x/x,h.y/y,h.z/z);
178                         cnt+=1;
179                 }
180         }
181
182                         }
183                 }
184         }
185
186         // second fcc lattice
187         if(fccdia=='1') {
188
189         for(i=0;i<x;i++) {
190                 for(j=0;j<y;j++) {
191                         for(k=0;k<z;k++) {
192
193         // first atom (all types)
194         r.x=i;
195         r.y=j;
196         r.z=k;
197
198         // add the diagonal
199         v3_add(&r,&r,&dia);
200         
201         strcpy(fixstr,"T T T");
202         if(((r.x==0)||(r.y==0)||(r.z==0))&foa)
203                 strcpy(fixstr,"F F F");
204         printf(" %.5f %.5f %.5f T T T\n",r.x/x,r.y/y,r.z/z);
205         cnt+=1;
206
207         // second atom (type 1)
208         if(type=='1') {
209                 v3_add(&h,&r,&(o[0]));
210                 strcpy(fixstr,"T T T");
211                 if(((h.x==0)||(h.y==0)||(h.z==0))&foa)
212                         strcpy(fixstr,"F F F");
213                 printf(" %.5f %.5f %.5f T T T\n",h.x/x,h.y/y,h.z/z);
214                 cnt+=1;
215         }
216
217         // face centered atoms (type 2)
218         if(type=='2') {
219                 for(l=0;l<3;l++) {
220                         v3_add(&h,&r,&(o[l]));
221                         strcpy(fixstr,"T T T");
222                         if(((h.x==0)||(h.y==0)||(h.z==0))&foa)
223                                 strcpy(fixstr,"F F F");
224                         printf(" %.5f %.5f %.5f T T T\n",h.x/x,h.y/y,h.z/z);
225                         cnt+=1;
226                 }
227         }
228
229                         }
230                 }
231         }
232
233
234         }
235
236
237         if(estimated!=cnt) {
238                 printf("\nWARNING! counted %d ions and estimated %d ions\n\n",
239                        cnt,estimated);
240         }
241
242         return 0;
243 }