Ejemplo n.º 1
0
void ExcitedStates::initMoPlot()
{
   m_moPlot = new CustomPlot(); 
   m_moPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectPlottables);
   m_moPlot->axisRect()->setRangeDrag(Qt::Vertical);
   m_moPlot->axisRect()->setRangeZoom(Qt::Vertical);
   m_moPlot->xAxis->setSelectableParts(QCPAxis::spNone);
   
   QFrame* frame(m_configurator.moFrame);
   QVBoxLayout* layout(new QVBoxLayout());
   frame->setLayout(layout);
   layout->addWidget(m_moPlot);

   m_moPlot->yAxis->setLabel("Energy/Hartree");
   QSharedPointer<QCPAxisTickerText> textTicker(new QCPAxisTickerText);
   m_moPlot->xAxis->setTicker(textTicker);
   m_moPlot->xAxis->setRange(0,3.25);
   textTicker->addTick(0.75, "Alpha");
   textTicker->addTick(2.5, "Beta");

   Data::OrbitalSymmetries const& orbitals(m_excitedStates.stateData().orbitalSymmetries());

   unsigned nOrbs(orbitals.nOrbitals());
   unsigned nAlpha(orbitals.nAlpha());
   unsigned nBeta(orbitals.nBeta());
   QVector<double>  xAlpha(nOrbs), yAlpha(nOrbs), xBeta(nOrbs), yBeta(nOrbs); 
   QVector<double> a(1), b(1), y(1);
   QCPGraph* graph(0);


   Data::Spin spin(Data::Alpha);
   unsigned nElectrons(nAlpha);
   unsigned i(0), g(0);

   while (i < nOrbs) {
       y[0] = orbitals.energy(spin, i);

       g = 1; // degeneracy
       while (i+g < nOrbs && 
              std::abs(y[0]-orbitals.energy(spin, i+g)) < 0.001) { ++g; }

       for (unsigned k = i; k < i+g; ++k) {
           a[0]  = 0.75 - 0.25*(g-1) + (k-i)*0.50;
           graph = m_moPlot->addGraph();
           graph->setData(a, y);
           graph->setName(QString::number(k));
           graph->selectionDecorator()->setPen(m_selectedPen);
           graph->setScatterStyle(k < nElectrons ? QCPScatterStyle::ssOccupied 
                                                 : QCPScatterStyle::ssVirtual);
           connect(graph, SIGNAL(selectionChanged(bool)), this, SLOT(moSelectionChanged(bool)));
       }

       i += g;
   }

   i    = 0;
   spin = Data::Beta;
   nElectrons = nBeta;

   while (i < nOrbs) {
       y[0] = orbitals.energy(spin, i);

       g = 1; // degeneracy
       while (i+g < nOrbs && 
              std::abs(y[0]-orbitals.energy(spin, i+g)) < 0.001) { ++g; }

       for (unsigned k = i; k < i+g; ++k) {
           a[0]  = 2.50 - 0.25*(g-1) + (k-i)*0.50;
           graph = m_moPlot->addGraph();
           graph->setData(a, y);
           graph->setName(QString::number(k+nOrbs));
           graph->selectionDecorator()->setPen(m_selectedPen);
           graph->setScatterStyle(k < nElectrons ? QCPScatterStyle::ssOccupied 
                                                 : QCPScatterStyle::ssVirtual);
           connect(graph, SIGNAL(selectionChanged(bool)), this, SLOT(moSelectionChanged(bool)));
       }

       i += g;
   }

   // Set the scale to show 5 occupied and virtual orbitals to start with
   int nShow(5);

   // Use the beta energies if there are more of them
   if (nBeta > nAlpha) {
      spin = Data::Beta;
      nElectrons = nBeta;
   }else {
      spin = Data::Alpha;
      nElectrons = nAlpha;
   }

   unsigned index(std::max(0, (int)nElectrons-nShow));
   double   yMin(orbitals.energy(spin, index));
   index =  std::min((int)nElectrons+nShow, (int)nOrbs);
   double   yMax(orbitals.energy(spin, index));
   
   // enlarge the range by 5% for asthetics
   double dy(0.05*std::abs(yMax-yMin));
   m_moPlot->yAxis->setRange(yMin-dy,yMax+dy);
}
Ejemplo n.º 2
0
void ExcitedStates::initMoPlot()
{
   m_moPlot   = new QCustomPlot(); 
   m_moPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectPlottables);
   m_moPlot->axisRect()->setRangeDrag(m_moPlot->yAxis->orientation());
   m_moPlot->axisRect()->setRangeZoom(m_moPlot->yAxis->orientation());
   m_moPlot->xAxis->setSelectableParts(QCPAxis::spNone);
   
   QFrame* frame(m_configurator.moFrame);
   QVBoxLayout* layout(new QVBoxLayout());
   frame->setLayout(layout);
   layout->addWidget(m_moPlot);

   //layout->addWidget(new QLabel("This is a test"));
   //layout->setStretch(0,1);
   //layout->setStretch(1,0);

   QVector<double>  ticks;
   QVector<QString> labels;

   ticks << 0.75 << 2.50;
   labels << "Alpha" << "Beta";

   m_moPlot->xAxis->setAutoTicks(false);
   m_moPlot->xAxis->setAutoTickLabels(false);
   m_moPlot->xAxis->setTickVector(ticks);
   m_moPlot->xAxis->setTickVectorLabels(labels);
   m_moPlot->xAxis->setSubTickCount(0);
   m_moPlot->xAxis->setRange(0,3.25);

   Data::OrbitalSymmetries const& orbitals(m_excitedStates.data().orbitalSymmetries());

   unsigned nOrbs(orbitals.nOrbitals());
   unsigned nAlpha(orbitals.nAlpha());
   unsigned nBeta(orbitals.nBeta());
   QVector<double>  xAlpha(nOrbs), yAlpha(nOrbs), xBeta(nOrbs), yBeta(nOrbs); 
   QVector<double> a(1), b(1), y(1);
   QCPGraph* graph(0);

   unsigned i(0), g(0);

   Data::Spin spin(Data::Alpha);

   while (i < nOrbs) {
       y[0] = orbitals.energy(spin, i);

       g = 1; // degeneracy
       while (i+g < nOrbs && 
              std::abs(y[0]-orbitals.energy(spin, i+g)) < 0.001) { ++g; }

       for (unsigned k = i; k < i+g; ++k) {
           a[0]  = 0.75 - 0.25*(g-1) + (k-i)*0.50;
           graph = m_moPlot->addGraph();
           graph->setData(a, y);
           graph->setName(QString::number(k));
           graph->setScatterStyle(k<nAlpha ? QCPScatterStyle::ssOccupied 
                                           : QCPScatterStyle::ssVirtual);
           connect(graph, SIGNAL(selectionChanged(bool)), this, SLOT(moSelectionChanged(bool)));
       }

       i += g;
   }

   i    = 0;
   spin = Data::Beta;

   while (i < nOrbs) {
       y[0] = orbitals.energy(spin, i);

       g = 1; // degeneracy
       while (i+g < nOrbs && 
              std::abs(y[0]-orbitals.energy(spin, i+g)) < 0.001) { ++g; }

       for (unsigned k = i; k < i+g; ++k) {
           a[0]  = 2.50 - 0.25*(g-1) + (k-i)*0.50;
           graph = m_moPlot->addGraph();
           graph->setData(a, y);
           graph->setName(QString::number(k+nOrbs));
           graph->setScatterStyle(k<nBeta ? QCPScatterStyle::ssOccupied 
                                           : QCPScatterStyle::ssVirtual);
           connect(graph, SIGNAL(selectionChanged(bool)), this, SLOT(moSelectionChanged(bool)));
       }

       i += g;
   }

   m_moPlot->yAxis->setLabel("Energy/Hartree");
   m_moPlot->yAxis->setNumberPrecision(3);
   // Set the scale
   double yMin(-1.0), yMax(0.5);
   // Show 5 occupied and virtual orbitals to start with
   unsigned index, nShow(5);
   
   if (nBeta > nAlpha) {
      // Use the beta energies instead
      index = nBeta < nShow ? 0 : nBeta-nShow;
      yMin  = orbitals.energy(Data::Beta, index);
      index = nOrbs > nBeta+nShow ? nBeta+nShow : nOrbs;
      yMax  = orbitals.energy(Data::Beta, index);
   }else {
      index = nAlpha < nShow ? 0 : nAlpha-nShow;
      yMin  = orbitals.energy(Data::Alpha, index);
      index = nOrbs > nAlpha+nShow ? nAlpha+nShow : nOrbs;
      yMax  = orbitals.energy(Data::Alpha, index);
   }

   yMax = std::min(yMax, 0.5*std::abs(yMin));
   m_moPlot->yAxis->setRange(1.05*yMin,1.05*yMax);

   // add the orbital label
   m_label = new QCPItemText(m_moPlot);
   m_moPlot->addItem(m_label);
   m_label->position->setType(QCPItemPosition::ptViewportRatio); 
   m_label->setPositionAlignment(Qt::AlignTop|Qt::AlignRight);
   m_label->position->setCoords(0, 0); 
   m_label->setText("Orbital");
   m_label->setFont(QFont(font().family(), 10));
}