added del_atoms, playing with Ef calc, some more TODO
[physik/posic.git] / mdrun.c
diff --git a/mdrun.c b/mdrun.c
index 34807e7..bd70d00 100644 (file)
--- a/mdrun.c
+++ b/mdrun.c
@@ -98,6 +98,9 @@ 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_INSERT_ATOMS:
                        psize=sizeof(t_insert_atoms_params);
                        break;
@@ -175,6 +178,7 @@ 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;
 
        /* open config file */
        fd=open(mdrun->cfile,O_RDONLY);
@@ -207,6 +211,7 @@ 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));
 
                // get command + args
                wcnt=0;
@@ -509,6 +514,13 @@ 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],"ins_atoms",9)) {
                                iap.ins_steps=atoi(word[2]);
                                iap.ins_atoms=atoi(word[3]);
@@ -732,6 +744,31 @@ int displace_atom(t_moldyn *moldyn,t_mdrun *mdrun) {
        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 insert_atoms(t_moldyn *moldyn,t_mdrun *mdrun) {
 
        t_insert_atoms_params *iap;
@@ -1108,6 +1145,11 @@ 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_INSERT_ATOMS:
                                stage_print("  -> insert atoms\n\n");
                                iap=stage->params;