1
/* Copyright (C) 2000 Damir Zucic */
3
/*=============================================================================
8
Execute save command: save the atomic coordinates to a specified
9
file. PDB format is used.
12
(1) Pointer to MolComplexS structure, with macromol. complexes.
13
(2) The number of macromolecular complexes.
14
(3) Pointer to RuntimeS structure.
17
(1) Atomic coordinates written to file, on success.
21
(1) Positive (command) code on success.
22
(2) Negative (error) code on failure.
24
========includes:============================================================*/
32
#include <X11/Xutil.h>
34
#include <X11/Xatom.h>
40
/*======function prototypes:=================================================*/
42
char *ExtractToken_ (char *, int, char *, char *);
43
int WriteLine_ (FILE *, RawAtomS *);
45
/*======execute save command:================================================*/
47
int Save_ (MolComplexS *mol_complexSP, int mol_complexesN, RuntimeS *runtimeSP)
50
char tokenA[STRINGSIZE];
52
char token_copyA[STRINGSIZE];
56
MolComplexS *curr_mol_complexSP;
60
/* Skip the first token: */
61
remainderP = ExtractToken_ (tokenA, STRINGSIZE,
62
runtimeSP->curr_commandA, " \t\n");
63
if (!remainderP) return ERROR_SAVE;
65
/* The second token should contain the file name: */
66
remainderP = ExtractToken_ (tokenA, STRINGSIZE, remainderP, " \t\n");
69
strcpy (runtimeSP->messageA, "Missing output file name!");
70
runtimeSP->message_length = strlen (runtimeSP->messageA);
71
return ERROR_NO_FILE_NAME;
74
/* Try to open the output file: */
75
if ((fileP = fopen (tokenA, "w")) == NULL)
77
strcpy (runtimeSP->messageA, "Failed to open output file!");
78
runtimeSP->message_length = strlen (runtimeSP->messageA);
79
return ERROR_OPEN_FAILURE;
82
/* If third token is present, it should contain the keyword SEL: */
83
remainderP = ExtractToken_ (tokenA, STRINGSIZE, remainderP, " \t\n");
86
/** Convert token to uppercase: **/
87
strncpy (token_copyA, tokenA, STRINGSIZE - 1);
89
while ((n = *P++) != '\0') *(P - 1) = toupper (n);
91
/** If this token contains the keyword SEL, set selectionF: **/
92
if (strstr (token_copyA, "SEL") == token_copyA) selectionF = 1;
95
/* Prepare the pointer to default caught complex: */
96
curr_mol_complexSP = mol_complexSP + runtimeSP->default_complexI;
98
/** Number of atoms in a macromolecular complex: **/
99
atomsN = curr_mol_complexSP->atomsN;
102
strcpy (runtimeSP->messageA, "Catch the complex which is not empty!");
103
runtimeSP->message_length = strlen (runtimeSP->messageA);
107
/* Scan all atoms in the current complex: */
108
for (atomI = 0; atomI < atomsN; atomI++)
110
/** Pointer to the current atom: **/
111
curr_atomSP = curr_mol_complexSP->atomSP + atomI;
113
/** If only selected atoms should be **/
114
/** saved, check is this atom selected: **/
117
if (curr_atomSP->selectedF == 0) continue;
120
/** Write data to output file: **/
121
WriteLine_ (fileP, &curr_atomSP->raw_atomS);
124
/* Close the output file: */
127
/* Return the command code: */
131
/*===========================================================================*/