RxDock 0.1.0
A fast, versatile, and open-source program for docking ligands to proteins and nucleic acids
Loading...
Searching...
No Matches
ChromElement.h
1/***********************************************************************
2 * The rDock program was developed from 1998 - 2006 by the software team
3 * at RiboTargets (subsequently Vernalis (R&D) Ltd).
4 * In 2006, the software was licensed to the University of York for
5 * maintenance and distribution.
6 * In 2012, Vernalis and the University of York agreed to release the
7 * program as Open Source software.
8 * This version is licensed under GNU-LGPL version 3.0 with support from
9 * the University of Barcelona.
10 * http://rdock.sourceforge.net/
11 ***********************************************************************/
12
13// Abstract interface for all chromosome elements (degrees of freedom)
14#ifndef RBTCHROMELEMENT_H_
15#define RBTCHROMELEMENT_H_
16
17#include "rxdock/Config.h"
18#include "rxdock/Rand.h"
19
20namespace rxdock {
21
22// Typedefs for crossover data.
23// To prevent splitting (for example) an orientation or position vector in two
24// during crossover, we convert the chromosome to a vector of vector of doubles
25// An orientation vector (3 Euler angles) is a single XOverElement
26// GetVector(std::vector<double>&) returns a flat vector of doubles (for use by
27// Simplex) GetVector(XOverList&) returns a vector of XOverElements (for
28// use by crossover)
29typedef std::vector<double> XOverElement;
30typedef XOverElement::iterator XOverElementIter;
31typedef XOverElement::const_iterator XOverElementConstIter;
32typedef std::vector<XOverElement> XOverList;
33typedef XOverList::iterator XOverListIter;
34typedef XOverList::const_iterator XOverListConstIter;
35
37public:
38 // Class type string
39 static const std::string _CT;
40 // Threshold used to assess equality of two chromosome elements
41 static double _THRESHOLD;
42
43 RBTDLL_EXPORT static double &GetThreshold();
44
45 // General enum for defining types of chromosome element flexibility.
46 // For use by subclasses of ChromElement if desired.
47 // There is no functionality in the base class that uses this enum.
48 enum eMode { FIXED = 0, TETHERED = 1, FREE = 2 };
49 // Static methods to convert from mode enum to string and vice versa
50 static eMode StrToMode(const std::string &modeStr); // case insensitive
51 static std::string RBTDLL_EXPORT
52 ModeToStr(eMode mode); // returns "FIXED", "TETHERED" or "FREE"ss
53
54 virtual ~ChromElement();
55 //
56 // INTERFACE METHODS - must be implemented in subclasses
57 //
58 // Resets the chromosome element to its initial value (extracted from
59 // model coords at time of construction)
60 virtual void Reset() = 0;
61 // Randomises the chromosome element within the context of any restraints
62 virtual void Randomise() = 0;
63 // Mutates the chromosome element
64 // relStepSize = fraction (0.0->1.0) of maximum defined step size
65 virtual void Mutate(double relStepSize) = 0;
66 // Updates the chromosome element to match the current model coords
67 virtual void SyncFromModel() = 0;
68 // Updates the model coords to match the chromosome element
69 virtual void SyncToModel() = 0;
70 // Creates an independent clone
71 // The current value of the cloned element should match the current value
72 // of this element.
73 virtual ChromElement *clone() const = 0;
74 // Gets the number of double values needed to represent this
75 // chromosome element
76 virtual int GetLength() const = 0;
77 // Gets the number of vectors of double values needed to represent this
78 // chromosome element for crossover purposes
79 // e.g. an orientation vector consists of 3 doubles, but should be crossed
80 // over as a single intact entity
81 virtual int GetXOverLength() const = 0;
82 // Converts chromosome element to a vector of double values,
83 // Number of double values appended should match GetLength().
84 // v = vector of doubles to append to.
85 virtual void GetVector(std::vector<double> &v) const = 0;
86 // Converts chromosome element to a vector of XOverElements
87 // where each XOverElement is itself a vector of double values
88 // v = vector of XOverElements to append to.
89 virtual void GetVector(XOverList &v) const = 0;
90 // Updates chromosome element from a vector of double values,
91 // Number of double values read should match GetLength().
92 // v = vector of doubles to extract from
93 // i = index of next vector element to read (should be updated by method)
94 virtual void SetVector(const std::vector<double> &v, int &i) = 0;
95 // Updates chromosome element from a vector of XOverElements,
96 // Number of XOverElements read should match GetXOverLength().
97 // v = vector of XOverElements to extract from
98 // i = index of next vector element to read (should be updated by method)
99 virtual void SetVector(const XOverList &v, int &i) = 0;
100 // Gets the vector of absolute step sizes that correspond to each double
101 // value.
102 virtual void GetStepVector(std::vector<double> &v) const = 0;
103 // Gets the maximum relative difference between this element and another
104 // element as represented by the vector. Differences should be normalised by
105 // the step size. This method is provided to allow better comparisons between
106 // values that are difficult to compare by simple numerical differences. e.g.
107 // Dihedral angles are cyclical, therefore -180 and + 179 only differ by 1
108 // deg.
109 virtual double CompareVector(const std::vector<double> &v, int &i) const = 0;
110 //
111 // IMPLEMENTED VIRTUAL METHODS
112 //
113 // Invalid operation in base class
114 virtual void Add(ChromElement *pChromElement);
115 // Prints details of element to stream (null implementation in base class)
116 virtual void Print(std::ostream &s) const {}
117 //
118 // NON-VIRTUAL METHODS
119 //
120 Rand &GetRand() const { return m_rand; }
121 void CauchyMutate(double mean, double variance);
122 // Compares two chromosome elements. Returns -1 if the comparison is invalid
123 //(unequal lengths), else returns the maximum relative pair-wise difference
124 // as returned by CompareVector.
125 RBTDLL_EXPORT double Compare(const ChromElement &c) const;
126 // Returns true if chromosome elements have near-equal values.
127 // i.e. if Compare(c) < threshold
128 // Returns false if comparison is invalid (unequal lengths)
129 bool Equals(const ChromElement &c, double threshold) const;
130 // Convenience method that calls SetVector(const std::vector<double>& v,
131 // Int& i) with i initialised to zero
132 void SetVector(const std::vector<double> &v);
133 // Convenience method that calls SetVector(const XOverList& v, Int& i)
134 // with i initialised to zero
135 void SetVector(const XOverList &v);
136 // operator== and operator!= are implemented by calling Equals with the
137 // static _THRESHOLD value
138 RBTDLL_EXPORT friend bool operator==(const ChromElement &c1,
139 const ChromElement &c2);
140 RBTDLL_EXPORT friend bool operator!=(const ChromElement &c1,
141 const ChromElement &c2);
142 // operator<< is implemented by calling Print()
143 RBTDLL_EXPORT friend std::ostream &operator<<(std::ostream &s,
144 const ChromElement &c);
145
146protected:
147 RBTDLL_EXPORT ChromElement();
148 RBTDLL_EXPORT ChromElement(const ChromElement &c);
149 RBTDLL_EXPORT ChromElement &operator=(const ChromElement &c);
150 // Helper method to check that index i is in range [0,v.size()}
151 // and that v has sufficient elements remaining to satisfy
152 // GetLength()
153 bool VectorOK(const std::vector<double> &v, unsigned int i) const;
154 // Helper method to check that index i is in range [0,v.size()}
155 // and that v has sufficient elements remaining to satisfy
156 // GetXOverLength()
157 bool VectorOK(const XOverList &v, unsigned int i) const;
158
159private:
160 Rand &m_rand; // Reference to singleton random number generator
161};
162
164typedef std::vector<ChromElement *>
165 ChromElementList; // Vector of regular pointers
166typedef ChromElementList::iterator ChromElementListIter;
167typedef ChromElementList::const_iterator ChromElementListConstIter;
168
169bool operator==(const ChromElement &c1, const ChromElement &c2);
170bool operator!=(const ChromElement &c1, const ChromElement &c2);
171std::ostream &operator<<(std::ostream &s, const ChromElement &c);
172
173// 2-point crossover
174RBTDLL_EXPORT void Crossover(ChromElement *pChr1, ChromElement *pChr2,
175 ChromElement *pChr3, ChromElement *pChr4);
176
177} // namespace rxdock
178
179#endif /*RBTCHROMELEMENT_H_*/
Definition ChromElement.h:36
Definition Rand.h:32
Definition SmartPointer.h:48