+ /* close file */
+ close(fd);
+
+ return 0;
+}
+
+int check_pressure(t_moldyn *moldyn,t_mdrun *mdrun) {
+
+ double delta;
+
+ if(!(mdrun->sattr&SATTR_PRELAX)) {
+ return TRUE;
+ }
+
+ delta=moldyn->p_avg-moldyn->p_ref;
+
+ if(delta<0)
+ delta=-delta;
+
+ if(delta>mdrun->dp)
+ return FALSE;
+
+ return TRUE;
+}
+
+int check_temperature(t_moldyn *moldyn,t_mdrun *mdrun) {
+
+ double delta;
+
+ if(!(mdrun->sattr&SATTR_TRELAX))
+ return TRUE;
+
+ delta=moldyn->t_avg-moldyn->t_ref;
+
+ if(delta<0)
+ delta=-delta;
+
+ if(delta>mdrun->dt)
+ return FALSE;
+
+ return TRUE;
+}
+
+int displace_atom(t_moldyn *moldyn,t_mdrun *mdrun) {
+
+ t_displace_atom_params *dap;
+ t_stage *stage;
+ t_atom *atom;
+
+ stage=mdrun->stage.current->data;
+ dap=stage->params;
+
+ atom=&(moldyn->atom[dap->nr]);
+ atom->r.x+=dap->dx;
+ atom->r.y+=dap->dy;
+ atom->r.z+=dap->dz;
+
+ return 0;
+}
+
+int del_atoms(t_moldyn *moldyn,t_mdrun *mdrun) {
+
+ t_stage *stage;
+ t_del_atoms_params *delp;
+ int i;
+ t_3dvec dist;
+
+ stage=mdrun->stage.current->data;
+ delp=stage->params;
+
+ for(i=0;i<moldyn->count;i++) {
+ v3_sub(&dist,&(delp->o),&(moldyn->atom[i].r));
+//printf("%d ----> %f %f %f = %f | %f\n",i,dist.x,dist.y,dist.z,v3_absolute_square(&dist),delp->r*delp->r);
+ if(v3_absolute_square(&dist)<=(delp->r*delp->r)) {
+ del_atom(moldyn,moldyn->atom[i].tag);
+ printf("%s atom deleted: %d %d %d\n",ME,
+ moldyn->atom[i].tag,moldyn->atom[i].element,
+ moldyn->atom[i].brand);
+ }
+ }
+
+ return 0;
+}
+
+int modify_atoms(t_moldyn *moldyn,t_mdrun *mdrun) {
+
+ t_modify_atoms_params *map;
+ t_stage *stage;
+ t_atom *atom;
+ t_3dvec v;
+ int i;
+
+ atom=moldyn->atom;
+ stage=mdrun->stage.current->data;
+ map=stage->params;
+ v.x=0.0; v.y=0.0; v.z=0.0;
+
+ for(i=0;i<moldyn->count;i++) {
+ if(atom[i].tag==map->tag) {
+ v.x=sqrt(2.0*fabs(map->ekin.x)/atom[i].mass);
+ if(map->ekin.x<0.0)
+ v.x=-v.x;
+ v.y=sqrt(2.0*fabs(map->ekin.y)/atom[i].mass);
+ if(map->ekin.y<0.0)
+ v.y=-v.y;
+ v.z=sqrt(2.0*fabs(map->ekin.z)/atom[i].mass);
+ if(map->ekin.z<0.0)
+ v.z=-v.z;
+ v3_copy(&(atom[i].v),&v);
+ printf("%s atom modified: v = (%f %f %f)\n",
+ ME,v.x,v.y,v.z);
+ }
+ }
+
+ return 0;
+}
+
+int insert_atoms(t_moldyn *moldyn,t_mdrun *mdrun) {
+
+ t_insert_atoms_params *iap;
+ t_stage *stage;
+ t_atom *atom;
+ t_3dvec r,v,dist;
+ double d,dmin,o;
+ int cnt,i;
+ double x,y,z;
+ double x0,y0,z0;
+ u8 cr_check,run;
+
+ stage=mdrun->stage.current->data;
+ iap=stage->params;
+
+ cr_check=FALSE;
+
+ v.x=0.0; v.y=0.0; v.z=0.0;
+ x=0; y=0; z=0;
+ o=0; dmin=0;
+
+ switch(mdrun->lattice) {
+ case CUBIC:
+ o=0.5*mdrun->lc;
+ break;
+ case FCC:
+ o=0.25*mdrun->lc;
+ break;
+ case DIAMOND:
+ case ZINCBLENDE:
+ o=0.125*mdrun->lc;
+ break;
+ default:
+ break;
+ }
+
+ switch(iap->type) {
+ case INS_TOTAL:
+ x=moldyn->dim.x;
+ x0=-x/2.0;
+ y=moldyn->dim.y;
+ y0=-y/2.0;
+ z=moldyn->dim.z;
+ z0=-z/2.0;
+ cr_check=TRUE;
+ break;
+ case INS_RECT:
+ x=iap->x1-iap->x0;
+ x0=iap->x0;
+ y=iap->y1-iap->y0;
+ y0=iap->y0;
+ z=iap->z1-iap->z0;
+ z0=iap->z0;
+ cr_check=TRUE;
+ break;
+ case INS_SPHERE:
+ x=2.0*iap->x1;
+ x0=iap->x0-iap->x1;
+ y=x;
+ y0=iap->y0-iap->x1;
+ z=x;
+ z0=iap->z0-iap->x1;
+ cr_check=TRUE;
+ break;
+ case INS_POS:
+ case INS_RELPOS:
+ x0=iap->x0;
+ y0=iap->y0;
+ z0=iap->z0;
+ cr_check=FALSE;
+ break;
+ default:
+ printf("%s unknown insertion mode: %02x\n",
+ ME,iap->type);
+ return -1;
+ }
+
+ cnt=0;
+ while(cnt<iap->ins_atoms) {
+ run=1;
+ while(run) {
+ if((iap->type!=INS_POS)&&(iap->type!=INS_RELPOS)) {
+ r.x=rand_get_double(&(moldyn->random))*x;
+ r.y=rand_get_double(&(moldyn->random))*y;
+ r.z=rand_get_double(&(moldyn->random))*z;
+ }
+ else {
+ r.x=0.0;
+ r.y=0.0;
+ r.z=0.0;
+ }
+ if(iap->type==INS_RELPOS) {
+ r.x+=x0*mdrun->lc;
+ r.y+=y0*mdrun->lc;
+ r.z+=z0*mdrun->lc;
+ }
+ else {
+ r.x+=x0;
+ r.y+=y0;
+ r.z+=z0;
+ }
+ // offset
+ if(iap->type!=INS_TOTAL) {
+ r.x+=o;
+ r.y+=o;
+ r.z+=o;
+ }
+ run=0;
+ if(cr_check==TRUE) {
+ dmin=1000; // for sure too high!
+ for(i=0;i<moldyn->count;i++) {
+ atom=&(moldyn->atom[i]);
+ v3_sub(&dist,&(atom->r),&r);
+ check_per_bound(moldyn,&dist);
+ d=v3_absolute_square(&dist);
+ if(d<(iap->cr*iap->cr)) {
+ run=1;
+ break;
+ }
+ if(d<dmin)
+ dmin=d;
+ }
+ }
+ if(iap->type==INS_SPHERE) {
+ if((r.x-iap->x0)*(r.x-iap->x0)+
+ (r.y-iap->y0)*(r.y-iap->y0)+
+ (r.z-iap->z0)*(r.z-iap->z0)>
+ (iap->x1*iap->x1)) {
+ run=1;
+ }
+ }
+ }
+ add_atom(moldyn,iap->element,
+ iap->brand,iap->attr,&r,&v);
+ printf("%s atom inserted (%d/%d): %f %f %f\n",
+ ME,(iap->cnt_steps+1)*iap->ins_atoms,
+ iap->ins_steps*iap->ins_atoms,r.x,r.y,r.z);
+ printf(" attributes: ");
+ if(iap->attr&ATOM_ATTR_VB)
+ printf("b ");
+ if(iap->attr&ATOM_ATTR_HB)
+ printf("h ");
+ if(iap->attr&ATOM_ATTR_VA)
+ printf("v ");
+ if(iap->attr&ATOM_ATTR_FP)
+ printf("f ");
+ if(iap->attr&ATOM_ATTR_1BP)
+ printf("1 ");
+ if(iap->attr&ATOM_ATTR_2BP)
+ printf("2 ");
+ if(iap->attr&ATOM_ATTR_3BP)
+ printf("3 ");
+ printf("\n");
+ printf(" d2 = %f/%f\n",dmin,iap->cr*iap->cr);
+ cnt+=1;
+ }
+
+ return 0;
+}
+
+int insert_mixed_atoms(t_moldyn *moldyn,t_mdrun *mdrun) {
+
+ t_stage *stage;
+ t_insert_mixed_atoms_params *imp;
+ t_atom *atom;
+ double x,x0,y,y0,z,z0;
+ double dmin,d,cmin,cmax;
+ u8 retry;
+ t_3dvec r,v,dist;
+ int i;
+
+
+ stage=mdrun->stage.current->data;
+ imp=stage->params;
+
+ x=moldyn->dim.x;
+ x0=-x/2.0;
+ y=moldyn->dim.y;
+ y0=-y/2.0;
+ z=moldyn->dim.z;
+ z0=-z/2.0;
+
+ v.x=0.0;
+ v.y=0.0;
+ v.z=0.0;
+
+ cmin=imp->crmin*imp->crmin;
+ cmax=imp->crmax*imp->crmax;
+
+ while(imp->amount1|imp->amount2) {
+ if(imp->amount1) {
+ retry=1;
+ while(retry) {
+ retry=0;
+ r.x=rand_get_double(&(moldyn->random))*x;
+ r.y=rand_get_double(&(moldyn->random))*y;
+ r.z=rand_get_double(&(moldyn->random))*z;
+ r.x+=x0;
+ r.y+=y0;
+ r.z+=z0;
+ dmin=1000.0; // for sure too high!
+ for(i=0;i<moldyn->count;i++) {
+ atom=&(moldyn->atom[i]);
+ v3_sub(&dist,&(atom->r),&r);
+ check_per_bound(moldyn,&dist);
+ d=v3_absolute_square(&dist);
+ if(d<cmin) {
+ retry=1;
+ break;
+ }
+ if(d<dmin)
+ dmin=d;
+ }
+ if(dmin!=1000.0)
+ if(dmin>cmax)
+ retry=1;
+ }
+ add_atom(moldyn,imp->element1,
+ imp->brand1,imp->attr1,&r,&v);
+ printf("%s (mixed) atom inserted (%d): %f %f %f\n",
+ ME,imp->amount1,r.x,r.y,r.z);
+ printf(" -> d2 = %f/%f/%f\n",dmin,cmin,cmax);
+ imp->amount1-=1;
+ }
+ if(imp->amount2) {
+ retry=1;
+ while(retry) {
+ retry=0;
+ r.x=rand_get_double(&(moldyn->random))*x;
+ r.y=rand_get_double(&(moldyn->random))*y;
+ r.z=rand_get_double(&(moldyn->random))*z;
+ r.x+=x0;
+ r.y+=y0;
+ r.z+=z0;
+ dmin=1000.0; // for sure too high!
+ for(i=0;i<moldyn->count;i++) {
+ atom=&(moldyn->atom[i]);
+ v3_sub(&dist,&(atom->r),&r);
+ check_per_bound(moldyn,&dist);
+ d=v3_absolute_square(&dist);
+ if(d<cmin) {
+ retry=1;
+ break;
+ }
+ if(d<dmin)
+ dmin=d;
+ }
+ if(dmin!=1000.0)
+ if(dmin>cmax)
+ retry=1;
+ }
+ add_atom(moldyn,imp->element2,
+ imp->brand2,imp->attr2,&r,&v);
+ printf("%s (mixed) atom inserted (%d): %f %f %f\n",
+ ME,imp->amount2,r.x,r.y,r.z);
+ printf(" -> d2 = %f/%f/%f\n",dmin,cmin,cmax);
+ imp->amount2-=1;
+ }
+ }
+
+ return 0;
+}
+
+int chaatr(t_moldyn *moldyn,t_mdrun *mdrun) {
+
+ t_stage *stage;
+ t_chaattr_params *cap;
+ t_atom *atom;
+ int i;
+
+ stage=mdrun->stage.current->data;
+ cap=stage->params;
+
+ for(i=0;i<moldyn->count;i++) {
+ atom=&(moldyn->atom[i]);
+ if(cap->type&CHAATTR_ELEMENT) {
+ if(cap->element!=atom->element)
+ continue;
+ }
+ if(cap->type&CHAATTR_NUMBER) {
+ if(cap->element!=atom->tag)
+ continue;
+ }
+ if(cap->type&CHAATTR_REGION) {
+ if(cap->x0>atom->r.x)
+ continue;
+ if(cap->y0>atom->r.y)
+ continue;
+ if(cap->z0>atom->r.z)
+ continue;
+ if(cap->x1<atom->r.x)
+ continue;
+ if(cap->y1<atom->r.y)
+ continue;
+ if(cap->z1<atom->r.z)
+ continue;
+ }
+ if(!(cap->type&CHAATTR_TOTALV))
+ printf(" changing attributes of atom %d (0x%x)\n",
+ i,cap->attr);
+ atom->attr=cap->attr;
+ }
+
+ printf("\n\n");
+
+ return 0;
+}
+
+int chsattr(t_moldyn *moldyn,t_mdrun *mdrun) {
+
+ t_stage *stage;
+ t_chsattr_params *csp;
+
+ stage=mdrun->stage.current->data;
+ csp=stage->params;
+
+ if(csp->type&CHSATTR_PCTRL) {
+ if(csp->ptau>0)
+ set_p_scale(moldyn,P_SCALE_BERENDSEN,csp->ptau);
+ else
+ set_p_scale(moldyn,P_SCALE_NONE,1.0);
+ }
+ if(csp->type&CHSATTR_TCTRL) {
+ if(csp->ttau>0)
+ set_t_scale(moldyn,T_SCALE_BERENDSEN,csp->ttau);
+ else
+ set_t_scale(moldyn,T_SCALE_NONE,1.0);
+ }
+ if(csp->type&CHSATTR_PRELAX) {
+ if(csp->dp<0)
+ mdrun->sattr&=(~(SATTR_PRELAX));
+ else
+ mdrun->sattr|=SATTR_PRELAX;
+ mdrun->dp=csp->dp;
+ }
+ if(csp->type&CHSATTR_TRELAX) {
+ if(csp->dt<0)
+ mdrun->sattr&=(~(SATTR_TRELAX));
+ else
+ mdrun->sattr|=SATTR_TRELAX;
+ mdrun->dt=csp->dt;
+ }
+ if(csp->type&CHSATTR_AVGRST) {
+ if(csp->avgrst)
+ mdrun->sattr|=SATTR_AVGRST;
+ else
+ mdrun->sattr&=(~(SATTR_AVGRST));
+ }
+ if(csp->type&CHSATTR_RSTEPS) {
+ mdrun->relax_steps=csp->rsteps;
+ }
+
+ return 0;
+}
+
+int crt(t_moldyn *moldyn,t_mdrun *mdrun) {
+
+ t_stage *stage;
+ t_crt_params *crtp;
+
+ int fd;
+ char line[128];
+ char *wptr;
+ int acount;
+ int ret;
+ void *ptr;
+
+ t_atom *atom;
+ t_3dvec disp;
+ double frac;
+ int i;
+
+ stage=mdrun->stage.current->data;
+ crtp=stage->params;
+
+ acount=0;
+
+ /* initial stuff */
+
+ if(crtp->count==0) {
+ printf(" crt init\n");
+ // read final positions, constraints and do the alloc
+ fd=open(crtp->file,O_RDONLY);
+ if(fd<0) {
+ perror("[mdrun] FATAL reading constraints file");
+ return fd;
+ }
+ while(1) {
+ ret=get_line(fd,line,128);
+ // check for end of file
+ if(ret<=0) {
+ printf(" read %d atom positions\n",acount);
+ if(acount!=moldyn->count)
+ printf(" atom count mismatch!!!\n");
+ printf("\n");
+ break;
+ }
+ // ignore # lines and \n
+ if((line[0]=='#')|(ret==1))
+ continue;
+ // allocate new memory
+ ptr=realloc(crtp->r_fin,(acount+1)*sizeof(t_3dvec));
+ if(ptr==NULL) {
+ perror("[mdrun] FATAL realloc crt positions");
+ return -1;
+ }
+ crtp->r_fin=ptr;
+ ptr=realloc(constraints,(acount+1)*3*sizeof(u8));
+ if(ptr==NULL) {
+ perror("[mdrun] FATAL realloc crt constraints");
+ return -1;
+ }
+ constraints=ptr;
+ // ignore type
+ wptr=strtok(line," \t");
+ // read x y z
+ wptr=strtok(NULL," \t");
+ crtp->r_fin[acount].x=atof(wptr);
+ wptr=strtok(NULL," \t");
+ crtp->r_fin[acount].y=atof(wptr);
+ wptr=strtok(NULL," \t");
+ crtp->r_fin[acount].z=atof(wptr);
+ // read constraints
+ wptr=strtok(NULL," \t");
+ constraints[3*acount]=atoi(wptr);
+ wptr=strtok(NULL," \t");
+ constraints[3*acount+1]=atoi(wptr);
+ wptr=strtok(NULL," \t");
+ constraints[3*acount+2]=atoi(wptr);
+ // done reading
+ acount+=1;
+ }
+ close(fd);
+ // allocate trafo angles
+ trafo_angle=malloc(acount*2*sizeof(double));
+ if(trafo_angle==NULL) {
+ perror("[mdrun] FATAL alloc trafo angles");
+ return -1;
+ }
+ // set crt mode
+ crtt=crtp->type;
+ }
+
+ /* write a save file s-crt_xofy.save */
+ snprintf(line,128,"%s/s-crt_%03dof%03d.save",
+ moldyn->vlsdir,crtp->count,crtp->steps);
+ fd=open(line,O_WRONLY|O_TRUNC|O_CREAT,S_IRUSR|S_IWUSR);
+ if(fd<0) perror("[mdrun] crt save fd open");
+ else {
+ write(fd,moldyn,sizeof(t_moldyn));
+ write(fd,moldyn->atom,
+ moldyn->count*sizeof(t_atom));
+ }
+ close(fd);
+
+ /* output energy */
+ printf(" crt energy: %d - %f\n\n",
+ crtp->count,(moldyn->ekin+moldyn->energy)/EV);
+
+ /* crt routines: calculate displacement + set individual constraints */
+
+ printf(" crt step %d of %d in total\n\n",crtp->count+1,crtp->steps);
+
+ if((crtp->type==1)|(crtp->count==0))
+ printf(" crt angle update\n\n");
+
+ for(i=0;i<moldyn->count;i++) {
+ // calc displacements
+ atom=moldyn->atom;
+ v3_sub(&disp,&(crtp->r_fin[i]),&(atom[i].r));
+ // angles
+ if((crtp->type==1)|(crtp->count==0)) {
+ trafo_angle[2*i]=atan2(disp.x,disp.y);
+ trafo_angle[2*i+1]=-atan2(disp.z,
+ sqrt(disp.x*disp.x+disp.y*disp.y));
+ }
+ // move atoms
+ frac=1.0/(crtp->steps-crtp->count);
+ v3_scale(&disp,&disp,frac);
+ v3_add(&(atom[i].r),&(atom[i].r),&disp);
+ }
+
+ return 0;
+}
+
+#define stage_print(m) if(!(stage->executed)) \
+ printf("%s",m)
+
+int mdrun_hook(void *ptr1,void *ptr2) {
+
+ t_moldyn *moldyn;
+ t_mdrun *mdrun;
+ t_stage *stage;
+ t_list *sl;
+ int steps;
+ u8 change_stage;
+ t_3dvec o;
+
+ t_insert_atoms_params *iap;
+ t_insert_mixed_atoms_params *imp;
+ t_continue_params *cp;
+ t_anneal_params *ap;
+ t_set_temp_params *stp;
+ t_set_timestep_params *stsp;
+ t_fill_params *fp;
+ t_crt_params *crtp;
+
+ moldyn=ptr1;
+ mdrun=ptr2;
+
+ sl=&(mdrun->stage);
+
+ change_stage=FALSE;
+
+ /* return immediately if there are no more stage */
+ if(sl->current==NULL)
+ return 0;
+
+ /* get stage description */
+ stage=sl->current->data;
+
+ /* steps in next schedule */
+ steps=mdrun->relax_steps;
+
+ /* check whether relaxation steps are necessary */
+ if((check_pressure(moldyn,mdrun)==TRUE)&\
+ (check_temperature(moldyn,mdrun)==TRUE)) {
+
+ /* be verbose */
+ stage_print("\n###########################\n");
+ stage_print("# [mdrun] executing stage #\n");
+ stage_print("###########################\n\n");
+
+ /* stage specific stuff */
+ switch(stage->type) {
+ case STAGE_DISPLACE_ATOM:
+ stage_print(" -> displace atom\n\n");
+ displace_atom(moldyn,mdrun);
+ change_stage=TRUE;
+ break;
+ case STAGE_DEL_ATOMS:
+ stage_print(" -> del atoms\n\n");
+ del_atoms(moldyn,mdrun);
+ change_stage=TRUE;
+ break;
+ case STAGE_MODIFY_ATOMS:
+ stage_print(" -> modify atoms\n\n");
+ modify_atoms(moldyn,mdrun);
+ change_stage=TRUE;
+ break;
+ case STAGE_INSERT_ATOMS:
+ stage_print(" -> insert atoms\n\n");
+ iap=stage->params;
+ if(iap->cnt_steps==iap->ins_steps) {
+ change_stage=TRUE;
+ break;
+ }
+ insert_atoms(moldyn,mdrun);
+ iap->cnt_steps+=1;
+ break;
+
+
+
+ case STAGE_INSERT_MIXED_ATOMS:
+ stage_print(" -> insert mixed atoms\n\n");
+ imp=stage->params;
+ insert_mixed_atoms(moldyn,mdrun);
+ change_stage=TRUE;
+ break;
+
+
+
+ case STAGE_CONTINUE:
+ stage_print(" -> continue\n\n");
+ if(stage->executed==TRUE) {
+ change_stage=TRUE;
+ break;
+ }
+ cp=stage->params;
+ steps=cp->runs;
+ break;
+ case STAGE_ANNEAL:
+ stage_print(" -> anneal\n\n");
+ ap=stage->params;
+ if(ap->count==ap->runs) {
+ change_stage=TRUE;
+ break;
+ }
+ if(moldyn->t_ref+ap->dt>=0.0)
+ set_temperature(moldyn,
+ moldyn->t_ref+ap->dt);
+ ap->count+=1;
+ steps=ap->interval;
+ break;
+ case STAGE_CHAATTR:
+ stage_print(" -> change atom attributes\n\n");
+ chaatr(moldyn,mdrun);
+ change_stage=TRUE;
+ break;
+ case STAGE_CHSATTR:
+ stage_print(" -> change sys attributes\n\n");
+ chsattr(moldyn,mdrun);
+ change_stage=TRUE;
+ break;
+ case STAGE_SET_TEMP:
+ stage_print(" -> set temperature\n\n");
+ stp=stage->params;
+ if(stp->type&SET_TEMP_CURRENT) {
+ set_temperature(moldyn,moldyn->t_avg);
+ }
+ else {
+ set_temperature(moldyn,stp->val);
+ }
+ change_stage=TRUE;
+ break;
+ case STAGE_SET_TIMESTEP:
+ stage_print(" -> set timestep\n\n");
+ stsp=stage->params;
+ mdrun->timestep=stsp->tau;
+ change_stage=TRUE;
+ break;
+ case STAGE_FILL:
+ stage_print(" -> fill lattice\n\n");
+ fp=stage->params;
+ switch(fp->lattice) {
+ case ZINCBLENDE:
+
+ o.x=0.5*0.25*fp->lc;
+ o.y=o.x;
+ o.z=o.x;
+ create_lattice(moldyn,
+ FCC,fp->lc,
+ mdrun->element1,
+ DEFAULT_ATOM_ATTR,0,
+ fp->lx,fp->ly,fp->lz,
+ &o,
+ &(fp->p_params),
+ &(fp->d_params),
+ &(fp->o_params));
+ o.x+=0.25*fp->lc;
+ o.y=o.x;
+ o.z=o.x;
+ create_lattice(moldyn,
+ FCC,fp->lc,
+ mdrun->element2,
+ DEFAULT_ATOM_ATTR,1,
+ fp->lx,fp->ly,fp->lz,
+ &o,
+ &(fp->p_params),
+ &(fp->d_params),
+ &(fp->o_params));
+ break;
+
+ default:
+
+ create_lattice(moldyn,
+ fp->lattice,fp->lc,
+ fp->fill_element,
+ DEFAULT_ATOM_ATTR,
+ fp->fill_brand,
+ fp->lx,fp->ly,fp->lz,
+ NULL,
+ &(fp->p_params),
+ &(fp->d_params),
+ &(fp->o_params));
+ break;
+ }
+ moldyn_bc_check(moldyn);
+ change_stage=TRUE;
+ break;
+ case STAGE_THERMAL_INIT:
+ stage_print(" -> thermal init\n\n");
+ thermal_init(moldyn,TRUE);
+ change_stage=TRUE;
+ break;
+ case STAGE_CRT:
+ stage_print(" -> constraint relaxation");
+ stage_print(" technique\n\n");
+ crtp=stage->params;
+ if(crtp->count==crtp->steps) {
+ free(constraints);
+ free(trafo_angle);
+ free(crtp->r_fin);
+ change_stage=TRUE;
+ break;
+ }
+ crt(moldyn,mdrun);
+ crtp->count+=1;
+ break;
+ default:
+ printf("%s unknwon stage type\n",ME);
+ break;
+ }
+
+ /* mark as executed */
+ stage->executed=TRUE;
+
+ /* change state */
+ if(change_stage==TRUE) {
+ printf("%s finished stage\n",ME);
+ if(list_next_f(sl)==L_NO_NEXT_ELEMENT) {
+ printf("%s no more stages\n",ME);
+ return 0;
+ }
+ steps=0;
+ }
+
+ }
+ else {
+
+ /* averages */
+ if(mdrun->sattr&SATTR_AVGRST)
+ average_reset(moldyn);
+
+ }
+
+ /* continue simulation */
+ moldyn_add_schedule(moldyn,steps,mdrun->timestep);
+