CCL Home Page
Up Directory CCL fract2xyz
#include 
#include 
#include 
#include 

/* fract2xyz is a conversion program that takes fractional coordinates input
   from stdin and converts it to a xmol xyz file on stdout

   Format of fractional coordinates file :

   first line   : natoms alpha beta gamma a-axis b-axis c-axis
   second line  : title / comment line
   natoms lines : atomname fract(x) fract(y) fract(z)  rest of line ignored

   atomname = elementname that may have a number concatenated to it
   i.g. C3 or H34b are valid : become C and H respectively
   fract(x) fract(y) fract(z) : floating point fractional coordinages

   to compile on SUN : cc fract2xyz.c -o fract2xyz -O -lm

   typical use : fract2xyz data.xyz

   bugs : report to KANTERS@URVAX.URICH.EDU

   Enjoy,
   Rene Kanters
*/

double sqr(x) double x; {return x*x;}

main(argc,argv)
int argc;
char *argv[];
{ long n;
  double a,b,c,t11,t12,t13,t22,t23,t33,al,be,ga;
  char buf[256],*ch;

  gets(buf); puts(buf);
  sscanf(buf,"%ld%lf%lf%lf%lf%lf%lf",&n,&al,&be,&ga,&a,&b,&c);
  t11=asin(1.00)/90;
  al*=t11; be*=t11; ga *= t11; /* converted angles from degree to rad */
  t22=sin(ga);
  t12=cos(ga);
  t13=cos(be);
  if((fabs(t22) < 0.0001) ||
     (t33=sqr(sin(al))+sqr(sin(be))+sqr(t22)+2*cos(al)*t12*t13-2)<0) {
    fprintf(stderr,"sorry, something wrong with the angles\n");
    exit(0);
  }
  t33=c*sqrt(t33)/t22;
  t23=c*(cos(al)-t12*t13)/t22;
  t13*=c;
  t22*=b;
  t12*=b;
  t11=a;
  
  /* copy the title line */
  gets(buf); puts(buf); /* copy the rest behind it too */
  
  while((--n >= 0) && (scanf("%s%lf%lf%lf",buf,&a,&b,&c)==4)) {
    /* make sure that there aren't any numbers dangling on the atom names */
    ch=buf; while(isalpha(*ch)) ch++; *ch=0;
    printf("%3s %15.6lg %15.6lg %15.6lg\n",buf,t11*a+t12*b+t13*c,t22*b+t23*c,t33*c);
    gets(buf);  /* read remaining possible junk */
  }
  if(n>=0) {fprintf(stderr,"input error reading atom\n"); exit(0);}
}


Modified: Sat Apr 25 16:00:00 1992 GMT
Page accessed 10397 times since Sat Apr 17 18:19:06 1999 GMT