NCBI C++ ToolKit
atom_set.cpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* $Id: atom_set.cpp 33815 2007-05-04 17:18:18Z kazimird $
2 * ===========================================================================
3 *
4 * PUBLIC DOMAIN NOTICE
5 * National Center for Biotechnology Information
6 *
7 * This software/database is a "United States Government Work" under the
8 * terms of the United States Copyright Act. It was written as part of
9 * the author's official duties as a United States Government employee and
10 * thus cannot be copyrighted. This software/database is freely available
11 * to the public for use. The National Library of Medicine and the U.S.
12 * Government have not placed any restriction on its use or reproduction.
13 *
14 * Although all reasonable efforts have been taken to ensure the accuracy
15 * and reliability of the software and data, the NLM and the U.S.
16 * Government do not and cannot warrant the performance or results that
17 * may be obtained by using this software or data. The NLM and the U.S.
18 * Government disclaim all warranties, express or implied, including
19 * warranties of performance, merchantability or fitness for any particular
20 * purpose.
21 *
22 * Please cite the author in any work or product based on this material.
23 *
24 * ===========================================================================
25 *
26 * Authors: Paul Thiessen
27 *
28 * File Description:
29 * Classes to hold sets of atomic data
30 *
31 * ===========================================================================
32 */
33 
34 #include <ncbi_pch.hpp>
35 #include <corelib/ncbistd.hpp>
36 
49 
51 
52 #include "atom_set.hpp"
53 #include "vector_math.hpp"
54 #include "cn3d_tools.hpp"
55 #include "structure_set.hpp"
56 
59 
60 
61 BEGIN_SCOPE(Cn3D)
62 
64  StructureBase(parent), activeEnsemble(NULL)
65 {
66  unsigned int nAtoms = coords.GetNumber_of_points();
67  TRACEMSG("model has " << nAtoms << " atomic coords");
68 
69  bool haveTemp = coords.IsSetTemperature_factors(),
70  haveOccup = coords.IsSetOccupancies(),
71  haveAlt = coords.IsSetAlternate_conf_ids();
72 
73  // sanity check
74  if (coords.GetAtoms().GetMolecule_ids().size()!=nAtoms ||
75  coords.GetAtoms().GetResidue_ids().size()!=nAtoms ||
76  coords.GetAtoms().GetAtom_ids().size()!=nAtoms ||
77  coords.GetSites().GetX().size()!=nAtoms ||
78  coords.GetSites().GetY().size()!=nAtoms ||
79  coords.GetSites().GetZ().size()!=nAtoms ||
80  (haveTemp &&
81  ((coords.GetTemperature_factors().IsIsotropic() &&
82  coords.GetTemperature_factors().GetIsotropic().GetB().size()!=nAtoms) ||
83  (coords.GetTemperature_factors().IsAnisotropic() &&
84  (coords.GetTemperature_factors().GetAnisotropic().GetB_11().size()!=nAtoms ||
85  coords.GetTemperature_factors().GetAnisotropic().GetB_12().size()!=nAtoms ||
86  coords.GetTemperature_factors().GetAnisotropic().GetB_13().size()!=nAtoms ||
87  coords.GetTemperature_factors().GetAnisotropic().GetB_22().size()!=nAtoms ||
88  coords.GetTemperature_factors().GetAnisotropic().GetB_23().size()!=nAtoms ||
89  coords.GetTemperature_factors().GetAnisotropic().GetB_33().size()!=nAtoms)))) ||
90  (haveOccup && coords.GetOccupancies().GetO().size()!=nAtoms) ||
91  (haveAlt && coords.GetAlternate_conf_ids().Get().size()!=nAtoms))
92  ERRORMSG("AtomSet: confused by list length mismatch");
93 
94  // atom-pntr iterators
95  CAtom_pntrs::TMolecule_ids::const_iterator
96  i_mID = coords.GetAtoms().GetMolecule_ids().begin();
97  CAtom_pntrs::TResidue_ids::const_iterator
98  i_rID = coords.GetAtoms().GetResidue_ids().begin();
99  CAtom_pntrs::TAtom_ids::const_iterator
100  i_aID = coords.GetAtoms().GetAtom_ids().begin();
101 
102  // atom site iterators
103  double siteScale = static_cast<double>(coords.GetSites().GetScale_factor());
104  CModel_space_points::TX::const_iterator i_X = coords.GetSites().GetX().begin();
105  CModel_space_points::TY::const_iterator i_Y = coords.GetSites().GetY().begin();
106  CModel_space_points::TZ::const_iterator i_Z = coords.GetSites().GetZ().begin();
107 
108  // occupancy iterator
109  CAtomic_occupancies::TO::const_iterator i_occup;
110  double occupScale = 0.0;
111  if (haveOccup) {
112  occupScale = static_cast<double>(coords.GetOccupancies().GetScale_factor());
113  i_occup = coords.GetOccupancies().GetO().begin();
114  }
115 
116  // altConfID iterator
117  CAlternate_conformation_ids::Tdata::const_iterator i_alt;
118  if (haveAlt) i_alt = coords.GetAlternate_conf_ids().Get().begin();
119 
120  // temperature iterators
121  double tempScale = 0.0;
122  CIsotropic_temperature_factors::TB::const_iterator i_tempI;
123  CAnisotropic_temperature_factors::TB_11::const_iterator i_tempA11;
124  CAnisotropic_temperature_factors::TB_12::const_iterator i_tempA12;
125  CAnisotropic_temperature_factors::TB_13::const_iterator i_tempA13;
126  CAnisotropic_temperature_factors::TB_22::const_iterator i_tempA22;
127  CAnisotropic_temperature_factors::TB_23::const_iterator i_tempA23;
128  CAnisotropic_temperature_factors::TB_33::const_iterator i_tempA33;
129  if (haveTemp) {
130  if (coords.GetTemperature_factors().IsIsotropic()) {
131  tempScale = static_cast<double>
132  (coords.GetTemperature_factors().GetIsotropic().GetScale_factor());
133  i_tempI = coords.GetTemperature_factors().GetIsotropic().GetB().begin();
134  } else {
135  tempScale = static_cast<double>
136  (coords.GetTemperature_factors().GetAnisotropic().GetScale_factor());
137  i_tempA11 = coords.GetTemperature_factors().GetAnisotropic().GetB_11().begin();
138  i_tempA12 = coords.GetTemperature_factors().GetAnisotropic().GetB_12().begin();
139  i_tempA13 = coords.GetTemperature_factors().GetAnisotropic().GetB_13().begin();
140  i_tempA22 = coords.GetTemperature_factors().GetAnisotropic().GetB_22().begin();
141  i_tempA23 = coords.GetTemperature_factors().GetAnisotropic().GetB_23().begin();
142  i_tempA33 = coords.GetTemperature_factors().GetAnisotropic().GetB_33().begin();
143  }
144  }
145 
146  const StructureObject *constObject;
147  if (!GetParentOfType(&constObject)) return;
148  StructureObject *object = const_cast<StructureObject*>(constObject);
149 
150  // actually do the work of unpacking serial atom data into Atom objects
151  for (unsigned int i=0; i<nAtoms; ++i) {
152  AtomCoord *atom = new AtomCoord(this);
153 
154  atom->site.x = (static_cast<double>(*(i_X++)))/siteScale;
155  atom->site.y = (static_cast<double>(*(i_Y++)))/siteScale;
156  atom->site.z = (static_cast<double>(*(i_Z++)))/siteScale;
157  if (haveOccup)
158  atom->occupancy = (static_cast<double>(*(i_occup++)))/occupScale;
159  if (haveAlt)
160  atom->altConfID = (i_alt++)->Get()[0];
161  if (haveTemp) {
162  if (coords.GetTemperature_factors().IsIsotropic()) {
163  atom->averageTemperature =
164  (static_cast<double>(*(i_tempI++)))/tempScale;
165  } else {
166  atom->averageTemperature = (
167  (static_cast<double>(*(i_tempA11++))) +
168  (static_cast<double>(*(i_tempA12++))) +
169  (static_cast<double>(*(i_tempA13++))) +
170  (static_cast<double>(*(i_tempA22++))) +
171  (static_cast<double>(*(i_tempA23++))) +
172  (static_cast<double>(*(i_tempA33++)))) / (tempScale * 6.0);
173  }
174  // track min and max temperatures over whole object
176  atom->averageTemperature < object->minTemperature)
177  object->minTemperature = atom->averageTemperature;
179  atom->averageTemperature > object->maxTemperature)
180  object->maxTemperature = atom->averageTemperature;
181  }
182 
183  // store pointer in map - key+altConfID must be unique
184  const AtomPntrKey& key = MakeKey(AtomPntr(
185  *(i_mID++),
186  *(i_rID++),
187  *(i_aID++)));
188  if (atomMap.find(key) != atomMap.end()) {
189  AtomAltList::const_iterator i_atom, e=atomMap[key].end();
190  for (i_atom=atomMap[key].begin(); i_atom!=e; ++i_atom) {
191  if ((*i_atom)->altConfID == atom->altConfID)
192  ERRORMSG("confused by multiple atoms of same pntr+altConfID");
193  }
194  }
195  atomMap[key].push_back(atom);
196 
197  if (i==0) TRACEMSG("first atom: x " << atom->site.x <<
198  ", y " << atom->site.y <<
199  ", z " << atom->site.z <<
200  ", occup " << atom->occupancy <<
201  ", altConfId '" << atom->altConfID << "'" <<
202  ", temp " << atom->averageTemperature);
203  }
204 
205  // get alternate conformer ensembles; store as string of altID characters
206  if (haveAlt && coords.IsSetConf_ensembles()) {
207  CAtomic_coordinates::TConf_ensembles::const_iterator i_ensemble,
208  e_ensemble = coords.GetConf_ensembles().end();
209  for (i_ensemble=coords.GetConf_ensembles().begin(); i_ensemble!=e_ensemble; ++i_ensemble) {
210  const CConformation_ensemble& ensemble = (*i_ensemble).GetObject();
211  string *ensembleStr = new string();
212  CConformation_ensemble::TAlt_conf_ids::const_iterator i_altIDs,
213  e_altIDs = ensemble.GetAlt_conf_ids().end();
214  for (i_altIDs=ensemble.GetAlt_conf_ids().begin();
215  i_altIDs!=e_altIDs; ++i_altIDs) {
216  (*ensembleStr) += i_altIDs->Get()[0];
217  }
218  ensembles.push_back(ensembleStr);
219  TRACEMSG("alt conf ensemble '" << (*ensembleStr) << "'");
220  }
221  }
222 }
223 
225 {
226  EnsembleList::iterator i, e=ensembles.end();
227  for (i=ensembles.begin(); i!=e; ++i)
228  delete const_cast<string *>(*i);
229 }
230 
231 const double AtomCoord::NO_TEMPERATURE = -1.0;
232 const double AtomCoord::NO_OCCUPANCY = -1.0;
233 const char AtomCoord::NO_ALTCONFID = '-';
234 
235 bool AtomSet::SetActiveEnsemble(const string *ensemble)
236 {
237  // if not NULL, make sure it's one of this AtomSet's ensembles
238  if (ensemble) {
239  EnsembleList::const_iterator e, ee=ensembles.end();
240  for (e=ensembles.begin(); e!=ee; ++e) {
241  if (*e == ensemble) break;
242  }
243  if (e == ee) {
244  ERRORMSG("AtomSet::SetActiveEnsemble received invalid ensemble");
245  return false;
246  }
247  }
248  activeEnsemble = ensemble;
249  return true;
250 }
251 
253  bool getAny, bool suppressWarning) const
254 {
255  AtomMap::const_iterator atomConfs = atomMap.find(MakeKey(ap));
256  if (atomConfs == atomMap.end()) {
257  if (!suppressWarning)
258  WARNINGMSG("can't find atom(s) from pointer (" << ap.mID << ','
259  << ap.rID << ',' << ap.aID << ')');
260  return NULL;
261  }
262  AtomAltList::const_iterator atom = atomConfs->second.begin();
263 
264  // if no activeEnsemble specified, just return first altConf
265  if (!activeEnsemble) return *atom;
266 
267  // otherwise, try to find first atom whose altConfID is in the activeEnsemble
268  AtomAltList::const_iterator e = atomConfs->second.end();
269  for (; atom!=e; ++atom) {
270  if (activeEnsemble->find((*atom)->altConfID) != activeEnsemble->npos)
271  return *atom;
272  }
273 
274  // if none found, but getAny is true, just return the first of the list
275  if (getAny) return atomConfs->second.front();
276 
277  return NULL;
278 }
279 
281  StructureBase(parent),
282  averageTemperature(NO_TEMPERATURE),
283  occupancy(NO_OCCUPANCY),
284  altConfID(NO_ALTCONFID)
285 {
286 }
287 
288 END_SCOPE(Cn3D)
User-defined methods of the data storage class.
User-defined methods of the data storage class.
User-defined methods of the data storage class.
User-defined methods of the data storage class.
User-defined methods of the data storage class.
User-defined methods of the data storage class.
User-defined methods of the data storage class.
User-defined methods of the data storage class.
User-defined methods of the data storage class.
User-defined methods of the data storage class.
User-defined methods of the data storage class.
User-defined methods of the data storage class.
USING_SCOPE(objects)
USING_NCBI_SCOPE
Definition: atom_set.cpp:57
double averageTemperature
Definition: atom_set.hpp:63
char altConfID
Definition: atom_set.hpp:65
static const double NO_TEMPERATURE
Definition: atom_set.hpp:66
double occupancy
Definition: atom_set.hpp:64
static const double NO_OCCUPANCY
Definition: atom_set.hpp:67
Vector site
Definition: atom_set.hpp:62
static const char NO_ALTCONFID
Definition: atom_set.hpp:68
AtomCoord(StructureBase *parent)
Definition: atom_set.cpp:280
EnsembleList ensembles
Definition: atom_set.hpp:89
const AtomCoord * GetAtom(const AtomPntr &atom, bool getAny=false, bool suppressWarning=false) const
Definition: atom_set.cpp:252
AtomMap atomMap
Definition: atom_set.hpp:109
const std::string * activeEnsemble
Definition: atom_set.hpp:110
AtomPntrKey MakeKey(const AtomPntr &ap) const
Definition: atom_set.hpp:103
std::pair< int, std::pair< int, int > > AtomPntrKey
Definition: atom_set.hpp:102
bool SetActiveEnsemble(const std::string *ensemble)
Definition: atom_set.cpp:235
~AtomSet(void)
Definition: atom_set.cpp:224
CAtomic_coordinates –.
CConformation_ensemble –.
static const double NO_TEMPERATURE
double y
Definition: vector_math.hpp:47
double x
Definition: vector_math.hpp:47
double z
Definition: vector_math.hpp:47
#define TRACEMSG(stream)
Definition: cn3d_tools.hpp:83
#define WARNINGMSG(stream)
Definition: cn3d_tools.hpp:85
#define ERRORMSG(stream)
Definition: cn3d_tools.hpp:86
static string MakeKey(CScoreValue const &)
Include a standard set of the NCBI C++ Toolkit most basic headers.
string
Definition: cgiapp.hpp:687
#define NULL
Definition: ncbistd.hpp:225
#define END_SCOPE(ns)
End the previously defined scope.
Definition: ncbistl.hpp:75
#define BEGIN_SCOPE(ns)
Define a new scope.
Definition: ncbistl.hpp:72
const TAlt_conf_ids & GetAlt_conf_ids(void) const
Get the Alt_conf_ids member data.
int i
const TYPE & Get(const CNamedParameterList *param)
const struct ncbi::grid::netcache::search::fields::KEY key
#define const
Definition: zconf.h:232
Modified on Wed Sep 04 14:59:34 2024 by modify_doxy.py rev. 669887