tau_square=moldyn->tau_square;
for(i=0;i<count;i++) {
+ /* check whether fixed atom */
+ if(atom[i].attr&ATOM_ATTR_FP)
+ continue;
/* new positions */
h=0.5/atom[i].mass;
v3_scale(&delta,&(atom[i].v),tau);
potential_force_calc(moldyn);
for(i=0;i<count;i++) {
+ /* check whether fixed atom */
+ if(atom[i].attr&ATOM_ATTR_FP)
+ continue;
/* again velocities [actually v(t+tau)] */
v3_scale(&delta,&(atom[i].f),0.5*tau/atom[i].mass);
v3_add(&(atom[i].v),&(atom[i].v),&delta);
//printf("\nATOM 0: %f %f %f\n\n",itom->f.x,itom->f.y,itom->f.z);
if(moldyn->time>DSTART&&moldyn->time<DEND) {
printf("force:\n");
- printf(" x: %0.40f\n",moldyn->atom[5832].f.x);
- printf(" y: %0.40f\n",moldyn->atom[5832].f.y);
- printf(" z: %0.40f\n",moldyn->atom[5832].f.z);
+ printf(" x: %0.40f\n",moldyn->atom[DATOM].f.x);
+ printf(" y: %0.40f\n",moldyn->atom[DATOM].f.y);
+ printf(" z: %0.40f\n",moldyn->atom[DATOM].f.z);
}
#endif
int fd;
int cnt,size;
+ int fsize;
+ int corr;
fd=open(file,O_RDONLY);
if(fd<0) {
return fd;
}
+ fsize=lseek(fd,0,SEEK_END);
+ lseek(fd,0,SEEK_SET);
+
size=sizeof(t_moldyn);
while(size) {
size=moldyn->count*sizeof(t_atom);
+ /* correcting possible atom data offset */
+ corr=0;
+ if(fsize!=sizeof(t_moldyn)+size) {
+ corr=fsize-sizeof(t_moldyn)-size;
+ printf("[moldyn] WARNING: lsf (illegal file size)\n");
+ printf(" moifying offset:\n");
+ printf(" - current pos: %d\n",sizeof(t_moldyn));
+ printf(" - atom size: %d\n",size);
+ printf(" - file size: %d\n",fsize);
+ printf(" => correction: %d\n",corr);
+ lseek(fd,corr,SEEK_CUR);
+ }
+
moldyn->atom=(t_atom *)malloc(size);
if(moldyn->atom==NULL) {
perror("[moldyn] load save file malloc (atoms)");
return 0;
}
+int calculate_diffusion_coefficient(t_moldyn *moldyn,double *dc) {
+
+ int i;
+ t_atom *atom;
+ t_3dvec dist;
+ double d2;
+ int a_cnt;
+ int b_cnt;
+
+ atom=moldyn->atom;
+ dc[0]=0;
+ dc[1]=0;
+ dc[2]=0;
+ a_cnt=0;
+ b_cnt=0;
+
+ for(i=0;i<moldyn->count;i++) {
+
+ v3_sub(&dist,&(atom[i].r),&(atom[i].r_0));
+ check_per_bound(moldyn,&dist);
+ d2=v3_absolute_square(&dist);
+
+ if(atom[i].brand) {
+ b_cnt+=1;
+ dc[1]+=d2;
+ }
+ else {
+ a_cnt+=1;
+ dc[0]+=d2;
+ }
+
+ dc[2]+=d2;
+ }
+
+ dc[0]*=(1.0/(6.0*moldyn->time*a_cnt));
+ dc[1]*=(1.0/(6.0*moldyn->time*b_cnt));
+ dc[2]*=(1.0/(6.0*moldyn->time*moldyn->count));
+
+ return 0;
+}
+
int calculate_pair_correlation(t_moldyn *moldyn,double dr,void *ptr) {
int slots;
unsigned char bc;
t_3dvec dist;
double d;
- //double norm;
+ double norm;
int o,s;
unsigned char ibrand;
lc=&(moldyn->lc);
- slots=moldyn->cutoff/dr;
+ slots=2.0*moldyn->cutoff/dr;
o=2*slots;
if(slots*dr<=moldyn->cutoff)
d=v3_absolute_square(&dist);
/* ignore if greater or equal cutoff */
- if(d>=moldyn->cutoff_square)
+ if(d>=4.0*moldyn->cutoff_square)
continue;
/* fill the slots */
}
}
- /* normalization
+ /* normalization */
for(i=1;i<slots;i++) {
- // normalization: 4 pi r r dr
+ // normalization: 4 pi r^2 dr
// here: not double counting pairs -> 2 pi r r dr
- norm=2*M_PI*moldyn->count*(i*dr*i*dr)*dr;
+ // ... and actually it's a constant times r^2
+ norm=i*i*dr*dr;
stat[i]/=norm;
stat[slots+i]/=norm;
stat[o+i]/=norm;
}
- */
+ /* */
if(ptr==NULL) {
/* todo: store/print pair correlation function */