RxDock 0.1.0
A fast, versatile, and open-source program for docking ligands to proteins and nucleic acids
Loading...
Searching...
No Matches
Population.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// Manages a population of genomes.
14// Main public method (GAstep) performs one iteration of a GA.
15#ifndef _RBTPOPULATION_H_
16#define _RBTPOPULATION_H_
17
18#include "rxdock/Error.h"
19#include "rxdock/Genome.h"
20
21#include <nlohmann/json.hpp>
22
23using json = nlohmann::json;
24
25namespace rxdock {
26
27class BaseSF; // forward definition
28
30public:
31 static const std::string _CT;
32 // Sole constructor to create a randomised genome population of a fixed size.
33 // pChr is the seed chromosome to clone to create each genome.
34 // size is the population size to create.
35 // pSF is the scoring function used to rank the genomes.
36 // Notes:
37 // 1) Each genome is randomised by calling the Randomise() method
38 // of the underlying chromosome.
39 // 2) Scoring function scores are calculated.
40 // 3) Genomes are sorted by score.
41 // 4) Roulette wheel fitness values are calculated.
42 // 5) Model coords are updated to match the fittest chromosome
43 // An BadArgument error is thrown if size is <=0, or if pChr or pSF is
44 // null.
45 RBTDLL_EXPORT Population(ChromElement *pChr, int size, BaseSF *pSF);
46 virtual ~Population();
47
48 friend void to_json(json &j, const Population &population);
49 friend void from_json(const json &j, Population &population);
50
51 // Gets the maximum size of the population as defined in the constructor.
52 int GetMaxSize() const { return m_size; }
53 // Gets the actual size of the population (may be < GetMaxSize())
54 int GetActualSize() const { return m_pop.size(); }
55 // Gets the best genome in the sorted population (element zero).
56 RBTDLL_EXPORT GenomePtr Best() const;
57 // Gets the average raw score across entire population
58 double GetScoreMean() const { return m_scoreMean; }
59 // Gets the raw score variance across entire population
60 double GetScoreVariance() const { return m_scoreVariance; }
61 // Gets the vector of genomes in the population.
62 const GenomeList &GetGenomeList() const { return m_pop; }
63
64 // Gets the scoring function used for ranking genomes
65 BaseSF *GetSF() const { return m_pSF; }
66 // Sets the scoring function used for ranking genomes
67 // Forces a recalculation of the genome scores, and the roulette wheel fitness
68 // values SetSF should be called whenever the scoring function parameters have
69 // changed e.g. in between GA stages. An BadArgument error is thrown if pSF
70 // is null. Model coords are updated to match the fittest chromosome
71 void SetSF(BaseSF *pSF);
72
73 // Main method for performing a GA iteration
74 RBTDLL_EXPORT void
75 GAstep(int nReplicates, // Number of new genomes to create in the iteration
76 double relStepSize, // Relative step size for chromosome mutations
77 double equalityThreshold, // Equality threshold for genomes
78 double pcross, // Probability of crossover
79 bool xovermut, // if true, perform cauchy mutation following crossover
80 bool cmutate // true=cauchy mutations, false=regular mutations
81 );
82 RBTDLL_EXPORT GenomePtr RouletteWheelSelect() const;
83
84 void Print(std::ostream &) const;
85 friend std::ostream &operator<<(std::ostream &, const Population &);
86
87private:
88 // Merges the new individuals created into the main population
89 // Duplicate genomes are removed (based on equality of chromosome elements,
90 // not scores)
91 void MergeNewPop(GenomeList &newPop, double equalityThreshold);
92 void EvaluateRWFitness();
93 Population(const Population &); // Disable
94 Population &operator=(const Population &); // Disable
95
96 GenomeList m_pop; // The population of genomes
97 unsigned int m_size; // The maximum size of the population
98 double m_c; // Sigma Truncation Multiplier
99 BaseSF *m_pSF; // The scoring function
100 Rand &m_rand; // reference to the singleton random number generator
101 double m_scoreMean; // the average raw score across all genomes
102 double m_scoreVariance; // the variance of raw scores across all genomes
103};
104
105void to_json(json &j, const Population &population);
106void from_json(const json &j, Population &population);
107
109
110} // namespace rxdock
111
112#endif //_RBTPOPULATION_H_
Definition BaseSF.h:28
Definition ChromElement.h:36
Definition Population.h:29
Definition Rand.h:32
Definition SmartPointer.h:48