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 printf("%s unknown stage type: %02x\n",ME,type);
130 stage=malloc(sizeof(t_stage));
132 perror("[mdrun] malloc (add stage)");
137 stage->executed=FALSE;
139 stage->params=malloc(psize);
140 if(stage->params==NULL) {
141 perror("[mdrun] malloc (stage params)");
145 memcpy(stage->params,params,psize);
147 list_add_immediate_f(&(mdrun->stage),stage);
152 int mdrun_parse_config(t_mdrun *mdrun) {
162 t_displace_atom_params dap;
163 t_insert_atoms_params iap;
164 t_insert_mixed_atoms_params imp;
165 t_continue_params cp;
167 t_chaattr_params cap;
168 t_chsattr_params csp;
169 t_set_temp_params stp;
170 t_set_timestep_params stsp;
172 /* open config file */
173 fd=open(mdrun->cfile,O_RDONLY);
175 snprintf(error,128,"%s open cfile %s",ME,mdrun->cfile);
180 /* read, parse, set */
185 ret=get_line(fd,line,128);
189 // ignore # lines and \n
190 if((line[0]=='#')|(ret==1))
194 memset(&iap,0,sizeof(t_insert_atoms_params));
195 memset(&imp,0,sizeof(t_insert_mixed_atoms_params));
196 memset(&cp,0,sizeof(t_continue_params));
197 memset(&ap,0,sizeof(t_anneal_params));
198 memset(&cap,0,sizeof(t_chaattr_params));
199 memset(&csp,0,sizeof(t_chsattr_params));
200 memset(&stp,0,sizeof(t_set_temp_params));
201 memset(&stsp,0,sizeof(t_set_timestep_params));
203 // get command + args
207 wptr=strtok(NULL," \t");
209 wptr=strtok(line," \t");
212 strncpy(word[wcnt],wptr,64);
216 if(!strncmp(word[0],"potential",9)) {
217 if(!strncmp(word[1],"albe",4))
218 mdrun->potential=MOLDYN_POTENTIAL_AM;
219 if(!strncmp(word[1],"tersoff",7))
220 mdrun->potential=MOLDYN_POTENTIAL_TM;
221 if(!strncmp(word[1],"ho",2))
222 mdrun->potential=MOLDYN_POTENTIAL_HO;
223 if(!strncmp(word[1],"lj",2))
224 mdrun->potential=MOLDYN_POTENTIAL_LJ;
226 else if(!strncmp(word[0],"continue",8))
227 strncpy(mdrun->continue_file,word[1],128);
228 else if(!strncmp(word[0],"cutoff",6))
229 mdrun->cutoff=atof(word[1]);
230 else if(!strncmp(word[0],"nnd",3))
231 mdrun->nnd=atof(word[1]);
232 else if(!strncmp(word[0],"intalgo",7)) {
233 if(!strncmp(word[1],"verlet",5))
234 mdrun->intalgo=MOLDYN_INTEGRATE_VERLET;
236 else if(!strncmp(word[0],"timestep",8))
237 mdrun->timestep=atof(word[1]);
238 else if(!strncmp(word[0],"volume",6)) {
239 mdrun->dim.x=atof(word[1]);
240 mdrun->dim.y=atof(word[2]);
241 mdrun->dim.z=atof(word[3]);
242 if(strncmp(word[4],"0",1))
245 else if(!strncmp(word[0],"pbc",3)) {
246 if(strncmp(word[1],"0",1))
250 if(strncmp(word[2],"0",1))
254 if(strncmp(word[3],"0",1))
259 else if(!strncmp(word[0],"temperature",11))
260 mdrun->temperature=atof(word[1]);
261 else if(!strncmp(word[0],"pressure",8))
262 mdrun->pressure=atof(word[1]);
263 else if(!strncmp(word[0],"lattice",7)) {
264 if(!strncmp(word[1],"zincblende",10))
265 mdrun->lattice=ZINCBLENDE;
266 if(!strncmp(word[1],"fcc",3))
268 if(!strncmp(word[1],"diamond",7))
269 mdrun->lattice=DIAMOND;
270 if(!strncmp(word[1],"none",4))
273 else if(!strncmp(word[0],"element1",8)) {
274 mdrun->element1=atoi(word[1]);
275 mdrun->m1=pse_mass[mdrun->element1];
277 else if(!strncmp(word[0],"element2",8)) {
278 mdrun->element2=atoi(word[1]);
279 mdrun->m2=pse_mass[mdrun->element2];
281 else if(!strncmp(word[0],"fill",6)) {
282 // only lc mode by now
283 mdrun->lx=atoi(word[2]);
284 mdrun->ly=atoi(word[3]);
285 mdrun->lz=atoi(word[4]);
286 mdrun->lc=atof(word[5]);
288 mdrun->fill_element=atoi(word[6]);
289 mdrun->fill_brand=atoi(word[7]);
292 mdrun->fill_element=mdrun->element1;
296 else if(!strncmp(word[0],"aattr",5)) {
297 // for aatrib line we need a special stage
298 // containing one schedule of 0 loops ...
299 for(i=0;i<strlen(word[1]);i++) {
302 cap.type|=CHAATTR_TOTALV;
305 cap.type|=CHAATTR_REGION;
308 cap.type|=CHAATTR_ELEMENT;
315 if(cap.type&CHAATTR_REGION) {
316 cap.x0=atof(word[1]);
317 cap.y0=atof(word[2]);
318 cap.z0=atof(word[3]);
319 cap.x1=atof(word[4]);
320 cap.y1=atof(word[5]);
321 cap.z1=atof(word[6]);
324 if(cap.type&CHAATTR_ELEMENT) {
325 cap.element=atoi(word[i]);
328 for(o=0;o<strlen(word[i]);o++) {
331 cap.attr|=ATOM_ATTR_VB;
334 cap.attr|=ATOM_ATTR_HB;
337 cap.attr|=ATOM_ATTR_VA;
340 cap.attr|=ATOM_ATTR_FP;
343 cap.attr|=ATOM_ATTR_1BP;
346 cap.attr|=ATOM_ATTR_2BP;
349 cap.attr|=ATOM_ATTR_3BP;
355 add_stage(mdrun,STAGE_CHAATTR,&cap);
357 else if(!strncmp(word[0],"sattr",5)) {
358 // for satrib line we need a special stage
359 // containing one schedule of 0 loops ...
361 for(i=1;i<wcnt;i++) {
362 if(!strncmp(word[i],"pctrl",5)) {
363 csp.ptau=0.01/(atof(word[++i])*GPA);
364 csp.type|=CHSATTR_PCTRL;
366 if(!strncmp(word[i],"tctrl",5)) {
367 csp.ttau=atof(word[++i]);
368 csp.type|=CHSATTR_TCTRL;
370 if(!strncmp(word[i],"prelax",6)) {
371 csp.dp=atof(word[++i])*BAR;
372 csp.type|=CHSATTR_PRELAX;
374 if(!strncmp(word[i],"trelax",6)) {
375 csp.dt=atof(word[++i]);
376 csp.type|=CHSATTR_TRELAX;
378 if(!strncmp(word[i],"rsteps",6)) {
379 csp.rsteps=atoi(word[++i]);
380 csp.type|=CHSATTR_RSTEPS;
382 if(!strncmp(word[i],"avgrst",6)) {
383 csp.avgrst=atoi(word[++i]);
384 csp.type|=CHSATTR_AVGRST;
387 add_stage(mdrun,STAGE_CHSATTR,&csp);
389 else if(!strncmp(word[0],"prerun",6))
390 mdrun->prerun=atoi(word[1]);
391 else if(!strncmp(word[0],"avgskip",7))
392 mdrun->avgskip=atoi(word[1]);
393 else if(!strncmp(word[0],"elog",4))
394 mdrun->elog=atoi(word[1]);
395 else if(!strncmp(word[0],"tlog",4))
396 mdrun->tlog=atoi(word[1]);
397 else if(!strncmp(word[0],"plog",4))
398 mdrun->plog=atoi(word[1]);
399 else if(!strncmp(word[0],"vlog",4))
400 mdrun->vlog=atoi(word[1]);
401 else if(!strncmp(word[0],"save",4))
402 mdrun->save=atoi(word[1]);
403 else if(!strncmp(word[0],"visualize",9))
404 mdrun->visualize=atoi(word[1]);
405 else if(!strncmp(word[0],"stage",5)) {
406 // for every stage line, add a stage
407 if(!strncmp(word[1],"displace",8)) {
408 dap.nr=atoi(word[2]);
409 dap.dx=atof(word[3]);
410 dap.dy=atof(word[4]);
411 dap.dz=atof(word[5]);
412 add_stage(mdrun,STAGE_DISPLACE_ATOM,&dap);
414 else if(!strncmp(word[1],"ins_atoms",9)) {
415 iap.ins_steps=atoi(word[2]);
416 iap.ins_atoms=atoi(word[3]);
417 iap.element=atoi(word[4]);
418 iap.brand=atoi(word[5]);
419 for(i=0;i<strlen(word[6]);i++) {
422 iap.attr|=ATOM_ATTR_VB;
425 iap.attr|=ATOM_ATTR_HB;
428 iap.attr|=ATOM_ATTR_VA;
431 iap.attr|=ATOM_ATTR_FP;
434 iap.attr|=ATOM_ATTR_1BP;
437 iap.attr|=ATOM_ATTR_2BP;
440 iap.attr|=ATOM_ATTR_3BP;
450 iap.x0=atof(word[8]);
451 iap.y0=atof(word[9]);
452 iap.z0=atof(word[10]);
455 if(word[8][0]=='t') {
457 iap.cr=atof(word[9]);
461 iap.x0=atof(word[8]);
462 iap.y0=atof(word[9]);
463 iap.z0=atof(word[10]);
464 iap.x1=atof(word[11]);
465 iap.y1=atof(word[12]);
466 iap.z1=atof(word[13]);
467 iap.cr=atof(word[14]);
472 add_stage(mdrun,STAGE_INSERT_ATOMS,&iap);
478 else if(!strncmp(word[1],"ins_m_atoms",11)) {
479 imp.element1=atoi(word[2]);
480 imp.element2=atoi(word[3]);
481 imp.amount1=atoi(word[4]);
482 imp.amount2=atoi(word[5]);
483 imp.brand1=atoi(word[6]);
484 imp.brand2=atoi(word[7]);
485 imp.crmin=atof(word[8]);
486 imp.crmax=atof(word[9]);
488 for(i=0;i<strlen(word[8]);i++) {
491 imp.attr|=ATOM_ATTR_VB;
494 imp.attr|=ATOM_ATTR_HB;
497 imp.attr|=ATOM_ATTR_VA;
500 imp.attr|=ATOM_ATTR_FP;
503 imp.attr|=ATOM_ATTR_1BP;
506 imp.attr|=ATOM_ATTR_2BP;
509 imp.attr|=ATOM_ATTR_3BP;
516 imp.attr1=ATOM_ATTR_HB|ATOM_ATTR_VA|ATOM_ATTR_1BP|ATOM_ATTR_2BP|ATOM_ATTR_3BP|ATOM_ATTR_FP;
517 imp.attr2=ATOM_ATTR_HB|ATOM_ATTR_VA|ATOM_ATTR_1BP|ATOM_ATTR_2BP|ATOM_ATTR_3BP|ATOM_ATTR_FP;
518 add_stage(mdrun,STAGE_INSERT_MIXED_ATOMS,&imp);
525 else if(!strncmp(word[1],"continue",8)) {
526 cp.runs=atoi(word[2]);
527 add_stage(mdrun,STAGE_CONTINUE,&cp);
529 else if(!strncmp(word[1],"anneal",6)) {
531 ap.runs=atoi(word[2]);
533 ap.interval=atoi(word[4]);
534 add_stage(mdrun,STAGE_ANNEAL,&ap);
536 else if(!strncmp(word[1],"set_temp",8)) {
537 if(word[2][0]=='c') {
538 stp.type=SET_TEMP_CURRENT;
542 stp.type=SET_TEMP_VALUE;
543 stp.val=atof(word[2]);
545 add_stage(mdrun,STAGE_SET_TEMP,&stp);
547 else if(!strncmp(word[1],"set_timestep",12)) {
548 stsp.tau=atof(word[2]);
549 add_stage(mdrun,STAGE_SET_TIMESTEP,&stsp);
552 printf("%s unknown stage type: %s\n",
558 printf("%s unknown keyword '%s', skipped!\n",
570 int check_pressure(t_moldyn *moldyn,t_mdrun *mdrun) {
574 if(!(mdrun->sattr&SATTR_PRELAX)) {
578 delta=moldyn->p_avg-moldyn->p_ref;
589 int check_temperature(t_moldyn *moldyn,t_mdrun *mdrun) {
593 if(!(mdrun->sattr&SATTR_TRELAX))
596 delta=moldyn->t_avg-moldyn->t_ref;
607 int displace_atom(t_moldyn *moldyn,t_mdrun *mdrun) {
609 t_displace_atom_params *dap;
613 stage=mdrun->stage.current->data;
616 atom=&(moldyn->atom[dap->nr]);
624 int insert_atoms(t_moldyn *moldyn,t_mdrun *mdrun) {
626 t_insert_atoms_params *iap;
636 stage=mdrun->stage.current->data;
641 v.x=0.0; v.y=0.0; v.z=0.0;
645 switch(mdrun->lattice) {
686 printf("%s unknown insertion mode: %02x\n",
692 while(cnt<iap->ins_atoms) {
695 if(iap->type!=INS_POS) {
696 r.x=rand_get_double(&(moldyn->random))*x;
697 r.y=rand_get_double(&(moldyn->random))*y;
698 r.z=rand_get_double(&(moldyn->random))*z;
709 if(iap->type!=INS_TOTAL) {
716 dmin=1000; // for sure too high!
717 for(i=0;i<moldyn->count;i++) {
718 atom=&(moldyn->atom[i]);
719 v3_sub(&dist,&(atom->r),&r);
720 check_per_bound(moldyn,&dist);
721 d=v3_absolute_square(&dist);
722 if(d<(iap->cr*iap->cr)) {
731 add_atom(moldyn,iap->element,pse_mass[iap->element],
732 iap->brand,iap->attr,&r,&v);
733 printf("%s atom inserted (%d/%d): %f %f %f\n",
734 ME,(iap->cnt_steps+1)*iap->ins_atoms,
735 iap->ins_steps*iap->ins_atoms,r.x,r.y,r.z);
736 printf(" -> d2 = %f/%f\n",dmin,iap->cr*iap->cr);
743 int insert_mixed_atoms(t_moldyn *moldyn,t_mdrun *mdrun) {
746 t_insert_mixed_atoms_params *imp;
748 double x,x0,y,y0,z,z0;
749 double dmin,d,cmin,cmax;
755 stage=mdrun->stage.current->data;
769 cmin=imp->crmin*imp->crmin;
770 cmax=imp->crmax*imp->crmax;
772 while(imp->amount1|imp->amount2) {
777 r.x=rand_get_double(&(moldyn->random))*x;
778 r.y=rand_get_double(&(moldyn->random))*y;
779 r.z=rand_get_double(&(moldyn->random))*z;
783 dmin=1000.0; // for sure too high!
784 for(i=0;i<moldyn->count;i++) {
785 atom=&(moldyn->atom[i]);
786 v3_sub(&dist,&(atom->r),&r);
787 check_per_bound(moldyn,&dist);
788 d=v3_absolute_square(&dist);
800 add_atom(moldyn,imp->element1,pse_mass[imp->element1],
801 imp->brand1,imp->attr1,&r,&v);
802 printf("%s (mixed) atom inserted (%d): %f %f %f\n",
803 ME,imp->amount1,r.x,r.y,r.z);
804 printf(" -> d2 = %f/%f/%f\n",dmin,cmin,cmax);
811 r.x=rand_get_double(&(moldyn->random))*x;
812 r.y=rand_get_double(&(moldyn->random))*y;
813 r.z=rand_get_double(&(moldyn->random))*z;
817 dmin=1000.0; // for sure too high!
818 for(i=0;i<moldyn->count;i++) {
819 atom=&(moldyn->atom[i]);
820 v3_sub(&dist,&(atom->r),&r);
821 check_per_bound(moldyn,&dist);
822 d=v3_absolute_square(&dist);
834 add_atom(moldyn,imp->element2,pse_mass[imp->element2],
835 imp->brand2,imp->attr2,&r,&v);
836 printf("%s (mixed) atom inserted (%d): %f %f %f\n",
837 ME,imp->amount2,r.x,r.y,r.z);
838 printf(" -> d2 = %f/%f/%f\n",dmin,cmin,cmax);
846 int chaatr(t_moldyn *moldyn,t_mdrun *mdrun) {
849 t_chaattr_params *cap;
853 stage=mdrun->stage.current->data;
856 for(i=0;i<moldyn->count;i++) {
857 atom=&(moldyn->atom[i]);
858 if(cap->type&CHAATTR_ELEMENT) {
859 if(cap->element!=atom->element)
862 if(cap->type&CHAATTR_REGION) {
863 if(cap->x0<atom->r.x)
865 if(cap->y0<atom->r.y)
867 if(cap->z0<atom->r.z)
869 if(cap->x1>atom->r.x)
871 if(cap->y1>atom->r.y)
873 if(cap->z1>atom->r.z)
876 atom->attr=cap->attr;
882 int chsattr(t_moldyn *moldyn,t_mdrun *mdrun) {
885 t_chsattr_params *csp;
887 stage=mdrun->stage.current->data;
890 if(csp->type&CHSATTR_PCTRL) {
892 set_p_scale(moldyn,P_SCALE_BERENDSEN,csp->ptau);
894 set_p_scale(moldyn,P_SCALE_BERENDSEN,csp->ptau);
896 if(csp->type&CHSATTR_TCTRL) {
898 set_t_scale(moldyn,T_SCALE_BERENDSEN,csp->ttau);
900 set_t_scale(moldyn,T_SCALE_BERENDSEN,csp->ttau);
902 if(csp->type&CHSATTR_PRELAX) {
904 mdrun->sattr&=(~(SATTR_PRELAX));
906 mdrun->sattr|=SATTR_PRELAX;
909 if(csp->type&CHSATTR_TRELAX) {
911 mdrun->sattr&=(~(SATTR_TRELAX));
913 mdrun->sattr|=SATTR_TRELAX;
916 if(csp->type&CHSATTR_AVGRST) {
918 mdrun->sattr|=SATTR_AVGRST;
920 mdrun->sattr&=(~(SATTR_AVGRST));
922 if(csp->type&CHSATTR_RSTEPS) {
923 mdrun->relax_steps=csp->rsteps;
929 #define stage_print(m) if(!(stage->executed)) \
932 int mdrun_hook(void *ptr1,void *ptr2) {
941 t_insert_atoms_params *iap;
942 t_insert_mixed_atoms_params *imp;
943 t_continue_params *cp;
945 t_set_temp_params *stp;
946 t_set_timestep_params *stsp;
955 /* return immediately if there are no more stage */
956 if(sl->current==NULL)
959 /* get stage description */
960 stage=sl->current->data;
962 /* steps in next schedule */
963 steps=mdrun->relax_steps;
965 /* check whether relaxation steps are necessary */
966 if((check_pressure(moldyn,mdrun)==TRUE)&\
967 (check_temperature(moldyn,mdrun)==TRUE)) {
970 stage_print("\n###########################\n");
971 stage_print("# [mdrun] executing stage #\n");
972 stage_print("###########################\n\n");
974 /* stage specific stuff */
975 switch(stage->type) {
976 case STAGE_DISPLACE_ATOM:
977 stage_print(" -> displace atom\n\n");
978 displace_atom(moldyn,mdrun);
981 case STAGE_INSERT_ATOMS:
982 stage_print(" -> insert atoms\n\n");
984 if(iap->cnt_steps==iap->ins_steps) {
988 insert_atoms(moldyn,mdrun);
994 case STAGE_INSERT_MIXED_ATOMS:
995 stage_print(" -> insert mixed atoms\n\n");
997 insert_mixed_atoms(moldyn,mdrun);
1003 case STAGE_CONTINUE:
1004 stage_print(" -> continue\n\n");
1005 if(stage->executed==TRUE) {
1013 stage_print(" -> anneal\n\n");
1015 if(ap->count==ap->runs) {
1019 if(moldyn->t_ref+ap->dt>=0.0)
1020 set_temperature(moldyn,
1021 moldyn->t_ref+ap->dt);
1026 stage_print(" -> change atom attributes\n\n");
1027 chaatr(moldyn,mdrun);
1031 stage_print(" -> change sys attributes\n\n");
1032 chsattr(moldyn,mdrun);
1035 case STAGE_SET_TEMP:
1036 stage_print(" -> set temperature\n\n");
1038 if(stp->type&SET_TEMP_CURRENT) {
1039 set_temperature(moldyn,moldyn->t_avg);
1042 set_temperature(moldyn,stp->val);
1046 case STAGE_SET_TIMESTEP:
1047 stage_print(" -> set timestep\n\n");
1049 mdrun->timestep=stsp->tau;
1053 printf("%s unknwon stage type\n",ME);
1057 /* mark as executed */
1058 stage->executed=TRUE;
1061 if(change_stage==TRUE) {
1062 printf("%s finished stage\n",ME);
1063 if(list_next_f(sl)==L_NO_NEXT_ELEMENT) {
1064 printf("%s no more stages\n",ME);
1074 if(mdrun->sattr&SATTR_AVGRST)
1075 average_reset(moldyn);
1079 /* continue simulation */
1080 moldyn_add_schedule(moldyn,steps,mdrun->timestep);
1085 int main(int argc,char **argv) {
1092 memset(&mdrun,0,sizeof(t_mdrun));
1093 memset(&moldyn,0,sizeof(t_moldyn));
1095 /* parse arguments */
1096 if(mdrun_parse_argv(&mdrun,argc,argv)<0)
1099 /* initialize list system */
1100 list_init_f(&(mdrun.stage));
1102 /* parse config file */
1103 mdrun_parse_config(&mdrun);
1105 /* reset the stage list */
1106 list_reset_f(&(mdrun.stage));
1110 /* prepare simulation */
1112 if(mdrun.continue_file[0]) {
1113 // read the save file
1114 moldyn_read_save_file(&moldyn,mdrun.continue_file);
1115 // manualaadjusting some stuff
1118 rand_init(&(moldyn.random),NULL,1);
1119 moldyn.random.status|=RAND_STAT_VERBOSE;
1122 moldyn_init(&moldyn,argc,argv);
1125 if(set_int_alg(&moldyn,mdrun.intalgo)<0)
1129 set_cutoff(&moldyn,mdrun.cutoff);
1130 if(set_potential(&moldyn,mdrun.potential)<0)
1132 switch(mdrun.potential) {
1133 case MOLDYN_POTENTIAL_AM:
1134 albe_mult_set_params(&moldyn,
1138 case MOLDYN_POTENTIAL_TM:
1139 tersoff_mult_set_params(&moldyn,
1143 case MOLDYN_POTENTIAL_HO:
1144 harmonic_oscillator_set_params(&moldyn,mdrun.element1);
1146 case MOLDYN_POTENTIAL_LJ:
1147 lennard_jones_set_params(&moldyn,mdrun.element1);
1150 printf("%s unknown potential: %02x\n",
1151 ME,mdrun.potential);
1155 /* if it is a continue run, reset schedule and skip lattice init */
1156 if(mdrun.continue_file[0]) {
1157 memset(&(moldyn.schedule),0,sizeof(t_moldyn_schedule));
1161 /* initial lattice and dimensions */
1162 set_dim(&moldyn,mdrun.dim.x,mdrun.dim.y,mdrun.dim.z,mdrun.vis);
1163 set_pbc(&moldyn,mdrun.pbcx,mdrun.pbcy,mdrun.pbcz);
1164 switch(mdrun.lattice) {
1166 create_lattice(&moldyn,FCC,mdrun.lc,mdrun.fill_element,
1167 mdrun.m1,DEFAULT_ATOM_ATTR,
1168 mdrun.fill_brand,mdrun.lx,
1169 mdrun.ly,mdrun.lz,NULL);
1172 create_lattice(&moldyn,DIAMOND,mdrun.lc,
1174 mdrun.m1,DEFAULT_ATOM_ATTR,
1175 mdrun.fill_brand,mdrun.lx,
1176 mdrun.ly,mdrun.lz,NULL);
1179 o.x=0.5*0.25*mdrun.lc; o.y=o.x; o.z=o.x;
1180 create_lattice(&moldyn,FCC,mdrun.lc,mdrun.element1,
1181 mdrun.m1,DEFAULT_ATOM_ATTR,0,mdrun.lx,
1182 mdrun.ly,mdrun.lz,&o);
1183 o.x+=0.25*mdrun.lc; o.y=o.x; o.z=o.x;
1184 create_lattice(&moldyn,FCC,mdrun.lc,mdrun.element2,
1185 mdrun.m2,DEFAULT_ATOM_ATTR,1,mdrun.lx,
1186 mdrun.ly,mdrun.lz,&o);
1189 set_nn_dist(&moldyn,mdrun.nnd);
1192 printf("%s unknown lattice type: %02x\n",
1196 moldyn_bc_check(&moldyn);
1198 /* temperature and pressure */
1199 set_temperature(&moldyn,mdrun.temperature);
1200 set_pressure(&moldyn,mdrun.pressure);
1201 thermal_init(&moldyn,TRUE);
1204 /* first schedule */
1205 moldyn_add_schedule(&moldyn,mdrun.prerun,mdrun.timestep);
1208 moldyn_set_log_dir(&moldyn,mdrun.sdir);
1209 moldyn_set_report(&moldyn,"CHANGE ME","CHANGE ME TOO");
1211 moldyn_set_log(&moldyn,LOG_TOTAL_ENERGY,mdrun.elog);
1213 moldyn_set_log(&moldyn,LOG_TEMPERATURE,mdrun.tlog);
1215 moldyn_set_log(&moldyn,LOG_PRESSURE,mdrun.plog);
1217 moldyn_set_log(&moldyn,LOG_VOLUME,mdrun.vlog);
1219 moldyn_set_log(&moldyn,VISUAL_STEP,mdrun.visualize);
1221 moldyn_set_log(&moldyn,SAVE_STEP,mdrun.save);
1222 moldyn_set_log(&moldyn,CREATE_REPORT,0);
1223 set_avg_skip(&moldyn,mdrun.avgskip);
1225 /* prepare the hook function */
1226 moldyn_set_schedule_hook(&moldyn,&mdrun_hook,&mdrun);
1228 /* run the simulation */
1229 moldyn_integrate(&moldyn);
1232 moldyn_shutdown(&moldyn);
1234 list_destroy_f(&(mdrun.stage));