relaxbase.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002                         relaxbase.cpp  -  description
00003                              -------------------
00004     begin                : Mon Jun 16 2003
00005     copyright            : (C) 2003-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 
00019 
00026 
00027 
00028 
00030 
00031 // C++ header files
00032 #include <algorithm>
00033 #include <cassert>
00034 #include <cmath>
00035 
00036 // Qt header files
00037 #include <qapplication.h>
00038 #include <qbuttongroup.h>
00039 #include <qcheckbox.h>
00040 #include <qcombobox.h>
00041 #include <qdir.h>
00042 #include <qdom.h>
00043 #include <qfiledialog.h>
00044 #include <qheader.h>
00045 #include <qlabel.h>
00046 #include <qlayout.h>
00047 #include <qlineedit.h>
00048 #include <qlistbox.h>
00049 #include <qlistview.h>
00050 #include <qmessagebox.h>
00051 #include <qprocess.h>
00052 #include <qpushbutton.h>
00053 #include <qradiobutton.h>
00054 #include <qspinbox.h>
00055 #include <qtable.h>
00056 #include <qtextedit.h>
00057 #include <qtoolbutton.h>
00058 #include <qvalidator.h>
00059 #include <qwidgetstack.h>
00060 
00061 // Xbrabo header files
00062 #include "atomset.h"
00063 #include "crdfactory.h"
00064 #include "domutils.h"
00065 #include "iconsets.h"
00066 #include "paths.h"
00067 #include "relaxbase.h"
00068 #include "textviewwidget.h"
00069 #include "utils.h"
00070 #include "version.h"
00071 
00075 
00077 RelaxBase::RelaxBase(AtomSet* atomset, QWidget* parent, const char* name, bool modal, WFlags fl) : RelaxWidget(parent, name, modal, fl),
00078   atoms(atomset)
00080 {
00081   assert(atomset != 0);
00082   
00083   makeConnections();
00084   init();
00085 }
00086 
00088 RelaxBase::~RelaxBase()
00090 {
00091 
00092 }
00093 
00095 void RelaxBase::setName(const QString name)
00098 {
00099   calcName = name;
00100 }
00101 
00103 void RelaxBase::setDescription(const QString description)
00105 {
00106   calcDescription = description;
00107 }
00108 
00110 void RelaxBase::setDir(const QString dir)
00112 {
00113   calcDir = dir;
00114 }
00115 
00117 void RelaxBase::setExtendedFormat(const bool state)
00119 {
00120   calcXF = state;
00121 }
00122 
00124 unsigned int RelaxBase::inputGenerationFrequency()
00127 {
00128   if(!CheckBoxAutogen->isChecked())
00129     return 0; // no regeneration if manually defined
00130   else if(!CheckBoxRegen->isChecked())
00131     return 0; // no regeneration
00132   
00133   return SpinBoxGenFreq->value(); // regeneration frequency
00134 }
00135 
00137 unsigned int RelaxBase::maxSteps()
00140 {
00141   return SpinBoxSteps->value();
00142 }
00143 
00145 void RelaxBase::scaleFactors(vector<unsigned int>& steps, vector<double>& factors)
00148 {
00149   steps.clear();
00150   factors.clear();
00151 
00152   if(data.useOneScaleFactor)
00153   {
00154     steps.push_back(0);
00155     factors.push_back(data.sfacValue1.toDouble());
00156   }
00157   else
00158   {
00159     steps.reserve(data.listNumSteps.size());
00160     steps.assign(data.listNumSteps.begin(), data.listNumSteps.end());
00161     for(QStringList::iterator it = data.listValues.begin(); it != data.listValues.end(); it++)
00162       factors.push_back((*it).toDouble());
00163   }
00164 
00165   qDebug("RelaxBase::scaleFactors:");
00166   for(unsigned int i = 0; i < steps.size(); i++)
00167     qDebug(" %d, step %d, factor %f", i, steps[i], factors[i]);
00168 }
00169   
00171 QStringList RelaxBase::generateInput(const Input type)
00175 {  
00176   QStringList result;  
00177   if(type == RelaxBase::AFF)
00178     return generateAFFHeader();
00179   else if(type == RelaxBase::MAFF)     
00180   {
00181     if(!CheckBoxAutogen->isChecked())
00182       return QStringList(); // this indicates that the aff returned by generateInput(AFF) is the complete one
00183 
00184     result += calcName; // Identification code
00185     if(calcXF)
00186       result += "y"; // use extended format
00187     else
00188       result += "n"; 
00189     switch(ComboBoxType->currentItem())
00190     {
00191       case 0: // GBMA
00192         result += "a"; // GBMA
00193         result += "y"; // automatically generate the bond list
00194         result += "n"; // add extra bonds
00195         if(CheckBoxHBonds->isChecked())
00196           result += "y"; // add H-bonds      
00197         else
00198           result += "n";                
00199         result += "n"; // check all atoms connect ? new option ?
00200         break;
00201       case 1: // BMAT
00202         result += "b";   // A or B => bmat
00203         result += "y";   // Use standard force constants
00204         result += "y";   // Use diagonal force constant matrix
00205         result += "n";   // Input op fort.4
00206         result += generateBmatInput();
00207         break;
00208     }
00209   }
00210   return result;
00211 }
00212 
00214 void RelaxBase::loadCML(const QDomElement* root)
00216 { 
00219   assert(!isVisible());
00220 
00221   const QString prefix = "geometry_optimization_";
00222   QDomNode childNode = root->firstChild();
00223   while(!childNode.isNull())
00224   {
00225     if(childNode.isElement() && childNode.toElement().tagName() == "parameter")
00226     {
00228       if(DomUtils::dictEntry(childNode, prefix + xml.type))
00229         DomUtils::readNode(&childNode, &data.type);
00230       else if(DomUtils::dictEntry(childNode, prefix + xml.autoGenerate))
00231         DomUtils::readNode(&childNode, &data.autoGenerate);
00232       else if(DomUtils::dictEntry(childNode, prefix + xml.autoRegen))
00233         DomUtils::readNode(&childNode, &data.autoRegen);
00234       else if(DomUtils::dictEntry(childNode, prefix + xml.autoGenFreq))
00235         DomUtils::readNode(&childNode, &data.autoGenFreq);
00236       else if(DomUtils::dictEntry(childNode, prefix + xml.autoHBonds))
00237         DomUtils::readNode(&childNode, &data.autoHBonds);
00238       else if(DomUtils::dictEntry(childNode, prefix + xml.useOneScaleFactor))
00239         DomUtils::readNode(&childNode, &data.useOneScaleFactor);
00240       else if(DomUtils::dictEntry(childNode, prefix + xml.sfacValue1))
00241         DomUtils::readNode(&childNode, &data.sfacValue1);
00242       else if(DomUtils::dictEntry(childNode, prefix + xml.sfacValue2))
00243         DomUtils::readNode(&childNode, &data.sfacValue2);
00244       else if(DomUtils::dictEntry(childNode, prefix + xml.sfacNumSteps))
00245         DomUtils::readNode(&childNode, &data.sfacNumSteps);
00246       else if(DomUtils::dictEntry(childNode, prefix + xml.numDIIS))
00247         DomUtils::readNode(&childNode, &data.numDIIS);
00248       else if(DomUtils::dictEntry(childNode, prefix + xml.printShifts))
00249         DomUtils::readNode(&childNode, &data.printShifts);
00250       else if(DomUtils::dictEntry(childNode, prefix + xml.numSteps))
00251         DomUtils::readNode(&childNode, &data.numSteps);
00252 
00253       else if(DomUtils::dictEntry(childNode, prefix + xml.listValues))
00254         DomUtils::readNode(&childNode, &data.listValues);
00255       else if(DomUtils::dictEntry(childNode, prefix + xml.listNumSteps))
00256         DomUtils::readNode(&childNode, &data.listNumSteps);
00257 
00259       else if(DomUtils::dictEntry(childNode, prefix + xml.ic_number))
00260       {
00261         vector<unsigned int> numbers;
00262         DomUtils::readNode(&childNode, &numbers);
00263         data.ic.resize(numbers.size());
00264         for(unsigned int i = 0; i < data.ic.size(); i++)
00265           data.ic[i].number = numbers[i];
00266       }
00267       else if(DomUtils::dictEntry(childNode, prefix + xml.ic_rootItem))
00268       {
00269         vector<bool> rootItems;
00270         DomUtils::readNode(&childNode, &rootItems);
00271         data.ic.resize(rootItems.size());
00272         for(unsigned int i = 0; i < data.ic.size(); i++)
00273           data.ic[i].rootItem = rootItems[i];
00274       }
00275       else if(DomUtils::dictEntry(childNode, prefix + xml.ic_type))
00276       {
00277         QStringList types;
00278         DomUtils::readNode(&childNode, &types);
00279         data.ic.resize(types.size());
00280         for(unsigned int i = 0; i < data.ic.size(); i++)
00281           data.ic[i].type = types[i];
00282       }
00283       else if(DomUtils::dictEntry(childNode, prefix + xml.ic_fc))
00284       {
00285         QStringList fcs;
00286         DomUtils::readNode(&childNode, &fcs);
00287         data.ic.resize(fcs.size());
00288         for(unsigned int i = 0; i < data.ic.size(); i++)
00289           data.ic[i].fc = fcs[i];
00290       }
00291       else if(DomUtils::dictEntry(childNode, prefix + xml.ic_fix))
00292       {
00293         vector<bool> fixed;
00294         DomUtils::readNode(&childNode, &fixed);
00295         data.ic.resize(fixed.size());
00296         for(unsigned int i = 0; i < data.ic.size(); i++)
00297           data.ic[i].fix = fixed[i];
00298       }
00299       else if(DomUtils::dictEntry(childNode, prefix + xml.ic_maximize))
00300       {
00301         vector<bool> maximized;
00302         DomUtils::readNode(&childNode, &maximized);
00303         data.ic.resize(maximized.size());
00304         for(unsigned int i = 0; i < data.ic.size(); i++)
00305           data.ic[i].maximize = maximized[i];
00306       }
00307       else if(DomUtils::dictEntry(childNode, prefix + xml.ic_refValue))
00308       {
00309         QStringList refValues;
00310         DomUtils::readNode(&childNode, &refValues);
00311         data.ic.resize(refValues.size());
00312         for(unsigned int i = 0; i < data.ic.size(); i++)
00313           data.ic[i].refValue = refValues[i];
00314       }
00315       else if(DomUtils::dictEntry(childNode, prefix + xml.ic_weight))
00316       {
00317         QStringList weights;
00318         DomUtils::readNode(&childNode, &weights);
00319         data.ic.resize(weights.size());
00320         for(unsigned int i = 0; i < data.ic.size(); i++)
00321          data.ic[i].weight = weights[i];
00322       }
00323       else if(DomUtils::dictEntry(childNode, prefix + xml.ic_atom1))
00324       {
00325         vector<unsigned int> firstAtoms;
00326         DomUtils::readNode(&childNode, &firstAtoms);
00327         data.ic.resize(firstAtoms.size());
00328         for(unsigned int i = 0; i < data.ic.size(); i++)
00329           data.ic[i].atom1 = firstAtoms[i];
00330       }
00331       else if(DomUtils::dictEntry(childNode, prefix + xml.ic_atom2))
00332       {
00333         vector<unsigned int> secondAtoms;
00334         DomUtils::readNode(&childNode, &secondAtoms);
00335         data.ic.resize(secondAtoms.size());
00336         for(unsigned int i = 0; i < data.ic.size(); i++)
00337           data.ic[i].atom2 = secondAtoms[i];
00338       }
00339       else if(DomUtils::dictEntry(childNode, prefix + xml.ic_atom3))
00340       {
00341         vector<unsigned int> thirdAtoms;
00342         DomUtils::readNode(&childNode, &thirdAtoms);
00343         data.ic.resize(thirdAtoms.size());
00344         for(unsigned int i = 0; i < data.ic.size(); i++)
00345           data.ic[i].atom3 = thirdAtoms[i];
00346       }
00347       else if(DomUtils::dictEntry(childNode, prefix + xml.ic_atom4))
00348       {
00349         vector<unsigned int> fourthAtoms;
00350         DomUtils::readNode(&childNode, &fourthAtoms);
00351         data.ic.resize(fourthAtoms.size());
00352         for(unsigned int i = 0; i < data.ic.size(); i++)
00353           data.ic[i].atom4 = fourthAtoms[i];
00354       }
00355 
00357       else if(DomUtils::dictEntry(childNode, prefix + xml.checkSymmetry))
00358         DomUtils::readNode(&childNode, &data.checkSymmetry);
00359       else if(DomUtils::dictEntry(childNode, prefix + xml.checkSymmX))
00360         DomUtils::readNode(&childNode, &data.checkSymmX);
00361       else if(DomUtils::dictEntry(childNode, prefix + xml.checkSymmY))
00362         DomUtils::readNode(&childNode, &data.checkSymmY);
00363       else if(DomUtils::dictEntry(childNode, prefix + xml.checkSymmZ))
00364         DomUtils::readNode(&childNode, &data.checkSymmZ);
00365       else if(DomUtils::dictEntry(childNode, prefix + xml.checkSymmXY))
00366         DomUtils::readNode(&childNode, &data.checkSymmXY);
00367       else if(DomUtils::dictEntry(childNode, prefix + xml.checkSymmXZ))
00368         DomUtils::readNode(&childNode, &data.checkSymmXZ);
00369       else if(DomUtils::dictEntry(childNode, prefix + xml.checkSymmYZ))
00370         DomUtils::readNode(&childNode, &data.checkSymmYZ);
00371       else if(DomUtils::dictEntry(childNode, prefix + xml.checkSymmXYZ))
00372         DomUtils::readNode(&childNode, &data.checkSymmXYZ);
00373 
00375       else if(DomUtils::dictEntry(childNode, prefix + xml.fixAtom))
00376         DomUtils::readNode(&childNode, &data.fixAtom);
00377       else if(DomUtils::dictEntry(childNode, prefix + xml.fixX))
00378         DomUtils::readNode(&childNode, &data.fixX);
00379       else if(DomUtils::dictEntry(childNode, prefix + xml.fixY))
00380         DomUtils::readNode(&childNode, &data.fixY);
00381       else if(DomUtils::dictEntry(childNode, prefix + xml.fixZ))
00382         DomUtils::readNode(&childNode, &data.fixZ);
00383       else if(DomUtils::dictEntry(childNode, prefix + xml.optExternal))
00384         DomUtils::readNode(&childNode, &data.optExternal);
00385       else if(DomUtils::dictEntry(childNode, prefix + xml.optExternalA))
00386         DomUtils::readNode(&childNode, &data.optExternalA);
00387       else if(DomUtils::dictEntry(childNode, prefix + xml.optExternalB))
00388         DomUtils::readNode(&childNode, &data.optExternalB);
00389       else if(DomUtils::dictEntry(childNode, prefix + xml.optExternalC))
00390         DomUtils::readNode(&childNode, &data.optExternalC);
00391       else if(DomUtils::dictEntry(childNode, prefix + xml.optExternalAlpha))
00392         DomUtils::readNode(&childNode, &data.optExternalAlpha);
00393       else if(DomUtils::dictEntry(childNode, prefix + xml.optExternalBeta))
00394         DomUtils::readNode(&childNode, &data.optExternalBeta);
00395       else if(DomUtils::dictEntry(childNode, prefix + xml.optExternalGamma))
00396         DomUtils::readNode(&childNode, &data.optExternalGamma);
00397       else if(DomUtils::dictEntry(childNode, prefix + xml.mirrorImage))
00398         DomUtils::readNode(&childNode, &data.mirrorImage);
00399       else if(DomUtils::dictEntry(childNode, prefix + xml.writeXYZ))
00400         DomUtils::readNode(&childNode, &data.writeXYZ);
00401 
00402       else if(DomUtils::dictEntry(childNode, prefix + xml.listFixedAtoms))
00403         DomUtils::readNode(&childNode, &data.listFixedAtoms);
00404       else if(DomUtils::dictEntry(childNode, prefix + xml.listFixedXYZ))
00405         DomUtils::readNode(&childNode, &data.listFixedXYZ);
00406 
00408       else if(DomUtils::dictEntry(childNode, prefix + xml.refineThre1))
00409         DomUtils::readNode(&childNode, &data.refineThre1);
00410       else if(DomUtils::dictEntry(childNode, prefix + xml.refineThre2))
00411         DomUtils::readNode(&childNode, &data.refineThre2);
00412       else if(DomUtils::dictEntry(childNode, prefix + xml.refineThre3))
00413         DomUtils::readNode(&childNode, &data.refineThre3);
00414       else if(DomUtils::dictEntry(childNode, prefix + xml.refineThre4))
00415         DomUtils::readNode(&childNode, &data.refineThre4);
00416       else if(DomUtils::dictEntry(childNode, prefix + xml.refineThre5))
00417         DomUtils::readNode(&childNode, &data.refineThre5);
00418       else if(DomUtils::dictEntry(childNode, prefix + xml.maxIter))
00419         DomUtils::readNode(&childNode, &data.maxIter);
00420       else if(DomUtils::dictEntry(childNode, prefix + xml.iterThre1))
00421         DomUtils::readNode(&childNode, &data.iterThre1);
00422       else if(DomUtils::dictEntry(childNode, prefix + xml.iterThre2))
00423         DomUtils::readNode(&childNode, &data.iterThre2);
00424       else if(DomUtils::dictEntry(childNode, prefix + xml.iterThre3))
00425         DomUtils::readNode(&childNode, &data.iterThre3);
00426       else if(DomUtils::dictEntry(childNode, prefix + xml.iterThre4))
00427         DomUtils::readNode(&childNode, &data.iterThre4);
00428 
00430       else if(DomUtils::dictEntry(childNode, prefix + xml.xbonAtom1))
00431         DomUtils::readNode(&childNode, &data.xbonAtom1);
00432       else if(DomUtils::dictEntry(childNode, prefix + xml.xbonAtom2))
00433         DomUtils::readNode(&childNode, &data.xbonAtom2);
00434       else if(DomUtils::dictEntry(childNode, prefix + xml.massType))
00435         DomUtils::readNode(&childNode, &data.massType);
00436       else if(DomUtils::dictEntry(childNode, prefix + xml.setLowFreqs))
00437         DomUtils::readNode(&childNode, &data.setLowFreqs);
00438       else if(DomUtils::dictEntry(childNode, prefix + xml.lowFreqs))
00439         DomUtils::readNode(&childNode, &data.lowFreqs);
00440       else if(DomUtils::dictEntry(childNode, prefix + xml.orden))
00441         DomUtils::readNode(&childNode, &data.orden);
00442 
00443       else if(DomUtils::dictEntry(childNode, prefix + xml.listXbonAtoms1))
00444         DomUtils::readNode(&childNode, &data.listXbonAtoms1);
00445       else if(DomUtils::dictEntry(childNode, prefix + xml.listXbonAtoms2))
00446         DomUtils::readNode(&childNode, &data.listXbonAtoms2);
00447 
00449       else if(DomUtils::dictEntry(childNode, prefix + xml.goon))
00450         DomUtils::readNode(&childNode, &data.goon);
00451       else if(DomUtils::dictEntry(childNode, prefix + xml.printDebug))
00452         DomUtils::readNode(&childNode, &data.printDebug);
00453       else if(DomUtils::dictEntry(childNode, prefix + xml.update))
00454         DomUtils::readNode(&childNode, &data.update);
00455       else if(DomUtils::dictEntry(childNode, prefix + xml.updateType))
00456         DomUtils::readNode(&childNode, &data.updateType);
00457       else if(DomUtils::dictEntry(childNode, prefix + xml.updateScaleFactor))
00458         DomUtils::readNode(&childNode, &data.updateScaleFactor);
00459       else if(DomUtils::dictEntry(childNode, prefix + xml.compact))
00460         DomUtils::readNode(&childNode, &data.compact);
00461       else if(DomUtils::dictEntry(childNode, prefix + xml.compactBonds))
00462         DomUtils::readNode(&childNode, &data.compactBonds);
00463       else if(DomUtils::dictEntry(childNode, prefix + xml.compactAngles))
00464         DomUtils::readNode(&childNode, &data.compactAngles);
00465       else if(DomUtils::dictEntry(childNode, prefix + xml.compactTorsions))
00466         DomUtils::readNode(&childNode, &data.compactTorsions);
00467 
00469       else if(DomUtils::dictEntry(childNode, prefix + xml.numLines))
00470         DomUtils::readNode(&childNode, &data.numLines);
00471       else if(DomUtils::dictEntry(childNode, prefix + xml.hPos))
00472         DomUtils::readNode(&childNode, &data.hPos);
00473       else if(DomUtils::dictEntry(childNode, prefix + xml.vPos))
00474         DomUtils::readNode(&childNode, &data.vPos);
00475       else if(DomUtils::dictEntry(childNode, prefix + xml.contents))
00476         DomUtils::readNode(&childNode, &data.contents);
00477     }
00478     childNode = childNode.nextSibling();
00479   }
00480   restoreWidgets();
00481   widgetChanged = false;
00482 }
00483 
00485 void RelaxBase::saveCML(QDomElement* root)
00487 {  
00490   assert(!isVisible());
00491   
00492   const QString prefix = "geometry_optimization_";
00494   DomUtils::makeNode(root, data.type, prefix + xml.type);
00495   DomUtils::makeNode(root, data.autoGenerate, prefix + xml.autoGenerate);
00496   DomUtils::makeNode(root, data.autoRegen, prefix + xml.autoRegen);    
00497   DomUtils::makeNode(root, data.autoGenFreq, prefix + xml.autoGenFreq);
00498   DomUtils::makeNode(root, data.autoHBonds, prefix + xml.autoHBonds);
00499   DomUtils::makeNode(root, data.useOneScaleFactor, prefix + xml.useOneScaleFactor);
00500   DomUtils::makeNode(root, data.sfacValue1, prefix + xml.sfacValue1);
00501   DomUtils::makeNode(root, data.sfacValue2, prefix + xml.sfacValue2);
00502   DomUtils::makeNode(root, data.sfacNumSteps, prefix + xml.sfacNumSteps);
00503   DomUtils::makeNode(root, data.listValues, prefix + xml.listValues);
00504   DomUtils::makeNode(root, data.listNumSteps, prefix + xml.listNumSteps);
00505   DomUtils::makeNode(root, data.numDIIS, prefix + xml.numDIIS);
00506   DomUtils::makeNode(root, data.printShifts, prefix + xml.printShifts);
00507   DomUtils::makeNode(root, data.numSteps, prefix + xml.numSteps);
00508 
00510   if(data.ic.size() != 0)
00511   {
00512     // fill vectors/QStringLists with the data to store
00513     vector<unsigned int> numbers;
00514     vector<bool> rootItems;
00515     QStringList types;
00516     QStringList fcs;
00517     vector<bool> fixed;
00518     vector<bool> maximized;
00519     QStringList refValues;
00520     QStringList weights;
00521     vector<unsigned int> firstAtoms;
00522     vector<unsigned int> secondAtoms;
00523     vector<unsigned int> thirdAtoms;
00524     vector<unsigned int> fourthAtoms;
00525     for(vector<ICData>::iterator it = data.ic.begin(); it != data.ic.end(); it++)
00526     {
00527       numbers.push_back(it->number);
00528       rootItems.push_back(it->rootItem);
00529       types.push_back(it->type);
00530       fcs.push_back(it->fc);
00531       fixed.push_back(it->fix);
00532       maximized.push_back(it->maximize);
00533       refValues.push_back(it->refValue);
00534       weights.push_back(it->weight);
00535       firstAtoms.push_back(it->atom1);
00536       secondAtoms.push_back(it->atom2);
00537       thirdAtoms.push_back(it->atom3);
00538       fourthAtoms.push_back(it->atom4);
00539     }
00540     // store them as arrays
00541     DomUtils::makeNode(root, numbers, prefix + xml.ic_number);
00542     DomUtils::makeNode(root, rootItems, prefix + xml.ic_rootItem);
00543     DomUtils::makeNode(root, types, prefix + xml.ic_type);
00544     DomUtils::makeNode(root, fcs, prefix + xml.ic_fc);
00545     DomUtils::makeNode(root, fixed, prefix + xml.ic_fix);
00546     DomUtils::makeNode(root, maximized, prefix + xml.ic_maximize);
00547     DomUtils::makeNode(root, refValues, prefix + xml.ic_refValue);
00548     DomUtils::makeNode(root, weights, prefix + xml.ic_weight);
00549     DomUtils::makeNode(root, firstAtoms, prefix + xml.ic_atom1);
00550     DomUtils::makeNode(root, secondAtoms, prefix + xml.ic_atom2);
00551     DomUtils::makeNode(root, thirdAtoms, prefix + xml.ic_atom3);
00552     DomUtils::makeNode(root, fourthAtoms, prefix + xml.ic_atom4);
00553   }
00554 
00556   DomUtils::makeNode(root, data.checkSymmetry, prefix + xml.checkSymmetry);
00557   DomUtils::makeNode(root, data.checkSymmX, prefix + xml.checkSymmX);
00558   DomUtils::makeNode(root, data.checkSymmY, prefix + xml.checkSymmY);
00559   DomUtils::makeNode(root, data.checkSymmZ, prefix + xml.checkSymmZ);
00560   DomUtils::makeNode(root, data.checkSymmXY, prefix + xml.checkSymmXY);
00561   DomUtils::makeNode(root, data.checkSymmXZ, prefix + xml.checkSymmXZ);
00562   DomUtils::makeNode(root, data.checkSymmYZ, prefix + xml.checkSymmYZ);
00563   DomUtils::makeNode(root, data.checkSymmXYZ, prefix + xml.checkSymmXYZ);
00564 
00566   DomUtils::makeNode(root, data.fixAtom, prefix + xml.fixAtom);
00567   DomUtils::makeNode(root, data.fixX, prefix + xml.fixX);
00568   DomUtils::makeNode(root, data.fixY, prefix + xml.fixY);
00569   DomUtils::makeNode(root, data.fixZ, prefix + xml.fixZ);
00570   DomUtils::makeNode(root, data.listFixedAtoms, prefix + xml.listFixedAtoms);
00571   DomUtils::makeNode(root, data.listFixedXYZ, prefix + xml.listFixedXYZ);
00572   DomUtils::makeNode(root, data.optExternal, prefix + xml.optExternal);
00573   DomUtils::makeNode(root, data.optExternalAngle, prefix + xml.optExternalAngle);
00574   DomUtils::makeNode(root, data.optExternalA, prefix + xml.optExternalA);
00575   DomUtils::makeNode(root, data.optExternalB, prefix + xml.optExternalB);
00576   DomUtils::makeNode(root, data.optExternalC, prefix + xml.optExternalC);
00577   DomUtils::makeNode(root, data.optExternalAlpha, prefix + xml.optExternalAlpha);
00578   DomUtils::makeNode(root, data.optExternalBeta, prefix + xml.optExternalBeta);
00579   DomUtils::makeNode(root, data.optExternalGamma, prefix + xml.optExternalGamma);
00580   DomUtils::makeNode(root, data.mirrorImage, prefix + xml.mirrorImage);
00581   DomUtils::makeNode(root, data.writeXYZ, prefix + xml.writeXYZ);
00582       
00584   DomUtils::makeNode(root, data.refineThre1, prefix + xml.refineThre1);
00585   DomUtils::makeNode(root, data.refineThre2, prefix + xml.refineThre2);
00586   DomUtils::makeNode(root, data.refineThre3, prefix + xml.refineThre3);
00587   DomUtils::makeNode(root, data.refineThre4, prefix + xml.refineThre4);
00588   DomUtils::makeNode(root, data.refineThre5, prefix + xml.refineThre5);
00589   DomUtils::makeNode(root, data.maxIter, prefix + xml.maxIter);
00590   DomUtils::makeNode(root, data.iterThre1, prefix + xml.iterThre1);
00591   DomUtils::makeNode(root, data.iterThre2, prefix + xml.iterThre2);
00592   DomUtils::makeNode(root, data.iterThre3, prefix + xml.iterThre3);
00593   DomUtils::makeNode(root, data.iterThre4, prefix + xml.iterThre4);
00594 
00596   DomUtils::makeNode(root, data.xbonAtom1, prefix + xml.xbonAtom1);
00597   DomUtils::makeNode(root, data.xbonAtom2, prefix + xml.xbonAtom2);
00598   DomUtils::makeNode(root, data.listXbonAtoms1, prefix + xml.listXbonAtoms1);
00599   DomUtils::makeNode(root, data.listXbonAtoms2, prefix + xml.listXbonAtoms2);
00600   DomUtils::makeNode(root, data.massType, prefix + xml.massType);
00601   DomUtils::makeNode(root, data.setLowFreqs, prefix + xml.setLowFreqs);
00602   DomUtils::makeNode(root, data.lowFreqs, prefix + xml.lowFreqs);
00603   DomUtils::makeNode(root, data.orden, prefix + xml.orden);
00604       
00606   DomUtils::makeNode(root, data.goon, prefix + xml.goon);
00607   DomUtils::makeNode(root, data.printDebug, prefix + xml.printDebug);
00608   DomUtils::makeNode(root, data.update, prefix + xml.update);
00609   DomUtils::makeNode(root, data.updateType, prefix + xml.updateType);
00610   DomUtils::makeNode(root, data.updateScaleFactor, prefix + xml.updateScaleFactor);
00611   DomUtils::makeNode(root, data.compact, prefix + xml.compact);
00612   DomUtils::makeNode(root, data.compactBonds, prefix + xml.compactBonds);
00613   DomUtils::makeNode(root, data.compactAngles, prefix + xml.compactAngles);
00614   DomUtils::makeNode(root, data.compactTorsions, prefix + xml.compactTorsions);
00615 
00617   qDebug("calling makeNode with data.numLines = %d and prefix = "+prefix+xml.numLines, data.numLines);
00618   DomUtils::makeNode(root, data.numLines, prefix + xml.numLines);
00619   DomUtils::makeNode(root, data.hPos, prefix + xml.hPos);
00620   DomUtils::makeNode(root, data.vPos, prefix + xml.vPos);
00621   DomUtils::makeNode(root, data.contents, prefix + xml.contents);
00622 }
00623 
00627 
00629 void RelaxBase::reset()
00631 {
00633   ComboBoxType->setCurrentItem(0);
00634   CheckBoxAutogen->setChecked(true);
00635   CheckBoxRegen->setChecked(false);
00636   SpinBoxGenFreq->setValue(1);
00637   CheckBoxHBonds->setChecked(true);
00638   RadioButtonSFAC1->setChecked(true);
00639   RadioButtonSFAC2->setChecked(false);
00640   LineEditSFAC1->setText("1.0");
00641   LineEditSFAC2->setText("1.0");
00642   SpinBoxSFAC->setValue(5);
00643   ListViewSFAC->clear();
00644   SpinBoxMAXD->setValue(5);
00645   CheckBoxSUMM->setChecked(true);
00646   SpinBoxSteps->setValue(atoms->count() < 4 ? 10 : 3 * atoms->count()); // 3N steps with a minimum of 10
00647   enableSFACWidgets();
00648 
00650   ListViewIC->clear();
00651   TextLabelICNumber->setText("1");
00652   ComboBoxICType->setCurrentItem(0);
00653   LineEditFC->setText("5.0");
00654   CheckBoxFIXC->setChecked(false);
00655   CheckBoxMAXI->setChecked(false);
00656   CheckBoxTORO->setChecked(false);
00657   LineEditTORO->setText("");
00658   TextLabelICPart->setText("1");
00659   TextLabelICType->setPixmap(QPixmap());
00660   LineEditICWeight->setText("1.0");
00661   SpinBoxICAtom1->setValue(1);
00662   SpinBoxICAtom2->setValue(1);
00663   SpinBoxICAtom3->setValue(1);
00664   SpinBoxICAtom4->setValue(1);
00665   GroupBoxICGlobal->setEnabled(false);
00666   GroupBoxICSpecific->setEnabled(false);
00667   ToolButtonICAdd2->setEnabled(false);
00668   ToolButtonICRemove->setEnabled(false);
00669   ToolButtonICClear->setEnabled(false);
00670   ToolButtonICUp->setEnabled(false);
00671   ToolButtonICDown->setEnabled(false);
00672 
00674   CheckBoxSYMM->setChecked(false);
00675   CheckBoxSYMMx->setChecked(false);
00676   CheckBoxSYMMy->setChecked(false);
00677   CheckBoxSYMMz->setChecked(false);
00678   CheckBoxSYMMxy->setChecked(false);
00679   CheckBoxSYMMxz->setChecked(false);
00680   CheckBoxSYMMyz->setChecked(false);
00681   CheckBoxSYMMxyz->setChecked(false);
00682   GroupBoxSYMM->setEnabled(false);
00683     
00685   SpinBoxFIXA->setValue(1);
00686   CheckBoxFIXA1->setChecked(true);
00687   CheckBoxFIXA2->setChecked(true);
00688   CheckBoxFIXA3->setChecked(true);
00689   ListViewFIXA->clear();
00690   CheckBoxTROT->setChecked(false);
00691   ComboBoxTROT->setCurrentItem(1);
00692   LineEditXTFK1->setText("1.0");
00693   LineEditXTFK2->setText("1.0");
00694   LineEditXTFK3->setText("1.0");
00695   LineEditXTFK4->setText("10.0");
00696   LineEditXTFK5->setText("10.0");
00697   LineEditXTFK6->setText("10.0");
00698   CheckBoxSIGN->setChecked(false);
00699   CheckBoxANIM->setChecked(false);
00700   enableTROTWidgets(false);
00701 
00703   LineEditREFT1->setText("0.0009");
00704   LineEditREFT2->setText("0.0009");
00705   LineEditREFT3->setText("0.0009");
00706   LineEditREFT4->setText("0.0009");
00707   LineEditREFT5->setText("0.0009");
00708   SpinBoxITER->setValue(0);
00709   LineEditTHRE1->setText("0.499");
00710   LineEditTHRE2->setText("9.0");
00711   LineEditTHRE3->setText("1.0");
00712   LineEditTHRE4->setText("7.0");
00713 
00715   SpinBoxXBON1->setValue(1);
00716   SpinBoxXBON2->setValue(2);
00717   ListViewXBON->clear();
00718   ButtonGroupMASS->setButton(0);
00719   CheckBoxFRET->setChecked(false);
00720   LineEditFRET->setText("");
00721   CheckBoxORDA->setChecked(false);
00722 
00724   CheckBoxGOON->setChecked(false);
00725   CheckBoxLONG->setChecked(false);
00726   CheckBoxUPDT->setChecked(false);
00727   ComboBoxUPDT->setCurrentItem(0);
00728   LineEditUPDT->setText("1.0");
00729   CheckBoxSHRT->setChecked(false);
00730   SpinBoxSHRT->setValue(100);
00731   LineEditSHRT1->setText("0.003");
00732   LineEditSHRT2->setText("0.5");
00733   LineEditSHRT3->setText("1.0");
00734   enableUPDTWidgets(false);
00735   enableSHRTWidgets(false);
00736 
00738   resetTable(Table);
00739 }
00740 
00744 
00746 void RelaxBase::showEvent(QShowEvent* e)
00748 {
00751   if(atoms->count() == 0)
00752   {
00754     GroupBoxIC->setEnabled(false);
00755     TextLabelICType->setPixmap(QPixmap());
00756     GroupBoxFIXA->setEnabled(false);
00757     GroupBoxXBON->setEnabled(false);
00758     ButtonPreview->setEnabled(false);
00759   }
00760   else
00761   {
00763     GroupBoxIC->setEnabled(true);
00764     GroupBoxFIXA->setEnabled(true);
00765     GroupBoxXBON->setEnabled(true);
00766     ButtonPreview->setEnabled(true);
00767     unsigned int numAtoms = atoms->count();
00768     unsigned int firstAtom, secondAtom, thirdAtom;
00769     int fourthAtom;
00771     QListViewItemIterator it1(ListViewIC);
00772     while(it1.current())
00773     {
00774       getAtomsFromIC(it1.current()->text(7), firstAtom, secondAtom, thirdAtom, fourthAtom);
00775 
00776       if((firstAtom > numAtoms) || (secondAtom > numAtoms) || (thirdAtom > numAtoms) || (fourthAtom > static_cast<int>(numAtoms)))
00777         delete it1.current();
00778       else
00779       {
00780         it1.current()->setText(7, icRepresentation(firstAtom, secondAtom, thirdAtom, fourthAtom));                
00781         it1++;
00782       }
00783     }
00784     renumberICs(); // some root IC's might have been deleted
00785     
00787     QListViewItemIterator it2(ListViewFIXA);
00788     while(it2.current())
00789     {
00790       unsigned int fixedAtom = it2.current()->text(0).replace(QRegExp("[A-Z, a-z]"), "").toUInt();
00791       if(fixedAtom > numAtoms)
00792         delete it2.current();
00793       else
00794       {
00795         it2.current()->setText(0, AtomSet::numToAtom(atoms->atomicNumber(fixedAtom-1)).stripWhiteSpace() + QString::number(fixedAtom));
00796         it2++;
00797       }
00798     }
00799 
00801     QListViewItemIterator it3(ListViewXBON);
00802     while(it3.current())
00803     {
00804       unsigned int firstAtom = it3.current()->text(0).replace(QRegExp("[A-Z, a-z]"), "").toUInt();
00805       unsigned int secondAtom = it3.current()->text(1).replace(QRegExp("[A-Z, a-z]"), "").toUInt();
00806       if((firstAtom > numAtoms) || (secondAtom > numAtoms))
00807         delete it3.current();
00808       else
00809       {
00810         it3.current()->setText(0, AtomSet::numToAtom(atoms->atomicNumber(firstAtom-1)).stripWhiteSpace() + QString::number(firstAtom));
00811         it3.current()->setText(1, AtomSet::numToAtom(atoms->atomicNumber(secondAtom-1)).stripWhiteSpace() + QString::number(secondAtom));
00812         it3++;
00813       }
00814     }
00815     
00817     SpinBoxICAtom1->setMaxValue(numAtoms);
00818     SpinBoxICAtom2->setMaxValue(numAtoms);
00819     SpinBoxICAtom3->setMaxValue(numAtoms);
00820     SpinBoxICAtom4->setMaxValue(numAtoms);
00821     SpinBoxFIXA->setMaxValue(numAtoms);
00822     SpinBoxXBON1->setMaxValue(numAtoms);
00823     SpinBoxXBON2->setMaxValue(numAtoms);            
00824   }
00825   
00826   RelaxWidget::showEvent(e);
00827 }
00828 
00832 
00834 void RelaxBase::accept()
00836 {
00837   if(widgetChanged)
00838   {
00839     setChanged(false);
00840     saveWidgets();
00841     RelaxWidget::accept();
00842   }
00843   else
00844     RelaxWidget::reject();
00845 }
00846 
00848 void RelaxBase::reject()
00850 {
00851   if(widgetChanged)
00852   {
00853     setChanged(false);
00854     restoreWidgets();
00855   }
00856   RelaxWidget::reject();
00857 }
00858 
00859 
00863 
00865 void RelaxBase::showPreview()
00868 {
00869   if(!CheckBoxAutogen->isChecked())
00870   {
00871     showPreview2();
00872     return;
00873   }
00874 
00876   if(!startMAFF(RelaxBase::PreviewAFF))
00877     return;
00878 
00880   ButtonPreview->setEnabled(false); // no reentracy
00881 }
00882 
00884 void RelaxBase::showPreview2()
00888 {
00889   bool ranMaff = false;
00890   if(!ButtonPreview->isEnabled())
00891   {
00892     // MAFF was run
00893     ButtonPreview->setEnabled(true);
00894     ranMaff = true;
00895   }
00896 
00898   QStringList relaxInp = generateAFFHeader();
00899   if(ranMaff)
00900   {
00901     relaxInp += readMAFFGeneratedICs(); // MAFF was run 
00902     relaxInp += "stop";
00903   }
00904 
00906   TextViewWidget* preview = new TextViewWidget(this, 0, true, 0);
00907   preview->TextEdit->setTextFormat(Qt::LogText);
00908   QFontMetrics metrics(preview->TextEdit->currentFont());
00909   int newWidth = 81*metrics.width(" ") + 2*preview->layout()->margin() + preview->TextEdit->verticalScrollBar()->sliderRect().width(); // 20 = 2 x layoutMargin
00910   preview->resize(newWidth, preview->height()); 
00911   QString previewCaption = tr("Preview input file ")+calcName + ".aff";
00912   if(!ranMaff)
00913     previewCaption += "1";  
00914   preview->setCaption(previewCaption);
00915   preview->TextEdit->setText(relaxInp.join("\n"));      
00916   preview->exec();
00917   delete preview;
00918 }
00919 
00921 void RelaxBase::readInputFile()
00923 {
00925   QString filename = QFileDialog::getOpenFileName(QString::null, "*.aff", this, 0, tr("Choose an AFF file"));
00926   if(filename.isEmpty())
00927     return;
00928 
00930   QFile file(filename);
00931   if(!file.open(IO_ReadOnly))
00932     return;
00933   QTextStream stream(&file);
00934   QString line, icTypeString;
00935   QStringList aff;
00936   unsigned int icType = 0;
00937   while(!stream.atEnd() && line.left(4).lower() != "stop")
00938   {
00939     line = stream.readLine();
00940     if(line.left(1) != "!" && !line.stripWhiteSpace().isEmpty())
00941       aff += line;
00942     if(line.left(4).lower() == "bmat")
00943       icType = 1;
00944     else if(line.left(4).lower() == "gbma")
00945       icType = 2;
00946   }
00947   
00948   bool readIC = false;
00949   if(icType != 0)
00950   {
00951     // Ask whether the internal coordinates should be read too.
00952     QString question = tr("Also read the ");
00953     if(icType == 1)
00954       question += tr("non");
00955     question += tr("redundant internal coordinates?");
00956     readIC = QMessageBox::question(this, Version::appName, question, QMessageBox::Yes, QMessageBox::No, QMessageBox::NoButton) == QMessageBox::Yes;    
00957   }
00958 
00960   reset();
00961 
00963   if(readIC)
00964     fillICListFromAFF(aff);
00965 
00968   bool pastICDef = false;
00969 
00971   unsigned numAtoms = atoms->count();
00972 
00974   for(QStringList::Iterator it = aff.begin(); it != aff.end(); it++)
00975   {
00976     QString line = (*it);
00977     QString key = line.left(4).lower(); // all recognized keys are 4 chars
00978 
00979     if(key == "bmat" || key == "gbma" || key == "fmat")
00980       pastICDef = true;
00981     else if(key == "fixc" || key == "maxi" || key == "toro")
00982       ; // already parsed in fillICListFromAFF
00983     else if(key == "maxd")
00984       SpinBoxMAXD->setValue(line.mid(10,10).toUInt());
00985     else if(key == "summ")
00986       CheckBoxSUMM->setChecked(true);
00987     else if(key == "symm")
00988     {
00989       CheckBoxSYMM->setChecked(true);
00990       for(unsigned int i = 0; i < 7; i++)
00991       {
00992         QString symmType = line.mid(10+10*i,10).stripWhiteSpace();
00993         if(symmType == "all")
00994         {
00995           CheckBoxSYMMx->setChecked(true);
00996           CheckBoxSYMMy->setChecked(true);
00997           CheckBoxSYMMz->setChecked(true);
00998           CheckBoxSYMMxy->setChecked(true);
00999           CheckBoxSYMMxz->setChecked(true);
01000           CheckBoxSYMMyz->setChecked(true);
01001           CheckBoxSYMMxyz->setChecked(true);
01002           break;
01003         }
01004         else if(symmType == "x")
01005           CheckBoxSYMMx->setChecked(true);
01006         else if(symmType == "y")
01007           CheckBoxSYMMy->setChecked(true);
01008         else if(symmType == "z")
01009           CheckBoxSYMMz->setChecked(true);
01010         else if(symmType == "xy")
01011           CheckBoxSYMMxy->setChecked(true);
01012         else if(symmType == "xz")
01013           CheckBoxSYMMxz->setChecked(true);
01014         else if(symmType == "yz")
01015           CheckBoxSYMMyz->setChecked(true);
01016         else if(symmType == "xyz")
01017           CheckBoxSYMMxyz->setChecked(true);
01018       }
01019     }
01020     else if(key == "fixa")
01021     {
01022       unsigned int atom = line.mid(10,10).toUInt();
01023       if(atom <= numAtoms)
01024       {
01025         SpinBoxFIXA->setValue(atom);  
01026         QString xyz = line.mid(20,10);
01027         CheckBoxFIXA1->setChecked(xyz.contains("x", false) != 0);
01028         CheckBoxFIXA2->setChecked(xyz.contains("y", false) != 0);
01029         CheckBoxFIXA3->setChecked(xyz.contains("z", false) != 0);
01030         newFixedAtom();
01031       }
01032     }
01033     else if(key == "trot")
01034     {
01035       CheckBoxTROT->setChecked(true);
01036       unsigned int trotType = line.mid(10,10).toUInt();
01037       if(trotType != 0)
01038         ComboBoxTROT->setCurrentItem(trotType - 1);
01039     }
01040     else if(key == "xtfk")
01041     {
01042       line = *(++it);
01043       LineEditXTFK1->setText(QString::number(line.section(" ",0,0,QString::SectionSkipEmpty).toDouble()));
01044       LineEditXTFK2->setText(QString::number(line.section(" ",1,1,QString::SectionSkipEmpty).toDouble()));
01045       LineEditXTFK3->setText(QString::number(line.section(" ",2,2,QString::SectionSkipEmpty).toDouble()));
01046       LineEditXTFK4->setText(QString::number(line.section(" ",3,3,QString::SectionSkipEmpty).toDouble()));
01047       LineEditXTFK5->setText(QString::number(line.section(" ",4,4,QString::SectionSkipEmpty).toDouble()));
01048       LineEditXTFK6->setText(QString::number(line.section(" ",5,5,QString::SectionSkipEmpty).toDouble()));
01049     }
01050     else if(key == "sign")
01051       CheckBoxSIGN->setChecked(true);
01052     else if(key == "anim")
01053       CheckBoxANIM->setChecked(true);
01054     else if(key == "reft")
01055     {
01056       if(!line.mid(10,10).stripWhiteSpace().isEmpty())
01057         LineEditREFT1->setText(QString::number(line.mid(10,10).toDouble()));
01058       if(!line.mid(20,10).stripWhiteSpace().isEmpty())
01059         LineEditREFT1->setText(QString::number(line.mid(20,10).toDouble()));
01060       if(!line.mid(30,10).stripWhiteSpace().isEmpty())
01061         LineEditREFT1->setText(QString::number(line.mid(30,10).toDouble()));
01062       if(!line.mid(40,10).stripWhiteSpace().isEmpty())
01063         LineEditREFT1->setText(QString::number(line.mid(40,10).toDouble()));
01064       if(!line.mid(50,10).stripWhiteSpace().isEmpty())
01065         LineEditREFT1->setText(QString::number(line.mid(50,10).toDouble()));
01066     }
01067     else if(key == "iter")
01068       SpinBoxITER->setValue(line.mid(10,10).toUInt());
01069     else if(key == "thre")
01070     {
01071       if(!line.mid(10,10).stripWhiteSpace().isEmpty())
01072       {
01073         double thre = line.mid(10,10).toDouble();
01074         double threA = log10(floor(thre) - thre);
01075         int threB = static_cast<int>(thre); // maybe use floor? 
01076         LineEditTHRE1->setText(QString::number(threA));
01077         LineEditTHRE2->setText(QString::number(threB));
01078       }
01079       if(!line.mid(20,10).stripWhiteSpace().isEmpty())
01080       {
01081         double thre = line.mid(20,10).toDouble();
01082         double threA = log10(floor(thre) - thre);
01083         int threB = static_cast<int>(thre); 
01084         LineEditTHRE3->setText(QString::number(threA));
01085         LineEditTHRE4->setText(QString::number(threB));
01086       }
01087     }
01088     else if(key == "xbon")
01089     {
01090       unsigned int atom1 = line.mid(10,10).toUInt();
01091       unsigned int atom2 = line.mid(20,10).toUInt();
01092       if(atom1 > numAtoms || atom2 > numAtoms)
01093         continue;
01094       SpinBoxXBON1->setValue(atom1);
01095       SpinBoxXBON1->setValue(atom1);
01096       newExtraBond();
01097     }
01098     else if(key == "mass")
01099       RadioButtonMASS2->setChecked(true);
01100     else if(key == "avma")
01101       RadioButtonMASS3->setChecked(true);
01102     else if(key == "fret")
01103       LineEditFRET->setText(QString::number(line.mid(10,10).toDouble()));
01104     else if(key == "orda")
01105       CheckBoxORDA->setChecked(true);
01106     else if(key == "goon")
01107       CheckBoxGOON->setChecked(true);
01108     else if(key == "long")
01109       CheckBoxLONG->setChecked(true);
01110     else if(key == "updt")
01111     {
01112       CheckBoxUPDT->setChecked(true);
01113       ComboBoxUPDT->setCurrentItem(line.mid(10,10).toUInt() - 1);
01114       LineEditUPDT->setText(QString::number(line.mid(20,10).toDouble()));
01115     }
01116     else if(key == "shrt")
01117     {
01118       CheckBoxSHRT->setChecked(true);
01119       LineEditSHRT1->setText(QString::number(line.mid(10,10).toDouble()));
01120       LineEditSHRT2->setText(QString::number(line.mid(20,10).toDouble()));
01121       LineEditSHRT3->setText(QString::number(line.mid(30,10).toDouble()));
01122     }
01123     else
01124     {
01125       if(pastICDef)
01126       {
01129         while(it != aff.end() && key != "xtfk")
01130           key = (*(++it)).left(4).lower();
01131         if(key == "xtfk")
01132         {
01133           line = *(++it);
01134           // free format or not?
01135 
01136           LineEditXTFK1->setText(QString::number(line.section(" ",0,0,QString::SectionSkipEmpty).toDouble()));
01137           LineEditXTFK2->setText(QString::number(line.section(" ",1,1,QString::SectionSkipEmpty).toDouble()));
01138           LineEditXTFK3->setText(QString::number(line.section(" ",2,2,QString::SectionSkipEmpty).toDouble()));
01139           LineEditXTFK4->setText(QString::number(line.section(" ",3,3,QString::SectionSkipEmpty).toDouble()));
01140           LineEditXTFK5->setText(QString::number(line.section(" ",4,4,QString::SectionSkipEmpty).toDouble()));
01141           LineEditXTFK6->setText(QString::number(line.section(" ",5,5,QString::SectionSkipEmpty).toDouble()));  
01142         }
01143         return;
01144       }
01145       else
01146       {
01148         QStringList texts;
01149         for(unsigned int i = 0; i < 8; i++)
01150           texts += line.mid(i*10,10);
01151         int row= firstEmptyTableRow(Table);
01152         for(unsigned int i = 0; i < 8; i++)
01153         {
01154           if(!(*(texts.at(i))).isEmpty())
01155             Table->setText(row, i, *(texts.at(i)));
01156         }
01157       }
01158     }
01159   }
01160 }
01161 
01163 void RelaxBase::setChanged(bool state)
01165 {
01166   widgetChanged = state;
01167 }
01168 
01170 void RelaxBase::selectWidget(QListViewItem* newItem)
01172 {
01173   if(newItem->childCount() != 0)
01174   {
01176     newItem->setOpen(true);
01177     ListViewCategory->setSelected(newItem->firstChild(), true);
01178     return;
01179   }
01180 
01182   if(newItem->parent() == 0)
01183   {
01185     if(newItem->text(0) == category[BASIC])
01186       WidgetStackCategory->raiseWidget(0);
01187     else if(newItem->text(0) == category[INTERNAL])
01188       WidgetStackCategory->raiseWidget(5);
01189     else if(newItem->text(0) == category[DEBUG1])
01190       WidgetStackCategory->raiseWidget(6);
01191     else if(newItem->text(0) == category[EXTRA])
01192       WidgetStackCategory->raiseWidget(7);
01193   }
01194   else
01195   {
01197     if(newItem->parent()->text(0) == category[CARTESIAN])
01198     {
01199       if(newItem->text(0) == category[CARTESIAN_SYMMETRY])
01200         WidgetStackCategory->raiseWidget(3);
01201       else if(newItem->text(0) == category[CARTESIAN_OTHER])
01202         WidgetStackCategory->raiseWidget(4);
01203     }
01204     else if(newItem->parent()->text(0) == category[ADVANCED])
01205     {
01206       if(newItem->text(0) == category[ADVANCED_THRESHOLDS])
01207         WidgetStackCategory->raiseWidget(1);
01208       else if(newItem->text(0) == category[ADVANCED_OTHER])
01209         WidgetStackCategory->raiseWidget(2);
01210     }
01211   }
01212 }
01213 
01215 void RelaxBase::enableAutogenWidgets()
01218 {
01219   CheckBoxRegen->setEnabled(CheckBoxAutogen->isChecked());
01220   SpinBoxGenFreq->setEnabled(CheckBoxRegen->isChecked() && CheckBoxRegen->isEnabled());
01221   CheckBoxHBonds->setEnabled(CheckBoxAutogen->isChecked());
01222 }
01223 
01225 void RelaxBase::enableSFACWidgets(bool state)
01228 {
01229   LineEditSFAC1->setEnabled(state);
01230   TextLabelSFAC1->setEnabled(!state);
01231   TextLabelSFAC2->setEnabled(!state);
01232   LineEditSFAC2->setEnabled(!state);
01233   SpinBoxSFAC->setEnabled(!state);
01234   ToolButtonSFAC1->setEnabled(!state);
01235   ToolButtonSFAC2->setEnabled(!state);
01236   ListViewSFAC->setEnabled(!state);  
01237 }
01238 
01240 void RelaxBase::newScaleFactor()
01242 {
01244   QListViewItem* lastItem = ListViewSFAC->lastItem();
01245   QListViewItem* newItem = new QListViewItem(ListViewSFAC, lastItem);
01246 
01248   newItem->setText(0, LineEditSFAC2->text());
01249   newItem->setText(1, QString::number(SpinBoxSFAC->value()));  
01250 }
01251 
01253 void RelaxBase::deleteScaleFactor()
01255 {
01256   QListViewItem* item = ListViewSFAC->selectedItem();
01257   if(item == 0)
01258     return;
01259   delete item;
01260 }
01261 
01263 void RelaxBase::updateICEdit()
01266 {
01267   /*
01268   qDebug("RelaxBase::updateICEdit() called");
01269   if(ListViewIC->currentItem() == 0)
01270     qDebug("  current  item: none");
01271   else
01272     qDebug("  current  item: "+ListViewIC->currentItem()->text(0)+"|"+ListViewIC->currentItem()->text(7));
01273   if(ListViewIC->selectedItem() == 0)
01274     qDebug("  selected item: none");
01275   else  
01276     qDebug("  selected item: "+ListViewIC->selectedItem()->text(0)+"|"+ListViewIC->selectedItem()->text(7));
01277   */
01278   
01280   QListViewItem* subItem = ListViewIC->selectedItem();
01281   if(subItem == 0)
01282   {
01284     GroupBoxICGlobal->setEnabled(false);
01285     GroupBoxICSpecific->setEnabled(false);
01286     ToolButtonICAdd2->setEnabled(false);
01287     ToolButtonICRemove->setEnabled(false);
01288     ToolButtonICClear->setEnabled(false);
01289     ToolButtonICUp->setEnabled(false);
01290     ToolButtonICDown->setEnabled(false);
01291     return;
01292   }
01293   else
01294   {
01295     GroupBoxICGlobal->setEnabled(true);
01296     GroupBoxICSpecific->setEnabled(true);    
01297     ToolButtonICAdd2->setEnabled(true);
01298     ToolButtonICRemove->setEnabled(true);
01299     ToolButtonICClear->setEnabled(true);
01300     ToolButtonICUp->setEnabled(true);
01301     ToolButtonICDown->setEnabled(true);
01302   }
01303 
01305   QListViewItem* rootItem;
01306   if(!subItem->text(0).isEmpty())
01307     rootItem = subItem;
01308   else
01309     rootItem = subItem->parent();
01310 
01312   TextLabelICNumber->setText(rootItem->text(0));
01313   ComboBoxICType->blockSignals(true); // updateICSpecifics should be called manually
01314   ComboBoxICType->setCurrentText(rootItem->text(1));
01315   ComboBoxICType->blockSignals(false);
01316   LineEditFC->blockSignals(true);
01317   LineEditFC->setText(rootItem->text(2));
01318   LineEditFC->blockSignals(false);
01319   CheckBoxFIXC->blockSignals(true);
01320   CheckBoxFIXC->setChecked(rootItem->pixmap(3) != 0);
01321   CheckBoxFIXC->blockSignals(false);
01322   CheckBoxMAXI->blockSignals(true);
01323   CheckBoxMAXI->setChecked(rootItem->pixmap(4) != 0);
01324   CheckBoxMAXI->blockSignals(false);
01325   CheckBoxTORO->blockSignals(true);
01326   CheckBoxTORO->setChecked(!rootItem->text(5).isEmpty());
01327   CheckBoxTORO->blockSignals(false);
01328   LineEditTORO->blockSignals(true);
01329   LineEditTORO->setText(rootItem->text(5));
01330   LineEditTORO->blockSignals(false);
01331 
01333   unsigned int icPart = 1;
01334   QListViewItemIterator it = rootItem->firstChild();
01335   while(it.current())
01336   {
01337     icPart++;
01338     if(it.current() == subItem)
01339       break;
01340     it++;
01341   }
01342   //qDebug("RelaxBase::updateICEdit(): icPart = %d", icPart);
01343   TextLabelICPart->setText(QString::number(icPart));
01344   LineEditICWeight->blockSignals(true);
01345   LineEditICWeight->setText(subItem->text(6));
01346   LineEditICWeight->blockSignals(false);
01347   updateICSpecifics();
01348 }
01349 
01351 void RelaxBase::updateICList()
01354 {
01355   ListViewIC->blockSignals(true);
01356   
01357   QString icNumber = TextLabelICNumber->text();
01358   QListViewItem* rootItem = ListViewIC->findItem(icNumber, 0);
01359   if(rootItem == 0) // no items in the ListView
01360     return;
01361       
01362   QListViewItem* subItem;
01363   unsigned int icPart = TextLabelICPart->text().toUShort();
01364   if(icPart == 1)
01365     subItem = rootItem;
01366   else
01367   {
01369     QListViewItemIterator it = rootItem->firstChild();
01370     for(unsigned int i = 2; i < icPart; i++)
01371       it++;
01372     subItem = it.current();
01373     ASSERT(subItem != 0);
01374   }
01376   rootItem->setText(1, ComboBoxICType->currentText());
01377   rootItem->setText(2, LineEditFC->text());
01378   if(CheckBoxFIXC->isChecked())
01379     rootItem->setPixmap(3, IconSets::getPixmap(IconSets::OK));
01380   else
01381     rootItem->setPixmap(3, QPixmap()); // clears the pixmap
01382   if(CheckBoxMAXI->isChecked())
01383     rootItem->setPixmap(4, IconSets::getPixmap(IconSets::OK));
01384   else
01385     rootItem->setPixmap(4, QPixmap());
01386   if(CheckBoxTORO->isChecked())
01387     rootItem->setText(5, LineEditTORO->text());
01388   else
01389     rootItem->setText(5, "");  
01391   subItem->setText(6, LineEditICWeight->text());
01392   unsigned int atom3 = 0;
01393   if(SpinBoxICAtom3->isEnabled())
01394     atom3 = SpinBoxICAtom3->value();
01395   unsigned int atom4 = 0;
01396   if(SpinBoxICAtom4->isEnabled())
01397   {
01398     atom4 = SpinBoxICAtom4->value();
01399     if(atom4 < 1)
01400       atom4--;
01401   }
01402   subItem->setText(7, icRepresentation(SpinBoxICAtom1->value(), SpinBoxICAtom2->value(), atom3, atom4));
01403           
01404   ListViewIC->blockSignals(false);  
01405 }
01406 
01408 void RelaxBase::updateICSpecifics()
01410 {
01411   QListViewItem* subItem = ListViewIC->selectedItem();
01412   unsigned int numAtoms = 0;;
01413   switch(ComboBoxICType->currentItem())
01414   {
01415     case 0: 
01416             numAtoms = 2;
01417             TextLabelICType->setPixmap(IconSets::getPixmap(IconSets::Stretch));
01418             break;
01419     case 1: 
01420             numAtoms = 3;
01421             TextLabelICType->setPixmap(IconSets::getPixmap(IconSets::Bend));
01422             break;
01423     case 2: 
01424             numAtoms = 4;
01425             TextLabelICType->setPixmap(IconSets::getPixmap(IconSets::Torsion));
01426             break;
01427     case 3: 
01428             numAtoms = 4;
01429             TextLabelICType->setPixmap(IconSets::getPixmap(IconSets::OutOfPlane));
01430             break;
01431     case 4: 
01432             numAtoms = 4;
01433             TextLabelICType->setPixmap(IconSets::getPixmap(IconSets::LinearBend));
01434   }
01435   SpinBoxICAtom1->blockSignals(true);
01436   SpinBoxICAtom1->setValue(subItem->text(7).section("-", 0, 0, QString::SectionSkipEmpty).replace(QRegExp("[A-Z, a-z]"), "").toInt());
01437   SpinBoxICAtom1->blockSignals(false);
01438   SpinBoxICAtom2->blockSignals(true);
01439   SpinBoxICAtom2->setValue(subItem->text(7).section("-", 1, 1, QString::SectionSkipEmpty).replace(QRegExp("[A-Z, a-z]"), "").toInt());
01440   SpinBoxICAtom2->blockSignals(false);
01441   SpinBoxICAtom3->blockSignals(true);
01442   if(numAtoms >= 3)
01443   {
01444     SpinBoxICAtom3->setEnabled(true);
01445     SpinBoxICAtom3->setValue(subItem->text(7).section("-", 2, 2, QString::SectionSkipEmpty).replace(QRegExp("[A-Z, a-z]"), "").toInt());
01446   }
01447   else
01448   {
01449     SpinBoxICAtom3->setEnabled(false);
01450     SpinBoxICAtom3->setValue(1);
01451   }
01452   SpinBoxICAtom3->blockSignals(false);
01453   SpinBoxICAtom4->blockSignals(true);
01454   if(numAtoms == 4)
01455   {
01456     SpinBoxICAtom4->setEnabled(true);
01457     QString section4 = subItem->text(7).section("-", 3, 3, QString::SectionSkipEmpty);
01458     if(section4 == "X")
01459       SpinBoxICAtom4->setValue(0);
01460     else if(section4 == "Y")
01461       SpinBoxICAtom4->setValue(-1);
01462     else if(section4 == "Z")
01463       SpinBoxICAtom4->setValue(-2);
01464     else
01465       SpinBoxICAtom4->setValue(section4.replace(QRegExp("[A-Z, a-z]"), "").toInt());
01466   }
01467   else
01468   {
01469     SpinBoxICAtom4->setEnabled(false);
01470     SpinBoxICAtom4->setValue(1);
01471   }
01472   SpinBoxICAtom4->blockSignals(false);
01473 
01474   //qDebug("RelaxBase::updateICSpecifics: manual call of updateICList()");
01475   //updateICList();
01476 }
01477 
01479 void RelaxBase::updateICType()
01481 // coordinate when the type changes.
01482 {
01484   QListViewItem* subItem = ListViewIC->selectedItem();
01485   if(subItem == 0)
01486     return; // no selection present
01487   QListViewItem* rootItem = subItem;
01488   if(subItem->parent() != 0)
01489     rootItem = subItem->parent();
01490 
01492   unsigned int numAtoms = 0;
01493   LineEditFC->blockSignals(true);
01494   switch(ComboBoxICType->currentItem())
01495   {
01496     case 0: 
01497             numAtoms = 2;
01498             TextLabelICType->setPixmap(IconSets::getPixmap(IconSets::Stretch));
01499             LineEditFC->setText("5.0");
01500             break;
01501     case 1: 
01502             numAtoms = 3;
01503             TextLabelICType->setPixmap(IconSets::getPixmap(IconSets::Bend));
01504             LineEditFC->setText("1.0");
01505             break;
01506     case 2: 
01507             numAtoms = 4;
01508             TextLabelICType->setPixmap(IconSets::getPixmap(IconSets::Torsion));
01509             LineEditFC->setText("0.1");
01510             break;
01511     case 3: 
01512             numAtoms = 4;
01513             TextLabelICType->setPixmap(IconSets::getPixmap(IconSets::OutOfPlane));
01514             LineEditFC->setText("0.1");
01515             break;
01516     case 4: 
01517             numAtoms = 4;
01518             TextLabelICType->setPixmap(IconSets::getPixmap(IconSets::LinearBend));
01519             LineEditFC->setText("0.5");
01520   }
01521   LineEditFC->blockSignals(false);
01522   LineEditTORO->blockSignals(true);
01523   LineEditTORO->setText("");
01524   LineEditTORO->blockSignals(false);  
01525   SpinBoxICAtom3->blockSignals(true);
01526   if(numAtoms >= 3)
01527   {
01528     if(!SpinBoxICAtom3->isEnabled())
01529     {
01530       SpinBoxICAtom3->setEnabled(true);
01531       SpinBoxICAtom3->setValue(1);
01532     }
01533   }
01534   else
01535   {
01536     SpinBoxICAtom3->setEnabled(false);
01537     SpinBoxICAtom3->setValue(1);
01538   }
01539   SpinBoxICAtom3->blockSignals(false);
01540   SpinBoxICAtom4->blockSignals(true);
01541   if(numAtoms == 4)
01542   {
01543     if(!SpinBoxICAtom4->isEnabled())
01544     {
01545       SpinBoxICAtom4->setEnabled(true);
01546       SpinBoxICAtom4->setValue(1);
01547     }
01548   }
01549   else
01550   {
01551     SpinBoxICAtom4->setEnabled(false);
01552     SpinBoxICAtom4->setValue(1);
01553   }
01554   SpinBoxICAtom4->blockSignals(false);
01555   
01557   ListViewIC->blockSignals(true);
01559   rootItem->setText(1, ComboBoxICType->currentText());
01560   rootItem->setText(2, LineEditFC->text());
01561   rootItem->setText(5, "");
01562   unsigned int atom1 = rootItem->text(7).section("-", 0, 0, QString::SectionSkipEmpty).replace(QRegExp("[A-Z, a-z]"), "").toInt();
01563   unsigned int atom2 = rootItem->text(7).section("-", 1, 1, QString::SectionSkipEmpty).replace(QRegExp("[A-Z, a-z]"), "").toInt();
01564   unsigned int atom3 = rootItem->text(7).section("-", 2, 2, QString::SectionSkipEmpty).replace(QRegExp("[A-Z, a-z]"), "").toInt();
01565   unsigned int atom4 = rootItem->text(7).section("-", 3, 3, QString::SectionSkipEmpty).replace(QRegExp("[A-Z, a-z]"), "").toInt();
01566   switch(numAtoms)
01567   {
01568     case 2: atom3 = atom4 = 0;
01569             break;            
01570     case 3: if(atom3 == 0)
01571               atom3 = 1;
01572             atom4 = 0;
01573             break;
01574     case 4: if(atom3 == 0)
01575               atom3 = 1;
01576             if(atom4 == 0)
01577               atom4 = 1;
01578   }
01579   rootItem->setText(7, icRepresentation(atom1, atom2, atom3, atom4));   
01580 
01582   QListViewItemIterator it(rootItem);
01583   while(it.current())
01584   {
01585     atom1 = it.current()->text(7).section("-", 0, 0, QString::SectionSkipEmpty).replace(QRegExp("[A-Z, a-z]"), "").toInt();
01586     atom2 = it.current()->text(7).section("-", 1, 1, QString::SectionSkipEmpty).replace(QRegExp("[A-Z, a-z]"), "").toInt();
01587     atom3 = it.current()->text(7).section("-", 2, 2, QString::SectionSkipEmpty).replace(QRegExp("[A-Z, a-z]"), "").toInt();
01588     atom4 = it.current()->text(7).section("-", 3, 3, QString::SectionSkipEmpty).replace(QRegExp("[A-Z, a-z]"), "").toInt();
01589     switch(numAtoms)
01590     {
01591       case 2: atom3 = atom4 = 0;
01592               break;
01593       case 3: if(atom3 == 0)
01594                 atom3 = 1;
01595               atom4 = 0;
01596               break;
01597       case 4: if(atom3 == 0)
01598                 atom3 = 1;
01599               if(atom4 == 0)
01600                 atom4 = 1;
01601     }
01602     it.current()->setText(7, icRepresentation(atom1, atom2, atom3, atom4));  
01603     it++;
01604   }
01605 
01606   ListViewIC->blockSignals(false);  
01607 }
01608 
01610 void RelaxBase::newIC()
01612 {
01613   QListViewItem* newItem; // this will be the newly inserted item
01614   QListViewItem* lastItem = ListViewIC->lastItem(); // get the last item
01615   if(lastItem != 0)
01616   {
01617     if(lastItem->parent() != 0)
01618       lastItem = lastItem->parent(); // if it's a subitem, get the root one
01619     newItem = new QListViewItem(ListViewIC, lastItem);
01620   }
01621   else
01622     newItem = new QListViewItem(ListViewIC); // the listview is empty
01623     
01624   newItem->setText(0, QString::number(ListViewIC->childCount()));
01625   newItem->setText(1, ComboBoxICType->text(0));
01626   newItem->setText(2, "5.0");
01627   newItem->setText(6, "1.0");
01628   switch(atoms->count())
01629   {
01630     case 0: newItem->setText(7, "X1-X1");
01631             break;
01632     case 1: newItem->setText(7, icRepresentation(1, 1));
01633             break;
01634     default: newItem->setText(7, icRepresentation(1, 2));
01635   }
01636   ListViewIC->setSelected(newItem, true);
01637   ListViewIC->ensureItemVisible(newItem);
01638   //qDebug("RelaxBase::newIC: manual call of updateICEdit()");
01639   updateICEdit();
01640   ToolButtonICAdd2->setEnabled(true);
01641   setChanged();
01642 }
01643 
01645 void RelaxBase::newICPart()
01647 {
01649   QListViewItem* rootItem = ListViewIC->selectedItem();
01650   if(rootItem == 0)
01651     return;
01652   if(rootItem->parent() != 0)
01653     rootItem = rootItem->parent();
01654 
01656   QListViewItem* newItem;
01657   if(rootItem->childCount() > 0)
01658   {
01660     QListViewItem* lastItem = 0;
01661     QListViewItemIterator it(rootItem);
01662     while(it.current())
01663     {
01664       lastItem = it.current();
01665       it++;
01666     }
01667     newItem = new QListViewItem(rootItem, lastItem);
01668   }
01669   else
01670     newItem = new QListViewItem(rootItem);
01671 
01673   newItem->setText(6, rootItem->text(6));
01674   newItem->setText(7, rootItem->text(7));
01675 
01677   ListViewIC->setSelected(newItem, true);
01678   ListViewIC->ensureItemVisible(newItem);
01679   //qDebug("RelaxBase::newICPart: manual call of updateICEdit()");
01680   updateICEdit();
01681   setChanged();  
01682 }
01683 
01685 void RelaxBase::deleteIC()
01687 {
01689   QListViewItem* item = ListViewIC->selectedItem();
01690   if(item == 0)
01691     return;
01692 
01694   QListViewItem* newItem = item->nextSibling();
01695   if(item->parent() == 0)
01696   {
01699     if(newItem == 0) // no root item below this one
01700       newItem = item->itemAbove();
01701     if(newItem == 0) // no item above this one (root or sub)
01702     {
01704       clearIC();
01705       return;
01706     }
01707     else
01708     {
01710       delete item; // delete the selected item
01711       renumberICs(); // renumber the remaining internal coordinates
01712       ListViewIC->setSelected(newItem, true); // select the new item
01713     }
01714   }
01715   else
01716   {
01718     if(newItem == 0) // no sub item below this one
01719       newItem = item->itemAbove(); // previous subitem or root item. always exists
01720     delete item;
01722     ListViewIC->setSelected(newItem, true);
01723   }
01724   setChanged();  
01725 }
01726 
01728 void RelaxBase::clearIC()
01730 {
01731   ListViewIC->clear();
01732   updateICEdit(); // disables everything
01733   setChanged();
01734 }
01735 
01737 void RelaxBase::genIC()
01740 {
01741   if(!startMAFF(RelaxBase::ICListAFF))
01742     return;
01743 
01745   ToolButtonICGen->setEnabled(false);
01746 }
01747 
01749 void RelaxBase::genIC2()
01752 {
01753   ToolButtonICGen->setEnabled(true);
01754 
01755   QStringList icList = readMAFFGeneratedICs();
01756   if(icList.isEmpty())
01757     return;
01758 
01759   fillICListFromAFF(icList);
01760   updateICEdit();
01761   setChanged();
01762 }
01763 
01765 void RelaxBase::moveICUp()
01767 {
01769   QListViewItem* item = ListViewIC->selectedItem();
01770   if(item == 0)
01771     return;
01772   if(item->parent() == 0)
01773   {
01775     if(item == ListViewIC->firstChild())
01776       return; // can't move the first item further up
01777     QListViewItem* newItem = item->itemAbove();
01778     while(newItem->parent() != 0)
01779       newItem = newItem->itemAbove();
01781     newItem->moveItem(item); // newItem is moved after item => equivalent to moving item before newItem
01782     renumberICs(); // maybe make an optimized version which just switches the 2 numbers
01783   }
01784   else
01785   {
01787     QListViewItem* rootItem = item->parent();
01788     if(item == rootItem->firstChild())
01789       return; // can't move the first item further up
01790     QListViewItem* newItem = item->itemAbove(); // certainly also a sub item
01791     newItem->moveItem(item);
01792   }
01793   ListViewIC->setSelected(item, true); // needed?
01794   setChanged();
01795 }
01796 
01798 void RelaxBase::moveICDown()
01800 {
01802   QListViewItem* item = ListViewIC->selectedItem();
01803   if(item == 0)
01804     return;
01805 
01806   QListViewItem* newItem = item->nextSibling();
01807   if(newItem == 0)
01808     return; // can't move last item further down (root or sub item)
01809   item->moveItem(newItem);
01810 
01811   if(item->parent() == 0)
01812     renumberICs(); // maybe make an optimized version which just switches the 2 numbers
01813     
01814   ListViewIC->setSelected(item, true); // needed?
01815   setChanged();
01816 }
01817 
01819 void RelaxBase::newFixedAtom()
01821 {
01824   QListViewItem* newItem = 0;
01825   QString newAtom = AtomSet::numToAtom(atoms->atomicNumber(SpinBoxFIXA->value() - 1)).stripWhiteSpace() + QString::number(SpinBoxFIXA->value());
01826   QListViewItemIterator it(ListViewFIXA);
01827   while(it.current())
01828   {
01829     if(it.current()->text(0) == newAtom)
01830     {
01831       newItem = it.current();
01832       break;
01833     }
01834     it++;
01835   }
01836   if(newItem == 0)
01837   {
01839     QListViewItem* lastItem = ListViewFIXA->lastItem();
01840     newItem = new QListViewItem(ListViewFIXA, lastItem);
01842     newItem->setText(0, newAtom);
01843   }
01845   QString xyz;
01846   if(CheckBoxFIXA1->isChecked())
01847     xyz += "x";
01848   if(CheckBoxFIXA2->isChecked())
01849     xyz += "y";
01850   if(CheckBoxFIXA3->isChecked())
01851     xyz += "z";
01852   if(xyz.isEmpty())
01853     delete newItem;
01854   else
01855   {
01856     if(newItem->text(1) == xyz)
01857       return; // updating an existing item with identical content should not trigger a changed signal
01858     newItem->setText(1, xyz);
01859   }
01860   
01861   setChanged();  
01862 }
01863 
01865 void RelaxBase::deleteFixedAtom()
01867 {
01868   QListViewItem* item = ListViewFIXA->selectedItem();
01869   if(item == 0)
01870     return;
01871 
01872   delete item;
01873   setChanged();
01874 }
01875 
01877 void RelaxBase::checkFIXABoxes()
01880 {
01881   // determine the number of checked boxes
01882   unsigned int numChecked = 0;
01883   if(CheckBoxFIXA1->isChecked())
01884     numChecked++;
01885   if(CheckBoxFIXA2->isChecked())
01886     numChecked++;
01887   if(CheckBoxFIXA3->isChecked())
01888     numChecked++;
01889   
01890   // if only 1 is checked, disable it so it cannot be unchecked
01891   if(numChecked == 1)
01892   {
01893     if(CheckBoxFIXA1->isChecked())
01894       CheckBoxFIXA1->setEnabled(false);
01895     else if(CheckBoxFIXA2->isChecked())
01896       CheckBoxFIXA2->setEnabled(false);
01897     else if(CheckBoxFIXA3->isChecked())
01898       CheckBoxFIXA3->setEnabled(false);
01899   }
01900   // otherwise make sure all are enabled
01901   else
01902   {
01903     CheckBoxFIXA1->setEnabled(true);
01904     CheckBoxFIXA2->setEnabled(true);
01905     CheckBoxFIXA3->setEnabled(true);
01906   }
01907 }
01908 
01910 void RelaxBase::enableTROTWidgets(bool state)
01913 {
01914   ComboBoxTROT->setEnabled(state);
01915   LineEditXTFK1->setEnabled(state);
01916   LineEditXTFK2->setEnabled(state);
01917   LineEditXTFK3->setEnabled(state);
01918   LineEditXTFK4->setEnabled(state);
01919   LineEditXTFK5->setEnabled(state);
01920   LineEditXTFK6->setEnabled(state);
01921 }
01922 
01924 void RelaxBase::newExtraBond()
01926 {
01928   QString atom1 = AtomSet::numToAtom(atoms->atomicNumber(SpinBoxXBON1->value() - 1)).stripWhiteSpace() + QString::number(SpinBoxXBON1->value());
01929   QString atom2 = AtomSet::numToAtom(atoms->atomicNumber(SpinBoxXBON2->value() - 1)).stripWhiteSpace() + QString::number(SpinBoxXBON2->value());
01930   QListViewItemIterator it(ListViewXBON);
01931   while(it.current())
01932   {
01933     if((it.current()->text(0) == atom1) && (it.current()->text(1) == atom2))
01934       return;
01935     it++;
01936   }
01937 
01939   QListViewItem* lastItem = ListViewXBON->lastItem();
01940   QListViewItem* newItem = new QListViewItem(ListViewXBON, lastItem);
01942   newItem->setText(0, atom1);
01943   newItem->setText(1, atom2);
01944 }
01945 
01947 void RelaxBase::deleteExtraBond()
01949 {
01950   QListViewItem* item = ListViewXBON->selectedItem();
01951   if(item == 0)
01952     return;
01953 
01954   delete item;
01955 }
01956 
01958 void RelaxBase::enableUPDTWidgets(bool state)
01961 {
01962   ComboBoxUPDT->setEnabled(state);
01963   LineEditUPDT->setEnabled(state);
01964 }
01965 
01967 void RelaxBase::enableSHRTWidgets(bool state)
01970 {
01971   TextLabelSHRT1->setEnabled(state);
01972   TextLabelSHRT2->setEnabled(state);
01973   TextLabelSHRT3->setEnabled(state);
01974   TextLabelSHRT4->setEnabled(state);
01975   TextLabelSHRT5->setEnabled(state);
01976   SpinBoxSHRT->setEnabled(state);
01977   LineEditSHRT1->setEnabled(state);
01978   LineEditSHRT2->setEnabled(state);
01979   LineEditSHRT3->setEnabled(state);  
01980 }
01981     
01983 void RelaxBase::checkOverflow(int row, int col)
01986 {
01987   checkTableOverflow(Table, row, col);
01988 }
01989 
01991 void RelaxBase::addExtraRow()
01994 {
01995   addTableRow(Table);
01996 }
01997 
01999 void RelaxBase::removeExtraRow()
02001 {
02002   if(removeTableRow(Table))
02003     setChanged();
02004 }
02005 
02007 void RelaxBase::clearSelection()
02009 {
02010   if(clearTableSelection(Table))
02011     setChanged();
02012 }
02013 
02014 
02018 
02020 void RelaxBase::makeConnections()
02022 {
02024   connect(ListViewCategory, SIGNAL(selectionChanged(QListViewItem*)), this, SLOT(selectWidget(QListViewItem*)));
02025 
02028   connect(ButtonOK, SIGNAL(clicked()), this, SLOT(accept()));
02029   connect(ButtonCancel, SIGNAL(clicked()), this, SLOT(reject()));
02030   connect(ButtonPreview, SIGNAL(clicked()), this, SLOT(showPreview()));
02031   connect(ButtonRead, SIGNAL(clicked()), this, SLOT(readInputFile()));
02032   connect(ButtonReset, SIGNAL(clicked()), this, SLOT(reset()));
02033 
02036   connect(CheckBoxAutogen, SIGNAL(toggled(bool)), this, SLOT(enableAutogenWidgets()));
02037   connect(CheckBoxRegen, SIGNAL(toggled(bool)), this, SLOT(enableAutogenWidgets()));
02038   connect(RadioButtonSFAC1, SIGNAL(toggled(bool)), this, SLOT(enableSFACWidgets(bool)));
02040   connect(CheckBoxTORO, SIGNAL(toggled(bool)), LineEditTORO, SLOT(setEnabled(bool)));  
02042   connect(CheckBoxSYMM, SIGNAL(toggled(bool)), GroupBoxSYMM, SLOT(setEnabled(bool)));
02044   connect(CheckBoxTROT, SIGNAL(toggled(bool)), this, SLOT(enableTROTWidgets(bool)));
02046   connect(CheckBoxFRET, SIGNAL(toggled(bool)), LineEditFRET, SLOT(setEnabled(bool)));  
02048   connect(CheckBoxUPDT, SIGNAL(toggled(bool)), this, SLOT(enableUPDTWidgets(bool)));
02049   connect(CheckBoxSHRT, SIGNAL(toggled(bool)), this, SLOT(enableSHRTWidgets(bool)));
02050         
02053   connect(ComboBoxType, SIGNAL(activated(int)), this, SLOT(setChanged()));
02054   connect(CheckBoxAutogen, SIGNAL(clicked()), this, SLOT(setChanged()));
02055   connect(CheckBoxRegen, SIGNAL(clicked()), this, SLOT(setChanged()));
02056   connect(SpinBoxGenFreq, SIGNAL(valueChanged(int)), this, SLOT(setChanged()));
02057   connect(CheckBoxHBonds, SIGNAL(clicked()), this, SLOT(setChanged()));
02058   connect(RadioButtonSFAC1, SIGNAL(clicked()), this, SLOT(setChanged()));
02059   connect(RadioButtonSFAC2, SIGNAL(clicked()), this, SLOT(setChanged()));
02060   connect(LineEditSFAC1, SIGNAL(textChanged(const QString&)), this, SLOT(setChanged()));
02061   connect(LineEditSFAC2, SIGNAL(textChanged(const QString&)), this, SLOT(setChanged()));
02062   connect(ToolButtonSFAC1, SIGNAL(clicked()), this, SLOT(setChanged()));
02063   connect(ToolButtonSFAC2, SIGNAL(clicked()), this, SLOT(setChanged()));
02064   connect(SpinBoxMAXD, SIGNAL(valueChanged(int)), this, SLOT(setChanged()));
02065   connect(CheckBoxSUMM, SIGNAL(clicked()), this, SLOT(setChanged()));
02066   connect(SpinBoxSteps, SIGNAL(valueChanged(int)), this, SLOT(setChanged()));
02068   connect(ComboBoxICType, SIGNAL(activated(int)), this, SLOT(setChanged()));
02069   connect(LineEditFC, SIGNAL(textChanged(const QString&)), this, SLOT(setChanged()));
02070   connect(CheckBoxFIXC, SIGNAL(clicked()), this, SLOT(setChanged()));
02071   connect(CheckBoxMAXI, SIGNAL(clicked()), this, SLOT(setChanged()));
02072   connect(CheckBoxTORO, SIGNAL(clicked()), this, SLOT(setChanged()));
02073   connect(LineEditTORO, SIGNAL(textChanged(const QString&)), this, SLOT(setChanged()));
02074   connect(LineEditICWeight, SIGNAL(textChanged(const QString&)), this, SLOT(setChanged()));
02075   connect(SpinBoxICAtom1, SIGNAL(valueChanged(int)), this, SLOT(setChanged()));
02076   connect(SpinBoxICAtom2, SIGNAL(valueChanged(int)), this, SLOT(setChanged()));
02077   connect(SpinBoxICAtom3, SIGNAL(valueChanged(int)), this, SLOT(setChanged()));
02078   connect(SpinBoxICAtom4, SIGNAL(valueChanged(int)), this, SLOT(setChanged()));
02080   connect(CheckBoxSYMM, SIGNAL(clicked()), this, SLOT(setChanged()));
02081   connect(CheckBoxSYMMx, SIGNAL(clicked()), this, SLOT(setChanged()));
02082   connect(CheckBoxSYMMy, SIGNAL(clicked()), this, SLOT(setChanged()));
02083   connect(CheckBoxSYMMz, SIGNAL(clicked()), this, SLOT(setChanged()));
02084   connect(CheckBoxSYMMxy, SIGNAL(clicked()), this, SLOT(setChanged()));
02085   connect(CheckBoxSYMMxz, SIGNAL(clicked()), this, SLOT(setChanged()));
02086   connect(CheckBoxSYMMyz, SIGNAL(clicked()), this, SLOT(setChanged()));
02087   connect(CheckBoxSYMMxyz, SIGNAL(clicked()), this, SLOT(setChanged()));
02089   connect(SpinBoxFIXA, SIGNAL(valueChanged(int)), this, SLOT(setChanged()));
02090   connect(CheckBoxFIXA1, SIGNAL(clicked()), this, SLOT(setChanged()));
02091   connect(CheckBoxFIXA2, SIGNAL(clicked()), this, SLOT(setChanged()));
02092   connect(CheckBoxFIXA3, SIGNAL(clicked()), this, SLOT(setChanged()));
02093   connect(CheckBoxTROT, SIGNAL(clicked()), this, SLOT(setChanged()));
02094   connect(ComboBoxTROT, SIGNAL(activated(int)), this, SLOT(setChanged()));
02095   connect(LineEditXTFK1, SIGNAL(textChanged(const QString&)), this, SLOT(setChanged()));
02096   connect(LineEditXTFK2, SIGNAL(textChanged(const QString&)), this, SLOT(setChanged()));
02097   connect(LineEditXTFK3, SIGNAL(textChanged(const QString&)), this, SLOT(setChanged()));
02098   connect(LineEditXTFK4, SIGNAL(textChanged(const QString&)), this, SLOT(setChanged()));
02099   connect(LineEditXTFK5, SIGNAL(textChanged(const QString&)), this, SLOT(setChanged()));
02100   connect(LineEditXTFK6, SIGNAL(textChanged(const QString&)), this, SLOT(setChanged()));
02101   connect(CheckBoxSIGN, SIGNAL(clicked()), this, SLOT(setChanged()));
02102   connect(CheckBoxANIM, SIGNAL(clicked()), this, SLOT(setChanged()));
02104   connect(LineEditREFT1, SIGNAL(textChanged(const QString&)), this, SLOT(setChanged()));
02105   connect(LineEditREFT2, SIGNAL(textChanged(const QString&)), this, SLOT(setChanged()));
02106   connect(LineEditREFT3, SIGNAL(textChanged(const QString&)), this, SLOT(setChanged()));
02107   connect(LineEditREFT4, SIGNAL(textChanged(const QString&)), this, SLOT(setChanged()));
02108   connect(LineEditREFT5, SIGNAL(textChanged(const QString&)), this, SLOT(setChanged()));
02109   connect(SpinBoxITER, SIGNAL(valueChanged(int)), this, SLOT(setChanged()));
02110   connect(LineEditTHRE1, SIGNAL(textChanged(const QString&)), this, SLOT(setChanged()));
02111   connect(LineEditTHRE2, SIGNAL(textChanged(const QString&)), this, SLOT(setChanged()));
02112   connect(LineEditTHRE3, SIGNAL(textChanged(const QString&)), this, SLOT(setChanged()));
02113   connect(LineEditTHRE4, SIGNAL(textChanged(const QString&)), this, SLOT(setChanged()));
02115   connect(SpinBoxXBON1, SIGNAL(valueChanged(int)), this, SLOT(setChanged()));
02116   connect(SpinBoxXBON2, SIGNAL(valueChanged(int)), this, SLOT(setChanged()));
02117   connect(ButtonGroupMASS, SIGNAL(clicked(int)), this, SLOT(setChanged()));
02118   connect(CheckBoxFRET, SIGNAL(clicked()), this, SLOT(setChanged()));
02119   connect(LineEditFRET, SIGNAL(textChanged(const QString&)), this, SLOT(setChanged()));
02120   connect(CheckBoxORDA, SIGNAL(clicked()), this, SLOT(setChanged()));
02122   connect(CheckBoxGOON, SIGNAL(clicked()), this, SLOT(setChanged()));
02123   connect(CheckBoxLONG, SIGNAL(clicked()), this, SLOT(setChanged()));
02124   connect(CheckBoxUPDT, SIGNAL(clicked()), this, SLOT(setChanged()));
02125   connect(ComboBoxUPDT, SIGNAL(activated(int)), this, SLOT(setChanged()));
02126   connect(LineEditUPDT, SIGNAL(textChanged(const QString&)), this, SLOT(setChanged()));
02127   connect(CheckBoxSHRT, SIGNAL(clicked()), this, SLOT(setChanged()));
02128   connect(LineEditSHRT1, SIGNAL(textChanged(const QString&)), this, SLOT(setChanged()));
02129   connect(LineEditSHRT2, SIGNAL(textChanged(const QString&)), this, SLOT(setChanged()));
02130   connect(LineEditSHRT3, SIGNAL(textChanged(const QString&)), this, SLOT(setChanged()));
02132   connect(Table, SIGNAL(valueChanged(int, int)), this, SLOT(setChanged()));
02133   connect(ToolButtonExtraAdd, SIGNAL(clicked()), this, SLOT(setChanged()));
02134   // Remove's and Clear's changes are handled in the slots removeRow and clearSelection
02135 
02137   connect(ToolButtonSFAC1, SIGNAL(clicked()), this, SLOT(newScaleFactor()));
02138   connect(ToolButtonSFAC2, SIGNAL(clicked()), this, SLOT(deleteScaleFactor()));  
02139   
02141   connect(ToolButtonICAdd, SIGNAL(clicked()), this, SLOT(newIC()));
02142   connect(ToolButtonICAdd2, SIGNAL(clicked()), this, SLOT(newICPart()));
02143   connect(ToolButtonICRemove, SIGNAL(clicked()), this, SLOT(deleteIC()));
02144   connect(ToolButtonICClear, SIGNAL(clicked()), this, SLOT(clearIC()));
02145   connect(ToolButtonICGen, SIGNAL(clicked()), this, SLOT(genIC()));
02146   connect(ToolButtonICUp, SIGNAL(clicked()), this, SLOT(moveICUp()));
02147   connect(ToolButtonICDown, SIGNAL(clicked()), this, SLOT(moveICDown()));
02148   connect(ListViewIC, SIGNAL(selectionChanged(QListViewItem*)), this, SLOT(updateICEdit()));
02149   connect(LineEditFC, SIGNAL(textChanged(const QString&)), this, SLOT(updateICList()));
02150   connect(CheckBoxFIXC, SIGNAL(clicked()), this, SLOT(updateICList()));
02151   connect(CheckBoxMAXI, SIGNAL(clicked()), this, SLOT(updateICList()));
02152   connect(CheckBoxTORO, SIGNAL(clicked()), this, SLOT(updateICList()));
02153   connect(LineEditTORO, SIGNAL(textChanged(const QString&)), this, SLOT(updateICList()));
02154   connect(LineEditICWeight, SIGNAL(textChanged(const QString&)), this, SLOT(updateICList()));
02155   connect(SpinBoxICAtom1, SIGNAL(valueChanged(int)), this, SLOT(updateICList()));
02156   connect(SpinBoxICAtom2, SIGNAL(valueChanged(int)), this, SLOT(updateICList()));
02157   connect(SpinBoxICAtom3, SIGNAL(valueChanged(int)), this, SLOT(updateICList()));
02158   connect(SpinBoxICAtom4, SIGNAL(valueChanged(int)), this, SLOT(updateICList()));
02159   connect(ComboBoxICType, SIGNAL(activated(int)), this, SLOT(updateICType()));
02160 
02162   connect(ToolButtonFIXA1, SIGNAL(clicked()), this, SLOT(newFixedAtom()));
02163   connect(ToolButtonFIXA2, SIGNAL(clicked()), this, SLOT(deleteFixedAtom()));  
02164   connect(CheckBoxFIXA1, SIGNAL(clicked()), this, SLOT(checkFIXABoxes()));
02165   connect(CheckBoxFIXA2, SIGNAL(clicked()), this, SLOT(checkFIXABoxes()));
02166   connect(CheckBoxFIXA3, SIGNAL(clicked()), this, SLOT(checkFIXABoxes()));
02167 
02169   connect(ToolButtonXBON1, SIGNAL(clicked()), this, SLOT(newExtraBond()));
02170   connect(ToolButtonXBON2, SIGNAL(clicked()), this, SLOT(deleteExtraBond()));
02171     
02173   connect(Table, SIGNAL(valueChanged(int, int)), this, SLOT(checkOverflow(int, int)));
02174   connect(ToolButtonExtraAdd, SIGNAL(clicked()), this, SLOT(addExtraRow()));
02175   connect(ToolButtonExtraRemove, SIGNAL(clicked()), this, SLOT(removeExtraRow()));
02176   connect(ToolButtonExtraClear, SIGNAL(clicked()), this, SLOT(clearSelection()));
02177   
02178   /*
02179   connect(CheckBox, SIGNAL(clicked()), this, SLOT(setChanged()));
02180   connect(SpinBox, SIGNAL(valueChanged(int)), this, SLOT(setChanged()));
02181   connect(ComboBox, SIGNAL(activated(int)), this, SLOT(setChanged()));
02182   connect(LineEdit, SIGNAL(textChanged(const QString&)), this, SLOT(setChanged()));
02183   */
02184  
02185 }
02186 
02188 void RelaxBase::init()
02191 {
02192 
02194   //category.clear();
02195   //TODO: setsize to the desired final size => done in header file
02196   category = vector<QString>(10);
02197   category.at(BASIC) = tr("Basic");
02198   category.at(INTERNAL) = tr("Internal coordinates");
02199   category.at(CARTESIAN) = tr("Cartesian coordinates");
02200   category.at(ADVANCED) = tr("Advanced");
02201   category.at(DEBUG1) = tr("Debug");
02202   category.at(EXTRA) = tr("Extra");
02203   category.at(CARTESIAN_SYMMETRY) = tr("Symmetry");
02204   category.at(CARTESIAN_OTHER) = tr("Other");
02205   category.at(ADVANCED_THRESHOLDS) = tr("Thresholds");
02206   category.at(ADVANCED_OTHER) = tr("Other");
02207 
02209   ListViewCategory->clear();
02210   ListViewCategory->setSorting(-1);
02211   ListViewCategory->header()->hide();
02213   QListViewItem* rootItem;
02215   new QListViewItem(ListViewCategory, category[EXTRA]);
02217   new QListViewItem(ListViewCategory, category[DEBUG1]);
02219   rootItem = new QListViewItem(ListViewCategory, category[ADVANCED]);
02220     new QListViewItem(rootItem, category[ADVANCED_OTHER]);
02221     new QListViewItem(rootItem, category[ADVANCED_THRESHOLDS]);
02223   rootItem = new QListViewItem(ListViewCategory, category[CARTESIAN]);
02224     new QListViewItem(rootItem, category[CARTESIAN_OTHER]);
02225     new QListViewItem(rootItem, category[CARTESIAN_SYMMETRY]);
02227   new QListViewItem(ListViewCategory, category[INTERNAL]);  
02229   rootItem = new QListViewItem(ListViewCategory, category[BASIC]);
02231   ListViewCategory->setSelected(rootItem, true);
02233   rootItem = 0;
02235   QListViewItemIterator it(ListViewCategory);
02236   int minWidth = 0;
02237   while(it.current())
02238   {
02239     int itemWidth = it.current()->width(fontMetrics(), ListViewCategory, 0);
02240     if(itemWidth > minWidth)
02241       minWidth = itemWidth;
02242     it++;
02243   }
02244   ListViewCategory->setFixedWidth(minWidth + 2*ListViewCategory->treeStepSize());
02245 
02248   // positive or negative
02249   QDoubleValidator* v = new QDoubleValidator(-99999999.0,999999999.,9,this);
02250   LineEditFRET->setValidator(v);
02251   LineEditTORO->setValidator(v);
02252   LineEditICWeight->setValidator(v);
02253   // positive only
02254   v = new QDoubleValidator(0.0,999999999.,9,this);
02255   LineEditSFAC1->setValidator(v);
02256   LineEditSFAC2->setValidator(v);
02257   LineEditFC->setValidator(v);
02258   LineEditXTFK1->setValidator(v);
02259   LineEditXTFK2->setValidator(v);
02260   LineEditXTFK3->setValidator(v);
02261   LineEditXTFK4->setValidator(v);
02262   LineEditXTFK5->setValidator(v);
02263   LineEditXTFK6->setValidator(v);
02264   LineEditREFT1->setValidator(v);
02265   LineEditREFT2->setValidator(v);
02266   LineEditREFT3->setValidator(v);
02267   LineEditREFT4->setValidator(v);
02268   LineEditREFT5->setValidator(v);
02269   LineEditTHRE1->setValidator(v);
02270   LineEditTHRE2->setValidator(v);
02271   LineEditTHRE3->setValidator(v);
02272   LineEditTHRE4->setValidator(v);
02273   LineEditUPDT->setValidator(v);
02274   LineEditSHRT1->setValidator(v);
02275   LineEditSHRT2->setValidator(v);
02276   LineEditSHRT3->setValidator(v); 
02277   v = 0;
02278 
02280   ToolButtonSFAC1->setIconSet(IconSets::getIconSet(IconSets::ArrowDown));
02281   ToolButtonSFAC2->setIconSet(IconSets::getIconSet(IconSets::ArrowUp));
02282   ToolButtonICAdd->setIconSet(IconSets::getIconSet(IconSets::New));
02283   ToolButtonICAdd2->setIconSet(IconSets::getIconSet(IconSets::NewPart));
02284   ToolButtonICGen->setIconSet(IconSets::getIconSet(IconSets::Generate));
02285   ToolButtonICRemove->setIconSet(IconSets::getIconSet(IconSets::Cut));
02286   ToolButtonICClear->setIconSet(IconSets::getIconSet(IconSets::Clear));
02287   ToolButtonICUp->setIconSet(IconSets::getIconSet(IconSets::ArrowUp));
02288   ToolButtonICDown->setIconSet(IconSets::getIconSet(IconSets::ArrowDown));
02289   ToolButtonFIXA1->setIconSet(IconSets::getIconSet(IconSets::ArrowRight));
02290   ToolButtonFIXA2->setIconSet(IconSets::getIconSet(IconSets::ArrowLeft));
02291   ToolButtonXBON1->setIconSet(IconSets::getIconSet(IconSets::ArrowRight));
02292   ToolButtonXBON2->setIconSet(IconSets::getIconSet(IconSets::ArrowLeft));
02293   ToolButtonExtraAdd->setIconSet(IconSets::getIconSet(IconSets::New));
02294   ToolButtonExtraRemove->setIconSet(IconSets::getIconSet(IconSets::Cut));
02295   ToolButtonExtraClear->setIconSet(IconSets::getIconSet(IconSets::Clear));
02296 
02298   CheckBoxSYMMx->setPixmap(IconSets::getPixmap(IconSets::SymmX));
02299   CheckBoxSYMMy->setPixmap(IconSets::getPixmap(IconSets::SymmY));
02300   CheckBoxSYMMz->setPixmap(IconSets::getPixmap(IconSets::SymmZ));
02301   CheckBoxSYMMxy->setPixmap(IconSets::getPixmap(IconSets::SymmXY));
02302   CheckBoxSYMMxz->setPixmap(IconSets::getPixmap(IconSets::SymmXZ));
02303   CheckBoxSYMMyz->setPixmap(IconSets::getPixmap(IconSets::SymmYZ));
02304   CheckBoxSYMMxyz->setPixmap(IconSets::getPixmap(IconSets::SymmXYZ));
02305 
02307   ListViewSFAC->setSorting(-1);
02308   ListViewIC->setSorting(-1);
02309   ListViewFIXA->setSorting(-1);
02310   ListViewXBON->setSorting(-1);
02311   
02313   resize(1,1);
02314 
02316   reset();
02317   saveWidgets();
02318   widgetChanged = false;
02319 }
02320 
02322 void RelaxBase::saveWidgets()
02324 {
02326   data.type = ComboBoxType->currentItem();
02327   data.autoGenerate = CheckBoxAutogen->isChecked();
02328   data.autoRegen = CheckBoxRegen->isChecked();
02329   data.autoGenFreq = SpinBoxGenFreq->value();
02330   data.autoHBonds = CheckBoxHBonds->isChecked();
02331   data.useOneScaleFactor = RadioButtonSFAC1->isChecked();
02332   data.sfacValue1 = LineEditSFAC1->text();
02333   data.sfacValue2 = LineEditSFAC2->text();
02334   data.sfacNumSteps = SpinBoxSFAC->value();
02335   data.listValues.clear();
02336   data.listNumSteps.clear();
02337   {
02338     QListViewItemIterator it(ListViewSFAC);
02339     for( ; it.current(); it++)
02340     {
02341       data.listValues += it.current()->text(0);
02342       data.listNumSteps.push_back(it.current()->text(1).toUInt());
02343     }
02344   }
02345   data.numDIIS = SpinBoxMAXD->value();
02346   data.printShifts = CheckBoxSUMM->isChecked();
02347   data.numSteps = SpinBoxSteps->value();
02348 
02350   data.ic.clear();
02351   {
02352     QListViewItemIterator it(ListViewIC);
02353     ICData tempIC;
02354     for ( ; it.current(); it++)
02355     {
02356       if(!it.current()->text(0).isEmpty())
02357       {
02359         tempIC.number = it.current()->text(0).toUInt();
02360         tempIC.rootItem = true;
02361       
02362         tempIC.type = it.current()->text(1);
02363         tempIC.fc = it.current()->text(2);
02364         tempIC.fix = it.current()->pixmap(3) != 0;
02365         tempIC.maximize = it.current()->pixmap(4) != 0;
02366         tempIC.refValue = it.current()->text(5);
02367       }
02368       else
02369       {
02371         tempIC.number = 0;
02372         tempIC.rootItem = false;
02373       }   
02374       tempIC.weight = it.current()->text(6);
02375       tempIC.atom1 = it.current()->text(7).section("-", 0, 0, QString::SectionSkipEmpty).replace(QRegExp("[A-Z, a-z]"), "").toUInt();
02376       tempIC.atom2 = it.current()->text(7).section("-", 1, 1, QString::SectionSkipEmpty).replace(QRegExp("[A-Z, a-z]"), "").toUInt();
02377       tempIC.atom3 = it.current()->text(7).section("-", 2, 2, QString::SectionSkipEmpty).replace(QRegExp("[A-Z, a-z]"), "").toUInt();
02378       tempIC.atom4 = it.current()->text(7).section("-", 3, 3, QString::SectionSkipEmpty).replace(QRegExp("[A-Z, a-z]"), "").toUInt();
02379       data.ic.push_back(tempIC);
02380     }
02381   }
02382 
02384   data.checkSymmetry = CheckBoxSYMM->isChecked();
02385   data.checkSymmX = CheckBoxSYMMx->isChecked();
02386   data.checkSymmY = CheckBoxSYMMy->isChecked();
02387   data.checkSymmZ = CheckBoxSYMMz->isChecked();
02388   data.checkSymmXY = CheckBoxSYMMxy->isChecked();
02389   data.checkSymmXZ = CheckBoxSYMMxz->isChecked();
02390   data.checkSymmYZ = CheckBoxSYMMyz->isChecked();
02391   data.checkSymmXYZ = CheckBoxSYMMxyz->isChecked();
02392 
02394   data.fixAtom = SpinBoxFIXA->value();
02395   data.fixX = CheckBoxFIXA1->isChecked();
02396   data.fixY = CheckBoxFIXA2->isChecked();
02397   data.fixZ = CheckBoxFIXA3->isChecked();
02398   data.listFixedAtoms.clear();
02399   data.listFixedXYZ.clear();
02400   {
02401     QListViewItemIterator it(ListViewFIXA);
02402     for ( ; it.current(); it++)
02403     {
02404       data.listFixedAtoms.push_back(it.current()->text(0).replace(QRegExp("[A-Z, a-z]"), "").toUInt());
02405       data.listFixedXYZ += it.current()->text(1);
02406     }
02407   }
02408   data.optExternal = CheckBoxTROT->isChecked();
02409   data.optExternalAngle = ComboBoxTROT->currentItem();
02410   data.optExternalA = LineEditXTFK1->text();
02411   data.optExternalB = LineEditXTFK2->text();
02412   data.optExternalC = LineEditXTFK3->text();
02413   data.optExternalAlpha = LineEditXTFK4->text();
02414   data.optExternalBeta  = LineEditXTFK5->text();
02415   data.optExternalGamma = LineEditXTFK6->text();
02416   data.mirrorImage = CheckBoxSIGN->isChecked();
02417   data.writeXYZ = CheckBoxANIM->isChecked();
02418 
02420   data.refineThre1 = LineEditREFT1->text();
02421   data.refineThre2 = LineEditREFT2->text();
02422   data.refineThre3 = LineEditREFT3->text();
02423   data.refineThre4 = LineEditREFT4->text();
02424   data.refineThre5 = LineEditREFT5->text();
02425   data.maxIter = SpinBoxITER->value();
02426   data.iterThre1 = LineEditTHRE1->text();
02427   data.iterThre2 = LineEditTHRE2->text();
02428   data.iterThre3 = LineEditTHRE3->text();
02429   data.iterThre4 = LineEditTHRE4->text();
02430 
02432   data.xbonAtom1 = SpinBoxXBON1->value();
02433   data.xbonAtom2 = SpinBoxXBON2->value();
02434   data.listXbonAtoms1.clear();
02435   data.listXbonAtoms2.clear();
02436   {
02437     QListViewItemIterator it(ListViewXBON);
02438     for ( ; it.current(); it++)
02439     {
02440       data.listXbonAtoms1.push_back(it.current()->text(0).replace(QRegExp("[A-Z, a-z]"), "").toUInt());
02441       data.listXbonAtoms2.push_back(it.current()->text(1).replace(QRegExp("[A-Z, a-z]"), "").toUInt());
02442     }
02443   }
02444   data.massType = ButtonGroupMASS->id(ButtonGroupMASS->selected());
02445   data.setLowFreqs = CheckBoxFRET->isChecked();
02446   data.lowFreqs = LineEditFRET->text();
02447   data.orden = CheckBoxORDA->isChecked();
02448 
02450   data.goon = CheckBoxGOON->isChecked();
02451   data.printDebug = CheckBoxLONG->isChecked();
02452   data.update = CheckBoxUPDT->isChecked();
02453   data.updateType = ComboBoxUPDT->currentItem();
02454   data.updateScaleFactor = LineEditUPDT->text();
02455   data.compact = CheckBoxSHRT->isChecked();
02456   data.compactBonds = LineEditSHRT1->text();
02457   data.compactAngles = LineEditSHRT2->text();
02458   data.compactTorsions = LineEditSHRT3->text();
02459 
02461   saveTable(Table, data.numLines, data.hPos, data.vPos, data.contents);
02462 }
02463 
02465 void RelaxBase::restoreWidgets()
02467 {
02469   ComboBoxType->setCurrentItem(data.type);
02470   CheckBoxAutogen->setChecked(data.autoGenerate);
02471   CheckBoxRegen->setChecked(data.autoRegen);
02472   SpinBoxGenFreq->setValue(data.autoGenFreq);
02473   CheckBoxHBonds->setChecked(data.autoHBonds);
02474   RadioButtonSFAC1->setChecked(data.useOneScaleFactor);
02475   RadioButtonSFAC2->setChecked(!data.useOneScaleFactor);
02476   LineEditSFAC1->setText(data.sfacValue1);
02477   LineEditSFAC2->setText(data.sfacValue2);
02478   SpinBoxSFAC->setValue(data.sfacNumSteps);
02479   ListViewSFAC->clear();
02480   { for(unsigned int i = 0; i < data.listNumSteps.size(); i++)
02481       new QListViewItem(ListViewSFAC, data.listValues[i], QString::number(data.listNumSteps[i])); }      
02482   SpinBoxMAXD->setValue(data.numDIIS);
02483   CheckBoxSUMM->setChecked(data.printShifts);
02484   SpinBoxSteps->setValue(data.numSteps);
02485 
02487   ListViewIC->clear();
02488   {
02489     QListViewItem* tempRoot = 0;
02490     QListViewItem* tempItem = 0;
02491     for(unsigned int i = 0; i < data.ic.size(); i++)
02492     {
02493       if(data.ic[i].rootItem)
02494       {
02496         tempItem = new QListViewItem(ListViewIC);
02497         tempItem->setText(0, QString::number(data.ic[i].number));
02498         tempItem->setText(1, data.ic[i].type);
02499         tempItem->setText(2, data.ic[i].fc);
02500         if(data.ic[i].fix)
02501           tempItem->setPixmap(3, IconSets::getPixmap(IconSets::OK));
02502         if(data.ic[i].maximize)
02503           tempItem->setPixmap(4, IconSets::getPixmap(IconSets::OK));      
02504         tempItem->setText(5, data.ic[i].refValue);
02505 
02506         tempRoot = tempItem;      
02507       }
02508       else
02509       {
02511         ASSERT(tempRoot != 0);
02512         tempItem = new QListViewItem(tempRoot);
02513       }
02514       tempItem->setText(6, data.ic[i].weight);
02515       tempItem->setText(7, icRepresentation(data.ic[i].atom1, data.ic[i].atom2, data.ic[i].atom3, data.ic[i].atom4));
02516     }
02517   }
02518 
02520   CheckBoxSYMM->setChecked(data.checkSymmetry);
02521   CheckBoxSYMMx->setChecked(data.checkSymmX);
02522   CheckBoxSYMMy->setChecked(data.checkSymmY);
02523   CheckBoxSYMMz->setChecked(data.checkSymmZ);
02524   CheckBoxSYMMxy->setChecked(data.checkSymmXY);
02525   CheckBoxSYMMxz->setChecked(data.checkSymmXZ);
02526   CheckBoxSYMMyz->setChecked(data.checkSymmYZ);
02527   CheckBoxSYMMxyz->setChecked(data.checkSymmXYZ);
02528 
02530   SpinBoxFIXA->setValue(data.fixAtom);
02531   CheckBoxFIXA1->setChecked(data.fixX);
02532   CheckBoxFIXA2->setChecked(data.fixY);
02533   CheckBoxFIXA3->setChecked(data.fixZ);
02534   ListViewFIXA->clear();
02535   { for(unsigned int i = 0; i < data.listFixedAtoms.size(); i++)
02536       new QListViewItem(ListViewFIXA, AtomSet::numToAtom(atoms->atomicNumber(data.listFixedAtoms[i]-1)).stripWhiteSpace() + QString::number(data.listFixedAtoms[i]), data.listFixedXYZ[i]); }
02537   CheckBoxTROT->setChecked(data.optExternal);
02538   ComboBoxTROT->setCurrentItem(data.optExternalAngle);
02539   LineEditXTFK1->setText(data.optExternalA);
02540   LineEditXTFK2->setText(data.optExternalB);
02541   LineEditXTFK3->setText(data.optExternalC);
02542   LineEditXTFK4->setText(data.optExternalAlpha);
02543   LineEditXTFK5->setText(data.optExternalBeta);
02544   LineEditXTFK6->setText(data.optExternalGamma);
02545   CheckBoxSIGN->setChecked(data.mirrorImage);
02546   CheckBoxANIM->setChecked(data.writeXYZ);
02547 
02549   LineEditREFT1->setText(data.refineThre1);
02550   LineEditREFT2->setText(data.refineThre2);
02551   LineEditREFT3->setText(data.refineThre3);
02552   LineEditREFT4->setText(data.refineThre4);
02553   LineEditREFT5->setText(data.refineThre5);
02554   SpinBoxITER->setValue(data.maxIter);
02555   LineEditTHRE1->setText(data.iterThre1);
02556   LineEditTHRE2->setText(data.iterThre2);
02557   LineEditTHRE3->setText(data.iterThre3);
02558   LineEditTHRE4->setText(data.iterThre4);
02559 
02561   SpinBoxXBON1->setValue(data.xbonAtom1);
02562   SpinBoxXBON2->setValue(data.xbonAtom2);
02563   ListViewXBON->clear();
02564   {
02565     for(unsigned int i = 0; i < data.listXbonAtoms1.size(); i++)
02566       new QListViewItem(ListViewXBON, AtomSet::numToAtom(atoms->atomicNumber(data.listXbonAtoms1[i]-1)).stripWhiteSpace() + QString::number(data.listXbonAtoms1[i]),
02567                                       AtomSet::numToAtom(atoms->atomicNumber(data.listXbonAtoms2[i]-1)).stripWhiteSpace() + QString::number(data.listXbonAtoms2[i]));
02568   }
02569   ButtonGroupMASS->setButton(data.massType);
02570   CheckBoxFRET->setChecked(data.setLowFreqs);
02571   LineEditFRET->setText(data.lowFreqs);
02572   CheckBoxORDA->setChecked(data.orden);
02573 
02575   CheckBoxGOON->setChecked(data.goon);
02576   CheckBoxLONG->setChecked(data.printDebug);
02577   CheckBoxUPDT->setChecked(data.update);
02578   ComboBoxUPDT->setCurrentItem(data.updateType);
02579   LineEditUPDT->setText(data.updateScaleFactor);
02580   CheckBoxSHRT->setChecked(data.compact);
02581   LineEditSHRT1->setText(data.compactBonds);
02582   LineEditSHRT2->setText(data.compactAngles);
02583   LineEditSHRT3->setText(data.compactTorsions);
02584 
02586   restoreTable(Table, data.numLines, data.hPos, data.vPos, data.contents);  
02587 }
02588 
02590 QString RelaxBase::icRepresentation(const unsigned int atom1, const unsigned int atom2, const unsigned int atom3, const int atom4)
02594 {
02595   QString result =  AtomSet::numToAtom(atoms->atomicNumber(atom1 - 1)).stripWhiteSpace() + QString::number(atom1);
02596   result +=   "-" + AtomSet::numToAtom(atoms->atomicNumber(atom2 - 1)).stripWhiteSpace() + QString::number(atom2);
02597   if(atom3 != 0)
02598     result += "-" + AtomSet::numToAtom(atoms->atomicNumber(atom3 - 1)).stripWhiteSpace() + QString::number(atom3);
02599   if(atom4 != 0)
02600   {
02601     if(atom4 == -1) 
02602       result += "-X";
02603     else if(atom4 == -2)
02604       result += "-Y";
02605     else if(atom4 == -3)
02606       result += "-Z";
02607     else
02608       result += "-" + AtomSet::numToAtom(atoms->atomicNumber(atom4 - 1)).stripWhiteSpace() + QString::number(atom4);
02609   }
02610   return result;  
02611 }
02612 
02614 void RelaxBase::getAtomsFromIC(const QString textIC, unsigned int& atom1, unsigned int& atom2, unsigned int& atom3, int& atom4)
02616 {
02617   atom1 = textIC.section("-", 0, 0, QString::SectionSkipEmpty).replace(QRegExp("[A-Z, a-z]"), "").toUInt();
02618   atom2 = textIC.section("-", 1, 1, QString::SectionSkipEmpty).replace(QRegExp("[A-Z, a-z]"), "").toUInt();
02619   atom3 = textIC.section("-", 2, 2, QString::SectionSkipEmpty).replace(QRegExp("[A-Z, a-z]"), "").toUInt();
02620   atom4 = textIC.section("-", 3, 3, QString::SectionSkipEmpty).replace(QRegExp("[A-Z, a-z]"), "").toUInt();
02621 
02622   if(atom4 == 0)
02623   {
02624     QString section4 = textIC.section("-", 3, 3, QString::SectionSkipEmpty);
02625     if(!section4.isEmpty())
02626     {
02627       if(section4 == "X")
02628         atom4 = -1;
02629       else if(section4 == "Y")
02630         atom4 = -2;
02631       else if(section4 == "Z")
02632         atom4 = -3;
02633     }
02634   }
02635 }
02636 
02638 void RelaxBase::renumberICs()
02640 {  
02641   unsigned int icNumber = 0;
02642   ListViewIC->blockSignals(true);
02643   QListViewItem* item = ListViewIC->firstChild();
02644   while(item != 0)
02645   {
02646     icNumber++;
02647     item->setText(0, QString::number(icNumber));
02648     item = item->nextSibling();
02649   }
02650   ListViewIC->blockSignals(false);
02651 }
02652 
02654 QStringList RelaxBase::generateAFFHeader()
02656 {
02657   QStringList result;
02658   
02659   result += "! " + tr("This file has been generated by") + " " + Version::appName + " " + Version::appVersion;
02660   result += "! " + tr("All changes made in this file will be lost!");
02662   result += inputLine("nato", static_cast<int>(atoms->count()));
02664   result  += "text      " + calcDescription;
02666   if(atoms->isLinear())
02667     result += "line";
02669   if(calcXF)
02670   {
02671     result += "xfcr";
02672     result += "xffo";
02673   }
02674       
02677   if(SpinBoxMAXD->value() != 0)
02678     result += inputLine("maxd", SpinBoxMAXD->value());
02680   if(CheckBoxSUMM->isChecked())
02681     result += "summ";
02683   result += "fdia";
02684 
02687   QListViewItem* item = ListViewIC->firstChild();
02688   while(item != 0)
02689   {
02690     if(item->pixmap(3) != 0)
02691       result += inputLine("fixc", item->text(0).toInt());  
02692     item = item->nextSibling();
02693   }
02695   item = ListViewIC->firstChild();
02696   while(item != 0)
02697   {
02698     if(item->pixmap(4) != 0)
02699       result += inputLine("maxi", item->text(0).toInt());
02700     item = item->nextSibling();
02701   }
02703   item = ListViewIC->firstChild();
02704   while(item != 0)
02705   {
02706     if(!item->text(5).isEmpty())
02707       result += inputLine("toro", item->text(0).toInt(), item->text(5).toDouble());
02708     item = item->nextSibling();
02709   }  
02710   
02712   if(CheckBoxSYMM->isChecked())
02713     result += validatedSYMMLine(CheckBoxSYMMx, CheckBoxSYMMy, CheckBoxSYMMz, CheckBoxSYMMxy, CheckBoxSYMMxz, CheckBoxSYMMyz, CheckBoxSYMMxyz);
02714 
02717   {
02718     QListViewItemIterator it(ListViewFIXA);
02719     for( ; it.current(); it++)
02720       result += inputLine("fixa", it.current()->text(0).replace(QRegExp("[A-Z, a-z]"), "").toInt()) + it.current()->text(1);
02721   }
02723   if(CheckBoxTROT->isChecked())
02724   {
02725     result += inputLine("trot", ComboBoxTROT->currentItem() + 1);
02726     result += "xtfk";
02727     QString temp1 =  QString::number(LineEditXTFK1->text().toDouble());
02728     temp1.truncate(13);
02729     QString temp2 = QString::number(LineEditXTFK2->text().toDouble());
02730     temp2.truncate(13);
02731     temp1 += " " + temp2;
02732     temp2 = QString::number(LineEditXTFK3->text().toDouble());
02733     temp2.truncate(13);
02734     temp1 += " " + temp2;
02735     temp2 = QString::number(LineEditXTFK4->text().toDouble());
02736     temp2.truncate(13);
02737     temp1 += " " + temp2;
02738     temp2 = QString::number(LineEditXTFK5->text().toDouble());
02739     temp2.truncate(13);
02740     temp1 += " " + temp2;
02741     temp2 = QString::number(LineEditXTFK6->text().toDouble());
02742     temp2.truncate(13);
02743     temp1 += " " + temp2;
02744     result += temp1;
02745   }
02747   if(CheckBoxSIGN->isChecked())
02748     result += "symm";
02750   if(CheckBoxANIM->isChecked())
02751     result += "anim";    
02752       
02755   double reft1 = LineEditREFT1->text().toDouble();
02756   double reft2 = LineEditREFT2->text().toDouble();
02757   double reft3 = LineEditREFT3->text().toDouble();
02758   double reft4 = LineEditREFT4->text().toDouble();
02759   double reft5 = LineEditREFT5->text().toDouble();
02760   if((reft1 != 0.0009) || (reft2 != 0.0009) || (reft3 != 0.0009) || (reft4 != 0.0009) || (reft5 != 0.0009))
02761   {
02762     if((reft1 == reft2) && (reft2 == reft3) && (reft3 == reft4) && (reft4 == reft5))
02763       result += inputLine("reft", reft1);
02764     else
02765     {
02766       result += "reft";
02767       QString a, b, c, d, e;
02768       a.setNum(reft1,'f',10).truncate(10);
02769       b.setNum(reft2,'f',10).truncate(10);
02770       c.setNum(reft3,'f',10).truncate(10);
02771       d.setNum(reft4,'f',10).truncate(10);
02772       e.setNum(reft5,'f',10).truncate(10);
02773       result += a + b + c + d + e;
02774     }    
02775   }
02777   if(SpinBoxITER->value() != 0)
02778     result += inputLine("iter", SpinBoxITER->value());
02780   double thre1 = - log10(LineEditTHRE1->text().toDouble()*pow(10.0, - LineEditTHRE2->text().toDouble()));
02781   double thre2 = - log10(LineEditTHRE3->text().toDouble()*pow(10.0, - LineEditTHRE4->text().toDouble())); 
02782   if((fabs(thre1 - 9.3019) > 0.00001) || (fabs(thre2 - 7.0) > 0.00001))
02783     result += inputLine("thre", thre1, thre2);
02784 
02787   {
02788     QListViewItemIterator it(ListViewXBON);
02789     while(it.current())
02790     {
02791       result += inputLine("xbon", it.current()->text(0).replace(QRegExp("[A-Z, a-z]"), "").toInt(),
02792                                   it.current()->text(1).replace(QRegExp("[A-Z, a-z]"), "").toInt());
02793       it++;
02794     }
02795   }
02797   switch(ButtonGroupMASS->id(ButtonGroupMASS->selected()))
02798   {
02799     case 1: result += "mass";
02800             break; 
02801     case 2: result += "avma";
02802   }
02804   if(CheckBoxFRET->isChecked())
02805     result += inputLine("fret", LineEditFRET->text().toDouble());
02807   if(CheckBoxORDA->isChecked())
02808     result += "orda";
02809 
02812   if(CheckBoxGOON->isChecked())
02813     result += "goon";
02815   if(CheckBoxLONG->isChecked())
02816     result += "long";
02818   if(CheckBoxUPDT->isChecked())
02819     result += inputLine("updt", ComboBoxUPDT->currentItem() + 1, LineEditUPDT->text().toDouble());
02821   if(CheckBoxSHRT->isChecked())
02822   {
02823     QString c, d;
02824     c.setNum(LineEditSHRT2->text().toDouble(),'f',10).truncate(10);
02825     d.setNum(LineEditSHRT3->text().toDouble(),'f',10).truncate(10);
02826     result += inputLine("shrt", SpinBoxSHRT->value(), LineEditSHRT1->text().toDouble()) + c + d;
02827   }  
02828 
02830   result += tableContents(Table);
02831 
02833   switch(ComboBoxType->currentItem())
02834   {
02835     case 0: result += "GBMA";
02836             break;
02837     case 1: result += "BMAT";
02838   }
02839   unsigned int icType = 0;
02840   double fc = 0.0;
02841   QListViewItemIterator it(ListViewIC);
02842   while(it.current())
02843   {
02844     QString line;
02845 
02847     if(!(it.current()->text(0).isEmpty()))
02848     {
02850       for(int i = 0; i < ComboBoxICType->count(); i++)
02851       {
02852         if(it.current()->text(1) == ComboBoxICType->text(i))
02853         {
02854           icType = i;
02855           break;
02856         }
02857       }
02858       fc = it.current()->text(2).toDouble();
02859       if(it.current()->pixmap(4) != 0)
02860         fc = -fc; // if maximizing the internal coordinate, the force constant should be negative
02861       QString fcString; fcString.setNum(fc,'f',7).truncate(7);
02862       line = "K " + fcString + " ";
02863     }
02864     else
02865     {
02867       line = "          ";
02868     }
02869 
02872     QString weightString; weightString.setNum(it.current()->text(6).toDouble(), 'f', 9).truncate(9);
02873     line += weightString + " ";    
02875     switch(icType)
02876     {
02877       case 0: 
02878               line += "stre      ";
02879               break;
02880       case 1: 
02881               line += "bend      ";
02882               break;
02883       case 2: 
02884               line += "tors      ";
02885               break;
02886       case 3: 
02887               line += "out       ";
02888               break;
02889       case 4: 
02890               line += "lin1      ";
02891               break;
02892     }         
02893     
02895     unsigned int atom1 = it.current()->text(7).section("-", 0, 0, QString::SectionSkipEmpty).replace(QRegExp("[A-Z, a-z]"), "").toUInt();
02896     unsigned int atom2 = it.current()->text(7).section("-", 1, 1, QString::SectionSkipEmpty).replace(QRegExp("[A-Z, a-z]"), "").toUInt();
02897     unsigned int atom3 = it.current()->text(7).section("-", 2, 2, QString::SectionSkipEmpty).replace(QRegExp("[A-Z, a-z]"), "").toUInt();
02898     QString atom4t = it.current()->text(7).section("-", 3, 3, QString::SectionSkipEmpty);  
02899     QString atom1s, atom2s, atom3s, atom4s;
02900     atom1s.setNum(atom1); atom1s += ".         "; atom1s.truncate(10);
02901     atom2s.setNum(atom2); atom2s += ".         "; atom2s.truncate(10);
02902     atom3s.setNum(atom3); atom3s += ".         "; atom3s.truncate(10);
02903     if(atom4t == "X")
02904       atom4s = "-1.";
02905     else if(atom4t == "Y")
02906       atom4s = "-2.";
02907     else if(atom4t == "Z")
02908       atom4s = "-3.";
02909     else
02910     {
02911       atom4s.setNum(atom4t.replace(QRegExp("[A-Z, a-z]"), "").toUInt()); atom4s += ".         "; atom4s.truncate(10);
02912     }
02913     switch(icType)
02914     {
02915       case 0: 
02916               line += atom1s + atom2s;
02917               break;
02918       case 1: 
02919               line += atom1s + atom3s + atom2s;
02920               break;
02921       case 2: 
02922               line += atom1s + atom2s + atom3s + atom4s;
02923               break;
02924       case 3: 
02925               line += atom1s + atom2s + atom3s + atom4s;
02926               break;
02927       case 4: 
02928               line += atom1s + atom2s + atom3s + atom4s;
02929     }
02930     result += line;
02931     if(icType == 4)
02932     {
02933       // linear bends always occur as pairs
02934       line.replace(23, 1, "2");
02935       result += line;
02936     }
02937     it++;
02938   }
02940   if(CheckBoxAutogen->isChecked())
02941   {
02942     if(CheckBoxRegen->isChecked())
02943     {
02944       result += "! " + tr("The following internal coordinates will be automatically generated");
02945       result += "! " + tr("every") + " " + QString::number(SpinBoxGenFreq->value()) + " " + tr("steps");
02946     }
02947     else
02948       result += "! " + tr("The following internal coordinates were automatically generated");
02949   }
02950   else
02951     result += "STOP";
02952 
02953   return result;
02954 }
02955 
02957 QStringList RelaxBase::generateBmatInput()
02961 {
02963   vector<unsigned int>* first;
02964   vector<unsigned int>* second;
02965   atoms->bonds(first, second);
02966 
02967   if(first->size() == 0)
02968     return QStringList(); // no bonds
02969 
02973 
02975   QStringList result = "1";
02977   for(unsigned int bond = 0; bond < first->size(); bond++)
02978   {
02979     const unsigned int atom1 = first->operator[](bond);
02980     const unsigned int atom2 = second->operator[](bond);
02981     
02982     if((atoms->numberOfBonds(atom1) > 1) && (atoms->numberOfBonds(atom2) > 1))
02983     {
02984       result += "2";
02985       result += QString::number(atom1) + "," + QString::number(atom2);
02986     }
02987   }
02989   if(CheckBoxHBonds->isChecked())
02990     result += "22";
02991 
02993   unsigned int a,b,c,d, numba, numbb, numbc, numbd;
02994   for(unsigned int i = 0; i < atoms->count(); i++)
02995   {
02997     vector<unsigned int> neighbours;
02998     for(unsigned int bond = 0; bond < first->size(); bond++)
02999     {
03000       const unsigned int atom1 = first->operator[](bond);
03001       const unsigned int atom2 = second->operator[](bond);
03002       if(atom1 == i)
03003         neighbours.push_back(atom2);
03004       else if(atom2 == i)
03005         neighbours.push_back(atom1);
03006     }
03007     if(neighbours.size() != atoms->numberOfBonds(i))
03008     {
03009       qDebug("Number of neighbours is not equal to number of bonds");
03010       qDebug("neighbours.size() = %d", static_cast<int>(neighbours.size()));
03011       qDebug("numberOfBonds() = %d", atoms->numberOfBonds(i));
03012       qDebug("first.size() = %d", static_cast<int>(first->size()));
03013       for(unsigned int bond = 0; bond < first->size(); bond++)
03014         qDebug("bond found between atoms %d and %d", first->operator[](bond), second->operator[](bond));
03015       qFatal("atom = %d",i);
03016     }
03017 
03031     switch(atoms->numberOfBonds(i))
03032     {
03033       case 0: 
03034       case 1: 
03035               break;
03036       case 2: 
03037 
03038               a = atoms->atomicNumber(neighbours[0]);
03039               b = atoms->atomicNumber(neighbours[1]);
03040               if((atoms->atomicNumber(i) == 8) && ((a == 1) || (b == 1))) // really special, do not add single bonded atoms
03041               {
03043                 result += "13";
03044                 QString stringX, stringH, stringO;
03045                 if(a == 1)
03046                   result += QString::number(neighbours[1]+1) + "," + QString::number(neighbours[0]+1) + "," + QString::number(i+1);
03047                 else
03048                   result += QString::number(neighbours[0]+1) + "," + QString::number(neighbours[1]+1) + "," + QString::number(i+1);
03049               }
03050               else
03051               {
03054                 QString stringD = "-1";
03055                 if(fabs(  atoms->y(neighbours[0])*atoms->z(neighbours[1])
03056                         - atoms->z(neighbours[0])*atoms->y(neighbours[1]) ) < 0.00001)
03057                   stringD = "-2";
03058                 result += QString::number(i+1) + "," + QString::number(neighbours[0]+1) + "," + QString::number(neighbours[1]+1) + "," + stringD;
03059               }
03060               break;
03061       case 3: 
03062 
03063 
03064 
03065               a = atoms->atomicNumber(neighbours[0]);
03066               b = atoms->atomicNumber(neighbours[1]);
03067               c = atoms->atomicNumber(neighbours[2]);
03068               if(atoms->atomicNumber(i) == 7) // really special, do not add halogens
03069               {
03071                 if(a == b == 1)
03072                 {
03074                   result += "8";
03075                   result += QString::number(i+1) + "," + QString::number(neighbours[2]+1) + "," + QString::number(neighbours[0]+1) + "," + QString::number(neighbours[1]+1);
03076                 }
03077                 else if(a == c == 1)
03078                 {
03080                   result += "8";
03081                   result += QString::number(i+1) + "," + QString::number(neighbours[1]+1) + "," + QString::number(neighbours[0]+1) + "," + QString::number(neighbours[2]+1);
03082                 }
03083                 else if(b == c == 1)
03084                 {
03086                   result += "8";
03087                   result += QString::number(i+1) + "," + QString::number(neighbours[0]+1) + "," + QString::number(neighbours[1]+1) + "," + QString::number(neighbours[2]+1);
03088                 }
03089                 else
03090                 {
03092                   result += "9";
03093                   result += QString::number(i+1) + "," + QString::number(neighbours[0]+1) + "," + QString::number(neighbours[1]+1) + "," + QString::number(neighbours[2]+1);
03094                 }
03095               }
03096               else
03097               {
03098                 numba = atoms->numberOfBonds(neighbours[0]);
03099                 numbb = atoms->numberOfBonds(neighbours[1]);
03100                 numbc = atoms->numberOfBonds(neighbours[2]);
03102                 if((a == b) && (numba == numbb == 1))
03103                 {
03105                   result += "5";
03106                   result += QString::number(i+1) + "," + QString::number(neighbours[2]+1) + "," + QString::number(neighbours[0]+1) + "," + QString::number(neighbours[1]+1);
03107 
03108                 }
03109                 else if((a == c) && (numba == numbc == 1))
03110                 {
03112                   result += "5";
03113                   result += QString::number(i+1) + "," + QString::number(neighbours[1]+1) + "," + QString::number(neighbours[0]+1) + "," + QString::number(neighbours[2]+1);
03114                 }
03115                 else if((b == c) && (numbb == numbc == 1))
03116                 {
03118                   result += "5";
03119                   result += QString::number(i+1) + "," + QString::number(neighbours[0]+1) + "," + QString::number(neighbours[1]+1) + "," + QString::number(neighbours[2]+1);
03120                 }
03121                 else
03122                 {
03124                   result += "6";
03125                   result += QString::number(i+1) + "," + QString::number(neighbours[0]+1) + "," + QString::number(neighbours[1]+1) + "," + QString::number(neighbours[2]+1);
03126                 }
03127               }
03128               break;
03129       case 4: 
03130 
03131 
03132               a = atoms->atomicNumber(neighbours[0]);
03133               b = atoms->atomicNumber(neighbours[1]);
03134               c = atoms->atomicNumber(neighbours[2]);
03135               d = atoms->atomicNumber(neighbours[3]);
03136               numba = atoms->numberOfBonds(neighbours[0]);
03137               numbb = atoms->numberOfBonds(neighbours[1]);
03138               numbc = atoms->numberOfBonds(neighbours[2]);
03139               numbd = atoms->numberOfBonds(neighbours[3]);
03140               if((a == b == c) && (numba == numbb == numbc == 1))
03141               {
03143                 result += "3";
03144                 result += QString::number(i+1) + "," + QString::number(neighbours[0]+1) + "," + QString::number(neighbours[1]+1) + "," + QString::number(neighbours[2]+1) + "," + QString::number(neighbours[3]+1);
03145               }
03146               else if((a == b == d) && (numba == numbb == numbd == 1))
03147               {
03149                 result += "3";
03150                 result += QString::number(i+1) + "," + QString::number(neighbours[0]+1) + "," + QString::number(neighbours[1]+1) + "," + QString::number(neighbours[3]+1) + "," + QString::number(neighbours[2]+1);
03151               }
03152               else if((a == c == d) && (numba == numbc == numbd == 1))
03153               {
03155                 result += "3";
03156                 result += QString::number(i+1) + "," + QString::number(neighbours[0]+1) + "," + QString::number(neighbours[2]+1) + "," + QString::number(neighbours[3]+1) + "," + QString::number(neighbours[1]+1);
03157               }
03158               else if((b == c == d) && (numbb == numbc == numbd == 1))
03159               {
03161                 result += "3";
03162                 result += QString::number(i+1) + "," + QString::number(neighbours[1]+1) + "," + QString::number(neighbours[2]+1) + "," + QString::number(neighbours[3]+1) + "," + QString::number(neighbours[0]+1);
03163               }
03164               else if((a == b) && (numba == numbb == 1))
03165               {
03167                 result += "4";
03168                 result += QString::number(i+1) + "," + QString::number(neighbours[2]+1) + "," + QString::number(neighbours[3]+1) + "," + QString::number(neighbours[0]+1) + "," + QString::number(neighbours[1]+1);
03169 
03170               }
03171               else if((a == c) && (numba == numbc == 1))
03172               {
03174                 result += "4";
03175                 result += QString::number(i+1) + "," + QString::number(neighbours[1]+1) + "," + QString::number(neighbours[3]+1) + "," + QString::number(neighbours[0]+1) + "," + QString::number(neighbours[2]+1);
03176               }
03177               else if((a == d) && (numba == numbd == 1))
03178               {
03180                 result += "4";
03181                 result += QString::number(i+1) + "," + QString::number(neighbours[1]+1) + "," + QString::number(neighbours[2]+1) + "," + QString::number(neighbours[0]+1) + "," + QString::number(neighbours[3]+1);
03182               }
03183               else if((b == c) && (numbb == numbc == 1))
03184               {
03186                 result += "4";
03187                 result += QString::number(i+1) + "," + QString::number(neighbours[0]+1) + "," + QString::number(neighbours[3]+1) + "," + QString::number(neighbours[1]+1) + "," + QString::number(neighbours[2]+1);
03188               }
03189               else if((b == d) && (numbb == numbd == 1))
03190               {
03192                 result += "4";
03193                 result += QString::number(i+1) + "," + QString::number(neighbours[0]+1) + "," + QString::number(neighbours[2]+1) + "," + QString::number(neighbours[1]+1) + "," + QString::number(neighbours[3]+1);
03194               }
03195               else if((c == d) && (numbc == numbd == 1))
03196               {
03198                 result += "4";
03199                 result += QString::number(i+1) + "," + QString::number(neighbours[0]+1) + "," + QString::number(neighbours[1]+1) + "," + QString::number(neighbours[2]+1) + "," + QString::number(neighbours[3]+1);
03200               }
03201               else
03202               {
03204                 result += "7";
03205                 result += QString::number(i+1) + "," + QString::number(neighbours[0]+1) + "," + QString::number(neighbours[1]+1) + "," + QString::number(neighbours[2]+1) + "," + QString::number(neighbours[3]+1);
03206               }
03207 
03208               break;
03209       default:
03210               qWarning("More than 4 bonds per atom are not supported by MAFF");
03211     }
03212   }
03214   result += "0";
03215   //if(CheckBoxFDIA->isChecked())
03216     result += "n";   // Only diagonal elements in F
03217   //else
03218   //  result += "y";   // Off-diagonal elements in F
03219 
03220   return result;
03221 }
03222 
03224 bool RelaxBase::makeDirCurrent(const QString dir, const QString title)
03227 {
03228   QDir workDir = dir;
03229   if(!workDir.exists())
03230   {
03231     if(!workDir.mkdir(workDir.path()))
03232     {
03233       QMessageBox::warning(this, title, tr("Unable to create the directory ") + workDir.path());
03234       return false;
03235     }
03236   }
03237   if(!QDir::setCurrent(workDir.path()))
03238   {
03239     QMessageBox::warning(this, title, tr("Unable to change to the directory ") + workDir.path());
03240     return false;
03241   }
03242   return true;
03243 }
03244 
03246 void RelaxBase::fillICListFromAFF(const QStringList aff)
03248 {
03250   vector<unsigned int> fixc, maxi, toro; // each value is the number of an internal coordinate
03251   vector<double> toroValues;
03253   QStringList::ConstIterator it = aff.begin();
03254   QString key;
03255   while(it != aff.end() && !(key == "gbma" || key == "bmat"))
03256   {
03257     key = (*it).left(4).lower();
03258     if(key == "fixc")
03259       fixc.push_back((*it).mid(10,10).toUInt());
03260     else if(key == "maxi")
03261       maxi.push_back((*it).mid(10,10).toUInt()); 
03262     else if(key == "toro")
03263     {
03264       toro.push_back((*it).mid(10,10).toUInt()); 
03265       toroValues.push_back((*it).mid(20,10).toDouble()); 
03266     }
03267     it++;
03268   }
03269 
03272   if(it == aff.end() && !aff.isEmpty())
03273     it = aff.begin();
03274 
03276   bool cnvrtaff = !(*it).mid(2,7).stripWhiteSpace().isEmpty();
03277 
03279   vector<double> fmat;
03280   if(!cnvrtaff)
03281   {
03282     // position the input after FMAT
03283     QStringList::ConstIterator itFMAT = it;
03284     while(itFMAT != aff.end() && (*itFMAT).left(4).lower() != "fmat")
03285       itFMAT++;
03286 
03287     // read as many doubles as possible as long as they decode OK;
03288     bool ok = true;
03289     while(itFMAT != aff.end() && ok)
03290     {
03291       QStringList values = QStringList::split(" ",*itFMAT);
03292       for(QStringList::Iterator itValues = values.begin(); itValues != values.end(); itValues++)
03293       {
03294         double fc = (*itValues).toDouble(&ok);
03295         if(!ok)
03296           break;
03297         fmat.push_back(fc);
03298       }
03299       itFMAT++;
03300     }
03301   }
03302   qDebug("force constants read from FMAT:");
03303   for(unsigned int i = 0; i < fmat.size(); i++)
03304     qDebug("%f",fmat[i]);
03305 
03307   unsigned int numAtoms = atoms->count();
03308 
03311   unsigned int numICs = 0;
03312 
03314   while(it != aff.end() && ((*it).left(2) == "K " || (*it).left(10).stripWhiteSpace().isEmpty()))
03315   {
03316     QString line = (*it).lower();
03317     //qDebug("parsing IC: "+line);
03318     if(!cnvrtaff && line.left(1) == "k")
03319       numICs++;
03320 
03322     // weight
03323     QString weight;
03324     if(line.mid(10,10).stripWhiteSpace().isEmpty())
03325       weight = "1.0";
03326     else
03327       weight = QString::number(line.mid(10,10).toDouble());
03328     // atom numbers
03329     unsigned int atom1 = static_cast<unsigned int>(line.mid(30,10).toDouble());
03330     unsigned int atom2 = static_cast<unsigned int>(line.mid(40,10).toDouble());
03331     unsigned int atom3 = static_cast<unsigned int>(line.mid(50,10).toDouble());
03332     int atom4 = static_cast<int>(line.mid(60,10).toDouble());
03333     if(atom1 > numAtoms || atom2 > numAtoms || atom3 > numAtoms || (atom4 > 0 && static_cast<unsigned int>(atom4) > numAtoms))
03334     {
03335       it++;
03336       continue;
03337     }
03338     // type
03339     QString type = line.mid(20,4);
03340     if(type == "stre")
03341     {
03342       type = tr("Stretch");
03343       atom3 = atom4 = 0;
03344     }
03345     else if(type == "bend")
03346     {
03347       type = tr("Bend");
03348       // swap atom2 and atom3 + clear atom4
03349       atom4 = atom2;
03350       atom2 = atom3;
03351       atom3 = atom4;
03352       atom4 = 0;
03353     }
03354     else if(type == "tors")
03355       type = tr("Torsion");
03356     else if(type == "out ")
03357       type = tr("Out-of-plane");
03358     else if(type == "lin1")
03359       type = tr("Linear bend");
03360     else if(type == "lin2")
03361     {
03362       it++; // LIN1 and LIN2 are always written as a pair in MAFF
03363       continue;
03364     }
03365 
03366     if(line.left(1) == "k")
03367     {
03369       newIC();
03370       QListViewItem* newItem = ListViewIC->selectedItem();
03371       newItem->setText(1, type);
03372       if(cnvrtaff)
03373         newItem->setText(2, QString::number(line.mid(2,7).toDouble())); // force constant from AFF
03374       else
03375         newItem->setText(2, QString::number(fmat[numICs-1]));
03376       newItem->setText(6, weight);
03377       newItem->setText(7, icRepresentation(atom1, atom2, atom3, atom4)); // force constant from FMAT
03379       if(std::find(fixc.begin(), fixc.end(), numICs) != fixc.end())
03380         newItem->setPixmap(3, IconSets::getPixmap(IconSets::OK));
03381       if(std::find(maxi.begin(), maxi.end(), numICs) != maxi.end())
03382         newItem->setPixmap(4, IconSets::getPixmap(IconSets::OK));
03383       if(!toro.empty())
03384       {
03385         vector<double>::iterator itToroValues = toroValues.begin();
03386         for(vector<unsigned int>::iterator itToro = toro.begin(); itToro != toro.end(); itToro++, itToroValues++)
03387         {
03388           if(*itToro == numICs)
03389             newItem->setText(5, QString::number(*itToroValues));
03390         }
03391       }
03392     }
03393     else
03394     { 
03396       newICPart();
03397       QListViewItem* newItem = ListViewIC->selectedItem();
03398       newItem->setText(6, weight);
03399       newItem->setText(7, icRepresentation(atom1, atom2, atom3, atom4));
03400     }
03401     it++;
03402   }
03403   
03408   if(!cnvrtaff && fmat.size() == numICs + 6)
03409   {
03410     LineEditXTFK1->setText(QString::number(fmat[fmat.size() - 6]));
03411     LineEditXTFK2->setText(QString::number(fmat[fmat.size() - 5]));
03412     LineEditXTFK3->setText(QString::number(fmat[fmat.size() - 4]));
03413     LineEditXTFK4->setText(QString::number(fmat[fmat.size() - 3]));
03414     LineEditXTFK5->setText(QString::number(fmat[fmat.size() - 2]));
03415     LineEditXTFK6->setText(QString::number(fmat[fmat.size() - 1]));
03416   }
03417 }
03418 
03420 bool RelaxBase::startMAFF(const unsigned int slot)
03423 {
03425   if(atoms->count() == 0)
03426     return false;    
03427   
03429   if(!makeDirCurrent(calcDir + QDir::separator() + "tmp", tr("Generate internal coordinates")))
03430     return false;
03431 
03433   if(CrdFactory::writeToFile(atoms, calcName + ".crd", calcXF) != CrdFactory::OK)
03434   {
03435     QMessageBox::warning(this, tr("Generate internal coordinates"), tr("Unable to write the cartesian coordinates"));
03436     return false;
03437   }
03438 
03440   QStringList maffInput = calcName; // Identification code
03441   if(calcXF)
03442     maffInput += "y"; // use extended format
03443   else
03444     maffInput += "n";
03445           
03446   switch(ComboBoxType->currentItem())
03447   {
03448     case 0:
03449 
03450       maffInput += "a"; // GBMA
03451       maffInput += "y"; // automatically generate the bond list
03452       maffInput += "n"; // add extra bonds
03453       if(CheckBoxHBonds->isChecked())
03454         maffInput += "y"; // add H-bonds      
03455       else
03456         maffInput += "n";                
03457       break;
03458       
03459     case 1:
03460 
03461       maffInput += "b";   // BMAT
03462       maffInput += "y";   // Use standard force constants
03463       maffInput += "y";   // Use diagonal force constant matrix
03464       maffInput += "n";   // Input op fort.4
03465 
03466       QStringList tempInput = generateBmatInput();
03467       if(tempInput.isEmpty())
03468         return false;
03469       else
03470         maffInput += tempInput;
03471       break;
03472   }
03473     
03475   maffProcess = new QProcess(this);
03476   // connect to the proper slot for processing of the output
03477   switch(slot)
03478   {
03479     case RelaxBase::PreviewAFF:    
03480       // generation of internal coordinates for showing as a preview
03481       connect(maffProcess, SIGNAL(processExited()), this, SLOT(showPreview2()));
03482       break;
03483     case RelaxBase::ICListAFF:     
03484       // generation of internal coordinates for filling in ListViewIC
03485       connect(maffProcess, SIGNAL(processExited()), this, SLOT(genIC2()));            
03486   }
03487   maffProcess->addArgument(Paths::maff);
03488   QString processStdin = maffInput.join("\n") + "\n";
03489   maffProcess->launch(processStdin);  
03490 
03491   return true;
03492 }
03493 
03495 QStringList RelaxBase::readMAFFGeneratedICs()
03497 {
03498   bool ok = maffProcess->normalExit();
03499   delete maffProcess;
03500   maffProcess = 0;
03501   if(!ok)
03502     return QStringList();
03503 
03506   QFile affFile(calcDir + QDir::separator() + "tmp" + QDir::separator() + calcName + ".aff");
03507   if(!affFile.exists())
03508   {
03509     QMessageBox::warning(this, tr("Generate internal coordinates"),tr("No internal coordinates were generated"));
03510     return QStringList();
03511   }
03512   if(!affFile.open(IO_ReadOnly))
03513   {
03514     QMessageBox::warning(this, tr("Generate internal coordinates"),tr("Unable to open the file ") + affFile.name());
03515     return QStringList();
03516   }
03518   QTextStream affStream(&affFile);
03519   while((affStream.readLine() != "FMAT") && !affStream.atEnd())
03520     ;
03521   vector<double> fc;
03522   double oneFC;
03523   while(!affStream.atEnd())
03524   {
03525     affStream >> oneFC;
03526     fc.push_back(oneFC);            
03527   }
03528      
03530   affFile.close();
03532   if(!affFile.open(IO_ReadOnly))
03533   {
03534     QMessageBox::warning(this, tr("Generate internal coordinates"),tr("Unable to open the file ") + affFile.name());
03535     return QStringList();
03536   }
03537   QTextStream affStream2(&affFile);
03538   QString line;
03539   while((line != "GBMA") && (line != "BMAT") && !affStream2.atEnd())
03540     line = affStream2.readLine();
03541 
03542   QStringList result;
03543   unsigned int counter = 0;
03544   line = affStream2.readLine(); // the first line after GBMA || BMAT
03545   while((line != "FMAT") && !affStream2.atEnd())
03546   {
03547     if(line.left(1) == "K")
03548     {
03549       if(counter == fc.size())
03550         break;
03551       QString fcString;
03552       fcString.setNum(fc[counter],'f',7).truncate(7);
03553       line = line.left(2) + fcString + line.mid(9);      
03554       counter++;
03555     }
03556     result += line;
03557     line = affStream2.readLine();    
03558   }    
03559      
03560   return result;
03561 }
03562 
03566 const RelaxBase::XMLData RelaxBase::xml = {
03568   "internal_coordinates_type",
03569   "autogenerate",
03570   "regenerate",   
03571   "generation_frequency",
03572   "hydrogen_bonds",
03573   "one_scale_factor",
03574   "scale_factor_single_value",
03575   "scale_factor_single_step",
03576   "scale_factor_number",
03577   "scale_factor_values",
03578   "scale_factor_steps",
03579   "diis",
03580   "shifts",
03581   "maximum_steps",
03583   "ic_numbers",
03584   "ic_root_items",
03585   "ic_types",
03586   "ic_force_constants",
03587   "ic_fixed",
03588   "ic_maximized",
03589   "ic_reference_values",
03590   "ic_weights",
03591   "ic_first_parts",
03592   "ic_second_parts",
03593   "ic_third_parts",
03594   "ic_fourth_parts",
03596   "symmetry_check",
03597   "symmetry_x__",
03598   "symmetry_y__",
03599   "symmetry_z__",
03600   "symmetry_xy_",
03601   "symmetry_xz_",
03602   "symmetry_yz_",
03603   "symmetry_xyz",
03605   "fix_atom_number",
03606   "fix_atom_x",
03607   "fix_atom_y",
03608   "fix_atom_z",
03609   "fixed_atom_numbers",
03610   "fixed_atom_axes",
03611   "use_external_coordinates",
03612   "external_angle",
03613   "external_coordinate_a_",
03614   "external_coordinate_b_",
03615   "external_coordinate_c_",
03616   "external_coordinate_alpha",
03617   "external_coordinate_beta",
03618   "external_coordinate_gamma",
03619   "mirror",
03620   "animate",
03622   "threshold_refine_1",
03623   "threshold_refine_2",
03624   "threshold_refine_3",
03625   "threshold_refine_4",
03626   "threshold_refine_5",
03627   "maximum_iterations",
03628   "threshold_iteration_1",
03629   "threshold_iteration_2",
03630   "threshold_iteration_3",
03631   "threshold_iteration_4",
03633   "extra_bond_1",
03634   "extra_bond_2",
03635   "extra_bond_list_1",
03636   "extra_bond_list_2",
03637   "mass",
03638   "low_frequencies_set",
03639   "low_frequencies_value",
03640   "orden",
03642   "override_checks",
03643   "debug_output",
03644   "use_update",
03645   "update_method",
03646   "update_scale_factor",
03647   "compact_output",
03648   "compact_bonds",
03649   "compact_angles",
03650   "compact_torsions",
03652   "extra_lines",
03653   "extra_hpos",
03654   "extra_vpos",
03655   "extra_contents"
03656 };
03657 

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