~ubuntu-branches/ubuntu/breezy/garlic/breezy

« back to all changes in this revision

Viewing changes to save.c

  • Committer: Bazaar Package Importer
  • Author(s): zhaoway
  • Date: 2001-04-24 07:09:13 UTC
  • Revision ID: james.westby@ubuntu.com-20010424070913-uzpupnwdfhmliebz
Tags: upstream-1.1
ImportĀ upstreamĀ versionĀ 1.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (C) 2000 Damir Zucic */
 
2
 
 
3
/*=============================================================================
 
4
 
 
5
                                save.c
 
6
 
 
7
Purpose:
 
8
        Execute save command: save the atomic coordinates to a specified
 
9
        file. PDB format is used.
 
10
 
 
11
Input:
 
12
        (1) Pointer to MolComplexS structure, with macromol. complexes.
 
13
        (2) The number of macromolecular complexes.
 
14
        (3) Pointer to RuntimeS structure.
 
15
 
 
16
Output:
 
17
        (1) Atomic coordinates written to file, on success.
 
18
        (2) Return value.
 
19
 
 
20
Return value:
 
21
        (1) Positive (command) code on success.
 
22
        (2) Negative (error) code on failure.
 
23
 
 
24
========includes:============================================================*/
 
25
 
 
26
#include <stdio.h>
 
27
 
 
28
#include <string.h>
 
29
#include <ctype.h>
 
30
 
 
31
#include <X11/Xlib.h>
 
32
#include <X11/Xutil.h>
 
33
#include <X11/Xos.h>
 
34
#include <X11/Xatom.h>
 
35
 
 
36
#include "defines.h"
 
37
#include "commands.h"
 
38
#include "typedefs.h"
 
39
 
 
40
/*======function prototypes:=================================================*/
 
41
 
 
42
char            *ExtractToken_ (char *, int, char *, char *);
 
43
int             WriteLine_ (FILE *, RawAtomS *);
 
44
 
 
45
/*======execute save command:================================================*/
 
46
 
 
47
int Save_ (MolComplexS *mol_complexSP, int mol_complexesN, RuntimeS *runtimeSP)
 
48
{
 
49
char            *remainderP;
 
50
char            tokenA[STRINGSIZE];
 
51
FILE            *fileP;
 
52
char            token_copyA[STRINGSIZE];
 
53
char            *P;
 
54
int             n;
 
55
int             selectionF = 0;
 
56
MolComplexS     *curr_mol_complexSP;
 
57
size_t          atomsN, atomI;
 
58
AtomS           *curr_atomSP;
 
59
 
 
60
/* Skip the first token: */
 
61
remainderP = ExtractToken_ (tokenA, STRINGSIZE,
 
62
                            runtimeSP->curr_commandA, " \t\n");
 
63
if (!remainderP) return ERROR_SAVE;
 
64
 
 
65
/* The second token should contain the file name: */
 
66
remainderP = ExtractToken_ (tokenA, STRINGSIZE, remainderP, " \t\n");
 
67
if (!remainderP)
 
68
        {
 
69
        strcpy (runtimeSP->messageA, "Missing output file name!");
 
70
        runtimeSP->message_length = strlen (runtimeSP->messageA);
 
71
        return ERROR_NO_FILE_NAME;
 
72
        }
 
73
 
 
74
/* Try to open the output file: */
 
75
if ((fileP = fopen (tokenA, "w")) == NULL)
 
76
        {
 
77
        strcpy (runtimeSP->messageA, "Failed to open output file!");
 
78
        runtimeSP->message_length = strlen (runtimeSP->messageA);
 
79
        return ERROR_OPEN_FAILURE;
 
80
        }
 
81
 
 
82
/* If third token is present, it should contain the keyword SEL: */
 
83
remainderP = ExtractToken_ (tokenA, STRINGSIZE, remainderP, " \t\n");
 
84
if (remainderP)
 
85
        {
 
86
        /** Convert token to uppercase: **/
 
87
        strncpy (token_copyA, tokenA, STRINGSIZE - 1);
 
88
        P = token_copyA;
 
89
        while ((n = *P++) != '\0') *(P - 1) = toupper (n);
 
90
 
 
91
        /** If this token contains the keyword SEL, set selectionF: **/
 
92
        if (strstr (token_copyA, "SEL") == token_copyA) selectionF = 1;
 
93
        }
 
94
 
 
95
/* Prepare the pointer to default caught complex: */
 
96
curr_mol_complexSP = mol_complexSP + runtimeSP->default_complexI;
 
97
 
 
98
/** Number of atoms in a macromolecular complex: **/
 
99
atomsN = curr_mol_complexSP->atomsN;
 
100
if (atomsN == 0)
 
101
        {
 
102
        strcpy (runtimeSP->messageA, "Catch the complex which is not empty!");
 
103
        runtimeSP->message_length = strlen (runtimeSP->messageA);
 
104
        return ERROR_SAVE;
 
105
        }
 
106
 
 
107
/* Scan all atoms in the current complex: */
 
108
for (atomI = 0; atomI < atomsN; atomI++)
 
109
        {
 
110
        /** Pointer to the current atom: **/
 
111
        curr_atomSP = curr_mol_complexSP->atomSP + atomI;
 
112
 
 
113
        /** If only  selected  atoms  should be **/
 
114
        /** saved, check is this atom selected: **/
 
115
        if (selectionF)
 
116
                {
 
117
                if (curr_atomSP->selectedF == 0) continue;
 
118
                }
 
119
 
 
120
        /** Write data to output file: **/
 
121
        WriteLine_ (fileP, &curr_atomSP->raw_atomS);
 
122
        }
 
123
 
 
124
/* Close the output file: */
 
125
fclose (fileP);
 
126
 
 
127
/* Return the command code: */
 
128
return COMMAND_SAVE;
 
129
}
 
130
 
 
131
/*===========================================================================*/
 
132
 
 
133