RDKit
Open-source cheminformatics and machine learning.
FileParserUtils.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2010 Greg Landrum and Rational Discovery LLC
3 //
4 // @@ All Rights Reserved @@
5 // This file is part of the RDKit.
6 // The contents are covered by the terms of the BSD license
7 // which is included in the file license.txt, found at the root
8 // of the RDKit source tree.
9 //
10 #include <RDGeneral/export.h>
11 #ifndef _RD_FILEPARSERUTILS_H
12 #define _RD_FILEPARSERUTILS_H
13 
14 #include <string>
15 #include <iostream>
17 #include <boost/lexical_cast.hpp>
18 #include <boost/algorithm/string.hpp>
20 
21 namespace RDKit {
22 class RWMol;
23 class Conformer;
24 
25 namespace FileParserUtils {
26 template <typename T>
27 T stripSpacesAndCast(const std::string &input, bool acceptSpaces = false) {
28  std::string trimmed = boost::trim_copy(input);
29  if (acceptSpaces && trimmed == "") {
30  return 0;
31  } else {
32  return boost::lexical_cast<T>(trimmed);
33  }
34 }
35 RDKIT_FILEPARSERS_EXPORT int toInt(const std::string &input, bool acceptSpaces = false);
36 RDKIT_FILEPARSERS_EXPORT double toDouble(const std::string &input, bool acceptSpaces = true);
37 
38 // reads a line from an MDL v3K CTAB
39 RDKIT_FILEPARSERS_EXPORT std::string getV3000Line(std::istream *inStream, unsigned int &line);
40 
41 // nAtoms and nBonds are ignored on input, set on output
42 RDKIT_FILEPARSERS_EXPORT bool ParseV3000CTAB(std::istream *inStream, unsigned int &line, RWMol *mol,
43  Conformer *&conf, bool &chiralityPossible,
44  unsigned int &nAtoms, unsigned int &nBonds,
45  bool strictParsing = true, bool expectMEND = true);
46 
47 // nAtoms and nBonds are used
48 RDKIT_FILEPARSERS_EXPORT bool ParseV2000CTAB(std::istream *inStream, unsigned int &line, RWMol *mol,
49  Conformer *&conf, bool &chiralityPossible,
50  unsigned int &nAtoms, unsigned int &nBonds,
51  bool strictParsing = true);
52 
54 }
55 }
56 
57 #endif
RDKIT_FILEPARSERS_EXPORT int toInt(const std::string &input, bool acceptSpaces=false)
#define RDKIT_FILEPARSERS_EXPORT
Definition: export.h:203
RDKIT_FILEPARSERS_EXPORT std::string getV3000Line(std::istream *inStream, unsigned int &line)
RWMol is a molecule class that is intended to be edited.
Definition: RWMol.h:31
RDKIT_FILEPARSERS_EXPORT bool ParseV2000CTAB(std::istream *inStream, unsigned int &line, RWMol *mol, Conformer *&conf, bool &chiralityPossible, unsigned int &nAtoms, unsigned int &nBonds, bool strictParsing=true)
RDKIT_FILEPARSERS_EXPORT double toDouble(const std::string &input, bool acceptSpaces=true)
Std stuff.
Definition: Atom.h:30
T stripSpacesAndCast(const std::string &input, bool acceptSpaces=false)
The class for representing 2D or 3D conformation of a molecule.
Definition: Conformer.h:42
RDKIT_FILEPARSERS_EXPORT bool ParseV3000CTAB(std::istream *inStream, unsigned int &line, RWMol *mol, Conformer *&conf, bool &chiralityPossible, unsigned int &nAtoms, unsigned int &nBonds, bool strictParsing=true, bool expectMEND=true)
RDKIT_FILEPARSERS_EXPORT Atom * replaceAtomWithQueryAtom(RWMol *mol, Atom *atom)
The class for representing atoms.
Definition: Atom.h:69