scaling to fs, angstrom, amu done, probs with velocity scaling!
[physik/posic.git] / visual / visual.c
index 6ad527a..d03903b 100644 (file)
 #include "../moldyn.h"
 #include "../math/math.h"
 
+/* the pse, only needed here */
+static char *pse[]={
+       "*",
+       "H",
+       "He",
+       "Li",
+       "Be",
+       "B",
+       "C",
+       "N",
+       "O",
+       "F",
+       "Ne",
+       "Na",
+       "Mg",
+       "Al",
+       "Si",
+       "P",
+       "S",
+       "Cl",
+       "Ar",
+};
+
 int visual_init(t_visual *v,char *filebase) {
 
        char file[128+8];
@@ -25,18 +48,22 @@ int visual_init(t_visual *v,char *filebase) {
        memset(file,0,128+8);
        sprintf(file,"%s.scr",v->fb);
 
-       v->fd=open(file,O_WRONLY);
+       v->fd=open(file,O_WRONLY|O_CREAT|O_TRUNC);
        if(v->fd<0) {
                perror("open visual fd");
                return -1;
        }
+       dprintf(v->fd,"set write on\n");
 
        return 0;
 }
 
 int visual_tini(t_visual *v) {
 
-       if(v->fd) close(v->fd);
+       if(v->fd) {
+               dprintf(v->fd,"quit\n");
+               close(v->fd);
+       }
 
        return 0;
 }
@@ -45,31 +72,14 @@ int visual_atoms(t_visual *v,double time,t_atom *atom,int n) {
 
        int i,fd;
        char file[128+64];
+       t_3dvec dim;
 
-       char pse[19][4]={
-               "foo",
-               "H",
-               "He",
-               "Li",
-               "Be",
-               "B",
-               "C",
-               "N",
-               "O",
-               "F",
-               "Ne",
-               "Na",
-               "Mg",
-               "Al",
-               "Si",
-               "P",
-               "S",
-               "Cl",
-               "Ar",
-       };
-
-       sprintf(file,"%s-%.15f.xyz",v->fb,time);
-       fd=open(file,O_WRONLY);
+       dim.x=v->dim.x;
+       dim.y=v->dim.y;
+       dim.z=v->dim.z;
+
+       sprintf(file,"%s-%07f.xyz",v->fb,time);
+       fd=open(file,O_WRONLY|O_CREAT|O_TRUNC);
        if(fd<0) {
                perror("open visual save file fd");
                return -1;
@@ -77,21 +87,35 @@ int visual_atoms(t_visual *v,double time,t_atom *atom,int n) {
 
        /* script file update */
        dprintf(v->fd,"load xyz %s\n",file);
-       dprintf(v->fd,"spacefill 200\n");
-       dprintf(v->fd,"rotate x 11\n");
-       dprintf(v->fd,"rotate y 13\n");
+       dprintf(v->fd,"spacefill 270\n");
+       dprintf(v->fd,"rotate x 100\n");
+       dprintf(v->fd,"rotate y 10\n");
        dprintf(v->fd,"set ambient 20\n");
        dprintf(v->fd,"set specular on\n");
+       dprintf(v->fd,"set boundbox on\n");
+       //dprintf(v->fd,"label\n");
        sprintf(file,"%s-%.15f.ppm",v->fb,time);
        dprintf(v->fd,"write ppm %s\n",file);
        dprintf(v->fd,"zap\n");
 
        /* write the actual data file */
-       dprintf(fd,"Atoms at time %.15f\n",time);
-       dprintf(fd,"%d\n",n);
+       dprintf(fd,"%d\n",(dim.x==0)?n:n+8);
+       dprintf(fd,"atoms at time %.15f\n",time);
        for(i=0;i<n;i++)
                dprintf(fd,"%s %f %f %f\n",pse[atom[i].element],
-                                          atom[i].r.x,atom[i].r.y,atom[i].r.z);
+                                          atom[i].r.x,
+                                          atom[i].r.y,
+                                          atom[i].r.z);
+       if(dim.x) {
+               dprintf(fd,"%s %f %f %f\n",pse[0],dim.x/2,dim.y/2,dim.z/2);
+               dprintf(fd,"%s %f %f %f\n",pse[0],-dim.x/2,dim.y/2,dim.z/2);
+               dprintf(fd,"%s %f %f %f\n",pse[0],dim.x/2,-dim.y/2,dim.z/2);
+               dprintf(fd,"%s %f %f %f\n",pse[0],dim.x/2,dim.y/2,-dim.z/2);
+               dprintf(fd,"%s %f %f %f\n",pse[0],-dim.x/2,-dim.y/2,dim.z/2);
+               dprintf(fd,"%s %f %f %f\n",pse[0],dim.x/2,-dim.y/2,-dim.z/2);
+               dprintf(fd,"%s %f %f %f\n",pse[0],-dim.x/2,dim.y/2,-dim.z/2);
+               dprintf(fd,"%s %f %f %f\n",pse[0],-dim.x/2,-dim.y/2,-dim.z/2);
+       }
        close(fd);
 
        return 0;