示例#1
0
Data::GridDataList GridInfoDialog::getSelectedGrids()
{
   QTableWidget* table(m_dialog.gridTable);
   Data::GridDataList grids;

   QList<QTableWidgetItem*> items(table->selectedItems());
   QList<QTableWidgetItem*>::iterator iter;

   int row, col;
   for (iter = items.begin(); iter != items.end(); ++iter) {
       row = (*iter)->row();
       col = (*iter)->column();
       if (col == 0 && row >= 0 && row < m_gridDataList->size()) {
          grids.append((*m_gridDataList)[row]);
       }
   }

   return grids; 
}
示例#2
0
// This requires all the Grids be of the same size and all the orbitals to be
// of the same spin.  Returns true only if something was calculated.
bool MolecularOrbitals::computeOrbitalGrids(Data::GridDataList& grids)
{
   if (grids.isEmpty()) return false;;

   // Check that the grids are all of the same size and Spin
   Data::GridData* g0(grids[0]);
   QList<int> orbitals;
   Data::GridDataList::iterator iter;

   for (iter = grids.begin(); iter != grids.end(); ++iter) {
qDebug() << "Computing grid" << (*iter)->surfaceType().toString() ;
(*iter)->size().dump();
       if ( ((*iter)->size() != g0->size()) ) {
          QLOG_ERROR() << "Different sized grids found in molecular orbitals calculator";
          return false;
       }
       if ( ((*iter)->surfaceType().kind() != Data::SurfaceType::AlphaOrbital) &&
            ((*iter)->surfaceType().kind() != Data::SurfaceType::BetaOrbital) ) {
          QLOG_ERROR() << "Incorrect grid type found in molecular orbitals calculator";
          QLOG_ERROR() << (*iter)->surfaceType().toString(); 
          return false;
       }
       orbitals.append((*iter)->surfaceType().index()-1);
   }

   QTime time;
   time.start();

   Matrix const* coefficients;
   if (g0->surfaceType().kind() == Data::SurfaceType::AlphaOrbital) {
      QLOG_TRACE() << "Setting MO coefficient data to Alpha";
      coefficients = &(m_molecularOrbitals.alphaCoefficients());
   }else {
      QLOG_TRACE() << "Setting MO coefficient data to Beta";
      coefficients = &(m_molecularOrbitals.betaCoefficients());
   }
   
   unsigned nOrb(orbitals.size());
   unsigned nx, ny, nz;
   g0->getNumberOfPoints(nx, ny, nz);
   Vec delta(g0->delta());
   Vec origin(g0->origin());

   QProgressDialog* progressDialog(new QProgressDialog("Calculating orbital grid data", 
       "Cancel", 0, nx));
       
   int progress(0);

   progressDialog->setValue(progress);
   progressDialog->setWindowModality(Qt::WindowModal);
   progressDialog->show();

   double  x, y, z;
   double* values;
   double* tmp = new double[nOrb];
   unsigned i, j, k;

   Data::ShellList const& shells(m_molecularOrbitals.shellList());
   Data::ShellList::const_iterator shell;

   for (i = 0, x = origin.x;  i < nx;  ++i, x += delta.x) {
       for (j = 0, y = origin.y;  j < ny;  ++j, y += delta.y) {
           for (k = 0, z = origin.z;  k < nz;  ++k, z += delta.z) {
   
               Vec gridPoint(x,y,z);

               for (unsigned orb = 0; orb < nOrb; ++orb) tmp[orb] = 0.0;
               unsigned count(0);

               //-----------------------------------------------------
               for (shell = shells.begin(); shell != shells.end(); ++shell) {
                   if ( (values = (*shell)->evaluate(gridPoint)) ) {
                      for (unsigned s = 0; s < (*shell)->nBasis(); ++s) {
                          for (unsigned orb = 0; orb < nOrb; ++orb) {
                              tmp[orb] += (*coefficients)(orbitals[orb], count) * values[s];
                          }
                          ++count;
                      }
                   }else {
                      count += (*shell)->nBasis();
                   }
               }

               for (unsigned orb = 0; orb < nOrb; ++orb) {
                   (*grids.at(orb))(i, j, k) = tmp[orb];
               }
               //-----------------------------------------------------
           }
       }

       ++progress;
       progressDialog->setValue(progress);
       if (progressDialog->wasCanceled()) {
          delete [] tmp;
#ifndef Q_WS_WIN32
          delete progressDialog;
#endif
          return false;
       }
   }

   delete [] tmp;

   double t = time.elapsed() / 1000.0;
   QLOG_INFO() << "Time to compute orbital grid data:" << t << "seconds";

   return true;
}
示例#3
0
bool MolecularOrbitals::processGridQueue(GridQueue const& gridQueue)
{
   // First obtain a list of the unique grid sizes
   std::set<Data::GridSize> sizes;
   GridQueue::const_iterator queued; 
   for (queued = gridQueue.begin(); queued != gridQueue.end(); ++queued) {
       sizes.insert(queued->second);    
   }

   // Second, determine what data is required for each grid size
   QLOG_TRACE() << "Computing data for" << gridQueue.size() <<"grids";
   QLOG_TRACE() << "There are" << sizes.size() << "different grid sizes";
   std::set<Data::GridSize>::iterator size;

   for (size = sizes.begin(); size != sizes.end(); ++size) {
       std::set<Data::SurfaceType> densities;
       std::set<Data::SurfaceType> alphaOrbitals;
       std::set<Data::SurfaceType> betaOrbitals;
       
       for (queued = gridQueue.begin(); queued != gridQueue.end(); ++queued) {
           if (queued->second == *size) {
              Data::SurfaceType type(queued->first);

              if (type.isDensity()) {
                 densities.insert(type);
              }else if (type.kind() == Data::SurfaceType::AlphaOrbital) {
                 alphaOrbitals.insert(type);
              }else if (type.kind() == Data::SurfaceType::BetaOrbital) {
                 betaOrbitals.insert(type); 
              }else  {
                 QLOG_WARN() << "Unknown Grid type found in processQueue";
              }
           }
       }

       if (densities.size() > 0) {
          QLOG_TRACE() << "Computing" << densities.size() << "density grids";
          Data::SurfaceType alpha(Data::SurfaceType::AlphaDensity);
          Data::GridData*   alphaGrid = new Data::GridData(*size, alpha);
          Data::SurfaceType beta(Data::SurfaceType::BetaDensity);
          Data::GridData*   betaGrid  = new Data::GridData(*size, beta);

          if (!computeDensityGrids(alphaGrid, betaGrid)) {
             // user canceled the action
             delete alphaGrid;
             delete betaGrid;
             return false;
          }

          m_availableGrids.append(alphaGrid);
          m_availableGrids.append(betaGrid);

          Data::GridData* spinGrid  = new Data::GridData(*alphaGrid);
          *spinGrid -= *betaGrid;
          spinGrid->setSurfaceType(Data::SurfaceType::SpinDensity);

          Data::GridData* totalGrid = new Data::GridData(*alphaGrid);
          *totalGrid += *betaGrid;
          totalGrid->setSurfaceType(Data::SurfaceType::TotalDensity);

          m_availableGrids.append(spinGrid);
          m_availableGrids.append(totalGrid);
       }

       Data::GridDataList grids;
       std::set<Data::SurfaceType>::iterator iter;
       for (iter = alphaOrbitals.begin(); iter != alphaOrbitals.end(); ++iter) {
           Data::GridData* grid = new Data::GridData(*size, *iter);
           grids.append(grid); 
       }

       if (grids.count() > 0) {
          QLOG_TRACE() << "Computing" << grids.size() << "alpha orbitals";
          if (computeOrbitalGrids(grids)) {
             m_availableGrids += grids;
          }else {
             for (int i = 0; i <  grids.size(); ++i) {
                 delete grids[i];
             }
             return false;
          }
       }

       grids.clear();
       for (iter = betaOrbitals.begin(); iter != betaOrbitals.end(); ++iter) {
           Data::GridData* grid = new Data::GridData(*size, *iter);
           grids.append(grid); 
       }

       if (grids.count() > 0) {
          QLOG_TRACE() << "Computing" << grids.size() << "beta orbitals";
          if (computeOrbitalGrids(grids)) {
             m_availableGrids += grids;
          }else {
             for (int i = 0; i <  grids.size(); ++i) {
                 delete grids[i];
             }
             return false;
          }
       }
       grids.clear();
   }

   return true;
}