]> www.hackdaworld.org Git - physik/posic.git/blob - visual_atoms.c
Merge branch 'leadoff'
[physik/posic.git] / visual_atoms.c
1 /*
2  * code visualize atoms
3  *
4  * author: frank.zirkelbach@physik.uni-augsburg.de
5  *
6  */
7
8 #define _GNU_SOURCE
9 #include <stdio.h>
10 //#include <stdlib.h>
11 //#include <unistd.h>
12 //#include <string.h>
13 //#include <sys/types.h>
14 //#include <sys/stat.h>
15 //#include <fcntl.h>
16
17 #include "moldyn.h"
18
19 /* pse */
20 #define PSE_NAME
21 #define PSE_COL
22 #include "pse.h"
23 #undef PSE_NAME
24 #undef PSE_COL
25
26 typedef struct s_data {
27         int ca;
28         double radius;
29         double lc;
30         int ma;
31         double ox,oy,oz;
32 } t_data;
33
34 int usage(char *prog) {
35
36         printf("\nusage:\n");
37         printf("  %s <file> <centre atom> <radius> <lc> [marked atom]\n\n",
38                prog);
39
40         return -1;
41 }
42
43 int process(t_moldyn *moldyn,t_atom *itom,t_atom *jtom,void *ptr,u8 bc) {
44
45         t_3dvec dist;
46         double d;
47         t_data *data;
48
49         data=ptr;
50
51         v3_sub(&dist,&(itom->r),&(jtom->r));
52         if(bc) check_per_bound(moldyn,&dist);
53         d=v3_norm(&dist);
54
55         if(d<=data->radius) {
56                 printf("%s %f %f %f %s %f\n",
57                        pse_name[jtom->element],
58                        jtom->r.x+data->ox,jtom->r.y+data->oy,jtom->r.z+data->oz,
59                        (jtom->tag==data->ma)?"Red":pse_col[jtom->element],
60                        jtom->ekin);
61         }
62
63         return 0;
64 }
65
66 int main(int argc,char **argv) {
67
68         t_moldyn moldyn;
69         t_data data;
70         int ret;
71         t_atom *atom;
72
73         if(argc<4) {
74                 usage(argv[0]);
75                 return -1;
76         }
77         
78         data.ca=atoi(argv[2]);
79         data.radius=atof(argv[3]);
80         data.lc=atof(argv[4]);
81         data.ma=-1;
82         if(argc==6)
83                 data.ma=atoi(argv[5]);
84
85         memset(&moldyn,0,sizeof(t_moldyn));
86
87         printf("[visual atoms] reading save file ...\n");
88         ret=moldyn_read_save_file(&moldyn,argv[1]);
89         if(ret) {
90                 printf("[visual atoms] exit!\n");
91                 return ret;
92         }
93
94         /* link cell init */
95         moldyn.cutoff=data.radius;
96         link_cell_init(&moldyn,VERBOSE);
97
98         atom=&(moldyn.atom[data.ca]);
99
100         /* prepare offset */
101         data.ox=0.0;
102         if(atom->r.x<0) {
103                 while((atom->r.x+data.ox)<(-data.lc/2.0))
104                         data.ox+=data.lc;
105         }
106         else {
107                 while((atom->r.x+data.ox)>(data.lc/2.0))
108                         data.ox-=data.lc;
109         }
110
111         data.oy=0.0;
112         if(atom->r.y<0) {
113                 while((atom->r.y+data.oy)<(-data.lc/2.0))
114                         data.oy+=data.lc;
115         }
116         else {
117                 while((atom->r.y+data.oy)>(data.lc/2.0))
118                         data.oy-=data.lc;
119         }
120
121         data.oz=0.0;
122         if(atom->r.z<0) {
123                 while((atom->r.z+data.oz)<(-data.lc/2.0))
124                         data.oz+=data.lc;
125         }
126         else {
127                 while((atom->r.z+data.oz)>(data.lc/2.0))
128                         data.oz-=data.lc;
129         }
130
131         /* print the centered atom */
132         printf("%s %f %f %f %s %f\n",
133                pse_name[atom->element],atom->r.x+data.ox,atom->r.y+data.oy,
134                atom->r.z+data.oz,"Green",atom->ekin);
135
136         process_neighbours(&moldyn,&data,atom,process);
137         
138         link_cell_shutdown(&moldyn);
139         moldyn_free_save_file(&moldyn);
140
141         return 0;
142 }
143