Example #1
0
  static bool isFacet(ZMatrix const &g, int index)
  {
    bool ret;
    dd_MatrixPtr M=NULL,M2=NULL,M3=NULL;
    dd_colrange d;
    dd_ErrorType err=dd_NoError;
    dd_rowset redrows,linrows,ignoredrows, basisrows;
    dd_colset ignoredcols, basiscols;
    dd_DataFileType inputfile;
    FILE *reading=NULL;

    cddinitGmp();

    M=ZMatrix2MatrixGmp(g, &err);
    if (err!=dd_NoError) goto _L99;

    d=M->colsize;

    static dd_Arow temp;
    dd_InitializeArow(g.getWidth()+1,&temp);

    ret= !dd_Redundant(M,index+1,temp,&err);

    dd_FreeMatrix(M);
    dd_FreeArow(g.getWidth()+1,temp);

    if (err!=dd_NoError) goto _L99;
    return ret;
   _L99:
    assert(0);
    return false;
  }
MpMatrix promote(const ZMatrix& orgData)
{
  const size_t rows = orgData.numberOfRows();
  const size_t cols = orgData.numberOfColumns();

  MpMatrix promoted(rows, cols);

  for (size_t i = 0; i < rows; ++i) {
    for (size_t j = 0; j < cols; ++j) {
      ZMatrix::ScalarType scalar = orgData[i][j];
      promoted[i][j] = (long) scalar; // for now it is enough, there is no support for long long.
      //      mpz_import(promoted[i][j].get_mpz_t(), 1, -1, sizeof(scalar), 0, 0, &scalar);
    }
  }

  return promoted;
}
Example #3
0
ZMatrix* FlyEm::ZBcfSet::load(const vector<string> &name)
{
  ZMatrix *matrix = NULL;
  for (vector<string>::const_iterator iter = name.begin(); iter != name.end();
       ++iter) {
    ZHdf5Reader reader;
    if (reader.open(m_featurePath + "/" + *iter + ".h5")) {
      mylib::Array *array = reader.readArray(*iter);

      if (matrix == NULL) {
        matrix = new ZMatrix(array->dims[0], array->dims[1]);
        matrix->copyValueFrom((double*) array->data);
      } else {
        int oldColumnNumber = matrix->getColumnNumber();
        matrix->resize(matrix->getRowNumber(),
                       matrix->getColumnNumber() + array->dims[1]);
        matrix->copyColumnValueFrom((double*) array->data, oldColumnNumber,
                                array->dims[1]);
      }

      mylib::Kill_Array(array);

      reader.close();
    } else {
      cout << "Failed to open " << *iter << endl;
    }
  }

  return matrix;
}
Example #4
0
 /*
   Heuristic for checking if inequality of full dimensional cone is a
   facet. If the routine returns true then the inequality is a
   facet. If it returns false it is unknown.
  */
 static bool fastIsFacetCriterion(ZMatrix const &normals, int i)
 {
   int n=normals.getWidth();
   for(int j=0;j<n;j++)
     if(normals[i][j].sign()!=0)
       {
         int sign=normals[i][j].sign();
         bool isTheOnly=true;
         for(int k=0;k<normals.getHeight();k++)
           if(k!=i)
             {
               if(normals[i][j].sign()==sign)
                 {
                   isTheOnly=false;
                   break;
                 }
             }
         if(isTheOnly)return true;
       }
   return false;
 }
Example #5
0
ZMatrix* FlyEm::ZBcfSet::load(const std::string &name)
{
  ZHdf5Reader reader;

  ZMatrix *matrix = NULL;

  if (reader.open(m_featurePath + "/" + name + ".h5")) {
    mylib::Array *array = reader.readArray(name);

#ifdef _DEBUG_2
    mylib::printArrayInfo(array);
    cout << ((double*)array->data)[0] << endl;
#endif
    matrix = new ZMatrix(array->dims[0], array->dims[1]);
    matrix->copyValueFrom((double*) array->data);

    mylib::Kill_Array(array);

    reader.close();
  }

  return matrix;
}
Example #6
0
void ZFlyEmMisc::NormalizeSimmat(ZMatrix &simmat)
{
  for (int j = 0; j < simmat.getColumnNumber(); ++j) {
    double maxC = simmat.getValue(j, j);
    for (int i = 0; i < simmat.getRowNumber(); ++i) {
      if (i != j) {
        double maxR = simmat.getValue(i, i);
        simmat.set(i, j, simmat.getValue(i, j) / dmax2(maxC, maxR));
      }
    }
  }
  simmat.setDiag(1);
}
Example #7
0
// Export data to the specified file
bool MOPAC71ControlModelPlugin::exportData()
{
	// Generate control lines
	int charge = pluginOptions_.value("charge").toInt();
	QString control1 = pluginOptions_.value("jobtype") + " " + pluginOptions_.value("hamiltonian") + " " + pluginOptions_.value("scftype") + " ";
	if (charge != 0) control1 += QString::number(charge) + " ";
	if (pluginOptions_.value("state") != "SINGLET") control1 += pluginOptions_.value("state") + " ";
	if (toBool(pluginOptions_.value("precise"))) control1 += "PRECISE ";
	if (toBool(pluginOptions_.value("campking"))) control1 += "KING ";
	if (!pluginOptions_.value("extra").isEmpty()) control1 += "+";

	// Write control and title lines
	if (!fileParser_.writeLine(control1)) return false;
	if (pluginOptions_.value("extra") != "") if (!fileParser_.writeLine(pluginOptions_.value("control2"))) return false;
	if (!fileParser_.writeLine(targetModel()->name())) return false;
	if (!fileParser_.writeLine("Coordinates churned out by Aten.")) return false;

	// Write atoms
	int fixedFlag;
	// -- If there are only three atoms we *must* use a zmatrix
	if (toBool(pluginOptions_.value("internal")) ||( targetModel()->nAtoms() <= 3))
	{
		ZMatrix* zmat = targetModel()->zMatrix();
		double distance, angle, torsion;
		int kk, jj, ll, count = 0;
		for (ZMatrixElement* ii = zmat->elements(); ii != NULL; ii = ii->next)
		{
			// Reset vars
			jj = 0;
			kk = 0;
			ll = 0;
			distance = 0.0;
			angle = 0.0;
			torsion = 0.0;

			// Grab ZMatrix data for element
			if (ii->distanceAtom())
			{
				jj = ii->distanceAtom()->id() + 1;
				distance = ii->distance();
			}
			if (ii->angleAtom())
			{
				kk = ii->angleAtom()->id() + 1;
				angle = ii->angle();
			}
			if (ii->torsionAtom())
			{
				ll = ii->torsionAtom()->id() + 1;
				torsion= ii->torsion();
			}

			// Write atom info
			fixedFlag = ii->atom(0)->isPositionFixed() ? 0 : 1;
			if (!fileParser_.writeLineF("%-3s  %11.6f %i  %11.6f %i  %11.6f %i  %i  %i  %i", ElementMap::symbol(ii->atom(0)->element()), distance, fixedFlag, angle, fixedFlag, torsion, jj, kk, ll)) return false;
		}
	}
	else
	{
		for (Atom* i = targetModel()->atoms(); i != NULL; i = i->next)
		{
			fixedFlag = i->isPositionFixed() ? 0 : 1;
			if (!fileParser_.writeLineF("%3s %12.6f %1i %12.6f %1i %12.6f %1i", ElementMap::symbol(i), i->r().x, fixedFlag, i->r().y, fixedFlag, i->r().z, fixedFlag)) return false;
		}
	}

	// Write translation vector for cell
	if (targetModel()->isPeriodic())
	{
		Matrix axes = targetModel()->cell().axes();
		if (!fileParser_.writeLineF("Tv  %12.6f 0 %12.6f 0 %12.6f 0\n", axes[0], axes[1], axes[2])) return false;
		if (!fileParser_.writeLineF("Tv  %12.6f 0 %12.6f 0 %12.6f 0\n", axes[4], axes[5], axes[6])) return false;
		if (!fileParser_.writeLineF("Tv  %12.6f 0 %12.6f 0 %12.6f 0\n", axes[8], axes[9], axes[10])) return false;
	}

	return true;
}