<commit_before>/* 
 * Copyright 2009-2011 The VOTCA Development Team (http://www.votca.org)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

#include <votca/csg/topologyreader.h>
#include <votca/csg/trajectoryreader.h>
#include <boost/program_options.hpp>
#include <boost/tokenizer.hpp>
#include <votca/csg/version.h>
#include <iostream>
#include <fstream>


using namespace std;
namespace po = boost::program_options;
using namespace votca::csg;
using namespace votca::tools;

/**
 *  *** Analyze particle distribution as a function of a coordinate ***
 *
 *  This program reads a topology and (set of) trajectory(ies). For every
 *  binned value of a chose coordinate, it outputs the time-averaged number of
 *  particles, listed by particle types.
 */
void help_text(void)
{
    votca::csg::HelpTextHeader("csg_part_dist");
    cout << "This program reads a topology and (set of) trajectory(ies). For every\n"
	"binned value of a chosen coordinate, it outputs the time-averaged number of\n"
	"particles, listed by particle types.\n\n";
}

void check_option(po::options_description &desc, po::variables_map &vm, const string &option)
{
    if(!vm.count(option)) {
        cout << "csg_part_dist \n\n";
        cout << desc << endl << "parameter " << option << " is not specified\n";
        exit(1);
    }
}

int main(int argc, char** argv)
{
    string top_file, trj_file, ptypes_file, out_file, grid, 
	comment, string_tmp, coordinate="z";
    double min, max, step, coord, com(0.);
    vector<int> ptypes;
    ifstream fl_ptypes;
    ofstream fl_out;
    Topology top;
    TopologyReader *reader;
    TrajectoryReader *trajreader;
    int part_type, n_bins, first_frame(0), last_frame(-1), 
	flag_found(0), **p_occ = NULL, n_part(0), frame_id(0),
	analyzed_frames(0);
    bool moreframes(1), not_the_last(1);

    MoleculeContainer::iterator mol;    
    // Load topology+trajectory formats
    TopologyReader::RegisterPlugins();
    TrajectoryReader::RegisterPlugins();

    // read program options
    namespace po = boost::program_options;

    // Declare the supported options.
    po::options_description desc("Allowed options");
    
    // let cg_engine add some program options
    desc.add_options()
	("top", po::value<string>(&top_file), "topology file")
	("trj", po::value<string>(&trj_file), "trajectory file")
	("grid", po::value<string>(&grid), "output grid spacing (min:step:max)")
	("out", po::value<string>(&out_file), 
	 "output particle distribution table")
	("ptypes", po::value<string>(&ptypes_file),
	 "particle types to include in the analysis\n"
	 " arg: file - particle types separated by space"
	 "\n default: all particle types")
	("first_frame", po::value<int>(&first_frame), "first frame considered for analysis")
	("last_frame", po::value<int>(&last_frame), "last frame considered for analysis")
	("coord", po::value<string>(&coordinate), "coordinate analyzed ('x', 'y', or 'z' (default))")
	("shift_com", "shift center of mass to zero")
	("comment", po::value<string>(&comment), "store a comment in the output table")
	("help", "produce this help message");
    
    // now read in the command line
    po::variables_map vm;
    try {
	po::store(po::parse_command_line(argc, argv, desc), vm);
	po::notify(vm);
    }
    catch(po::error& err) {
	cout << "error parsing command line: " << err.what() << endl;
	return -1;
    }

    // does the user want help?
    if (vm.count("help")) {
        help_text();
        cout << desc << endl;
        return 0;
    }

    check_option(desc, vm, "top");
    check_option(desc, vm, "trj");
    check_option(desc, vm, "out");
    check_option(desc, vm, "grid");

    if (coordinate.compare("x") != 0 && coordinate.compare("y") != 0 && coordinate.compare("z") != 0) {
	cout << "Bad format for coordinate: " << coordinate << endl;
	return 1;
    }

    // Parse grid
    Tokenizer tok(grid, ":");
    vector<string> toks;
    tok.ToVector(toks);
    if(toks.size()!=3) {
	cout << "Wrong range format, use min:step:max\n";
	return 1;
    }
    min = boost::lexical_cast<double>(toks[0]);
    step = boost::lexical_cast<double>(toks[1]);
    max = boost::lexical_cast<double>(toks[2]);
    // Calculate number of bins
    n_bins = (int)((max-min)/(1.*step)+1);

    try {
	// Load topology
        reader = TopReaderFactory().Create(vm["top"].as<string>());
        if(reader == NULL) <commit_msg>switched lexical_cast<double> to stod<commit_after>/* 
 * Copyright 2009-2011 The VOTCA Development Team (http://www.votca.org)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

#include <votca/csg/topologyreader.h>
#include <votca/csg/trajectoryreader.h>
#include <boost/program_options.hpp>
#include <boost/tokenizer.hpp>
#include <votca/csg/version.h>
#include <iostream>
#include <fstream>


using namespace std;
namespace po = boost::program_options;
using namespace votca::csg;
using namespace votca::tools;

/**
 *  *** Analyze particle distribution as a function of a coordinate ***
 *
 *  This program reads a topology and (set of) trajectory(ies). For every
 *  binned value of a chose coordinate, it outputs the time-averaged number of
 *  particles, listed by particle types.
 */
void help_text(void)
{
    votca::csg::HelpTextHeader("csg_part_dist");
    cout << "This program reads a topology and (set of) trajectory(ies). For every\n"
	"binned value of a chosen coordinate, it outputs the time-averaged number of\n"
	"particles, listed by particle types.\n\n";
}

void check_option(po::options_description &desc, po::variables_map &vm, const string &option)
{
    if(!vm.count(option)) {
        cout << "csg_part_dist \n\n";
        cout << desc << endl << "parameter " << option << " is not specified\n";
        exit(1);
    }
}

int main(int argc, char** argv)
{
    string top_file, trj_file, ptypes_file, out_file, grid, 
	comment, string_tmp, coordinate="z";
    double min, max, step, coord, com(0.);
    vector<int> ptypes;
    ifstream fl_ptypes;
    ofstream fl_out;
    Topology top;
    TopologyReader *reader;
    TrajectoryReader *trajreader;
    int part_type, n_bins, first_frame(0), last_frame(-1), 
	flag_found(0), **p_occ = NULL, n_part(0), frame_id(0),
	analyzed_frames(0);
    bool moreframes(1), not_the_last(1);

    MoleculeContainer::iterator mol;    
    // Load topology+trajectory formats
    TopologyReader::RegisterPlugins();
    TrajectoryReader::RegisterPlugins();

    // read program options
    namespace po = boost::program_options;

    // Declare the supported options.
    po::options_description desc("Allowed options");
    
    // let cg_engine add some program options
    desc.add_options()
	("top", po::value<string>(&top_file), "topology file")
	("trj", po::value<string>(&trj_file), "trajectory file")
	("grid", po::value<string>(&grid), "output grid spacing (min:step:max)")
	("out", po::value<string>(&out_file), 
	 "output particle distribution table")
	("ptypes", po::value<string>(&ptypes_file),
	 "particle types to include in the analysis\n"
	 " arg: file - particle types separated by space"
	 "\n default: all particle types")
	("first_frame", po::value<int>(&first_frame), "first frame considered for analysis")
	("last_frame", po::value<int>(&last_frame), "last frame considered for analysis")
	("coord", po::value<string>(&coordinate), "coordinate analyzed ('x', 'y', or 'z' (default))")
	("shift_com", "shift center of mass to zero")
	("comment", po::value<string>(&comment), "store a comment in the output table")
	("help", "produce this help message");
    
    // now read in the command line
    po::variables_map vm;
    try {
	po::store(po::parse_command_line(argc, argv, desc), vm);
	po::notify(vm);
    }
    catch(po::error& err) {
	cout << "error parsing command line: " << err.what() << endl;
	return -1;
    }

    // does the user want help?
    if (vm.count("help")) {
        help_text();
        cout << desc << endl;
        return 0;
    }

    check_option(desc, vm, "top");
    check_option(desc, vm, "trj");
    check_option(desc, vm, "out");
    check_option(desc, vm, "grid");

    if (coordinate.compare("x") != 0 && coordinate.compare("y") != 0 && coordinate.compare("z") != 0) {
	cout << "Bad format for coordinate: " << coordinate << endl;
	return 1;
    }

    // Parse grid
    Tokenizer tok(grid, ":");
    vector<string> toks;
    tok.ToVector(toks);
    if(toks.size()!=3) {
	cout << "Wrong range format, use min:step:max\n";
	return 1;
    }
    min = stod(toks[0]);
    step = stod(toks[1]);
    max = stod(toks[2]);
    // Calculate number of bins
    n_bins = (int)((max-min)/(1.*step)+1);

    try {
	// Load topology
        reader = TopReaderFactory().Create(vm["top"].as<string>());
        if(reader == NULL) 
{'fraction_non_alphanumeric': 0.14759995888580532, 'fraction_numerical': 0.007194984068249563, 'mean_word_length': 3.865, 'pattern_counts': {'":': 2, '<': 109, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1643247', 'n_tokens_mistral': 3188, 'n_tokens_neox': 3100, 'n_words': 925}