Coverage Report

Created: 2025-08-29 06:48

/src/openbabel/src/descriptors/cansmidescriptor.cpp
Line
Count
Source (jump to first uncovered line)
1
/**********************************************************************
2
cansmi.cpp - OBDescriptor class accessing Canonical SMILES
3
4
Copyright (C) 2009 by Chris Morley
5
6
This file is part of the Open Babel project.
7
For more information, see <http://openbabel.org/>
8
9
This program is free software; you can redistribute it and/or modify
10
it under the terms of the GNU General Public License as published by
11
the Free Software Foundation version 2 of the License.
12
13
This program is distributed in the hope that it will be useful,
14
but WITHOUT ANY WARRANTY; without even the implied warranty of
15
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
GNU General Public License for more details.
17
***********************************************************************/
18
19
#include <openbabel/babelconfig.h>
20
#include <openbabel/oberror.h>
21
#include <openbabel/tokenst.h>
22
#include <openbabel/obconversion.h>
23
#include <openbabel/descriptor.h>
24
25
using namespace std;
26
namespace OpenBabel
27
{
28
class CanSmiles : public OBDescriptor
29
{
30
public:
31
12
  CanSmiles(const char* ID, bool noStereo) : OBDescriptor(ID), _noStereo(noStereo){};
32
  const char* Description() override
33
0
  {
34
0
    return _noStereo ? "Canonical SMILES without isotopes or stereo" : "Canonical SMILES";
35
0
  };
36
  bool Compare(OBBase* pOb, istream& optionText, bool noEval, string* param = nullptr) override;
37
  double GetStringValue(OBBase* pOb, std::string& svalue, std::string* = nullptr) override;
38
private:
39
  bool _noStereo;
40
};
41
42
bool CanSmiles::Compare(OBBase* pOb, istream& optionText, bool noEval, string* param)
43
0
{
44
0
  string can;
45
0
  GetStringValue(pOb, can);
46
0
  return CompareStringWithFilter(optionText, can, noEval);
47
0
}
48
49
double CanSmiles::GetStringValue(OBBase* pOb, std::string& svalue, std::string*)
50
0
{
51
0
  OBConversion conv;
52
0
  conv.AddOption("n"); //no name
53
0
  if(_noStereo)
54
0
    conv.AddOption("i");
55
0
  if(conv.SetOutFormat("can"))
56
0
    svalue = conv.WriteString(pOb);
57
0
  else
58
0
    obErrorLog.ThrowError(__FUNCTION__, "SmilesFormat is not loaded" , obError);
59
0
  Trim(svalue);
60
61
0
  return std::numeric_limits<double>::quiet_NaN();
62
0
}
63
64
//Make a global instance
65
CanSmiles theCanSmiles("cansmi", false);
66
CanSmiles theCanSmilesNS("cansmiNS", true);
67
68
//**************************************************************
69
70
} //namespace