File: rotate.c

package info (click to toggle)
garlic 1.6-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 4,516 kB
  • sloc: ansic: 52,465; makefile: 2,254
file content (319 lines) | stat: -rw-r--r-- 8,547 bytes parent folder | download | duplicates (5)
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
/* Copyright (C) 2000-2002 Damir Zucic */

/*=============================================================================

				rotate.c

Purpose:
	Rotate all caught macromolecular complexes  or edit default complex.

Input:
	(1) Pointer to MolComplexS structure, with macromolecular complexes.
	(2) Number of macromolecular complexes.
	(3) Pointer to RuntimeS structure.
	(4) Pointer to ConfigS structure.
	(5) Rotation angle.
	(6) Rotation axis identifier (1 = x, 2 = y, 3 = z).

Output:
	(1) Atoms rotated in all caught macromolecular complexes.

Return value:
	(1) Edit mode index (positive or zero) on success.
	(2) Negative on failure.

========includes:============================================================*/

#include <stdio.h>

#include <math.h>

#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xos.h>
#include <X11/Xatom.h>

#include "defines.h"
#include "typedefs.h"

/*======function prototypes:=================================================*/

int		EditPhi_ (MolComplexS *, RuntimeS *, ConfigS *, double);
int		EditPsi_ (MolComplexS *, RuntimeS *, ConfigS *, double);
int		EditOmega_ (MolComplexS *, RuntimeS *, ConfigS *, double);
int		EditBond_ (MolComplexS *, int, RuntimeS *, ConfigS *, double);
int		EditChi1_ (MolComplexS *, RuntimeS *, ConfigS *, double);
int		EditChi2_ (MolComplexS *, RuntimeS *, ConfigS *, double);
int		PrepareStereoData_ (MolComplexS *, ConfigS *);
void		RotatePlane_ (MolComplexS *, ConfigS *, double, int);
void		RotateMembrane_ (MolComplexS *, ConfigS *, double, int);

/*======rotate all caught macromol. complexes:===============================*/

int Rotate_ (MolComplexS *mol_complexSP, int mol_complexesN,
	      RuntimeS *runtimeSP, ConfigS *configSP,
	      double rotation_angle, int axisID)
{
MolComplexS	*curr_mol_complexSP;
int		edit_modeI;
int		mol_complexI;
double		cos_angle, sin_angle;
size_t		atomsN, atomI;
AtomS		*curr_atomSP;
double		x0, y0, z0, x, y, z, x_new = 0.0, y_new = 0.0, z_new = 0.0;

/* Pointer to default macromolecular complex: */
curr_mol_complexSP = mol_complexSP + runtimeSP->default_complexI;

/* Copy the edit mode index: */
edit_modeI = runtimeSP->edit_modeI;

/* Check the axis identifier and edit mode index. */

/* If axisID is three and edit_modeI is two, three, four or */
/* six,  edit phi, psi,  omega or selected side chain bond: */
if ((axisID == 3) &&
    ((edit_modeI == 2) || (edit_modeI == 3) ||
     (edit_modeI == 4) || (edit_modeI == 6))) 
	{
	/* Edit phi: */
	if (edit_modeI == 2)
		{
		EditPhi_ (curr_mol_complexSP,
			  runtimeSP, configSP,
			  rotation_angle);
		}

	/* Edit psi: */
	else if (edit_modeI == 3)
		{
		EditPsi_ (curr_mol_complexSP,
			  runtimeSP, configSP,
			  rotation_angle);
		}

	/* Edit omega: */
	else if (edit_modeI == 4)
		{
		EditOmega_ (curr_mol_complexSP,
			    runtimeSP, configSP,
			    rotation_angle);
		}

	/* Edit some other bond (side chain): */
	else if (edit_modeI == 6)
		{
		EditBond_ (curr_mol_complexSP,
			   runtimeSP->default_complexI,
			   runtimeSP, configSP,
			   rotation_angle);
		}

	/* Prepare the stereo data,  update one */
	/* flag and return the edit mode index: */
	/* Prepare stereo data, if required: */
	if (configSP->stereoF)
		{
		PrepareStereoData_ (curr_mol_complexSP, configSP);
		}

	/* Set the position_changedF: */
	curr_mol_complexSP->position_changedF = 1;

	/* Return the edit mode index: */
	return edit_modeI;
	}

/* If axis identifier is two and edit_modeI is five, edit phi: */
else if ((axisID == 2) && (edit_modeI == 5))
	{
	/* Edit phi: */
	rotation_angle *= -1;
	EditPhi_ (curr_mol_complexSP, runtimeSP, configSP, rotation_angle);

	/* Prepare the stereo data,  update one */
	/* flag and return the edit mode index: */
	/* Prepare stereo data, if required: */
	if (configSP->stereoF)
		{
		PrepareStereoData_ (curr_mol_complexSP, configSP);
		}

	/* Set the position_changedF: */
	curr_mol_complexSP->position_changedF = 1;

	/* Return the edit mode index: */
	return edit_modeI;
	}

/* If axis identifier is two and edit_modeI is seven, edit chi1: */
else if ((axisID == 2) && (edit_modeI == 7))
	{
	/* Edit chi1: */
	rotation_angle *= -1;
	EditChi1_ (curr_mol_complexSP, runtimeSP, configSP, rotation_angle);

	/* Prepare the stereo data,  update one */
	/* flag and return the edit mode index: */
	/* Prepare stereo data, if required: */
	if (configSP->stereoF)
		{
		PrepareStereoData_ (curr_mol_complexSP, configSP);
		}

	/* Set the position_changedF: */
	curr_mol_complexSP->position_changedF = 1;

	/* Return the edit mode index: */
	return edit_modeI;
	}

/* If axis identifier is one and edit_modeI is five, edit psi: */
else if ((axisID == 1) && (edit_modeI == 5))
	{
	/* Edit psi: */
	rotation_angle *= -1;
	EditPsi_ (curr_mol_complexSP, runtimeSP, configSP, rotation_angle);

	/* Prepare the stereo data,  update one */
	/* flag and return the edit mode index: */
	/* Prepare stereo data, if required: */
	if (configSP->stereoF)
		{
		PrepareStereoData_ (curr_mol_complexSP, configSP);
		}

	/* Set the position_changedF: */
	curr_mol_complexSP->position_changedF = 1;

	/* Return the edit mode index: */
	return edit_modeI;
	}

/* If axis identifier is one and edit_modeI is seven, edit chi2: */
else if ((axisID == 1) && (edit_modeI == 7))
	{
	/* Edit chi2: */
	rotation_angle *= -1;
	EditChi2_ (curr_mol_complexSP, runtimeSP, configSP, rotation_angle);

	/* Prepare the stereo data,  update one */
	/* flag and return the edit mode index: */
	/* Prepare stereo data, if required: */
	if (configSP->stereoF)
		{
		PrepareStereoData_ (curr_mol_complexSP, configSP);
		}

	/* Set the position_changedF: */
	curr_mol_complexSP->position_changedF = 1;

	/* Return the edit mode index: */
	return edit_modeI;
	}

/* If this point is reached, the entire structure should be rotated. */

/* Calculate cosine and sine of the rotation angle: */
cos_angle = cos (rotation_angle);
sin_angle = sin (rotation_angle);

/* If working in default mode, rotate the entire structure: */
for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++)
	{
	/* Pointer to the current macromolecular complex: */
	curr_mol_complexSP = mol_complexSP + mol_complexI;

	/* Check is the current macromolecular complex caught: */
	if (curr_mol_complexSP->catchF == 0) continue;

	/* Check is it necessary to rotate the plane: */
	if (curr_mol_complexSP->move_bits & PLANE_MASK)
		{
		RotatePlane_ (curr_mol_complexSP, configSP,
			      rotation_angle, axisID);
		}

	/* Check is it necessary to rotate the membrane: */
	if (curr_mol_complexSP->move_bits & MEMBRANE_MASK)
		{
		RotateMembrane_ (curr_mol_complexSP, configSP,
				 rotation_angle, axisID);
		}

	/* Check is it necessary to rotate the structure at all: */
	if (!(curr_mol_complexSP->move_bits & STRUCTURE_MASK)) continue;

	/* Copy the rotation center coordinates: */
	x0 = curr_mol_complexSP->rotation_center_vectorS.x;
	y0 = curr_mol_complexSP->rotation_center_vectorS.y;
	z0 = curr_mol_complexSP->rotation_center_vectorS.z;

	/* Number of atoms in a macromolecular complex: */
	atomsN = curr_mol_complexSP->atomsN;

	/* Scan all atoms in the current complex: */
	for (atomI = 0; atomI < atomsN; atomI++)
		{
		/* Pointer to the current atom: */
		curr_atomSP = curr_mol_complexSP->atomSP + atomI;

		/* Coordinates relative to the rotation center: */
		x = curr_atomSP->raw_atomS.x[0] - x0;
		y = curr_atomSP->raw_atomS.y    - y0;
		z = curr_atomSP->raw_atomS.z[0] - z0;

		/* Rotate these coordinates: */
		switch (axisID)
			{
			/* Rotate around x: */
			case 1:
				x_new =  x;
				y_new =  y * cos_angle - z * sin_angle;
				z_new =  y * sin_angle + z * cos_angle;
				break;

			/* Rotate around y: */
			case 2:
				x_new =  x * cos_angle + z * sin_angle;
				y_new =  y;
				z_new = -x * sin_angle + z * cos_angle;
				break;

			/* Rotate around z: */
			case 3:
				x_new =  x * cos_angle - y * sin_angle;
				y_new =  x * sin_angle + y * cos_angle;
				z_new =  z;
				break;

			/* The impossible case: */
			default:
				;
				break;

			}

		/* Translate and store new coordinates: */
		curr_atomSP->raw_atomS.x[0] = x_new + x0;
		curr_atomSP->raw_atomS.y    = y_new + y0;
		curr_atomSP->raw_atomS.z[0] = z_new + z0;
		}

	/* Prepare stereo data, if required: */
	if (configSP->stereoF)
		{
		PrepareStereoData_ (curr_mol_complexSP, configSP);
		}

	/* Set the position_changedF: */
	curr_mol_complexSP->position_changedF = 1;
	}

/* Return edit mode index: */
return edit_modeI;
}

/*===========================================================================*/