calculation.h

Go to the documentation of this file.
00001 /***************************************************************************
00002                          calculation.h  -  description
00003                              -------------------
00004     begin                : Thu April 28 2005
00005     copyright            : (C) 2005-2006 by Ben Swerts
00006     email                : bswerts@users.sourceforge.net
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00020 
00021 #ifndef CALCULATION_H
00022 #define CALCULATION_H
00023 
00025 
00026 // STL header files
00027 #include <list>
00028 #include <vector>
00029 
00030 // Qt forward class declarations & header files
00031 class QDomElement;
00032 class QProcess;
00033 #include <qstringlist.h>
00034 class QWidget;
00035 
00036 // Xbrabo forward class declarations
00037 class AtomSet;
00038 
00039 // Base class header file
00040 #include <qobject.h>
00041 
00043 class Calculation : public QObject
00044 {
00045   Q_OBJECT
00046 
00047   public:
00048     // constructor/destructor
00049     Calculation(AtomSet* atomset, QWidget* parent = 0, const char* name = 0);   // constructor
00050     ~Calculation();                     // destructor
00051    
00052     // public enums
00053     enum Errors{NoError, UndefinedError, NoConvergence, CloseNuclei, MaxCyclesExceeded, ManualStop}; 
00054 
00055     // public member functions for starting/stopping the calculation
00056     bool start();                       // starts the calculation
00057     bool pause();                       // pauses the calculation
00058     bool stop();                        // stops the calculation (ask whether to stop immediately or after the current step is finished)
00059 
00060     // public member functions for setting up the calculation
00061     void setModified(const bool status = true);   // sets the 'modified' status of the calculation
00062     void setBraboInput(const QStringList stdInput, const QStringList basissets, const QString startVector, const bool preferStartVector, const unsigned int startVectorSize1, const unsigned int startVectorSize2);         // sets the BRABO input file, the list of basisets to be used and the place where the starting vector should be copied from
00063     void setStockInput(const QStringList stin, const QString atdens = QString::null); // sets the STOCK input file and the specific atdens file
00064     void setRelaxInput(const QStringList aff, const QStringList maff, const unsigned int updateFreq, const unsigned int maxSteps, const std::vector<unsigned int>& steps, const std::vector<double>& factors);    // sets the Relax AFF (header) file, its update frequency and scalefactor info
00065     void setCalculationType(const unsigned int type, const unsigned int buur); // SPE/OPT/FREQ, NoBuur/PC/SM
00066     void setParameters(const QString name, const QString dir, const bool format);         // Some more needed parameters
00067     void setBackup(const unsigned int freq, const bool brabo = false, const bool stock = false, const bool relax = false, const bool aff = false, const bool crd = false);// Sets the backup options
00068     void setContinuable(const bool status);       // Sets whether an optimization can be continued after having it stopped.
00069 
00070     // public member functions for returning data
00071     bool isRunning() const;             // returns whether the calculation is running
00072     bool isPaused() const;              // returns whether the calculation is paused
00073     void getRefinementParameters(bool& largestCart, bool& magnCart, bool& largestInt, bool& magnInt, bool& largestShift);         // Returns the 5 refinement criteria for the latest cycle
00074     void getAvailableOutputs(std::vector<unsigned int>& cycles, std::vector<bool>& brabo, std::vector<bool>& stock, std::vector<bool>& relax, std::vector<bool>& aff);    // Returns the cycles for which outputs are available
00075     QStringList braboOutput(const unsigned int step = 0);   // Returns the contents of the Brabo output file for a step
00076     QStringList stockOutput(const unsigned int step = 0);   // Returns the contents of the Stock output file for a step
00077     QStringList relaxOutput(const unsigned int step = 0);   // Returns the contents of the Relax output file for a step
00078     QStringList affOutput(const unsigned int step = 0);     // Returns the contents of the AFF file for a step
00079 
00080     // public member functions for IO
00081     void loadCML(const QDomElement* root);        // loads the settings from file
00082     void saveCML(QDomElement* root);    // saves the settings to file 
00083     void writeInput();                  // writes all input files
00084     void clean();                       // cleans up the calculation directory
00085 
00086   signals:
00087     void newIteration(unsigned int, double);      
00088     void newCycle(unsigned int);        
00089     void updated();                     
00090     void finished(unsigned int error);  
00091     void modified();                    
00092 
00093   private slots:
00094     void finishBrabo();                 // Does cleanup of a BRABO run
00095     void readStdOutBrabo();             // Reads output from the process running BRABO
00096     void finishStock();                 // Does cleanup of a STOCK run
00097     void finishMAFF();                  // Does cleanup of a MAFF run
00098     void finishCnvrtAFF();              // Does cleanup of a CNVRTAFF run
00099     void finishRelax();                 // Does cleanup of a RELAX run
00100     void readStdOutAll();               // Reads output from the process without checking the contents
00101 
00102   private:
00103     // private enums
00104     enum CalculationStep{NEW_CYCLE, ACHAR, BRABO, BUUR, CNVRTAFF, DISTOR, FORKON, MAFF, RELAX, STOCK, UPDATE};        
00105 
00106     // private member functions
00107     bool checkBasissets();              // checks whether all basisset files given in basissetList exist
00108     bool checkExecutables();            // checks whether all needed executables are present
00109     bool makeDirCurrent(const QString dir, const QString title);      // switches to the desired directory
00110     bool copyStartVector();             // copies startVectorFile to the calculation directory
00111     void doNextStep();                  // starts the next step of the calculation
00112     void runBrabo();                    // starts a BRABO run
00113     void runStock();                    // starts a STOCK run
00114     void runMAFF();                     // starts a MAFF run
00115     void runCnvrtAFF();                 // starts a CNVRTAFF run
00116     void runRelax();                    // starts a RELAX run
00117     void runCleanup();                  // cleanup at the end of a calculation
00118     void runUpdate();                   // updates the AtomSet with the newly calculated properties (and coordinates)
00119     double scaleFactor(const unsigned int step);  // returns the scalefactor corresponding to the optimization step
00120     void backupOutputs();               // does a backup of requested output files
00121     bool copyFile(const QString source, const QString destination);   // blocking copy
00122     QStringList output(const QString extension, const unsigned int step = 0);     // Returns the contents of a file with the given extension for a certain step
00123     std::vector<double> loadFromPunch(const QString code, const unsigned int numValues, const unsigned int fieldSize, const unsigned int fieldsPerLine);        // Reads data from the punch file in fixed format
00124 
00125     // private member data
00126     AtomSet* atoms;                     
00127     QWidget* parentWidget;              
00128     QStringList braboInput;             
00129     QStringList stockInput;             
00130     QStringList relaxInput;             
00131     QStringList maffInput;              
00132     QStringList basissetList;           
00133     QString startVectorFile;            
00134     QString atdensFile;                 
00135     unsigned int affUpdateFreq;         
00136     unsigned int calculationType;       
00137     unsigned int crystalType;           
00138     bool updateBraboInput;              
00139     bool updateStockInput;              
00140     bool updateRelaxInput;              
00141     bool doBasissetCheck;               
00142     bool copyAtdens;                    
00143     bool calcRunning;                   
00144     bool calcPaused;                    
00145     QString calcName;                   
00146     QString calcDir;                    
00147     QProcess* calcProcess;              
00148     unsigned int calcMaxCycle;          
00149     bool calcXF;                        
00150     unsigned int currentCycle;          
00151     bool calcSuccess;                   
00152     std::list<CalculationStep> calculationSteps;  
00153     std::vector<unsigned int> scaleSteps;         
00154     std::vector<double> scaleFactors;             
00155     bool stopRequested;                 
00156     unsigned int backupFrequency;       
00157     bool backupBrabo;                   
00158     bool backupStock;                   
00159     bool backupRelax;                   
00160     bool backupAFF;                     
00161     bool backupCRD;                     
00162     bool calcModified;                  
00163     unsigned int calcError;             
00164     bool calcContinuable;               
00165 };
00166 
00167 #endif
00168 

Generated on Fri May 19 14:31:54 2006 for Brabosphere by  doxygen 1.4.6-NO