BALL  1.4.79
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
fragmentDB.h
Go to the documentation of this file.
1 // -*- Mode: C++; tab-width: 2; -*-
2 // vi: set ts=2:
3 //
4 
5 #ifndef BALL_STRUCTURE_FRAGMENTDB_H
6 #define BALL_STRUCTURE_FRAGMENTDB_H
7 
8 #ifndef BALL_DATATYPE_STRINGHASHMAP_H
10 #endif
11 
12 #ifndef BALL_KERNEL_RESIDUE_H
13 # include <BALL/KERNEL/residue.h>
14 #endif
15 
16 #ifndef BALL_KERNEL_MOLECULE_H
17 # include <BALL/KERNEL/molecule.h>
18 #endif
19 
20 #ifndef BALL_KERNEL_BOND_H
21 # include <BALL/KERNEL/bond.h>
22 #endif
23 
24 #ifndef BALL_STRUCTURE_RECONSTRUCTFRAGMENTPROCESSOR_H
26 #endif
27 
28 #include <vector>
29 #include <list>
30 
31 namespace BALL
32 {
33 
34  class ResourceEntry;
35 
45  {
46  public:
47 
48  class AddHydrogensProcessor;
49  friend class FragmentDB::AddHydrogensProcessor;
50 
52 
53 
56 
60  {
61  TYPE__UNKNOWN = -1,
64  TYPE__MOLECULE
65  };
67 
71 
74  typedef short Type;
77 
79 
82 
89  {
90  public:
91  NoFragmentNode(const char* file, int line, const string& filename);
92  ~NoFragmentNode() throw() {}
93 
94  protected:
95  string filename_;
96  };
97 
99 
102 
105  FragmentDB();
106 
111  FragmentDB(const String& filename);
112 
115  FragmentDB(const FragmentDB& db, bool deep = true);
116 
118  FragmentDB& operator = (const FragmentDB& db);
119 
122  virtual ~FragmentDB();
123 
126  void destroy();
127 
129 
132 
137  void init();
138 
140 
143 
147  void setFilename(const String& filename);
148 
151  const String& getFilename() const;
152 
155  bool has(const String& fragment_name) const;
156 
158  const std::vector<Residue*>& getFragments() const { return fragments_;}
159 
162  FragmentDB::Type getFragmentType(const String& fragment_name) const;
163 
166  list<String> getVariantNames(const String& name) const;
167 
170  const Fragment* getFragment(const String& fragment_name) const;
171 
178  const Fragment* getReferenceFragment(const Fragment& fragment) const;
179 
182  const Residue* getResidue(const String& fragment_name) const;
183 
192  Fragment* getFragmentCopy(const String& fragment_name) const;
193 
202  Molecule* getMoleculeCopy(const String& fragment_name) const;
203 
212  Residue* getResidueCopy(const String& fragment_name) const;
213 
216  const String& getDefaultNamingStandard() const;
217 
220  StringHashMap<NameMap>& getNamingStandards();
221 
228  const StringHashMap<String>& getNamingStandard(const String& std) const;
229 
233  std::vector<String> getAvailableNamingStandards() const;
234 
236 
240 
243  bool isValid() const;
244 
246 
249 
255  : public UnaryProcessor<Fragment>
256  {
257 
258  public:
259 
263 
267 
268 
272 
275  virtual ~NormalizeNamesProcessor();
276 
278 
281 
284  void setFragmentDB(FragmentDB& db);
285 
288  void setNamingStandard(const String& naming_standard);
289 
292  const String& getNamingStandard();
293 
296  bool matchName(String& res_name, String& atom_name, const NameMap& map) const;
297 
299 
302 
305  virtual bool start();
306 
309  virtual bool finish();
310 
313  virtual Processor::Result operator () (Fragment& fragment);
314 
316 
317  private:
318  enum CountingMode { ADD, OVERWRITE };
319  String getSuffix_(const Fragment* frag) const;
320  bool doMatch_(String& res_name, const String& res_name_suffix, String& atom_name, const NameMap& map) const;
321  void countHits_(HashMap<NameMap*, Index>& maps, const std::list<Fragment*>& frags);
322  void countHits_(HashMap<NameMap*, Index>& maps, const Fragment* frag, CountingMode mode = OVERWRITE);
323  const NameMap* getBestMap_(const HashMap<NameMap*, Index>& maps) const;
324  void normalizeFragments_(const NameMap* map, const std::list<Fragment*>& frags);
325  void normalizeFragment_ (const NameMap* map, Fragment* frag);
326 
327  String naming_standard_;
328 
329  FragmentDB* fragment_db_;
330 
331  std::list<Fragment*> fragments_;
332 
333  };
334 
335 
339  : public UnaryProcessor<Fragment>
340  {
341 
342  public:
343 
347  struct Connection
349  {
354  float dist;
355  float delta;
356  };
357 
359  typedef std::list<Connection> ConnectionList;
361 
362 
366 
369 
372 
374  virtual ~BuildBondsProcessor();
376 
380 
382  virtual bool finish();
383 
385  virtual bool start();
386 
388  virtual Processor::Result operator () (Fragment& fragment);
390 
394 
396  Size getNumberOfBondsBuilt();
397 
399  void setFragmentDB(const FragmentDB& fragment_db);
400 
402 
406 
412  Size buildFragmentBonds(Fragment& fragment) const;
413 
421  Size buildFragmentBonds(Fragment& fragment, const Fragment& tplate) const;
422 
429  Size buildInterFragmentBonds(Fragment& first, Fragment& second) const;
430 
432 
433  protected:
434 
440  void storeConnections_(Fragment& fragment);
441 
445  bool buildConnection_(Connection& con1, Connection& con2);
446 
450 
455  std::list<Fragment*> fragment_list_;
456 
457  /*_ The number of bonds built.
458  This value is reset in the start method, so each application of
459  the processor, so <TT> getNumberOfBuiltBonds </TT> always returns
460  the number of bonds built in the last application.
461  */
463 
464  /*_ The list of connects between(!) fragments still to be examined
465  */
467  };
468 
470 
473 
477 
481 
485 
489 
491 
492  private:
493 
494  /*_ @name Parse functions
495  These functions parse different sections of the fragment DB resource
496  tree and translate everything into the correct data structures.
497  */
498  //_@{
499 
500  /*_ Parses the Atoms entry and creates the atoms of the fragment
501  */
502  void parseAtoms_(ResourceEntry& entry, Fragment& fragment);
503 
504  /*_ Parses the Bonds entry and creates the bonds of the fragment
505  */
506  void parseBonds_(ResourceEntry& entry, Fragment& fragment);
507 
508  /*_ Parses the properties of a fragment/variant and sets the corresponding properties.
509  Properties are set or reset (if the property name starts with "!") for the current
510  fragment. All properties of fragment and residue are recognized, if they
511  are written exactly as in the header file (case insensitive) and set.
512  Unknown properties are set as name/value pairs as bool properties and set to
513  <b> true </b>.
514  */
515  void parseProperties_(ResourceEntry& entry, PropertyManager& property_man);
516 
517  /*_ Parses the Delete section.
518  All atoms given in this section are removed from the fragment.
519  */
520  void parseDelete_(ResourceEntry& entry, Fragment& fragment);
521 
522  /*_ Parses the Rename section.
523  All atoms given in this section are renamed to the given new name.
524  */
525  void parseRename_(ResourceEntry& entry, Fragment& fragment);
526 
527  //_@}
528 
530  Position addNewFragment_(Residue* fragment);
531 
532  /*_ Expands all include directives in the resource file.
533  This method calls expandFirst_ until it returns true.
534  */
535  void expandTree_(ResourceEntry& root_entry);
536 
537  /*_ Expands the first occuring include directive.
538  If no include directive is found, <b> false </b> is returned, otherwise <b> true </b>.
539  @exception Exception::FileNotFound if the file is not found in the BALL_DATA_PATH
540  */
541  bool expandFirst_(ResourceEntry& root_entry);
542 
543  // The status of the FragmentDB
544  bool valid_;
545 
546  // The filename of the master fragment file.
547  String filename_;
548 
549  // The naming standard we default to.
550  String default_standard_;
551 
552  // An array containing all allocated residues.
553  std::vector<Residue*> fragments_;
554 
555  // Maps a fragment name back to a path in the database
556  NameMap name_to_path_;
557 
558  // Maps a fragment name back to the array index in fragments_
559  StringHashMap<Position> name_to_frag_index_;
560 
561  // Maps all variants of a specific fragment back to array indices.
562  StringHashMap<list<Position> > name_to_variants_;
563 
564  // Contains the naming standards as a nested map.
565  StringHashMap<NameMap> standards_;
566  };
567 
568 } // namespace BALL
569 
570 
571 #endif // BALL_STRUCTURE_FRAGMENTDB_H
BuildBondsProcessor build_bonds
Definition: fragmentDB.h:484
std::list< Connection > ConnectionList
Definition: fragmentDB.h:359
short Order
Definition: bond.h:86
std::list< Fragment * > fragment_list_
Definition: fragmentDB.h:455
ResourceEntry * tree
Definition: fragmentDB.h:488
NormalizeNamesProcessor normalize_names
Definition: fragmentDB.h:476
#define BALL_CREATE_DEEP(name)
Definition: create.h:26
StringHashMap< String > NameMap
Definition: fragmentDB.h:76
const std::vector< Residue * > & getFragments() const
Definition: fragmentDB.h:158
ReconstructFragmentProcessor add_hydrogens
Definition: fragmentDB.h:480
HashMap class based on the STL map (containing serveral convenience functions)
Definition: hashMap.h:73
#define BALL_EXPORT
Definition: COMMON/global.h:50