+ }
+ } while(list_next(this)!=L_NO_NEXT_ELEMENT);
+
+ /*
+ * direct neighbour cells
+ * => no boundary condition check necessary
+ */
+ for(j=1;j<c;j++) {
+ this=&(neighbour[j]);
+ list_reset(this); /* there might not be a single atom */
+ if(this->start!=NULL) {
+
+ do {
+ btom=this->current->data;
+ v3_sub(&distance,&(atom[i].r),&(btom->r));
+ d=v3_norm(&distance);
+ if(d<=moldyn->cutoff) {
+ u+=(0.5*sc*(d-equi_dist)*(d-equi_dist));
+ v3_scale(&force,&distance,
+ -sc*(1.0-(equi_dist/d)));
+ v3_add(&(atom[i].f),&(atom[i].f),
+ &force);
+ }
+ } while(list_next(this)!=L_NO_NEXT_ELEMENT);
+
+ }
+ }
+
+ /*
+ * indirect neighbour cells
+ * => check boundary conditions
+ */
+ for(j=c;j<27;j++) {
+ this=&(neighbour[j]);
+ list_reset(this); /* check boundary conditions */
+ if(this->start!=NULL) {
+
+ do {
+ btom=this->current->data;
+ v3_sub(&distance,&(atom[i].r),&(btom->r));
+ v3_per_bound(&distance,&(moldyn->dim));
+ d=v3_norm(&distance);
+ if(d<=moldyn->cutoff) {
+ u+=(0.5*sc*(d-equi_dist)*(d-equi_dist));
+ v3_scale(&force,&distance,
+ -sc*(1.0-(equi_dist/d)));
+ v3_add(&(atom[i].f),&(atom[i].f),
+ &force);
+ }
+ } while(list_next(this)!=L_NO_NEXT_ELEMENT);
+