2 * mdrun.c - main code to run a md simulation
4 * author: Frank Zirkelbach <frank.zirkelbach@physik.uni-augsburg.de>
11 #include "potentials/harmonic_oscillator.h"
12 #include "potentials/lennard_jones.h"
13 #include "potentials/albe.h"
15 #include "potentials/tersoff_orig.h"
17 #include "potentials/tersoff.h"
31 int mdrun_usage(void) {
33 printf("%s usage:\n",ME);
38 int mdrun_parse_argv(t_mdrun *mdrun,int argc,char **argv) {
45 printf("%s unknown switch: %s\n",ME,argv[i]);
51 strncpy(mdrun->cfile,argv[++i],128);
54 strncpy(mdrun->sdir,argv[++i],128);
60 printf("%s unknown option: %s\n",ME,argv[i]);
70 int del_stages(t_mdrun *mdrun) {
83 stage=sl->current->data;
86 } while(list_next_f(sl)!=L_NO_NEXT_ELEMENT);
91 int add_stage(t_mdrun *mdrun,u8 type,void *params) {
98 case STAGE_DISPLACE_ATOM:
99 psize=sizeof(t_displace_atom_params);
101 case STAGE_DEL_ATOMS:
102 psize=sizeof(t_del_atoms_params);
104 case STAGE_INSERT_ATOMS:
105 psize=sizeof(t_insert_atoms_params);
107 case STAGE_INSERT_MIXED_ATOMS:
108 psize=sizeof(t_insert_mixed_atoms_params);
111 psize=sizeof(t_continue_params);
114 psize=sizeof(t_anneal_params);
117 psize=sizeof(t_chaattr_params);
120 psize=sizeof(t_chsattr_params);
123 psize=sizeof(t_set_temp_params);
125 case STAGE_SET_TIMESTEP:
126 psize=sizeof(t_set_timestep_params);
129 psize=sizeof(t_fill_params);
131 case STAGE_THERMAL_INIT:
135 printf("%s unknown stage type: %02x\n",ME,type);
139 stage=malloc(sizeof(t_stage));
141 perror("[mdrun] malloc (add stage)");
146 stage->executed=FALSE;
148 stage->params=malloc(psize);
149 if(stage->params==NULL) {
150 perror("[mdrun] malloc (stage params)");
154 memcpy(stage->params,params,psize);
156 list_add_immediate_f(&(mdrun->stage),stage);
161 int mdrun_parse_config(t_mdrun *mdrun) {
171 t_displace_atom_params dap;
172 t_insert_atoms_params iap;
173 t_insert_mixed_atoms_params imp;
174 t_continue_params cp;
176 t_chaattr_params cap;
177 t_chsattr_params csp;
178 t_set_temp_params stp;
179 t_set_timestep_params stsp;
181 t_del_atoms_params delp;
183 /* open config file */
184 fd=open(mdrun->cfile,O_RDONLY);
186 snprintf(error,128,"%s open cfile %s",ME,mdrun->cfile);
191 /* read, parse, set */
196 ret=get_line(fd,line,128);
200 // ignore # lines and \n
201 if((line[0]=='#')|(ret==1))
205 memset(&iap,0,sizeof(t_insert_atoms_params));
206 memset(&imp,0,sizeof(t_insert_mixed_atoms_params));
207 memset(&cp,0,sizeof(t_continue_params));
208 memset(&ap,0,sizeof(t_anneal_params));
209 memset(&cap,0,sizeof(t_chaattr_params));
210 memset(&csp,0,sizeof(t_chsattr_params));
211 memset(&stp,0,sizeof(t_set_temp_params));
212 memset(&stsp,0,sizeof(t_set_timestep_params));
213 memset(&fp,0,sizeof(t_fill_params));
214 memset(&delp,0,sizeof(t_del_atoms_params));
216 // get command + args
220 wptr=strtok(NULL," \t");
222 wptr=strtok(line," \t");
225 strncpy(word[wcnt],wptr,64);
229 if(!strncmp(word[0],"potential",9)) {
230 if(!strncmp(word[1],"albe",4))
231 mdrun->potential=MOLDYN_POTENTIAL_AM;
232 if(!strncmp(word[1],"tersoff",7))
233 mdrun->potential=MOLDYN_POTENTIAL_TM;
234 if(!strncmp(word[1],"ho",2))
235 mdrun->potential=MOLDYN_POTENTIAL_HO;
236 if(!strncmp(word[1],"lj",2))
237 mdrun->potential=MOLDYN_POTENTIAL_LJ;
239 else if(!strncmp(word[0],"continue",8))
240 strncpy(mdrun->continue_file,word[1],128);
241 else if(!strncmp(word[0],"cutoff",6))
242 mdrun->cutoff=atof(word[1]);
243 else if(!strncmp(word[0],"nnd",3))
244 mdrun->nnd=atof(word[1]);
245 else if(!strncmp(word[0],"intalgo",7)) {
246 if(!strncmp(word[1],"verlet",5))
247 mdrun->intalgo=MOLDYN_INTEGRATE_VERLET;
249 else if(!strncmp(word[0],"timestep",8))
250 mdrun->timestep=atof(word[1]);
251 else if(!strncmp(word[0],"volume",6)) {
252 mdrun->dim.x=atof(word[1]);
253 mdrun->dim.y=atof(word[2]);
254 mdrun->dim.z=atof(word[3]);
255 if(strncmp(word[4],"0",1))
258 else if(!strncmp(word[0],"pbc",3)) {
259 if(strncmp(word[1],"0",1))
263 if(strncmp(word[2],"0",1))
267 if(strncmp(word[3],"0",1))
272 else if(!strncmp(word[0],"temperature",11))
273 mdrun->temperature=atof(word[1]);
274 else if(!strncmp(word[0],"pressure",8))
275 mdrun->pressure=atof(word[1]);
276 else if(!strncmp(word[0],"lattice",7)) {
277 if(!strncmp(word[1],"zincblende",10))
278 mdrun->lattice=ZINCBLENDE;
279 if(!strncmp(word[1],"fcc",3))
281 if(!strncmp(word[1],"diamond",7))
282 mdrun->lattice=DIAMOND;
283 if(!strncmp(word[1],"none",4))
286 mdrun->lc=atof(word[2]);
288 else if(!strncmp(word[0],"element1",8)) {
289 mdrun->element1=atoi(word[1]);
291 else if(!strncmp(word[0],"element2",8)) {
292 mdrun->element2=atoi(word[1]);
294 else if(!strncmp(word[0],"fill",6)) {
296 fp.fill_element=mdrun->element1;
298 fp.lattice=mdrun->lattice;
302 // parse fill command
305 if(!strncmp(word[i],"lc",2)) {
306 fp.lx=atoi(word[++i]);
307 fp.ly=atoi(word[++i]);
308 fp.lz=atoi(word[++i]);
309 fp.lc=atof(word[++i]);
312 if(!strncmp(word[i],"eb",2)) {
313 fp.fill_element=atoi(word[++i]);
314 fp.fill_brand=atoi(word[++i]);
316 if(word[i][0]=='p') {
321 fp.p_params.type=PART_INSIDE_R;
323 fp.p_params.type=PART_INSIDE_D;
327 fp.p_params.type=PART_OUTSIDE_R;
329 fp.p_params.type=PART_OUTSIDE_D;
334 if((fp.p_params.type==PART_INSIDE_R)||
335 (fp.p_params.type==PART_OUTSIDE_R)) {
336 fp.p_params.r=atof(word[++i]);
337 fp.p_params.p.x=atof(word[++i]);
338 fp.p_params.p.y=atof(word[++i]);
339 fp.p_params.p.z=atof(word[++i]);
341 if((fp.p_params.type==PART_INSIDE_D)||
342 (fp.p_params.type==PART_OUTSIDE_D)) {
343 fp.p_params.p.x=atof(word[++i]);
344 fp.p_params.p.y=atof(word[++i]);
345 fp.p_params.p.z=atof(word[++i]);
346 fp.p_params.d.x=atof(word[++i]);
347 fp.p_params.d.y=atof(word[++i]);
348 fp.p_params.d.z=atof(word[++i]);
351 if(word[i][0]=='d') {
352 switch(word[++i][0]) {
355 fp.d_params.type=DEFECT_TYPE_0D;
356 if(!strncmp(word[i+1],"dbx",3)) {
357 fp.d_params.stype=DEFECT_STYPE_DB_X;
359 if(!strncmp(word[i+1],"dby",3)) {
360 fp.d_params.stype=DEFECT_STYPE_DB_Y;
362 if(!strncmp(word[i+1],"dbz",3)) {
363 fp.d_params.stype=DEFECT_STYPE_DB_Z;
365 if(!strncmp(word[i+1],"dbr",3)) {
366 fp.d_params.stype=DEFECT_STYPE_DB_R;
369 fp.d_params.od=atof(word[++i]);
370 fp.d_params.dd=atof(word[++i]);
371 fp.d_params.element=atoi(word[++i]);
372 fp.d_params.brand=atoi(word[++i]);
374 fp.d_params.attr=ATOM_ATTR_HB|ATOM_ATTR_VA;
375 fp.d_params.attr|=ATOM_ATTR_1BP|ATOM_ATTR_2BP|ATOM_ATTR_3BP;
379 fp.d_params.type=DEFECT_TYPE_1D;
382 fp.d_params.type=DEFECT_TYPE_2D;
385 fp.d_params.type=DEFECT_TYPE_3D;
394 add_stage(mdrun,STAGE_FILL,&fp);
396 else if(!strncmp(word[0],"thermal_init",12)) {
397 add_stage(mdrun,STAGE_THERMAL_INIT,NULL);
399 else if(!strncmp(word[0],"aattr",5)) {
400 // for aatrib line we need a special stage
401 // containing one schedule of 0 loops ...
402 for(i=0;i<strlen(word[1]);i++) {
405 cap.type|=CHAATTR_TOTALV;
408 cap.type|=CHAATTR_REGION;
411 cap.type|=CHAATTR_ELEMENT;
418 if(cap.type&CHAATTR_REGION) {
419 cap.x0=atof(word[1]);
420 cap.y0=atof(word[2]);
421 cap.z0=atof(word[3]);
422 cap.x1=atof(word[4]);
423 cap.y1=atof(word[5]);
424 cap.z1=atof(word[6]);
427 if(cap.type&CHAATTR_ELEMENT) {
428 cap.element=atoi(word[i]);
431 for(o=0;o<strlen(word[i]);o++) {
434 cap.attr|=ATOM_ATTR_VB;
437 cap.attr|=ATOM_ATTR_HB;
440 cap.attr|=ATOM_ATTR_VA;
443 cap.attr|=ATOM_ATTR_FP;
446 cap.attr|=ATOM_ATTR_1BP;
449 cap.attr|=ATOM_ATTR_2BP;
452 cap.attr|=ATOM_ATTR_3BP;
458 add_stage(mdrun,STAGE_CHAATTR,&cap);
460 else if(!strncmp(word[0],"sattr",5)) {
461 // for satrib line we need a special stage
462 // containing one schedule of 0 loops ...
464 for(i=1;i<wcnt;i++) {
465 if(!strncmp(word[i],"pctrl",5)) {
466 csp.ptau=0.01/(atof(word[++i])*GPA);
467 csp.type|=CHSATTR_PCTRL;
469 if(!strncmp(word[i],"tctrl",5)) {
470 csp.ttau=atof(word[++i]);
471 csp.type|=CHSATTR_TCTRL;
473 if(!strncmp(word[i],"prelax",6)) {
474 csp.dp=atof(word[++i])*BAR;
475 csp.type|=CHSATTR_PRELAX;
477 if(!strncmp(word[i],"trelax",6)) {
478 csp.dt=atof(word[++i]);
479 csp.type|=CHSATTR_TRELAX;
481 if(!strncmp(word[i],"rsteps",6)) {
482 csp.rsteps=atoi(word[++i]);
483 csp.type|=CHSATTR_RSTEPS;
485 if(!strncmp(word[i],"avgrst",6)) {
486 csp.avgrst=atoi(word[++i]);
487 csp.type|=CHSATTR_AVGRST;
490 add_stage(mdrun,STAGE_CHSATTR,&csp);
492 else if(!strncmp(word[0],"prerun",6))
493 mdrun->prerun=atoi(word[1]);
494 else if(!strncmp(word[0],"avgskip",7))
495 mdrun->avgskip=atoi(word[1]);
496 else if(!strncmp(word[0],"elog",4))
497 mdrun->elog=atoi(word[1]);
498 else if(!strncmp(word[0],"tlog",4))
499 mdrun->tlog=atoi(word[1]);
500 else if(!strncmp(word[0],"plog",4))
501 mdrun->plog=atoi(word[1]);
502 else if(!strncmp(word[0],"vlog",4))
503 mdrun->vlog=atoi(word[1]);
504 else if(!strncmp(word[0],"save",4))
505 mdrun->save=atoi(word[1]);
506 else if(!strncmp(word[0],"visualize",9))
507 mdrun->visualize=atoi(word[1]);
508 else if(!strncmp(word[0],"stage",5)) {
509 // for every stage line, add a stage
510 if(!strncmp(word[1],"displace",8)) {
511 dap.nr=atoi(word[2]);
512 dap.dx=atof(word[3]);
513 dap.dy=atof(word[4]);
514 dap.dz=atof(word[5]);
515 add_stage(mdrun,STAGE_DISPLACE_ATOM,&dap);
517 else if(!strncmp(word[1],"del_atoms",9)) {
518 delp.o.x=atof(word[2]);
519 delp.o.y=atof(word[3]);
520 delp.o.z=atof(word[4]);
521 delp.r=atof(word[5]);
522 add_stage(mdrun,STAGE_DEL_ATOMS,&delp);
524 else if(!strncmp(word[1],"ins_atoms",9)) {
525 iap.ins_steps=atoi(word[2]);
526 iap.ins_atoms=atoi(word[3]);
527 iap.element=atoi(word[4]);
528 iap.brand=atoi(word[5]);
529 for(i=0;i<strlen(word[6]);i++) {
532 iap.attr|=ATOM_ATTR_VB;
535 iap.attr|=ATOM_ATTR_HB;
538 iap.attr|=ATOM_ATTR_VA;
541 iap.attr|=ATOM_ATTR_FP;
544 iap.attr|=ATOM_ATTR_1BP;
547 iap.attr|=ATOM_ATTR_2BP;
550 iap.attr|=ATOM_ATTR_3BP;
560 iap.x0=atof(word[8]);
561 iap.y0=atof(word[9]);
562 iap.z0=atof(word[10]);
569 iap.cr=atof(word[9]);
573 iap.x0=atof(word[9]);
574 iap.y0=atof(word[10]);
575 iap.z0=atof(word[11]);
576 iap.x1=atof(word[12]);
577 iap.y1=atof(word[13]);
578 iap.z1=atof(word[14]);
579 iap.cr=atof(word[15]);
583 iap.x0=atof(word[9]);
584 iap.y0=atof(word[10]);
585 iap.z0=atof(word[11]);
586 iap.x1=atof(word[12]);
587 iap.cr=atof(word[13]);
595 add_stage(mdrun,STAGE_INSERT_ATOMS,&iap);
601 else if(!strncmp(word[1],"ins_m_atoms",11)) {
602 imp.element1=atoi(word[2]);
603 imp.element2=atoi(word[3]);
604 imp.amount1=atoi(word[4]);
605 imp.amount2=atoi(word[5]);
606 imp.brand1=atoi(word[6]);
607 imp.brand2=atoi(word[7]);
608 imp.crmin=atof(word[8]);
609 imp.crmax=atof(word[9]);
611 for(i=0;i<strlen(word[8]);i++) {
614 imp.attr|=ATOM_ATTR_VB;
617 imp.attr|=ATOM_ATTR_HB;
620 imp.attr|=ATOM_ATTR_VA;
623 imp.attr|=ATOM_ATTR_FP;
626 imp.attr|=ATOM_ATTR_1BP;
629 imp.attr|=ATOM_ATTR_2BP;
632 imp.attr|=ATOM_ATTR_3BP;
639 imp.attr1=ATOM_ATTR_HB|ATOM_ATTR_VA|ATOM_ATTR_1BP|ATOM_ATTR_2BP|ATOM_ATTR_3BP|ATOM_ATTR_FP;
640 imp.attr2=ATOM_ATTR_HB|ATOM_ATTR_VA|ATOM_ATTR_1BP|ATOM_ATTR_2BP|ATOM_ATTR_3BP|ATOM_ATTR_FP;
641 add_stage(mdrun,STAGE_INSERT_MIXED_ATOMS,&imp);
648 else if(!strncmp(word[1],"continue",8)) {
649 cp.runs=atoi(word[2]);
650 add_stage(mdrun,STAGE_CONTINUE,&cp);
652 else if(!strncmp(word[1],"anneal",6)) {
654 ap.runs=atoi(word[2]);
656 ap.interval=atoi(word[4]);
657 add_stage(mdrun,STAGE_ANNEAL,&ap);
659 else if(!strncmp(word[1],"set_temp",8)) {
660 if(word[2][0]=='c') {
661 stp.type=SET_TEMP_CURRENT;
665 stp.type=SET_TEMP_VALUE;
666 stp.val=atof(word[2]);
668 add_stage(mdrun,STAGE_SET_TEMP,&stp);
670 else if(!strncmp(word[1],"set_timestep",12)) {
671 stsp.tau=atof(word[2]);
672 add_stage(mdrun,STAGE_SET_TIMESTEP,&stsp);
675 printf("%s unknown stage type: %s\n",
681 printf("%s unknown keyword '%s', skipped!\n",
693 int check_pressure(t_moldyn *moldyn,t_mdrun *mdrun) {
697 if(!(mdrun->sattr&SATTR_PRELAX)) {
701 delta=moldyn->p_avg-moldyn->p_ref;
712 int check_temperature(t_moldyn *moldyn,t_mdrun *mdrun) {
716 if(!(mdrun->sattr&SATTR_TRELAX))
719 delta=moldyn->t_avg-moldyn->t_ref;
730 int displace_atom(t_moldyn *moldyn,t_mdrun *mdrun) {
732 t_displace_atom_params *dap;
736 stage=mdrun->stage.current->data;
739 atom=&(moldyn->atom[dap->nr]);
747 int del_atoms(t_moldyn *moldyn,t_mdrun *mdrun) {
750 t_del_atoms_params *delp;
754 stage=mdrun->stage.current->data;
757 for(i=0;i<moldyn->count;i++) {
758 v3_sub(&dist,&(delp->o),&(moldyn->atom[i].r));
759 //printf("%d ----> %f %f %f = %f | %f\n",i,dist.x,dist.y,dist.z,v3_absolute_square(&dist),delp->r*delp->r);
760 if(v3_absolute_square(&dist)<=(delp->r*delp->r)) {
761 del_atom(moldyn,moldyn->atom[i].tag);
762 printf("%s atom deleted: %d %d %d\n",ME,
763 moldyn->atom[i].tag,moldyn->atom[i].element,
764 moldyn->atom[i].brand);
772 int insert_atoms(t_moldyn *moldyn,t_mdrun *mdrun) {
774 t_insert_atoms_params *iap;
784 stage=mdrun->stage.current->data;
789 v.x=0.0; v.y=0.0; v.z=0.0;
793 switch(mdrun->lattice) {
843 printf("%s unknown insertion mode: %02x\n",
849 while(cnt<iap->ins_atoms) {
852 if(iap->type!=INS_POS) {
853 r.x=rand_get_double(&(moldyn->random))*x;
854 r.y=rand_get_double(&(moldyn->random))*y;
855 r.z=rand_get_double(&(moldyn->random))*z;
866 if(iap->type!=INS_TOTAL) {
873 dmin=1000; // for sure too high!
874 for(i=0;i<moldyn->count;i++) {
875 atom=&(moldyn->atom[i]);
876 v3_sub(&dist,&(atom->r),&r);
877 check_per_bound(moldyn,&dist);
878 d=v3_absolute_square(&dist);
879 if(d<(iap->cr*iap->cr)) {
887 if(iap->type==INS_SPHERE) {
888 if((r.x-iap->x0)*(r.x-iap->x0)+
889 (r.y-iap->y0)*(r.y-iap->y0)+
890 (r.z-iap->z0)*(r.z-iap->z0)>
896 add_atom(moldyn,iap->element,
897 iap->brand,iap->attr,&r,&v);
898 printf("%s atom inserted (%d/%d): %f %f %f\n",
899 ME,(iap->cnt_steps+1)*iap->ins_atoms,
900 iap->ins_steps*iap->ins_atoms,r.x,r.y,r.z);
901 printf(" -> d2 = %f/%f\n",dmin,iap->cr*iap->cr);
908 int insert_mixed_atoms(t_moldyn *moldyn,t_mdrun *mdrun) {
911 t_insert_mixed_atoms_params *imp;
913 double x,x0,y,y0,z,z0;
914 double dmin,d,cmin,cmax;
920 stage=mdrun->stage.current->data;
934 cmin=imp->crmin*imp->crmin;
935 cmax=imp->crmax*imp->crmax;
937 while(imp->amount1|imp->amount2) {
942 r.x=rand_get_double(&(moldyn->random))*x;
943 r.y=rand_get_double(&(moldyn->random))*y;
944 r.z=rand_get_double(&(moldyn->random))*z;
948 dmin=1000.0; // for sure too high!
949 for(i=0;i<moldyn->count;i++) {
950 atom=&(moldyn->atom[i]);
951 v3_sub(&dist,&(atom->r),&r);
952 check_per_bound(moldyn,&dist);
953 d=v3_absolute_square(&dist);
965 add_atom(moldyn,imp->element1,
966 imp->brand1,imp->attr1,&r,&v);
967 printf("%s (mixed) atom inserted (%d): %f %f %f\n",
968 ME,imp->amount1,r.x,r.y,r.z);
969 printf(" -> d2 = %f/%f/%f\n",dmin,cmin,cmax);
976 r.x=rand_get_double(&(moldyn->random))*x;
977 r.y=rand_get_double(&(moldyn->random))*y;
978 r.z=rand_get_double(&(moldyn->random))*z;
982 dmin=1000.0; // for sure too high!
983 for(i=0;i<moldyn->count;i++) {
984 atom=&(moldyn->atom[i]);
985 v3_sub(&dist,&(atom->r),&r);
986 check_per_bound(moldyn,&dist);
987 d=v3_absolute_square(&dist);
999 add_atom(moldyn,imp->element2,
1000 imp->brand2,imp->attr2,&r,&v);
1001 printf("%s (mixed) atom inserted (%d): %f %f %f\n",
1002 ME,imp->amount2,r.x,r.y,r.z);
1003 printf(" -> d2 = %f/%f/%f\n",dmin,cmin,cmax);
1011 int chaatr(t_moldyn *moldyn,t_mdrun *mdrun) {
1014 t_chaattr_params *cap;
1018 stage=mdrun->stage.current->data;
1021 for(i=0;i<moldyn->count;i++) {
1022 atom=&(moldyn->atom[i]);
1023 if(cap->type&CHAATTR_ELEMENT) {
1024 if(cap->element!=atom->element)
1027 if(cap->type&CHAATTR_REGION) {
1028 if(cap->x0<atom->r.x)
1030 if(cap->y0<atom->r.y)
1032 if(cap->z0<atom->r.z)
1034 if(cap->x1>atom->r.x)
1036 if(cap->y1>atom->r.y)
1038 if(cap->z1>atom->r.z)
1041 atom->attr=cap->attr;
1047 int chsattr(t_moldyn *moldyn,t_mdrun *mdrun) {
1050 t_chsattr_params *csp;
1052 stage=mdrun->stage.current->data;
1055 if(csp->type&CHSATTR_PCTRL) {
1057 set_p_scale(moldyn,P_SCALE_BERENDSEN,csp->ptau);
1059 set_p_scale(moldyn,P_SCALE_BERENDSEN,csp->ptau);
1061 if(csp->type&CHSATTR_TCTRL) {
1063 set_t_scale(moldyn,T_SCALE_BERENDSEN,csp->ttau);
1065 set_t_scale(moldyn,T_SCALE_BERENDSEN,csp->ttau);
1067 if(csp->type&CHSATTR_PRELAX) {
1069 mdrun->sattr&=(~(SATTR_PRELAX));
1071 mdrun->sattr|=SATTR_PRELAX;
1074 if(csp->type&CHSATTR_TRELAX) {
1076 mdrun->sattr&=(~(SATTR_TRELAX));
1078 mdrun->sattr|=SATTR_TRELAX;
1081 if(csp->type&CHSATTR_AVGRST) {
1083 mdrun->sattr|=SATTR_AVGRST;
1085 mdrun->sattr&=(~(SATTR_AVGRST));
1087 if(csp->type&CHSATTR_RSTEPS) {
1088 mdrun->relax_steps=csp->rsteps;
1094 #define stage_print(m) if(!(stage->executed)) \
1097 int mdrun_hook(void *ptr1,void *ptr2) {
1107 t_insert_atoms_params *iap;
1108 t_insert_mixed_atoms_params *imp;
1109 t_continue_params *cp;
1110 t_anneal_params *ap;
1111 t_set_temp_params *stp;
1112 t_set_timestep_params *stsp;
1122 /* return immediately if there are no more stage */
1123 if(sl->current==NULL)
1126 /* get stage description */
1127 stage=sl->current->data;
1129 /* steps in next schedule */
1130 steps=mdrun->relax_steps;
1132 /* check whether relaxation steps are necessary */
1133 if((check_pressure(moldyn,mdrun)==TRUE)&\
1134 (check_temperature(moldyn,mdrun)==TRUE)) {
1137 stage_print("\n###########################\n");
1138 stage_print("# [mdrun] executing stage #\n");
1139 stage_print("###########################\n\n");
1141 /* stage specific stuff */
1142 switch(stage->type) {
1143 case STAGE_DISPLACE_ATOM:
1144 stage_print(" -> displace atom\n\n");
1145 displace_atom(moldyn,mdrun);
1148 case STAGE_DEL_ATOMS:
1149 stage_print(" -> del atoms\n\n");
1150 del_atoms(moldyn,mdrun);
1153 case STAGE_INSERT_ATOMS:
1154 stage_print(" -> insert atoms\n\n");
1156 if(iap->cnt_steps==iap->ins_steps) {
1160 insert_atoms(moldyn,mdrun);
1166 case STAGE_INSERT_MIXED_ATOMS:
1167 stage_print(" -> insert mixed atoms\n\n");
1169 insert_mixed_atoms(moldyn,mdrun);
1175 case STAGE_CONTINUE:
1176 stage_print(" -> continue\n\n");
1177 if(stage->executed==TRUE) {
1185 stage_print(" -> anneal\n\n");
1187 if(ap->count==ap->runs) {
1191 if(moldyn->t_ref+ap->dt>=0.0)
1192 set_temperature(moldyn,
1193 moldyn->t_ref+ap->dt);
1198 stage_print(" -> change atom attributes\n\n");
1199 chaatr(moldyn,mdrun);
1203 stage_print(" -> change sys attributes\n\n");
1204 chsattr(moldyn,mdrun);
1207 case STAGE_SET_TEMP:
1208 stage_print(" -> set temperature\n\n");
1210 if(stp->type&SET_TEMP_CURRENT) {
1211 set_temperature(moldyn,moldyn->t_avg);
1214 set_temperature(moldyn,stp->val);
1218 case STAGE_SET_TIMESTEP:
1219 stage_print(" -> set timestep\n\n");
1221 mdrun->timestep=stsp->tau;
1225 stage_print(" -> fill lattice\n\n");
1227 switch(fp->lattice) {
1230 o.x=0.5*0.25*fp->lc;
1233 create_lattice(moldyn,
1236 DEFAULT_ATOM_ATTR,0,
1237 fp->lx,fp->ly,fp->lz,
1244 create_lattice(moldyn,
1247 DEFAULT_ATOM_ATTR,1,
1248 fp->lx,fp->ly,fp->lz,
1256 create_lattice(moldyn,
1259 DEFAULT_ATOM_ATTR,0,
1260 fp->lx,fp->ly,fp->lz,
1266 moldyn_bc_check(moldyn);
1269 case STAGE_THERMAL_INIT:
1270 stage_print(" -> thermal init\n\n");
1271 thermal_init(moldyn,TRUE);
1275 printf("%s unknwon stage type\n",ME);
1279 /* mark as executed */
1280 stage->executed=TRUE;
1283 if(change_stage==TRUE) {
1284 printf("%s finished stage\n",ME);
1285 if(list_next_f(sl)==L_NO_NEXT_ELEMENT) {
1286 printf("%s no more stages\n",ME);
1296 if(mdrun->sattr&SATTR_AVGRST)
1297 average_reset(moldyn);
1301 /* continue simulation */
1302 moldyn_add_schedule(moldyn,steps,mdrun->timestep);
1307 int main(int argc,char **argv) {
1314 memset(&mdrun,0,sizeof(t_mdrun));
1315 memset(&moldyn,0,sizeof(t_moldyn));
1317 /* parse arguments */
1318 if(mdrun_parse_argv(&mdrun,argc,argv)<0)
1321 /* initialize list system */
1322 list_init_f(&(mdrun.stage));
1324 /* parse config file */
1325 mdrun_parse_config(&mdrun);
1327 /* reset the stage list */
1328 list_reset_f(&(mdrun.stage));
1332 /* prepare simulation */
1334 if(mdrun.continue_file[0]) {
1335 // read the save file
1336 moldyn_read_save_file(&moldyn,mdrun.continue_file);
1337 // manualaadjusting some stuff
1340 rand_init(&(moldyn.random),NULL,1);
1341 moldyn.random.status|=RAND_STAT_VERBOSE;
1344 moldyn_init(&moldyn,argc,argv);
1347 if(set_int_alg(&moldyn,mdrun.intalgo)<0)
1351 set_cutoff(&moldyn,mdrun.cutoff);
1352 if(set_potential(&moldyn,mdrun.potential)<0)
1354 switch(mdrun.potential) {
1355 case MOLDYN_POTENTIAL_AM:
1356 albe_mult_set_params(&moldyn,
1360 case MOLDYN_POTENTIAL_TM:
1361 tersoff_mult_set_params(&moldyn,
1365 case MOLDYN_POTENTIAL_HO:
1366 harmonic_oscillator_set_params(&moldyn,mdrun.element1);
1368 case MOLDYN_POTENTIAL_LJ:
1369 lennard_jones_set_params(&moldyn,mdrun.element1);
1372 printf("%s unknown potential: %02x\n",
1373 ME,mdrun.potential);
1377 /* if it is a continue run, reset schedule and skip lattice init */
1378 if(mdrun.continue_file[0]) {
1379 memset(&(moldyn.schedule),0,sizeof(t_moldyn_schedule));
1383 /* initial lattice and dimensions */
1384 set_dim(&moldyn,mdrun.dim.x,mdrun.dim.y,mdrun.dim.z,mdrun.vis);
1385 set_pbc(&moldyn,mdrun.pbcx,mdrun.pbcy,mdrun.pbcz);
1386 /* replaced by fill stage !!
1387 switch(mdrun.lattice) {
1389 create_lattice(&moldyn,FCC,mdrun.lc,mdrun.fill_element,
1390 mdrun.m1,DEFAULT_ATOM_ATTR,
1391 mdrun.fill_brand,mdrun.lx,
1392 mdrun.ly,mdrun.lz,NULL,0,NULL);
1395 create_lattice(&moldyn,DIAMOND,mdrun.lc,
1397 mdrun.m1,DEFAULT_ATOM_ATTR,
1398 mdrun.fill_brand,mdrun.lx,
1399 mdrun.ly,mdrun.lz,NULL,0,NULL);
1402 o.x=0.5*0.25*mdrun.lc; o.y=o.x; o.z=o.x;
1403 create_lattice(&moldyn,FCC,mdrun.lc,mdrun.element1,
1404 mdrun.m1,DEFAULT_ATOM_ATTR,0,mdrun.lx,
1405 mdrun.ly,mdrun.lz,&o,0,NULL);
1406 o.x+=0.25*mdrun.lc; o.y=o.x; o.z=o.x;
1407 create_lattice(&moldyn,FCC,mdrun.lc,mdrun.element2,
1408 mdrun.m2,DEFAULT_ATOM_ATTR,1,mdrun.lx,
1409 mdrun.ly,mdrun.lz,&o,0,NULL);
1412 set_nn_dist(&moldyn,mdrun.nnd);
1415 printf("%s unknown lattice type: %02x\n",
1419 moldyn_bc_check(&moldyn);
1420 replaced by fill stage !! */
1422 /* temperature and pressure */
1423 set_temperature(&moldyn,mdrun.temperature);
1424 set_pressure(&moldyn,mdrun.pressure);
1425 /* replaced thermal_init stage
1426 thermal_init(&moldyn,TRUE);
1430 /* first schedule */
1431 moldyn_add_schedule(&moldyn,mdrun.prerun,mdrun.timestep);
1434 moldyn_set_log_dir(&moldyn,mdrun.sdir);
1435 moldyn_set_report(&moldyn,"CHANGE ME","CHANGE ME TOO");
1437 moldyn_set_log(&moldyn,LOG_TOTAL_ENERGY,mdrun.elog);
1439 moldyn_set_log(&moldyn,LOG_TEMPERATURE,mdrun.tlog);
1441 moldyn_set_log(&moldyn,LOG_PRESSURE,mdrun.plog);
1443 moldyn_set_log(&moldyn,LOG_VOLUME,mdrun.vlog);
1445 moldyn_set_log(&moldyn,VISUAL_STEP,mdrun.visualize);
1447 moldyn_set_log(&moldyn,SAVE_STEP,mdrun.save);
1448 moldyn_set_log(&moldyn,CREATE_REPORT,0);
1449 set_avg_skip(&moldyn,mdrun.avgskip);
1451 /* prepare the hook function */
1452 moldyn_set_schedule_hook(&moldyn,&mdrun_hook,&mdrun);
1454 /* run the simulation */
1455 moldyn_integrate(&moldyn);
1458 moldyn_shutdown(&moldyn);
1460 list_destroy_f(&(mdrun.stage));