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 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335
|
/* Copyright (C) 2000-2003 Damir Zucic */
/*=============================================================================
discard.c
Purpose:
Execute discard command: discard the specified macromolecular
complex.
Input:
(1) Pointer to MolComplexS structure, with macromol. complexes.
(2) Pointer to the number of macromolecular complexes.
(3) Pointer to the next macromolecular complex identifier.
(4) Pointer to RuntimeS structure, with some runtime data.
(5) Pointer to ConfigS structure, with configuration data.
(6) Pointer to GUIS structure, with GUI data.
(7) Pointer to NearestAtomS structure.
(8) The number of pixels in the main window free area.
(9) Pointer to refreshI.
(10) The string which contains macromol. complex identifier.
Output:
(1) The specified macromolecular complex discarded.
(2) The number of complexes updated.
(3) The next macromolecular complex identifier updated.
(4) Return value.
Return value:
(1) Positive (command) code on success.
(2) Negative (error) code on failure.
Notes:
(1) The value of refreshI (*refreshIP) may be changed in this
function or in some function called by this function. It is
checked in EventLoop_ (see event_loop.c). It is assumed
that refreshI is updated no more than once in each event
handling function. If this is not the case, the care should
be taken to avoid refreshI overflow.
(2) The number of macromolecular complexes is not changed. It
should not be used as the actual number of macromolecular
complexes. It should be used in loops as the value which is
defines the highest value of the array index.
(3) If the currently caught macromol. complex is discarded, it
may happen that nothing is caught. This may be fixed by
catch (take) command. The ID of some complex which was not
discarded should be specified as argument to catch.
(4) This functions resets the edit mode index and some flags.
========includes:============================================================*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xos.h>
#include <X11/Xatom.h>
#include "defines.h"
#include "commands.h"
#include "typedefs.h"
/*======function prototypes:=================================================*/
char *ExtractToken_ (char *, int, char *, char *);
size_t MainRefresh_ (MolComplexS *, int,
RuntimeS *, ConfigS *, GUIS *,
NearestAtomS *, size_t, unsigned int);
int ControlRefresh_ (MolComplexS *, ConfigS *, GUIS *);
/*======execute discard command:=============================================*/
int Discard_ (MolComplexS *mol_complexSP,
int *mol_complexesNP, int *next_mol_complexIDP,
RuntimeS *runtimeSP, ConfigS *configSP, GUIS *guiSP,
NearestAtomS *nearest_atomSP, size_t pixelsN,
unsigned int *refreshIP, char *stringP)
{
char *remainderP;
char tokenA[SHORTSTRINGSIZE];
int complexID;
int mol_complexI;
MolComplexS *curr_mol_complexSP;
int job_doneF = 0;
/* Extract the macromolecular complex identifier: */
remainderP = ExtractToken_ (tokenA, SHORTSTRINGSIZE, stringP, " \t\n");
if (!remainderP)
{
strcpy (runtimeSP->messageA, "Complex identifier missing!");
runtimeSP->message_length = strlen (runtimeSP->messageA);
return ERROR_NO_ID;
}
/* If the second token contains the keyword ALL or *, */
/* discard all macromolecular complexes and return: */
if ((strstr (tokenA, "ALL") == tokenA) || (strstr (tokenA, "*")))
{
for (mol_complexI = 0; mol_complexI < *mol_complexesNP; mol_complexI++)
{
/* Prepare the pointer to the current macromol. complex: */
curr_mol_complexSP = mol_complexSP + mol_complexI;
/* Discard the complex and reinitialize associated data: */
/* Reset counters: */
curr_mol_complexSP->atomsN = 0;
curr_mol_complexSP->max_atomsN = 0;
/* Atomic array: */
if (curr_mol_complexSP->atomSP)
{
free (curr_mol_complexSP->atomSP);
curr_mol_complexSP->atomSP = NULL;
}
/* Header: */
if (curr_mol_complexSP->headerS.dataP)
{
free (curr_mol_complexSP->headerS.dataP);
curr_mol_complexSP->headerS.dataP = NULL;
}
/* Backbone data: */
if (curr_mol_complexSP->backboneSP)
{
free (curr_mol_complexSP->backboneSP);
curr_mol_complexSP->backboneSP = NULL;
}
curr_mol_complexSP->c_alphaN = 0;
/* Sequence information: */
if (curr_mol_complexSP->residueSP)
{
free (curr_mol_complexSP->residueSP);
curr_mol_complexSP->residueSP = NULL;
}
curr_mol_complexSP->residuesN = 0;
/* Secondary structure: */
if (curr_mol_complexSP->secondary_structureP)
{
free (curr_mol_complexSP->secondary_structureP);
curr_mol_complexSP->secondary_structureP = NULL;
}
/* Catch flag, tag flag, plane */
/* flag and two membrane flags: */
curr_mol_complexSP->catchF = 0;
curr_mol_complexSP->tagF = 0;
curr_mol_complexSP->planeS.hiddenF = 1;
curr_mol_complexSP->membraneS.definedF = 0;
curr_mol_complexSP->membraneS.hiddenF = 1;
}
/* Reset default_complexI: */
runtimeSP->default_complexI = 0;
/* Reset the edit mode index: */
runtimeSP->edit_modeI = 0;
/* Reset the edit_single_bondF flag: */
runtimeSP->edit_single_bondF = 0;
/* If some structures were grouped, reset the group flag: */
runtimeSP->groupF = 0;
/* If some structures were involved in a formation of a */
/* group, restore the original rotation center vectors: */
for (mol_complexI = 0; mol_complexI < *mol_complexesNP; mol_complexI++)
{
/* The pointer to the current macromolecular complex: */
curr_mol_complexSP = mol_complexSP + mol_complexI;
/* Check was this complex a group member: */
if (curr_mol_complexSP->group_memberF == 0) continue;
/* If this point is reached, this */
/* complex was a group member. */
/* Restore the original rotation center vector: */
curr_mol_complexSP->rotation_center_vectorS.x =
curr_mol_complexSP->backup_vectorS.x;
curr_mol_complexSP->rotation_center_vectorS.y =
curr_mol_complexSP->backup_vectorS.y;
curr_mol_complexSP->rotation_center_vectorS.z =
curr_mol_complexSP->backup_vectorS.z;
/* Reset the group_memberF: */
curr_mol_complexSP->group_memberF = 0;
}
/* Reinitialize the number of macromol. complexes */
/* and the next macromolecular complex identifier: */
*mol_complexesNP = 0;
*next_mol_complexIDP = 1;
/* Refresh the main window: */
(*refreshIP)++;
MainRefresh_ (mol_complexSP, *mol_complexesNP,
runtimeSP, configSP, guiSP,
nearest_atomSP, pixelsN, *refreshIP);
/* Refresh the control window: */
ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI,
configSP, guiSP);
/* Return positive value on success: */
return COMMAND_DISCARD;
}
/* If this point is reached, a single macromolecular complex should */
/* be discarded. Read the complex identifier (integer expected): */
if (sscanf (tokenA, "%d", &complexID) != 1)
{
strcpy (runtimeSP->messageA, "Bad macromolecular complex identifier!");
runtimeSP->message_length = strlen (runtimeSP->messageA);
return ERROR_BAD_ID;
}
/* Find and discard the specified macromolecular complex: */
for (mol_complexI = 0; mol_complexI < *mol_complexesNP; mol_complexI++)
{
/* Prepare the pointer to the current macromolecular complex: */
curr_mol_complexSP = mol_complexSP + mol_complexI;
/* If macromolecular complex is recognized */
/* discard it and set the flag job_doneF: */
if (curr_mol_complexSP->mol_complexID == complexID)
{
/* Reset counters: */
curr_mol_complexSP->atomsN = 0;
curr_mol_complexSP->max_atomsN = 0;
/* Free storage: */
if (curr_mol_complexSP->atomSP)
{
free (curr_mol_complexSP->atomSP);
curr_mol_complexSP->atomSP = NULL;
}
if (curr_mol_complexSP->headerS.dataP)
{
free (curr_mol_complexSP->headerS.dataP);
curr_mol_complexSP->headerS.dataP = NULL;
}
if (curr_mol_complexSP->backboneSP)
{
free (curr_mol_complexSP->backboneSP);
curr_mol_complexSP->backboneSP = NULL;
}
if (curr_mol_complexSP->residueSP)
{
free (curr_mol_complexSP->residueSP);
curr_mol_complexSP->residueSP = NULL;
}
if (curr_mol_complexSP->secondary_structureP)
{
free (curr_mol_complexSP->secondary_structureP);
curr_mol_complexSP->secondary_structureP = NULL;
}
/* Catch flag, tag flag, plane flag, two */
/* membrane flags and group member flag: */
curr_mol_complexSP->catchF = 0;
curr_mol_complexSP->tagF = 0;
curr_mol_complexSP->planeS.hiddenF = 1;
curr_mol_complexSP->membraneS.definedF = 0;
curr_mol_complexSP->membraneS.hiddenF = 1;
curr_mol_complexSP->group_memberF = 0;
/* Flag which says that job was done: */
job_doneF = 1;
}
}
/* If complex was not found, return the error code: */
if (job_doneF == 0)
{
strcpy (runtimeSP->messageA, "Bad complex identifier (out of range)!");
runtimeSP->message_length = strlen (runtimeSP->messageA);
return ERROR_BAD_ID;
}
/* Reset the edit mode index: */
runtimeSP->edit_modeI = 0;
/* Reset the edit_single_bondF flag: */
runtimeSP->edit_single_bondF = 0;
/* If some structures were grouped, reset the group flag: */
runtimeSP->groupF = 0;
/* If some structures were involved in a formation of a */
/* group, restore the original rotation center vectors: */
for (mol_complexI = 0; mol_complexI < *mol_complexesNP; mol_complexI++)
{
/* Prepare the pointer to the current macromolecular complex: */
curr_mol_complexSP = mol_complexSP + mol_complexI;
/* Check was this complex a group member: */
if (curr_mol_complexSP->group_memberF == 0) continue;
/* If this point is reached, the current complex was a group member. */
/* Restore the original rotation center vector: */
curr_mol_complexSP->rotation_center_vectorS.x =
curr_mol_complexSP->backup_vectorS.x;
curr_mol_complexSP->rotation_center_vectorS.y =
curr_mol_complexSP->backup_vectorS.y;
curr_mol_complexSP->rotation_center_vectorS.z =
curr_mol_complexSP->backup_vectorS.z;
}
/* Refresh the main window: */
(*refreshIP)++;
MainRefresh_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, guiSP,
nearest_atomSP, pixelsN, *refreshIP);
/* Refresh the control window: */
ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI, configSP, guiSP);
/* Return positive value on success: */
return COMMAND_DISCARD;
}
/*===========================================================================*/
|