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
|
/* Copyright (C) 2000 Damir Zucic */
/*=============================================================================
save.c
Purpose:
Execute save command: save the atomic coordinates to a specified
file. PDB format is used.
Input:
(1) Pointer to MolComplexS structure, with macromol. complexes.
(2) The number of macromolecular complexes.
(3) Pointer to RuntimeS structure.
Output:
(1) Atomic coordinates written to file, on success.
(2) Return value.
Return value:
(1) Positive (command) code on success.
(2) Negative (error) code on failure.
========includes:============================================================*/
#include <stdio.h>
#include <string.h>
#include <ctype.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 *);
int WriteLine_ (FILE *, RawAtomS *);
/*======execute save command:================================================*/
int Save_ (MolComplexS *mol_complexSP, int mol_complexesN, RuntimeS *runtimeSP)
{
char *remainderP;
char tokenA[STRINGSIZE];
FILE *fileP;
char token_copyA[STRINGSIZE];
char *P;
int n;
int selectionF = 0;
MolComplexS *curr_mol_complexSP;
size_t atomsN, atomI;
AtomS *curr_atomSP;
/* Skip the first token: */
remainderP = ExtractToken_ (tokenA, STRINGSIZE,
runtimeSP->curr_commandA, " \t\n");
if (!remainderP) return ERROR_SAVE;
/* The second token should contain the file name: */
remainderP = ExtractToken_ (tokenA, STRINGSIZE, remainderP, " \t\n");
if (!remainderP)
{
strcpy (runtimeSP->messageA, "Missing output file name!");
runtimeSP->message_length = strlen (runtimeSP->messageA);
return ERROR_NO_FILE_NAME;
}
/* Try to open the output file: */
if ((fileP = fopen (tokenA, "w")) == NULL)
{
strcpy (runtimeSP->messageA, "Failed to open output file!");
runtimeSP->message_length = strlen (runtimeSP->messageA);
return ERROR_OPEN_FAILURE;
}
/* If third token is present, it should contain the keyword SEL: */
remainderP = ExtractToken_ (tokenA, STRINGSIZE, remainderP, " \t\n");
if (remainderP)
{
/** Convert token to uppercase: **/
strncpy (token_copyA, tokenA, STRINGSIZE - 1);
P = token_copyA;
while ((n = *P++) != '\0') *(P - 1) = toupper (n);
/** If this token contains the keyword SEL, set selectionF: **/
if (strstr (token_copyA, "SEL") == token_copyA) selectionF = 1;
}
/* Prepare the pointer to default caught complex: */
curr_mol_complexSP = mol_complexSP + runtimeSP->default_complexI;
/** Number of atoms in a macromolecular complex: **/
atomsN = curr_mol_complexSP->atomsN;
if (atomsN == 0)
{
strcpy (runtimeSP->messageA, "Catch the complex which is not empty!");
runtimeSP->message_length = strlen (runtimeSP->messageA);
return ERROR_SAVE;
}
/* 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;
/** If only selected atoms should be **/
/** saved, check is this atom selected: **/
if (selectionF)
{
if (curr_atomSP->selectedF == 0) continue;
}
/** Write data to output file: **/
WriteLine_ (fileP, &curr_atomSP->raw_atomS);
}
/* Close the output file: */
fclose (fileP);
/* Return the command code: */
return COMMAND_SAVE;
}
/*===========================================================================*/
|