X-Git-Url: https://hackdaworld.org/gitweb/?p=physik%2Fposic.git;a=blobdiff_plain;f=mdrun.c;h=26fbc871708c262a19eead0b398d8773a2941902;hp=d0636939c17b68ac6d9f0206b95b076d023aa158;hb=HEAD;hpb=dfb47bde6bf974d1b231048ec8bcda712404ccc1 diff --git a/mdrun.c b/mdrun.c index d063693..26fbc87 100644 --- a/mdrun.c +++ b/mdrun.c @@ -11,17 +11,13 @@ #include "potentials/harmonic_oscillator.h" #include "potentials/lennard_jones.h" #include "potentials/albe.h" +#include "potentials/albe_orig.h" #ifdef TERSOFF_ORIG #include "potentials/tersoff_orig.h" #else #include "potentials/tersoff.h" #endif -/* pse */ -#define PSE_MASS -#include "pse.h" -#undef PSE_MASS - #define ME "[mdrun]" /* @@ -98,6 +94,12 @@ int add_stage(t_mdrun *mdrun,u8 type,void *params) { 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; @@ -128,6 +130,9 @@ int add_stage(t_mdrun *mdrun,u8 type,void *params) { 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; @@ -161,11 +166,12 @@ int mdrun_parse_config(t_mdrun *mdrun) { char error[128]; char line[128]; char *wptr; - char word[16][64]; + 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; @@ -175,6 +181,8 @@ int mdrun_parse_config(t_mdrun *mdrun) { 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); @@ -199,6 +207,7 @@ int mdrun_parse_config(t_mdrun *mdrun) { // 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)); @@ -207,6 +216,8 @@ int mdrun_parse_config(t_mdrun *mdrun) { 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; @@ -224,6 +235,8 @@ int mdrun_parse_config(t_mdrun *mdrun) { if(!strncmp(word[0],"potential",9)) { if(!strncmp(word[1],"albe",4)) mdrun->potential=MOLDYN_POTENTIAL_AM; + if(!strncmp(word[1],"albe_o",6)) + mdrun->potential=MOLDYN_POTENTIAL_AO; if(!strncmp(word[1],"tersoff",7)) mdrun->potential=MOLDYN_POTENTIAL_TM; if(!strncmp(word[1],"ho",2)) @@ -293,6 +306,7 @@ int mdrun_parse_config(t_mdrun *mdrun) { 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(ilc=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; @@ -341,6 +357,7 @@ int mdrun_parse_config(t_mdrun *mdrun) { 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]) { @@ -381,8 +398,17 @@ int mdrun_parse_config(t_mdrun *mdrun) { 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); @@ -404,24 +430,30 @@ int mdrun_parse_config(t_mdrun *mdrun) { 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;o0) + csp.ptau=0.01/(csp.ptau*GPA); csp.type|=CHSATTR_PCTRL; } if(!strncmp(word[i],"tctrl",5)) { @@ -508,6 +542,29 @@ int mdrun_parse_config(t_mdrun *mdrun) { 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(istage.current->data; + delp=stage->params; + + if(delp->r<0) + outer=1; + + for(i=0;icount;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)) { + if(!outer) { + 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); + } + } + else { + if(outer) { + 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;icount;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; @@ -764,7 +920,7 @@ int insert_atoms(t_moldyn *moldyn,t_mdrun *mdrun) { 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; @@ -773,7 +929,17 @@ int insert_atoms(t_moldyn *moldyn,t_mdrun *mdrun) { 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; @@ -789,7 +955,7 @@ int insert_atoms(t_moldyn *moldyn,t_mdrun *mdrun) { while(cntins_atoms) { run=1; while(run) { - if(iap->type!=INS_POS) { + 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; @@ -799,9 +965,16 @@ int insert_atoms(t_moldyn *moldyn,t_mdrun *mdrun) { r.y=0.0; r.z=0.0; } - r.x+=x0; - r.y+=y0; - r.z+=z0; + 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; @@ -824,13 +997,37 @@ int insert_atoms(t_moldyn *moldyn,t_mdrun *mdrun) { 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, 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; } @@ -956,23 +1153,32 @@ int chaatr(t_moldyn *moldyn,t_mdrun *mdrun) { if(cap->element!=atom->element) continue; } + if(cap->type&CHAATTR_NUMBER) { + if(cap->element!=atom->tag) + continue; + } if(cap->type&CHAATTR_REGION) { - if(cap->x0r.x) + if(cap->x0>atom->r.x) continue; - if(cap->y0r.y) + if(cap->y0>atom->r.y) continue; - if(cap->z0r.z) + if(cap->z0>atom->r.z) continue; - if(cap->x1>atom->r.x) + if(cap->x1r.x) continue; - if(cap->y1>atom->r.y) + if(cap->y1r.y) continue; - if(cap->z1>atom->r.z) + if(cap->z1r.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; } @@ -988,13 +1194,13 @@ int chsattr(t_moldyn *moldyn,t_mdrun *mdrun) { 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) @@ -1023,6 +1229,138 @@ int chsattr(t_moldyn *moldyn,t_mdrun *mdrun) { 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;icount;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) @@ -1043,6 +1381,7 @@ int mdrun_hook(void *ptr1,void *ptr2) { t_set_temp_params *stp; t_set_timestep_params *stsp; t_fill_params *fp; + t_crt_params *crtp; moldyn=ptr1; mdrun=ptr2; @@ -1077,6 +1416,16 @@ int mdrun_hook(void *ptr1,void *ptr2) { 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; @@ -1164,7 +1513,8 @@ int mdrun_hook(void *ptr1,void *ptr2) { fp->lx,fp->ly,fp->lz, &o, &(fp->p_params), - &(fp->d_params)); + &(fp->d_params), + &(fp->o_params)); o.x+=0.25*fp->lc; o.y=o.x; o.z=o.x; @@ -1175,19 +1525,22 @@ int mdrun_hook(void *ptr1,void *ptr2) { fp->lx,fp->ly,fp->lz, &o, &(fp->p_params), - &(fp->d_params)); + &(fp->d_params), + &(fp->o_params)); break; default: create_lattice(moldyn, fp->lattice,fp->lc, - mdrun->element1, - DEFAULT_ATOM_ATTR,0, + fp->fill_element, + DEFAULT_ATOM_ATTR, + fp->fill_brand, fp->lx,fp->ly,fp->lz, NULL, &(fp->p_params), - &(fp->d_params)); + &(fp->d_params), + &(fp->o_params)); break; } moldyn_bc_check(moldyn); @@ -1198,6 +1551,20 @@ int mdrun_hook(void *ptr1,void *ptr2) { 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; @@ -1241,6 +1608,11 @@ int main(int argc,char **argv) { 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; @@ -1284,6 +1656,11 @@ int main(int argc,char **argv) { mdrun.element1, mdrun.element2); break; + case MOLDYN_POTENTIAL_AO: + albe_orig_mult_set_params(&moldyn, + mdrun.element1, + mdrun.element2); + break; case MOLDYN_POTENTIAL_TM: tersoff_mult_set_params(&moldyn, mdrun.element1,