From: hackbard Date: Mon, 5 May 2008 08:07:01 +0000 (+0200) Subject: search bonds using infrastructure now, new visual atoms tool X-Git-Url: https://www.hackdaworld.org/gitweb/?p=physik%2Fposic.git;a=commitdiff_plain;h=a58211f24f237b51e708b9e8b9fd463a709754a6 search bonds using infrastructure now, new visual atoms tool --- diff --git a/Makefile b/Makefile index 62a137e..36c411e 100644 --- a/Makefile +++ b/Makefile @@ -23,7 +23,7 @@ DEPS += potentials/lennard_jones.o potentials/harmonic_oscillator.o DEPS += potentials/tersoff.o potentials/albe.o ALL = mdrun sic fluctuation_calc postproc pair_correlation_calc diffusion_calc -ALL += bond_analyze search_bonds +ALL += bond_analyze search_bonds visual_atoms all: $(ALL) @@ -41,6 +41,8 @@ bond_analyze: $(DEPS) search_bonds: $(DEPS) +visual_atoms: $(DEPS) + .PHONY:clean clean: rm -vf $(ALL) *.o */*.o diff --git a/mdrun.h b/mdrun.h index fa16906..ad5c0c2 100644 --- a/mdrun.h +++ b/mdrun.h @@ -18,9 +18,6 @@ /* main molecular dynamics api */ #include "moldyn.h" -/* elements */ -#include "pse.h" - /* list api */ #include "list/list.h" diff --git a/moldyn.c b/moldyn.c index 82ae543..4330396 100644 --- a/moldyn.c +++ b/moldyn.c @@ -30,101 +30,6 @@ #include "potentials/tersoff.h" #endif - -/* - * global variables, pse and atom colors (only needed here) - */ - -static char *pse_name[]={ - "*", - "H", - "He", - "Li", - "Be", - "B", - "C", - "N", - "O", - "F", - "Ne", - "Na", - "Mg", - "Al", - "Si", - "P", - "S", - "Cl", - "Ar", -}; - -static char *pse_col[]={ - "*", - "White", - "He", - "Li", - "Be", - "B", - "Gray", - "N", - "Blue", - "F", - "Ne", - "Na", - "Mg", - "Al", - "Yellow", - "P", - "S", - "Cl", - "Ar", -}; - -/* -static double pse_mass[]={ - 0, - 0, - 0, - 0, - 0, - 0, - M_C, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - M_SI, - 0, - 0, - 0, - 0, -}; - -static double pse_lc[]={ - 0, - 0, - 0, - 0, - 0, - 0, - LC_C, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - LC_SI, - 0, - 0, - 0, - 0, -}; -*/ - /* * the moldyn functions */ diff --git a/moldyn.h b/moldyn.h index cd7c5d0..ca40103 100644 --- a/moldyn.h +++ b/moldyn.h @@ -353,6 +353,12 @@ typedef struct s_vb { #define DIAMOND 0x04 #define ZINCBLENDE 0x08 +/* + * more includes + */ + +#include "pse.h" + /* * * function prototypes diff --git a/pse.h b/pse.h index d9aff12..3391d26 100644 --- a/pse.h +++ b/pse.h @@ -51,3 +51,47 @@ static double pse_lc[]={ 0, }; +static char *pse_name[]={ + "*", + "H", + "He", + "Li", + "Be", + "B", + "C", + "N", + "O", + "F", + "Ne", + "Na", + "Mg", + "Al", + "Si", + "P", + "S", + "Cl", + "Ar", +}; + +static char *pse_col[]={ + "*", + "White", + "He", + "Li", + "Be", + "B", + "Gray", + "N", + "Blue", + "F", + "Ne", + "Na", + "Mg", + "Al", + "Yellow", + "P", + "S", + "Cl", + "Ar", +}; + diff --git a/search_bonds.c b/search_bonds.c index d3c1199..8291109 100644 --- a/search_bonds.c +++ b/search_bonds.c @@ -17,6 +17,11 @@ #include "moldyn.h" #include "potentials/albe.h" +typedef struct s_data { + double pm,len; + u8 type; +} t_data; + int usage(char *prog) { printf("\nusage:\n"); @@ -28,25 +33,63 @@ int usage(char *prog) { return -1; } +int process(t_moldyn *moldyn,t_atom *ai,t_atom *aj,void *ptr,u8 bc) { + + t_3dvec dist; + double d; + t_data *data; + + data=ptr; + + if(ajtype) { + case 'a': + if(ai->brand!=0) + return 0; + if(aj->brand!=0) + return 0; + + break; + case 'b': + if(ai->brand!=1) + return 0; + if(aj->brand!=1) + return 0; + break; + default: + if(ai->brand==aj->brand) + return 0; + break; + } + + v3_sub(&dist,&(ai->r),&(aj->r)); + check_per_bound(moldyn,&dist); + d=v3_norm(&dist); + + if((d<=data->len+data->pm)&(d>=data->len-data->pm)) + printf(" # atoms %d/%d %d/%d - %f\n", + ai->tag,ai->brand, + aj->tag,aj->brand,d); + + return 0; +} + int main(int argc,char **argv) { t_moldyn moldyn; - t_atom *itom,*jtom; - int i,j; int ret; - t_list n[27]; - t_list *this; - t_linkcell *lc; - t_3dvec dist; - double d,bondlen,bondpm; + t_data data; if(argc!=5) { usage(argv[0]); return -1; } - bondlen=atof(argv[3]); - bondpm=atof(argv[4]); + data.type=argv[2][0]; + data.len=atof(argv[3]); + data.pm=atof(argv[4]); memset(&moldyn,0,sizeof(t_moldyn)); @@ -58,67 +101,12 @@ int main(int argc,char **argv) { } /* link cell init */ - moldyn.cutoff=bondlen+bondpm; + moldyn.cutoff=data.len+data.pm; link_cell_init(&moldyn,VERBOSE); - lc=&(moldyn.lc); - /* analyzing ... */ - for(i=0;ir.x+moldyn.dim.x/2)/lc->x, - (itom->r.y+moldyn.dim.y/2)/lc->y, - (itom->r.z+moldyn.dim.z/2)/lc->z, - n); - for(j=0;j<27;j++) { - this=&(n[j]); - list_reset_f(this); - - if(this->start==NULL) - continue; - - do { - - jtom=this->current->data; - - if(jtombrand!=0) - continue; - if(jtom->brand!=0) - continue; - break; - case 'b': - if(itom->brand!=1) - continue; - if(jtom->brand!=1) - continue; - break; - default: - if(itom->brand==jtom->brand) - continue; - break; - } - - v3_sub(&dist,&(itom->r),&(jtom->r)); - check_per_bound(&moldyn,&dist); - d=v3_norm(&dist); - - if((d<=bondlen+bondpm)&(d>=bondlen-bondpm)) { - - printf(" # atoms %d/%d %d/%d - %f\n", - itom->tag,itom->brand, - jtom->tag,jtom->brand,d); - - } - - } while(list_next_f(this)!=L_NO_NEXT_ELEMENT); - } - } + process_2b_bonds(&moldyn,&data,process); + /* analyzing ... */ link_cell_shutdown(&moldyn); moldyn_free_save_file(&moldyn); diff --git a/visual_atoms.c b/visual_atoms.c new file mode 100644 index 0000000..9baa487 --- /dev/null +++ b/visual_atoms.c @@ -0,0 +1,113 @@ +/* + * code visualize atoms + * + * author: frank.zirkelbach@physik.uni-augsburg.de + * + */ + +#define _GNU_SOURCE +#include +//#include +//#include +//#include +//#include +//#include +//#include + +#include "moldyn.h" + +int usage(char *prog) { + + printf("\nusage:\n"); + printf(" %s [marked atom]\n\n",prog); + + return -1; +} + +int main(int argc,char **argv) { + + t_moldyn moldyn; + t_atom *itom,*jtom; + int j; + int ret; + t_list n[27]; + t_list *this; + t_linkcell *lc; + t_3dvec dist; + double d,radius; + int ma,ca; + + if(argc<4) { + usage(argv[0]); + return -1; + } + + ca=atoi(argv[2]); + radius=atof(argv[3]); + + ma=-1; + if(argc==5) + ma=atoi(argv[4]); + + memset(&moldyn,0,sizeof(t_moldyn)); + + printf("[visual atoms] reading save file ...\n"); + ret=moldyn_read_save_file(&moldyn,argv[1]); + if(ret) { + printf("[visual atoms] exit!\n"); + return ret; + } + + /* link cell init */ + moldyn.cutoff=radius; + link_cell_init(&moldyn,VERBOSE); + lc=&(moldyn.lc); + + /* serach atoms */ + itom=&(moldyn.atom[ca]); + link_cell_neighbour_index(&moldyn, + (itom->r.x+moldyn.dim.x/2)/lc->x, + (itom->r.y+moldyn.dim.y/2)/lc->y, + (itom->r.z+moldyn.dim.z/2)/lc->z, + n); + + + printf("%s %f %f %f %s %f\n", + pse_name[itom->element],itom->r.x,itom->r.y,itom->r.z, + "Green",itom->ekin); + + for(j=0;j<27;j++) { + this=&(n[j]); + list_reset_f(this); + + if(this->start==NULL) + continue; + + do { + + jtom=this->current->data; + + if(jtom==itom) + continue; + + v3_sub(&dist,&(itom->r),&(jtom->r)); + check_per_bound(&moldyn,&dist); + d=v3_norm(&dist); + + if(d<=radius) { + printf("%s %f %f %f %s %f\n", + pse_name[jtom->element], + jtom->r.x,jtom->r.y,jtom->r.z, + (jtom->tag==ma)?"Red":pse_col[jtom->element], + jtom->ekin); + } + + } while(list_next_f(this)!=L_NO_NEXT_ELEMENT); + } + + link_cell_shutdown(&moldyn); + + moldyn_free_save_file(&moldyn); + + return 0; +}