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_INSERT_ATOMS:
102 psize=sizeof(t_insert_atoms_params);
104 case STAGE_INSERT_MIXED_ATOMS:
105 psize=sizeof(t_insert_mixed_atoms_params);
108 psize=sizeof(t_continue_params);
111 psize=sizeof(t_anneal_params);
114 psize=sizeof(t_chaattr_params);
117 psize=sizeof(t_chsattr_params);
120 psize=sizeof(t_set_temp_params);
122 case STAGE_SET_TIMESTEP:
123 psize=sizeof(t_set_timestep_params);
126 psize=sizeof(t_fill_params);
128 case STAGE_THERMAL_INIT:
132 printf("%s unknown stage type: %02x\n",ME,type);
136 stage=malloc(sizeof(t_stage));
138 perror("[mdrun] malloc (add stage)");
143 stage->executed=FALSE;
145 stage->params=malloc(psize);
146 if(stage->params==NULL) {
147 perror("[mdrun] malloc (stage params)");
151 memcpy(stage->params,params,psize);
153 list_add_immediate_f(&(mdrun->stage),stage);
158 int mdrun_parse_config(t_mdrun *mdrun) {
168 t_displace_atom_params dap;
169 t_insert_atoms_params iap;
170 t_insert_mixed_atoms_params imp;
171 t_continue_params cp;
173 t_chaattr_params cap;
174 t_chsattr_params csp;
175 t_set_temp_params stp;
176 t_set_timestep_params stsp;
179 /* open config file */
180 fd=open(mdrun->cfile,O_RDONLY);
182 snprintf(error,128,"%s open cfile %s",ME,mdrun->cfile);
187 /* read, parse, set */
192 ret=get_line(fd,line,128);
196 // ignore # lines and \n
197 if((line[0]=='#')|(ret==1))
201 memset(&iap,0,sizeof(t_insert_atoms_params));
202 memset(&imp,0,sizeof(t_insert_mixed_atoms_params));
203 memset(&cp,0,sizeof(t_continue_params));
204 memset(&ap,0,sizeof(t_anneal_params));
205 memset(&cap,0,sizeof(t_chaattr_params));
206 memset(&csp,0,sizeof(t_chsattr_params));
207 memset(&stp,0,sizeof(t_set_temp_params));
208 memset(&stsp,0,sizeof(t_set_timestep_params));
209 memset(&fp,0,sizeof(t_fill_params));
211 // get command + args
215 wptr=strtok(NULL," \t");
217 wptr=strtok(line," \t");
220 strncpy(word[wcnt],wptr,64);
224 if(!strncmp(word[0],"potential",9)) {
225 if(!strncmp(word[1],"albe",4))
226 mdrun->potential=MOLDYN_POTENTIAL_AM;
227 if(!strncmp(word[1],"tersoff",7))
228 mdrun->potential=MOLDYN_POTENTIAL_TM;
229 if(!strncmp(word[1],"ho",2))
230 mdrun->potential=MOLDYN_POTENTIAL_HO;
231 if(!strncmp(word[1],"lj",2))
232 mdrun->potential=MOLDYN_POTENTIAL_LJ;
234 else if(!strncmp(word[0],"continue",8))
235 strncpy(mdrun->continue_file,word[1],128);
236 else if(!strncmp(word[0],"cutoff",6))
237 mdrun->cutoff=atof(word[1]);
238 else if(!strncmp(word[0],"nnd",3))
239 mdrun->nnd=atof(word[1]);
240 else if(!strncmp(word[0],"intalgo",7)) {
241 if(!strncmp(word[1],"verlet",5))
242 mdrun->intalgo=MOLDYN_INTEGRATE_VERLET;
244 else if(!strncmp(word[0],"timestep",8))
245 mdrun->timestep=atof(word[1]);
246 else if(!strncmp(word[0],"volume",6)) {
247 mdrun->dim.x=atof(word[1]);
248 mdrun->dim.y=atof(word[2]);
249 mdrun->dim.z=atof(word[3]);
250 if(strncmp(word[4],"0",1))
253 else if(!strncmp(word[0],"pbc",3)) {
254 if(strncmp(word[1],"0",1))
258 if(strncmp(word[2],"0",1))
262 if(strncmp(word[3],"0",1))
267 else if(!strncmp(word[0],"temperature",11))
268 mdrun->temperature=atof(word[1]);
269 else if(!strncmp(word[0],"pressure",8))
270 mdrun->pressure=atof(word[1]);
271 else if(!strncmp(word[0],"lattice",7)) {
272 if(!strncmp(word[1],"zincblende",10))
273 mdrun->lattice=ZINCBLENDE;
274 if(!strncmp(word[1],"fcc",3))
276 if(!strncmp(word[1],"diamond",7))
277 mdrun->lattice=DIAMOND;
278 if(!strncmp(word[1],"none",4))
281 else if(!strncmp(word[0],"element1",8)) {
282 mdrun->element1=atoi(word[1]);
283 mdrun->m1=pse_mass[mdrun->element1];
285 else if(!strncmp(word[0],"element2",8)) {
286 mdrun->element2=atoi(word[1]);
287 mdrun->m2=pse_mass[mdrun->element2];
289 else if(!strncmp(word[0],"fill",6)) {
295 if(!strncmp(word[1],"lc",2)) {
297 fp.fill_element=atoi(word[6]);
298 fp.fill_brand=atoi(word[7]);
301 fp.fill_element=mdrun->element1;
309 fp.p_type=PART_INSIDE_R;
311 fp.p_type=PART_INSIDE_D;
315 fp.p_type=PART_OUTSIDE_R;
317 fp.p_type=PART_OUTSIDE_D;
323 if((fp.p_type==PART_INSIDE_R)||
324 (fp.p_type==PART_OUTSIDE_R)) {
325 fp.p_vals.r=atof(word[7]);
326 fp.p_vals.p.x=atof(word[8]);
327 fp.p_vals.p.y=atof(word[9]);
328 fp.p_vals.p.z=atof(word[10]);
330 if((fp.p_type==PART_INSIDE_D)||
331 (fp.p_type==PART_OUTSIDE_D)) {
332 fp.p_vals.p.x=atof(word[7]);
333 fp.p_vals.p.y=atof(word[8]);
334 fp.p_vals.p.z=atof(word[9]);
335 fp.p_vals.d.x=atof(word[10]);
336 fp.p_vals.d.y=atof(word[11]);
337 fp.p_vals.d.z=atof(word[12]);
339 fp.lattice=mdrun->lattice;
340 add_stage(mdrun,STAGE_FILL,&fp);
342 else if(!strncmp(word[0],"thermal_init",12)) {
343 add_stage(mdrun,STAGE_THERMAL_INIT,NULL);
345 else if(!strncmp(word[0],"aattr",5)) {
346 // for aatrib line we need a special stage
347 // containing one schedule of 0 loops ...
348 for(i=0;i<strlen(word[1]);i++) {
351 cap.type|=CHAATTR_TOTALV;
354 cap.type|=CHAATTR_REGION;
357 cap.type|=CHAATTR_ELEMENT;
364 if(cap.type&CHAATTR_REGION) {
365 cap.x0=atof(word[1]);
366 cap.y0=atof(word[2]);
367 cap.z0=atof(word[3]);
368 cap.x1=atof(word[4]);
369 cap.y1=atof(word[5]);
370 cap.z1=atof(word[6]);
373 if(cap.type&CHAATTR_ELEMENT) {
374 cap.element=atoi(word[i]);
377 for(o=0;o<strlen(word[i]);o++) {
380 cap.attr|=ATOM_ATTR_VB;
383 cap.attr|=ATOM_ATTR_HB;
386 cap.attr|=ATOM_ATTR_VA;
389 cap.attr|=ATOM_ATTR_FP;
392 cap.attr|=ATOM_ATTR_1BP;
395 cap.attr|=ATOM_ATTR_2BP;
398 cap.attr|=ATOM_ATTR_3BP;
404 add_stage(mdrun,STAGE_CHAATTR,&cap);
406 else if(!strncmp(word[0],"sattr",5)) {
407 // for satrib line we need a special stage
408 // containing one schedule of 0 loops ...
410 for(i=1;i<wcnt;i++) {
411 if(!strncmp(word[i],"pctrl",5)) {
412 csp.ptau=0.01/(atof(word[++i])*GPA);
413 csp.type|=CHSATTR_PCTRL;
415 if(!strncmp(word[i],"tctrl",5)) {
416 csp.ttau=atof(word[++i]);
417 csp.type|=CHSATTR_TCTRL;
419 if(!strncmp(word[i],"prelax",6)) {
420 csp.dp=atof(word[++i])*BAR;
421 csp.type|=CHSATTR_PRELAX;
423 if(!strncmp(word[i],"trelax",6)) {
424 csp.dt=atof(word[++i]);
425 csp.type|=CHSATTR_TRELAX;
427 if(!strncmp(word[i],"rsteps",6)) {
428 csp.rsteps=atoi(word[++i]);
429 csp.type|=CHSATTR_RSTEPS;
431 if(!strncmp(word[i],"avgrst",6)) {
432 csp.avgrst=atoi(word[++i]);
433 csp.type|=CHSATTR_AVGRST;
436 add_stage(mdrun,STAGE_CHSATTR,&csp);
438 else if(!strncmp(word[0],"prerun",6))
439 mdrun->prerun=atoi(word[1]);
440 else if(!strncmp(word[0],"avgskip",7))
441 mdrun->avgskip=atoi(word[1]);
442 else if(!strncmp(word[0],"elog",4))
443 mdrun->elog=atoi(word[1]);
444 else if(!strncmp(word[0],"tlog",4))
445 mdrun->tlog=atoi(word[1]);
446 else if(!strncmp(word[0],"plog",4))
447 mdrun->plog=atoi(word[1]);
448 else if(!strncmp(word[0],"vlog",4))
449 mdrun->vlog=atoi(word[1]);
450 else if(!strncmp(word[0],"save",4))
451 mdrun->save=atoi(word[1]);
452 else if(!strncmp(word[0],"visualize",9))
453 mdrun->visualize=atoi(word[1]);
454 else if(!strncmp(word[0],"stage",5)) {
455 // for every stage line, add a stage
456 if(!strncmp(word[1],"displace",8)) {
457 dap.nr=atoi(word[2]);
458 dap.dx=atof(word[3]);
459 dap.dy=atof(word[4]);
460 dap.dz=atof(word[5]);
461 add_stage(mdrun,STAGE_DISPLACE_ATOM,&dap);
463 else if(!strncmp(word[1],"ins_atoms",9)) {
464 iap.ins_steps=atoi(word[2]);
465 iap.ins_atoms=atoi(word[3]);
466 iap.element=atoi(word[4]);
467 iap.brand=atoi(word[5]);
468 for(i=0;i<strlen(word[6]);i++) {
471 iap.attr|=ATOM_ATTR_VB;
474 iap.attr|=ATOM_ATTR_HB;
477 iap.attr|=ATOM_ATTR_VA;
480 iap.attr|=ATOM_ATTR_FP;
483 iap.attr|=ATOM_ATTR_1BP;
486 iap.attr|=ATOM_ATTR_2BP;
489 iap.attr|=ATOM_ATTR_3BP;
499 iap.x0=atof(word[8]);
500 iap.y0=atof(word[9]);
501 iap.z0=atof(word[10]);
504 if(word[8][0]=='t') {
506 iap.cr=atof(word[9]);
510 iap.x0=atof(word[8]);
511 iap.y0=atof(word[9]);
512 iap.z0=atof(word[10]);
513 iap.x1=atof(word[11]);
514 iap.y1=atof(word[12]);
515 iap.z1=atof(word[13]);
516 iap.cr=atof(word[14]);
521 add_stage(mdrun,STAGE_INSERT_ATOMS,&iap);
527 else if(!strncmp(word[1],"ins_m_atoms",11)) {
528 imp.element1=atoi(word[2]);
529 imp.element2=atoi(word[3]);
530 imp.amount1=atoi(word[4]);
531 imp.amount2=atoi(word[5]);
532 imp.brand1=atoi(word[6]);
533 imp.brand2=atoi(word[7]);
534 imp.crmin=atof(word[8]);
535 imp.crmax=atof(word[9]);
537 for(i=0;i<strlen(word[8]);i++) {
540 imp.attr|=ATOM_ATTR_VB;
543 imp.attr|=ATOM_ATTR_HB;
546 imp.attr|=ATOM_ATTR_VA;
549 imp.attr|=ATOM_ATTR_FP;
552 imp.attr|=ATOM_ATTR_1BP;
555 imp.attr|=ATOM_ATTR_2BP;
558 imp.attr|=ATOM_ATTR_3BP;
565 imp.attr1=ATOM_ATTR_HB|ATOM_ATTR_VA|ATOM_ATTR_1BP|ATOM_ATTR_2BP|ATOM_ATTR_3BP|ATOM_ATTR_FP;
566 imp.attr2=ATOM_ATTR_HB|ATOM_ATTR_VA|ATOM_ATTR_1BP|ATOM_ATTR_2BP|ATOM_ATTR_3BP|ATOM_ATTR_FP;
567 add_stage(mdrun,STAGE_INSERT_MIXED_ATOMS,&imp);
574 else if(!strncmp(word[1],"continue",8)) {
575 cp.runs=atoi(word[2]);
576 add_stage(mdrun,STAGE_CONTINUE,&cp);
578 else if(!strncmp(word[1],"anneal",6)) {
580 ap.runs=atoi(word[2]);
582 ap.interval=atoi(word[4]);
583 add_stage(mdrun,STAGE_ANNEAL,&ap);
585 else if(!strncmp(word[1],"set_temp",8)) {
586 if(word[2][0]=='c') {
587 stp.type=SET_TEMP_CURRENT;
591 stp.type=SET_TEMP_VALUE;
592 stp.val=atof(word[2]);
594 add_stage(mdrun,STAGE_SET_TEMP,&stp);
596 else if(!strncmp(word[1],"set_timestep",12)) {
597 stsp.tau=atof(word[2]);
598 add_stage(mdrun,STAGE_SET_TIMESTEP,&stsp);
601 printf("%s unknown stage type: %s\n",
607 printf("%s unknown keyword '%s', skipped!\n",
619 int check_pressure(t_moldyn *moldyn,t_mdrun *mdrun) {
623 if(!(mdrun->sattr&SATTR_PRELAX)) {
627 delta=moldyn->p_avg-moldyn->p_ref;
638 int check_temperature(t_moldyn *moldyn,t_mdrun *mdrun) {
642 if(!(mdrun->sattr&SATTR_TRELAX))
645 delta=moldyn->t_avg-moldyn->t_ref;
656 int displace_atom(t_moldyn *moldyn,t_mdrun *mdrun) {
658 t_displace_atom_params *dap;
662 stage=mdrun->stage.current->data;
665 atom=&(moldyn->atom[dap->nr]);
673 int insert_atoms(t_moldyn *moldyn,t_mdrun *mdrun) {
675 t_insert_atoms_params *iap;
685 stage=mdrun->stage.current->data;
690 v.x=0.0; v.y=0.0; v.z=0.0;
694 switch(mdrun->lattice) {
735 printf("%s unknown insertion mode: %02x\n",
741 while(cnt<iap->ins_atoms) {
744 if(iap->type!=INS_POS) {
745 r.x=rand_get_double(&(moldyn->random))*x;
746 r.y=rand_get_double(&(moldyn->random))*y;
747 r.z=rand_get_double(&(moldyn->random))*z;
758 if(iap->type!=INS_TOTAL) {
765 dmin=1000; // for sure too high!
766 for(i=0;i<moldyn->count;i++) {
767 atom=&(moldyn->atom[i]);
768 v3_sub(&dist,&(atom->r),&r);
769 check_per_bound(moldyn,&dist);
770 d=v3_absolute_square(&dist);
771 if(d<(iap->cr*iap->cr)) {
780 add_atom(moldyn,iap->element,pse_mass[iap->element],
781 iap->brand,iap->attr,&r,&v);
782 printf("%s atom inserted (%d/%d): %f %f %f\n",
783 ME,(iap->cnt_steps+1)*iap->ins_atoms,
784 iap->ins_steps*iap->ins_atoms,r.x,r.y,r.z);
785 printf(" -> d2 = %f/%f\n",dmin,iap->cr*iap->cr);
792 int insert_mixed_atoms(t_moldyn *moldyn,t_mdrun *mdrun) {
795 t_insert_mixed_atoms_params *imp;
797 double x,x0,y,y0,z,z0;
798 double dmin,d,cmin,cmax;
804 stage=mdrun->stage.current->data;
818 cmin=imp->crmin*imp->crmin;
819 cmax=imp->crmax*imp->crmax;
821 while(imp->amount1|imp->amount2) {
826 r.x=rand_get_double(&(moldyn->random))*x;
827 r.y=rand_get_double(&(moldyn->random))*y;
828 r.z=rand_get_double(&(moldyn->random))*z;
832 dmin=1000.0; // for sure too high!
833 for(i=0;i<moldyn->count;i++) {
834 atom=&(moldyn->atom[i]);
835 v3_sub(&dist,&(atom->r),&r);
836 check_per_bound(moldyn,&dist);
837 d=v3_absolute_square(&dist);
849 add_atom(moldyn,imp->element1,pse_mass[imp->element1],
850 imp->brand1,imp->attr1,&r,&v);
851 printf("%s (mixed) atom inserted (%d): %f %f %f\n",
852 ME,imp->amount1,r.x,r.y,r.z);
853 printf(" -> d2 = %f/%f/%f\n",dmin,cmin,cmax);
860 r.x=rand_get_double(&(moldyn->random))*x;
861 r.y=rand_get_double(&(moldyn->random))*y;
862 r.z=rand_get_double(&(moldyn->random))*z;
866 dmin=1000.0; // for sure too high!
867 for(i=0;i<moldyn->count;i++) {
868 atom=&(moldyn->atom[i]);
869 v3_sub(&dist,&(atom->r),&r);
870 check_per_bound(moldyn,&dist);
871 d=v3_absolute_square(&dist);
883 add_atom(moldyn,imp->element2,pse_mass[imp->element2],
884 imp->brand2,imp->attr2,&r,&v);
885 printf("%s (mixed) atom inserted (%d): %f %f %f\n",
886 ME,imp->amount2,r.x,r.y,r.z);
887 printf(" -> d2 = %f/%f/%f\n",dmin,cmin,cmax);
895 int chaatr(t_moldyn *moldyn,t_mdrun *mdrun) {
898 t_chaattr_params *cap;
902 stage=mdrun->stage.current->data;
905 for(i=0;i<moldyn->count;i++) {
906 atom=&(moldyn->atom[i]);
907 if(cap->type&CHAATTR_ELEMENT) {
908 if(cap->element!=atom->element)
911 if(cap->type&CHAATTR_REGION) {
912 if(cap->x0<atom->r.x)
914 if(cap->y0<atom->r.y)
916 if(cap->z0<atom->r.z)
918 if(cap->x1>atom->r.x)
920 if(cap->y1>atom->r.y)
922 if(cap->z1>atom->r.z)
925 atom->attr=cap->attr;
931 int chsattr(t_moldyn *moldyn,t_mdrun *mdrun) {
934 t_chsattr_params *csp;
936 stage=mdrun->stage.current->data;
939 if(csp->type&CHSATTR_PCTRL) {
941 set_p_scale(moldyn,P_SCALE_BERENDSEN,csp->ptau);
943 set_p_scale(moldyn,P_SCALE_BERENDSEN,csp->ptau);
945 if(csp->type&CHSATTR_TCTRL) {
947 set_t_scale(moldyn,T_SCALE_BERENDSEN,csp->ttau);
949 set_t_scale(moldyn,T_SCALE_BERENDSEN,csp->ttau);
951 if(csp->type&CHSATTR_PRELAX) {
953 mdrun->sattr&=(~(SATTR_PRELAX));
955 mdrun->sattr|=SATTR_PRELAX;
958 if(csp->type&CHSATTR_TRELAX) {
960 mdrun->sattr&=(~(SATTR_TRELAX));
962 mdrun->sattr|=SATTR_TRELAX;
965 if(csp->type&CHSATTR_AVGRST) {
967 mdrun->sattr|=SATTR_AVGRST;
969 mdrun->sattr&=(~(SATTR_AVGRST));
971 if(csp->type&CHSATTR_RSTEPS) {
972 mdrun->relax_steps=csp->rsteps;
978 #define stage_print(m) if(!(stage->executed)) \
981 int mdrun_hook(void *ptr1,void *ptr2) {
991 t_insert_atoms_params *iap;
992 t_insert_mixed_atoms_params *imp;
993 t_continue_params *cp;
995 t_set_temp_params *stp;
996 t_set_timestep_params *stsp;
1006 /* return immediately if there are no more stage */
1007 if(sl->current==NULL)
1010 /* get stage description */
1011 stage=sl->current->data;
1013 /* steps in next schedule */
1014 steps=mdrun->relax_steps;
1016 /* check whether relaxation steps are necessary */
1017 if((check_pressure(moldyn,mdrun)==TRUE)&\
1018 (check_temperature(moldyn,mdrun)==TRUE)) {
1021 stage_print("\n###########################\n");
1022 stage_print("# [mdrun] executing stage #\n");
1023 stage_print("###########################\n\n");
1025 /* stage specific stuff */
1026 switch(stage->type) {
1027 case STAGE_DISPLACE_ATOM:
1028 stage_print(" -> displace atom\n\n");
1029 displace_atom(moldyn,mdrun);
1032 case STAGE_INSERT_ATOMS:
1033 stage_print(" -> insert atoms\n\n");
1035 if(iap->cnt_steps==iap->ins_steps) {
1039 insert_atoms(moldyn,mdrun);
1045 case STAGE_INSERT_MIXED_ATOMS:
1046 stage_print(" -> insert mixed atoms\n\n");
1048 insert_mixed_atoms(moldyn,mdrun);
1054 case STAGE_CONTINUE:
1055 stage_print(" -> continue\n\n");
1056 if(stage->executed==TRUE) {
1064 stage_print(" -> anneal\n\n");
1066 if(ap->count==ap->runs) {
1070 if(moldyn->t_ref+ap->dt>=0.0)
1071 set_temperature(moldyn,
1072 moldyn->t_ref+ap->dt);
1077 stage_print(" -> change atom attributes\n\n");
1078 chaatr(moldyn,mdrun);
1082 stage_print(" -> change sys attributes\n\n");
1083 chsattr(moldyn,mdrun);
1086 case STAGE_SET_TEMP:
1087 stage_print(" -> set temperature\n\n");
1089 if(stp->type&SET_TEMP_CURRENT) {
1090 set_temperature(moldyn,moldyn->t_avg);
1093 set_temperature(moldyn,stp->val);
1097 case STAGE_SET_TIMESTEP:
1098 stage_print(" -> set timestep\n\n");
1100 mdrun->timestep=stsp->tau;
1104 stage_print(" -> fill lattice\n\n");
1106 if(fp->lattice!=ZINCBLENDE) {
1107 create_lattice(moldyn,
1111 DEFAULT_ATOM_ATTR,0,
1112 fp->lx,fp->ly,fp->lz,
1117 o.x=0.5*0.25*fp->lc;
1120 create_lattice(moldyn,
1124 DEFAULT_ATOM_ATTR,0,
1125 fp->lx,fp->ly,fp->lz,
1131 create_lattice(moldyn,
1135 DEFAULT_ATOM_ATTR,1,
1136 fp->lx,fp->ly,fp->lz,
1140 moldyn_bc_check(moldyn);
1143 case STAGE_THERMAL_INIT:
1144 stage_print(" -> thermal init\n\n");
1145 thermal_init(moldyn,TRUE);
1149 printf("%s unknwon stage type\n",ME);
1153 /* mark as executed */
1154 stage->executed=TRUE;
1157 if(change_stage==TRUE) {
1158 printf("%s finished stage\n",ME);
1159 if(list_next_f(sl)==L_NO_NEXT_ELEMENT) {
1160 printf("%s no more stages\n",ME);
1170 if(mdrun->sattr&SATTR_AVGRST)
1171 average_reset(moldyn);
1175 /* continue simulation */
1176 moldyn_add_schedule(moldyn,steps,mdrun->timestep);
1181 int main(int argc,char **argv) {
1188 memset(&mdrun,0,sizeof(t_mdrun));
1189 memset(&moldyn,0,sizeof(t_moldyn));
1191 /* parse arguments */
1192 if(mdrun_parse_argv(&mdrun,argc,argv)<0)
1195 /* initialize list system */
1196 list_init_f(&(mdrun.stage));
1198 /* parse config file */
1199 mdrun_parse_config(&mdrun);
1201 /* reset the stage list */
1202 list_reset_f(&(mdrun.stage));
1206 /* prepare simulation */
1208 if(mdrun.continue_file[0]) {
1209 // read the save file
1210 moldyn_read_save_file(&moldyn,mdrun.continue_file);
1211 // manualaadjusting some stuff
1214 rand_init(&(moldyn.random),NULL,1);
1215 moldyn.random.status|=RAND_STAT_VERBOSE;
1218 moldyn_init(&moldyn,argc,argv);
1221 if(set_int_alg(&moldyn,mdrun.intalgo)<0)
1225 set_cutoff(&moldyn,mdrun.cutoff);
1226 if(set_potential(&moldyn,mdrun.potential)<0)
1228 switch(mdrun.potential) {
1229 case MOLDYN_POTENTIAL_AM:
1230 albe_mult_set_params(&moldyn,
1234 case MOLDYN_POTENTIAL_TM:
1235 tersoff_mult_set_params(&moldyn,
1239 case MOLDYN_POTENTIAL_HO:
1240 harmonic_oscillator_set_params(&moldyn,mdrun.element1);
1242 case MOLDYN_POTENTIAL_LJ:
1243 lennard_jones_set_params(&moldyn,mdrun.element1);
1246 printf("%s unknown potential: %02x\n",
1247 ME,mdrun.potential);
1251 /* if it is a continue run, reset schedule and skip lattice init */
1252 if(mdrun.continue_file[0]) {
1253 memset(&(moldyn.schedule),0,sizeof(t_moldyn_schedule));
1257 /* initial lattice and dimensions */
1258 set_dim(&moldyn,mdrun.dim.x,mdrun.dim.y,mdrun.dim.z,mdrun.vis);
1259 set_pbc(&moldyn,mdrun.pbcx,mdrun.pbcy,mdrun.pbcz);
1260 /* replaced by fill stage !!
1261 switch(mdrun.lattice) {
1263 create_lattice(&moldyn,FCC,mdrun.lc,mdrun.fill_element,
1264 mdrun.m1,DEFAULT_ATOM_ATTR,
1265 mdrun.fill_brand,mdrun.lx,
1266 mdrun.ly,mdrun.lz,NULL,0,NULL);
1269 create_lattice(&moldyn,DIAMOND,mdrun.lc,
1271 mdrun.m1,DEFAULT_ATOM_ATTR,
1272 mdrun.fill_brand,mdrun.lx,
1273 mdrun.ly,mdrun.lz,NULL,0,NULL);
1276 o.x=0.5*0.25*mdrun.lc; o.y=o.x; o.z=o.x;
1277 create_lattice(&moldyn,FCC,mdrun.lc,mdrun.element1,
1278 mdrun.m1,DEFAULT_ATOM_ATTR,0,mdrun.lx,
1279 mdrun.ly,mdrun.lz,&o,0,NULL);
1280 o.x+=0.25*mdrun.lc; o.y=o.x; o.z=o.x;
1281 create_lattice(&moldyn,FCC,mdrun.lc,mdrun.element2,
1282 mdrun.m2,DEFAULT_ATOM_ATTR,1,mdrun.lx,
1283 mdrun.ly,mdrun.lz,&o,0,NULL);
1286 set_nn_dist(&moldyn,mdrun.nnd);
1289 printf("%s unknown lattice type: %02x\n",
1293 moldyn_bc_check(&moldyn);
1294 replaced by fill stage !! */
1296 /* temperature and pressure */
1297 set_temperature(&moldyn,mdrun.temperature);
1298 set_pressure(&moldyn,mdrun.pressure);
1299 /* replaced thermal_init stage
1300 thermal_init(&moldyn,TRUE);
1304 /* first schedule */
1305 moldyn_add_schedule(&moldyn,mdrun.prerun,mdrun.timestep);
1308 moldyn_set_log_dir(&moldyn,mdrun.sdir);
1309 moldyn_set_report(&moldyn,"CHANGE ME","CHANGE ME TOO");
1311 moldyn_set_log(&moldyn,LOG_TOTAL_ENERGY,mdrun.elog);
1313 moldyn_set_log(&moldyn,LOG_TEMPERATURE,mdrun.tlog);
1315 moldyn_set_log(&moldyn,LOG_PRESSURE,mdrun.plog);
1317 moldyn_set_log(&moldyn,LOG_VOLUME,mdrun.vlog);
1319 moldyn_set_log(&moldyn,VISUAL_STEP,mdrun.visualize);
1321 moldyn_set_log(&moldyn,SAVE_STEP,mdrun.save);
1322 moldyn_set_log(&moldyn,CREATE_REPORT,0);
1323 set_avg_skip(&moldyn,mdrun.avgskip);
1325 /* prepare the hook function */
1326 moldyn_set_schedule_hook(&moldyn,&mdrun_hook,&mdrun);
1328 /* run the simulation */
1329 moldyn_integrate(&moldyn);
1332 moldyn_shutdown(&moldyn);
1334 list_destroy_f(&(mdrun.stage));