~ubuntu-branches/debian/stretch/openbabel/stretch

« back to all changes in this revision

Viewing changes to src/residue.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michael Banck
  • Date: 2008-07-22 23:54:58 UTC
  • mfrom: (3.1.10 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080722235458-3o606czluviz4akx
Tags: 2.2.0-2
* Upload to unstable.
* debian/control: Updated descriptions.
* debian/patches/gauss_cube_format.patch: New patch, makes the 
  gaussian cube format available again.
* debian/rules (DEB_DH_MAKESHLIBS_ARGS_libopenbabel3): Removed.
* debian/rules (DEB_CONFIGURE_EXTRA_FLAGS): Likewise.
* debian/libopenbabel3.install: Adjust formats directory to single 
  version hierarchy.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
residue.cpp - Handle macromolecule residues.
3
3
 
4
4
Copyright (C) 2001, 2002  OpenEye Scientific Software, Inc.
5
 
Some portions Copyright (C) 2001-2005 by Geoffrey R. Hutchison
 
5
Some portions Copyright (C) 2001-2006 by Geoffrey R. Hutchison
6
6
 
7
7
This file is part of the Open Babel project.
8
8
For more information, see <http://openbabel.sourceforge.net/>
26
26
// File Includes
27
27
///////////////////////////////////////////////////////////////////////////////
28
28
 
29
 
#include "babelconfig.h"
30
 
 
31
 
#if HAVE_IOSTREAM
32
 
#include <iostream>
33
 
#elif HAVE_IOSTREAM_H
34
 
#include <iostream.h>
35
 
#endif
36
 
 
37
 
#if HAVE_FSTREAM
38
 
#include <fstream>
39
 
#elif HAVE_FSTREAM_H
40
 
#include <fstream.h>
41
 
#endif
42
 
 
43
 
#include "mol.h"
44
 
#include "bitvec.h"
 
29
#include <openbabel/babelconfig.h>
 
30
 
 
31
#include <openbabel/residue.h>
 
32
#include <openbabel/atom.h>
 
33
#include <openbabel/oberror.h>
 
34
#include <openbabel/bitvec.h>
 
35
#include <openbabel/bond.h>
 
36
#include <cstring>
 
37
#include <cstdlib>
45
38
 
46
39
using namespace std;
47
40
 
48
41
namespace OpenBabel
49
42
{
50
 
/** \class OBResidue
51
 
    \brief Residue information
 
43
   ////////////////////////////////////////////////////////////////////////////////
 
44
  // Global Variables
 
45
  ////////////////////////////////////////////////////////////////////////////////
 
46
 
 
47
  char Residue[MAXRES][4] = {
 
48
    /*===============*/
 
49
    /*  Amino Acids  */
 
50
    /*===============*/
 
51
 
 
52
    /* Ordered by Cumulative Frequency in Brookhaven *
 
53
     * Protein Databank, December 1991               */
 
54
 
 
55
    "ALA", /* 8.4% */     "GLY", /* 8.3% */
 
56
    "LEU", /* 8.0% */     "SER", /* 7.5% */
 
57
    "VAL", /* 7.1% */     "THR", /* 6.4% */
 
58
    "LYS", /* 5.8% */     "ASP", /* 5.5% */
 
59
    "ILE", /* 5.2% */     "ASN", /* 4.9% */
 
60
    "GLU", /* 4.9% */     "PRO", /* 4.4% */
 
61
    "ARG", /* 3.8% */     "PHE", /* 3.7% */
 
62
    "GLN", /* 3.5% */     "TYR", /* 3.5% */
 
63
    "HIS", /* 2.3% */     "CYS", /* 2.0% */
 
64
    "MET", /* 1.8% */     "TRP", /* 1.4% */
 
65
 
 
66
    "ASX", "GLX", "PCA", "HYP",
 
67
 
 
68
    /*===================*/
 
69
    /*  DNA Nucleotides  */
 
70
    /*===================*/
 
71
    "  A", "  C", "  G", "  T",
 
72
 
 
73
    /*===================*/
 
74
    /*  RNA Nucleotides  */
 
75
    /*===================*/
 
76
    "  U", " +U", "  I", "1MA",
 
77
    "5MC", "OMC", "1MG", "2MG",
 
78
    "M2G", "7MG", "OMG", " YG",
 
79
    "H2U", "5MU", "PSU",
 
80
 
 
81
    /*=================*/
 
82
    /*  Miscellaneous  */
 
83
    /*=================*/
 
84
    "UNK", "ACE", "FOR", "HOH",
 
85
    "DOD", "SO4", "PO4", "NAD",
 
86
    "COA", "NAP", "NDP"
 
87
  };
 
88
 
 
89
  /* Avoid SGI Compiler Warnings! */
 
90
  char ElemDesc[MAXELEM][4] = {
 
91
    { ' ', 'N', ' ', ' ' },  /* 0*/
 
92
    { ' ', 'C', 'A', ' ' },  /* 1*/
 
93
    { ' ', 'C', ' ', ' ' },  /* 2*/
 
94
    { ' ', 'O', ' ', ' ' },  /* 3*/   /* 0-3   Amino Acid Backbone    */
 
95
    { ' ', 'C', '\'', ' ' }, /* 4*/
 
96
    { ' ', 'O', 'T', ' ' },  /* 5*/
 
97
    { ' ', 'S', ' ', ' ' },  /* 6*/
 
98
    { ' ', 'P', ' ', ' ' },  /* 7*/   /* 4-7   Shapely Amino Backbone */
 
99
    { ' ', 'O', '1', 'P' },  /* 8*/
 
100
    { ' ', 'O', '2', 'P' },  /* 9*/
 
101
    { ' ', 'O', '5', '*' },  /*10*/
 
102
    { ' ', 'C', '5', '*' },  /*11*/
 
103
    { ' ', 'C', '4', '*' },  /*12*/
 
104
    { ' ', 'O', '4', '*' },  /*13*/
 
105
    { ' ', 'C', '3', '*' },  /*14*/
 
106
    { ' ', 'O', '3', '*' },  /*15*/
 
107
    { ' ', 'C', '2', '*' },  /*16*/
 
108
    { ' ', 'O', '2', '*' },  /*17*/
 
109
    { ' ', 'C', '1', '*' },  /*18*/   /* 7-18  Nucleic Acid Backbone  */
 
110
    { ' ', 'C', 'A', '2' },  /*19*/   /* 19    Shapely Special        */
 
111
    { ' ', 'S', 'G', ' ' },  /*20*/   /* 20    Cysteine Sulphur       */
 
112
    { ' ', 'N', '1', ' ' },  /*21*/
 
113
    { ' ', 'N', '2', ' ' },  /*22*/
 
114
    { ' ', 'N', '3', ' ' },  /*23*/
 
115
    { ' ', 'N', '4', ' ' },  /*24*/
 
116
    { ' ', 'N', '6', ' ' },  /*25*/
 
117
    { ' ', 'O', '2', ' ' },  /*26*/
 
118
    { ' ', 'O', '4', ' ' },  /*27*/
 
119
    { ' ', 'O', '6', ' ' }   /*28*/   /* 21-28 Nucleic Acid H-Bonding */
 
120
  };
 
121
 
 
122
  unsigned int ResNo  = MINRES;
 
123
  unsigned int ElemNo = MINELEM;
 
124
 
 
125
 /** \class OBResidue residue.h <openbabel/residue.h>
 
126
      \brief Residue information
52
127
 
53
 
    The residue information is drawn from PDB or MOL2 files (or similar), which
54
 
    track biomolecule information,
55
 
    and are stored in the OBResidue class. OBResidues are stored inside the 
56
 
    OBAtom class and OBMol classes. 
57
 
    The residue information for an atom can be requested in 
58
 
    the following way:
59
 
\code
60
 
 OBAtom *atom;
61
 
 OBResidue *r;
62
 
 atom = mol.GetAtom(1);
63
 
 r = atom->GetResidue();
64
 
\endcode
65
 
    The residue information for a molecule can be manipulated too:
66
 
\code
67
 
  cout << "This molecule has " << mol.NumResidues() << " residues." << endl;
68
 
  OBResidue *r;
69
 
  r = mol.GetResidue(1);
70
 
\endcode
71
 
*/
72
 
 
73
 
///////////////////////////////////////////////////////////////////////////////
74
 
// Global Definitions
75
 
///////////////////////////////////////////////////////////////////////////////
76
 
 
77
 
#define MAXSETNO 40
78
 
#define MAXELEM  1024
79
 
#define MINELEM  29
80
 
#define MAXRES   100
81
 
#define MINRES   54
82
 
 
83
 
///////////////////////////////////////////////////////////////////////////////
84
 
// Amino Acid Definitions
85
 
///////////////////////////////////////////////////////////////////////////////
86
 
 
87
 
#define AA_ALA (1<<1)
88
 
#define AA_GLY (1<<2)
89
 
#define AA_LEU (1<<3)
90
 
#define AA_SER (1<<4)
91
 
#define AA_VAL (1<<5)
92
 
#define AA_THR (1<<6)
93
 
#define AA_LYS (1<<7)
94
 
#define AA_ASP (1<<8)
95
 
#define AA_ILE (1<<9)
96
 
#define AA_ASN (1<<10)
97
 
#define AA_GLU (1<<11)
98
 
#define AA_PRO (1<<12)
99
 
#define AA_ARG (1<<13)
100
 
#define AA_PHE (1<<14)
101
 
#define AA_GLN (1<<15)
102
 
#define AA_TYR (1<<16)
103
 
#define AA_HIS (1<<17)
104
 
#define AA_CYS (1<<18)
105
 
#define AA_MET (1<<19)
106
 
#define AA_TRP (1<<20)
107
 
 
108
 
//! Residue property definitions
109
 
namespace OBAminoAcidProperty
110
 
{
111
 
static const unsigned int ACIDIC      =  0;
112
 
static const unsigned int ACYCLIC     =  1;
113
 
static const unsigned int ALIPHATIC   =  2;
114
 
static const unsigned int AROMATIC    =  3;
115
 
static const unsigned int BASIC       =  4;
116
 
static const unsigned int BURIED      =  5;
117
 
static const unsigned int CHARGED     =  6;
118
 
static const unsigned int CYCLIC      =  7;
119
 
static const unsigned int HYDROPHOBIC =  8;
120
 
static const unsigned int LARGE       =  9;
121
 
static const unsigned int MEDIUM      = 10;
122
 
static const unsigned int NEGATIVE    = 11;
123
 
static const unsigned int NEUTRAL     = 12;
124
 
static const unsigned int POLAR       = 13;
125
 
static const unsigned int POSITIVE    = 14;
126
 
static const unsigned int SMALL       = 15;
127
 
static const unsigned int SURFACE     = 16;
128
 
}
129
 
 
130
 
//! Residue atom properties
131
 
namespace OBResidueAtomProperty
132
 
{
133
 
static const unsigned int ALPHA_CARBON     = 0;
134
 
static const unsigned int AMINO_BACKBONE   = 1;
135
 
static const unsigned int BACKBONE         = 2;
136
 
static const unsigned int CYSTEINE_SULPHUR = 3;
137
 
static const unsigned int LIGAND           = 4;
138
 
static const unsigned int NUCLEIC_BACKBONE = 5;
139
 
static const unsigned int SHAPELY_BACKBONE = 6;
140
 
static const unsigned int SHAPELY_SPECIAL  = 7;
141
 
static const unsigned int SIDECHAIN        = 8;
142
 
static const unsigned int SUGAR_PHOSPHATE  = 9;
143
 
}
144
 
/// Residue names
145
 
namespace OBResidueIndex
146
 
{
147
 
static const unsigned int ALA   =  0;
148
 
static const unsigned int GLY   =  1;
149
 
static const unsigned int LEU   =  2;
150
 
static const unsigned int SER   =  3;
151
 
static const unsigned int VAL   =  4;
152
 
static const unsigned int THR   =  5;
153
 
static const unsigned int LYS   =  6;
154
 
static const unsigned int ASP   =  7;
155
 
static const unsigned int ILE   =  8;
156
 
static const unsigned int ASN   =  9;
157
 
static const unsigned int GLU   = 10;
158
 
static const unsigned int PRO   = 11;
159
 
static const unsigned int ARG   = 12;
160
 
static const unsigned int PHE   = 13;
161
 
static const unsigned int GLN   = 14;
162
 
static const unsigned int TYR   = 15;
163
 
static const unsigned int HIS   = 16;
164
 
static const unsigned int CYS   = 17;
165
 
static const unsigned int MET   = 18;
166
 
static const unsigned int TRP   = 19;
167
 
static const unsigned int ASX   = 20;
168
 
static const unsigned int GLX   = 21;
169
 
static const unsigned int PCA   = 22;
170
 
static const unsigned int HYP   = 23;
171
 
static const unsigned int A     = 24;
172
 
static const unsigned int C     = 25;
173
 
static const unsigned int G     = 26;
174
 
static const unsigned int T     = 27;
175
 
static const unsigned int U     = 28;
176
 
static const unsigned int UPLUS = 29;
177
 
static const unsigned int I     = 30;
178
 
//static const unsigned int _1MA  = 31;
179
 
//static const unsigned int _5MC  = 32;
180
 
static const unsigned int OMC   = 33;
181
 
//static const unsigned int _1MG  = 34;
182
 
//static const unsigned int _2MG  = 35;
183
 
static const unsigned int M2G   = 36;
184
 
//static const unsigned int _7MG  = 37;
185
 
static const unsigned int OMG   = 38;
186
 
static const unsigned int YG    = 39;
187
 
static const unsigned int H2U   = 40;
188
 
//static const unsigned int _5MU  = 41;
189
 
static const unsigned int PSU   = 42;
190
 
static const unsigned int UNK   = 43;
191
 
static const unsigned int ACE   = 44;
192
 
static const unsigned int FOR   = 45;
193
 
static const unsigned int HOH   = 46;
194
 
static const unsigned int DOD   = 47;
195
 
static const unsigned int SO4   = 48;
196
 
static const unsigned int PO4   = 49;
197
 
static const unsigned int NAD   = 50;
198
 
static const unsigned int COA   = 51;
199
 
static const unsigned int NAP   = 52;
200
 
static const unsigned int NDP   = 53;
201
 
}
202
 
/// Residue types.
203
 
namespace OBResidueProperty
204
 
{
205
 
static const unsigned int AMINO        = 0;
206
 
static const unsigned int AMINO_NUCLEO = 1;
207
 
static const unsigned int COENZYME     = 2;
208
 
static const unsigned int ION          = 3;
209
 
static const unsigned int NUCLEO       = 4;
210
 
static const unsigned int PROTEIN      = 5;
211
 
static const unsigned int PURINE       = 6;
212
 
static const unsigned int PYRIMIDINE   = 7;
213
 
static const unsigned int SOLVENT      = 8;
214
 
static const unsigned int WATER        = 9;
215
 
}
216
 
 
217
 
///////////////////////////////////////////////////////////////////////////////
218
 
// Amino Acid Property Definitions
219
 
///////////////////////////////////////////////////////////////////////////////
220
 
 
221
 
#define IS_ACIDIC(x)      ((x) & ((AA_ASP)|(AA_GLU)))
222
 
#define IS_ACYCLIC(x)     ((x) & ((AA_ALA)|(AA_GLY)|(AA_LEU)|(AA_SER)| \
223
 
                                  (AA_VAL)|(AA_THR)|(AA_LYS)|(AA_ASP)| \
224
 
                                  (AA_ILE)|(AA_ASN)|(AA_GLU)|(AA_GLN)| \
225
 
                                  (AA_CYS)|(AA_MET)))
226
 
#define IS_ALIPHATIC(x)   ((x) & ((AA_ALA)|(AA_GLY)|(AA_ILE)|(AA_LEU)| \
227
 
                                  (AA_VAL)))
228
 
#define IS_AROMATIC(x)    ((x) & ((AA_HIS)|(AA_PHE)|(AA_TRP)|(AA_TYR)))
229
 
#define IS_BASIC(x)       ((x) & ((AA_ARG)|(AA_HIS)|(AA_LYS)))
230
 
#define IS_BURIED(x)      ((x) & ((AA_ALA)|(AA_CYS)|(AA_ILE)|(AA_LEU)| \
231
 
                                  (AA_MET)|(AA_PHE)|(AA_TRP)|(AA_VAL)))
232
 
#define IS_CHARGED(x)     ((x) & ((AA_ASP)|(AA_GLU)|(AA_ARG)|(AA_HIS)| \
233
 
                                  (AA_LYS)))
234
 
#define IS_CYCLIC(x)      ((x) & ((AA_HIS)|(AA_PHE)|(AA_PRO)|(AA_TRP)| \
235
 
                                  (AA_TYR)))
236
 
#define IS_HYDROPHOBIC(x) ((x) & ((AA_ALA)|(AA_LEU)|(AA_VAL)|(AA_ILE)| \
237
 
                                  (AA_PRO)|(AA_PHE)|(AA_MET)|(AA_TRP)))
238
 
#define IS_LARGE(x)       ((x) & ((AA_ARG)|(AA_PHE)|(AA_GLN)|(AA_TYR)| \
239
 
                                  (AA_HIS)|(AA_LEU)|(AA_LYS)|(AA_ILE)| \
240
 
                                  (AA_GLU)|(AA_MET)|(AA_TRP)))
241
 
#define IS_MEDIUM(x)      ((x) & ((AA_VAL)|(AA_THR)|(AA_ASP)|(AA_ASN)| \
242
 
                                  (AA_PRO)|(AA_CYS)))
243
 
#define IS_NEGATIVE(x)    ((x) & ((AA_ASP)|(AA_GLU)))
244
 
#define IS_NEUTRAL(x)     ((x) & ((AA_ALA)|(AA_GLY)|(AA_LEU)|(AA_SER)| \
245
 
                                  (AA_VAL)|(AA_THR)|(AA_PHE)|(AA_GLN)| \
246
 
                                  (AA_TYR)|(AA_HIS)|(AA_CYS)|(AA_MET)| \
247
 
                                  (AA_TRP)|(AA_ILE)|(AA_ASN)|(AA_PRO)))
248
 
#define IS_POLAR(x)       ((x) & ((AA_ASP)|(AA_ILE)|(AA_ASN)|(AA_GLU)| \
249
 
                                  (AA_SER)|(AA_THR)|(AA_ARG)|(AA_GLN)| \
250
 
                                  (AA_CYS)|(AA_HIS)))
251
 
#define IS_POSITIVE(x)    ((x) & ((AA_ARG)|(AA_HIS)|(AA_LYS)))
252
 
#define IS_SMALL(x)       ((x) & ((AA_ALA)|(AA_GLY)|(AA_SER)))
253
 
#define IS_SURFACE(x)     ((x) & ((AA_THR)|(AA_LYS)|(AA_ASP)|(AA_ILE)| \
254
 
                                  (AA_ASN)|(AA_GLU)|(AA_PRO)|(AA_ARG)| \
255
 
                                  (AA_GLY)|(AA_SER)|(AA_GLN)|(AA_TYR)| \
256
 
                                  (AA_HIS)))
257
 
 
258
 
////////////////////////////////////////////////////////////////////////////////
259
 
// Global Variables
260
 
////////////////////////////////////////////////////////////////////////////////
261
 
 
262
 
static char Residue[MAXRES][4] = {
263
 
                                     /*===============*/
264
 
                                     /*  Amino Acids  */
265
 
                                     /*===============*/
266
 
 
267
 
                                     /* Ordered by Cumulative Frequency in Brookhaven *
268
 
                                      * Protein Databank, December 1991               */
269
 
 
270
 
                                     "ALA", /* 8.4% */     "GLY", /* 8.3% */
271
 
                                     "LEU", /* 8.0% */     "SER", /* 7.5% */
272
 
                                     "VAL", /* 7.1% */     "THR", /* 6.4% */
273
 
                                     "LYS", /* 5.8% */     "ASP", /* 5.5% */
274
 
                                     "ILE", /* 5.2% */     "ASN", /* 4.9% */
275
 
                                     "GLU", /* 4.9% */     "PRO", /* 4.4% */
276
 
                                     "ARG", /* 3.8% */     "PHE", /* 3.7% */
277
 
                                     "GLN", /* 3.5% */     "TYR", /* 3.5% */
278
 
                                     "HIS", /* 2.3% */     "CYS", /* 2.0% */
279
 
                                     "MET", /* 1.8% */     "TRP", /* 1.4% */
280
 
 
281
 
                                     "ASX", "GLX", "PCA", "HYP",
282
 
 
283
 
                                     /*===================*/
284
 
                                     /*  DNA Nucleotides  */
285
 
                                     /*===================*/
286
 
                                     "  A", "  C", "  G", "  T",
287
 
 
288
 
                                     /*===================*/
289
 
                                     /*  RNA Nucleotides  */
290
 
                                     /*===================*/
291
 
                                     "  U", " +U", "  I", "1MA",
292
 
                                     "5MC", "OMC", "1MG", "2MG",
293
 
                                     "M2G", "7MG", "OMG", " YG",
294
 
                                     "H2U", "5MU", "PSU",
295
 
 
296
 
                                     /*=================*/
297
 
                                     /*  Miscellaneous  */
298
 
                                     /*=================*/
299
 
                                     "UNK", "ACE", "FOR", "HOH",
300
 
                                     "DOD", "SO4", "PO4", "NAD",
301
 
                                     "COA", "NAP", "NDP"
302
 
                                 };
303
 
 
304
 
/* Avoid SGI Compiler Warnings! */
305
 
static char ElemDesc[MAXELEM][4] = {
306
 
                                       { ' ', 'N', ' ', ' ' },  /* 0*/
307
 
                                       { ' ', 'C', 'A', ' ' },  /* 1*/
308
 
                                       { ' ', 'C', ' ', ' ' },  /* 2*/
309
 
                                       { ' ', 'O', ' ', ' ' },  /* 3*/   /* 0-3   Amino Acid Backbone    */
310
 
                                       { ' ', 'C', '\'', ' ' }, /* 4*/
311
 
                                       { ' ', 'O', 'T', ' ' },  /* 5*/
312
 
                                       { ' ', 'S', ' ', ' ' },  /* 6*/
313
 
                                       { ' ', 'P', ' ', ' ' },  /* 7*/   /* 4-7   Shapely Amino Backbone */
314
 
                                       { ' ', 'O', '1', 'P' },  /* 8*/
315
 
                                       { ' ', 'O', '2', 'P' },  /* 9*/
316
 
                                       { ' ', 'O', '5', '*' },  /*10*/
317
 
                                       { ' ', 'C', '5', '*' },  /*11*/
318
 
                                       { ' ', 'C', '4', '*' },  /*12*/
319
 
                                       { ' ', 'O', '4', '*' },  /*13*/
320
 
                                       { ' ', 'C', '3', '*' },  /*14*/
321
 
                                       { ' ', 'O', '3', '*' },  /*15*/
322
 
                                       { ' ', 'C', '2', '*' },  /*16*/
323
 
                                       { ' ', 'O', '2', '*' },  /*17*/
324
 
                                       { ' ', 'C', '1', '*' },  /*18*/   /* 7-18  Nucleic Acid Backbone  */
325
 
                                       { ' ', 'C', 'A', '2' },  /*19*/   /* 19    Shapely Special        */
326
 
                                       { ' ', 'S', 'G', ' ' },  /*20*/   /* 20    Cysteine Sulphur       */
327
 
                                       { ' ', 'N', '1', ' ' },  /*21*/
328
 
                                       { ' ', 'N', '2', ' ' },  /*22*/
329
 
                                       { ' ', 'N', '3', ' ' },  /*23*/
330
 
                                       { ' ', 'N', '4', ' ' },  /*24*/
331
 
                                       { ' ', 'N', '6', ' ' },  /*25*/
332
 
                                       { ' ', 'O', '2', ' ' },  /*26*/
333
 
                                       { ' ', 'O', '4', ' ' },  /*27*/
334
 
                                       { ' ', 'O', '6', ' ' }   /*28*/   /* 21-28 Nucleic Acid H-Bonding */
335
 
                                   };
336
 
 
337
 
static unsigned int ResNo  = MINRES;
338
 
static unsigned int ElemNo = MINELEM;
339
 
 
340
 
///////////////////////////////////////////////////////////////////////////////
341
 
// Residue Functions
342
 
///////////////////////////////////////////////////////////////////////////////
343
 
 
344
 
static unsigned int GetAtomIDNumber(const char *atomid)
345
 
{
 
128
      The residue information is drawn from PDB or MOL2 files (or similar), which
 
129
      track biomolecule information,
 
130
      and are stored in the OBResidue class. OBResidues are stored inside the 
 
131
      OBAtom class and OBMol classes. 
 
132
      The residue information for an atom can be requested in 
 
133
      the following way:
 
134
      \code
 
135
      OBAtom *atom;
 
136
      OBResidue *r;
 
137
      atom = mol.GetAtom(1);
 
138
      r = atom->GetResidue();
 
139
      \endcode
 
140
      The residue information for a molecule can be manipulated too:
 
141
      \code
 
142
      cout << "This molecule has " << mol.NumResidues() << " residues." << endl;
 
143
      OBResidue *r;
 
144
      r = mol.GetResidue(1);
 
145
      \endcode
 
146
  */
 
147
 
 
148
  ///////////////////////////////////////////////////////////////////////////////
 
149
  // Residue Functions
 
150
  ///////////////////////////////////////////////////////////////////////////////
 
151
 
 
152
  static unsigned int GetAtomIDNumber(const char *atomid)
 
153
  {
346
154
    if (atomid != NULL)
347
 
    {
 
155
      {
348
156
        int ch1 = toupper(atomid[0]);
349
157
        int ch2 = toupper(atomid[1]);
350
158
        int ch3 = toupper(atomid[2]);
351
159
        int ch4 = toupper(atomid[3]);
352
160
 
353
161
        if (ch1 == ' ')
354
 
        {
 
162
          {
355
163
            switch(ch2)
356
 
            {
357
 
            case 'C':
 
164
              {
 
165
              case 'C':
358
166
 
359
167
                switch(ch3)
360
 
                {
361
 
                case 'A':
 
168
                  {
 
169
                  case 'A':
362
170
 
363
171
                    if (ch4 == ' ')
364
 
                        return 1;
 
172
                      return 1;
365
173
                    else if (ch4 == '2')
366
 
                        return 19;
367
 
 
368
 
                    break;
369
 
 
370
 
                case ' ':
371
 
                    if (ch4 == ' ')
372
 
                        return 2;
373
 
                    break;
374
 
 
375
 
                case '\'':
376
 
                    if (ch4 == ' ')
377
 
                        return 4;
378
 
                    break;
379
 
 
380
 
                case '1':
381
 
                    if (ch4 == '*')
382
 
                        return 18;
383
 
                    break;
384
 
 
385
 
                case '2':
386
 
                    if (ch4 == '*')
387
 
                        return 16;
388
 
                    break;
389
 
 
390
 
                case '3':
391
 
                    if (ch4 == '*')
392
 
                        return 14;
393
 
                    break;
394
 
 
395
 
                case '4':
396
 
                    if (ch4 == '*')
397
 
                        return 12;
398
 
                    break;
399
 
 
400
 
                case '5':
401
 
                    if (ch4 == '*')
402
 
                        return 11;
403
 
                    break;
404
 
 
405
 
                }
 
174
                      return 19;
 
175
 
 
176
                    break;
 
177
 
 
178
                  case ' ':
 
179
                    if (ch4 == ' ')
 
180
                      return 2;
 
181
                    break;
 
182
 
 
183
                  case '\'':
 
184
                    if (ch4 == ' ')
 
185
                      return 4;
 
186
                    break;
 
187
 
 
188
                  case '1':
 
189
                    if (ch4 == '*')
 
190
                      return 18;
 
191
                    break;
 
192
 
 
193
                  case '2':
 
194
                    if (ch4 == '*')
 
195
                      return 16;
 
196
                    break;
 
197
 
 
198
                  case '3':
 
199
                    if (ch4 == '*')
 
200
                      return 14;
 
201
                    break;
 
202
 
 
203
                  case '4':
 
204
                    if (ch4 == '*')
 
205
                      return 12;
 
206
                    break;
 
207
 
 
208
                  case '5':
 
209
                    if (ch4 == '*')
 
210
                      return 11;
 
211
                    break;
 
212
 
 
213
                  }
406
214
 
407
215
                break;
408
216
 
409
 
            case 'N':
 
217
              case 'N':
410
218
 
411
219
                if (ch4 == ' ')
412
 
                {
 
220
                  {
413
221
                    switch (ch3)
414
 
                    {
415
 
                    case ' ':
 
222
                      {
 
223
                      case ' ':
416
224
                        return 0;
417
 
                    case '1':
 
225
                      case '1':
418
226
                        return 21;
419
 
                    case '2':
 
227
                      case '2':
420
228
                        return 22;
421
 
                    case '3':
 
229
                      case '3':
422
230
                        return 23;
423
 
                    case '4':
 
231
                      case '4':
424
232
                        return 24;
425
 
                    case '6':
 
233
                      case '6':
426
234
                        return 25;
427
 
                    }
428
 
                }
 
235
                      }
 
236
                  }
429
237
 
430
238
                break;
431
239
 
432
 
            case 'O':
 
240
              case 'O':
433
241
 
434
242
                switch(ch3)
435
 
                {
436
 
                case ' ':
437
 
 
438
 
                    if (ch4 == ' ')
439
 
                        return 3;
440
 
 
441
 
                    break;
442
 
 
443
 
                case 'T':
444
 
 
445
 
                    if (ch4 == ' ')
446
 
                        return 5;
447
 
 
448
 
                    break;
449
 
 
450
 
                case '1':
451
 
 
452
 
                    if (ch4 == 'P')
453
 
                        return 8;
454
 
 
455
 
                    break;
456
 
 
457
 
                case '2':
458
 
 
459
 
                    if (ch4 == 'P')
460
 
                        return 9;
 
243
                  {
 
244
                  case ' ':
 
245
 
 
246
                    if (ch4 == ' ')
 
247
                      return 3;
 
248
 
 
249
                    break;
 
250
 
 
251
                  case 'T':
 
252
 
 
253
                    if (ch4 == ' ')
 
254
                      return 5;
 
255
 
 
256
                    break;
 
257
 
 
258
                  case '1':
 
259
 
 
260
                    if (ch4 == 'P')
 
261
                      return 8;
 
262
 
 
263
                    break;
 
264
 
 
265
                  case '2':
 
266
 
 
267
                    if (ch4 == 'P')
 
268
                      return 9;
461
269
                    else if (ch4 == '*')
462
 
                        return 17;
463
 
                    else if (ch4 == ' ')
464
 
                        return 26;
465
 
 
466
 
                    break;
467
 
 
468
 
                case '3':
469
 
 
470
 
                    if (ch4 == '*')
471
 
                        return 15;
472
 
 
473
 
                    break;
474
 
 
475
 
                case '4':
476
 
 
477
 
                    if (ch4 == '*')
478
 
                        return 13;
479
 
                    else if (ch4 == ' ')
480
 
                        return 27;
481
 
 
482
 
                    break;
483
 
 
484
 
                case '5':
485
 
 
486
 
                    if (ch4 == '*')
487
 
                        return 10;
488
 
 
489
 
                    break;
490
 
 
491
 
                case '6':
 
270
                      return 17;
 
271
                    else if (ch4 == ' ')
 
272
                      return 26;
 
273
 
 
274
                    break;
 
275
 
 
276
                  case '3':
 
277
 
 
278
                    if (ch4 == '*')
 
279
                      return 15;
 
280
 
 
281
                    break;
 
282
 
 
283
                  case '4':
 
284
 
 
285
                    if (ch4 == '*')
 
286
                      return 13;
 
287
                    else if (ch4 == ' ')
 
288
                      return 27;
 
289
 
 
290
                    break;
 
291
 
 
292
                  case '5':
 
293
 
 
294
                    if (ch4 == '*')
 
295
                      return 10;
 
296
 
 
297
                    break;
 
298
 
 
299
                  case '6':
492
300
 
493
301
                    if (ch4 == ' ')
494
 
                        return 28;
 
302
                      return 28;
495
303
 
496
304
                    break;
497
 
                }
 
305
                  }
498
306
 
499
307
                break;
500
308
 
501
 
            case 'P':
 
309
              case 'P':
502
310
 
503
311
                if ((ch3 == ' ') && (ch4 == ' '))
504
 
                    return 7;
 
312
                  return 7;
505
313
 
506
314
                break;
507
315
 
508
 
            case 'S':
 
316
              case 'S':
509
317
 
510
318
                if (ch4 == ' ')
511
 
                {
 
319
                  {
512
320
                    if (ch3 == ' ')
513
 
                        return 6;
 
321
                      return 6;
514
322
                    else if (ch3 == 'G')
515
 
                        return 20;
516
 
                }
 
323
                      return 20;
 
324
                  }
517
325
 
518
326
                break;
519
 
            }
520
 
        }
 
327
              }
 
328
          }
521
329
 
522
330
        unsigned int refno;
523
331
        for( refno = MINELEM ; refno < ElemNo ; refno++ )
524
 
            if( !strncmp(ElemDesc[refno], atomid, 4) )
525
 
                return refno;
 
332
          if( !strncmp(ElemDesc[refno], atomid, 4) )
 
333
            return refno;
526
334
 
527
335
        if ( ElemNo < MAXELEM - 1 )
528
 
        {
 
336
          {
529
337
            ElemNo++;
530
338
            ElemDesc[refno][0] = (char) ch1;
531
339
            ElemDesc[refno][1] = (char) ch2;
532
340
            ElemDesc[refno][2] = (char) ch3;
533
341
            ElemDesc[refno][3] = (char) ch4;
534
342
            return refno;
535
 
        }
 
343
          }
536
344
        else
537
 
        {
538
 
          obErrorLog.ThrowError(__FUNCTION__, "Maximum number of atom ids exceeded", obWarning);
539
 
          return 0;
540
 
        }
541
 
    }
 
345
          {
 
346
            obErrorLog.ThrowError(__FUNCTION__, "Maximum number of atom ids exceeded", obWarning);
 
347
            return 0;
 
348
          }
 
349
      }
542
350
    else
543
 
    {
544
 
      obErrorLog.ThrowError(__FUNCTION__, "NULL Atom IDs specified", obWarning);
545
 
      return 0;
546
 
    }
547
 
}
 
351
      {
 
352
        obErrorLog.ThrowError(__FUNCTION__, "NULL Atom IDs specified", obWarning);
 
353
        return 0;
 
354
      }
 
355
  }
548
356
 
549
 
static unsigned int GetResidueNumber(const char *res)
550
 
{
551
 
    if (res != NULL)
552
 
    {
 
357
  static unsigned int GetResidueNumber(const char *res)
 
358
  {
 
359
    if (res != NULL && strlen(res) > 2)
 
360
      {
553
361
        int ch1 = toupper(res[0]);
554
362
        int ch2 = toupper(res[1]);
555
363
        int ch3 = toupper(res[2]);
556
364
 
557
365
        switch( ch1 )
558
 
        {
559
 
        case(' '):
560
 
 
561
 
                        if( ch2 == ' ' )
562
 
                {
563
 
                    switch( ch3 )
564
 
                    {
565
 
                    case('A'):  return( 24 );
566
 
                    case('C'):  return( 25 );
567
 
                    case('G'):  return( 26 );
568
 
                    case('T'):  return( 27 );
569
 
                    case('U'):  return( 28 );
570
 
                    case('I'):  return( 30 );
571
 
                    }
572
 
                }
573
 
                else if( ch2 == '+' )
574
 
                {
575
 
                    if( ch3 == 'U' )
576
 
                        return( 29 );
577
 
                }
578
 
                else if( ch2 == 'Y' )
579
 
                {
580
 
                    if( ch3 == 'G' )
581
 
                        return( 39 );
582
 
                }
583
 
 
584
 
            break;
585
 
 
586
 
        case('0'):
587
 
 
588
 
                        if( ch2 == 'M' )
589
 
                {
590
 
                    if( ch3 == 'C' )
591
 
                        return( 33 );
592
 
                    else if( ch3 == 'G' )
593
 
                        return( 38 );
594
 
                }
595
 
 
596
 
            break;
597
 
 
598
 
        case('1'):
599
 
 
600
 
                        if( ch2 == 'M' )
601
 
                {
602
 
                    if( ch3 == 'A' )
603
 
                        return( 31 );
604
 
                    else if( ch3 == 'G' )
605
 
                        return( 34 );
606
 
                }
607
 
 
608
 
            break;
609
 
 
610
 
        case('2'):
611
 
 
612
 
                        if( ch2 == 'M' )
613
 
                            if( ch3 == 'G' )
614
 
                                return( 35 );
615
 
 
616
 
            break;
617
 
 
618
 
        case('5'):
619
 
 
620
 
                        if( ch2 == 'M' )
621
 
                {
622
 
                    if( ch3 == 'C' )
623
 
                        return( 32 );
624
 
                    else if( ch3 == 'U' )
625
 
                        return( 41 );
626
 
                }
627
 
 
628
 
            break;
629
 
 
630
 
        case('7'):
631
 
 
632
 
                        if( ch2 == 'M' )
633
 
                            if( ch3 == 'G' )
634
 
                                return( 37 );
635
 
 
636
 
            break;
637
 
 
638
 
        case('A'):
639
 
 
640
 
                        if( ch2 == 'L' )
641
 
                {
642
 
                    if( ch3 == 'A' )
643
 
                        return(  0 );
644
 
                }
645
 
                else if( ch2 == 'S' )
646
 
                {
647
 
                    if( ch3 == 'P' )
648
 
                        return(  7 );
649
 
                    else if( ch3 == 'N' )
650
 
                        return(  9 );
651
 
                    else if( ch3 == 'X' )
652
 
                        return( 20 );
653
 
                }
654
 
                else if( ch2 == 'R' )
655
 
                {
656
 
                    if( ch3 == 'G' )
657
 
                        return( 12 );
658
 
                }
659
 
                else if( ch2 == 'C' )
660
 
                {
661
 
                    if( ch3 == 'E' )
662
 
                        return( 44 );
663
 
                }
664
 
                else if( ch2 == 'D' )
665
 
                {
666
 
                    if( ch3 == 'E' )
667
 
                        return( 24 );    /* "ADE" -> "  A" */
668
 
                }
669
 
 
670
 
            break;
671
 
 
672
 
        case('C'):
673
 
 
674
 
                        if( ch2 == 'Y' )
675
 
                {
676
 
                    if( ch3 == 'S' )
677
 
                        return( 17 );
678
 
                    else if( ch3 == 'H' )
679
 
                        return( 17 );    /* "CYH" -> "CYS" */
680
 
                    else if( ch3 == 'T' )
681
 
                        return( 25 );    /* "CYT" -> "  C" */
682
 
                }
683
 
                else if( ch2 == 'O' )
684
 
                {
685
 
                    if( ch3 == 'A' )
686
 
                        return( 51 );
687
 
                }
688
 
                else if( ch2 == 'P' )
689
 
                {
690
 
                    if( ch3 == 'R' )
691
 
                        return( 11 );    /* "CPR" -> "PRO" */
692
 
                }
693
 
                else if( ch2 == 'S' )
694
 
                {
695
 
                    if( ch3 == 'H' )
696
 
                        return( 17 );    /* "CSH" -> "CYS" */
697
 
                    else if( ch3 == 'M' )
698
 
                        return( 17 );    /* "CSM" -> "CYS" */
699
 
                }
700
 
 
701
 
            break;
702
 
 
703
 
        case('D'):
704
 
 
705
 
                        if( ch2 == 'O' )
706
 
                {
707
 
                    if( ch3 == 'D' )
708
 
                        return( 47 );
709
 
                }
710
 
                else if( ch2 == '2' )
711
 
                {
712
 
                    if( ch3 == 'O' )
713
 
                        return( 47 );    /* "D2O" -> "DOD" */
714
 
                }
715
 
 
716
 
            break;
717
 
 
718
 
        case('F'):
719
 
 
720
 
                        if( ch2 == 'O' )
721
 
                            if( ch3 == 'R' )
722
 
                                return( 45 );
723
 
 
724
 
            break;
725
 
 
726
 
        case('G'):
727
 
 
728
 
                        if( ch2 == 'L' )
729
 
                {
730
 
                    if( ch3 == 'Y' )
731
 
                        return(  1 );
732
 
                    else if( ch3 == 'U' )
733
 
                        return( 10 );
734
 
                    else if( ch3 == 'N' )
735
 
                        return( 14 );
736
 
                    else if( ch3 == 'X' )
737
 
                        return( 21 );
738
 
                }
739
 
                else if( ch2 == 'U' )
740
 
                {
741
 
                    if( ch3 == 'A' )
742
 
                        return( 26 );    /* "GUA" -> "  G" */
743
 
                }
744
 
 
745
 
            break;
746
 
 
747
 
        case('H'):
748
 
 
749
 
                        if( ch2 == 'I' )
750
 
                {
751
 
                    if( ch3 == 'S' )
752
 
                        return( 16 );
753
 
                }
754
 
                else if( ch2 == 'O' )
755
 
                {
756
 
                    if( ch3 == 'H' )
757
 
                        return( 46 );
758
 
                }
759
 
                else if( ch2 == 'Y' )
760
 
                {
761
 
                    if( ch3 == 'P' )
762
 
                        return( 23 );
763
 
                }
764
 
                else if( ch2 == '2' )
765
 
                {
766
 
                    if( ch3 == 'O' )
767
 
                        return( 46 );    /* "H20" -> "HOH" */
768
 
                    else if( ch3 == 'U' )
769
 
                        return( 40 );
770
 
                }
771
 
 
772
 
            break;
773
 
 
774
 
        case('I'):
775
 
 
776
 
                        if( ch2 == 'L' )
777
 
                            if( ch3 == 'E' )
778
 
                                return(  8 );
779
 
 
780
 
            break;
781
 
 
782
 
        case('L'):
783
 
 
784
 
                        if( ch2 == 'E' )
785
 
                {
786
 
                    if( ch3 == 'U' )
787
 
                        return(  2 );
788
 
                }
789
 
                else if( ch2 == 'Y' )
790
 
                {
791
 
                    if( ch3 == 'S' )
792
 
                        return(  6 );
793
 
                }
794
 
 
795
 
            break;
796
 
 
797
 
        case('M'):
798
 
 
799
 
                        if( ch2 == 'E' )
800
 
                {
801
 
                    if( ch3 == 'T' )
802
 
                        return( 18 );
803
 
                }
804
 
                else if( ch2 == '2' )
805
 
                {
806
 
                    if( ch3 == 'G' )
807
 
                        return( 36 );
808
 
                }
809
 
 
810
 
            break;
811
 
 
812
 
        case('N'):
813
 
 
814
 
                        if( ch2 == 'A' )
815
 
                {
816
 
                    if( ch3 == 'D' )
817
 
                        return( 50 );
818
 
                    else if( ch3 == 'P' )
819
 
                        return( 52 );
820
 
                }
821
 
                else if( ch2 == 'D' )
822
 
                {
823
 
                    if( ch3 == 'P' )
824
 
                        return( 53 );
825
 
                }
826
 
 
827
 
            break;
828
 
 
829
 
        case('P'):
830
 
 
831
 
                        if( ch2 == 'R' )
832
 
                {
833
 
                    if( ch3 == 'O' )
834
 
                        return( 11 );
835
 
                }
836
 
                else if( ch2 == 'H' )
837
 
                {
838
 
                    if( ch3 == 'E' )
839
 
                        return( 13 );
840
 
                }
841
 
                else if( ch2 == 'C' )
842
 
                {
843
 
                    if( ch3 == 'A' )
844
 
                        return( 22 );
845
 
                }
846
 
                else if( ch2 == 'O' )
847
 
                {
848
 
                    if( ch3 == '4' )
849
 
                        return( 49 );
850
 
                }
851
 
                else if( ch2 == 'S' )
852
 
                {
853
 
                    if( ch3 == 'U' )
854
 
                        return( 42 );
855
 
                }
856
 
 
857
 
            break;
858
 
 
859
 
        case('S'):
860
 
 
861
 
                        if( ch2 == 'E' )
862
 
                {
863
 
                    if( ch3 == 'R' )
864
 
                        return(  3 );
865
 
                }
866
 
                else if( ch2 == 'O' )
867
 
                {
868
 
                    if( ch3 == '4' )
869
 
                        return( 48 );
870
 
                    else if( ch3 == 'L' )
871
 
                        return( 46 );    /* "SOL" -> "HOH" */
872
 
                }
873
 
                else if( ch2 == 'U' )
874
 
                {
875
 
                    if( ch3 == 'L' )
876
 
                        return( 48 );    /* "SUL" -> "SO4" */
877
 
                }
878
 
 
879
 
            break;
880
 
 
881
 
        case('T'):
882
 
 
883
 
                        if( ch2 == 'H' )
884
 
                {
885
 
                    if( ch3 == 'R' )
886
 
                        return(  5 );
887
 
                    else if( ch3 == 'Y' )
888
 
                        return( 27 );    /* "THY" -> "  T" */
889
 
                }
890
 
                else if( ch2 == 'Y' )
891
 
                {
892
 
                    if( ch3 == 'R' )
893
 
                        return( 15 );
894
 
                }
895
 
                else if( ch2 == 'R' )
896
 
                {
897
 
                    if( ch3 == 'P' )
898
 
                        return( 19 );
899
 
                    else if( ch3 == 'Y' )
900
 
                        return( 19 );    /* "TRY" -> "TRP" */
901
 
                }
902
 
                else if( ch2 == 'I' )
903
 
                {
904
 
                    if( ch3 == 'P' )
905
 
                        return( 46 );    /* "TIP" -> "HOH" */
906
 
                }
907
 
 
908
 
            break;
909
 
 
910
 
        case('U'):
911
 
 
912
 
                        if( ch2 == 'N' )
913
 
                {
914
 
                    if( ch3 == 'K' )
915
 
                        return( 43 );
916
 
                }
917
 
                else if( ch2 == 'R' )
918
 
                {
919
 
                    if( ch3 == 'A' )
920
 
                        return( 28 );    /* "URA" -> "  U" */
921
 
                    else if( ch3 == 'I' )
922
 
                        return( 28 );    /* "URI" -> "  U" */
923
 
                }
924
 
 
925
 
            break;
926
 
 
927
 
        case('V'):
928
 
 
929
 
                        if( ch2 == 'A' )
930
 
                            if( ch3 == 'L' )
931
 
                                return(  4 );
932
 
 
933
 
            break;
934
 
 
935
 
        case('W'):
936
 
 
937
 
                        if( ch2 == 'A' )
938
 
                            if( ch3 == 'T' )
939
 
                                return( 46 );    /* "WAT" -> "HOH" */
940
 
 
941
 
            break;
942
 
        }
 
366
          {
 
367
          case(' '):
 
368
 
 
369
            if( ch2 == ' ' )
 
370
              {
 
371
                switch( ch3 )
 
372
                  {
 
373
                  case('A'):  return( 24 );
 
374
                  case('C'):  return( 25 );
 
375
                  case('G'):  return( 26 );
 
376
                  case('T'):  return( 27 );
 
377
                  case('U'):  return( 28 );
 
378
                  case('I'):  return( 30 );
 
379
                  }
 
380
              }
 
381
            else if( ch2 == '+' )
 
382
              {
 
383
                if( ch3 == 'U' )
 
384
                  return( 29 );
 
385
              }
 
386
            else if( ch2 == 'Y' )
 
387
              {
 
388
                if( ch3 == 'G' )
 
389
                  return( 39 );
 
390
              }
 
391
 
 
392
            break;
 
393
 
 
394
          case('0'):
 
395
 
 
396
            if( ch2 == 'M' )
 
397
              {
 
398
                if( ch3 == 'C' )
 
399
                  return( 33 );
 
400
                else if( ch3 == 'G' )
 
401
                  return( 38 );
 
402
              }
 
403
 
 
404
            break;
 
405
 
 
406
          case('1'):
 
407
 
 
408
            if( ch2 == 'M' )
 
409
              {
 
410
                if( ch3 == 'A' )
 
411
                  return( 31 );
 
412
                else if( ch3 == 'G' )
 
413
                  return( 34 );
 
414
              }
 
415
 
 
416
            break;
 
417
 
 
418
          case('2'):
 
419
 
 
420
            if( ch2 == 'M' )
 
421
              if( ch3 == 'G' )
 
422
                return( 35 );
 
423
 
 
424
            break;
 
425
 
 
426
          case('5'):
 
427
 
 
428
            if( ch2 == 'M' )
 
429
              {
 
430
                if( ch3 == 'C' )
 
431
                  return( 32 );
 
432
                else if( ch3 == 'U' )
 
433
                  return( 41 );
 
434
              }
 
435
 
 
436
            break;
 
437
 
 
438
          case('7'):
 
439
 
 
440
            if( ch2 == 'M' )
 
441
              if( ch3 == 'G' )
 
442
                return( 37 );
 
443
 
 
444
            break;
 
445
 
 
446
          case('A'):
 
447
 
 
448
            if( ch2 == 'L' )
 
449
              {
 
450
                if( ch3 == 'A' )
 
451
                  return(  0 );
 
452
              }
 
453
            else if( ch2 == 'S' )
 
454
              {
 
455
                if( ch3 == 'P' )
 
456
                  return(  7 );
 
457
                else if( ch3 == 'N' )
 
458
                  return(  9 );
 
459
                else if( ch3 == 'X' )
 
460
                  return( 20 );
 
461
              }
 
462
            else if( ch2 == 'R' )
 
463
              {
 
464
                if( ch3 == 'G' )
 
465
                  return( 12 );
 
466
              }
 
467
            else if( ch2 == 'C' )
 
468
              {
 
469
                if( ch3 == 'E' )
 
470
                  return( 44 );
 
471
              }
 
472
            else if( ch2 == 'D' )
 
473
              {
 
474
                if( ch3 == 'E' )
 
475
                  return( 24 );    /* "ADE" -> "  A" */
 
476
              }
 
477
 
 
478
            break;
 
479
 
 
480
          case('C'):
 
481
 
 
482
            if( ch2 == 'Y' )
 
483
              {
 
484
                if( ch3 == 'S' )
 
485
                  return( 17 );
 
486
                else if( ch3 == 'H' )
 
487
                  return( 17 );    /* "CYH" -> "CYS" */
 
488
                else if( ch3 == 'T' )
 
489
                  return( 25 );    /* "CYT" -> "  C" */
 
490
              }
 
491
            else if( ch2 == 'O' )
 
492
              {
 
493
                if( ch3 == 'A' )
 
494
                  return( 51 );
 
495
              }
 
496
            else if( ch2 == 'P' )
 
497
              {
 
498
                if( ch3 == 'R' )
 
499
                  return( 11 );    /* "CPR" -> "PRO" */
 
500
              }
 
501
            else if( ch2 == 'S' )
 
502
              {
 
503
                if( ch3 == 'H' )
 
504
                  return( 17 );    /* "CSH" -> "CYS" */
 
505
                else if( ch3 == 'M' )
 
506
                  return( 17 );    /* "CSM" -> "CYS" */
 
507
              }
 
508
 
 
509
            break;
 
510
 
 
511
          case('D'):
 
512
 
 
513
            if( ch2 == 'O' )
 
514
              {
 
515
                if( ch3 == 'D' )
 
516
                  return( 47 );
 
517
              }
 
518
            else if( ch2 == '2' )
 
519
              {
 
520
                if( ch3 == 'O' )
 
521
                  return( 47 );    /* "D2O" -> "DOD" */
 
522
              }
 
523
 
 
524
            break;
 
525
 
 
526
          case('F'):
 
527
 
 
528
            if( ch2 == 'O' )
 
529
              if( ch3 == 'R' )
 
530
                return( 45 );
 
531
 
 
532
            break;
 
533
 
 
534
          case('G'):
 
535
 
 
536
            if( ch2 == 'L' )
 
537
              {
 
538
                if( ch3 == 'Y' )
 
539
                  return(  1 );
 
540
                else if( ch3 == 'U' )
 
541
                  return( 10 );
 
542
                else if( ch3 == 'N' )
 
543
                  return( 14 );
 
544
                else if( ch3 == 'X' )
 
545
                  return( 21 );
 
546
              }
 
547
            else if( ch2 == 'U' )
 
548
              {
 
549
                if( ch3 == 'A' )
 
550
                  return( 26 );    /* "GUA" -> "  G" */
 
551
              }
 
552
 
 
553
            break;
 
554
 
 
555
          case('H'):
 
556
 
 
557
            if( ch2 == 'I' )
 
558
              {
 
559
                if( ch3 == 'S' )
 
560
                  return( 16 );
 
561
              }
 
562
            else if( ch2 == 'O' )
 
563
              {
 
564
                if( ch3 == 'H' )
 
565
                  return( 46 );
 
566
              }
 
567
            else if( ch2 == 'Y' )
 
568
              {
 
569
                if( ch3 == 'P' )
 
570
                  return( 23 );
 
571
              }
 
572
            else if( ch2 == '2' )
 
573
              {
 
574
                if( ch3 == 'O' )
 
575
                  return( 46 );    /* "H20" -> "HOH" */
 
576
                else if( ch3 == 'U' )
 
577
                  return( 40 );
 
578
              }
 
579
 
 
580
            break;
 
581
 
 
582
          case('I'):
 
583
 
 
584
            if( ch2 == 'L' )
 
585
              if( ch3 == 'E' )
 
586
                return(  8 );
 
587
 
 
588
            break;
 
589
 
 
590
          case('L'):
 
591
 
 
592
            if( ch2 == 'E' )
 
593
              {
 
594
                if( ch3 == 'U' )
 
595
                  return(  2 );
 
596
              }
 
597
            else if( ch2 == 'Y' )
 
598
              {
 
599
                if( ch3 == 'S' )
 
600
                  return(  6 );
 
601
              }
 
602
 
 
603
            break;
 
604
 
 
605
          case('M'):
 
606
 
 
607
            if( ch2 == 'E' )
 
608
              {
 
609
                if( ch3 == 'T' )
 
610
                  return( 18 );
 
611
              }
 
612
            else if( ch2 == '2' )
 
613
              {
 
614
                if( ch3 == 'G' )
 
615
                  return( 36 );
 
616
              }
 
617
 
 
618
            break;
 
619
 
 
620
          case('N'):
 
621
 
 
622
            if( ch2 == 'A' )
 
623
              {
 
624
                if( ch3 == 'D' )
 
625
                  return( 50 );
 
626
                else if( ch3 == 'P' )
 
627
                  return( 52 );
 
628
              }
 
629
            else if( ch2 == 'D' )
 
630
              {
 
631
                if( ch3 == 'P' )
 
632
                  return( 53 );
 
633
              }
 
634
 
 
635
            break;
 
636
 
 
637
          case('P'):
 
638
 
 
639
            if( ch2 == 'R' )
 
640
              {
 
641
                if( ch3 == 'O' )
 
642
                  return( 11 );
 
643
              }
 
644
            else if( ch2 == 'H' )
 
645
              {
 
646
                if( ch3 == 'E' )
 
647
                  return( 13 );
 
648
              }
 
649
            else if( ch2 == 'C' )
 
650
              {
 
651
                if( ch3 == 'A' )
 
652
                  return( 22 );
 
653
              }
 
654
            else if( ch2 == 'O' )
 
655
              {
 
656
                if( ch3 == '4' )
 
657
                  return( 49 );
 
658
              }
 
659
            else if( ch2 == 'S' )
 
660
              {
 
661
                if( ch3 == 'U' )
 
662
                  return( 42 );
 
663
              }
 
664
 
 
665
            break;
 
666
 
 
667
          case('S'):
 
668
 
 
669
            if( ch2 == 'E' )
 
670
              {
 
671
                if( ch3 == 'R' )
 
672
                  return(  3 );
 
673
              }
 
674
            else if( ch2 == 'O' )
 
675
              {
 
676
                if( ch3 == '4' )
 
677
                  return( 48 );
 
678
                else if( ch3 == 'L' )
 
679
                  return( 46 );    /* "SOL" -> "HOH" */
 
680
              }
 
681
            else if( ch2 == 'U' )
 
682
              {
 
683
                if( ch3 == 'L' )
 
684
                  return( 48 );    /* "SUL" -> "SO4" */
 
685
              }
 
686
 
 
687
            break;
 
688
 
 
689
          case('T'):
 
690
 
 
691
            if( ch2 == 'H' )
 
692
              {
 
693
                if( ch3 == 'R' )
 
694
                  return(  5 );
 
695
                else if( ch3 == 'Y' )
 
696
                  return( 27 );    /* "THY" -> "  T" */
 
697
              }
 
698
            else if( ch2 == 'Y' )
 
699
              {
 
700
                if( ch3 == 'R' )
 
701
                  return( 15 );
 
702
              }
 
703
            else if( ch2 == 'R' )
 
704
              {
 
705
                if( ch3 == 'P' )
 
706
                  return( 19 );
 
707
                else if( ch3 == 'Y' )
 
708
                  return( 19 );    /* "TRY" -> "TRP" */
 
709
              }
 
710
            else if( ch2 == 'I' )
 
711
              {
 
712
                if( ch3 == 'P' )
 
713
                  return( 46 );    /* "TIP" -> "HOH" */
 
714
              }
 
715
 
 
716
            break;
 
717
 
 
718
          case('U'):
 
719
 
 
720
            if( ch2 == 'N' )
 
721
              {
 
722
                if( ch3 == 'K' )
 
723
                  return( 43 );
 
724
              }
 
725
            else if( ch2 == 'R' )
 
726
              {
 
727
                if( ch3 == 'A' )
 
728
                  return( 28 );    /* "URA" -> "  U" */
 
729
                else if( ch3 == 'I' )
 
730
                  return( 28 );    /* "URI" -> "  U" */
 
731
              }
 
732
 
 
733
            break;
 
734
 
 
735
          case('V'):
 
736
 
 
737
            if( ch2 == 'A' )
 
738
              if( ch3 == 'L' )
 
739
                return(  4 );
 
740
 
 
741
            break;
 
742
 
 
743
          case('W'):
 
744
 
 
745
            if( ch2 == 'A' )
 
746
              if( ch3 == 'T' )
 
747
                return( 46 );    /* "WAT" -> "HOH" */
 
748
 
 
749
            break;
 
750
          }
943
751
 
944
752
        unsigned int refno;
945
753
        for( refno = MINRES; refno < ResNo ; refno++ )
946
 
            if( !strncmp(Residue[refno],res,3) )
947
 
                return refno;
 
754
          if( !strncmp(Residue[refno],res,3) )
 
755
            return refno;
948
756
 
949
757
        if ( ResNo < MAXRES - 1 )
950
 
{
 
758
          {
951
759
            ResNo++;
952
760
            Residue[refno][0] = (char) ch1;
953
761
            Residue[refno][1] = (char) ch2;
954
762
            Residue[refno][2] = (char) ch3;
955
763
            return refno;
956
 
        }
957
 
    }
 
764
          }
 
765
      }
958
766
 
959
767
    return OBResidueIndex::UNK;
960
 
}
 
768
  }
961
769
 
962
 
static void SetResidueKeys(const char   *residue,
963
 
                           unsigned int &reskey,
964
 
                           unsigned int &aakey)
965
 
{
 
770
  static void SetResidueKeys(const char   *residue,
 
771
                             unsigned int &reskey,
 
772
                             unsigned int &aakey)
 
773
  {
966
774
    reskey = GetResidueNumber(residue);
967
775
    switch(reskey)
968
 
    {
969
 
    case OBResidueIndex::ALA:
 
776
      {
 
777
      case OBResidueIndex::ALA:
970
778
        aakey = AA_ALA;
971
779
        break;
972
 
    case OBResidueIndex::GLY:
 
780
      case OBResidueIndex::GLY:
973
781
        aakey = AA_GLY;
974
782
        break;
975
 
    case OBResidueIndex::LEU:
 
783
      case OBResidueIndex::LEU:
976
784
        aakey = AA_LEU;
977
785
        break;
978
 
    case OBResidueIndex::SER:
 
786
      case OBResidueIndex::SER:
979
787
        aakey = AA_SER;
980
788
        break;
981
 
    case OBResidueIndex::VAL:
 
789
      case OBResidueIndex::VAL:
982
790
        aakey = AA_VAL;
983
791
        break;
984
 
    case OBResidueIndex::THR:
 
792
      case OBResidueIndex::THR:
985
793
        aakey = AA_THR;
986
794
        break;
987
 
    case OBResidueIndex::LYS:
 
795
      case OBResidueIndex::LYS:
988
796
        aakey = AA_LYS;
989
797
        break;
990
 
    case OBResidueIndex::ASP:
 
798
      case OBResidueIndex::ASP:
991
799
        aakey = AA_ASP;
992
800
        break;
993
 
    case OBResidueIndex::ILE:
 
801
      case OBResidueIndex::ILE:
994
802
        aakey = AA_ILE;
995
803
        break;
996
 
    case OBResidueIndex::ASN:
 
804
      case OBResidueIndex::ASN:
997
805
        aakey = AA_ASN;
998
806
        break;
999
 
    case OBResidueIndex::GLU:
 
807
      case OBResidueIndex::GLU:
1000
808
        aakey = AA_GLU;
1001
809
        break;
1002
 
    case OBResidueIndex::PRO:
 
810
      case OBResidueIndex::PRO:
1003
811
        aakey = AA_PRO;
1004
812
        break;
1005
 
    case OBResidueIndex::ARG:
 
813
      case OBResidueIndex::ARG:
1006
814
        aakey = AA_ARG;
1007
815
        break;
1008
 
    case OBResidueIndex::PHE:
 
816
      case OBResidueIndex::PHE:
1009
817
        aakey = AA_PHE;
1010
818
        break;
1011
 
    case OBResidueIndex::GLN:
 
819
      case OBResidueIndex::GLN:
1012
820
        aakey = AA_GLN;
1013
821
        break;
1014
 
    case OBResidueIndex::TYR:
 
822
      case OBResidueIndex::TYR:
1015
823
        aakey = AA_TYR;
1016
824
        break;
1017
 
    case OBResidueIndex::HIS:
 
825
      case OBResidueIndex::HIS:
1018
826
        aakey = AA_HIS;
1019
827
        break;
1020
 
    case OBResidueIndex::CYS:
 
828
      case OBResidueIndex::CYS:
1021
829
        aakey = AA_CYS;
1022
830
        break;
1023
 
    case OBResidueIndex::MET:
 
831
      case OBResidueIndex::MET:
1024
832
        aakey = AA_MET;
1025
833
        break;
1026
 
    case OBResidueIndex::TRP:
 
834
      case OBResidueIndex::TRP:
1027
835
        aakey = AA_TRP;
1028
836
        break;
1029
 
    default:
 
837
      default:
1030
838
        aakey = 0;
1031
839
        break;
1032
 
    }
1033
 
}
1034
 
 
1035
 
///////////////////////////////////////////////////////////////////////////////
1036
 
// OBResidue: Constructors / Destructor
1037
 
///////////////////////////////////////////////////////////////////////////////
1038
 
 
1039
 
OBResidue::OBResidue()
1040
 
{
 
840
      }
 
841
  }
 
842
 
 
843
  ///////////////////////////////////////////////////////////////////////////////
 
844
  // OBResidue: Constructors / Destructor
 
845
  ///////////////////////////////////////////////////////////////////////////////
 
846
 
 
847
  OBResidue::OBResidue()
 
848
  {
1041
849
    _chain    = 'A';
1042
850
    _idx      = 0;
1043
851
    _aakey    = 0;
1044
852
    _reskey   = OBResidueIndex::UNK;
1045
 
    _resnum   = 0;
 
853
    _resnum   = "";
1046
854
    _resname  = "";
1047
855
    _vdata.clear();
1048
 
}
1049
 
 
1050
 
OBResidue::OBResidue(const OBResidue &src)
1051
 
// Currently does not copy vdata information
1052
 
{
 
856
 
 
857
  }
 
858
 
 
859
  OBResidue::OBResidue(const OBResidue &src) :
 
860
    OBBase()
 
861
  {
1053
862
    _chain    = src._chain;
1054
863
    _aakey    = src._aakey;
1055
864
    _reskey   = src._reskey;
1058
867
    _atomid   = src._atomid;
1059
868
    _hetatm   = src._hetatm;
1060
869
    _sernum   = src._sernum;
1061
 
}
1062
 
 
1063
 
OBResidue::~OBResidue()
1064
 
{
 
870
 
 
871
  }
 
872
 
 
873
  OBResidue::~OBResidue()
 
874
  {
1065
875
    vector<OBAtom*>::iterator a;
1066
876
    for ( a = _atoms.begin() ; a != _atoms.end() ; a++ )
1067
 
        (*a)->SetResidue(NULL);
 
877
      (*a)->SetResidue(NULL);
1068
878
    _atoms.clear();
1069
 
    if (!_vdata.empty())
1070
 
    {
1071
 
        vector<OBGenericData*>::iterator m;
1072
 
        for (m = _vdata.begin();m != _vdata.end();m++)
1073
 
            delete *m;
1074
 
        _vdata.clear();
1075
 
    }
1076
 
}
1077
 
 
1078
 
///////////////////////////////////////////////////////////////////////////////
1079
 
// OBResidue: Operator Overloads
1080
 
///////////////////////////////////////////////////////////////////////////////
1081
 
 
1082
 
OBResidue &OBResidue::operator = (const OBResidue &src)
1083
 
//copy residue information
1084
 
// Currently does not copy vdata informtion
1085
 
{
 
879
 
 
880
  }
 
881
 
 
882
  ///////////////////////////////////////////////////////////////////////////////
 
883
  // OBResidue: Operator Overloads
 
884
  ///////////////////////////////////////////////////////////////////////////////
 
885
 
 
886
  OBResidue &OBResidue::operator = (const OBResidue &src)
 
887
    //copy residue information
 
888
    // Currently does not copy vdata informtion
 
889
  {
1086
890
    if (this != &src)
1087
 
    {
 
891
      {
1088
892
        _chain    = src._chain;
1089
893
        _aakey    = src._aakey;
1090
894
        _reskey   = src._reskey;
1093
897
        _atomid   = src._atomid;
1094
898
        _hetatm   = src._hetatm;
1095
899
        _sernum   = src._sernum;
1096
 
    }
 
900
      }
1097
901
 
1098
902
    return(*this);
1099
 
}
1100
 
 
1101
 
///////////////////////////////////////////////////////////////////////////////
1102
 
// OBResidue: Data Access / Manipulation
1103
 
///////////////////////////////////////////////////////////////////////////////
1104
 
 
1105
 
void OBResidue::AddAtom(OBAtom *atom)
1106
 
{
1107
 
    if (atom != NULL)
1108
 
    {
1109
 
        atom->SetResidue(this);
1110
 
 
1111
 
        _atoms.push_back(atom);
1112
 
        _atomid.push_back("");
1113
 
        _hetatm.push_back(false);
1114
 
        _sernum.push_back(0);
1115
 
    }
1116
 
}
1117
 
 
1118
 
void OBResidue::InsertAtom(OBAtom *atom)
1119
 
{
1120
 
    if (atom != NULL)
1121
 
    {
1122
 
        atom->SetResidue(this);
1123
 
 
1124
 
        _atoms.push_back(atom);
1125
 
        _atomid.push_back("");
1126
 
        _hetatm.push_back(false);
1127
 
        _sernum.push_back(0);
1128
 
    }
1129
 
}
1130
 
 
1131
 
void OBResidue::RemoveAtom(OBAtom *atom)
1132
 
{
1133
 
    if (atom != NULL)
1134
 
    {
1135
 
        for ( unsigned int i = 0 ; i < _atoms.size() ; i++ )
1136
 
        {
1137
 
            if (_atoms[i] == atom)
1138
 
            {
 
903
  }
 
904
 
 
905
  ///////////////////////////////////////////////////////////////////////////////
 
906
  // OBResidue: Data Access / Manipulation
 
907
  ///////////////////////////////////////////////////////////////////////////////
 
908
 
 
909
  void OBResidue::AddAtom(OBAtom *atom)
 
910
  {
 
911
    if (atom != NULL)
 
912
      {
 
913
        atom->SetResidue(this);
 
914
 
 
915
        _atoms.push_back(atom);
 
916
        _atomid.push_back("");
 
917
        _hetatm.push_back(false);
 
918
        _sernum.push_back(0);
 
919
      }
 
920
  }
 
921
 
 
922
  void OBResidue::InsertAtom(OBAtom *atom)
 
923
  {
 
924
    AddAtom(atom);
 
925
  }
 
926
 
 
927
  void OBResidue::RemoveAtom(OBAtom *atom)
 
928
  {
 
929
    if (atom != NULL && _atoms.size())
 
930
      {
 
931
        for ( unsigned int i = 0 ; i < _atoms.size() ; ++i)
 
932
          {
 
933
            if (_atoms[i] != NULL && _atoms[i] == atom)
 
934
              {
1139
935
                atom->SetResidue(NULL);
1140
936
                _atoms.erase(_atoms.begin() + i);
1141
937
                _atomid.erase(_atomid.begin() + i);
1142
938
                _hetatm.erase(_hetatm.begin() + i);
1143
939
                _sernum.erase(_sernum.begin() + i);
1144
 
            }
1145
 
        }
1146
 
    }
1147
 
}
 
940
              }
 
941
          }
 
942
      }
 
943
  }
1148
944
 
1149
 
void OBResidue::Clear(void)
1150
 
{
1151
 
    for (unsigned int i = 0 ; i < _atoms.size() ; i++ )
1152
 
        _atoms[i]->SetResidue(NULL);
 
945
  bool OBResidue::Clear(void)
 
946
  {
 
947
    for (unsigned int i = 0 ; i < _atoms.size() ; ++i)
 
948
      _atoms[i]->SetResidue(NULL);
1153
949
 
1154
950
    _chain   = 'A';
1155
951
    _idx     = 0;
1156
952
    _aakey   = 0;
1157
953
    _reskey  = OBResidueIndex::UNK;
1158
 
    _resnum  = 0;
 
954
    _resnum  = "";
1159
955
    _resname = "";
1160
956
 
1161
957
    _atoms.clear();
1162
958
    _atomid.clear();
1163
959
    _hetatm.clear();
1164
960
    _sernum.clear();
1165
 
}
 
961
    
 
962
    return (OBBase::Clear());
 
963
  }
1166
964
 
1167
 
void OBResidue::SetChain(char chain)
1168
 
{
 
965
  void OBResidue::SetChain(char chain)
 
966
  {
1169
967
    _chain = chain;
1170
 
}
 
968
  }
1171
969
 
1172
 
void OBResidue::SetChainNum(unsigned int chainnum)
1173
 
{
 
970
  void OBResidue::SetChainNum(unsigned int chainnum)
 
971
  {
1174
972
    _chain = (char) ('A' + chainnum - 1);
1175
 
}
 
973
  }
1176
974
 
1177
 
void OBResidue::SetIdx(unsigned int idx)
1178
 
{
 
975
  void OBResidue::SetIdx(unsigned int idx)
 
976
  {
1179
977
    _idx = idx;
1180
 
}
 
978
  }
1181
979
 
1182
 
void OBResidue::SetName(const string &name)
1183
 
{
 
980
  void OBResidue::SetName(const string &name)
 
981
  {
1184
982
    _resname = name;
1185
983
    SetResidueKeys(_resname.c_str(), _reskey, _aakey);
1186
 
}
1187
 
 
1188
 
void OBResidue::SetNum(unsigned int resnum)
1189
 
{
 
984
  }
 
985
 
 
986
  void OBResidue::SetNum(const unsigned int resnum)
 
987
  {
 
988
    stringstream temp;
 
989
    temp << resnum;
 
990
    _resnum = temp.str();
 
991
  }
 
992
 
 
993
  void OBResidue::SetNum(const string resnum)
 
994
  {
1190
995
    _resnum = resnum;
1191
 
}
1192
 
 
1193
 
void OBResidue::SetAtomID(OBAtom *atom, const string &id)
1194
 
{
1195
 
    for ( unsigned int i = 0 ; i < _atoms.size() ; i++ )
1196
 
        if (_atoms[i] == atom)
1197
 
            _atomid[i] = id;
1198
 
}
1199
 
 
1200
 
void OBResidue::SetHetAtom(OBAtom *atom, bool hetatm)
1201
 
{
1202
 
    for ( unsigned int i = 0 ; i < _atoms.size() ; i++ )
1203
 
        if (_atoms[i] == atom)
1204
 
            _hetatm[i] = hetatm;
1205
 
}
1206
 
 
1207
 
void OBResidue::SetSerialNum(OBAtom *atom, unsigned int sernum)
1208
 
{
1209
 
    for ( unsigned int i = 0 ; i < _atoms.size() ; i++ )
1210
 
        if (_atoms[i] == atom)
1211
 
            _sernum[i] = sernum;
1212
 
}
1213
 
 
1214
 
vector<OBAtom*> OBResidue::GetAtoms(void) const
1215
 
{
 
996
  }
 
997
 
 
998
  void OBResidue::SetAtomID(OBAtom *atom, const string &id)
 
999
  {
 
1000
    for ( unsigned int i = 0 ; i < _atoms.size() ; ++i )
 
1001
      if (_atoms[i] == atom)
 
1002
        _atomid[i] = id;
 
1003
  }
 
1004
 
 
1005
  void OBResidue::SetHetAtom(OBAtom *atom, bool hetatm)
 
1006
  {
 
1007
    for ( unsigned int i = 0 ; i < _atoms.size() ; ++i )
 
1008
      if (_atoms[i] == atom)
 
1009
        _hetatm[i] = hetatm;
 
1010
  }
 
1011
 
 
1012
  void OBResidue::SetSerialNum(OBAtom *atom, unsigned int sernum)
 
1013
  {
 
1014
    for ( unsigned int i = 0 ; i < _atoms.size() ; ++i )
 
1015
      if (_atoms[i] == atom)
 
1016
        _sernum[i] = sernum;
 
1017
  }
 
1018
 
 
1019
  vector<OBAtom*> OBResidue::GetAtoms(void) const
 
1020
  {
1216
1021
    return _atoms;
1217
 
}
 
1022
  }
1218
1023
 
1219
 
vector<OBBond*> OBResidue::GetBonds(bool exterior) const
1220
 
{
 
1024
  vector<OBBond*> OBResidue::GetBonds(bool exterior) const
 
1025
  {
1221
1026
    OBAtom         *atom;
1222
1027
    vector<OBBond*> bonds;
1223
1028
    OBBitVec        idxs;
1224
1029
    unsigned int    sz;
1225
1030
 
1226
1031
    sz = (unsigned int) _atoms.size();
1227
 
    for ( unsigned int i = 0 ; i < sz ; i++ )
1228
 
    {
 
1032
    for ( unsigned int i = 0 ; i < sz ; ++i )
 
1033
      {
1229
1034
        atom = _atoms[i];
1230
1035
        OBBond *bond;
1231
 
        vector<OBEdgeBase*>::iterator b;
 
1036
        vector<OBBond*>::iterator b;
1232
1037
        for (bond = atom->BeginBond(b) ; bond ; bond = atom->NextBond(b))
1233
 
        {
 
1038
          {
1234
1039
            if (!idxs.BitIsOn(bond->GetIdx()))
1235
 
            {
 
1040
              {
1236
1041
                if (!exterior)
1237
 
                {
 
1042
                  {
1238
1043
                    if (bond->GetNbrAtom(atom)->GetResidue() == this)
1239
 
                        bonds.push_back(&(*bond));
1240
 
                }
 
1044
                      bonds.push_back(&(*bond));
 
1045
                  }
1241
1046
                else
1242
 
                    bonds.push_back(&(*bond));
 
1047
                  bonds.push_back(&(*bond));
1243
1048
 
1244
1049
                idxs.SetBitOn(bond->GetIdx());
1245
 
            }
1246
 
        }
1247
 
    }
 
1050
              }
 
1051
          }
 
1052
      }
1248
1053
 
1249
1054
    return bonds;
1250
 
}
 
1055
  }
1251
1056
 
1252
 
string OBResidue::GetName(void) const
1253
 
{
 
1057
  string OBResidue::GetName(void) const
 
1058
  {
1254
1059
    return _resname;
1255
 
}
 
1060
  }
1256
1061
 
1257
 
unsigned int OBResidue::GetNum(void) const
1258
 
{
 
1062
  std::string OBResidue::GetNumString(void)
 
1063
  {
1259
1064
    return _resnum;
1260
 
}
1261
 
 
1262
 
unsigned int OBResidue::GetNumAtoms(void) const
1263
 
{
 
1065
  }
 
1066
 
 
1067
  unsigned int OBResidue::GetNum(void) 
 
1068
  {
 
1069
    return atoi(_resnum.c_str());
 
1070
  }
 
1071
 
 
1072
  unsigned int OBResidue::GetNumAtoms(void) const
 
1073
  {
1264
1074
    return (unsigned int)_atoms.size();
1265
 
}
 
1075
  }
1266
1076
 
1267
 
char OBResidue::GetChain(void) const
1268
 
{
 
1077
  char OBResidue::GetChain(void) const
 
1078
  {
1269
1079
    return _chain;
1270
 
}
 
1080
  }
1271
1081
 
1272
 
unsigned int OBResidue::GetChainNum(void) const
1273
 
{
 
1082
  unsigned int OBResidue::GetChainNum(void) const
 
1083
  {
1274
1084
    if (isdigit(_chain))
1275
 
        return (_chain - '0');
 
1085
      return (_chain - '0');
1276
1086
    else
1277
 
        return (_chain - 'A' + 1);
1278
 
}
 
1087
      return (_chain - 'A' + 1);
 
1088
  }
1279
1089
 
1280
 
unsigned int OBResidue::GetIdx(void) const
1281
 
{
 
1090
  unsigned int OBResidue::GetIdx(void) const
 
1091
  {
1282
1092
    return(_idx);
1283
 
}
 
1093
  }
1284
1094
 
1285
 
unsigned int OBResidue::GetResKey(void) const
1286
 
{
 
1095
  unsigned int OBResidue::GetResKey(void) const
 
1096
  {
1287
1097
    return(_reskey);
1288
 
}
 
1098
  }
1289
1099
 
1290
 
string OBResidue::GetAtomID(OBAtom *atom) const
1291
 
{
1292
 
    for ( unsigned int i = 0 ; i < _atoms.size() ; i++ )
1293
 
        if (_atoms[i] == atom)
1294
 
            return _atomid[i];
 
1100
  string OBResidue::GetAtomID(OBAtom *atom) const
 
1101
  {
 
1102
    for ( unsigned int i = 0 ; i < _atoms.size() ; ++i )
 
1103
      if (_atoms[i] == atom)
 
1104
        return _atomid[i];
1295
1105
    return "";
1296
 
}
 
1106
  }
1297
1107
 
1298
 
unsigned int OBResidue::GetSerialNum(OBAtom *atom) const
1299
 
{
1300
 
    for ( unsigned int i = 0 ; i < _atoms.size() ; i++ )
1301
 
        if (_atoms[i] == atom)
1302
 
            return _sernum[i];
 
1108
  unsigned int OBResidue::GetSerialNum(OBAtom *atom) const
 
1109
  {
 
1110
    for ( unsigned int i = 0 ; i < _atoms.size() ; ++i )
 
1111
      if (_atoms[i] == atom)
 
1112
        return _sernum[i];
1303
1113
    return 0;
1304
 
}
 
1114
  }
1305
1115
 
1306
 
bool OBResidue::IsHetAtom(OBAtom *atom) const
1307
 
{
1308
 
    for ( unsigned int i = 0 ; i < _atoms.size() ; i++ )
1309
 
        if (_atoms[i] == atom)
1310
 
            return _hetatm[i];
 
1116
  bool OBResidue::IsHetAtom(OBAtom *atom) const
 
1117
  {
 
1118
    for ( unsigned int i = 0 ; i < _atoms.size() ; ++i )
 
1119
      if (_atoms[i] == atom)
 
1120
        return _hetatm[i];
1311
1121
    return false;
1312
 
}
1313
 
 
1314
 
///////////////////////////////////////////////////////////////////////////////
1315
 
// OBResidue: Iteration Utilities
1316
 
///////////////////////////////////////////////////////////////////////////////
1317
 
 
1318
 
OBAtom *OBResidue::BeginAtom(vector<OBAtom*>::iterator &i)
1319
 
{
 
1122
  }
 
1123
 
 
1124
  ///////////////////////////////////////////////////////////////////////////////
 
1125
  // OBResidue: Iteration Utilities
 
1126
  ///////////////////////////////////////////////////////////////////////////////
 
1127
 
 
1128
  OBAtom *OBResidue::BeginAtom(vector<OBAtom*>::iterator &i)
 
1129
  {
1320
1130
    i = _atoms.begin();
1321
1131
    return ((i == _atoms.end()) ? NULL : *i);
1322
 
}
 
1132
  }
1323
1133
 
1324
 
OBAtom *OBResidue::NextAtom(vector<OBAtom*>::iterator &i)
1325
 
{
1326
 
    i++;
 
1134
  OBAtom *OBResidue::NextAtom(vector<OBAtom*>::iterator &i)
 
1135
  {
 
1136
    ++i;
1327
1137
    return ((i == _atoms.end()) ? NULL : *i);
1328
 
}
1329
 
 
1330
 
///////////////////////////////////////////////////////////////////////////////
1331
 
// OBResidue: Information Functions
1332
 
///////////////////////////////////////////////////////////////////////////////
1333
 
 
1334
 
bool OBResidue::GetAminoAcidProperty(int property) const
1335
 
{
 
1138
  }
 
1139
 
 
1140
  ///////////////////////////////////////////////////////////////////////////////
 
1141
  // OBResidue: Information Functions
 
1142
  ///////////////////////////////////////////////////////////////////////////////
 
1143
 
 
1144
  bool OBResidue::GetAminoAcidProperty(int property) const
 
1145
  {
1336
1146
    switch(property)
1337
 
    {
1338
 
    case OBAminoAcidProperty::ACIDIC:
 
1147
      {
 
1148
      case OBAminoAcidProperty::ACIDIC:
1339
1149
        return IS_ACIDIC(_aakey)      != 0;
1340
 
    case OBAminoAcidProperty::ACYCLIC:
 
1150
      case OBAminoAcidProperty::ACYCLIC:
1341
1151
        return IS_ACYCLIC(_aakey)     != 0;
1342
 
    case OBAminoAcidProperty::ALIPHATIC:
 
1152
      case OBAminoAcidProperty::ALIPHATIC:
1343
1153
        return IS_ALIPHATIC(_aakey)   != 0;
1344
 
    case OBAminoAcidProperty::AROMATIC:
 
1154
      case OBAminoAcidProperty::AROMATIC:
1345
1155
        return IS_AROMATIC(_aakey)    != 0;
1346
 
    case OBAminoAcidProperty::BASIC:
 
1156
      case OBAminoAcidProperty::BASIC:
1347
1157
        return IS_BASIC(_aakey)       != 0;
1348
 
    case OBAminoAcidProperty::BURIED:
 
1158
      case OBAminoAcidProperty::BURIED:
1349
1159
        return IS_BURIED(_aakey)      != 0;
1350
 
    case OBAminoAcidProperty::CHARGED:
 
1160
      case OBAminoAcidProperty::CHARGED:
1351
1161
        return IS_CHARGED(_aakey)     != 0;
1352
 
    case OBAminoAcidProperty::CYCLIC:
 
1162
      case OBAminoAcidProperty::CYCLIC:
1353
1163
        return IS_CYCLIC(_aakey)      != 0;
1354
 
    case OBAminoAcidProperty::HYDROPHOBIC:
 
1164
      case OBAminoAcidProperty::HYDROPHOBIC:
1355
1165
        return IS_HYDROPHOBIC(_aakey) != 0;
1356
 
    case OBAminoAcidProperty::LARGE:
 
1166
      case OBAminoAcidProperty::LARGE:
1357
1167
        return IS_LARGE(_aakey)       != 0;
1358
 
    case OBAminoAcidProperty::MEDIUM:
 
1168
      case OBAminoAcidProperty::MEDIUM:
1359
1169
        return IS_MEDIUM(_aakey)      != 0;
1360
 
    case OBAminoAcidProperty::NEGATIVE:
 
1170
      case OBAminoAcidProperty::NEGATIVE:
1361
1171
        return IS_NEGATIVE(_aakey)    != 0;
1362
 
    case OBAminoAcidProperty::NEUTRAL:
 
1172
      case OBAminoAcidProperty::NEUTRAL:
1363
1173
        return IS_NEUTRAL(_aakey)     != 0;
1364
 
    case OBAminoAcidProperty::POLAR:
 
1174
      case OBAminoAcidProperty::POLAR:
1365
1175
        return IS_POLAR(_aakey)       != 0;
1366
 
    case OBAminoAcidProperty::POSITIVE:
 
1176
      case OBAminoAcidProperty::POSITIVE:
1367
1177
        return IS_POSITIVE(_aakey)    != 0;
1368
 
    case OBAminoAcidProperty::SMALL:
 
1178
      case OBAminoAcidProperty::SMALL:
1369
1179
        return IS_SMALL(_aakey)       != 0;
1370
 
    case OBAminoAcidProperty::SURFACE:
 
1180
      case OBAminoAcidProperty::SURFACE:
1371
1181
        return IS_SURFACE(_aakey)     != 0;
1372
 
    default:
 
1182
      default:
1373
1183
        return false;
1374
 
    }
1375
 
}
 
1184
      }
 
1185
  }
1376
1186
 
1377
 
bool OBResidue::GetAtomProperty(OBAtom *atom, int property) const
1378
 
{
 
1187
  bool OBResidue::GetAtomProperty(OBAtom *atom, int property) const
 
1188
  {
1379
1189
    if (atom != NULL)
1380
 
    {
 
1190
      {
1381
1191
        unsigned int atomid = GetAtomIDNumber(GetAtomID(atom).c_str());
1382
1192
 
1383
1193
        switch(property)
1384
 
        {
1385
 
        case OBResidueAtomProperty::ALPHA_CARBON:
 
1194
          {
 
1195
          case OBResidueAtomProperty::ALPHA_CARBON:
1386
1196
            return (atomid == 1);
1387
1197
 
1388
 
        case OBResidueAtomProperty::AMINO_BACKBONE:
 
1198
          case OBResidueAtomProperty::AMINO_BACKBONE:
1389
1199
            return (atomid <= 3);
1390
1200
 
1391
 
        case OBResidueAtomProperty::BACKBONE:
 
1201
          case OBResidueAtomProperty::BACKBONE:
1392
1202
            return (atomid <= 18);
1393
1203
 
1394
 
        case OBResidueAtomProperty::CYSTEINE_SULPHUR:
 
1204
          case OBResidueAtomProperty::CYSTEINE_SULPHUR:
1395
1205
            return (atomid == 20);
1396
1206
 
1397
 
        case OBResidueAtomProperty::LIGAND:
 
1207
          case OBResidueAtomProperty::LIGAND:
1398
1208
            return IsHetAtom(atom) &&
1399
 
                   !GetResidueProperty(OBResidueProperty::SOLVENT);
 
1209
              !GetResidueProperty(OBResidueProperty::SOLVENT);
1400
1210
 
1401
 
        case OBResidueAtomProperty::NUCLEIC_BACKBONE:
 
1211
          case OBResidueAtomProperty::NUCLEIC_BACKBONE:
1402
1212
            return ((atomid >= 7) && (atomid <= 18));
1403
1213
 
1404
 
        case OBResidueAtomProperty::SHAPELY_BACKBONE:
 
1214
          case OBResidueAtomProperty::SHAPELY_BACKBONE:
1405
1215
            return (atomid <= 7);
1406
1216
 
1407
 
        case OBResidueAtomProperty::SHAPELY_SPECIAL:
 
1217
          case OBResidueAtomProperty::SHAPELY_SPECIAL:
1408
1218
            return (atomid == 19);
1409
1219
 
1410
 
        case OBResidueAtomProperty::SIDECHAIN:
 
1220
          case OBResidueAtomProperty::SIDECHAIN:
1411
1221
            return GetResidueProperty(OBResidueProperty::AMINO_NUCLEO) &&
1412
 
                   (atomid > 18);
 
1222
              (atomid > 18);
1413
1223
 
1414
 
        case OBResidueAtomProperty::SUGAR_PHOSPHATE:
 
1224
          case OBResidueAtomProperty::SUGAR_PHOSPHATE:
1415
1225
            return (atomid == 7);
1416
 
        }
1417
 
    }
 
1226
          }
 
1227
      }
1418
1228
 
1419
1229
    return false;
1420
 
}
 
1230
  }
1421
1231
 
1422
 
bool OBResidue::GetResidueProperty(int property) const
1423
 
{
 
1232
  bool OBResidue::GetResidueProperty(int property) const
 
1233
  {
1424
1234
    switch(property)
1425
 
    {
1426
 
    case OBResidueProperty::AMINO:
 
1235
      {
 
1236
      case OBResidueProperty::AMINO:
1427
1237
        return (_reskey <= OBResidueIndex::HYP);
1428
1238
 
1429
 
    case OBResidueProperty::AMINO_NUCLEO:
 
1239
      case OBResidueProperty::AMINO_NUCLEO:
1430
1240
        return (_reskey <= OBResidueIndex::PSU);
1431
1241
 
1432
 
    case OBResidueProperty::COENZYME:
 
1242
      case OBResidueProperty::COENZYME:
1433
1243
        return (_reskey >= OBResidueIndex::NAD) &&
1434
 
               (_reskey <= OBResidueIndex::NDP);
 
1244
          (_reskey <= OBResidueIndex::NDP);
1435
1245
 
1436
 
    case OBResidueProperty::ION:
 
1246
      case OBResidueProperty::ION:
1437
1247
        return (_reskey == OBResidueIndex::SO4) ||
1438
 
               (_reskey == OBResidueIndex::PO4);
 
1248
          (_reskey == OBResidueIndex::PO4);
1439
1249
 
1440
 
    case OBResidueProperty::NUCLEO:
 
1250
      case OBResidueProperty::NUCLEO:
1441
1251
        return (_reskey >= OBResidueIndex::A) &&
1442
 
               (_reskey <= OBResidueIndex::PSU);
 
1252
          (_reskey <= OBResidueIndex::PSU);
1443
1253
 
1444
 
    case OBResidueProperty::PROTEIN:
 
1254
      case OBResidueProperty::PROTEIN:
1445
1255
        return (_reskey <= OBResidueIndex::HYP) ||
1446
 
               ((_reskey >= OBResidueIndex::UNK) &&
1447
 
                (_reskey <= OBResidueIndex::FOR));
 
1256
          ((_reskey >= OBResidueIndex::UNK) &&
 
1257
           (_reskey <= OBResidueIndex::FOR));
1448
1258
 
1449
 
    case OBResidueProperty::PURINE:
 
1259
      case OBResidueProperty::PURINE:
1450
1260
        return (_reskey == OBResidueIndex::A) ||
1451
 
               (_reskey == OBResidueIndex::G);
 
1261
          (_reskey == OBResidueIndex::G);
1452
1262
 
1453
 
    case OBResidueProperty::PYRIMIDINE:
 
1263
      case OBResidueProperty::PYRIMIDINE:
1454
1264
        return (_reskey == OBResidueIndex::C) ||
1455
 
               (_reskey == OBResidueIndex::T);
 
1265
          (_reskey == OBResidueIndex::T);
1456
1266
 
1457
 
    case OBResidueProperty::SOLVENT:
 
1267
      case OBResidueProperty::SOLVENT:
1458
1268
        return (_reskey >= OBResidueIndex::HOH) &&
1459
 
               (_reskey <= OBResidueIndex::PO4);
 
1269
          (_reskey <= OBResidueIndex::PO4);
1460
1270
 
1461
 
    case OBResidueProperty::WATER:
 
1271
      case OBResidueProperty::WATER:
1462
1272
        return (_reskey == OBResidueIndex::HOH) ||
1463
 
               (_reskey == OBResidueIndex::DOD);
 
1273
          (_reskey == OBResidueIndex::DOD);
1464
1274
 
1465
 
    default:
 
1275
      default:
1466
1276
        return false;
1467
 
    }
1468
 
}
 
1277
      }
 
1278
  }
1469
1279
 
1470
 
bool OBResidue::IsResidueType(int restype) const
1471
 
{
 
1280
  bool OBResidue::IsResidueType(int restype) const
 
1281
  {
1472
1282
    return ((int)_reskey == restype);
1473
 
}
1474
 
 
1475
 
// OBGenericData methods
1476
 
bool OBResidue::HasData(string &s)
1477
 
//returns true if the generic attribute/value pair exists
1478
 
{
1479
 
    if (_vdata.empty())
1480
 
        return(false);
1481
 
 
1482
 
    vector<OBGenericData*>::iterator i;
1483
 
 
1484
 
    for (i = _vdata.begin();i != _vdata.end();i++)
1485
 
        if ((*i)->GetAttribute() == s)
1486
 
            return(true);
1487
 
 
1488
 
    return(false);
1489
 
}
1490
 
 
1491
 
bool OBResidue::HasData(const char *s)
1492
 
//returns true if the generic attribute/value pair exists
1493
 
{
1494
 
    if (_vdata.empty())
1495
 
        return(false);
1496
 
 
1497
 
    vector<OBGenericData*>::iterator i;
1498
 
 
1499
 
    for (i = _vdata.begin();i != _vdata.end();i++)
1500
 
        if ((*i)->GetAttribute() == s)
1501
 
            return(true);
1502
 
 
1503
 
    return(false);
1504
 
}
1505
 
 
1506
 
bool OBResidue::HasData(unsigned int dt)
1507
 
//returns true if the generic attribute/value pair exists
1508
 
{
1509
 
    if (_vdata.empty())
1510
 
        return(false);
1511
 
 
1512
 
    vector<OBGenericData*>::iterator i;
1513
 
 
1514
 
    for (i = _vdata.begin();i != _vdata.end();i++)
1515
 
        if ((*i)->GetDataType() == dt)
1516
 
            return(true);
1517
 
 
1518
 
    return(false);
1519
 
}
1520
 
 
1521
 
OBGenericData *OBResidue::GetData(string &s)
1522
 
//returns the value given an attribute
1523
 
{
1524
 
    vector<OBGenericData*>::iterator i;
1525
 
 
1526
 
    for (i = _vdata.begin();i != _vdata.end();i++)
1527
 
        if ((*i)->GetAttribute() == s)
1528
 
            return(*i);
1529
 
 
1530
 
    return(NULL);
1531
 
}
1532
 
 
1533
 
OBGenericData *OBResidue::GetData(const char *s)
1534
 
//returns the value given an attribute
1535
 
{
1536
 
    vector<OBGenericData*>::iterator i;
1537
 
 
1538
 
    for (i = _vdata.begin();i != _vdata.end();i++)
1539
 
        if ((*i)->GetAttribute() == s)
1540
 
            return(*i);
1541
 
 
1542
 
    return(NULL);
1543
 
}
1544
 
 
1545
 
OBGenericData *OBResidue::GetData(unsigned int dt)
1546
 
{
1547
 
    vector<OBGenericData*>::iterator i;
1548
 
    for (i = _vdata.begin();i != _vdata.end();i++)
1549
 
        if ((*i)->GetDataType() == dt)
1550
 
            return(*i);
1551
 
    return(NULL);
1552
 
}
1553
 
 
1554
 
void OBResidue::DeleteData(unsigned int dt)
1555
 
{
1556
 
    vector<OBGenericData*> vdata;
1557
 
    vector<OBGenericData*>::iterator i;
1558
 
    for (i = _vdata.begin();i != _vdata.end();i++)
1559
 
        if ((*i)->GetDataType() == dt)
1560
 
            delete *i;
1561
 
        else
1562
 
            vdata.push_back(*i);
1563
 
    _vdata = vdata;
1564
 
}
1565
 
 
1566
 
void OBResidue::DeleteData(vector<OBGenericData*> &vg)
1567
 
{
1568
 
    vector<OBGenericData*> vdata;
1569
 
    vector<OBGenericData*>::iterator i,j;
1570
 
 
1571
 
    bool del;
1572
 
    for (i = _vdata.begin();i != _vdata.end();i++)
1573
 
    {
1574
 
        del = false;
1575
 
        for (j = vg.begin();j != vg.end();j++)
1576
 
            if (*i == *j)
1577
 
            {
1578
 
                del = true;
1579
 
                break;
1580
 
            }
1581
 
        if (del)
1582
 
            delete *i;
1583
 
        else
1584
 
            vdata.push_back(*i);
1585
 
    }
1586
 
    _vdata = vdata;
1587
 
}
1588
 
 
1589
 
void OBResidue::DeleteData(OBGenericData *gd)
1590
 
{
1591
 
    vector<OBGenericData*>::iterator i;
1592
 
    for (i = _vdata.begin();i != _vdata.end();i++)
1593
 
        if (*i == gd)
1594
 
        {
1595
 
            delete *i;
1596
 
            _vdata.erase(i);
1597
 
        }
1598
 
 
1599
 
}
 
1283
  }
1600
1284
 
1601
1285
} // end namespace OpenBabel
1602
1286