当前位置: 首页>>代码示例>>C++>>正文


C++ OBMol::Has2D方法代码示例

本文整理汇总了C++中OBMol::Has2D方法的典型用法代码示例。如果您正苦于以下问题:C++ OBMol::Has2D方法的具体用法?C++ OBMol::Has2D怎么用?C++ OBMol::Has2D使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在OBMol的用法示例。


在下文中一共展示了OBMol::Has2D方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: tmpStr

extern "C" int
ob_2D (char *molfile)
{
  OBMol mol;
  OBConversion conv;
  string tmpStr (molfile);
  istringstream molstream (tmpStr);
  int twod = 0;

  conv.SetInAndOutFormats ("MDL", "MDL");

  conv.Read (&mol, &molstream);

  if (mol.Has2D ())
    twod++;

  return (twod);
}
开发者ID:RitaDo,项目名称:pgchem,代码行数:18,代码来源:obwrapper.cpp

示例2: WriteSVG


//.........这里部分代码省略.........
   opts |= OBDepict::asymmetricDoubleBond;
  if(pConv->IsOption("X"))
    opts |= OBDepict::allExplicit;

  bool balldepict = false;
  if(pConv->IsOption("S"))
    balldepict = true;

  double factor = 1.0;
  int nc = _ncols ? _ncols : 1;
  int nr = (_nrows ? _nrows : 1);
  double cellsize = 100. / std::max(nc, nr);

  stringstream molfs;
  std::set<ColorGradient> gradients;

  OBOp* pOp = OBOp::FindType("gen2D");
  if(!pOp)
  {
    obErrorLog.ThrowError("SVGFormat", "gen2D not found", obError, onceOnly);
    return false;
  }

  vector<OBBase*>::iterator iter;
  int indx = 0;
  for(iter=_objects.begin(); ret && iter!=_objects.end(); ++iter,++indx)
  {
    OBMol* pmol = dynamic_cast<OBMol*>(*iter);

    if (!pmol)
      continue;
    //*** Coordinate generation ***
    //Generate coordinates only if no existing 2D coordinates
    if( (pConv->IsOption("y") || !pmol->Has2D(true)) && !pConv->IsOption("n") )
    {
      if(!pOp->Do(pmol))
      {
        obErrorLog.ThrowError("SVGFormat", string(pmol->GetTitle()) + "- Coordinate generation unsuccessful", obError);
        return false;
      }
    }
    if(!pmol->Has2D() && pmol->NumAtoms()>1)//allows 3D coordinates (if passed by -xn above)
    {
      string mes("Molecule ");
      mes += pmol->GetTitle();
      mes += " needs 2D coordinates to display in SVGformat";
      obErrorLog.ThrowError("SVGFormat", mes, obError);
      return false;
    }
    double innerX = 0.0;
    double innerY = 0.0;
    if(hasTable)
    {
      //*** Parameter for inner svg ***
      innerX  = (indx % nc) * cellsize;
      innerY  = (indx / nc) * cellsize;

      // Change the background in this cell if the condition in the first
      // parameter of  the -xh option is met. Use a default color if
      // the highlight color is not specified in the second parameter.
      const char* htxt = pConv->IsOption("h");
      if(htxt)
      {
        vector<string> vec;
        tokenize(vec, htxt);
        string highlight(vec.size()>1 ? vec[1] : "#f4f0ff");
开发者ID:ghutchis,项目名称:openbabel,代码行数:67,代码来源:svgformat.cpp

示例3: WriteMolecule

bool SVGFormat::WriteMolecule(OBBase* pOb, OBConversion* pConv)
{
  OBMol* pmol = dynamic_cast<OBMol*>(pOb);
  if(!pmol)
    return false;
  ostream &ofs = *pConv->GetOutStream();

  //Check for option for single mol in fixed size image
  const char* fixedpx = pConv->IsOption("P");
  if(!fixedpx)
    fixedpx= pConv->IsOption("px", OBConversion::GENOPTIONS);
  //If WriteMolecule called directly, e.g. from OBConversion::Write()
  //the default mode is a fixed image size of 200px square
  if(!fixedpx && !pConv->IsOption("svgwritechemobject"))
    fixedpx = "200";
  if(fixedpx)
  {
    _nmax = _nrows = _ncols = 1;
    pConv->AddOption("j");
    pConv->SetLast(true);
    pConv->SetOutputIndex(1);
  }

  //*** Coordinate generation ***
  //Generate coordinates only if no existing 2D coordinates
  if( (pConv->IsOption("y") || !pmol->Has2D(true)) && !pConv->IsOption("n") )
  {
    OBOp* pOp = OBOp::FindType("gen2D");
    if(!pOp)
    {
      obErrorLog.ThrowError("SVGFormat", "gen2D not found", obError, onceOnly);
      return false;
    }
    if(!pOp->Do(pmol))
    {
      obErrorLog.ThrowError("SVGFormat", string(pmol->GetTitle()) + "- Coordinate generation unsuccessful", obError);
      return false;
    }
  }
  if(!pmol->Has2D() && pmol->NumAtoms()>1)//allows 3D coordinates (if passed by -xn above)
  {
    string mes("Molecule ");
    mes += pmol->GetTitle();
    mes += " needs 2D coordinates to display in SVGformat";
    obErrorLog.ThrowError("SVGFormat", mes, obError);
    return false;
  }
  
  bool hasTable = (_nrows || _ncols);

  bool transparent=false;
  string background, bondcolor;
  const char* bg = pConv->IsOption("b");
  background = bg ? "black" : "white";
  bondcolor  = bg ? "white" : "black";
  if(bg && (!strcmp(bg, "none") || bg[0]=='0'))
  {
    transparent = true;
    bondcolor = "gray";
  }
  const char* bcol = pConv->IsOption("B");
  if(bcol && *bcol)
    bondcolor = bcol;
  if(bg && *bg)
    background = bg;
  
  if(pConv->GetOutputIndex()==1 || fixedpx)
  {
    //For the first molecule...
    if(hasTable)
    {
      //multiple molecules - use a table
      //Outer svg has viewbox for 0 0 100 100 or adjusted for table shape,
      //and no width or height - it uses the whole of its containing element.
      //Inner svg with width, height, x, y of table cell,
      //and viewbox to match molecule min and max x and y
      if(!pConv->IsOption("x"))
        ofs << "<?xml version=\"1.0\"?>\n";

      ofs << "<svg version=\"1.1\" id=\"topsvg\"\n"
             "xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n"
             "xmlns:cml=\"http://www.xml-cml.org/schema\" ";

      //*** Outer viewbox ***
      double vbwidth=100, vbheight=100;
      if (_nrows>_ncols)
        vbwidth = (100*_ncols)/_nrows;
      else if(_ncols>_nrows)
        vbheight = (100*_nrows)/_ncols;

      if(fixedpx)//fixed size image
        ofs << "x=\"0\" y=\"0\" width=\"" << fixedpx << "px\" height=\"" << fixedpx <<"px\" ";
      else
        ofs << "x=\"0\" y=\"0\" width=\"100%\" height=\"100%\" ";
      
      ofs << "viewBox=\"0 0 " << vbwidth << ' ' << vbheight << "\">\n";

      ofs << "<title>OBDepict</title>\n";
      // Draw the background unless transparent
      if(!transparent)
//.........这里部分代码省略.........
开发者ID:Antipina,项目名称:OpenBabel-BFGS,代码行数:101,代码来源:svgformat.cpp

示例4: WriteMolecule

bool SVGFormat::WriteMolecule(OBBase* pOb, OBConversion* pConv)
{
    OBMol* pmol = dynamic_cast<OBMol*>(pOb);
    if(!pmol)
        return false;
    ostream &ofs = *pConv->GetOutStream();

    //*** Coordinate generation ***
    //Generate coordinates only if no existing 2D coordinates
    if( (pConv->IsOption("y") || !pmol->Has2D(true)) && !pConv->IsOption("n") )
    {
        OBOp* pOp = OBOp::FindType("gen2D");
        if(!pOp)
        {
            obErrorLog.ThrowError("SVGFormat", "gen2D not found", obError, onceOnly);
            return false;
        }
        if(!pOp->Do(pmol))
        {
            obErrorLog.ThrowError("SVGFormat", string(pmol->GetTitle()) + "- Coordinate generation unsuccessful", obError);
            return false;
        }
    }
    if(!pmol->Has2D() && pmol->NumAtoms()>1)//allows 3D coordinates (if passed by -xn above)
    {
        string mes("Molecule ");
        mes += pmol->GetTitle();
        mes += " needs 2D coordinates to display in SVGformat";
        obErrorLog.ThrowError("SVGFormat", mes, obError);
        return false;
    }

    bool hasTable = (_nrows || _ncols);

    string background = pConv->IsOption("b") ? "black" : "white";
    string bondcolor  = pConv->IsOption("b") ? "white" : "black";

    if(pConv->GetOutputIndex()==1)
    {
        //For the first molecule...
        if(hasTable)
        {
            //multiple molecules - use a table
            //Outer svg has viewbox for 0 0 100 100 or adjusted for table shape,
            //and no width or height - it uses the whole of its containing element.
            //Inner svg with width, height, x, y of table cell,
            //and viewbox to match molecule min and max x and y
            if(!pConv->IsOption("x"))
                ofs << "<?xml version=\"1.0\"?>\n";

            ofs << "<svg version=\"1.1\" id=\"topsvg\"\n"
                "xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n"
                "xmlns:cml=\"http://www.xml-cml.org/schema\" ";

            //*** Outer viewbox ***
            double vbwidth=100, vbheight=100;
            if (_nrows>_ncols)
                vbwidth = (100*_ncols)/_nrows;
            else if(_ncols>_nrows)
                vbheight = (100*_nrows)/_ncols;
            ofs << "viewBox=\"0 0 " << vbwidth << ' ' << vbheight << "\">\n";

            ofs << "<title>OBDepict</title>\n";
            // Draw the background
            ofs << "<rect x=\"0\" y=\"0\" width=\"" << vbwidth << "\" height=\"" << vbheight
                << "\" fill=\"" << background << "\"/>\n";
        }
    }

    //All mols
    double cellsize;
    if(hasTable)
    {
        //*** Parameter for inner svg ***
        int nc = _ncols ? _ncols : 1;
        int nr = (_nrows ? _nrows : 1);
        cellsize = 100. / std::max(nc, nr);
        int indx = pConv->GetOutputIndex() - 1;
        double innerX  = (indx % nc) * cellsize;
        double innerY  = (indx / nc) * cellsize;

        //*** Write molecule name ***
        if(!pConv->IsOption("d"))
            ofs << "<text text-anchor=\"middle\" font-size=\"" << 0.06*cellsize << "\""
                << " fill =\"" << bondcolor << "\" font-family=\"sans-serif\"\n"
                << "x=\"" << innerX + cellsize * 0.5 << "\" y=\"" << innerY + cellsize - 2.0/nr << "\" >"
                << pmol->GetTitle() << "</text>\n";

        SVGPainter painter(*pConv->GetOutStream(), true, cellsize,cellsize,innerX,innerY);
        OBDepict depictor(&painter);

        if(pConv->IsOption("w"))
            depictor.SetOption(OBDepict::genWedgeHash);
        if(!pConv->IsOption("C"))
            depictor.SetOption(OBDepict::drawTermC);// on by default
        if(pConv->IsOption("a"))
            depictor.SetOption(OBDepict::drawAllC);

        if(pConv->IsOption("A"))
        {
//.........这里部分代码省略.........
开发者ID:sneumann,项目名称:pgchem,代码行数:101,代码来源:svgformat.cpp


注:本文中的OBMol::Has2D方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。