Loading...
Searching...
No Matches
fragmentDB.h
Go to the documentation of this file.
// -*- Mode: C++; tab-width: 2; -*-
// vi: set ts=2:
//
#ifndef BALL_STRUCTURE_FRAGMENTDB_H
#define BALL_STRUCTURE_FRAGMENTDB_H
#ifndef BALL_DATATYPE_STRINGHASHMAP_H
# include <BALL/DATATYPE/stringHashMap.h>
#endif
#ifndef BALL_KERNEL_RESIDUE_H
# include <BALL/KERNEL/residue.h>
#endif
#ifndef BALL_KERNEL_MOLECULE_H
# include <BALL/KERNEL/molecule.h>
#endif
#ifndef BALL_KERNEL_BOND_H
# include <BALL/KERNEL/bond.h>
#endif
#ifndef BALL_STRUCTURE_RECONSTRUCTFRAGMENTPROCESSOR_H
# include <BALL/STRUCTURE/reconstructFragmentProcessor.h>
#endif
#include <vector>
#include <list>
namespace BALL
{
class ResourceEntry;
class BALL_EXPORT FragmentDB
{
public:
class AddHydrogensProcessor;
friend class FragmentDB::AddHydrogensProcessor;
BALL_CREATE_DEEP(FragmentDB)
enum FragmentTypes
{
TYPE__UNKNOWN = -1,
TYPE__FRAGMENT,
TYPE__RESIDUE,
TYPE__MOLECULE
};
typedef short Type;
typedef StringHashMap<String> NameMap;
class BALL_EXPORT NoFragmentNode
: public Exception::GeneralException
{
public:
NoFragmentNode(const char* file, int line, const string& filename);
~NoFragmentNode() throw() {}
protected:
string filename_;
};
FragmentDB();
FragmentDB(const String& filename);
FragmentDB(const FragmentDB& db, bool deep = true);
FragmentDB& operator = (const FragmentDB& db);
virtual ~FragmentDB();
void destroy();
void init();
void setFilename(const String& filename);
const String& getFilename() const;
bool has(const String& fragment_name) const;
const std::vector<Residue*>& getFragments() const { return fragments_;}
FragmentDB::Type getFragmentType(const String& fragment_name) const;
list<String> getVariantNames(const String& name) const;
const Fragment* getFragment(const String& fragment_name) const;
const Fragment* getReferenceFragment(const Fragment& fragment) const;
const Residue* getResidue(const String& fragment_name) const;
Fragment* getFragmentCopy(const String& fragment_name) const;
Molecule* getMoleculeCopy(const String& fragment_name) const;
Residue* getResidueCopy(const String& fragment_name) const;
const String& getDefaultNamingStandard() const;
StringHashMap<NameMap>& getNamingStandards();
const StringHashMap<String>& getNamingStandard(const String& std) const;
std::vector<String> getAvailableNamingStandards() const;
bool isValid() const;
class BALL_EXPORT NormalizeNamesProcessor
: public UnaryProcessor<Fragment>
{
public:
NormalizeNamesProcessor();
NormalizeNamesProcessor(FragmentDB& db);
virtual ~NormalizeNamesProcessor();
void setFragmentDB(FragmentDB& db);
void setNamingStandard(const String& naming_standard);
const String& getNamingStandard();
bool matchName(String& res_name, String& atom_name, const NameMap& map) const;
virtual bool start();
virtual bool finish();
virtual Processor::Result operator () (Fragment& fragment);
private:
enum CountingMode { ADD, OVERWRITE };
String getSuffix_(const Fragment* frag) const;
bool doMatch_(String& res_name, const String& res_name_suffix, String& atom_name, const NameMap& map) const;
void countHits_(HashMap<NameMap*, Index>& maps, const std::list<Fragment*>& frags);
void countHits_(HashMap<NameMap*, Index>& maps, const Fragment* frag, CountingMode mode = OVERWRITE);
const NameMap* getBestMap_(const HashMap<NameMap*, Index>& maps) const;
void normalizeFragments_(const NameMap* map, const std::list<Fragment*>& frags);
void normalizeFragment_ (const NameMap* map, Fragment* frag);
String naming_standard_;
FragmentDB* fragment_db_;
std::list<Fragment*> fragments_;
};
class BALL_EXPORT BuildBondsProcessor
: public UnaryProcessor<Fragment>
{
public:
struct Connection
{
Atom* atom;
String type_name;
String connect_to;
Bond::Order order;
float dist;
float delta;
};
typedef std::list<Connection> ConnectionList;
BuildBondsProcessor();
BuildBondsProcessor(const FragmentDB& db);
virtual ~BuildBondsProcessor();
virtual bool finish();
virtual bool start();
virtual Processor::Result operator () (Fragment& fragment);
Size getNumberOfBondsBuilt();
void setFragmentDB(const FragmentDB& fragment_db);
Size buildFragmentBonds(Fragment& fragment) const;
Size buildFragmentBonds(Fragment& fragment, const Fragment& tplate) const;
Size buildInterFragmentBonds(Fragment& first, Fragment& second) const;
protected:
void storeConnections_(Fragment& fragment);
bool buildConnection_(Connection& con1, Connection& con2);
FragmentDB* fragment_db_;
std::list<Fragment*> fragment_list_;
/*_ The number of bonds built.
This value is reset in the start method, so each application of
the processor, so <TT> getNumberOfBuiltBonds </TT> always returns
the number of bonds built in the last application.
*/
Size bonds_built_;
/*_ The list of connects between(!) fragments still to be examined
*/
ConnectionList connections_;
};
NormalizeNamesProcessor normalize_names;
ReconstructFragmentProcessor add_hydrogens;
BuildBondsProcessor build_bonds;
ResourceEntry* tree;
private:
/*_ @name Parse functions
These functions parse different sections of the fragment DB resource
tree and translate everything into the correct data structures.
*/
//_@{
/*_ Parses the Atoms entry and creates the atoms of the fragment
*/
void parseAtoms_(ResourceEntry& entry, Fragment& fragment);
/*_ Parses the Bonds entry and creates the bonds of the fragment
*/
void parseBonds_(ResourceEntry& entry, Fragment& fragment);
/*_ Parses the properties of a fragment/variant and sets the corresponding properties.
Properties are set or reset (if the property name starts with "!") for the current
fragment. All properties of fragment and residue are recognized, if they
are written exactly as in the header file (case insensitive) and set.
Unknown properties are set as name/value pairs as bool properties and set to
<b> true </b>.
*/
void parseProperties_(ResourceEntry& entry, PropertyManager& property_man);
/*_ Parses the Delete section.
All atoms given in this section are removed from the fragment.
*/
void parseDelete_(ResourceEntry& entry, Fragment& fragment);
/*_ Parses the Rename section.
All atoms given in this section are renamed to the given new name.
*/
void parseRename_(ResourceEntry& entry, Fragment& fragment);
//_@}
Position addNewFragment_(Residue* fragment);
/*_ Expands all include directives in the resource file.
This method calls expandFirst_ until it returns true.
*/
void expandTree_(ResourceEntry& root_entry);
/*_ Expands the first occuring include directive.
If no include directive is found, <b> false </b> is returned, otherwise <b> true </b>.
@exception Exception::FileNotFound if the file is not found in the BALL_DATA_PATH
*/
bool expandFirst_(ResourceEntry& root_entry);
// The status of the FragmentDB
bool valid_;
// The filename of the master fragment file.
String filename_;
// The naming standard we default to.
String default_standard_;
// An array containing all allocated residues.
std::vector<Residue*> fragments_;
// Maps a fragment name back to a path in the database
NameMap name_to_path_;
// Maps a fragment name back to the array index in fragments_
StringHashMap<Position> name_to_frag_index_;
// Maps all variants of a specific fragment back to array indices.
StringHashMap<list<Position> > name_to_variants_;
// Contains the naming standards as a nested map.
StringHashMap<NameMap> standards_;
};
} // namespace BALL
#endif // BALL_STRUCTURE_FRAGMENTDB_H
BALL_EXPORT
#define BALL_EXPORT
Definition COMMON/global.h:50
db
db
Definition GAFFTypeProcessor.h:74
bond.h
BALL::Atom
Definition atom.h:90
BALL::Bond::Order
short Order
Definition bond.h:86
BALL::Exception::GeneralException
Definition COMMON/exception.h:61
BALL::FragmentDB::BuildBondsProcessor
Definition fragmentDB.h:340
BALL::FragmentDB::BuildBondsProcessor::fragment_db_
FragmentDB * fragment_db_
Definition fragmentDB.h:449
BALL::FragmentDB::BuildBondsProcessor::BuildBondsProcessor
BuildBondsProcessor(const FragmentDB &db)
BALL::FragmentDB::BuildBondsProcessor::~BuildBondsProcessor
virtual ~BuildBondsProcessor()
BALL::FragmentDB::BuildBondsProcessor::buildFragmentBonds
Size buildFragmentBonds(Fragment &fragment, const Fragment &tplate) const
BALL::FragmentDB::BuildBondsProcessor::buildConnection_
bool buildConnection_(Connection &con1, Connection &con2)
BALL::FragmentDB::BuildBondsProcessor::connections_
ConnectionList connections_
Definition fragmentDB.h:466
BALL::FragmentDB::BuildBondsProcessor::buildInterFragmentBonds
Size buildInterFragmentBonds(Fragment &first, Fragment &second) const
BALL::FragmentDB::BuildBondsProcessor::fragment_list_
std::list< Fragment * > fragment_list_
Definition fragmentDB.h:455
BALL::FragmentDB::BuildBondsProcessor::start
virtual bool start()
BALL::FragmentDB::BuildBondsProcessor::BuildBondsProcessor
BuildBondsProcessor()
BALL::FragmentDB::BuildBondsProcessor::finish
virtual bool finish()
BALL::FragmentDB::BuildBondsProcessor::storeConnections_
void storeConnections_(Fragment &fragment)
BALL::FragmentDB::BuildBondsProcessor::ConnectionList
std::list< Connection > ConnectionList
Definition fragmentDB.h:359
BALL::FragmentDB::BuildBondsProcessor::bonds_built_
Size bonds_built_
Definition fragmentDB.h:462
BALL::FragmentDB::BuildBondsProcessor::buildFragmentBonds
Size buildFragmentBonds(Fragment &fragment) const
BALL::FragmentDB::BuildBondsProcessor::setFragmentDB
void setFragmentDB(const FragmentDB &fragment_db)
Set the fragment database.
BALL::FragmentDB::BuildBondsProcessor::getNumberOfBondsBuilt
Size getNumberOfBondsBuilt()
Return the number of bonds built during the last application.
BALL::FragmentDB::NoFragmentNode::filename_
string filename_
Definition fragmentDB.h:95
BALL::FragmentDB::NoFragmentNode::~NoFragmentNode
~NoFragmentNode()
Definition fragmentDB.h:92
BALL::FragmentDB::NoFragmentNode::NoFragmentNode
NoFragmentNode(const char *file, int line, const string &filename)
BALL::FragmentDB::NormalizeNamesProcessor
Definition fragmentDB.h:256
BALL::FragmentDB::NormalizeNamesProcessor::~NormalizeNamesProcessor
virtual ~NormalizeNamesProcessor()
BALL::FragmentDB::NormalizeNamesProcessor::NormalizeNamesProcessor
NormalizeNamesProcessor()
BALL::FragmentDB::NormalizeNamesProcessor::matchName
bool matchName(String &res_name, String &atom_name, const NameMap &map) const
BALL::FragmentDB::NormalizeNamesProcessor::setNamingStandard
void setNamingStandard(const String &naming_standard)
BALL::FragmentDB::NormalizeNamesProcessor::NormalizeNamesProcessor
NormalizeNamesProcessor(FragmentDB &db)
BALL::FragmentDB::NormalizeNamesProcessor::getNamingStandard
const String & getNamingStandard()
BALL::FragmentDB::NormalizeNamesProcessor::setFragmentDB
void setFragmentDB(FragmentDB &db)
BALL::FragmentDB::NormalizeNamesProcessor::finish
virtual bool finish()
BALL::FragmentDB::NormalizeNamesProcessor::start
virtual bool start()
BALL::FragmentDB::build_bonds
BuildBondsProcessor build_bonds
Definition fragmentDB.h:484
BALL::FragmentDB::FragmentDB
FragmentDB(const String &filename)
BALL::FragmentDB::getMoleculeCopy
Molecule * getMoleculeCopy(const String &fragment_name) const
BALL::FragmentDB::getResidue
const Residue * getResidue(const String &fragment_name) const
BALL::FragmentDB::tree
ResourceEntry * tree
Definition fragmentDB.h:488
BALL::FragmentDB::NameMap
StringHashMap< String > NameMap
Definition fragmentDB.h:76
BALL::FragmentDB::getNamingStandards
StringHashMap< NameMap > & getNamingStandards()
BALL::FragmentDB::destroy
void destroy()
BALL::FragmentDB::getNamingStandard
const StringHashMap< String > & getNamingStandard(const String &std) const
BALL::FragmentDB::getResidueCopy
Residue * getResidueCopy(const String &fragment_name) const
BALL::FragmentDB::getFragments
const std::vector< Residue * > & getFragments() const
Definition fragmentDB.h:158
BALL::FragmentDB::FragmentDB
FragmentDB(const FragmentDB &db, bool deep=true)
BALL::FragmentDB::getDefaultNamingStandard
const String & getDefaultNamingStandard() const
BALL::FragmentDB::add_hydrogens
ReconstructFragmentProcessor add_hydrogens
Definition fragmentDB.h:480
BALL::FragmentDB::getFilename
const String & getFilename() const
BALL::FragmentDB::Type
short Type
Definition fragmentDB.h:74
BALL::FragmentDB::isValid
bool isValid() const
BALL::FragmentDB::init
void init()
BALL::FragmentDB::FragmentTypes
FragmentTypes
Definition fragmentDB.h:60
BALL::FragmentDB::TYPE__MOLECULE
@ TYPE__MOLECULE
Definition fragmentDB.h:64
BALL::FragmentDB::TYPE__UNKNOWN
@ TYPE__UNKNOWN
Definition fragmentDB.h:61
BALL::FragmentDB::TYPE__RESIDUE
@ TYPE__RESIDUE
Definition fragmentDB.h:63
BALL::FragmentDB::TYPE__FRAGMENT
@ TYPE__FRAGMENT
Definition fragmentDB.h:62
BALL::FragmentDB::getReferenceFragment
const Fragment * getReferenceFragment(const Fragment &fragment) const
BALL::FragmentDB::FragmentDB
FragmentDB()
BALL::FragmentDB::getAvailableNamingStandards
std::vector< String > getAvailableNamingStandards() const
BALL::FragmentDB::getFragmentCopy
Fragment * getFragmentCopy(const String &fragment_name) const
BALL::FragmentDB::normalize_names
NormalizeNamesProcessor normalize_names
Definition fragmentDB.h:476
BALL::FragmentDB::getFragmentType
FragmentDB::Type getFragmentType(const String &fragment_name) const
BALL::FragmentDB::getFragment
const Fragment * getFragment(const String &fragment_name) const
BALL::FragmentDB::setFilename
void setFilename(const String &filename)
BALL::FragmentDB::~FragmentDB
virtual ~FragmentDB()
BALL::FragmentDB::has
bool has(const String &fragment_name) const
BALL::FragmentDB::AddHydrogensProcessor
friend class FragmentDB::AddHydrogensProcessor
Definition fragmentDB.h:49
BALL::FragmentDB::getVariantNames
list< String > getVariantNames(const String &name) const
BALL::Fragment
Definition fragment.h:22
BALL::HashMap
HashMap class based on the STL map (containing serveral convenience functions).
Definition hashMap.h:74
BALL::Molecule
Definition molecule.h:31
BALL::Processor::Result
int Result
Definition processor.h:36
BALL::PropertyManager
Definition property.h:344
BALL::ReconstructFragmentProcessor
Definition reconstructFragmentProcessor.h:35
BALL::Residue
Definition residue.h:38
BALL::ResourceEntry
Definition resourceFile.h:43
BALL::StringHashMap
Definition stringHashMap.h:42
BALL::String
Definition string.h:57
BALL::UnaryProcessor< Fragment >::UnaryProcessor
UnaryProcessor()
Definition processor.h:69
BALL_CREATE_DEEP
#define BALL_CREATE_DEEP(name)
Definition create.h:26
molecule.h
BALL
Definition constants.h:13
BALL::Size
BALL_SIZE_TYPE Size
Definition COMMON/global.h:114
BALL::Position
BALL_SIZE_TYPE Position
Definition COMMON/global.h:140
std
STL namespace.
reconstructFragmentProcessor.h
residue.h
stringHashMap.h
BALL::FragmentDB::BuildBondsProcessor::Connection
Definition fragmentDB.h:349
BALL::FragmentDB::BuildBondsProcessor::Connection::order
Bond::Order order
Definition fragmentDB.h:353
BALL::FragmentDB::BuildBondsProcessor::Connection::delta
float delta
Definition fragmentDB.h:355
BALL::FragmentDB::BuildBondsProcessor::Connection::atom
Atom * atom
Definition fragmentDB.h:350
BALL::FragmentDB::BuildBondsProcessor::Connection::type_name
String type_name
Definition fragmentDB.h:351
BALL::FragmentDB::BuildBondsProcessor::Connection::dist
float dist
Definition fragmentDB.h:354
BALL::FragmentDB::BuildBondsProcessor::Connection::connect_to
String connect_to
Definition fragmentDB.h:352