Example #1
0
 bool MopacAux::readDensityMatrix(unsigned int n)
 {
   m_density.resize(m_zeta.size(), m_zeta.size());
   unsigned int cnt = 0;
   unsigned int i = 0, j = 0;
   unsigned int f = 1;
   // Skip the first commment line...
   m_in.readLine();
   while (cnt < n) {
     QString line = m_in.readLine();
     QStringList list = line.split(' ', QString::SkipEmptyParts);
     for (int k = 0; k < list.size(); ++k) {
       //m_overlap.part<Eigen::SelfAdjoint>()(i, j) = list.at(k).toDouble();
       m_density(i, j) = m_density(j, i) = list.at(k).toDouble();
       ++i; ++cnt;
       if (i == f) {
         // We need to move down to the next row and increment f - lower tri
         i = 0;
         ++f;
         ++j;
       }
     }
   }
   return true;
 }
Example #2
0
bool GaussianFchk::readDensityMatrix(unsigned int n, int width)
{
  // This function reads in the lower triangular density matrix
  m_density.resize(m_numBasisFunctions, m_numBasisFunctions);
  unsigned int cnt = 0;
  unsigned int i = 0, j = 0;
  unsigned int f = 1;
  bool ok = false;
  while (cnt < n) {
    if (m_in->atEnd()) {
      qDebug() << "GaussianFchk::readDensityMatrix could not read all elements"
               << n << "expected" << cnt << "parsed.";
      return false;
    }
    QString line = m_in->readLine();
    if (line.isEmpty())
      return false;

    if (width == 0) { // we can split by spaces
      QStringList list = line.split(' ', QString::SkipEmptyParts);
      for (int k = 0; k < list.size(); ++k) {
        if (cnt >= n) {
          qDebug() << "Too many variables read in. File may be inconsistent."
                   << cnt << "of" << n;
          return false;
        }
        // Read in lower half matrix
        m_density(i, j) = list.at(k).toDouble(&ok);
        if (ok) { // Valid double converted, carry on
          ++j; ++cnt;
          if (j == f) {
            // We need to move down to the next row and increment f - lower tri
            j = 0;
            ++f;
            ++i;
          }
        }
        else { // Invalid conversion of a string to double
          qDebug() << "Warning: problem converting string to double:"
                   << list.at(k) << "\nIn GaussianFchk::readDensityMatrix.";
          return false;
        }
      }
    }
    else { // Q-Chem files use 16-character fields
      int maxColumns = 80 / width;
      for (int c = 0; c < maxColumns; ++c) {
        QString substring = line.mid(c * width, width);
        if (substring.length() != width)
          break;
        else if (cnt >= n) {
          qDebug() << "Too many variables read in. File may be inconsistent."
                   << cnt << "of" << n;
          return false;
        }
        // Read in lower half matrix
        m_density(i, j) = substring.toDouble(&ok);
        if (ok) { // Valid double converted, carry on
          ++j; ++cnt;
          if (j == f) {
            // We need to move down to the next row and increment f - lower tri
            j = 0;
            ++f;
            ++i;
          }
        }
        else { // Invalid conversion of a string to double
          qDebug() << "Warning: problem converting string to double:"
                   << substring << "\nIn GaussianFchk::readDensityMatrix.";
          return false;
        }
      }
    }
  }
  return true;
}
Example #3
0
bool GaussianSet::generateDensity()
{
  if (m_scfType == Unknown)
    return false;

  m_density.resize(m_numMOs, m_numMOs);
  m_density = MatrixX::Zero(m_numMOs, m_numMOs);
  for (unsigned int iBasis=0; iBasis < m_numMOs; ++iBasis) {
    for (unsigned int jBasis=0;jBasis<=iBasis; ++jBasis) {
      switch (m_scfType) {
      case Rhf:
        for (unsigned int iMO = 0; iMO < m_electrons[0] / 2; ++iMO) {
          double icoeff = m_moMatrix[0](iBasis, iMO);
          double jcoeff = m_moMatrix[0](jBasis, iMO);
          m_density(jBasis, iBasis) += 2.0 * icoeff * jcoeff;
          m_density(iBasis, jBasis) = m_density(jBasis, iBasis);
        }
        cout << iBasis << ", " << jBasis << ": "
             << m_density(iBasis, jBasis) << endl;
        break;
      case Uhf:
        for (unsigned int iaMO = 0; iaMO < m_electrons[0]; ++iaMO) {
          double icoeff = m_moMatrix[0](iBasis, iaMO);
          double jcoeff = m_moMatrix[0](jBasis, iaMO);
          m_density(jBasis, iBasis) += icoeff * jcoeff;
          m_density(iBasis, jBasis) = m_density(jBasis, iBasis);
        }
        for (unsigned int ibMO=0;ibMO < m_electrons[1]; ibMO++) {
          double icoeff = m_moMatrix[1](iBasis, ibMO);
          double jcoeff = m_moMatrix[1](jBasis, ibMO);
          m_density(jBasis, iBasis) += icoeff * jcoeff;
          m_density(iBasis, jBasis) = m_density(jBasis, iBasis);
        }
        cout << iBasis << ", " << jBasis << ": " << m_density(iBasis, jBasis)
             << endl;
        break;
      default:
        cout << "Unhandled scf type:" << m_scfType << endl;
      }
    }
  }
  return true;
}