| 1 | /********************************************************************** |
|---|
| 2 | XtalOpt - Holds all data for genetic optimization |
|---|
| 3 | |
|---|
| 4 | Copyright (C) 2009-2011 by David C. Lonie |
|---|
| 5 | |
|---|
| 6 | This program is free software; you can redistribute it and/or modify |
|---|
| 7 | it under the terms of the GNU General Public License as published by |
|---|
| 8 | the Free Software Foundation version 2 of the License. |
|---|
| 9 | |
|---|
| 10 | This program is distributed in the hope that it will be useful, |
|---|
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 13 | GNU General Public License for more details. |
|---|
| 14 | ***********************************************************************/ |
|---|
| 15 | |
|---|
| 16 | #ifndef XTALOPT_H |
|---|
| 17 | #define XTALOPT_H |
|---|
| 18 | |
|---|
| 19 | #include <xtalopt/structures/xtal.h> |
|---|
| 20 | #include <xtalopt/genetic.h> |
|---|
| 21 | |
|---|
| 22 | #include <globalsearch/optbase.h> |
|---|
| 23 | #include <globalsearch/queuemanager.h> |
|---|
| 24 | #include <globalsearch/macros.h> |
|---|
| 25 | |
|---|
| 26 | #include <QtCore/QDebug> |
|---|
| 27 | #include <QtCore/QMutex> |
|---|
| 28 | #include <QtCore/QFuture> |
|---|
| 29 | #include <QtCore/QStringList> |
|---|
| 30 | #include <QtCore/QReadWriteLock> |
|---|
| 31 | |
|---|
| 32 | #include <QtGui/QInputDialog> |
|---|
| 33 | |
|---|
| 34 | namespace GlobalSearch { |
|---|
| 35 | class SlottedWaitCondition; |
|---|
| 36 | } |
|---|
| 37 | |
|---|
| 38 | namespace XtalOpt { |
|---|
| 39 | class MolecularXtal; |
|---|
| 40 | class SubMoleculeSource; |
|---|
| 41 | class XtalOptDialog; |
|---|
| 42 | |
|---|
| 43 | struct XtalCompositionStruct |
|---|
| 44 | { |
|---|
| 45 | double minRadius; |
|---|
| 46 | unsigned int quantity; |
|---|
| 47 | }; |
|---|
| 48 | |
|---|
| 49 | struct MolecularCompStruct |
|---|
| 50 | { |
|---|
| 51 | SubMoleculeSource *source; |
|---|
| 52 | unsigned int quantity; |
|---|
| 53 | }; |
|---|
| 54 | |
|---|
| 55 | class XtalOpt : public GlobalSearch::OptBase |
|---|
| 56 | { |
|---|
| 57 | Q_OBJECT |
|---|
| 58 | |
|---|
| 59 | public: |
|---|
| 60 | explicit XtalOpt(XtalOptDialog *parent); |
|---|
| 61 | virtual ~XtalOpt(); |
|---|
| 62 | |
|---|
| 63 | enum OptTypes { |
|---|
| 64 | OT_VASP = 0, |
|---|
| 65 | OT_GULP, |
|---|
| 66 | OT_PWscf, |
|---|
| 67 | OT_CASTEP |
|---|
| 68 | }; |
|---|
| 69 | |
|---|
| 70 | enum QueueInterfaces { |
|---|
| 71 | QI_LOCAL = 0 |
|---|
| 72 | #ifdef ENABLE_SSH |
|---|
| 73 | , |
|---|
| 74 | QI_PBS, |
|---|
| 75 | QI_SGE, |
|---|
| 76 | QI_SLURM, |
|---|
| 77 | QI_LSF, |
|---|
| 78 | QI_LOADLEVELER |
|---|
| 79 | #endif // ENABLE_SSH |
|---|
| 80 | }; |
|---|
| 81 | |
|---|
| 82 | enum Operators { |
|---|
| 83 | OP_Crossover = 0, |
|---|
| 84 | OP_Stripple, |
|---|
| 85 | OP_Permustrain |
|---|
| 86 | }; |
|---|
| 87 | |
|---|
| 88 | Xtal* generateRandomXtal(uint generation, uint id); |
|---|
| 89 | MolecularXtal* generateRandomMXtal(uint generation, uint id); |
|---|
| 90 | bool addSeed(const QString & filename); |
|---|
| 91 | |
|---|
| 92 | GlobalSearch::Structure* replaceWithRandom(GlobalSearch::Structure *s, |
|---|
| 93 | const QString & reason = ""); |
|---|
| 94 | Xtal* replaceWithRandomXtal(Xtal *s, |
|---|
| 95 | const QString & reason = ""); |
|---|
| 96 | MolecularXtal* replaceWithRandomMXtal(MolecularXtal *s, |
|---|
| 97 | const QString & reason = ""); |
|---|
| 98 | |
|---|
| 99 | GlobalSearch::Structure* replaceWithOffspring(GlobalSearch::Structure *s, |
|---|
| 100 | const QString &reason = ""); |
|---|
| 101 | Xtal* replaceWithOffspringXtal(Xtal *s, |
|---|
| 102 | const QString &reason = ""); |
|---|
| 103 | MolecularXtal* replaceWithOffspringMXtal(MolecularXtal *s, |
|---|
| 104 | const QString &reason = ""); |
|---|
| 105 | |
|---|
| 106 | bool checkLimits(); |
|---|
| 107 | bool checkXtal(Xtal *xtal, QString * err = NULL); |
|---|
| 108 | QString interpretTemplate(const QString & templateString, GlobalSearch::Structure* structure); |
|---|
| 109 | QString getTemplateKeywordHelp(); |
|---|
| 110 | bool load(const QString & filename, const bool forceReadOnly = false); |
|---|
| 111 | |
|---|
| 112 | uint numInitial; // Number of initial structures |
|---|
| 113 | |
|---|
| 114 | uint popSize; // Population size |
|---|
| 115 | |
|---|
| 116 | uint p_cross; // Percentage of new structures by crossover |
|---|
| 117 | uint p_strip; // Percentage of new structures by stripple |
|---|
| 118 | uint p_perm; // Percentage of new structures by permustrain |
|---|
| 119 | |
|---|
| 120 | uint cross_minimumContribution; // Minimum contribution each parent in crossover |
|---|
| 121 | |
|---|
| 122 | double strip_amp_min; // Minimum amplitude of periodic displacement |
|---|
| 123 | double strip_amp_max; // Maximum amplitude of periodic displacement |
|---|
| 124 | uint strip_per1; // Number of cosine waves in direction 1 |
|---|
| 125 | uint strip_per2; // Number of cosine waves in direction 2 |
|---|
| 126 | double strip_strainStdev_min; // Minimum standard deviation of epsilon in the stripple strain matrix |
|---|
| 127 | double strip_strainStdev_max; // Maximum standard deviation of epsilon in the stripple strain matrix |
|---|
| 128 | |
|---|
| 129 | uint perm_ex; // Number of times atoms are swapped in permustrain |
|---|
| 130 | double perm_strainStdev_max; // Max standard deviation of epsilon in the permustrain strain matrix |
|---|
| 131 | |
|---|
| 132 | double |
|---|
| 133 | a_min, a_max, // Limits for lattice |
|---|
| 134 | b_min, b_max, |
|---|
| 135 | c_min, c_max, |
|---|
| 136 | alpha_min, alpha_max, |
|---|
| 137 | beta_min, beta_max, |
|---|
| 138 | gamma_min, gamma_max, |
|---|
| 139 | vol_min, vol_max, vol_fixed, |
|---|
| 140 | scaleFactor, minRadius; |
|---|
| 141 | |
|---|
| 142 | double tol_xcLength; // Duplicate matching tolerances |
|---|
| 143 | double tol_xcAngle; |
|---|
| 144 | double tol_spg; |
|---|
| 145 | |
|---|
| 146 | // MXtalOptGenetic params |
|---|
| 147 | // - Crossover |
|---|
| 148 | int mga_p_cross; //! [0, 100] |
|---|
| 149 | double mga_cross_minimumContribution; //! [0.0, 50.0] |
|---|
| 150 | // - Reconf |
|---|
| 151 | int mga_p_reconf; //! [0, 100] |
|---|
| 152 | int mga_reconf_minSubMolsToReplace; //! [0, sum(i, mcomp[i].quantity)] |
|---|
| 153 | int mga_reconf_maxSubMolsToReplace; //! [0, sum(i, mcomp[i].quantity)] |
|---|
| 154 | double mga_reconf_minStrain; //! [0, 1] |
|---|
| 155 | double mga_reconf_maxStrain; //! [0, 1] |
|---|
| 156 | // - Swirl |
|---|
| 157 | int mga_p_swirl; //! [0, 100] |
|---|
| 158 | int mga_swirl_minSubMolsToRotate; //! [0, sum(i, mcomp[i].quantity)] |
|---|
| 159 | int mga_swirl_maxSubMolsToRotate; //! [0, sum(i, mcomp[i].quantity)] |
|---|
| 160 | int mga_swirl_minRotationDegree; //! [0, 180] |
|---|
| 161 | double mga_swirl_fracInPlane; //! [0, 1] |
|---|
| 162 | double mga_swirl_minStrain; //! [0, 1] |
|---|
| 163 | double mga_swirl_maxStrain; //! [0, 1] |
|---|
| 164 | |
|---|
| 165 | bool using_fixed_volume; |
|---|
| 166 | bool using_interatomicDistanceLimit; |
|---|
| 167 | |
|---|
| 168 | QHash<uint, XtalCompositionStruct> comp; |
|---|
| 169 | QList<MolecularCompStruct> mcomp; |
|---|
| 170 | QStringList seedList; |
|---|
| 171 | |
|---|
| 172 | bool isMolecularXtalSearch() {return m_isMolecular;} |
|---|
| 173 | |
|---|
| 174 | QMutex *xtalInitMutex; |
|---|
| 175 | |
|---|
| 176 | public slots: |
|---|
| 177 | void startSearch(); |
|---|
| 178 | bool initializeSubMoleculeSources(bool notify); |
|---|
| 179 | void initializeSMSProgressUpdate(int finished, int total); |
|---|
| 180 | void generateNewStructure(); |
|---|
| 181 | Xtal* generateNewXtal(); |
|---|
| 182 | void initializeAndAddXtal(Xtal *xtal, |
|---|
| 183 | unsigned int generation, |
|---|
| 184 | const QString &parents); |
|---|
| 185 | void resetSpacegroups(); |
|---|
| 186 | void resetDuplicates(); |
|---|
| 187 | void checkForDuplicates(); |
|---|
| 188 | void setMolecularXtalSearch(bool b) |
|---|
| 189 | { |
|---|
| 190 | if (m_isMolecular == b) return; |
|---|
| 191 | m_isMolecular = b; |
|---|
| 192 | emit isMolecularXtalSearchChanged(b); |
|---|
| 193 | } |
|---|
| 194 | |
|---|
| 195 | Q_SIGNALS: |
|---|
| 196 | void isMolecularXtalSearchChanged(bool); |
|---|
| 197 | |
|---|
| 198 | protected: |
|---|
| 199 | friend class XtalOptUnitTest; |
|---|
| 200 | void resetSpacegroups_(); |
|---|
| 201 | void resetDuplicates_(); |
|---|
| 202 | void checkForDuplicates_(); |
|---|
| 203 | void generateNewStructure_(); |
|---|
| 204 | |
|---|
| 205 | void interpretKeyword(QString &keyword, GlobalSearch::Structure* structure); |
|---|
| 206 | QString getTemplateKeywordHelp_xtalopt(); |
|---|
| 207 | |
|---|
| 208 | GlobalSearch::SlottedWaitCondition *m_initWC; |
|---|
| 209 | bool m_isMolecular; |
|---|
| 210 | // Used for progress updates during initializeSubMoleculeSource |
|---|
| 211 | int m_currentSubMolSourceProgress; |
|---|
| 212 | }; |
|---|
| 213 | |
|---|
| 214 | } // end namespace XtalOpt |
|---|
| 215 | |
|---|
| 216 | #endif |
|---|