| 1 |
/********************************************************************** |
| 2 |
* Copyright (C) 2002-2003 by Gezelter's Group
|
| 3 |
*This program is free software; you can redistribute it and/or modify
|
| 4 |
*it under the terms of the GNU General Public License as published by
|
| 5 |
*the Free Software Foundation version 2 of the License.
|
| 6 |
*
|
| 7 |
*This program is distributed in the hope that it will be useful,
|
| 8 |
*but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 9 |
*MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 10 |
*GNU General Public License for more details.
|
| 11 |
*
|
| 12 |
************************************************************************ |
| 13 |
*Author: Teng Lin Email: tlin@nd.edu |
| 14 |
*Date: 08/13/2002 Version: 1.0 |
| 15 |
* |
| 16 |
************************************************************************ |
| 17 |
*Description: |
| 18 |
* |
| 19 |
***********************************************************************/ |
| 20 |
#include <algorithm> |
| 21 |
#include "fasresidue.h" |
| 22 |
#include "fasatom.h" |
| 23 |
#include "fasbond.h" |
| 24 |
#include "bitvector.h" |
| 25 |
|
| 26 |
//constuctor/destructor |
| 27 |
TFASResidue::TFASResidue() |
| 28 |
{ |
| 29 |
Clear(); |
| 30 |
} |
| 31 |
|
| 32 |
TFASResidue::TFASResidue(const unsigned int index) |
| 33 |
{ |
| 34 |
Clear(); |
| 35 |
|
| 36 |
_index = index; |
| 37 |
} |
| 38 |
|
| 39 |
TFASResidue::TFASResidue(const TFASResidue &residue) |
| 40 |
{ |
| 41 |
_index = residue._index; |
| 42 |
_resid = residue._resid; |
| 43 |
_model = residue._model; |
| 44 |
_mol = residue._mol; |
| 45 |
_atomList = residue._atomList; |
| 46 |
|
| 47 |
} |
| 48 |
|
| 49 |
TFASResidue::~TFASResidue() |
| 50 |
{ |
| 51 |
Clear(); |
| 52 |
} |
| 53 |
|
| 54 |
void TFASResidue::Clear() |
| 55 |
{ |
| 56 |
vector<TFASAtom *>::iterator i; |
| 57 |
TFASAtom *atom; |
| 58 |
for (atom=BeginAtom(i); atom!=NULL;atom=NextAtom(i)) |
| 59 |
{ |
| 60 |
atom->SetResidue(NULL); |
| 61 |
} |
| 62 |
|
| 63 |
_index = -1; |
| 64 |
_resid = -1; |
| 65 |
_mol = NULL; |
| 66 |
_model = NULL; |
| 67 |
_atomList.clear(); |
| 68 |
} |
| 69 |
|
| 70 |
//overload operator = |
| 71 |
TFASResidue &TFASResidue::operator =(const TFASResidue &residue) |
| 72 |
{ |
| 73 |
if (this != &residue) |
| 74 |
{ |
| 75 |
_index = residue._index; |
| 76 |
_resid = residue._resid; |
| 77 |
_model = residue._model; |
| 78 |
_mol = residue._mol; |
| 79 |
_atomList = residue._atomList; |
| 80 |
} |
| 81 |
|
| 82 |
return *this; |
| 83 |
} |
| 84 |
//method to traverse atoms |
| 85 |
TFASAtom *TFASResidue::BeginAtom(vector<TFASAtom *>::iterator &i) |
| 86 |
{ |
| 87 |
i = _atomList.begin(); |
| 88 |
|
| 89 |
if (i != _atomList.end()) |
| 90 |
{ |
| 91 |
return *i; |
| 92 |
} |
| 93 |
else |
| 94 |
{ |
| 95 |
return NULL; |
| 96 |
} |
| 97 |
|
| 98 |
|
| 99 |
} |
| 100 |
|
| 101 |
TFASAtom *TFASResidue::NextAtom(vector<TFASAtom *>::iterator &i) |
| 102 |
{ |
| 103 |
i++; |
| 104 |
|
| 105 |
if (i != _atomList.end()) |
| 106 |
{ |
| 107 |
return *i; |
| 108 |
} |
| 109 |
else |
| 110 |
{ |
| 111 |
return NULL; |
| 112 |
} |
| 113 |
|
| 114 |
} |
| 115 |
|
| 116 |
void TFASResidue::AddAtom(TFASAtom *atom) |
| 117 |
{ |
| 118 |
if (atom != NULL) |
| 119 |
{ |
| 120 |
_atomList.push_back(atom); |
| 121 |
atom->SetResidue(this); |
| 122 |
} |
| 123 |
|
| 124 |
} |
| 125 |
|
| 126 |
void TFASResidue::DeleteAtom(TFASAtom *atom) |
| 127 |
{ |
| 128 |
vector<TFASAtom *>::iterator i; |
| 129 |
|
| 130 |
i = find(_atomList.begin(), _atomList.end(), atom); |
| 131 |
|
| 132 |
if (i != _atomList.end()) |
| 133 |
{ |
| 134 |
_atomList.erase(i); |
| 135 |
} |
| 136 |
|
| 137 |
} |
| 138 |
|
| 139 |
vector<TFASBond *> TFASResidue::GetBonds(bool exterior) |
| 140 |
{ |
| 141 |
vector<TFASAtom *>::iterator i; |
| 142 |
vector<TFASBond *>::iterator j; |
| 143 |
TFASAtom * atom; |
| 144 |
TFASBond * bond; |
| 145 |
vector<TFASBond *> bondList; |
| 146 |
TBitVector bondIndexs; |
| 147 |
|
| 148 |
for (atom=BeginAtom(i); atom!=NULL; atom=NextAtom(i)) |
| 149 |
{ |
| 150 |
for (bond=atom->BeginBond(j); bond!=NULL; bond=atom->NextBond(j)) |
| 151 |
{ |
| 152 |
if (bondIndexs.IsBitOn(bond->GetIndex())) |
| 153 |
{ |
| 154 |
if (!exterior) |
| 155 |
{ |
| 156 |
if ((bond->GetNbrAtom(atom))->GetResidue() == this) |
| 157 |
{ |
| 158 |
bondList.push_back(bond); |
| 159 |
} |
| 160 |
|
| 161 |
} |
| 162 |
else |
| 163 |
bondList.push_back(bond); |
| 164 |
|
| 165 |
bondIndexs.SetBitOn(bond->GetIndex()); |
| 166 |
} |
| 167 |
} |
| 168 |
|
| 169 |
} |
| 170 |
|
| 171 |
return bondList; |
| 172 |
} |
| 173 |
|
| 174 |
vector<TFASBond *> TFASResidue::GetBondsByType(int bondType) |
| 175 |
{ |
| 176 |
vector<TFASAtom *>::iterator i; |
| 177 |
vector<TFASBond *>::iterator j; |
| 178 |
TFASAtom * atom; |
| 179 |
TFASBond * bond; |
| 180 |
vector<TFASBond *> bondList; |
| 181 |
TBitVector bondIndexs; |
| 182 |
|
| 183 |
for (atom=BeginAtom(i); atom!=NULL; atom=NextAtom(i)) |
| 184 |
{ |
| 185 |
for (bond=atom->BeginBond(j); bond!=NULL; bond=atom->NextBond(j)) |
| 186 |
{ |
| 187 |
if (bondIndexs.IsBitOn(bond->GetIndex())) |
| 188 |
{ |
| 189 |
if (bond->HasBondType(bondType)) |
| 190 |
bondList.push_back(bond); |
| 191 |
|
| 192 |
bondIndexs.SetBitOn(bond->GetIndex()); |
| 193 |
} |
| 194 |
} |
| 195 |
|
| 196 |
} |
| 197 |
|
| 198 |
return bondList; |
| 199 |
} |