00001
00002
00003
00004
00005 #ifndef BALL_STRUCTURE_FRAGMENTDB_H
00006 #define BALL_STRUCTURE_FRAGMENTDB_H
00007
00008 #ifndef BALL_DATATYPE_STRINGHASHMAP_H
00009 # include <BALL/DATATYPE/stringHashMap.h>
00010 #endif
00011
00012 #ifndef BALL_KERNEL_RESIDUE_H
00013 # include <BALL/KERNEL/residue.h>
00014 #endif
00015
00016 #ifndef BALL_KERNEL_MOLECULE_H
00017 # include <BALL/KERNEL/molecule.h>
00018 #endif
00019
00020 #ifndef BALL_KERNEL_BOND_H
00021 # include <BALL/KERNEL/bond.h>
00022 #endif
00023
00024 #ifndef BALL_STRUCTURE_RECONSTRUCTFRAGMENTPROCESSOR_H
00025 # include <BALL/STRUCTURE/reconstructFragmentProcessor.h>
00026 #endif
00027
00028 #include <vector>
00029 #include <list>
00030
00031 namespace BALL
00032 {
00033
00034 class ResourceEntry;
00035
00044 class BALL_EXPORT FragmentDB
00045 {
00046 public:
00047
00048 class AddHydrogensProcessor;
00049 friend class FragmentDB::AddHydrogensProcessor;
00050
00051 BALL_CREATE_DEEP(FragmentDB)
00052
00053
00056
00059 enum FragmentTypes
00060 {
00061 TYPE__UNKNOWN = -1,
00062 TYPE__FRAGMENT,
00063 TYPE__RESIDUE,
00064 TYPE__MOLECULE
00065 };
00067
00071
00074 typedef short Type;
00076 typedef StringHashMap<String> NameMap;
00077
00079
00082
00087 class BALL_EXPORT NoFragmentNode
00088 : public Exception::GeneralException
00089 {
00090 public:
00091 NoFragmentNode(const char* file, int line, const string& filename);
00092 ~NoFragmentNode() throw() {}
00093
00094 protected:
00095 string filename_;
00096 };
00097
00099
00102
00105 FragmentDB();
00106
00111 FragmentDB(const String& filename);
00112
00115 FragmentDB(const FragmentDB& db, bool deep = true);
00116
00118 FragmentDB& operator = (const FragmentDB& db);
00119
00122 virtual ~FragmentDB();
00123
00126 void destroy();
00127
00129
00132
00137 void init();
00138
00140
00143
00147 void setFilename(const String& filename);
00148
00151 const String& getFilename() const;
00152
00155 bool has(const String& fragment_name) const;
00156
00158 const std::vector<Residue*>& getFragments() const { return fragments_;}
00159
00162 FragmentDB::Type getFragmentType(const String& fragment_name) const;
00163
00166 list<String> getVariantNames(const String& name) const;
00167
00170 const Fragment* getFragment(const String& fragment_name) const;
00171
00178 const Fragment* getReferenceFragment(const Fragment& fragment) const;
00179
00182 const Residue* getResidue(const String& fragment_name) const;
00183
00192 Fragment* getFragmentCopy(const String& fragment_name) const;
00193
00202 Molecule* getMoleculeCopy(const String& fragment_name) const;
00203
00212 Residue* getResidueCopy(const String& fragment_name) const;
00213
00216 const String& getDefaultNamingStandard() const;
00217
00220 StringHashMap<NameMap>& getNamingStandards();
00221
00228 const StringHashMap<String>& getNamingStandard(const String& std) const;
00229
00233 std::vector<String> getAvailableNamingStandards() const;
00234
00236
00240
00243 bool isValid() const;
00244
00246
00249
00254 class BALL_EXPORT NormalizeNamesProcessor
00255 : public UnaryProcessor<Fragment>
00256 {
00257
00258 public:
00259
00263
00266 NormalizeNamesProcessor();
00267
00268
00271 NormalizeNamesProcessor(FragmentDB& db);
00272
00275 virtual ~NormalizeNamesProcessor();
00276
00278
00281
00284 void setFragmentDB(FragmentDB& db);
00285
00288 void setNamingStandard(const String& naming_standard);
00289
00292 const String& getNamingStandard();
00293
00296 bool matchName(String& res_name, String& atom_name, const NameMap& map) const;
00297
00299
00302
00305 virtual bool start();
00306
00309 virtual bool finish();
00310
00313 virtual Processor::Result operator () (Fragment& fragment);
00314
00316
00317 private:
00318 enum CountingMode { ADD, OVERWRITE };
00319 String getSuffix_(const Fragment* frag) const;
00320 bool doMatch_(String& res_name, const String& res_name_suffix, String& atom_name, const NameMap& map) const;
00321 void countHits_(HashMap<NameMap*, Index>& maps, const std::list<Fragment*>& frags);
00322 void countHits_(HashMap<NameMap*, Index>& maps, const Fragment* frag, CountingMode mode = OVERWRITE);
00323 const NameMap* getBestMap_(const HashMap<NameMap*, Index>& maps) const;
00324 void normalizeFragments_(const NameMap* map, const std::list<Fragment*>& frags);
00325 void normalizeFragment_ (const NameMap* map, Fragment* frag);
00326
00327 String naming_standard_;
00328
00329 FragmentDB* fragment_db_;
00330
00331 std::list<Fragment*> fragments_;
00332
00333 };
00334
00335
00338 class BALL_EXPORT BuildBondsProcessor
00339 : public UnaryProcessor<Fragment>
00340 {
00341
00342 public:
00343
00347
00348 struct Connection
00349 {
00350 Atom* atom;
00351 String type_name;
00352 String connect_to;
00353 Bond::Order order;
00354 float dist;
00355 float delta;
00356 };
00357
00359 typedef std::list<Connection> ConnectionList;
00361
00362
00366
00368 BuildBondsProcessor();
00369
00371 BuildBondsProcessor(const FragmentDB& db);
00372
00374 virtual ~BuildBondsProcessor();
00376
00380
00382 virtual bool finish();
00383
00385 virtual bool start();
00386
00388 virtual Processor::Result operator () (Fragment& fragment);
00390
00394
00396 Size getNumberOfBondsBuilt();
00397
00399 void setFragmentDB(const FragmentDB& fragment_db);
00400
00402
00406
00412 Size buildFragmentBonds(Fragment& fragment) const;
00413
00421 Size buildFragmentBonds(Fragment& fragment, const Fragment& tplate) const;
00422
00429 Size buildInterFragmentBonds(Fragment& first, Fragment& second) const;
00430
00432
00433 protected:
00434
00440 void storeConnections_(Fragment& fragment);
00441
00445 bool buildConnection_(Connection& con1, Connection& con2);
00446
00449 FragmentDB* fragment_db_;
00450
00455 std::list<Fragment*> fragment_list_;
00456
00457
00458
00459
00460
00461
00462 Size bonds_built_;
00463
00464
00465
00466 ConnectionList connections_;
00467 };
00468
00470
00473
00476 NormalizeNamesProcessor normalize_names;
00477
00480 ReconstructFragmentProcessor add_hydrogens;
00481
00484 BuildBondsProcessor build_bonds;
00485
00488 ResourceEntry* tree;
00489
00491
00492 private:
00493
00494
00495
00496
00497
00498
00499
00500
00501
00502 void parseAtoms_(ResourceEntry& entry, Fragment& fragment);
00503
00504
00505
00506 void parseBonds_(ResourceEntry& entry, Fragment& fragment);
00507
00508
00509
00510
00511
00512
00513
00514
00515 void parseProperties_(ResourceEntry& entry, PropertyManager& property_man);
00516
00517
00518
00519
00520 void parseDelete_(ResourceEntry& entry, Fragment& fragment);
00521
00522
00523
00524
00525 void parseRename_(ResourceEntry& entry, Fragment& fragment);
00526
00527
00528
00530 Position addNewFragment_(Residue* fragment);
00531
00532
00533
00534
00535 void expandTree_(ResourceEntry& root_entry);
00536
00537
00538
00539
00540
00541 bool expandFirst_(ResourceEntry& root_entry);
00542
00543
00544 bool valid_;
00545
00546
00547 String filename_;
00548
00549
00550 String default_standard_;
00551
00552
00553 std::vector<Residue*> fragments_;
00554
00555
00556 NameMap name_to_path_;
00557
00558
00559 StringHashMap<Position> name_to_frag_index_;
00560
00561
00562 StringHashMap<list<Position> > name_to_variants_;
00563
00564
00565 StringHashMap<NameMap> standards_;
00566 };
00567
00568 }
00569
00570
00571 #endif // BALL_STRUCTURE_FRAGMENTDB_H