File: crystal.c

package info (click to toggle)
xmakemol 5.16-5
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 1,696 kB
  • ctags: 1,393
  • sloc: ansic: 19,032; sh: 2,989; makefile: 123; perl: 98
file content (169 lines) | stat: -rw-r--r-- 3,572 bytes parent folder | download | duplicates (6)
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
/*

Copyright (C) 2001, 2002, 2004, 2005 Matthew P. Hodges
This file is part of XMakemol.

XMakemol 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 2, or (at your option)
any later version.

XMakemol 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 XMakemol; see the file COPYING.  If not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

*/

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <Xm/Xm.h>

#include "globals.h"
#include "bbox.h"

static int crystal_origin_set = 0;
static int crystal_vector_set[3] = {0, 0, 0};
static int crystal_images_set = 0;

static double crystal_origin[3];
static double crystal_vector[9];
static int crystal_images[3];

void set_crystal_origin (double *x)
{
  int i;

  for (i = 0; i < 3; i++)
    {
      crystal_origin[i] = x[i];
    }

  crystal_origin_set = 1;
}

void set_crystal_vector (int i, double *x)
{
  int j;

  for (j = 0; j < 3; j++)
    {
      crystal_vector[((i - 1) * 3) + j] = x[j];
    }

  crystal_vector_set[i - 1] = 1;
}

double * get_crystal_vector (void)
{
  return (crystal_vector);
}

void set_crystal_images (int *p)
{
  int i;

  for (i = 0; i < 3; i++)
    {
      crystal_images[i] = p[i];
    }

  crystal_images_set = 1;
}

int * get_crystal_images (void)
{
  return (crystal_images);
}

int crystal_p (void)
{
  if (crystal_origin_set
      && crystal_images_set
      && crystal_vector_set[0]
      && crystal_vector_set[1]
      && crystal_vector_set[2])
    {
      return (1);
    }
  else
    {
      return (0);
    }
}

void reset_crystal_status (void)
{
  crystal_origin_set = 0;
  crystal_images_set = 0;
  crystal_vector_set[0] = 0;
  crystal_vector_set[1] = 0;
  crystal_vector_set[2] = 0;
}

void update_crystal_bbox (bounding_box *bbox)
{
  double get_angle_axis (double *);
  void rotate (double *);
  void set_rotate_axis (double *);
  void set_rotate_angle (double);
  void set_rotate_origin (double *);

  int i, j;
  double axis[3], phi, rotated_vector[9];

  /* Copy the vectors */

  for (i = 0; i < 9; i++)
    {
      rotated_vector[i] = crystal_vector[i];
    }

  /* Set up rotation */

  for (i = 0; i < 3; i++)
    {
      for (j = 0; j < 3; j++)
        {
          angle_axis_matrix[i][j] = global_matrix[i][j];
        }
    }

  phi = get_angle_axis (axis);

  set_rotate_axis (axis);
  set_rotate_angle (phi);
  set_rotate_origin (NULL);

  /* Rotate the vectors */

  rotate (rotated_vector);
  rotate (rotated_vector + 3);
  rotate (rotated_vector + 6);

  /* Build the bounding box */

  /* TODO: this won't work if we don't have the crystal origin
     coincident with the first atom */

  bbox->v[2][0] = atoms[0].x;
  bbox->v[2][1] = atoms[0].y;
  bbox->v[2][2] = atoms[0].z;
 
  for (i = 0; i < 3; i++)
    {
      bbox->v[3][i] = bbox->v[2][i] + rotated_vector[i];
      bbox->v[6][i] = bbox->v[2][i] + rotated_vector[3 + i];
      bbox->v[7][i] = bbox->v[6][i] + rotated_vector[i];
      bbox->v[0][i] = bbox->v[2][i] + rotated_vector[6 + i];
      bbox->v[1][i] = bbox->v[0][i] + rotated_vector[i];
      bbox->v[4][i] = bbox->v[0][i] + rotated_vector[3 + i];
      bbox->v[5][i] = bbox->v[4][i] + rotated_vector[i];
    }
}