<commit_before>#include <cassert>
#include <cstring>
#include <string>

#include <sqlite3ext.h>
extern const sqlite3_api_routines *sqlite3_api;

#include <RDGeneral/versions.h>
#include <GraphMol/RDKitBase.h>
#include <GraphMol/MolPickler.h>
#include <GraphMol/Descriptors/MolDescriptors.h>
#include <GraphMol/SmilesParse/SmilesParse.h>
#include <GraphMol/SmilesParse/SmartsWrite.h>
#include <GraphMol/SmilesParse/SmilesWrite.h>
#include <GraphMol/Substruct/SubstructMatch.h>
#include <GraphMol/Fingerprints/Fingerprints.h>
#include <GraphMol/Fingerprints/AtomPairs.h>
#include <GraphMol/Fingerprints/MorganFingerprints.h>
#include <GraphMol/Fingerprints/MACCS.h>
#include <DataStructs/ExplicitBitVect.h>
#include <DataStructs/BitOps.h>

#include "chemicalite.h"
#include "bfp_ops.h"
#include "rdkit_adapter.h"

struct Mol : RDKit::ROMol {
  Mol(const Mol & other) : RDKit::ROMol(other) {}
  Mol(const std::string & pickle) : RDKit::ROMol(pickle) {}
};

void free_mol(Mol *pMol)
{
  delete static_cast<RDKit::ROMol *>(pMol);
}

Mol * clone_mol(Mol *pMol)
{
  return new Mol(*pMol);
}

struct Bfp : std::string {
  Bfp() : std::string() {}
  Bfp(const Bfp & other) : std::string(other) {}
  Bfp(const std::string & other) : std::string(other) {}
  Bfp(const char* s, size_t n) : std::string(s, n) {}
};

void free_bfp(Bfp *pBfp) { delete pBfp; }

namespace {
  const unsigned int SSS_FP_SIZE            = 8*MOL_SIGNATURE_SIZE;
  const unsigned int LAYERED_FP_SIZE        = 1024;
  const unsigned int MORGAN_FP_SIZE         = 512;
  const unsigned int HASHED_TORSION_FP_SIZE = 1024;
  const unsigned int HASHED_PAIR_FP_SIZE    = 2048;
}

// SMILES/SMARTS <-> Molecule ////////////////////////////////////////////////

int txt_to_mol(const char * txt, int as_smarts, Mol **ppMol)
{
  assert(txt);
  int rc = SQLITE_OK;

  try {
    std::string data(txt);
    RDKit::ROMol *pROMol = as_smarts ?
      RDKit::SmartsToMol(data) : RDKit::SmilesToMol(data);
      *ppMol = static_cast<Mol *>(pROMol);
  } 
  catch (...) {
    // problem generating molecule from smiles
    *ppMol = 0;
    sqlite3_log(
      SQLITE_ERROR,
      "Conversion from '%s' to %s triggered an exception.",
      txt, as_smarts ? "qmol" : "mol"
      );
  }

  if (!*ppMol) {
    // parse error
    rc = SQLITE_ERROR;
    sqlite3_log(
      SQLITE_ERROR,
      "Could not convert '%s' to %s",
      txt, as_smarts ? "qmol" : "mol"
      );
  }

  return rc;
}

int mol_to_txt(Mol *pMol, int as_smarts, char **pTxt)
{
  assert(pMol);
  *pTxt = 0;
  int rc = SQLITE_OK;

  std::string txt;
  try {
    txt.assign( as_smarts ? 
		RDKit::MolToSmarts(*pMol, false) : 
		RDKit::MolToSmiles(*pMol, true) );
  } 
  catch (...) {
    // unknown exception
    rc = SQLITE_ERROR;
  }       <commit_msg>downgrade failure at converting text to mol/qmol from error to warning<commit_after>#include <cassert>
#include <cstring>
#include <string>

#include <sqlite3ext.h>
extern const sqlite3_api_routines *sqlite3_api;

#include <RDGeneral/versions.h>
#include <GraphMol/RDKitBase.h>
#include <GraphMol/MolPickler.h>
#include <GraphMol/Descriptors/MolDescriptors.h>
#include <GraphMol/SmilesParse/SmilesParse.h>
#include <GraphMol/SmilesParse/SmartsWrite.h>
#include <GraphMol/SmilesParse/SmilesWrite.h>
#include <GraphMol/Substruct/SubstructMatch.h>
#include <GraphMol/Fingerprints/Fingerprints.h>
#include <GraphMol/Fingerprints/AtomPairs.h>
#include <GraphMol/Fingerprints/MorganFingerprints.h>
#include <GraphMol/Fingerprints/MACCS.h>
#include <DataStructs/ExplicitBitVect.h>
#include <DataStructs/BitOps.h>

#include "chemicalite.h"
#include "bfp_ops.h"
#include "rdkit_adapter.h"

struct Mol : RDKit::ROMol {
  Mol(const Mol & other) : RDKit::ROMol(other) {}
  Mol(const std::string & pickle) : RDKit::ROMol(pickle) {}
};

void free_mol(Mol *pMol)
{
  delete static_cast<RDKit::ROMol *>(pMol);
}

Mol * clone_mol(Mol *pMol)
{
  return new Mol(*pMol);
}

struct Bfp : std::string {
  Bfp() : std::string() {}
  Bfp(const Bfp & other) : std::string(other) {}
  Bfp(const std::string & other) : std::string(other) {}
  Bfp(const char* s, size_t n) : std::string(s, n) {}
};

void free_bfp(Bfp *pBfp) { delete pBfp; }

namespace {
  const unsigned int SSS_FP_SIZE            = 8*MOL_SIGNATURE_SIZE;
  const unsigned int LAYERED_FP_SIZE        = 1024;
  const unsigned int MORGAN_FP_SIZE         = 512;
  const unsigned int HASHED_TORSION_FP_SIZE = 1024;
  const unsigned int HASHED_PAIR_FP_SIZE    = 2048;
}

// SMILES/SMARTS <-> Molecule ////////////////////////////////////////////////

int txt_to_mol(const char * txt, int as_smarts, Mol **ppMol)
{
  assert(txt);
  int rc = SQLITE_OK;

  try {
    std::string data(txt);
    RDKit::ROMol *pROMol = as_smarts ?
      RDKit::SmartsToMol(data) : RDKit::SmilesToMol(data);
      *ppMol = static_cast<Mol *>(pROMol);
  } 
  catch (...) {
    // problem generating molecule from smiles
    *ppMol = 0;
    sqlite3_log(
      SQLITE_ERROR,
      "Conversion from '%s' to %s triggered an exception.",
      txt, as_smarts ? "qmol" : "mol"
      );
  }

  if (!*ppMol) {
    // parse error
    rc = SQLITE_WARNING;
    sqlite3_log(
      rc,
      "Could not convert '%s' to %s",
      txt, as_smarts ? "qmol" : "mol"
      );
  }

  return rc;
}

int mol_to_txt(Mol *pMol, int as_smarts, char **pTxt)
{
  assert(pMol);
  *pTxt = 0;
  int rc = SQLITE_OK;

  std::string txt;
  try {
    txt.assign( as_smarts ? 
		RDKit::MolToSmarts(*pMol, false) : 
		RDKit::MolToSmiles(*pMol, true) );
  } 
  catch (...) {
    // unknown exception
    rc = SQLITE_ERROR;
  }       
{'fraction_non_alphanumeric': 0.1568733153638814, 'fraction_numerical': 0.008265947888589397, 'mean_word_length': 3.43859649122807, 'pattern_counts': {'":': 0, '<': 45, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1319406', 'n_tokens_mistral': 2288, 'n_tokens_neox': 2199, 'n_words': 438}