root/src/xtalopt/xtalopt.h @ a426e387c8cde074662fe6aa3a60c39141e5390b

Revision a426e387c8cde074662fe6aa3a60c39141e5390b, 7.1 KB (checked in by David C. Lonie <loniedavid@…>, 13 months ago)

Add XtalOpt::generateNewMXtal().

  • Property mode set to 100644
Line 
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
34namespace GlobalSearch {
35  class SlottedWaitCondition;
36}
37
38namespace 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    enum MXtalOperator {
89      MXOP_Crossover = 0,
90      MXOP_Reconf,
91      MXOP_Swirl
92    };
93
94    Xtal* generateRandomXtal(uint generation, uint id);
95    MolecularXtal* generateRandomMXtal(uint generation, uint id);
96    bool addSeed(const QString & filename);
97
98    GlobalSearch::Structure* replaceWithRandom(GlobalSearch::Structure *s,
99                                               const QString & reason = "");
100    Xtal* replaceWithRandomXtal(Xtal *s,
101                                const QString & reason = "");
102    MolecularXtal* replaceWithRandomMXtal(MolecularXtal *s,
103                                          const QString & reason = "");
104
105    GlobalSearch::Structure* replaceWithOffspring(GlobalSearch::Structure *s,
106                                                  const QString &reason = "");
107    Xtal* replaceWithOffspringXtal(Xtal *s,
108                                   const QString &reason = "");
109    MolecularXtal* replaceWithOffspringMXtal(MolecularXtal *s,
110                                             const QString &reason = "");
111
112    bool checkLimits();
113    bool checkXtal(Xtal *xtal, QString * err = NULL);
114    QString interpretTemplate(const QString & templateString, GlobalSearch::Structure* structure);
115    QString getTemplateKeywordHelp();
116    bool load(const QString & filename, const bool forceReadOnly = false);
117
118    uint numInitial;                    // Number of initial structures
119
120    uint popSize;                       // Population size
121
122    uint p_cross;                       // Percentage of new structures by crossover
123    uint p_strip;                       // Percentage of new structures by stripple
124    uint p_perm;                        // Percentage of new structures by permustrain
125
126    uint cross_minimumContribution;     // Minimum contribution each parent in crossover
127
128    double strip_amp_min;               // Minimum amplitude of periodic displacement
129    double strip_amp_max;               // Maximum amplitude of periodic displacement
130    uint strip_per1;                    // Number of cosine waves in direction 1
131    uint strip_per2;                    // Number of cosine waves in direction 2
132    double strip_strainStdev_min;       // Minimum standard deviation of epsilon in the stripple strain matrix
133    double strip_strainStdev_max;       // Maximum standard deviation of epsilon in the stripple strain matrix
134
135    uint perm_ex;                       // Number of times atoms are swapped in permustrain
136    double perm_strainStdev_max;        // Max standard deviation of epsilon in the permustrain strain matrix
137
138    double
139      a_min,            a_max,          // Limits for lattice
140      b_min,            b_max,
141      c_min,            c_max,
142      alpha_min,        alpha_max,
143      beta_min,         beta_max,
144      gamma_min,        gamma_max,
145      vol_min, vol_max, vol_fixed,
146      scaleFactor, minRadius;
147
148    double tol_xcLength;                // Duplicate matching tolerances
149    double tol_xcAngle;
150    double tol_spg;
151
152    // MXtalOptGenetic params
153    // - Crossover
154    int mga_p_cross;                      //! [0, 100]
155    double mga_cross_minimumContribution; //! [0.0, 50.0]
156    // - Reconf
157    int mga_p_reconf;                     //! [0, 100]
158    int mga_reconf_minSubMolsToReplace;   //! [0, sum(i, mcomp[i].quantity)]
159    int mga_reconf_maxSubMolsToReplace;   //! [0, sum(i, mcomp[i].quantity)]
160    double mga_reconf_minStrain;          //! [0, 1]
161    double mga_reconf_maxStrain;          //! [0, 1]
162    // - Swirl
163    int mga_p_swirl;                      //! [0, 100]
164    int mga_swirl_minSubMolsToRotate;     //! [0, sum(i, mcomp[i].quantity)]
165    int mga_swirl_maxSubMolsToRotate;     //! [0, sum(i, mcomp[i].quantity)]
166    int mga_swirl_minRotationDegree;      //! [0, 180]
167    double mga_swirl_fracInPlane;         //! [0, 1]
168    double mga_swirl_minStrain;           //! [0, 1]
169    double mga_swirl_maxStrain;           //! [0, 1]
170
171    bool using_fixed_volume;
172    bool using_interatomicDistanceLimit;
173
174    QHash<uint, XtalCompositionStruct> comp;
175    QList<MolecularCompStruct> mcomp;
176    QStringList seedList;
177
178    bool isMolecularXtalSearch() {return m_isMolecular;}
179
180    QMutex *xtalInitMutex;
181
182  public slots:
183    void startSearch();
184    bool initializeSubMoleculeSources(bool notify);
185    void initializeSMSProgressUpdate(int finished, int total);
186    void generateNewStructure();
187    Xtal* generateNewXtal();
188    MolecularXtal* generateNewMXtal();
189    void initializeAndAddXtal(Xtal *xtal,
190                              unsigned int generation,
191                              const QString &parents);
192    void resetSpacegroups();
193    void resetDuplicates();
194    void checkForDuplicates();
195    void setMolecularXtalSearch(bool b)
196    {
197      if (m_isMolecular == b) return;
198      m_isMolecular = b;
199      emit isMolecularXtalSearchChanged(b);
200    }
201
202  Q_SIGNALS:
203    void isMolecularXtalSearchChanged(bool);
204
205   protected:
206    friend class XtalOptUnitTest;
207    void resetSpacegroups_();
208    void resetDuplicates_();
209    void checkForDuplicates_();
210    void generateNewStructure_();
211
212    void interpretKeyword(QString &keyword, GlobalSearch::Structure* structure);
213    QString getTemplateKeywordHelp_xtalopt();
214
215    GlobalSearch::SlottedWaitCondition *m_initWC;
216    bool m_isMolecular;
217    // Used for progress updates during initializeSubMoleculeSource
218    int m_currentSubMolSourceProgress;
219  };
220
221} // end namespace XtalOpt
222
223#endif
Note: See TracBrowser for help on using the browser.