X-Git-Url: https://hackdaworld.org/gitweb/?p=physik%2Fposic.git;a=blobdiff_plain;f=vasp_tools%2Fpc_calc.c;fp=vasp_tools%2Fpc_calc.c;h=db12f50c6e1a8f70cb758a6f17199a602e92d049;hp=0000000000000000000000000000000000000000;hb=6e6d7126ea9a845f11637d8e1b8eb2b570ac4dc9;hpb=97dc63eb6a519b8e1f4fbfaa9760dd94539436b0 diff --git a/vasp_tools/pc_calc.c b/vasp_tools/pc_calc.c new file mode 100644 index 0000000..db12f50 --- /dev/null +++ b/vasp_tools/pc_calc.c @@ -0,0 +1,276 @@ +/* + * pc_calc.c - calculate the pc + * + * author: frank.zirkelbach@physik.uni-augsburg.de + * + */ + +#include +#include +#include +#include +#include +#include +#include + +#include + + +#define MAXR 6.0 +#define DELTA 0.01 + +typedef struct s_atom { + double x,y,z; + char type; +} t_atom; + +int get_line(int fd,char *line,int max) { + + int count,ret; + + count=0; + + while(1) { + if(count==max) return count; + ret=read(fd,line+count,1); + if(ret<=0) return ret; + if(line[count]=='\n') { + memset(line+count,0,max-count-1); + //line[count]='\0'; + return count+1; + } + count+=1; + } +} + +int get_max3_vals(char *buf,int amount,double *v1, double *v2,double *v3) { + + int i,j,k; + char temp[128]; + + i=0; + + for(k=0;k scale + cnt=get_line(fd,buf,256); + get_max3_vals(buf,1,&scale,NULL,NULL); + printf("scale: %f\n",scale); + + // third line -> X + cnt=get_line(fd,buf,256); + get_max3_vals(buf,3,&X1,&X2,&X3); + printf("X: %f %f %f\n",X1,X2,X3); + + // 4th line -> Y + cnt=get_line(fd,buf,256); + get_max3_vals(buf,3,&Y1,&Y2,&Y3); + printf("Y: %f %f %f\n",Y1,Y2,Y3); + + // 5th line -> Z + cnt=get_line(fd,buf,256); + get_max3_vals(buf,3,&Z1,&Z2,&Z3); + printf("Z: %f %f %f\n",Z1,Z2,Z3); + + // 6th line -> nsi + nc = ntot + cnt=get_line(fd,buf,256); + get_2_ints(buf,&nsi,&nc); + ntot=nsi+nc; + printf("Si: %d - C: %d - tot: %d\n",nsi,nc,ntot); + + // 7th line + cnt=get_line(fd,buf,256); + + // 8th line + cnt=get_line(fd,buf,256); + + // read in atoms + count=0; + while(count0.5) + dx-=1; + else if(dx<-0.5) + dx+=1; + + dy=atom[i].y-atom[j].y; + if(dy>0.5) + dy-=1; + else if(dy<-0.5) + dy+=1; + + dz=atom[i].z-atom[j].z; + if(dz>0.5) + dz-=1; + else if(dz<-0.5) + dz+=1; + + dxt=dx*X1+dy*Y1+dz*Z1; + dyt=dx*X2+dy*Y2+dz*Z2; + dzt=dx*X3+dy*Y3+dz*Z3; + + dist=sqrt(dxt*dxt+dyt*dyt+dzt*dzt); + dist*=scale; + + if(dist>=MAXR) + continue; + k=dist/DELTA; + if((atom[i].type=='S')&&(atom[j].type=='S')) { + aslot[k]+=1; + } + else if((atom[i].type=='C')&&(atom[j].type=='C')) { + bslot[k]+=1; + } + else { + cslot[k]+=1; + } + } + } + + close(fd); + + } + + // normalization and output + for(i=1;i