2 * moldyn.c - molecular dynamics library main file
4 * author: Frank Zirkelbach <frank.zirkelbach@physik.uni-augsburg.de>
12 #include <sys/types.h>
20 int moldyn_init(t_moldyn *moldyn,int argc,char **argv) {
22 memset(moldyn,0,sizeof(t_moldyn));
24 rand_init(&(moldyn->random),NULL,1);
25 moldyn->random.status|=RAND_STAT_VERBOSE;
30 int moldyn_shutdown(t_moldyn *moldyn) {
32 printf("[moldyn] shutdown\n");
33 moldyn_log_shutdown(moldyn);
34 link_cell_shutdown(moldyn);
35 rand_close(&(moldyn->random));
41 int set_int_alg(t_moldyn *moldyn,u8 algo) {
44 case MOLDYN_INTEGRATE_VERLET:
45 moldyn->integrate=velocity_verlet;
48 printf("unknown integration algorithm: %02x\n",algo);
55 int set_cutoff(t_moldyn *moldyn,double cutoff) {
57 moldyn->cutoff=cutoff;
62 int set_temperature(t_moldyn *moldyn,double t_ref) {
69 int set_pressure(t_moldyn *moldyn,double p_ref) {
76 int set_pt_scale(t_moldyn *moldyn,u8 ptype,double ptc,u8 ttype,double ttc) {
78 moldyn->pt_scale=(ptype|ttype);
85 int set_dim(t_moldyn *moldyn,double x,double y,double z,u8 visualize) {
99 printf("[moldyn] dimensions in A and A^3 respectively:\n");
100 printf(" x: %f\n",moldyn->dim.x);
101 printf(" y: %f\n",moldyn->dim.y);
102 printf(" z: %f\n",moldyn->dim.z);
103 printf(" volume: %f\n",moldyn->volume);
104 printf(" visualize simulation box: %s\n",visualize?"on":"off");
109 int set_nn_dist(t_moldyn *moldyn,double dist) {
116 int set_pbc(t_moldyn *moldyn,u8 x,u8 y,u8 z) {
119 moldyn->status|=MOLDYN_STAT_PBX;
122 moldyn->status|=MOLDYN_STAT_PBY;
125 moldyn->status|=MOLDYN_STAT_PBZ;
130 int set_potential1b(t_moldyn *moldyn,pf_func1b func,void *params) {
133 moldyn->pot1b_params=params;
138 int set_potential2b(t_moldyn *moldyn,pf_func2b func,void *params) {
141 moldyn->pot2b_params=params;
146 int set_potential2b_post(t_moldyn *moldyn,pf_func2b_post func,void *params) {
148 moldyn->func2b_post=func;
149 moldyn->pot2b_params=params;
154 int set_potential3b(t_moldyn *moldyn,pf_func3b func,void *params) {
157 moldyn->pot3b_params=params;
162 int moldyn_set_log_dir(t_moldyn *moldyn,char *dir) {
164 strncpy(moldyn->vlsdir,dir,127);
169 int moldyn_set_log(t_moldyn *moldyn,u8 type,int timer) {
175 case LOG_TOTAL_ENERGY:
176 moldyn->ewrite=timer;
177 snprintf(filename,127,"%s/energy",moldyn->vlsdir);
178 moldyn->efd=open(filename,
179 O_WRONLY|O_CREAT|O_EXCL,
182 perror("[moldyn] energy log fd open");
185 dprintf(moldyn->efd,"# total energy log file\n");
187 case LOG_TOTAL_MOMENTUM:
188 moldyn->mwrite=timer;
189 snprintf(filename,127,"%s/momentum",moldyn->vlsdir);
190 moldyn->mfd=open(filename,
191 O_WRONLY|O_CREAT|O_EXCL,
194 perror("[moldyn] momentum log fd open");
197 dprintf(moldyn->efd,"# total momentum log file\n");
200 moldyn->swrite=timer;
203 moldyn->vwrite=timer;
204 ret=visual_init(&(moldyn->vis),moldyn->vlsdir);
206 printf("[moldyn] visual init failure\n");
211 printf("[moldyn] unknown log mechanism: %02x\n",type);
218 int moldyn_log_shutdown(t_moldyn *moldyn) {
220 printf("[moldyn] log shutdown\n");
221 if(moldyn->efd) close(moldyn->efd);
222 if(moldyn->mfd) close(moldyn->mfd);
223 if(&(moldyn->vis)) visual_tini(&(moldyn->vis));
229 * creating lattice functions
232 int create_lattice(t_moldyn *moldyn,u8 type,double lc,int element,double mass,
233 u8 attr,u8 brand,int a,int b,int c) {
244 /* how many atoms do we expect */
245 if(type==FCC) new*=4;
246 if(type==DIAMOND) new*=8;
248 /* allocate space for atoms */
249 ptr=realloc(moldyn->atom,(count+new)*sizeof(t_atom));
251 perror("[moldyn] realloc (create lattice)");
255 atom=&(moldyn->atom[count]);
261 ret=fcc_init(a,b,c,lc,atom,&origin);
264 ret=diamond_init(a,b,c,lc,atom,&origin);
267 printf("unknown lattice type (%02x)\n",type);
273 printf("[moldyn] creating lattice failed\n");
274 printf(" amount of atoms\n");
275 printf(" - expected: %d\n",new);
276 printf(" - created: %d\n",ret);
281 printf("[moldyn] created lattice with %d atoms\n",new);
283 for(ret=0;ret<new;ret++) {
284 atom[ret].element=element;
287 atom[ret].brand=brand;
288 atom[ret].tag=count+ret;
289 check_per_bound(moldyn,&(atom[ret].r));
295 /* fcc lattice init */
296 int fcc_init(int a,int b,int c,double lc,t_atom *atom,t_3dvec *origin) {
309 if(origin) v3_copy(&o,origin);
312 /* construct the basis */
315 if(i!=j) help[j]=0.5*lc;
318 v3_set(&basis[i],help);
324 /* fill up the room */
331 v3_copy(&(atom[count].r),&r);
332 atom[count].element=1;
335 v3_add(&n,&r,&basis[i]);
339 v3_copy(&(atom[count].r),&n);
350 /* coordinate transformation */
356 v3_sub(&(atom[i].r),&(atom[i].r),&n);
361 int diamond_init(int a,int b,int c,double lc,t_atom *atom,t_3dvec *origin) {
366 count=fcc_init(a,b,c,lc,atom,origin);
372 if(origin) v3_add(&o,&o,origin);
374 count+=fcc_init(a,b,c,lc,&atom[count],&o);
379 int add_atom(t_moldyn *moldyn,int element,double mass,u8 brand,u8 attr,
380 t_3dvec *r,t_3dvec *v) {
387 count=(moldyn->count)++;
389 ptr=realloc(atom,(count+1)*sizeof(t_atom));
391 perror("[moldyn] realloc (add atom)");
399 atom[count].element=element;
400 atom[count].mass=mass;
401 atom[count].brand=brand;
402 atom[count].tag=count;
403 atom[count].attr=attr;
408 int destroy_atoms(t_moldyn *moldyn) {
410 if(moldyn->atom) free(moldyn->atom);
415 int thermal_init(t_moldyn *moldyn,u8 equi_init) {
418 * - gaussian distribution of velocities
419 * - zero total momentum
420 * - velocity scaling (E = 3/2 N k T), E: kinetic energy
425 t_3dvec p_total,delta;
430 random=&(moldyn->random);
432 /* gaussian distribution of velocities */
434 for(i=0;i<moldyn->count;i++) {
435 sigma=sqrt(2.0*K_BOLTZMANN*moldyn->t_ref/atom[i].mass);
437 v=sigma*rand_get_gauss(random);
439 p_total.x+=atom[i].mass*v;
441 v=sigma*rand_get_gauss(random);
443 p_total.y+=atom[i].mass*v;
445 v=sigma*rand_get_gauss(random);
447 p_total.z+=atom[i].mass*v;
450 /* zero total momentum */
451 v3_scale(&p_total,&p_total,1.0/moldyn->count);
452 for(i=0;i<moldyn->count;i++) {
453 v3_scale(&delta,&p_total,1.0/atom[i].mass);
454 v3_sub(&(atom[i].v),&(atom[i].v),&delta);
457 /* velocity scaling */
458 scale_velocity(moldyn,equi_init);
463 double temperature_calc(t_moldyn *moldyn) {
471 for(i=0;i<moldyn->count;i++)
472 double_ekin+=atom[i].mass*v3_absolute_square(&(atom[i].v));
474 /* kinetic energy = 3/2 N k_B T */
475 moldyn->t=double_ekin/(3.0*K_BOLTZMANN*moldyn->count);
480 double get_temperature(t_moldyn *moldyn) {
485 int scale_velocity(t_moldyn *moldyn,u8 equi_init) {
495 * - velocity scaling (E = 3/2 N k T), E: kinetic energy
498 /* get kinetic energy / temperature & count involved atoms */
501 for(i=0;i<moldyn->count;i++) {
502 if((equi_init&TRUE)||(atom[i].attr&ATOM_ATTR_HB)) {
503 e+=atom[i].mass*v3_absolute_square(&(atom[i].v));
508 if(count!=0) moldyn->t=e/(1.5*count*K_BOLTZMANN);
509 else return 0; /* no atoms involved in scaling! */
511 /* (temporary) hack for e,t = 0 */
514 if(moldyn->t_ref!=0.0) {
515 thermal_init(moldyn,equi_init);
519 return 0; /* no scaling needed */
523 /* get scaling factor */
524 scale=moldyn->t_ref/moldyn->t;
528 if(moldyn->pt_scale&T_SCALE_BERENDSEN)
529 scale=1.0+(scale-1.0)/moldyn->t_tc;
532 /* velocity scaling */
533 for(i=0;i<moldyn->count;i++) {
534 if((equi_init&TRUE)||(atom[i].attr&ATOM_ATTR_HB))
535 v3_scale(&(atom[i].v),&(atom[i].v),scale);
541 double pressure_calc(t_moldyn *moldyn) {
547 for(i=0;i<moldyn->count;i++) {
552 p1=(moldyn->count*K_BOLTZMANN*moldyn->t-ONE_THIRD*moldyn->vt1);
555 p2=(moldyn->count*K_BOLTZMANN*moldyn->t-ONE_THIRD*moldyn->vt2);
558 printf("compare pressures: %f %f\n",p1/ATM,p2/ATM);
563 double get_pressure(t_moldyn *moldyn) {
569 int scale_volume(t_moldyn *moldyn) {
580 vdim=&(moldyn->vis.dim);
583 memset(&virial,0,sizeof(t_virial));
585 for(i=0;i<moldyn->count;i++) {
586 virial.xx+=atom[i].virial.xx;
587 virial.yy+=atom[i].virial.yy;
588 virial.zz+=atom[i].virial.zz;
589 virial.xy+=atom[i].virial.xy;
590 virial.xz+=atom[i].virial.xz;
591 virial.yz+=atom[i].virial.yz;
594 /* just a guess so far ... */
595 v=virial.xx+virial.yy+virial.zz;
598 /* get pressure from virial */
599 moldyn->p=moldyn->count*K_BOLTZMANN*moldyn->t+ONE_THIRD*v;
600 moldyn->p/=moldyn->volume;
601 printf("%f | %f\n",moldyn->p/(ATM),moldyn->p_ref/ATM);
604 if(moldyn->pt_scale&P_SCALE_BERENDSEN)
605 scale=3*sqrt(1-(moldyn->p_ref-moldyn->p)/moldyn->p_tc);
607 /* should actually never be used */
608 scale=pow(moldyn->p/moldyn->p_ref,1.0/3.0);
610 printf("scale = %f\n",scale);
615 if(vdim->x) vdim->x=dim->x;
616 if(vdim->y) vdim->y=dim->y;
617 if(vdim->z) vdim->z=dim->z;
618 moldyn->volume*=(scale*scale*scale);
620 /* check whether we need a new linkcell init */
621 if((dim->x/moldyn->cutoff!=lc->nx)||
622 (dim->y/moldyn->cutoff!=lc->ny)||
623 (dim->z/moldyn->cutoff!=lc->nx)) {
624 link_cell_shutdown(moldyn);
625 link_cell_init(moldyn);
632 double get_e_kin(t_moldyn *moldyn) {
640 for(i=0;i<moldyn->count;i++)
641 moldyn->ekin+=0.5*atom[i].mass*v3_absolute_square(&(atom[i].v));
646 double update_e_kin(t_moldyn *moldyn) {
648 return(get_e_kin(moldyn));
651 double get_total_energy(t_moldyn *moldyn) {
653 return(moldyn->ekin+moldyn->energy);
656 t_3dvec get_total_p(t_moldyn *moldyn) {
665 for(i=0;i<moldyn->count;i++) {
666 v3_scale(&p,&(atom[i].v),atom[i].mass);
667 v3_add(&p_total,&p_total,&p);
673 double estimate_time_step(t_moldyn *moldyn,double nn_dist) {
677 /* nn_dist is the nearest neighbour distance */
679 tau=(0.05*nn_dist*moldyn->atom[0].mass)/sqrt(3.0*K_BOLTZMANN*moldyn->t);
688 /* linked list / cell method */
690 int link_cell_init(t_moldyn *moldyn) {
697 /* partitioning the md cell */
698 lc->nx=moldyn->dim.x/moldyn->cutoff;
699 lc->x=moldyn->dim.x/lc->nx;
700 lc->ny=moldyn->dim.y/moldyn->cutoff;
701 lc->y=moldyn->dim.y/lc->ny;
702 lc->nz=moldyn->dim.z/moldyn->cutoff;
703 lc->z=moldyn->dim.z/lc->nz;
705 lc->cells=lc->nx*lc->ny*lc->nz;
706 lc->subcell=malloc(lc->cells*sizeof(t_list));
709 printf("[moldyn] FATAL: less then 27 subcells!\n");
711 printf("[moldyn] initializing linked cells (%d)\n",lc->cells);
713 for(i=0;i<lc->cells;i++)
714 list_init_f(&(lc->subcell[i]));
716 link_cell_update(moldyn);
721 int link_cell_update(t_moldyn *moldyn) {
739 for(i=0;i<lc->cells;i++)
740 list_destroy_f(&(lc->subcell[i]));
742 for(count=0;count<moldyn->count;count++) {
743 i=((atom[count].r.x+(moldyn->dim.x/2))/lc->x);
744 j=((atom[count].r.y+(moldyn->dim.y/2))/lc->y);
745 k=((atom[count].r.z+(moldyn->dim.z/2))/lc->z);
746 list_add_immediate_f(&(moldyn->lc.subcell[i+j*nx+k*nx*ny]),
753 int link_cell_neighbour_index(t_moldyn *moldyn,int i,int j,int k,t_list *cell) {
771 cell[0]=lc->subcell[i+j*nx+k*a];
772 for(ci=-1;ci<=1;ci++) {
779 for(cj=-1;cj<=1;cj++) {
786 for(ck=-1;ck<=1;ck++) {
793 if(!(ci|cj|ck)) continue;
795 cell[--count2]=lc->subcell[x+y*nx+z*a];
798 cell[count1++]=lc->subcell[x+y*nx+z*a];
809 int link_cell_shutdown(t_moldyn *moldyn) {
816 for(i=0;i<lc->nx*lc->ny*lc->nz;i++)
817 list_destroy_f(&(moldyn->lc.subcell[i]));
824 int moldyn_add_schedule(t_moldyn *moldyn,int runs,double tau) {
828 t_moldyn_schedule *schedule;
830 schedule=&(moldyn->schedule);
831 count=++(schedule->total_sched);
833 ptr=realloc(schedule->runs,count*sizeof(int));
835 perror("[moldyn] realloc (runs)");
839 schedule->runs[count-1]=runs;
841 ptr=realloc(schedule->tau,count*sizeof(double));
843 perror("[moldyn] realloc (tau)");
847 schedule->tau[count-1]=tau;
852 int moldyn_set_schedule_hook(t_moldyn *moldyn,void *hook,void *hook_params) {
854 moldyn->schedule.hook=hook;
855 moldyn->schedule.hook_params=hook_params;
862 * 'integration of newtons equation' - algorithms
866 /* start the integration */
868 int moldyn_integrate(t_moldyn *moldyn) {
871 unsigned int e,m,s,v;
873 t_moldyn_schedule *sched;
879 sched=&(moldyn->schedule);
882 /* initialize linked cell method */
883 link_cell_init(moldyn);
885 /* logging & visualization */
891 /* sqaure of some variables */
892 moldyn->tau_square=moldyn->tau*moldyn->tau;
893 moldyn->cutoff_square=moldyn->cutoff*moldyn->cutoff;
895 /* calculate initial forces */
896 potential_force_calc(moldyn);
898 /* some stupid checks before we actually start calculating bullshit */
899 if(moldyn->cutoff>0.5*moldyn->dim.x)
900 printf("[moldyn] warning: cutoff > 0.5 x dim.x\n");
901 if(moldyn->cutoff>0.5*moldyn->dim.y)
902 printf("[moldyn] warning: cutoff > 0.5 x dim.y\n");
903 if(moldyn->cutoff>0.5*moldyn->dim.z)
904 printf("[moldyn] warning: cutoff > 0.5 x dim.z\n");
905 ds=0.5*atom[0].f.x*moldyn->tau_square/atom[0].mass;
906 if(ds>0.05*moldyn->nnd)
907 printf("[moldyn] warning: forces too high / tau too small!\n");
909 /* zero absolute time */
912 /* debugging, ignore */
915 /* executing the schedule */
916 for(sched->count=0;sched->count<sched->total_sched;sched->count++) {
918 /* setting amount of runs and finite time step size */
919 moldyn->tau=sched->tau[sched->count];
920 moldyn->tau_square=moldyn->tau*moldyn->tau;
921 moldyn->time_steps=sched->runs[sched->count];
923 /* integration according to schedule */
925 for(i=0;i<moldyn->time_steps;i++) {
927 /* integration step */
928 moldyn->integrate(moldyn);
931 if(moldyn->pt_scale&(T_SCALE_BERENDSEN|T_SCALE_DIRECT))
932 scale_velocity(moldyn,FALSE);
933 if(moldyn->pt_scale&(P_SCALE_BERENDSEN|P_SCALE_DIRECT))
934 scale_volume(moldyn);
936 /* check for log & visualization */
943 //ax=((0.28-0.25)*sqrt(3)*LC_SI/2)*cos(ao*i);
944 //av=ao*(0.28-0.25)*sqrt(3)*LC_SI/2*sin(ao*i);
945 update_e_kin(moldyn);
948 moldyn->time,moldyn->ekin,
950 get_total_energy(moldyn));
951 //moldyn->atom[0].r.x,ax,av*av*M_SI,0.1*ax*ax,av*av*M_SI+0.1*ax*ax);
955 p=get_total_p(moldyn);
957 "%f %f\n",moldyn->time,v3_norm(&p));
962 snprintf(dir,128,"%s/s-%07.f.save",
963 moldyn->vlsdir,moldyn->time);
964 fd=open(dir,O_WRONLY|O_TRUNC|O_CREAT);
965 if(fd<0) perror("[moldyn] save fd open");
967 write(fd,moldyn,sizeof(t_moldyn));
968 write(fd,moldyn->atom,
969 moldyn->count*sizeof(t_atom));
976 visual_atoms(&(moldyn->vis),moldyn->time,
977 moldyn->atom,moldyn->count);
978 printf("\rsched: %d, steps: %d, debug: %d",
979 sched->count,i,moldyn->debug);
984 /* increase absolute time */
985 moldyn->time+=moldyn->tau;
989 /* check for hooks */
991 sched->hook(moldyn,sched->hook_params);
993 /* get a new info line */
1001 /* velocity verlet */
1003 int velocity_verlet(t_moldyn *moldyn) {
1006 double tau,tau_square,h;
1011 count=moldyn->count;
1013 tau_square=moldyn->tau_square;
1015 for(i=0;i<count;i++) {
1018 v3_scale(&delta,&(atom[i].v),tau);
1019 v3_add(&(atom[i].r),&(atom[i].r),&delta);
1020 v3_scale(&delta,&(atom[i].f),h*tau_square);
1021 v3_add(&(atom[i].r),&(atom[i].r),&delta);
1022 check_per_bound(moldyn,&(atom[i].r));
1024 /* velocities [actually v(t+tau/2)] */
1025 v3_scale(&delta,&(atom[i].f),h*tau);
1026 v3_add(&(atom[i].v),&(atom[i].v),&delta);
1029 /* neighbour list update */
1030 link_cell_update(moldyn);
1032 /* forces depending on chosen potential */
1033 potential_force_calc(moldyn);
1035 for(i=0;i<count;i++) {
1036 /* again velocities [actually v(t+tau)] */
1037 v3_scale(&delta,&(atom[i].f),0.5*tau/atom[i].mass);
1038 v3_add(&(atom[i].v),&(atom[i].v),&delta);
1047 * potentials & corresponding forces & virial routine
1051 /* generic potential and force calculation */
1053 int potential_force_calc(t_moldyn *moldyn) {
1056 t_atom *itom,*jtom,*ktom;
1059 t_list neighbour_i[27];
1060 t_list neighbour_i2[27];
1065 count=moldyn->count;
1074 /* get energy and force of every atom */
1075 for(i=0;i<count;i++) {
1078 v3_zero(&(itom[i].f));
1080 /* reset viral of atom i */
1081 virial=&(itom[i].virial);
1090 /* reset site energy */
1093 /* single particle potential/force */
1094 if(itom[i].attr&ATOM_ATTR_1BP)
1095 moldyn->func1b(moldyn,&(itom[i]));
1097 if(!(itom[i].attr&(ATOM_ATTR_2BP|ATOM_ATTR_3BP)))
1100 /* 2 body pair potential/force */
1102 link_cell_neighbour_index(moldyn,
1103 (itom[i].r.x+moldyn->dim.x/2)/lc->x,
1104 (itom[i].r.y+moldyn->dim.y/2)/lc->y,
1105 (itom[i].r.z+moldyn->dim.z/2)/lc->z,
1112 this=&(neighbour_i[j]);
1115 if(this->start==NULL)
1121 jtom=this->current->data;
1123 if(jtom==&(itom[i]))
1126 if((jtom->attr&ATOM_ATTR_2BP)&
1127 (itom[i].attr&ATOM_ATTR_2BP)) {
1128 moldyn->func2b(moldyn,
1134 /* 3 body potential/force */
1136 if(!(itom[i].attr&ATOM_ATTR_3BP)||
1137 !(jtom->attr&ATOM_ATTR_3BP))
1140 /* copy the neighbour lists */
1141 memcpy(neighbour_i2,neighbour_i,
1144 /* get neighbours of i */
1147 that=&(neighbour_i2[k]);
1150 if(that->start==NULL)
1157 ktom=that->current->data;
1159 if(!(ktom->attr&ATOM_ATTR_3BP))
1165 if(ktom==&(itom[i]))
1168 moldyn->func3b(moldyn,
1174 } while(list_next_f(that)!=\
1179 /* 2bp post function */
1180 if(moldyn->func2b_post) {
1181 moldyn->func2b_post(moldyn,
1186 } while(list_next_f(this)!=L_NO_NEXT_ELEMENT);
1199 for(i=0;i<count;i++)
1200 moldyn->vt2-=v3_scalar_product(&(itom[i].r),&(itom[i].f));
1202 printf("compare: vt1: %f vt2: %f\n",moldyn->vt1,moldyn->vt2);
1204 pressure_calc(moldyn);
1210 * virial calculation
1213 inline int virial_calc(t_atom *a,t_3dvec *f,t_3dvec *d) {
1215 a->virial.xx-=f->x*d->x;
1216 a->virial.yy-=f->y*d->y;
1217 a->virial.zz-=f->z*d->z;
1218 a->virial.xy-=f->x*d->y;
1219 a->virial.xz-=f->x*d->z;
1220 a->virial.yz-=f->y*d->z;
1226 * periodic boundayr checking
1229 inline int check_per_bound(t_moldyn *moldyn,t_3dvec *a) {
1240 if(moldyn->status&MOLDYN_STAT_PBX) {
1241 if(a->x>=x) a->x-=dim->x;
1242 else if(-a->x>x) a->x+=dim->x;
1244 if(moldyn->status&MOLDYN_STAT_PBY) {
1245 if(a->y>=y) a->y-=dim->y;
1246 else if(-a->y>y) a->y+=dim->y;
1248 if(moldyn->status&MOLDYN_STAT_PBZ) {
1249 if(a->z>=z) a->z-=dim->z;
1250 else if(-a->z>z) a->z+=dim->z;
1258 * example potentials
1261 /* harmonic oscillator potential and force */
1263 int harmonic_oscillator(t_moldyn *moldyn,t_atom *ai,t_atom *aj,u8 bc) {
1265 t_ho_params *params;
1266 t_3dvec force,distance;
1268 double sc,equi_dist;
1270 params=moldyn->pot2b_params;
1271 sc=params->spring_constant;
1272 equi_dist=params->equilibrium_distance;
1276 v3_sub(&distance,&(aj->r),&(ai->r));
1278 if(bc) check_per_bound(moldyn,&distance);
1279 d=v3_norm(&distance);
1280 if(d<=moldyn->cutoff) {
1281 moldyn->energy+=(0.5*sc*(d-equi_dist)*(d-equi_dist));
1282 /* f = -grad E; grad r_ij = -1 1/r_ij distance */
1283 f=sc*(1.0-equi_dist/d);
1284 v3_scale(&force,&distance,f);
1285 v3_add(&(ai->f),&(ai->f),&force);
1286 virial_calc(ai,&force,&distance);
1287 virial_calc(aj,&force,&distance); /* f and d signe switched */
1288 v3_scale(&force,&distance,-f);
1289 v3_add(&(aj->f),&(aj->f),&force);
1295 /* lennard jones potential & force for one sort of atoms */
1297 int lennard_jones(t_moldyn *moldyn,t_atom *ai,t_atom *aj,u8 bc) {
1299 t_lj_params *params;
1300 t_3dvec force,distance;
1302 double eps,sig6,sig12;
1304 params=moldyn->pot2b_params;
1305 eps=params->epsilon4;
1306 sig6=params->sigma6;
1307 sig12=params->sigma12;
1311 v3_sub(&distance,&(aj->r),&(ai->r));
1312 if(bc) check_per_bound(moldyn,&distance);
1313 d=v3_absolute_square(&distance); /* 1/r^2 */
1314 if(d<=moldyn->cutoff_square) {
1315 d=1.0/d; /* 1/r^2 */
1318 h1=h2*h2; /* 1/r^12 */
1319 moldyn->energy+=(eps*(sig12*h1-sig6*h2)-params->uc);
1326 v3_scale(&force,&distance,d);
1327 v3_add(&(aj->f),&(aj->f),&force);
1328 v3_scale(&force,&distance,-1.0*d); /* f = - grad E */
1329 v3_add(&(ai->f),&(ai->f),&force);
1330 virial_calc(ai,&force,&distance);
1331 virial_calc(aj,&force,&distance); /* f and d signe switched */
1332 moldyn->vt1-=v3_scalar_product(&force,&distance);
1339 * tersoff potential & force for 2 sorts of atoms
1342 /* create mixed terms from parameters and set them */
1343 int tersoff_mult_complete_params(t_tersoff_mult_params *p) {
1345 printf("[moldyn] tersoff parameter completion\n");
1346 p->S2[0]=p->S[0]*p->S[0];
1347 p->S2[1]=p->S[1]*p->S[1];
1348 p->Smixed=sqrt(p->S[0]*p->S[1]);
1349 p->S2mixed=p->Smixed*p->Smixed;
1350 p->Rmixed=sqrt(p->R[0]*p->R[1]);
1351 p->Amixed=sqrt(p->A[0]*p->A[1]);
1352 p->Bmixed=sqrt(p->B[0]*p->B[1]);
1353 p->lambda_m=0.5*(p->lambda[0]+p->lambda[1]);
1354 p->mu_m=0.5*(p->mu[0]+p->mu[1]);
1356 printf("[moldyn] tersoff mult parameter info:\n");
1357 printf(" S (A) | %f | %f | %f\n",p->S[0],p->S[1],p->Smixed);
1358 printf(" R (A) | %f | %f | %f\n",p->R[0],p->R[1],p->Rmixed);
1359 printf(" A (eV) | %f | %f | %f\n",p->A[0]/EV,p->A[1]/EV,p->Amixed/EV);
1360 printf(" B (eV) | %f | %f | %f\n",p->B[0]/EV,p->B[1]/EV,p->Bmixed/EV);
1361 printf(" lambda | %f | %f | %f\n",p->lambda[0],p->lambda[1],
1363 printf(" mu | %f | %f | %f\n",p->mu[0],p->mu[1],p->mu_m);
1364 printf(" beta | %.10f | %.10f\n",p->beta[0],p->beta[1]);
1365 printf(" n | %f | %f\n",p->n[0],p->n[1]);
1366 printf(" c | %f | %f\n",p->c[0],p->c[1]);
1367 printf(" d | %f | %f\n",p->d[0],p->d[1]);
1368 printf(" h | %f | %f\n",p->h[0],p->h[1]);
1369 printf(" chi | %f \n",p->chi);
1374 /* tersoff 1 body part */
1375 int tersoff_mult_1bp(t_moldyn *moldyn,t_atom *ai) {
1378 t_tersoff_mult_params *params;
1379 t_tersoff_exchange *exchange;
1382 params=moldyn->pot1b_params;
1383 exchange=&(params->exchange);
1386 * simple: point constant parameters only depending on atom i to
1387 * their right values
1390 exchange->beta_i=&(params->beta[brand]);
1391 exchange->n_i=&(params->n[brand]);
1392 exchange->c_i=&(params->c[brand]);
1393 exchange->d_i=&(params->d[brand]);
1394 exchange->h_i=&(params->h[brand]);
1396 exchange->betaini=pow(*(exchange->beta_i),*(exchange->n_i));
1397 exchange->ci2=params->c[brand]*params->c[brand];
1398 exchange->di2=params->d[brand]*params->d[brand];
1399 exchange->ci2di2=exchange->ci2/exchange->di2;
1404 /* tersoff 2 body part */
1405 int tersoff_mult_2bp(t_moldyn *moldyn,t_atom *ai,t_atom *aj,u8 bc) {
1407 t_tersoff_mult_params *params;
1408 t_tersoff_exchange *exchange;
1409 t_3dvec dist_ij,force;
1411 double A,B,R,S,S2,lambda,mu;
1418 params=moldyn->pot2b_params;
1420 exchange=&(params->exchange);
1422 /* clear 3bp and 2bp post run */
1424 exchange->run2bp_post=0;
1426 /* reset S > r > R mark */
1427 exchange->d_ij_between_rs=0;
1430 * calc of 2bp contribution of V_ij and dV_ij/ji
1432 * for Vij and dV_ij we need:
1436 * for dV_ji we need:
1437 * - f_c_ji = f_c_ij, df_c_ji = df_c_ij
1438 * - f_r_ji = f_r_ij; df_r_ji = df_r_ij
1443 if(brand==ai->brand) {
1445 S2=params->S2[brand];
1449 lambda=params->lambda[brand];
1450 mu=params->mu[brand];
1459 lambda=params->lambda_m;
1461 params->exchange.chi=params->chi;
1465 v3_sub(&dist_ij,&(aj->r),&(ai->r));
1466 if(bc) check_per_bound(moldyn,&dist_ij);
1467 d_ij2=v3_absolute_square(&dist_ij);
1469 /* if d_ij2 > S2 => no force & potential energy contribution */
1473 /* now we will need the distance */
1474 //d_ij=v3_norm(&dist_ij);
1477 /* save for use in 3bp */
1478 exchange->d_ij=d_ij;
1479 exchange->d_ij2=d_ij2;
1480 exchange->dist_ij=dist_ij;
1482 /* more constants */
1483 exchange->beta_j=&(params->beta[brand]);
1484 exchange->n_j=&(params->n[brand]);
1485 exchange->c_j=&(params->c[brand]);
1486 exchange->d_j=&(params->d[brand]);
1487 exchange->h_j=&(params->h[brand]);
1488 if(brand==ai->brand) {
1489 exchange->betajnj=exchange->betaini;
1490 exchange->cj2=exchange->ci2;
1491 exchange->dj2=exchange->di2;
1492 exchange->cj2dj2=exchange->ci2di2;
1495 exchange->betajnj=pow(*(exchange->beta_j),*(exchange->n_j));
1496 exchange->cj2=params->c[brand]*params->c[brand];
1497 exchange->dj2=params->d[brand]*params->d[brand];
1498 exchange->cj2dj2=exchange->cj2/exchange->dj2;
1501 /* f_r_ij = f_r_ji, df_r_ij = df_r_ji */
1502 f_r=A*exp(-lambda*d_ij);
1503 df_r=lambda*f_r/d_ij;
1505 /* f_a, df_a calc (again, same for ij and ji) | save for later use! */
1506 exchange->f_a=-B*exp(-mu*d_ij);
1507 exchange->df_a=mu*exchange->f_a/d_ij;
1509 /* f_c, df_c calc (again, same for ij and ji) */
1511 /* f_c = 1, df_c = 0 */
1514 /* two body contribution (ij, ji) */
1515 v3_scale(&force,&dist_ij,-df_r);
1519 arg=M_PI*(d_ij-R)/s_r;
1520 f_c=0.5+0.5*cos(arg);
1521 df_c=0.5*sin(arg)*(M_PI/(s_r*d_ij));
1522 /* two body contribution (ij, ji) */
1523 v3_scale(&force,&dist_ij,-df_c*f_r-df_r*f_c);
1524 /* tell 3bp that S > r > R */
1525 exchange->d_ij_between_rs=1;
1528 /* add forces of 2bp (ij, ji) contribution
1529 * dVij = dVji and we sum up both: no 1/2) */
1530 v3_add(&(ai->f),&(ai->f),&force);
1533 ai->virial.xx-=force.x*dist_ij.x;
1534 ai->virial.yy-=force.y*dist_ij.y;
1535 ai->virial.zz-=force.z*dist_ij.z;
1536 ai->virial.xy-=force.x*dist_ij.y;
1537 ai->virial.xz-=force.x*dist_ij.z;
1538 ai->virial.yz-=force.y*dist_ij.z;
1541 if(ai==&(moldyn->atom[0])) {
1542 printf("dVij, dVji (2bp) contrib:\n");
1543 printf("%f | %f\n",force.x,ai->f.x);
1544 printf("%f | %f\n",force.y,ai->f.y);
1545 printf("%f | %f\n",force.z,ai->f.z);
1549 if(ai==&(moldyn->atom[0])) {
1550 printf("dVij, dVji (2bp) contrib:\n");
1551 printf("%f | %f\n",force.x*dist_ij.x,ai->virial.xx);
1552 printf("%f | %f\n",force.y*dist_ij.y,ai->virial.yy);
1553 printf("%f | %f\n",force.z*dist_ij.z,ai->virial.zz);
1557 /* energy 2bp contribution (ij, ji) is 0.5 f_r f_c ... */
1558 moldyn->energy+=(0.5*f_r*f_c);
1560 /* save for use in 3bp */
1562 exchange->df_c=df_c;
1564 /* enable the run of 3bp function and 2bp post processing */
1566 exchange->run2bp_post=1;
1568 /* reset 3bp sums */
1569 exchange->zeta_ij=0.0;
1570 exchange->zeta_ji=0.0;
1571 v3_zero(&(exchange->dzeta_ij));
1572 v3_zero(&(exchange->dzeta_ji));
1577 /* tersoff 2 body post part */
1579 int tersoff_mult_post_2bp(t_moldyn *moldyn,t_atom *ai,t_atom *aj,u8 bc) {
1582 * here we have to allow for the 3bp sums
1585 * - zeta_ij, dzeta_ij
1586 * - zeta_ji, dzeta_ji
1588 * to compute the 3bp contribution to:
1594 t_tersoff_mult_params *params;
1595 t_tersoff_exchange *exchange;
1600 double f_c,df_c,f_a,df_a;
1601 double chi,ni,betaini,nj,betajnj;
1604 params=moldyn->pot2b_params;
1605 exchange=&(params->exchange);
1607 /* we do not run if f_c_ij was detected to be 0! */
1608 if(!(exchange->run2bp_post))
1612 df_c=exchange->df_c;
1614 df_a=exchange->df_a;
1615 betaini=exchange->betaini;
1616 betajnj=exchange->betajnj;
1617 ni=*(exchange->n_i);
1618 nj=*(exchange->n_j);
1620 dist_ij=&(exchange->dist_ij);
1623 zeta=exchange->zeta_ij;
1625 moldyn->debug++; /* just for debugging ... */
1627 v3_scale(&force,dist_ij,df_a*b*f_c);
1630 tmp=betaini*pow(zeta,ni-1.0); /* beta^n * zeta^n-1 */
1631 b=(1+zeta*tmp); /* 1 + beta^n zeta^n */
1632 db=chi*pow(b,-1.0/(2*ni)-1); /* x(...)^(-1/2n - 1) */
1634 db*=-0.5*tmp; /* db_ij */
1635 v3_scale(&force,&(exchange->dzeta_ij),f_a*db);
1636 v3_scale(&temp,dist_ij,df_a*b);
1637 v3_add(&force,&force,&temp);
1638 v3_scale(&force,&force,f_c);
1640 v3_scale(&temp,dist_ij,df_c*b*f_a);
1641 v3_add(&force,&force,&temp);
1642 v3_scale(&force,&force,-0.5);
1645 v3_add(&(ai->f),&(ai->f),&force);
1648 ai->virial.xx-=force.x*dist_ij->x;
1649 ai->virial.yy-=force.y*dist_ij->y;
1650 ai->virial.zz-=force.z*dist_ij->z;
1651 ai->virial.xy-=force.x*dist_ij->y;
1652 ai->virial.xz-=force.x*dist_ij->z;
1653 ai->virial.yz-=force.y*dist_ij->z;
1656 if(ai==&(moldyn->atom[0])) {
1657 printf("dVij (3bp) contrib:\n");
1658 printf("%f | %f\n",force.x,ai->f.x);
1659 printf("%f | %f\n",force.y,ai->f.y);
1660 printf("%f | %f\n",force.z,ai->f.z);
1664 if(ai==&(moldyn->atom[0])) {
1665 printf("dVij (3bp) contrib:\n");
1666 printf("%f | %f\n",force.x*dist_ij->x,ai->virial.xx);
1667 printf("%f | %f\n",force.y*dist_ij->y,ai->virial.yy);
1668 printf("%f | %f\n",force.z*dist_ij->z,ai->virial.zz);
1672 /* add energy of 3bp sum */
1673 moldyn->energy+=(0.5*f_c*b*f_a);
1676 zeta=exchange->zeta_ji;
1680 v3_scale(&force,dist_ij,df_a*b*f_c);
1683 tmp=betajnj*pow(zeta,nj-1.0); /* beta^n * zeta^n-1 */
1684 b=(1+zeta*tmp); /* 1 + beta^n zeta^n */
1685 db=chi*pow(b,-1.0/(2*nj)-1); /* x(...)^(-1/2n - 1) */
1687 db*=-0.5*tmp; /* db_ij */
1688 v3_scale(&force,&(exchange->dzeta_ji),f_a*db);
1689 v3_scale(&temp,dist_ij,df_a*b);
1690 v3_add(&force,&force,&temp);
1691 v3_scale(&force,&force,f_c);
1693 v3_scale(&temp,dist_ij,df_c*b*f_a);
1694 v3_add(&force,&force,&temp);
1695 v3_scale(&force,&force,-0.5);
1698 v3_add(&(ai->f),&(ai->f),&force);
1700 /* virial - plus sign, as dist_ij = - dist_ji - (really??) */
1701 // TEST ... with a minus instead
1702 ai->virial.xx-=force.x*dist_ij->x;
1703 ai->virial.yy-=force.y*dist_ij->y;
1704 ai->virial.zz-=force.z*dist_ij->z;
1705 ai->virial.xy-=force.x*dist_ij->y;
1706 ai->virial.xz-=force.x*dist_ij->z;
1707 ai->virial.yz-=force.y*dist_ij->z;
1710 if(ai==&(moldyn->atom[0])) {
1711 printf("dVji (3bp) contrib:\n");
1712 printf("%f | %f\n",force.x,ai->f.x);
1713 printf("%f | %f\n",force.y,ai->f.y);
1714 printf("%f | %f\n",force.z,ai->f.z);
1718 if(ai==&(moldyn->atom[0])) {
1719 printf("dVji (3bp) contrib:\n");
1720 printf("%f | %f\n",force.x*dist_ij->x,ai->virial.xx);
1721 printf("%f | %f\n",force.y*dist_ij->y,ai->virial.yy);
1722 printf("%f | %f\n",force.z*dist_ij->z,ai->virial.zz);
1729 /* tersoff 3 body part */
1731 int tersoff_mult_3bp(t_moldyn *moldyn,t_atom *ai,t_atom *aj,t_atom *ak,u8 bc) {
1733 t_tersoff_mult_params *params;
1734 t_tersoff_exchange *exchange;
1735 t_3dvec dist_ij,dist_ik,dist_jk;
1736 t_3dvec temp1,temp2;
1740 double d_ij,d_ik,d_jk,d_ij2,d_ik2,d_jk2;
1743 double f_c_ik,df_c_ik,arg;
1747 double cos_theta,d_costheta1,d_costheta2;
1748 double h_cos,d2_h_cos2;
1749 double frac,g,zeta,chi;
1753 params=moldyn->pot3b_params;
1754 exchange=&(params->exchange);
1756 if(!(exchange->run3bp))
1760 * calc of 3bp contribution of V_ij and dV_ij/ji/jk &
1761 * 2bp contribution of dV_jk
1763 * for Vij and dV_ij we still need:
1764 * - b_ij, db_ij (zeta_ij)
1765 * - f_c_ik, df_c_ik, constants_i, cos_theta_ijk, d_costheta_ijk
1767 * for dV_ji we still need:
1768 * - b_ji, db_ji (zeta_ji)
1769 * - f_c_jk, d_c_jk, constants_j, cos_theta_jik, d_costheta_jik
1771 * for dV_jk we need:
1775 * - f_c_ji, df_c_ji, constants_j, cos_theta_jki, d_costheta_jki
1783 /* dist_ij, d_ij - this is < S_ij ! */
1784 dist_ij=exchange->dist_ij;
1785 d_ij=exchange->d_ij;
1786 d_ij2=exchange->d_ij2;
1788 /* f_c_ij, df_c_ij (same for ji) */
1790 df_c=exchange->df_c;
1793 * calculate unknown values now ...
1796 /* V_ij and dV_ij stuff (in b_ij there is f_c_ik) */
1799 v3_sub(&dist_ik,&(ak->r),&(ai->r));
1800 if(bc) check_per_bound(moldyn,&dist_ik);
1801 d_ik2=v3_absolute_square(&dist_ik);
1805 if(brand==ak->brand) {
1808 S2=params->S2[brand];
1816 /* zeta_ij/dzeta_ij contribution only for d_ik < S */
1819 /* now we need d_ik */
1822 /* get constants_i from exchange data */
1829 c2d2=exchange->ci2di2;
1831 /* cosine of theta_ijk by scalaproduct */
1832 rr=v3_scalar_product(&dist_ij,&dist_ik);
1838 d_costheta1=cos_theta/d_ij2-tmp;
1839 d_costheta2=cos_theta/d_ik2-tmp;
1841 /* some usefull values */
1842 h_cos=(h-cos_theta);
1843 d2_h_cos2=d2+(h_cos*h_cos);
1844 frac=c2/(d2_h_cos2);
1849 /* d_costheta_ij and dg(cos_theta) - needed in any case! */
1850 v3_scale(&temp1,&dist_ij,d_costheta1);
1851 v3_scale(&temp2,&dist_ik,d_costheta2);
1852 v3_add(&temp1,&temp1,&temp2);
1853 v3_scale(&temp1,&temp1,-2.0*frac*h_cos/d2_h_cos2); /* dg */
1855 /* f_c_ik & df_c_ik + {d,}zeta contribution */
1856 dzeta=&(exchange->dzeta_ij);
1860 // => df_c_ik=0.0; of course we do not set this!
1863 exchange->zeta_ij+=g;
1866 v3_add(dzeta,dzeta,&temp1);
1871 arg=M_PI*(d_ik-R)/s_r;
1872 f_c_ik=0.5+0.5*cos(arg);
1873 df_c_ik=0.5*sin(arg)*(M_PI/(s_r*d_ik));
1876 exchange->zeta_ij+=f_c_ik*g;
1879 v3_scale(&temp1,&temp1,f_c_ik);
1880 v3_scale(&temp2,&dist_ik,g*df_c_ik);
1881 v3_add(&temp1,&temp1,&temp2);
1882 v3_add(dzeta,dzeta,&temp1);
1886 /* dV_ji stuff (in b_ji there is f_c_jk) + dV_jk stuff! */
1889 v3_sub(&dist_jk,&(ak->r),&(aj->r));
1890 if(bc) check_per_bound(moldyn,&dist_jk);
1891 d_jk2=v3_absolute_square(&dist_jk);
1895 if(brand==ak->brand) {
1898 S2=params->S2[brand];
1900 mu=params->mu[brand];
1912 /* zeta_ji/dzeta_ji contribution only for d_jk < S_jk */
1915 /* now we need d_ik */
1918 /* constants_j from exchange data */
1925 c2d2=exchange->cj2dj2;
1927 /* cosine of theta_jik by scalaproduct */
1928 rr=-v3_scalar_product(&dist_ij,&dist_jk); /* -1, as ij -> ji */
1934 d_costheta2=cos_theta/d_ij2;
1936 /* some usefull values */
1937 h_cos=(h-cos_theta);
1938 d2_h_cos2=d2+(h_cos*h_cos);
1939 frac=c2/(d2_h_cos2);
1944 /* d_costheta_jik and dg(cos_theta) - needed in any case! */
1945 v3_scale(&temp1,&dist_jk,d_costheta1);
1946 v3_scale(&temp2,&dist_ij,-d_costheta2); /* ji -> ij => -1 */
1947 //v3_add(&temp1,&temp1,&temp2);
1948 v3_sub(&temp1,&temp1,&temp2); /* there is a minus! */
1949 v3_scale(&temp1,&temp1,-2.0*frac*h_cos/d2_h_cos2); /* dg */
1951 /* store dg in temp2 and use it for dVjk later */
1952 v3_copy(&temp2,&temp1);
1954 /* f_c_jk + {d,}zeta contribution (df_c_jk = 0) */
1955 dzeta=&(exchange->dzeta_ji);
1961 exchange->zeta_ji+=g;
1964 v3_add(dzeta,dzeta,&temp1);
1969 arg=M_PI*(d_jk-R)/s_r;
1970 f_c_jk=0.5+0.5*cos(arg);
1973 exchange->zeta_ji+=f_c_jk*g;
1976 v3_scale(&temp1,&temp1,f_c_jk);
1977 v3_add(dzeta,dzeta,&temp1);
1980 /* dV_jk stuff | add force contribution on atom i immediately */
1981 if(exchange->d_ij_between_rs) {
1983 v3_scale(&temp1,&temp2,f_c);
1984 v3_scale(&temp2,&dist_ij,df_c*g);
1985 v3_add(&temp2,&temp2,&temp1); /* -> dzeta_jk in temp2 */
1989 // dzeta_jk is simply dg, which is stored in temp2
1991 /* betajnj * zeta_jk ^ nj-1 */
1992 tmp=exchange->betajnj*pow(zeta,(n-1.0));
1993 tmp=-chi/2.0*pow((1+tmp*zeta),(-1.0/(2.0*n)-1))*tmp;
1994 v3_scale(&temp2,&temp2,tmp*B*exp(-mu*d_jk)*f_c_jk*0.5);
1995 v3_add(&(ai->f),&(ai->f),&temp2); /* -1 skipped in f_a calc ^ */
1996 /* scaled with 0.5 ^ */
1999 ai->virial.xx-=temp2.x*dist_jk.x;
2000 ai->virial.yy-=temp2.y*dist_jk.y;
2001 ai->virial.zz-=temp2.z*dist_jk.z;
2002 ai->virial.xy-=temp2.x*dist_jk.y;
2003 ai->virial.xz-=temp2.x*dist_jk.z;
2004 ai->virial.yz-=temp2.y*dist_jk.z;
2007 if(ai==&(moldyn->atom[0])) {
2008 printf("dVjk (3bp) contrib:\n");
2009 printf("%f | %f\n",temp2.x,ai->f.x);
2010 printf("%f | %f\n",temp2.y,ai->f.y);
2011 printf("%f | %f\n",temp2.z,ai->f.z);
2015 if(ai==&(moldyn->atom[0])) {
2016 printf("dVjk (3bp) contrib:\n");
2017 printf("%f | %f\n",temp2.x*dist_jk.x,ai->virial.xx);
2018 printf("%f | %f\n",temp2.y*dist_jk.y,ai->virial.yy);
2019 printf("%f | %f\n",temp2.z*dist_jk.z,ai->virial.zz);
2030 * debugging / critical check functions
2033 int moldyn_bc_check(t_moldyn *moldyn) {
2046 for(i=0;i<moldyn->count;i++) {
2047 if(atom[i].r.x>=dim->x/2||-atom[i].r.x>dim->x/2) {
2048 printf("FATAL: atom %d: x: %.20f (%.20f)\n",
2049 i,atom[i].r.x,dim->x/2);
2050 printf("diagnostic:\n");
2051 printf("-----------\natom.r.x:\n");
2053 memcpy(&byte,(u8 *)(&(atom[i].r.x))+j,1);
2056 ((byte)&(1<<k))?1:0,
2059 printf("---------------\nx=dim.x/2:\n");
2061 memcpy(&byte,(u8 *)(&x)+j,1);
2064 ((byte)&(1<<k))?1:0,
2067 if(atom[i].r.x==x) printf("the same!\n");
2068 else printf("different!\n");
2070 if(atom[i].r.y>=dim->y/2||-atom[i].r.y>dim->y/2)
2071 printf("FATAL: atom %d: y: %.20f (%.20f)\n",
2072 i,atom[i].r.y,dim->y/2);
2073 if(atom[i].r.z>=dim->z/2||-atom[i].r.z>dim->z/2)
2074 printf("FATAL: atom %d: z: %.20f (%.20f)\n",
2075 i,atom[i].r.z,dim->z/2);