<commit_before>/*
 * molgridder.cpp
 *
 *  Created on: Apr 23, 2019
 *      Author: dkoes
 */

#include "molgridder.h"
#include <libmolgrid/cartesian_grid.h>
#include <boost/timer/timer.hpp>
#include <boost/lexical_cast.hpp>


using namespace std;
using namespace libmolgrid;

MolGridder::MolGridder(const gridoptions& opt) :
    dimension(opt.dim), resolution(opt.res),
    random_rotate(opt.randrotate), random_translate(opt.randtranslate),
    gmaker(opt.res, opt.dim), gpu(opt.gpu) {

  //setup typers
  rectyper = std::make_shared<FileMappedGninaTyper>(defaultGninaReceptorTyper);
  ligtyper = std::make_shared<FileMappedGninaTyper>(defaultGninaLigandTyper);

  if (opt.recmap.size() > 0) {
    rectyper = std::make_shared<FileMappedGninaTyper>(opt.recmap);
  }
  if (opt.ligmap.size() > 0) {
    ligtyper = std::make_shared<FileMappedGninaTyper>(opt.ligmap);
  }

  float3 dims = gmaker.get_grid_dims();
  grid = MGrid4f(rectyper->num_types()+ligtyper->num_types(), dims[0], dims[1], dims[2]);
  tee log(true);
  FlexInfo finfo(log); //dummy
  mols.create_init_model(opt.receptorfile, "", finfo, log);
  mols.setInputFile(opt.ligandfile);
  N = 1 + round(dimension / resolution);

  if (opt.examplegrid.size() > 0) set_from_example(opt.examplegrid);
  if (opt.usergrids.size()) set_usergrids(opt.usergrids);

  setReceptor(mols.getInitModel());
  if(opt.separate) setGrid(gpu);

  ex.sets.resize(2);
}

//set receptor coordinate set from model
void MolGridder::setReceptor(const model& m) {
  const atomv& atoms = m.get_fixed_atoms();
  vector<libmolgrid::cuda_float3> coords; coords.reserve(atoms.size());
  vector<unsigned> t; t.reserve(atoms.size());
  vector<float> r; t.reserve(atoms.size());

  for (unsigned i = 0, n = atoms.size(); i < n; i++) {
    const atom& a = atoms[i];
    auto t_r = rectyper->get_int_type(a.sm);<commit_msg>fix segfault<commit_after>/*
 * molgridder.cpp
 *
 *  Created on: Apr 23, 2019
 *      Author: dkoes
 */

#include "molgridder.h"
#include <libmolgrid/cartesian_grid.h>
#include <boost/timer/timer.hpp>
#include <boost/lexical_cast.hpp>


using namespace std;
using namespace libmolgrid;

MolGridder::MolGridder(const gridoptions& opt) :
    dimension(opt.dim), resolution(opt.res),
    random_rotate(opt.randrotate), random_translate(opt.randtranslate),
    gmaker(opt.res, opt.dim), gpu(opt.gpu) {

  ex.sets.resize(2); //ligand and receptor

  //setup typers
  rectyper = std::make_shared<FileMappedGninaTyper>(defaultGninaReceptorTyper);
  ligtyper = std::make_shared<FileMappedGninaTyper>(defaultGninaLigandTyper);

  if (opt.recmap.size() > 0) {
    rectyper = std::make_shared<FileMappedGninaTyper>(opt.recmap);
  }
  if (opt.ligmap.size() > 0) {
    ligtyper = std::make_shared<FileMappedGninaTyper>(opt.ligmap);
  }

  float3 dims = gmaker.get_grid_dims();
  grid = MGrid4f(rectyper->num_types()+ligtyper->num_types(), dims[0], dims[1], dims[2]);
  tee log(true);
  FlexInfo finfo(log); //dummy
  mols.create_init_model(opt.receptorfile, "", finfo, log);
  mols.setInputFile(opt.ligandfile);
  N = 1 + round(dimension / resolution);

  if (opt.examplegrid.size() > 0) set_from_example(opt.examplegrid);
  if (opt.usergrids.size()) set_usergrids(opt.usergrids);

  setReceptor(mols.getInitModel());
  if(opt.separate) setGrid(gpu);

}

//set receptor coordinate set from model
void MolGridder::setReceptor(const model& m) {
  const atomv& atoms = m.get_fixed_atoms();
  vector<libmolgrid::cuda_float3> coords; coords.reserve(atoms.size());
  vector<unsigned> t; t.reserve(atoms.size());
  vector<float> r; t.reserve(atoms.size());

  for (unsigned i = 0, n = atoms.size(); i < n; i++) {
    const atom& a = atoms[i];
    auto t_r = rectyper->get_int_type(a.sm);
{'fraction_non_alphanumeric': 0.1567043618739903, 'fraction_numerical': 0.009693053311793215, 'mean_word_length': 4.934504792332269, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 35, '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': '7200156', 'n_tokens_mistral': 1473, 'n_tokens_neox': 1416, 'n_words': 243}