t_stage *stage;
switch(type) {
+ case STAGE_DISPLACE_ATOM:
+ psize=sizeof(t_displace_atom_params);
+ break;
+ case STAGE_DEL_ATOMS:
+ psize=sizeof(t_del_atoms_params);
+ break;
+ case STAGE_MODIFY_ATOMS:
+ psize=sizeof(t_modify_atoms_params);
+ break;
case STAGE_INSERT_ATOMS:
psize=sizeof(t_insert_atoms_params);
break;
+ case STAGE_INSERT_MIXED_ATOMS:
+ psize=sizeof(t_insert_mixed_atoms_params);
+ break;
case STAGE_CONTINUE:
psize=sizeof(t_continue_params);
break;
case STAGE_CHSATTR:
psize=sizeof(t_chsattr_params);
break;
+ case STAGE_SET_TEMP:
+ psize=sizeof(t_set_temp_params);
+ break;
+ case STAGE_SET_TIMESTEP:
+ psize=sizeof(t_set_timestep_params);
+ break;
+ case STAGE_FILL:
+ psize=sizeof(t_fill_params);
+ break;
+ case STAGE_THERMAL_INIT:
+ psize=0;
+ break;
+ case STAGE_CRT:
+ psize=sizeof(t_crt_params);
+ break;
default:
printf("%s unknown stage type: %02x\n",ME,type);
return -1;
char error[128];
char line[128];
char *wptr;
- char word[16][32];
+ char word[32][64];
int wcnt;
int i,o;
+ t_displace_atom_params dap;
+ t_modify_atoms_params map;
t_insert_atoms_params iap;
+ t_insert_mixed_atoms_params imp;
t_continue_params cp;
t_anneal_params ap;
t_chaattr_params cap;
t_chsattr_params csp;
+ t_set_temp_params stp;
+ t_set_timestep_params stsp;
+ t_fill_params fp;
+ t_del_atoms_params delp;
+ t_crt_params crtp;
/* open config file */
fd=open(mdrun->cfile,O_RDONLY);
// reset
memset(&iap,0,sizeof(t_insert_atoms_params));
+ memset(&map,0,sizeof(t_modify_atoms_params));
+ memset(&imp,0,sizeof(t_insert_mixed_atoms_params));
memset(&cp,0,sizeof(t_continue_params));
memset(&ap,0,sizeof(t_anneal_params));
memset(&cap,0,sizeof(t_chaattr_params));
memset(&csp,0,sizeof(t_chsattr_params));
+ memset(&stp,0,sizeof(t_set_temp_params));
+ memset(&stsp,0,sizeof(t_set_timestep_params));
+ memset(&fp,0,sizeof(t_fill_params));
+ memset(&delp,0,sizeof(t_del_atoms_params));
+ memset(&crtp,0,sizeof(t_crt_params));
// get command + args
wcnt=0;
wptr=strtok(line," \t");
if(wptr==NULL)
break;
- strncpy(word[wcnt],wptr,32);
+ strncpy(word[wcnt],wptr,64);
wcnt+=1;
}
if(!strncmp(word[1],"lj",2))
mdrun->potential=MOLDYN_POTENTIAL_LJ;
}
+ else if(!strncmp(word[0],"continue",8))
+ strncpy(mdrun->continue_file,word[1],128);
else if(!strncmp(word[0],"cutoff",6))
mdrun->cutoff=atof(word[1]);
else if(!strncmp(word[0],"nnd",3))
mdrun->lattice=FCC;
if(!strncmp(word[1],"diamond",7))
mdrun->lattice=DIAMOND;
+ if(!strncmp(word[1],"none",4))
+ mdrun->lattice=NONE;
+ if(wcnt==3)
+ mdrun->lc=atof(word[2]);
}
else if(!strncmp(word[0],"element1",8)) {
mdrun->element1=atoi(word[1]);
- mdrun->m1=pse_mass[mdrun->element1];
}
else if(!strncmp(word[0],"element2",8)) {
mdrun->element2=atoi(word[1]);
- mdrun->m2=pse_mass[mdrun->element2];
}
else if(!strncmp(word[0],"fill",6)) {
- // only lc mode by now
- mdrun->lx=atoi(word[2]);
- mdrun->ly=atoi(word[3]);
- mdrun->lz=atoi(word[4]);
- mdrun->lc=atof(word[5]);
+ // default values
+ fp.fill_element=mdrun->element1;
+ fp.fill_brand=0;
+ fp.lattice=mdrun->lattice;
+ fp.p_params.type=0;
+ fp.d_params.type=0;
+ fp.d_params.stype=0;
+ // parse fill command
+ i=1;
+ while(i<wcnt) {
+ if(!strncmp(word[i],"lc",2)) {
+ fp.lx=atoi(word[++i]);
+ fp.ly=atoi(word[++i]);
+ fp.lz=atoi(word[++i]);
+ fp.lc=atof(word[++i]);
+ mdrun->lc=fp.lc;
+ continue;
+ }
+ if(!strncmp(word[i],"eb",2)) {
+ fp.fill_element=atoi(word[++i]);
+ fp.fill_brand=atoi(word[++i]);
+ continue;
+ }
+ if(word[i][0]=='p') {
+ i+=1;
+ switch(word[i][0]) {
+ case 'i':
+ if(word[i][1]=='r')
+ fp.p_params.type=PART_INSIDE_R;
+ else
+ fp.p_params.type=PART_INSIDE_D;
+ break;
+ case 'o':
+ if(word[i][1]=='r')
+ fp.p_params.type=PART_OUTSIDE_R;
+ else
+ fp.p_params.type=PART_OUTSIDE_D;
+ break;
+ default:
+ break;
+ }
+ if((fp.p_params.type==PART_INSIDE_R)||
+ (fp.p_params.type==PART_OUTSIDE_R)) {
+ fp.p_params.r=atof(word[++i]);
+ fp.p_params.p.x=atof(word[++i]);
+ fp.p_params.p.y=atof(word[++i]);
+ fp.p_params.p.z=atof(word[++i]);
+ }
+ if((fp.p_params.type==PART_INSIDE_D)||
+ (fp.p_params.type==PART_OUTSIDE_D)) {
+ fp.p_params.p.x=atof(word[++i]);
+ fp.p_params.p.y=atof(word[++i]);
+ fp.p_params.p.z=atof(word[++i]);
+ fp.p_params.d.x=atof(word[++i]);
+ fp.p_params.d.y=atof(word[++i]);
+ fp.p_params.d.z=atof(word[++i]);
+ }
+ continue;
+ }
+ if(word[i][0]=='d') {
+ switch(word[++i][0]) {
+ case '0':
+
+ fp.d_params.type=DEFECT_TYPE_0D;
+ if(!strncmp(word[i+1],"dbx",3)) {
+ fp.d_params.stype=DEFECT_STYPE_DB_X;
+ }
+ if(!strncmp(word[i+1],"dby",3)) {
+ fp.d_params.stype=DEFECT_STYPE_DB_Y;
+ }
+ if(!strncmp(word[i+1],"dbz",3)) {
+ fp.d_params.stype=DEFECT_STYPE_DB_Z;
+ }
+ if(!strncmp(word[i+1],"dbr",3)) {
+ fp.d_params.stype=DEFECT_STYPE_DB_R;
+ }
+ i+=1;
+ fp.d_params.od=atof(word[++i]);
+ fp.d_params.dd=atof(word[++i]);
+ fp.d_params.element=atoi(word[++i]);
+ fp.d_params.brand=atoi(word[++i]);
+ // parsed in future
+ fp.d_params.attr=ATOM_ATTR_HB|ATOM_ATTR_VA;
+ fp.d_params.attr|=ATOM_ATTR_1BP|ATOM_ATTR_2BP|ATOM_ATTR_3BP;
+ break;
+
+ case '1':
+ fp.d_params.type=DEFECT_TYPE_1D;
+ break;
+ case '2':
+ fp.d_params.type=DEFECT_TYPE_2D;
+ break;
+ case '3':
+ fp.d_params.type=DEFECT_TYPE_3D;
+ break;
+ default:
+ break;
+ }
+ continue;
+
+ }
+ // offset
+ if(word[i][0]=='o') {
+ fp.o_params.o.x=atof(word[++i])*fp.lc;
+ fp.o_params.o.y=atof(word[++i])*fp.lc;
+ fp.o_params.o.z=atof(word[++i])*fp.lc;
+ fp.o_params.use=1;
+ continue;
+ }
+ i+=1;
+ }
+ add_stage(mdrun,STAGE_FILL,&fp);
+ }
+ else if(!strncmp(word[0],"thermal_init",12)) {
+ add_stage(mdrun,STAGE_THERMAL_INIT,NULL);
}
else if(!strncmp(word[0],"aattr",5)) {
// for aatrib line we need a special stage
case 'e':
cap.type|=CHAATTR_ELEMENT;
break;
+ case 'n':
+ cap.type|=CHAATTR_NUMBER;
default:
break;
}
}
i=2;
if(cap.type&CHAATTR_REGION) {
- cap.x0=atof(word[1]);
- cap.y0=atof(word[2]);
- cap.z0=atof(word[3]);
- cap.x1=atof(word[4]);
- cap.y1=atof(word[5]);
- cap.z1=atof(word[6]);
+ cap.x0=atof(word[2]);
+ cap.y0=atof(word[3]);
+ cap.z0=atof(word[4]);
+ cap.x1=atof(word[5]);
+ cap.y1=atof(word[6]);
+ cap.z1=atof(word[7]);
i+=6;
}
if(cap.type&CHAATTR_ELEMENT) {
cap.element=atoi(word[i]);
i+=1;
}
+ if(cap.type&CHAATTR_NUMBER) {
+ cap.element=atoi(word[i]);
+ i+=1;
+ }
for(o=0;o<strlen(word[i]);o++) {
switch(word[i][o]) {
case 'b':
csp.type=0;
for(i=1;i<wcnt;i++) {
if(!strncmp(word[i],"pctrl",5)) {
- csp.ptau=0.01/(atof(word[++i])*GPA);
+ csp.ptau=atof(word[++i]);
+ if(csp.ptau>0)
+ csp.ptau=0.01/(csp.ptau*GPA);
csp.type|=CHSATTR_PCTRL;
}
if(!strncmp(word[i],"tctrl",5)) {
csp.type|=CHSATTR_TCTRL;
}
if(!strncmp(word[i],"prelax",6)) {
- csp.dp=atof(word[++i]);
+ csp.dp=atof(word[++i])*BAR;
csp.type|=CHSATTR_PRELAX;
}
if(!strncmp(word[i],"trelax",6)) {
mdrun->visualize=atoi(word[1]);
else if(!strncmp(word[0],"stage",5)) {
// for every stage line, add a stage
- if(!strncmp(word[1],"ins_atoms",9)) {
+ if(!strncmp(word[1],"displace",8)) {
+ dap.nr=atoi(word[2]);
+ dap.dx=atof(word[3]);
+ dap.dy=atof(word[4]);
+ dap.dz=atof(word[5]);
+ add_stage(mdrun,STAGE_DISPLACE_ATOM,&dap);
+ }
+ else if(!strncmp(word[1],"del_atoms",9)) {
+ delp.o.x=atof(word[2]);
+ delp.o.y=atof(word[3]);
+ delp.o.z=atof(word[4]);
+ delp.r=atof(word[5]);
+ add_stage(mdrun,STAGE_DEL_ATOMS,&delp);
+ }
+ else if(!strncmp(word[1],"mod_atoms",8)) {
+ i=2;
+ while(i<wcnt) {
+ if(!strncmp(word[i],"t",1)) {
+ map.tag=atoi(word[++i]);
+ i+=1;
+ }
+ if(!strncmp(word[i],"ekin",5)) {
+ map.ekin.x=atof(word[++i])*EV;
+ map.ekin.y=atof(word[++i])*EV;
+ map.ekin.z=atof(word[++i])*EV;
+ i+=1;
+ }
+ }
+ add_stage(mdrun,STAGE_MODIFY_ATOMS,&map);
+ }
+ else if(!strncmp(word[1],"ins_atoms",9)) {
iap.ins_steps=atoi(word[2]);
iap.ins_atoms=atoi(word[3]);
iap.element=atoi(word[4]);
- iap.element=atoi(word[4]);
iap.brand=atoi(word[5]);
for(i=0;i<strlen(word[6]);i++) {
switch(word[6][i]) {
break;
}
}
- // only rand mode by now
- if(word[8][0]=='t') {
- iap.type=INS_TOTAL;
- iap.cr=atof(word[9]);
- }
- else {
- iap.type=INS_REGION;
- iap.x0=atof(word[8]);
- iap.y0=atof(word[9]);
- iap.z0=atof(word[10]);
- iap.x1=atof(word[11]);
- iap.y1=atof(word[12]);
- iap.z1=atof(word[13]);
- iap.cr=atof(word[14]);
+ switch(word[7][0]) {
+ // insertion types
+ case 'p':
+ iap.type=INS_POS;
+ iap.x0=atof(word[8]);
+ iap.y0=atof(word[9]);
+ iap.z0=atof(word[10]);
+ break;
+ case 'P':
+ iap.type=INS_RELPOS;
+ iap.x0=atof(word[8]);
+ iap.y0=atof(word[9]);
+ iap.z0=atof(word[10]);
+ break;
+ case 'r':
+ switch(word[8][0]) {
+
+ case 't':
+ iap.type=INS_TOTAL;
+ iap.cr=atof(word[9]);
+ break;
+ case 'r':
+ iap.type=INS_RECT;
+ iap.x0=atof(word[9]);
+ iap.y0=atof(word[10]);
+ iap.z0=atof(word[11]);
+ iap.x1=atof(word[12]);
+ iap.y1=atof(word[13]);
+ iap.z1=atof(word[14]);
+ iap.cr=atof(word[15]);
+ break;
+ case 's':
+ iap.type=INS_SPHERE;
+ iap.x0=atof(word[9]);
+ iap.y0=atof(word[10]);
+ iap.z0=atof(word[11]);
+ iap.x1=atof(word[12]);
+ iap.cr=atof(word[13]);
+ break;
+ default:
+ break;
+ }
+ default:
+ break;
}
add_stage(mdrun,STAGE_INSERT_ATOMS,&iap);
}
+
+
+ // HERE WE GO ...
+
+ else if(!strncmp(word[1],"ins_m_atoms",11)) {
+ imp.element1=atoi(word[2]);
+ imp.element2=atoi(word[3]);
+ imp.amount1=atoi(word[4]);
+ imp.amount2=atoi(word[5]);
+ imp.brand1=atoi(word[6]);
+ imp.brand2=atoi(word[7]);
+ imp.crmin=atof(word[8]);
+ imp.crmax=atof(word[9]);
+ /* do this later ...
+ for(i=0;i<strlen(word[8]);i++) {
+ switch(word[8][i]) {
+ case 'b':
+ imp.attr|=ATOM_ATTR_VB;
+ break;
+ case 'h':
+ imp.attr|=ATOM_ATTR_HB;
+ break;
+ case 'v':
+ imp.attr|=ATOM_ATTR_VA;
+ break;
+ case 'f':
+ imp.attr|=ATOM_ATTR_FP;
+ break;
+ case '1':
+ imp.attr|=ATOM_ATTR_1BP;
+ break;
+ case '2':
+ imp.attr|=ATOM_ATTR_2BP;
+ break;
+ case '3':
+ imp.attr|=ATOM_ATTR_3BP;
+ break;
+ default:
+ break;
+ }
+ }
+ */
+ imp.attr1=ATOM_ATTR_HB|ATOM_ATTR_VA|ATOM_ATTR_1BP|ATOM_ATTR_2BP|ATOM_ATTR_3BP|ATOM_ATTR_FP;
+ imp.attr2=ATOM_ATTR_HB|ATOM_ATTR_VA|ATOM_ATTR_1BP|ATOM_ATTR_2BP|ATOM_ATTR_3BP|ATOM_ATTR_FP;
+ add_stage(mdrun,STAGE_INSERT_MIXED_ATOMS,&imp);
+ }
+
+
+
+
+
else if(!strncmp(word[1],"continue",8)) {
cp.runs=atoi(word[2]);
add_stage(mdrun,STAGE_CONTINUE,&cp);
ap.count=0;
ap.runs=atoi(word[2]);
ap.dt=atof(word[3]);
+ ap.interval=atoi(word[4]);
add_stage(mdrun,STAGE_ANNEAL,&ap);
}
+ else if(!strncmp(word[1],"set_temp",8)) {
+ if(word[2][0]=='c') {
+ stp.type=SET_TEMP_CURRENT;
+ stp.val=0.0;
+ }
+ else {
+ stp.type=SET_TEMP_VALUE;
+ stp.val=atof(word[2]);
+ }
+ add_stage(mdrun,STAGE_SET_TEMP,&stp);
+ }
+ else if(!strncmp(word[1],"set_timestep",12)) {
+ stsp.tau=atof(word[2]);
+ add_stage(mdrun,STAGE_SET_TIMESTEP,&stsp);
+ }
+ else if(!strncmp(word[1],"crt",3)) {
+ crtp.type=atoi(word[2]);
+ crtp.steps=atoi(word[3]);
+ strncpy(crtp.file,word[4],127);
+ add_stage(mdrun,STAGE_CRT,&crtp);
+ }
else {
printf("%s unknown stage type: %s\n",
ME,word[1]);
double delta;
- if(!(mdrun->sattr&SATTR_PRELAX))
+ if(!(mdrun->sattr&SATTR_PRELAX)) {
return TRUE;
+ }
delta=moldyn->p_avg-moldyn->p_ref;
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;
+ double d,dmin,o;
int cnt,i;
double x,y,z;
double x0,y0,z0;
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=0.0;
+ x0=-x/2.0;
y=moldyn->dim.y;
- y0=0.0;
+ y0=-y/2.0;
z=moldyn->dim.z;
- z0=0.0;
+ z0=-z/2.0;
cr_check=TRUE;
break;
- case INS_REGION:
+ case INS_RECT:
x=iap->x1-iap->x0;
x0=iap->x0;
y=iap->y1-iap->y0;
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);
while(cnt<iap->ins_atoms) {
run=1;
while(run) {
- r.x=(rand_get_double(&(moldyn->random))-0.5)*x+x0;
- r.y=(rand_get_double(&(moldyn->random))-0.5)*y+y0;
- r.z=(rand_get_double(&(moldyn->random))-0.5)*z+z0;
+ 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!
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,pse_mass[iap->element],
+ 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(" -> d2 = %f/%f\n",dmin,iap->cr*iap->cr);
+ 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;
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)
+ if(cap->x0>atom->r.x)
continue;
- if(cap->y0<atom->r.y)
+ if(cap->y0>atom->r.y)
continue;
- if(cap->z0<atom->r.z)
+ if(cap->z0>atom->r.z)
continue;
- if(cap->x1>atom->r.x)
+ if(cap->x1<atom->r.x)
continue;
- if(cap->y1>atom->r.y)
+ if(cap->y1<atom->r.y)
continue;
- if(cap->z1>atom->r.z)
+ 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;
}
if(csp->ptau>0)
set_p_scale(moldyn,P_SCALE_BERENDSEN,csp->ptau);
else
- set_p_scale(moldyn,P_SCALE_BERENDSEN,csp->ptau);
+ 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_BERENDSEN,csp->ttau);
+ set_t_scale(moldyn,T_SCALE_NONE,1.0);
}
if(csp->type&CHSATTR_PRELAX) {
if(csp->dp<0)
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);
+ /* visualize atoms */
+ visual_atoms(moldyn);
+
+ /* 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)
t_stage *stage;
t_list *sl;
int steps;
- double tau;
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;
/* get stage description */
stage=sl->current->data;
- /* default steps and tau values */
+ /* steps in next schedule */
steps=mdrun->relax_steps;
- tau=mdrun->timestep;
/* check whether relaxation steps are necessary */
- if(!((check_pressure(moldyn,mdrun)==FALSE)|\
- (check_temperature(moldyn,mdrun)==FALSE))) {
+ if((check_pressure(moldyn,mdrun)==TRUE)&\
+ (check_temperature(moldyn,mdrun)==TRUE)) {
/* be verbose */
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;
}
insert_atoms(moldyn,mdrun);
iap->cnt_steps+=1;
- break;
+ 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) {
}
cp=stage->params;
steps=cp->runs;
- break;
+ break;
case STAGE_ANNEAL:
stage_print(" -> anneal\n\n");
ap=stage->params;
change_stage=TRUE;
break;
}
- set_temperature(moldyn,moldyn->t_ref+ap->dt);
+ 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(" -> chaattr\n\n");
+ stage_print(" -> change atom attributes\n\n");
chaatr(moldyn,mdrun);
change_stage=TRUE;
break;
case STAGE_CHSATTR:
- stage_print(" -> chsattr\n\n");
+ 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;
return 0;
}
steps=0;
- tau=mdrun->timestep;
}
}
}
/* continue simulation */
- moldyn_add_schedule(moldyn,steps,tau);
+ moldyn_add_schedule(moldyn,steps,mdrun->timestep);
return 0;
}
t_mdrun mdrun;
t_moldyn moldyn;
- t_3dvec o;
+ //t_3dvec o;
/* clear structs */
memset(&mdrun,0,sizeof(t_mdrun));
memset(&moldyn,0,sizeof(t_moldyn));
+ /* init crt variables */
+ crtt=0;
+ constraints=NULL;
+ trafo_angle=NULL;
+
/* parse arguments */
if(mdrun_parse_argv(&mdrun,argc,argv)<0)
return -1;
/* sanity check! */
/* prepare simulation */
- moldyn_init(&moldyn,argc,argv);
+
+ if(mdrun.continue_file[0]) {
+ // read the save file
+ moldyn_read_save_file(&moldyn,mdrun.continue_file);
+ // manualaadjusting some stuff
+ moldyn.argc=argc;
+ moldyn.args=argv;
+ rand_init(&(moldyn.random),NULL,1);
+ moldyn.random.status|=RAND_STAT_VERBOSE;
+ }
+ else {
+ moldyn_init(&moldyn,argc,argv);
+ }
+
if(set_int_alg(&moldyn,mdrun.intalgo)<0)
return -1;
+
+ /* potential */
set_cutoff(&moldyn,mdrun.cutoff);
if(set_potential(&moldyn,mdrun.potential)<0)
return -1;
ME,mdrun.potential);
return -1;
}
+
+ /* if it is a continue run, reset schedule and skip lattice init */
+ if(mdrun.continue_file[0]) {
+ memset(&(moldyn.schedule),0,sizeof(t_moldyn_schedule));
+ goto addsched;
+ }
+
+ /* initial lattice and dimensions */
set_dim(&moldyn,mdrun.dim.x,mdrun.dim.y,mdrun.dim.z,mdrun.vis);
set_pbc(&moldyn,mdrun.pbcx,mdrun.pbcy,mdrun.pbcz);
+ /* replaced by fill stage !!
switch(mdrun.lattice) {
case FCC:
- create_lattice(&moldyn,FCC,mdrun.lc,mdrun.element1,
- mdrun.m1,DEFAULT_ATOM_ATTR,0,mdrun.lx,
- mdrun.ly,mdrun.lz,NULL);
+ create_lattice(&moldyn,FCC,mdrun.lc,mdrun.fill_element,
+ mdrun.m1,DEFAULT_ATOM_ATTR,
+ mdrun.fill_brand,mdrun.lx,
+ mdrun.ly,mdrun.lz,NULL,0,NULL);
break;
case DIAMOND:
- create_lattice(&moldyn,DIAMOND,mdrun.lc,mdrun.element1,
- mdrun.m1,DEFAULT_ATOM_ATTR,0,mdrun.lx,
- mdrun.ly,mdrun.lz,NULL);
+ create_lattice(&moldyn,DIAMOND,mdrun.lc,
+ mdrun.fill_element,
+ mdrun.m1,DEFAULT_ATOM_ATTR,
+ mdrun.fill_brand,mdrun.lx,
+ mdrun.ly,mdrun.lz,NULL,0,NULL);
break;
case ZINCBLENDE:
o.x=0.5*0.25*mdrun.lc; o.y=o.x; o.z=o.x;
create_lattice(&moldyn,FCC,mdrun.lc,mdrun.element1,
mdrun.m1,DEFAULT_ATOM_ATTR,0,mdrun.lx,
- mdrun.ly,mdrun.lz,&o);
+ mdrun.ly,mdrun.lz,&o,0,NULL);
o.x+=0.25*mdrun.lc; o.y=o.x; o.z=o.x;
create_lattice(&moldyn,FCC,mdrun.lc,mdrun.element2,
mdrun.m2,DEFAULT_ATOM_ATTR,1,mdrun.lx,
- mdrun.ly,mdrun.lz,&o);
+ mdrun.ly,mdrun.lz,&o,0,NULL);
+ break;
+ case NONE:
+ set_nn_dist(&moldyn,mdrun.nnd);
break;
default:
printf("%s unknown lattice type: %02x\n",
return -1;
}
moldyn_bc_check(&moldyn);
+ replaced by fill stage !! */
+
+ /* temperature and pressure */
set_temperature(&moldyn,mdrun.temperature);
set_pressure(&moldyn,mdrun.pressure);
+ /* replaced thermal_init stage
thermal_init(&moldyn,TRUE);
+ */
+
+addsched:
+ /* first schedule */
moldyn_add_schedule(&moldyn,mdrun.prerun,mdrun.timestep);
+
+ /* log */
moldyn_set_log_dir(&moldyn,mdrun.sdir);
moldyn_set_report(&moldyn,"CHANGE ME","CHANGE ME TOO");
if(mdrun.elog)