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 mdrun->lc=atof(word[2]);
283 else if(!strncmp(word[0],"element1",8)) {
284 mdrun->element1=atoi(word[1]);
286 else if(!strncmp(word[0],"element2",8)) {
287 mdrun->element2=atoi(word[1]);
289 else if(!strncmp(word[0],"fill",6)) {
291 fp.fill_element=mdrun->element1;
293 fp.lattice=mdrun->lattice;
297 // parse fill command
300 if(!strncmp(word[i],"lc",2)) {
301 fp.lx=atoi(word[++i]);
302 fp.ly=atoi(word[++i]);
303 fp.lz=atoi(word[++i]);
304 fp.lc=atof(word[++i]);
307 if(!strncmp(word[i],"eb",2)) {
308 fp.fill_element=atoi(word[++i]);
309 fp.fill_brand=atoi(word[++i]);
311 if(word[i][0]=='p') {
316 fp.p_params.type=PART_INSIDE_R;
318 fp.p_params.type=PART_INSIDE_D;
322 fp.p_params.type=PART_OUTSIDE_R;
324 fp.p_params.type=PART_OUTSIDE_D;
329 if((fp.p_params.type==PART_INSIDE_R)||
330 (fp.p_params.type==PART_OUTSIDE_R)) {
331 fp.p_params.r=atof(word[++i]);
332 fp.p_params.p.x=atof(word[++i]);
333 fp.p_params.p.y=atof(word[++i]);
334 fp.p_params.p.z=atof(word[++i]);
336 if((fp.p_params.type==PART_INSIDE_D)||
337 (fp.p_params.type==PART_OUTSIDE_D)) {
338 fp.p_params.p.x=atof(word[++i]);
339 fp.p_params.p.y=atof(word[++i]);
340 fp.p_params.p.z=atof(word[++i]);
341 fp.p_params.d.x=atof(word[++i]);
342 fp.p_params.d.y=atof(word[++i]);
343 fp.p_params.d.z=atof(word[++i]);
346 if(word[i][0]=='d') {
347 switch(word[++i][0]) {
350 fp.d_params.type=DEFECT_TYPE_0D;
351 if(!strncmp(word[i+1],"dbx",3)) {
352 fp.d_params.stype=DEFECT_STYPE_DB_X;
354 if(!strncmp(word[i+1],"dby",3)) {
355 fp.d_params.stype=DEFECT_STYPE_DB_Y;
357 if(!strncmp(word[i+1],"dbz",3)) {
358 fp.d_params.stype=DEFECT_STYPE_DB_Z;
360 if(!strncmp(word[i+1],"dbr",3)) {
361 fp.d_params.stype=DEFECT_STYPE_DB_R;
364 fp.d_params.od=atof(word[++i]);
365 fp.d_params.dd=atof(word[++i]);
366 fp.d_params.element=atoi(word[++i]);
367 fp.d_params.brand=atoi(word[++i]);
369 fp.d_params.attr=ATOM_ATTR_HB|ATOM_ATTR_VA;
370 fp.d_params.attr|=ATOM_ATTR_1BP|ATOM_ATTR_2BP|ATOM_ATTR_3BP;
374 fp.d_params.type=DEFECT_TYPE_1D;
377 fp.d_params.type=DEFECT_TYPE_2D;
380 fp.d_params.type=DEFECT_TYPE_3D;
389 add_stage(mdrun,STAGE_FILL,&fp);
391 else if(!strncmp(word[0],"thermal_init",12)) {
392 add_stage(mdrun,STAGE_THERMAL_INIT,NULL);
394 else if(!strncmp(word[0],"aattr",5)) {
395 // for aatrib line we need a special stage
396 // containing one schedule of 0 loops ...
397 for(i=0;i<strlen(word[1]);i++) {
400 cap.type|=CHAATTR_TOTALV;
403 cap.type|=CHAATTR_REGION;
406 cap.type|=CHAATTR_ELEMENT;
413 if(cap.type&CHAATTR_REGION) {
414 cap.x0=atof(word[1]);
415 cap.y0=atof(word[2]);
416 cap.z0=atof(word[3]);
417 cap.x1=atof(word[4]);
418 cap.y1=atof(word[5]);
419 cap.z1=atof(word[6]);
422 if(cap.type&CHAATTR_ELEMENT) {
423 cap.element=atoi(word[i]);
426 for(o=0;o<strlen(word[i]);o++) {
429 cap.attr|=ATOM_ATTR_VB;
432 cap.attr|=ATOM_ATTR_HB;
435 cap.attr|=ATOM_ATTR_VA;
438 cap.attr|=ATOM_ATTR_FP;
441 cap.attr|=ATOM_ATTR_1BP;
444 cap.attr|=ATOM_ATTR_2BP;
447 cap.attr|=ATOM_ATTR_3BP;
453 add_stage(mdrun,STAGE_CHAATTR,&cap);
455 else if(!strncmp(word[0],"sattr",5)) {
456 // for satrib line we need a special stage
457 // containing one schedule of 0 loops ...
459 for(i=1;i<wcnt;i++) {
460 if(!strncmp(word[i],"pctrl",5)) {
461 csp.ptau=0.01/(atof(word[++i])*GPA);
462 csp.type|=CHSATTR_PCTRL;
464 if(!strncmp(word[i],"tctrl",5)) {
465 csp.ttau=atof(word[++i]);
466 csp.type|=CHSATTR_TCTRL;
468 if(!strncmp(word[i],"prelax",6)) {
469 csp.dp=atof(word[++i])*BAR;
470 csp.type|=CHSATTR_PRELAX;
472 if(!strncmp(word[i],"trelax",6)) {
473 csp.dt=atof(word[++i]);
474 csp.type|=CHSATTR_TRELAX;
476 if(!strncmp(word[i],"rsteps",6)) {
477 csp.rsteps=atoi(word[++i]);
478 csp.type|=CHSATTR_RSTEPS;
480 if(!strncmp(word[i],"avgrst",6)) {
481 csp.avgrst=atoi(word[++i]);
482 csp.type|=CHSATTR_AVGRST;
485 add_stage(mdrun,STAGE_CHSATTR,&csp);
487 else if(!strncmp(word[0],"prerun",6))
488 mdrun->prerun=atoi(word[1]);
489 else if(!strncmp(word[0],"avgskip",7))
490 mdrun->avgskip=atoi(word[1]);
491 else if(!strncmp(word[0],"elog",4))
492 mdrun->elog=atoi(word[1]);
493 else if(!strncmp(word[0],"tlog",4))
494 mdrun->tlog=atoi(word[1]);
495 else if(!strncmp(word[0],"plog",4))
496 mdrun->plog=atoi(word[1]);
497 else if(!strncmp(word[0],"vlog",4))
498 mdrun->vlog=atoi(word[1]);
499 else if(!strncmp(word[0],"save",4))
500 mdrun->save=atoi(word[1]);
501 else if(!strncmp(word[0],"visualize",9))
502 mdrun->visualize=atoi(word[1]);
503 else if(!strncmp(word[0],"stage",5)) {
504 // for every stage line, add a stage
505 if(!strncmp(word[1],"displace",8)) {
506 dap.nr=atoi(word[2]);
507 dap.dx=atof(word[3]);
508 dap.dy=atof(word[4]);
509 dap.dz=atof(word[5]);
510 add_stage(mdrun,STAGE_DISPLACE_ATOM,&dap);
512 else if(!strncmp(word[1],"ins_atoms",9)) {
513 iap.ins_steps=atoi(word[2]);
514 iap.ins_atoms=atoi(word[3]);
515 iap.element=atoi(word[4]);
516 iap.brand=atoi(word[5]);
517 for(i=0;i<strlen(word[6]);i++) {
520 iap.attr|=ATOM_ATTR_VB;
523 iap.attr|=ATOM_ATTR_HB;
526 iap.attr|=ATOM_ATTR_VA;
529 iap.attr|=ATOM_ATTR_FP;
532 iap.attr|=ATOM_ATTR_1BP;
535 iap.attr|=ATOM_ATTR_2BP;
538 iap.attr|=ATOM_ATTR_3BP;
548 iap.x0=atof(word[8]);
549 iap.y0=atof(word[9]);
550 iap.z0=atof(word[10]);
557 iap.cr=atof(word[9]);
561 iap.x0=atof(word[9]);
562 iap.y0=atof(word[10]);
563 iap.z0=atof(word[11]);
564 iap.x1=atof(word[12]);
565 iap.y1=atof(word[13]);
566 iap.z1=atof(word[14]);
567 iap.cr=atof(word[15]);
571 iap.x0=atof(word[9]);
572 iap.y0=atof(word[10]);
573 iap.z0=atof(word[11]);
574 iap.x1=atof(word[12]);
575 iap.cr=atof(word[13]);
583 add_stage(mdrun,STAGE_INSERT_ATOMS,&iap);
589 else if(!strncmp(word[1],"ins_m_atoms",11)) {
590 imp.element1=atoi(word[2]);
591 imp.element2=atoi(word[3]);
592 imp.amount1=atoi(word[4]);
593 imp.amount2=atoi(word[5]);
594 imp.brand1=atoi(word[6]);
595 imp.brand2=atoi(word[7]);
596 imp.crmin=atof(word[8]);
597 imp.crmax=atof(word[9]);
599 for(i=0;i<strlen(word[8]);i++) {
602 imp.attr|=ATOM_ATTR_VB;
605 imp.attr|=ATOM_ATTR_HB;
608 imp.attr|=ATOM_ATTR_VA;
611 imp.attr|=ATOM_ATTR_FP;
614 imp.attr|=ATOM_ATTR_1BP;
617 imp.attr|=ATOM_ATTR_2BP;
620 imp.attr|=ATOM_ATTR_3BP;
627 imp.attr1=ATOM_ATTR_HB|ATOM_ATTR_VA|ATOM_ATTR_1BP|ATOM_ATTR_2BP|ATOM_ATTR_3BP|ATOM_ATTR_FP;
628 imp.attr2=ATOM_ATTR_HB|ATOM_ATTR_VA|ATOM_ATTR_1BP|ATOM_ATTR_2BP|ATOM_ATTR_3BP|ATOM_ATTR_FP;
629 add_stage(mdrun,STAGE_INSERT_MIXED_ATOMS,&imp);
636 else if(!strncmp(word[1],"continue",8)) {
637 cp.runs=atoi(word[2]);
638 add_stage(mdrun,STAGE_CONTINUE,&cp);
640 else if(!strncmp(word[1],"anneal",6)) {
642 ap.runs=atoi(word[2]);
644 ap.interval=atoi(word[4]);
645 add_stage(mdrun,STAGE_ANNEAL,&ap);
647 else if(!strncmp(word[1],"set_temp",8)) {
648 if(word[2][0]=='c') {
649 stp.type=SET_TEMP_CURRENT;
653 stp.type=SET_TEMP_VALUE;
654 stp.val=atof(word[2]);
656 add_stage(mdrun,STAGE_SET_TEMP,&stp);
658 else if(!strncmp(word[1],"set_timestep",12)) {
659 stsp.tau=atof(word[2]);
660 add_stage(mdrun,STAGE_SET_TIMESTEP,&stsp);
663 printf("%s unknown stage type: %s\n",
669 printf("%s unknown keyword '%s', skipped!\n",
681 int check_pressure(t_moldyn *moldyn,t_mdrun *mdrun) {
685 if(!(mdrun->sattr&SATTR_PRELAX)) {
689 delta=moldyn->p_avg-moldyn->p_ref;
700 int check_temperature(t_moldyn *moldyn,t_mdrun *mdrun) {
704 if(!(mdrun->sattr&SATTR_TRELAX))
707 delta=moldyn->t_avg-moldyn->t_ref;
718 int displace_atom(t_moldyn *moldyn,t_mdrun *mdrun) {
720 t_displace_atom_params *dap;
724 stage=mdrun->stage.current->data;
727 atom=&(moldyn->atom[dap->nr]);
735 int insert_atoms(t_moldyn *moldyn,t_mdrun *mdrun) {
737 t_insert_atoms_params *iap;
747 stage=mdrun->stage.current->data;
752 v.x=0.0; v.y=0.0; v.z=0.0;
756 switch(mdrun->lattice) {
806 printf("%s unknown insertion mode: %02x\n",
812 while(cnt<iap->ins_atoms) {
815 if(iap->type!=INS_POS) {
816 r.x=rand_get_double(&(moldyn->random))*x;
817 r.y=rand_get_double(&(moldyn->random))*y;
818 r.z=rand_get_double(&(moldyn->random))*z;
829 if(iap->type!=INS_TOTAL) {
836 dmin=1000; // for sure too high!
837 for(i=0;i<moldyn->count;i++) {
838 atom=&(moldyn->atom[i]);
839 v3_sub(&dist,&(atom->r),&r);
840 check_per_bound(moldyn,&dist);
841 d=v3_absolute_square(&dist);
842 if(d<(iap->cr*iap->cr)) {
850 if(iap->type==INS_SPHERE) {
851 if((r.x-iap->x0)*(r.x-iap->x0)+
852 (r.y-iap->y0)*(r.y-iap->y0)+
853 (r.z-iap->z0)*(r.z-iap->z0)>
859 add_atom(moldyn,iap->element,
860 iap->brand,iap->attr,&r,&v);
861 printf("%s atom inserted (%d/%d): %f %f %f\n",
862 ME,(iap->cnt_steps+1)*iap->ins_atoms,
863 iap->ins_steps*iap->ins_atoms,r.x,r.y,r.z);
864 printf(" -> d2 = %f/%f\n",dmin,iap->cr*iap->cr);
871 int insert_mixed_atoms(t_moldyn *moldyn,t_mdrun *mdrun) {
874 t_insert_mixed_atoms_params *imp;
876 double x,x0,y,y0,z,z0;
877 double dmin,d,cmin,cmax;
883 stage=mdrun->stage.current->data;
897 cmin=imp->crmin*imp->crmin;
898 cmax=imp->crmax*imp->crmax;
900 while(imp->amount1|imp->amount2) {
905 r.x=rand_get_double(&(moldyn->random))*x;
906 r.y=rand_get_double(&(moldyn->random))*y;
907 r.z=rand_get_double(&(moldyn->random))*z;
911 dmin=1000.0; // for sure too high!
912 for(i=0;i<moldyn->count;i++) {
913 atom=&(moldyn->atom[i]);
914 v3_sub(&dist,&(atom->r),&r);
915 check_per_bound(moldyn,&dist);
916 d=v3_absolute_square(&dist);
928 add_atom(moldyn,imp->element1,
929 imp->brand1,imp->attr1,&r,&v);
930 printf("%s (mixed) atom inserted (%d): %f %f %f\n",
931 ME,imp->amount1,r.x,r.y,r.z);
932 printf(" -> d2 = %f/%f/%f\n",dmin,cmin,cmax);
939 r.x=rand_get_double(&(moldyn->random))*x;
940 r.y=rand_get_double(&(moldyn->random))*y;
941 r.z=rand_get_double(&(moldyn->random))*z;
945 dmin=1000.0; // for sure too high!
946 for(i=0;i<moldyn->count;i++) {
947 atom=&(moldyn->atom[i]);
948 v3_sub(&dist,&(atom->r),&r);
949 check_per_bound(moldyn,&dist);
950 d=v3_absolute_square(&dist);
962 add_atom(moldyn,imp->element2,
963 imp->brand2,imp->attr2,&r,&v);
964 printf("%s (mixed) atom inserted (%d): %f %f %f\n",
965 ME,imp->amount2,r.x,r.y,r.z);
966 printf(" -> d2 = %f/%f/%f\n",dmin,cmin,cmax);
974 int chaatr(t_moldyn *moldyn,t_mdrun *mdrun) {
977 t_chaattr_params *cap;
981 stage=mdrun->stage.current->data;
984 for(i=0;i<moldyn->count;i++) {
985 atom=&(moldyn->atom[i]);
986 if(cap->type&CHAATTR_ELEMENT) {
987 if(cap->element!=atom->element)
990 if(cap->type&CHAATTR_REGION) {
991 if(cap->x0<atom->r.x)
993 if(cap->y0<atom->r.y)
995 if(cap->z0<atom->r.z)
997 if(cap->x1>atom->r.x)
999 if(cap->y1>atom->r.y)
1001 if(cap->z1>atom->r.z)
1004 atom->attr=cap->attr;
1010 int chsattr(t_moldyn *moldyn,t_mdrun *mdrun) {
1013 t_chsattr_params *csp;
1015 stage=mdrun->stage.current->data;
1018 if(csp->type&CHSATTR_PCTRL) {
1020 set_p_scale(moldyn,P_SCALE_BERENDSEN,csp->ptau);
1022 set_p_scale(moldyn,P_SCALE_BERENDSEN,csp->ptau);
1024 if(csp->type&CHSATTR_TCTRL) {
1026 set_t_scale(moldyn,T_SCALE_BERENDSEN,csp->ttau);
1028 set_t_scale(moldyn,T_SCALE_BERENDSEN,csp->ttau);
1030 if(csp->type&CHSATTR_PRELAX) {
1032 mdrun->sattr&=(~(SATTR_PRELAX));
1034 mdrun->sattr|=SATTR_PRELAX;
1037 if(csp->type&CHSATTR_TRELAX) {
1039 mdrun->sattr&=(~(SATTR_TRELAX));
1041 mdrun->sattr|=SATTR_TRELAX;
1044 if(csp->type&CHSATTR_AVGRST) {
1046 mdrun->sattr|=SATTR_AVGRST;
1048 mdrun->sattr&=(~(SATTR_AVGRST));
1050 if(csp->type&CHSATTR_RSTEPS) {
1051 mdrun->relax_steps=csp->rsteps;
1057 #define stage_print(m) if(!(stage->executed)) \
1060 int mdrun_hook(void *ptr1,void *ptr2) {
1070 t_insert_atoms_params *iap;
1071 t_insert_mixed_atoms_params *imp;
1072 t_continue_params *cp;
1073 t_anneal_params *ap;
1074 t_set_temp_params *stp;
1075 t_set_timestep_params *stsp;
1085 /* return immediately if there are no more stage */
1086 if(sl->current==NULL)
1089 /* get stage description */
1090 stage=sl->current->data;
1092 /* steps in next schedule */
1093 steps=mdrun->relax_steps;
1095 /* check whether relaxation steps are necessary */
1096 if((check_pressure(moldyn,mdrun)==TRUE)&\
1097 (check_temperature(moldyn,mdrun)==TRUE)) {
1100 stage_print("\n###########################\n");
1101 stage_print("# [mdrun] executing stage #\n");
1102 stage_print("###########################\n\n");
1104 /* stage specific stuff */
1105 switch(stage->type) {
1106 case STAGE_DISPLACE_ATOM:
1107 stage_print(" -> displace atom\n\n");
1108 displace_atom(moldyn,mdrun);
1111 case STAGE_INSERT_ATOMS:
1112 stage_print(" -> insert atoms\n\n");
1114 if(iap->cnt_steps==iap->ins_steps) {
1118 insert_atoms(moldyn,mdrun);
1124 case STAGE_INSERT_MIXED_ATOMS:
1125 stage_print(" -> insert mixed atoms\n\n");
1127 insert_mixed_atoms(moldyn,mdrun);
1133 case STAGE_CONTINUE:
1134 stage_print(" -> continue\n\n");
1135 if(stage->executed==TRUE) {
1143 stage_print(" -> anneal\n\n");
1145 if(ap->count==ap->runs) {
1149 if(moldyn->t_ref+ap->dt>=0.0)
1150 set_temperature(moldyn,
1151 moldyn->t_ref+ap->dt);
1156 stage_print(" -> change atom attributes\n\n");
1157 chaatr(moldyn,mdrun);
1161 stage_print(" -> change sys attributes\n\n");
1162 chsattr(moldyn,mdrun);
1165 case STAGE_SET_TEMP:
1166 stage_print(" -> set temperature\n\n");
1168 if(stp->type&SET_TEMP_CURRENT) {
1169 set_temperature(moldyn,moldyn->t_avg);
1172 set_temperature(moldyn,stp->val);
1176 case STAGE_SET_TIMESTEP:
1177 stage_print(" -> set timestep\n\n");
1179 mdrun->timestep=stsp->tau;
1183 stage_print(" -> fill lattice\n\n");
1185 switch(fp->lattice) {
1188 o.x=0.5*0.25*fp->lc;
1191 create_lattice(moldyn,
1194 DEFAULT_ATOM_ATTR,0,
1195 fp->lx,fp->ly,fp->lz,
1202 create_lattice(moldyn,
1205 DEFAULT_ATOM_ATTR,1,
1206 fp->lx,fp->ly,fp->lz,
1214 create_lattice(moldyn,
1217 DEFAULT_ATOM_ATTR,0,
1218 fp->lx,fp->ly,fp->lz,
1224 moldyn_bc_check(moldyn);
1227 case STAGE_THERMAL_INIT:
1228 stage_print(" -> thermal init\n\n");
1229 thermal_init(moldyn,TRUE);
1233 printf("%s unknwon stage type\n",ME);
1237 /* mark as executed */
1238 stage->executed=TRUE;
1241 if(change_stage==TRUE) {
1242 printf("%s finished stage\n",ME);
1243 if(list_next_f(sl)==L_NO_NEXT_ELEMENT) {
1244 printf("%s no more stages\n",ME);
1254 if(mdrun->sattr&SATTR_AVGRST)
1255 average_reset(moldyn);
1259 /* continue simulation */
1260 moldyn_add_schedule(moldyn,steps,mdrun->timestep);
1265 int main(int argc,char **argv) {
1272 memset(&mdrun,0,sizeof(t_mdrun));
1273 memset(&moldyn,0,sizeof(t_moldyn));
1275 /* parse arguments */
1276 if(mdrun_parse_argv(&mdrun,argc,argv)<0)
1279 /* initialize list system */
1280 list_init_f(&(mdrun.stage));
1282 /* parse config file */
1283 mdrun_parse_config(&mdrun);
1285 /* reset the stage list */
1286 list_reset_f(&(mdrun.stage));
1290 /* prepare simulation */
1292 if(mdrun.continue_file[0]) {
1293 // read the save file
1294 moldyn_read_save_file(&moldyn,mdrun.continue_file);
1295 // manualaadjusting some stuff
1298 rand_init(&(moldyn.random),NULL,1);
1299 moldyn.random.status|=RAND_STAT_VERBOSE;
1302 moldyn_init(&moldyn,argc,argv);
1305 if(set_int_alg(&moldyn,mdrun.intalgo)<0)
1309 set_cutoff(&moldyn,mdrun.cutoff);
1310 if(set_potential(&moldyn,mdrun.potential)<0)
1312 switch(mdrun.potential) {
1313 case MOLDYN_POTENTIAL_AM:
1314 albe_mult_set_params(&moldyn,
1318 case MOLDYN_POTENTIAL_TM:
1319 tersoff_mult_set_params(&moldyn,
1323 case MOLDYN_POTENTIAL_HO:
1324 harmonic_oscillator_set_params(&moldyn,mdrun.element1);
1326 case MOLDYN_POTENTIAL_LJ:
1327 lennard_jones_set_params(&moldyn,mdrun.element1);
1330 printf("%s unknown potential: %02x\n",
1331 ME,mdrun.potential);
1335 /* if it is a continue run, reset schedule and skip lattice init */
1336 if(mdrun.continue_file[0]) {
1337 memset(&(moldyn.schedule),0,sizeof(t_moldyn_schedule));
1341 /* initial lattice and dimensions */
1342 set_dim(&moldyn,mdrun.dim.x,mdrun.dim.y,mdrun.dim.z,mdrun.vis);
1343 set_pbc(&moldyn,mdrun.pbcx,mdrun.pbcy,mdrun.pbcz);
1344 /* replaced by fill stage !!
1345 switch(mdrun.lattice) {
1347 create_lattice(&moldyn,FCC,mdrun.lc,mdrun.fill_element,
1348 mdrun.m1,DEFAULT_ATOM_ATTR,
1349 mdrun.fill_brand,mdrun.lx,
1350 mdrun.ly,mdrun.lz,NULL,0,NULL);
1353 create_lattice(&moldyn,DIAMOND,mdrun.lc,
1355 mdrun.m1,DEFAULT_ATOM_ATTR,
1356 mdrun.fill_brand,mdrun.lx,
1357 mdrun.ly,mdrun.lz,NULL,0,NULL);
1360 o.x=0.5*0.25*mdrun.lc; o.y=o.x; o.z=o.x;
1361 create_lattice(&moldyn,FCC,mdrun.lc,mdrun.element1,
1362 mdrun.m1,DEFAULT_ATOM_ATTR,0,mdrun.lx,
1363 mdrun.ly,mdrun.lz,&o,0,NULL);
1364 o.x+=0.25*mdrun.lc; o.y=o.x; o.z=o.x;
1365 create_lattice(&moldyn,FCC,mdrun.lc,mdrun.element2,
1366 mdrun.m2,DEFAULT_ATOM_ATTR,1,mdrun.lx,
1367 mdrun.ly,mdrun.lz,&o,0,NULL);
1370 set_nn_dist(&moldyn,mdrun.nnd);
1373 printf("%s unknown lattice type: %02x\n",
1377 moldyn_bc_check(&moldyn);
1378 replaced by fill stage !! */
1380 /* temperature and pressure */
1381 set_temperature(&moldyn,mdrun.temperature);
1382 set_pressure(&moldyn,mdrun.pressure);
1383 /* replaced thermal_init stage
1384 thermal_init(&moldyn,TRUE);
1388 /* first schedule */
1389 moldyn_add_schedule(&moldyn,mdrun.prerun,mdrun.timestep);
1392 moldyn_set_log_dir(&moldyn,mdrun.sdir);
1393 moldyn_set_report(&moldyn,"CHANGE ME","CHANGE ME TOO");
1395 moldyn_set_log(&moldyn,LOG_TOTAL_ENERGY,mdrun.elog);
1397 moldyn_set_log(&moldyn,LOG_TEMPERATURE,mdrun.tlog);
1399 moldyn_set_log(&moldyn,LOG_PRESSURE,mdrun.plog);
1401 moldyn_set_log(&moldyn,LOG_VOLUME,mdrun.vlog);
1403 moldyn_set_log(&moldyn,VISUAL_STEP,mdrun.visualize);
1405 moldyn_set_log(&moldyn,SAVE_STEP,mdrun.save);
1406 moldyn_set_log(&moldyn,CREATE_REPORT,0);
1407 set_avg_skip(&moldyn,mdrun.avgskip);
1409 /* prepare the hook function */
1410 moldyn_set_schedule_hook(&moldyn,&mdrun_hook,&mdrun);
1412 /* run the simulation */
1413 moldyn_integrate(&moldyn);
1416 moldyn_shutdown(&moldyn);
1418 list_destroy_f(&(mdrun.stage));