+ for(cnt=0;cnt<tag;cnt++)
+ new[cnt]=old[cnt];
+
+ for(cnt=tag+1;cnt<moldyn->count;cnt++) {
+ new[cnt-1]=old[cnt];
+ new[cnt-1].tag=cnt-1;
+ }
+
+ moldyn->count-=1;
+ moldyn->atom=new;
+
+ free(old);
+
+#ifdef LOWMEM_LISTS
+ ptr=realloc(moldyn->lc.subcell->list,moldyn->count*sizeof(int));
+ if(!ptr) {
+ perror("[moldyn] list realloc (del atom)");
+ return -1;
+ }
+ moldyn->lc.subcell->list=ptr;
+ // update lists
+ link_cell_update(moldyn);
+#endif
+
+#ifdef PTHREADS
+ ptr=realloc(amutex,moldyn->count*sizeof(pthread_mutex_t));
+ if(!ptr) {
+ perror("[moldyn] mutex realloc (add atom)");
+ return -1;
+ }
+ amutex=ptr;
+ pthread_mutex_destroy(&(amutex[moldyn->count+1]));
+#endif
+
+
+ return 0;
+}
+
+#define set_atom_positions(pos) \
+ if(d_params->type) {\
+ d_o.x=0; d_o.y=0; d_o.z=0;\
+ d_d.x=0; d_d.y=0; d_d.z=0;\
+ switch(d_params->stype) {\
+ case DEFECT_STYPE_DB_X:\
+ d_o.x=d_params->od;\
+ d_d.x=d_params->dd;\
+ break;\
+ case DEFECT_STYPE_DB_Y:\
+ d_o.y=d_params->od;\
+ d_d.y=d_params->dd;\
+ break;\
+ case DEFECT_STYPE_DB_Z:\
+ d_o.z=d_params->od;\
+ d_d.z=d_params->dd;\
+ break;\
+ case DEFECT_STYPE_DB_R:\
+ break;\
+ default:\
+ printf("[moldyn] WARNING: unknown defect\n");\
+ break;\
+ }\
+ v3_add(&dr,&pos,&d_o);\
+ v3_copy(&(atom[count].r),&dr);\
+ count+=1;\
+ v3_add(&dr,&pos,&d_d);\
+ v3_copy(&(atom[count].r),&dr);\
+ count+=1;\
+ }\
+ else {\
+ v3_copy(&(atom[count].r),&pos);\
+ count+=1;\
+ }
+
+/* cubic init */
+int cubic_init(int a,int b,int c,double lc,t_atom *atom,t_3dvec *origin,
+ t_part_params *p_params,t_defect_params *d_params) {
+
+ int count;
+ t_3dvec r;
+ int i,j,k;
+ t_3dvec o;
+ t_3dvec dist;
+ t_3dvec p;
+ t_3dvec d_o;
+ t_3dvec d_d;
+ t_3dvec dr;
+
+ p.x=0; p.y=0; p.z=0;
+
+ count=0;
+ if(origin)
+ v3_copy(&o,origin);
+ else
+ v3_zero(&o);
+
+ /* shift partition values */
+ if(p_params->type) {
+ p.x=p_params->p.x+(a*lc)/2.0;
+ p.y=p_params->p.y+(b*lc)/2.0;
+ p.z=p_params->p.z+(c*lc)/2.0;
+ }
+
+ r.x=o.x;
+ for(i=0;i<a;i++) {
+ r.y=o.y;
+ for(j=0;j<b;j++) {
+ r.z=o.z;
+ for(k=0;k<c;k++) {
+ switch(p_params->type) {
+ case PART_INSIDE_R:
+ v3_sub(&dist,&r,&p);
+ if(v3_absolute_square(&dist)<
+ (p_params->r*p_params->r)) {
+ set_atom_positions(r);
+ }
+ break;
+ case PART_OUTSIDE_R:
+ v3_sub(&dist,&r,&p);
+ if(v3_absolute_square(&dist)>=
+ (p_params->r*p_params->r)) {
+ set_atom_positions(r);
+ }
+ break;
+ case PART_INSIDE_D:
+ v3_sub(&dist,&r,&p);
+ if((fabs(dist.x)<p_params->d.x)&&
+ (fabs(dist.y)<p_params->d.y)&&
+ (fabs(dist.z)<p_params->d.z)) {
+ set_atom_positions(r);
+ }
+ break;
+ case PART_OUTSIDE_D:
+ v3_sub(&dist,&r,&p);
+ if((fabs(dist.x)>=p_params->d.x)||
+ (fabs(dist.y)>=p_params->d.y)||
+ (fabs(dist.z)>=p_params->d.z)) {
+ set_atom_positions(r);
+ }
+ break;
+ default:
+ set_atom_positions(r);
+ break;
+ }
+ r.z+=lc;
+ }
+ r.y+=lc;
+ }
+ r.x+=lc;
+ }
+
+ for(i=0;i<count;i++) {
+ atom[i].r.x-=(a*lc)/2.0;
+ atom[i].r.y-=(b*lc)/2.0;
+ atom[i].r.z-=(c*lc)/2.0;
+ }
+
+ return count;
+}
+
+/* fcc lattice init */
+int fcc_init(int a,int b,int c,double lc,t_atom *atom,t_3dvec *origin,
+ t_part_params *p_params,t_defect_params *d_params) {
+
+ int count;
+ int i,j,k,l;
+ t_3dvec o,r,n;
+ t_3dvec basis[3];
+ t_3dvec dist;
+ t_3dvec p;
+ t_3dvec d_d,d_o,dr;
+
+ p.x=0; p.y=0; p.z=0;
+
+ count=0;
+ if(origin)
+ v3_copy(&o,origin);
+ else
+ v3_zero(&o);
+
+ /* construct the basis */
+ memset(basis,0,3*sizeof(t_3dvec));
+ basis[0].x=0.5*lc;
+ basis[0].y=0.5*lc;
+ basis[1].x=0.5*lc;
+ basis[1].z=0.5*lc;
+ basis[2].y=0.5*lc;
+ basis[2].z=0.5*lc;
+
+ /* shift partition values */
+ if(p_params->type) {
+ p.x=p_params->p.x+(a*lc)/2.0;
+ p.y=p_params->p.y+(b*lc)/2.0;
+ p.z=p_params->p.z+(c*lc)/2.0;
+ }
+
+ /* fill up the room */
+ r.x=o.x;
+ for(i=0;i<a;i++) {
+ r.y=o.y;
+ for(j=0;j<b;j++) {
+ r.z=o.z;
+ for(k=0;k<c;k++) {
+ /* first atom */
+ switch(p_params->type) {
+ case PART_INSIDE_R:
+ v3_sub(&dist,&r,&p);
+ if(v3_absolute_square(&dist)<
+ (p_params->r*p_params->r)) {
+ set_atom_positions(r);
+ }
+ break;
+ case PART_OUTSIDE_R:
+ v3_sub(&dist,&r,&p);
+ if(v3_absolute_square(&dist)>=
+ (p_params->r*p_params->r)) {
+ set_atom_positions(r);
+ }
+ break;
+ case PART_INSIDE_D:
+ v3_sub(&dist,&r,&p);
+ if((fabs(dist.x)<p_params->d.x)&&
+ (fabs(dist.y)<p_params->d.y)&&
+ (fabs(dist.z)<p_params->d.z)) {
+ set_atom_positions(r);
+ }
+ break;
+ case PART_OUTSIDE_D:
+ v3_sub(&dist,&r,&p);
+ if((fabs(dist.x)>=p_params->d.x)||
+ (fabs(dist.y)>=p_params->d.y)||
+ (fabs(dist.z)>=p_params->d.z)) {
+ set_atom_positions(r);
+ }
+ break;
+ default:
+ set_atom_positions(r);
+ break;
+ }
+ /* the three face centered atoms */
+ for(l=0;l<3;l++) {
+ v3_add(&n,&r,&basis[l]);
+ switch(p_params->type) {
+ case PART_INSIDE_R:
+ v3_sub(&dist,&n,&p);
+ if(v3_absolute_square(&dist)<
+ (p_params->r*p_params->r)) {
+ set_atom_positions(n);
+ }
+ break;
+ case PART_OUTSIDE_R:
+ v3_sub(&dist,&n,&p);
+ if(v3_absolute_square(&dist)>=
+ (p_params->r*p_params->r)) {
+ set_atom_positions(n);
+ }
+ break;
+ case PART_INSIDE_D:
+ v3_sub(&dist,&n,&p);
+ if((fabs(dist.x)<p_params->d.x)&&
+ (fabs(dist.y)<p_params->d.y)&&
+ (fabs(dist.z)<p_params->d.z)) {
+ set_atom_positions(n);
+ }
+ break;
+ case PART_OUTSIDE_D:
+ v3_sub(&dist,&n,&p);
+ if((fabs(dist.x)>=p_params->d.x)||
+ (fabs(dist.y)>=p_params->d.y)||
+ (fabs(dist.z)>=p_params->d.z)) {
+ set_atom_positions(n);
+ }
+ break;
+ default:
+ set_atom_positions(n);
+ break;
+ }
+ }
+ r.z+=lc;
+ }
+ r.y+=lc;
+ }
+ r.x+=lc;
+ }
+
+ /* coordinate transformation */
+ for(i=0;i<count;i++) {
+ atom[i].r.x-=(a*lc)/2.0;
+ atom[i].r.y-=(b*lc)/2.0;
+ atom[i].r.z-=(c*lc)/2.0;
+ }
+
+ return count;
+}
+
+int diamond_init(int a,int b,int c,double lc,t_atom *atom,t_3dvec *origin,
+ t_part_params *p_params,t_defect_params *d_params) {
+
+ int count;
+ t_3dvec o;
+
+ count=fcc_init(a,b,c,lc,atom,origin,p_params,d_params);
+
+ 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,p_params,d_params);
+
+ return count;
+}
+
+int destroy_atoms(t_moldyn *moldyn) {
+
+ if(moldyn->atom) free(moldyn->atom);
+
+ return 0;
+}
+
+int thermal_init(t_moldyn *moldyn,u8 equi_init) {
+
+ /*
+ * - gaussian distribution of velocities
+ * - zero total momentum
+ * - velocity scaling (E = 3/2 N k T), E: kinetic energy
+ */
+
+ int i;
+ double v,sigma;
+ t_3dvec p_total,delta;
+ t_atom *atom;
+ t_random *random;
+
+ atom=moldyn->atom;
+ random=&(moldyn->random);
+
+ printf("[moldyn] thermal init (equi init: %s)\n",equi_init?"yes":"no");
+
+ /* gaussian distribution of velocities */
+ v3_zero(&p_total);
+ for(i=0;i<moldyn->count;i++) {
+ sigma=sqrt(2.0*K_BOLTZMANN*moldyn->t_ref/atom[i].mass);
+ /* x direction */
+ v=sigma*rand_get_gauss(random);
+ atom[i].v.x=v;
+ p_total.x+=atom[i].mass*v;
+ /* y direction */
+ v=sigma*rand_get_gauss(random);
+ atom[i].v.y=v;
+ p_total.y+=atom[i].mass*v;
+ /* z direction */
+ v=sigma*rand_get_gauss(random);
+ atom[i].v.z=v;
+ p_total.z+=atom[i].mass*v;
+ }
+
+ /* zero total momentum */
+ v3_scale(&p_total,&p_total,1.0/moldyn->count);
+ for(i=0;i<moldyn->count;i++) {
+ v3_scale(&delta,&p_total,1.0/atom[i].mass);
+ v3_sub(&(atom[i].v),&(atom[i].v),&delta);
+ }
+
+ /* velocity scaling */
+ scale_velocity(moldyn,equi_init);
+
+ return 0;
+}
+
+double total_mass_calc(t_moldyn *moldyn) {
+
+ int i;
+
+ moldyn->mass=0.0;
+
+ for(i=0;i<moldyn->count;i++)
+ moldyn->mass+=moldyn->atom[i].mass;
+
+ return moldyn->mass;
+}
+
+double temperature_calc(t_moldyn *moldyn) {
+
+ /* assume up to date kinetic energy, which is 3/2 N k_B T */
+
+ if(moldyn->count)
+ moldyn->t=(2.0*moldyn->ekin)/(3.0*K_BOLTZMANN*moldyn->count);
+ else moldyn->t=0.0;
+
+ return moldyn->t;
+}
+
+double get_temperature(t_moldyn *moldyn) {
+
+ return moldyn->t;
+}
+
+int scale_velocity(t_moldyn *moldyn,u8 equi_init) {
+
+ int i;
+ double e,scale;
+ t_atom *atom;
+ int count;
+
+ atom=moldyn->atom;
+
+ /*
+ * - velocity scaling (E = 3/2 N k T), E: kinetic energy
+ */
+
+ /* get kinetic energy / temperature & count involved atoms */
+ e=0.0;
+ count=0;
+ for(i=0;i<moldyn->count;i++) {
+ if((equi_init&TRUE)||(atom[i].attr&ATOM_ATTR_HB)) {
+ e+=atom[i].mass*v3_absolute_square(&(atom[i].v));
+ count+=1;
+ }
+ }
+ e*=0.5;
+ if(count!=0) moldyn->t=e/(1.5*count*K_BOLTZMANN);
+ else return 0; /* no atoms involved in scaling! */
+
+ /* (temporary) hack for e,t = 0 */
+ if(e==0.0) {
+ moldyn->t=0.0;
+ if(moldyn->t_ref!=0.0) {
+ thermal_init(moldyn,equi_init);
+ return 0;
+ }
+ else
+ return 0; /* no scaling needed */
+ }
+
+
+ /* get scaling factor */
+ scale=moldyn->t_ref/moldyn->t;
+ if(equi_init&TRUE)
+ scale*=2.0;
+ else
+ if(moldyn->pt_scale&T_SCALE_BERENDSEN)
+ scale=1.0+(scale-1.0)*moldyn->tau/moldyn->t_tc;
+ scale=sqrt(scale);
+
+ /* velocity scaling */
+ for(i=0;i<moldyn->count;i++) {
+ if((equi_init&TRUE)||(atom[i].attr&ATOM_ATTR_HB))
+ v3_scale(&(atom[i].v),&(atom[i].v),scale);
+ }
+
+ return 0;
+}
+
+double ideal_gas_law_pressure(t_moldyn *moldyn) {
+
+ double p;
+
+ p=moldyn->count*moldyn->t*K_BOLTZMANN/moldyn->volume;
+
+ return p;
+}
+
+double virial_sum(t_moldyn *moldyn) {
+
+ int i;
+ t_virial *virial;
+
+ /* virial (sum over atom virials) */
+ moldyn->virial=0.0;
+ moldyn->vir.xx=0.0;
+ moldyn->vir.yy=0.0;
+ moldyn->vir.zz=0.0;
+ moldyn->vir.xy=0.0;
+ moldyn->vir.xz=0.0;
+ moldyn->vir.yz=0.0;
+ for(i=0;i<moldyn->count;i++) {
+ virial=&(moldyn->atom[i].virial);
+ moldyn->virial+=(virial->xx+virial->yy+virial->zz);
+ moldyn->vir.xx+=virial->xx;
+ moldyn->vir.yy+=virial->yy;
+ moldyn->vir.zz+=virial->zz;
+ moldyn->vir.xy+=virial->xy;
+ moldyn->vir.xz+=virial->xz;
+ moldyn->vir.yz+=virial->yz;
+ }
+
+ /* global virial (absolute coordinates) */
+ //virial=&(moldyn->gvir);
+ //moldyn->gv=virial->xx+virial->yy+virial->zz;
+
+ return moldyn->virial;
+}
+
+double pressure_calc(t_moldyn *moldyn) {
+
+ /*
+ * PV = NkT + <W>
+ * with W = 1/3 sum_i f_i r_i (- skipped!)
+ * virial = sum_i f_i r_i
+ *
+ * => P = (2 Ekin + virial) / (3V)
+ */
+
+ /* assume up to date virial & up to date kinetic energy */
+
+ /* pressure (atom virials) */
+ moldyn->p=2.0*moldyn->ekin+moldyn->virial;
+ moldyn->p/=(3.0*moldyn->volume);
+
+ //moldyn->px=2.0*moldyn->ekinx+moldyn->vir.xx;
+ //moldyn->px/=moldyn->volume;
+ //moldyn->py=2.0*moldyn->ekiny+moldyn->vir.yy;
+ //moldyn->py/=moldyn->volume;
+ //moldyn->pz=2.0*moldyn->ekinz+moldyn->vir.zz;
+ //moldyn->pz/=moldyn->volume;
+
+ /* pressure (absolute coordinates) */
+ //moldyn->gp=2.0*moldyn->ekin+moldyn->gv;
+ //moldyn->gp/=(3.0*moldyn->volume);
+
+ return moldyn->p;
+}
+
+int average_reset(t_moldyn *moldyn) {
+
+ printf("[moldyn] average reset\n");
+
+ /* update skip value */
+ moldyn->avg_skip=moldyn->total_steps;
+
+ /* kinetic energy */
+ moldyn->k_sum=0.0;
+ moldyn->k2_sum=0.0;
+
+ /* potential energy */
+ moldyn->v_sum=0.0;
+ moldyn->v2_sum=0.0;
+
+ /* temperature */
+ moldyn->t_sum=0.0;
+
+ /* virial */
+ moldyn->virial_sum=0.0;
+ //moldyn->gv_sum=0.0;
+
+ /* pressure */
+ moldyn->p_sum=0.0;
+ //moldyn->gp_sum=0.0;
+ moldyn->tp_sum=0.0;
+
+ return 0;
+}
+
+int average_and_fluctuation_calc(t_moldyn *moldyn) {
+
+ int denom;
+
+ if(moldyn->total_steps<moldyn->avg_skip)
+ return 0;
+
+ denom=moldyn->total_steps+1-moldyn->avg_skip;
+
+ /* assume up to date energies, temperature, pressure etc */
+
+ /* kinetic energy */
+ moldyn->k_sum+=moldyn->ekin;
+ moldyn->k2_sum+=(moldyn->ekin*moldyn->ekin);
+ moldyn->k_avg=moldyn->k_sum/denom;
+ moldyn->k2_avg=moldyn->k2_sum/denom;
+ moldyn->dk2_avg=moldyn->k2_avg-(moldyn->k_avg*moldyn->k_avg);
+
+ /* potential energy */
+ moldyn->v_sum+=moldyn->energy;
+ moldyn->v2_sum+=(moldyn->energy*moldyn->energy);
+ moldyn->v_avg=moldyn->v_sum/denom;
+ moldyn->v2_avg=moldyn->v2_sum/denom;
+ moldyn->dv2_avg=moldyn->v2_avg-(moldyn->v_avg*moldyn->v_avg);
+
+ /* temperature */
+ moldyn->t_sum+=moldyn->t;
+ moldyn->t_avg=moldyn->t_sum/denom;
+
+ /* virial */
+ moldyn->virial_sum+=moldyn->virial;
+ moldyn->virial_avg=moldyn->virial_sum/denom;
+ //moldyn->gv_sum+=moldyn->gv;
+ //moldyn->gv_avg=moldyn->gv_sum/denom;
+
+ /* pressure */
+ moldyn->p_sum+=moldyn->p;
+ moldyn->p_avg=moldyn->p_sum/denom;
+ //moldyn->gp_sum+=moldyn->gp;
+ //moldyn->gp_avg=moldyn->gp_sum/denom;
+ moldyn->tp_sum+=moldyn->tp;
+ moldyn->tp_avg=moldyn->tp_sum/denom;
+
+ return 0;
+}
+
+int get_heat_capacity(t_moldyn *moldyn) {
+
+ double temp2,ighc;
+
+ /* averages needed for heat capacity calc */
+ if(moldyn->total_steps<moldyn->avg_skip)
+ return 0;
+
+ /* (temperature average)^2 */
+ temp2=moldyn->t_avg*moldyn->t_avg;
+ printf("[moldyn] specific heat capacity for T=%f K [J/(kg K)]\n",
+ moldyn->t_avg);
+
+ /* ideal gas contribution */
+ ighc=3.0*moldyn->count*K_BOLTZMANN/2.0;
+ printf(" ideal gas contribution: %f\n",
+ ighc/moldyn->mass*KILOGRAM/JOULE);
+
+ /* specific heat for nvt ensemble */
+ moldyn->c_v_nvt=moldyn->dv2_avg/(K_BOLTZMANN*temp2)+ighc;
+ moldyn->c_v_nvt/=moldyn->mass;
+
+ /* specific heat for nve ensemble */
+ moldyn->c_v_nve=ighc/(1.0-(moldyn->dv2_avg/(ighc*K_BOLTZMANN*temp2)));
+ moldyn->c_v_nve/=moldyn->mass;
+
+ printf(" NVE: %f\n",moldyn->c_v_nve*KILOGRAM/JOULE);
+ printf(" NVT: %f\n",moldyn->c_v_nvt*KILOGRAM/JOULE);
+printf(" --> <dV2> sim: %f experimental: %f\n",moldyn->dv2_avg,1.5*moldyn->count*K_B2*moldyn->t_avg*moldyn->t_avg*(1.0-1.5*moldyn->count*K_BOLTZMANN/(700*moldyn->mass*JOULE/KILOGRAM)));
+
+ return 0;
+}
+
+double thermodynamic_pressure_calc(t_moldyn *moldyn) {
+
+ t_3dvec dim;
+ //t_3dvec *tp;
+ double h,dv;
+ double y0,y1;
+ double su,sd;
+ t_atom *store;
+
+ /*
+ * dU = - p dV
+ *
+ * => p = - dU/dV
+ *
+ */
+
+ /* store atomic configuration + dimension */
+ store=malloc(moldyn->count*sizeof(t_atom));
+ if(store==NULL) {
+ printf("[moldyn] allocating store mem failed\n");
+ return -1;
+ }
+ memcpy(store,moldyn->atom,moldyn->count*sizeof(t_atom));
+ dim=moldyn->dim;
+
+ /* x1, y1 */
+ sd=0.00001;
+ h=(1.0-sd)*(1.0-sd)*(1.0-sd);
+ su=pow(2.0-h,ONE_THIRD)-1.0;
+ dv=(1.0-h)*moldyn->volume;
+
+ /* scale up dimension and atom positions */
+ scale_dim(moldyn,SCALE_UP,su,TRUE,TRUE,TRUE);
+ scale_atoms(moldyn,SCALE_UP,su,TRUE,TRUE,TRUE);
+ link_cell_shutdown(moldyn);
+ link_cell_init(moldyn,QUIET);
+ potential_force_calc(moldyn);
+ y1=moldyn->energy;
+
+ /* restore atomic configuration + dim */
+ memcpy(moldyn->atom,store,moldyn->count*sizeof(t_atom));
+ moldyn->dim=dim;
+
+ /* scale down dimension and atom positions */
+ scale_dim(moldyn,SCALE_DOWN,sd,TRUE,TRUE,TRUE);
+ scale_atoms(moldyn,SCALE_DOWN,sd,TRUE,TRUE,TRUE);
+ link_cell_shutdown(moldyn);
+ link_cell_init(moldyn,QUIET);
+ potential_force_calc(moldyn);
+ y0=moldyn->energy;
+
+ /* calculate pressure */
+ moldyn->tp=-(y1-y0)/(2.0*dv);
+
+ /* restore atomic configuration */
+ memcpy(moldyn->atom,store,moldyn->count*sizeof(t_atom));
+ moldyn->dim=dim;
+ link_cell_shutdown(moldyn);
+ link_cell_init(moldyn,QUIET);
+ //potential_force_calc(moldyn);
+
+ /* free store buffer */
+ if(store)
+ free(store);
+
+ return moldyn->tp;
+}
+
+double get_pressure(t_moldyn *moldyn) {
+
+ return moldyn->p;
+
+}
+
+int scale_dim(t_moldyn *moldyn,u8 dir,double scale,u8 x,u8 y,u8 z) {
+
+ t_3dvec *dim;
+
+ dim=&(moldyn->dim);
+
+ if(dir==SCALE_UP)
+ scale=1.0+scale;
+
+ if(dir==SCALE_DOWN)
+ scale=1.0-scale;
+
+ if(x) dim->x*=scale;
+ if(y) dim->y*=scale;
+ if(z) dim->z*=scale;
+
+ return 0;
+}
+
+int scale_atoms(t_moldyn *moldyn,u8 dir,double scale,u8 x,u8 y,u8 z) {
+
+ int i;
+ t_3dvec *r;
+
+ if(dir==SCALE_UP)
+ scale=1.0+scale;
+
+ if(dir==SCALE_DOWN)
+ scale=1.0-scale;
+
+ for(i=0;i<moldyn->count;i++) {
+ r=&(moldyn->atom[i].r);
+ if(x) r->x*=scale;
+ if(y) r->y*=scale;
+ if(z) r->z*=scale;
+ }
+
+ return 0;
+}
+
+int scale_atoms_ind(t_moldyn *moldyn,double x,double y,double z) {
+
+ int i;
+ t_3dvec *r;
+
+ for(i=0;i<moldyn->count;i++) {
+ r=&(moldyn->atom[i].r);
+ r->x*=x;
+ r->y*=y;
+ r->z*=z;
+ }
+
+ return 0;
+}
+
+int scale_dim_ind(t_moldyn *moldyn,double x,double y,double z) {
+
+ t_3dvec *dim;
+
+ dim=&(moldyn->dim);
+
+ dim->x*=x;
+ dim->y*=y;
+ dim->z*=z;
+
+ return 0;
+}
+
+int scale_volume(t_moldyn *moldyn) {
+
+ t_3dvec *dim,*vdim;
+ double scale;
+ t_linkcell *lc;
+ //double sx,sy,sz;
+
+ vdim=&(moldyn->vis.dim);
+ dim=&(moldyn->dim);