<commit_before>/*
 * SminaConverter.cpp
 *
 *  Created on: Jun 4, 2014
 *      Author: dkoes
 *
 *  Convert internal molecular data (ie OBMol) into smina parse tree.
 */

#include "SminaConverter.h"
#include "parsing.h"
#include "PDBQTUtilities.h"

#include <boost/archive/binary_oarchive.hpp>
#include <boost/archive/text_oarchive.hpp>
#include <boost/iostreams/filter/gzip.hpp>
#include <map>

namespace SminaConverter {

using namespace OpenBabel;
using namespace std;


MCMolConverter::MCMolConverter(OpenBabel::OBMol& m): mol(m)
{
	//precompute fragments and tree
	int nc = mol.NumConformers();
	mol.AddHydrogens();

	mol.SetAutomaticFormalCharge(false);
	DeleteHydrogens(mol); //leaves just polars

	//we kind of assume a connected molecule
	unsigned best_root_atom = FindFragments(mol, rigid_fragments);
	torsdof=rigid_fragments.size()-1;

	unsigned int root_piece = 0;
    for (unsigned j = 0; j < rigid_fragments.size(); j++)
    {
      if (IsIn((rigid_fragments[j]), best_root_atom)) {root_piece=j; break;} //this is the root rigid molecule fragment
    }

    ConstructTree(tree, rigid_fragments, root_piece, mol, true);

    assert(nc == mol.NumConformers()); //didn't lose any in analysis, did we?
}


//output data for this conformer
void MCMolConverter::convertConformer(unsigned conf, std::ostream& out)
{
	parsing_struct p;
	context c;

	mol.SetConformer(conf);
    OutputTree(mol, c, p, tree, torsdof);

	boost::iostreams::filtering_stream<boost::iostreams::output> strm;
	strm.push(boost::iostreams::gzip_compressor());
	strm.push(out);

	boost::archive::binary_oarchive serialout(strm,boost::archive::no_header|boost::archive::no_tracking);

	serialout << torsdof;
	serialout << p;
	serialout << c;
}

//sets up data structures used by both text and binary
//we link with smina to nsure compatibility
unsigned convertParsing(OBMol& mol, parsing_struct& p, context& c)
{
	mol.AddHydrogens();

	mol.SetAutomaticFormalCharge(false);
	DeleteHydrogens(mol); //leaves just polars
<commit_msg>bug fix for multiconformer smina conversion<commit_after>/*
 * SminaConverter.cpp
 *
 *  Created on: Jun 4, 2014
 *      Author: dkoes
 *
 *  Convert internal molecular data (ie OBMol) into smina parse tree.
 */

#include "SminaConverter.h"
#include "parsing.h"
#include "PDBQTUtilities.h"

#include <boost/archive/binary_oarchive.hpp>
#include <boost/archive/text_oarchive.hpp>
#include <boost/iostreams/filter/gzip.hpp>
#include <map>

namespace SminaConverter {

using namespace OpenBabel;
using namespace std;


MCMolConverter::MCMolConverter(OpenBabel::OBMol& m): mol(m)
{
	//precompute fragments and tree
	int nc = mol.NumConformers();
	mol.AddHydrogens();

	mol.SetAutomaticFormalCharge(false);
	DeleteHydrogens(mol); //leaves just polars

	//we kind of assume a connected molecule
	unsigned best_root_atom = FindFragments(mol, rigid_fragments);
	torsdof=rigid_fragments.size()-1;

	unsigned int root_piece = 0;
    for (unsigned j = 0; j < rigid_fragments.size(); j++)
    {
      if (IsIn((rigid_fragments[j]), best_root_atom)) {root_piece=j; break;} //this is the root rigid molecule fragment
    }

    ConstructTree(tree, rigid_fragments, root_piece, mol, true);

    assert(nc == mol.NumConformers()); //didn't lose any in analysis, did we?
}


//output data for this conformer
void MCMolConverter::convertConformer(unsigned conf, std::ostream& out)
{
	parsing_struct p;
	context c;

	mol.SetConformer(conf);
	std::map<unsigned int, obbranch> tmptree(tree); //tree gets modified by outputtree
    OutputTree(mol, c, p, tmptree, torsdof);

	boost::iostreams::filtering_stream<boost::iostreams::output> strm;
	strm.push(boost::iostreams::gzip_compressor());
	strm.push(out);

	boost::archive::binary_oarchive serialout(strm,boost::archive::no_header|boost::archive::no_tracking);

	serialout << torsdof;
	serialout << p;
	serialout << c;
}

//sets up data structures used by both text and binary
//we link with smina to nsure compatibility
unsigned convertParsing(OBMol& mol, parsing_struct& p, context& c)
{
	mol.AddHydrogens();

	mol.SetAutomaticFormalCharge(false);
	DeleteHydrogens(mol); //leaves just polars

{'fraction_non_alphanumeric': 0.12539336722343258, 'fraction_numerical': 0.0038731541999515854, 'mean_word_length': 5.2042042042042045, 'pattern_counts': {'":': 0, '<': 28, '<?xml version=': 0, '>': 14, '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': '2103405', 'n_tokens_mistral': 1492, 'n_tokens_neox': 1403, 'n_words': 350}