~ubuntu-branches/ubuntu/karmic/gpp4/karmic

« back to all changes in this revision

Viewing changes to src/csymlib.c

  • Committer: Bazaar Package Importer
  • Author(s): Morten Kjeldgaard
  • Date: 2008-12-03 11:21:42 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20081203112142-bvuelg39lt2lnokb
Tags: 1.1.0-0ubuntu1
* New upstream version (LP: #322205)
* Some compilation warnings fixed, patch 01-ubuntu-fixes
  sent upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
#include "cvecmat.h"
35
35
#include "ccp4_errno.h"
36
36
#include "ccp4_unitcell.h"
37
 
#include "ccp4_sysdep.h"
38
37
 
39
38
/* stuff for error reporting */
40
39
#define CSYM_ERRNO(n) (CCP4_ERR_SYM | (n))
46
45
#define  CSYMERR_NullSpacegroup      3
47
46
#define  CSYMERR_NoAsuDefined        4
48
47
#define  CSYMERR_NoLaueCodeDefined   5
49
 
 
50
 
 /*!
51
 
   Find the path of the SYMINFO file. We will try to locate the file
52
 
   in several places (in increasing order of significance):
53
 
      -# $SYMINFO environment variable
54
 
      -# ./syminfo.lib
55
 
      -# $prefix/share/gpp4/syminfo.lib
56
 
      -# $prefix/lib/syminfo.lib
57
 
      -# $CCP4/lib/data/syminfo.lib
58
 
   where $prefix is defined by the --prefix switch to the configure script.
59
 
   The function allocates memory for the pathname that must be free'd
60
 
   by the caller in order to avoid a memory leak.
61
 
   @return path to syminfo.lib file.
62
 
 */
63
 
static char *open_syminfo_file()
64
 
{
65
 
  struct stat statbuf;
66
 
  char *str;
67
 
  char *fnam = (char *)ccp4_utils_malloc(512);
68
 
 
69
 
  if ((str = getenv("SYMINFO"))) {
70
 
    /* SYMINFO was defined, now check to see if file exists */
71
 
    strncpy (fnam, str, 512);
72
 
    if( stat(fnam,&statbuf) == 0) {
73
 
      printf("\n Spacegroup information obtained from library file: \n");
74
 
      printf(" Logical Name: SYMINFO   Filename: %s\n\n", fnam);
75
 
      return fnam;
76
 
    }
77
 
  }
78
 
 
79
 
  printf("Environment variable SYMINFO not set ... guessing location of symmetry file.\n");
80
 
 
81
 
  strncpy (fnam, "./syminfo.lib", 14);
82
 
  if( stat(fnam,&statbuf) == 0) {
83
 
    printf("\n Spacegroup information obtained from local file: %s\n", fnam);
84
 
    return fnam;
85
 
  }
86
 
 
87
 
  strncpy (fnam, GPP4_PREFIX, 512-24);
88
 
  strncat (fnam, "/share/gpp4/syminfo.lib", 24);
89
 
  if( stat(fnam,&statbuf) == 0) {
90
 
    printf("\n Spacegroup information obtained from system file: %s\n", fnam);
91
 
    return fnam;
92
 
  }
93
 
 
94
 
  strncpy (fnam, GPP4_PREFIX, 512-17);
95
 
  strncpy (fnam, "/lib/syminfo.lib", 17);
96
 
  if( stat(fnam,&statbuf) == 0) {
97
 
    printf("\n Spacegroup information obtained from system file: %s\n", fnam);
98
 
    return fnam;
99
 
  }
100
 
 
101
 
  /* Hmmm. Try one last time in the CCP4 installation */
102
 
 
103
 
  if (!(str = getenv("CCP4"))) {
104
 
    printf("Environment variable CCP4 not set ... big trouble! \n");
105
 
    free(fnam);
106
 
    return NULL;
107
 
  }
108
 
 
109
 
  strncpy(fnam, str, 512);
110
 
  strncat(fnam,"/lib/data/syminfo.lib", 22);
111
 
  if( stat(fnam,&statbuf) == 0) {
112
 
    printf("\n Spacegroup information obtained from CCP4 library: %s\n", fnam);
113
 
    return fnam;
114
 
  }
115
 
 
116
 
  /* We give up... */
117
 
  free(fnam);
118
 
  return NULL;
119
 
}
 
48
#define  CSYMERR_SyminfoTokensMissing 6
 
49
 
120
50
 
121
51
CCP4SPG *ccp4spg_load_by_standard_num(const int numspg) 
122
52
143
73
  return ccp4spg_load_spacegroup(0, 0, NULL, NULL, nsym1, op1);
144
74
}
145
75
 
 
76
 
 
77
char *gpp4_open_syminfo_file();
 
78
 
 
79
 
146
80
CCP4SPG *ccp4spg_load_spacegroup(const int numspg, const int ccp4numspg,
147
81
         const char *spgname, const char *ccp4spgname, 
148
82
         const int nsym1, const ccp4_symop *op1) 
149
83
 
150
84
{ CCP4SPG *spacegroup;
151
85
  int i,j,k,l,debug=0,nsym2,symops_provided=0,ierr,ilaue;
152
 
  float sg_chb[4][4],limits[2],rot1[4][4],rot2[4][4];
 
86
  float sg_chb[4][4],limits[2],rot1[4][4],rot2[4][4],det;
153
87
  FILE *filein;
154
88
  char *symopfile, *ccp4dir, filerec[80];
155
89
  ccp4_symop *op2,*op3,opinv;
156
90
 
 
91
  static int reported_syminfo = 0;       /* report location of SYMINFO first time only */
 
92
 
157
93
  /* spacegroup variables */
158
94
  int sg_num, sg_ccp4_num, sg_nsymp, sg_num_cent;
159
95
  float cent_ops[4][4];
206
142
 
207
143
  /* Open the symop file: */
208
144
 
209
 
  if (!(symopfile = open_syminfo_file()))
 
145
  if (!(symopfile = gpp4_open_syminfo_file()))
210
146
    return NULL;
211
147
 
212
148
  filein = fopen(symopfile,"r");
217
153
    return NULL;
218
154
  }
219
155
 
 
156
  if (!(getenv("SYMINFO"))) free(symopfile);
 
157
 
220
158
  parser = ccp4_parse_start(20);
221
159
  if (parser == NULL) 
222
160
    ccp4_signal(CSYM_ERRNO(CSYMERR_ParserFail),"ccp4spg_load_spacegroup",NULL);
230
168
    printf(" parser initialised \n");
231
169
 
232
170
  while (fgets(filerec,80,filein)) {
 
171
 
 
172
    /* If syminfo.lib comes from a DOS platform, and we are on
 
173
       unix, need to strip spurious \r character. Note this is
 
174
       necessary because we have removed \r as parser delimiter. */
 
175
    if (strlen(filerec) > 1){
 
176
      if (filerec[strlen(filerec)-2]=='\r') {
 
177
        filerec[strlen(filerec)-2]='\n';
 
178
        filerec[strlen(filerec)-1]='\0';
 
179
      }
 
180
    }
 
181
 
233
182
    if (strlen(filerec) > 1) {
234
183
 
235
184
      ccp4_parser(filerec, 80, parser, iprint);
236
185
 
237
186
      if (ccp4_keymatch(key, "number")) {
238
 
        sg_num = (int) token[1].value;
 
187
        if (parser->ntokens < 2) {
 
188
           printf("Current SYMINFO line = %s\n",filerec);
 
189
           ccp4_signal(CCP4_ERRLEVEL(2) | CSYM_ERRNO(CSYMERR_SyminfoTokensMissing),"ccp4spg_load_spacegroup",NULL);
 
190
        } else {
 
191
          sg_num = (int) token[1].value;
 
192
        }
239
193
      }
240
194
 
241
195
      if (ccp4_keymatch(key, "basisop")) {
243
197
      }
244
198
 
245
199
      if (ccp4_keymatch(key, "symbol")) {
246
 
        if (strcmp(token[1].fullstring,"ccp4") == 0)
247
 
          sg_ccp4_num = (int) token[2].value;
248
 
        if (strcmp(token[1].fullstring,"Hall") == 0)
249
 
          strcpy(sg_symbol_Hall,token[2].fullstring);
250
 
        if (strcmp(token[1].fullstring,"xHM") == 0)
251
 
          strcpy(sg_symbol_xHM,token[2].fullstring);
252
 
        if (strcmp(token[1].fullstring,"old") == 0)
253
 
          strcpy(sg_symbol_old,token[2].fullstring);
254
 
        if (strcmp(token[1].fullstring,"patt") == 0)
255
 
          strcpy(sg_patt_group,token[3].fullstring);
256
 
        if (strcmp(token[1].fullstring,"pgrp") == 0)
257
 
          strcpy(sg_point_group,token[3].fullstring);
 
200
        if (parser->ntokens < 3) {
 
201
           printf("Current SYMINFO line = %s\n",filerec);
 
202
           ccp4_signal(CCP4_ERRLEVEL(2) | CSYM_ERRNO(CSYMERR_SyminfoTokensMissing),"ccp4spg_load_spacegroup",NULL);
 
203
        } else {
 
204
          if (strcmp(token[1].fullstring,"ccp4") == 0)
 
205
            sg_ccp4_num = (int) token[2].value;
 
206
          if (strcmp(token[1].fullstring,"Hall") == 0)
 
207
            strcpy(sg_symbol_Hall,token[2].fullstring);
 
208
          if (strcmp(token[1].fullstring,"xHM") == 0)
 
209
            strcpy(sg_symbol_xHM,token[2].fullstring);
 
210
          if (strcmp(token[1].fullstring,"old") == 0)
 
211
            strcpy(sg_symbol_old,token[2].fullstring);
 
212
          if (strcmp(token[1].fullstring,"patt") == 0)
 
213
            strcpy(sg_patt_group,token[3].fullstring);
 
214
          if (strcmp(token[1].fullstring,"pgrp") == 0)
 
215
            strcpy(sg_point_group,token[3].fullstring);
 
216
        }
258
217
      }
259
218
 
260
219
      if (ccp4_keymatch(key, "hklasu")) {
261
 
        if (strcmp(token[1].fullstring,"ccp4") == 0)
262
 
          strcpy(sg_asu_descr,token[2].fullstring);
 
220
        if (parser->ntokens < 3) {
 
221
           printf("Current SYMINFO line = %s\n",filerec);
 
222
           ccp4_signal(CCP4_ERRLEVEL(2) | CSYM_ERRNO(CSYMERR_SyminfoTokensMissing),"ccp4spg_load_spacegroup",NULL);
 
223
        } else {
 
224
          if (strcmp(token[1].fullstring,"ccp4") == 0)
 
225
            strcpy(sg_asu_descr,token[2].fullstring);
 
226
        }
263
227
      }
264
228
 
265
229
      if (ccp4_keymatch(key, "mapasu")) {
266
 
        if (strcmp(token[1].fullstring,"zero") == 0) {
267
 
          strcpy(map_asu_x,token[2].fullstring);
268
 
          strcpy(map_asu_y,token[3].fullstring);
269
 
          strcpy(map_asu_z,token[4].fullstring);
270
 
        } else if (strcmp(token[1].fullstring,"ccp4") == 0) {
271
 
          strcpy(map_asu_ccp4_x,token[2].fullstring);
272
 
          strcpy(map_asu_ccp4_y,token[3].fullstring);
273
 
          strcpy(map_asu_ccp4_z,token[4].fullstring);
 
230
        if (parser->ntokens < 5) {
 
231
           printf("Current SYMINFO line = %s\n",filerec);
 
232
           ccp4_signal(CCP4_ERRLEVEL(2) | CSYM_ERRNO(CSYMERR_SyminfoTokensMissing),"ccp4spg_load_spacegroup",NULL);
 
233
        } else {
 
234
          if (strcmp(token[1].fullstring,"zero") == 0) {
 
235
            strcpy(map_asu_x,token[2].fullstring);
 
236
            strcpy(map_asu_y,token[3].fullstring);
 
237
            strcpy(map_asu_z,token[4].fullstring);
 
238
          } else if (strcmp(token[1].fullstring,"ccp4") == 0) {
 
239
            strcpy(map_asu_ccp4_x,token[2].fullstring);
 
240
            strcpy(map_asu_ccp4_y,token[3].fullstring);
 
241
            strcpy(map_asu_ccp4_z,token[4].fullstring);
 
242
          }
274
243
        }
275
244
      }
276
245
 
393
362
     strncpy(filerec,sg_symop[j],80);   /* symop_to_mat4 overwrites later sg_symop */
394
363
     symop_to_mat4(filerec,filerec+strlen(filerec),rot2[0]);
395
364
     ccp4_4matmul(rot1,(const float (*)[4])cent_ops,(const float (*)[4])rot2);
396
 
     invert4matrix((const float (*)[4])rot1,rot2);
 
365
     det=invert4matrix((const float (*)[4])rot1,rot2);
 
366
     if (debug) printf("symop determinant: %f\n",det);
397
367
     for (k = 0; k < 3; ++k) {
398
368
      for (l = 0; l < 3; ++l) {
399
369
        spacegroup->symop[i*sg_nsymp+j].rot[k][l]=rot1[k][l];
891
861
    *ch1 = ' ';
892
862
    *(ch1+1) = ' ';
893
863
    ch1 = strstr(name,"R");
894
 
    if (ch1) *ch1 = 'H';
 
864
    if (ch1 != NULL) *ch1 = 'H';
895
865
  }
896
866
    
897
867
  return;
969
939
  return ( i == n );
970
940
}
971
941
 
 
942
int ccp4_spgrp_equal_order( int nsym1, const ccp4_symop *op1, int nsym2, const ccp4_symop *op2 )
 
943
{
 
944
  int i;
 
945
 
 
946
  /* first check that we have equal number of symops */
 
947
  if ( nsym1 != nsym2 ) return 0;
 
948
 
 
949
  /* compare the symcodes */
 
950
  for ( i = 0; i < nsym1; i++ ) {
 
951
    if ( ccp4_symop_code( op1[i] ) != ccp4_symop_code( op2[i] ) ) break;
 
952
  }
 
953
 
 
954
  /* return true if they are equal */
 
955
  return ( i == nsym1 );
 
956
}
 
957
 
972
958
int ccp4_symop_code(ccp4_symop op)
973
959
{
974
960
  int i, j, code=0;
1603
1589
 
1604
1590
void ccp4spg_print_recip_spgrp(const CCP4SPG* sp)
1605
1591
{
 
1592
  if (!sp) {  
 
1593
    ccp4_signal(CSYM_ERRNO(CSYMERR_NullSpacegroup),"ccp4spg_print_recip_spgrp",NULL); 
 
1594
    return;
 
1595
  }
 
1596
 
1606
1597
    printf("Reciprocal space symmetry: \n");
1607
1598
    printf("Space group: \"%s\" Point group: \"%s\" Laue group: \"%s\" \n",
1608
1599
       sp->symbol_xHM,sp->point_group,sp->laue_name); 
1946
1937
  int i,k,l,status=1;
1947
1938
  ccp4_symop *op1;
1948
1939
 
 
1940
  if (nsym <= 0) return 0;
 
1941
 
1949
1942
  /* identify spacegroup from supplied symops */
1950
1943
  op1 = (ccp4_symop *) ccp4_utils_malloc(nsym*sizeof(ccp4_symop));
1951
1944
  for (i = 0; i < nsym; ++i) {
1963
1956
    status = ccp4uc_is_rhombohedral(cell,0.01F);
1964
1957
  } else if (strstr(spacegroup->symbol_xHM,":H")) {
1965
1958
    status = ccp4uc_is_hexagonal(cell,0.01F);
 
1959
  } else if (spacegroup->spg_num >= 168 && spacegroup->spg_num <= 194) {
 
1960
    status = ccp4uc_is_hexagonal(cell,0.01F);
1966
1961
  }
1967
1962
 
1968
1963
  free(op1);