File: xplor_write.c

package info (click to toggle)
c2x 2.35a%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 1,020 kB
  • sloc: ansic: 19,816; makefile: 54; sh: 1
file content (99 lines) | stat: -rw-r--r-- 3,058 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/* Write an xplor file, charge density only */

/* Copyright (c) 2007 MJ Rutter 
 * 
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation, either version 3
 * of the Licence, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, see http://www.gnu.org/licenses/
 */ 


/* Some programs (pymol) are very fussy about the precise format statements
 *
 */

/* The xplor file format is:
 *
 * Blank line
 * I8      ntitles (must be >0)
 * ntitles lines of text as titles
 * 9I8     na,amin,amax,nb,bmin,bmax,nc,cmin,cmax
 * 6E12.5  a,b,c,alpha,beta,gamma  (Angstroms and degrees)
 * ZYX     precisely those three characters
 * do  c=cmin,cmax
 * I8      section number (1..nc ?)
 * 6E12.5  ((map(a,b,c),a=amin,amax),b=bmin,bmax)
 * enddo
 *
 * The stupid thing has a grid offset of half a grid cell compared to
 * anyone else's idea of sanity. So we have an option to shift all
 * atoms by this amount, rather than using inexact grid interpolation
 * schemes
 */

#include<stdio.h>
#include<stdlib.h>

#include "c2xsf.h"

void xplor_write(FILE* outfile, struct unit_cell *c, struct contents *m,
                 struct grid *g){
  int i,j,k;
  double *dptr1,*dptr2,abc[6];

  if(!g->data) error_exit("Xplor output requested, but no grid data");

  fprintf(outfile,"\n      1 !NTITLE\n%s\n",g->name);

  fprintf(outfile," %7d %7d %7d %7d %7d %7d %7d %7d %7d\n",
                                                 g->size[0],0,g->size[0]-1,
                                                 g->size[1],0,g->size[1]-1,
                                                 g->size[2],0,g->size[2]-1);

  cart2abc(c,m,abc,NULL,1);
  fprintf(outfile," %11f %11f %11f %11f %11f %11f\n",abc[0],abc[1],abc[2],
                                                     abc[3],abc[4],abc[5]);

  fprintf(outfile,"ZYX\n");

  dptr2=g->data;
  for(k=0;k<g->size[2];k++){
    fprintf(outfile,"%d\n",k+1);
    for(j=0;j<g->size[1];j++){
      dptr1=dptr2+k+j*g->size[2];              ;
      for(i=0;i<g->size[0];i++)
        fprintf(outfile,"%f\n",*(dptr1+i*g->size[1]*g->size[2]));
    }
  }
}

void xplor_fudge(struct unit_cell *c, struct contents *m, struct grid *g){
  double sx,sy,sz;
  int i;

  if((g->size[0]==0)||(g->size[1]==0)||(g->size[2]==0))
    error_exit("Shift of half grid cell requested, but no grid found.");

  if (debug>0) fprintf(stderr,"Shifting by half grid cell as requested\n");

  sx=0.5/g->size[0];
  sy=0.5/g->size[1];
  sz=0.5/g->size[2];

  for(i=0;i<m->n;i++){
    m->atoms[i].frac[0]+=sx;
    m->atoms[i].frac[1]+=sy;
    m->atoms[i].frac[2]+=sz;
  }

  addabs(m->atoms,m->n,c->basis);
}