RxDock 0.1.0
A fast, versatile, and open-source program for docking ligands to proteins and nucleic acids
Loading...
Searching...
No Matches
Genome.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// Genome for roulette wheel selection.
14// Manages a chromosome element, an associated raw score from a scoring function
15// and a scaled fitness value for roulette wheel selection
16#ifndef _RBT_GENOME_H_
17#define _RBT_GENOME_H_
18
19#include "rxdock/ChromElement.h"
20
21#include <nlohmann/json.hpp>
22
23using json = nlohmann::json;
24
25namespace rxdock {
26
27class BaseSF;
28
29class Genome {
30public:
31 static const std::string _CT;
32 // Sole constructor accepting an existing chromosome.
33 // A clone of the existing chromosome is stored,
34 // and is deleted in the Genome destructor
35 Genome(ChromElement *pChr);
36 // Copy constructor and Assignment operator.
37 // The underlying chromosome is cloned during the copy.
38 Genome(const Genome &);
39 Genome &operator=(const Genome &);
40 Genome *clone() const;
41 virtual ~Genome();
42
43 friend void to_json(json &j, const Genome &genome);
44 friend void from_json(const json &j, Genome &genome);
45
46 // Gets the underlying chromosome
47 ChromElement *GetChrom() const { return m_chrom; }
48
49 // Sets the raw score from the scoring function.
50 // Model coordinates are updated to reflect the current chromosome element
51 // values. Scores are negated so that higher positive scores are better. pSF
52 // is a pointer to a scoring function object. If pSF is null, a zero score is
53 // set.
54 void SetScore(BaseSF *pSF);
55 // Gets the stored raw score (without re-evaluation of the scoring function).
56 double GetScore() const { return m_score; }
57
58 // ROULETTE WHEEL SELECTION METHODS
59 // The following three methods should be used only in the context of
60 // genome lists sorted into ascending order by score.
61 // See Population::EvaluateRWFitness for example of use.
62 //
63 // Sets the fitness value used for roulette wheel selection
64 // sigmaOffset is the calculated offset for scaling using sigma truncation
65 //(Goldberg page 124)
66 // partialSum is the partial sum of all previous fitness values in the sorted
67 // genome list.
68 double SetRWFitness(double sigmaOffset, double partialSum);
69 // Normalises the roulette wheel fitness values to lie between 0 and 1
70 // total is the total sum of absolute fitness values returned by the last call
71 // to SetRWFitness
72 void NormaliseRWFitness(double total);
73 // Gets the fitness value for roulette wheel selection
74 double GetRWFitness() const { return m_RWFitness; }
75
76 // Tests equality based on chromosome element values.
77 // Does not take score into account.
78 bool Equals(const Genome &g, double threshold) const {
79 return m_chrom->Equals(*(g.m_chrom), threshold);
80 }
81 friend bool operator==(const Genome &g1, const Genome &g2) {
82 return g1.Equals(g2, ChromElement::_THRESHOLD);
83 }
84
85 void Print(std::ostream &) const;
86 friend std::ostream &operator<<(std::ostream &s, const Genome &g);
87
88private:
89 Genome(); // Default constructor disabled
90
91private:
93 // Private data
95 ChromElement *m_chrom;
96 double m_score; // raw value of the scoring function
97 double m_RWFitness; // scaled value of the raw score suitable for use
98 // with roulette wheel selection
99};
100
101void to_json(json &j, const Genome &genome);
102void from_json(const json &j, Genome &genome);
103
104// Useful typedefs
105typedef SmartPtr<Genome> GenomePtr; // Smart pointer
106typedef std::vector<GenomePtr> GenomeList; // Vector of smart pointers
107typedef GenomeList::iterator GenomeListIter;
108typedef GenomeList::const_iterator GenomeListConstIter;
109
110// Compare class to compare different genomes inside a population
111// This is used to sort the genomes in a population depending
112// of the value of their scoring function.
114public:
115 bool operator()(const Genome *pG1, const Genome *pG2) const {
116 return (pG1->GetScore() > pG2->GetScore());
117 }
118};
119
120// STL binary predicate to compare two Genome* for equality.
121// Tests equality based on chromosome element values.
122// Does not take score into account.
123// Uses operator== which ultimately calls ChromElement::Equals()
124class isGenome_eq : public std::function<bool(Genome *, Genome *)> {
125private:
126 double m_threshold; // equality threshold
127public:
128 explicit isGenome_eq(double threshold) : m_threshold(threshold) {}
129 bool operator()(const Genome *pG1, const Genome *pG2) const {
130 return pG1->Equals(*pG2, m_threshold);
131 }
132};
133
134} // namespace rxdock
135
136#endif //_RBT_GENOME_H_
Definition BaseSF.h:28
Definition ChromElement.h:36
Definition Genome.h:113
Definition Genome.h:29
Definition SmartPointer.h:48
Definition Genome.h:124