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 throw(Exception::FileNotFound);
00113
00116 FragmentDB(const FragmentDB& db, bool deep = true);
00117
00119 FragmentDB& operator = (const FragmentDB& db)
00120 ;
00121
00124 virtual ~FragmentDB();
00125
00128 void destroy();
00129
00131
00134
00137 void init()
00138 throw(Exception::FileNotFound, NoFragmentNode);
00139
00141
00144
00147 void setFilename(const String& filename)
00148 throw(Exception::FileNotFound);
00149
00152 const String& getFilename() const;
00153
00156 bool has(const String& fragment_name) const;
00157
00159 const std::vector<Residue*>& getFragments() const { return fragments_;}
00160
00163 FragmentDB::Type getFragmentType(const String& fragment_name) const;
00164
00167 list<String> getVariantNames(const String& name) const;
00168
00171 const Fragment* getFragment(const String& fragment_name) const;
00172
00179 const Fragment* getReferenceFragment(const Fragment& fragment) const;
00180
00183 const Residue* getResidue(const String& fragment_name) const;
00184
00193 Fragment* getFragmentCopy(const String& fragment_name) const;
00194
00203 Molecule* getMoleculeCopy(const String& fragment_name) const;
00204
00213 Residue* getResidueCopy(const String& fragment_name) const;
00214
00217 const String& getDefaultNamingStandard() const;
00218
00221 StringHashMap<NameMap>& getNamingStandards();
00222
00229 const StringHashMap<String>& getNamingStandard(const String& std) const
00230 throw(StringHashMap<String>::IllegalKey);
00231
00235 std::vector<String> getAvailableNamingStandards() const;
00236
00238
00242
00245 bool isValid() const;
00246
00248
00251
00256 class BALL_EXPORT NormalizeNamesProcessor
00257 : public UnaryProcessor<Fragment>
00258 {
00259
00260 public:
00261
00265
00268 NormalizeNamesProcessor();
00269
00270
00273 NormalizeNamesProcessor(FragmentDB& db);
00274
00277 virtual ~NormalizeNamesProcessor();
00278
00280
00283
00286 void setFragmentDB(FragmentDB& db);
00287
00290 void setNamingStandard(const String& naming_standard);
00291
00294 const String& getNamingStandard();
00295
00298 bool matchName(String& res_name, String& atom_name, const NameMap& map) const;
00299
00301
00304
00307 virtual bool start();
00308
00311 virtual bool finish();
00312
00315 virtual Processor::Result operator () (Fragment& fragment);
00316
00318
00319 private:
00320 enum CountingMode { ADD, OVERWRITE };
00321 String getSuffix_(const Fragment* frag) const;
00322 bool doMatch_(String& res_name, const String& res_name_suffix, String& atom_name, const NameMap& map) const;
00323 void countHits_(HashMap<NameMap*, Index>& maps, const std::list<Fragment*>& frags);
00324 void countHits_(HashMap<NameMap*, Index>& maps, const Fragment* frag, CountingMode mode = OVERWRITE);
00325 const NameMap* getBestMap_(const HashMap<NameMap*, Index>& maps) const;
00326 void normalizeFragments_(const NameMap* map, const std::list<Fragment*>& frags);
00327 void normalizeFragment_ (const NameMap* map, Fragment* frag);
00328
00329 String naming_standard_;
00330
00331 FragmentDB* fragment_db_;
00332
00333 std::list<Fragment*> fragments_;
00334
00335 };
00336
00337
00340 class BALL_EXPORT BuildBondsProcessor
00341 : public UnaryProcessor<Fragment>
00342 {
00343
00344 public:
00345
00349
00350 struct Connection
00351 {
00352 Atom* atom;
00353 String type_name;
00354 String connect_to;
00355 Bond::Order order;
00356 float dist;
00357 float delta;
00358 };
00359
00361 typedef std::list<Connection> ConnectionList;
00363
00364
00368
00370 BuildBondsProcessor();
00371
00373 BuildBondsProcessor(const FragmentDB& db);
00374
00376 virtual ~BuildBondsProcessor();
00378
00382
00384 virtual bool finish();
00385
00387 virtual bool start();
00388
00390 virtual Processor::Result operator () (Fragment& fragment);
00392
00396
00398 Size getNumberOfBondsBuilt();
00399
00401 void setFragmentDB(const FragmentDB& fragment_db);
00402
00404
00408
00414 Size buildFragmentBonds(Fragment& fragment) const;
00415
00422 Size buildFragmentBonds(Fragment& fragment, const Fragment& tplate) const
00423 throw(Exception::TooManyBonds);
00424
00430 Size buildInterFragmentBonds(Fragment& first, Fragment& second) const
00431 throw(Exception::TooManyBonds);
00432
00434
00435 protected:
00436
00442 void storeConnections_(Fragment& fragment);
00443
00446 bool buildConnection_(Connection& con1, Connection& con2)
00447 throw(Exception::TooManyBonds);
00448
00451 FragmentDB* fragment_db_;
00452
00457 std::list<Fragment*> fragment_list_;
00458
00459
00460
00461
00462
00463
00464 Size bonds_built_;
00465
00466
00467
00468 ConnectionList connections_;
00469 };
00470
00472
00475
00478 NormalizeNamesProcessor normalize_names;
00479
00482 ReconstructFragmentProcessor add_hydrogens;
00483
00486 BuildBondsProcessor build_bonds;
00487
00490 ResourceEntry* tree;
00491
00493
00494 private:
00495
00496
00497
00498
00499
00500
00501
00502
00503
00504 void parseAtoms_(ResourceEntry& entry, Fragment& fragment);
00505
00506
00507
00508 void parseBonds_(ResourceEntry& entry, Fragment& fragment);
00509
00510
00511
00512
00513
00514
00515
00516
00517 void parseProperties_(ResourceEntry& entry, PropertyManager& property_man);
00518
00519
00520
00521
00522 void parseDelete_(ResourceEntry& entry, Fragment& fragment);
00523
00524
00525
00526
00527 void parseRename_(ResourceEntry& entry, Fragment& fragment);
00528
00529
00530
00532 Position addNewFragment_(Residue* fragment);
00533
00534
00535
00536
00537 void expandTree_(ResourceEntry& root_entry);
00538
00539
00540
00541
00542 bool expandFirst_(ResourceEntry& root_entry)
00543 throw(Exception::FileNotFound);
00544
00545
00546 bool valid_;
00547
00548
00549 String filename_;
00550
00551
00552 String default_standard_;
00553
00554
00555 std::vector<Residue*> fragments_;
00556
00557
00558 NameMap name_to_path_;
00559
00560
00561 StringHashMap<Position> name_to_frag_index_;
00562
00563
00564 StringHashMap<list<Position> > name_to_variants_;
00565
00566
00567 StringHashMap<NameMap> standards_;
00568 };
00569
00570 }
00571
00572
00573 #endif // BALL_STRUCTURE_FRAGMENTDB_H