+/* fcc lattice init */
+int fcc_init(int a,int b,int c,double lc,t_atom *atom,t_3dvec *origin) {
+
+ int count;
+ int i,j;
+ t_3dvec o,r,n;
+ t_3dvec basis[3];
+ double help[3];
+ double x,y,z;
+
+ x=a*lc;
+ y=b*lc;
+ z=c*lc;
+
+ if(origin) v3_copy(&o,origin);
+ else v3_zero(&o);
+
+ /* construct the basis */
+ for(i=0;i<3;i++) {
+ for(j=0;j<3;j++) {
+ if(i!=j) help[j]=0.5*lc;
+ else help[j]=.0;
+ }
+ v3_set(&basis[i],help);
+ }
+
+ v3_zero(&r);
+ count=0;
+
+ /* fill up the room */
+ r.x=o.x;
+ while(r.x<x) {
+ r.y=o.y;
+ while(r.y<y) {
+ r.z=o.z;
+ while(r.z<z) {
+ v3_copy(&(atom[count].r),&r);
+ atom[count].element=1;
+ count+=1;
+ for(i=0;i<3;i++) {
+ v3_add(&n,&r,&basis[i]);
+ if((n.x<x+o.x)&&
+ (n.y<y+o.y)&&
+ (n.z<z+o.z)) {
+ v3_copy(&(atom[count].r),&n);
+ count+=1;
+ }
+ }
+ r.z+=lc;
+ }
+ r.y+=lc;
+ }
+ r.x+=lc;
+ }
+
+ /* coordinate transformation */
+ help[0]=x/2.0;
+ help[1]=y/2.0;
+ help[2]=z/2.0;
+ v3_set(&n,help);
+ for(i=0;i<count;i++)
+ v3_sub(&(atom[i].r),&(atom[i].r),&n);
+
+ return count;
+}
+
+int diamond_init(int a,int b,int c,double lc,t_atom *atom,t_3dvec *origin) {
+
+ int count;
+ t_3dvec o;
+
+ count=fcc_init(a,b,c,lc,atom,origin);
+
+ o.x=0.25*lc;
+ o.y=0.25*lc;
+ o.z=0.25*lc;
+
+ if(origin) v3_add(&o,&o,origin);
+
+ count+=fcc_init(a,b,c,lc,&atom[count],&o);
+
+ return count;
+}
+