<commit_before>// $Id: templates.C,v 1.5 2000/02/10 15:16:57 oliver Exp $
//

#include <BALL/MOLMEC/PARAMETER/templates.h>
#include <BALL/KERNEL/residue.h>

using namespace std;

namespace BALL 
{

	FFPSTemplates::FFPSTemplates()
		: FFParameterSection()
	{
	}


	FFPSTemplates::FFPSTemplates(const FFPSTemplates& templates, bool /* deep */)
		: FFParameterSection(templates)
	{
		charges_ = templates.charges_;
		type_names_ = templates.type_names_;
	}


	void FFPSTemplates::destroy()
	{
		charges_.destroy();
		type_names_.destroy();

		FFParameterSection::destroy();
	}

		

	FFPSTemplates::~FFPSTemplates()
	{
		destroy();
	}

	FFPSTemplates& FFPSTemplates::operator = (const FFPSTemplates& templates)
	{
		charges_.set(templates.charges_);
		type_names_.set(templates.type_names_);

		return *this;
	}

	bool FFPSTemplates::extractSection
		(ForceFieldParameters& parameters, 
		 const String& section_name)
	{
		// clean up first
		type_names_.destroy();
		charges_.destroy();

		// extract the basis information
		if (!FFParameterSection::extractSection(parameters, section_name))
		{
			Log.level(LogStream::ERROR) << "Didn't find section for " << section_name << endl;
			return false;
		}

		// check for the correct entries:
		if (!hasVariable("q") || !hasVariable("type"))
		{
			Log.level(LogStream::ERROR) << "residue template section [" << section_name << "] requires variables q and type." << endl;
			return false;
		}

		// check for the correct unit
		if (!options.has("unit_q") || (options["unit_q"] != "e0"))
		{
			Log.level(LogStream::ERROR) << "unknown unit in section [" << section_name 
				<< "]. Please specify charges in multiples of the elementary charge (e0)" << endl;
			return false;
		}

		// iterate over all entries and store charges and types in the
		// corresponding hash maps
		StringHashMap<Index>::Iterator	it;
		for (it = section_entries_.begin(); it != section_entries_.end(); ++it)
		{
			type_names_[it->first] = getValue(it->first, "type");
			charges_[it->first] = getValue(it->first, "q").toFloat();
		}
		
		return true;
	}

	bool FFPSTemplates::has(const String& name) const 
	{
		return type_names_.has(name);
	}

	float FFPSTemplates::getCharge(const String& name) const 
	{
		if (charges_.has(name)) 
		{
			return (*charges_.find(name)).second;
		} else {
			return 0.0;
		}
	}

	String FFPSTemplates::getTypeName(const String& name) const 
	{
		if (type_names_.has(name)) 
		{
			return (*type_names_.find(name)).second;
		} else {
			return "";
		}
	}
	
	void FFPSTemplates::assign(System& system, bool overwrite_existing_type_names, bool overwrite_non_zero_charges) const
	{
		// remember the current parent to avoid
		// the recalculation of the parent`s name
		Fragment* parent = 0;
		String		parent_name(":");

		// iterate over all atoms
		AtomIterator it = system.beginAtom();
		for (; +it; ++it)
		{
			String name(it->getFullName());
			if (overwrite_non_zero_charges || (it->getCharge() == 0.0))
			{
				if (charges_.has(name))
				{
					it->setCharge(charges_[name]);
				} else {
					Log.warn() << "FFPSTemplates::assign: cannot assign charge for atom " << name << endl;
				}
			}
			if (overwrite_existing_type_names || (it->getTypeName() == BALL_ATOM_DEFAULT_TYPE_NAME))
			{
				if (type_names_.has(name))
				{
					it->setTypeName(type_names_[name]);
				} else {<commit_msg>fxied: warning due to an unused variable<commit_after>// $Id: templates.C,v 1.6 2000/02/13 16:54:47 oliver Exp $
//

#include <BALL/MOLMEC/PARAMETER/templates.h>
#include <BALL/KERNEL/residue.h>

using namespace std;

namespace BALL 
{

	FFPSTemplates::FFPSTemplates()
		: FFParameterSection()
	{
	}


	FFPSTemplates::FFPSTemplates(const FFPSTemplates& templates, bool /* deep */)
		: FFParameterSection(templates)
	{
		charges_ = templates.charges_;
		type_names_ = templates.type_names_;
	}


	void FFPSTemplates::destroy()
	{
		charges_.destroy();
		type_names_.destroy();

		FFParameterSection::destroy();
	}

		

	FFPSTemplates::~FFPSTemplates()
	{
		destroy();
	}

	FFPSTemplates& FFPSTemplates::operator = (const FFPSTemplates& templates)
	{
		charges_.set(templates.charges_);
		type_names_.set(templates.type_names_);

		return *this;
	}

	bool FFPSTemplates::extractSection
		(ForceFieldParameters& parameters, 
		 const String& section_name)
	{
		// clean up first
		type_names_.destroy();
		charges_.destroy();

		// extract the basis information
		if (!FFParameterSection::extractSection(parameters, section_name))
		{
			Log.level(LogStream::ERROR) << "Didn't find section for " << section_name << endl;
			return false;
		}

		// check for the correct entries:
		if (!hasVariable("q") || !hasVariable("type"))
		{
			Log.level(LogStream::ERROR) << "residue template section [" << section_name << "] requires variables q and type." << endl;
			return false;
		}

		// check for the correct unit
		if (!options.has("unit_q") || (options["unit_q"] != "e0"))
		{
			Log.level(LogStream::ERROR) << "unknown unit in section [" << section_name 
				<< "]. Please specify charges in multiples of the elementary charge (e0)" << endl;
			return false;
		}

		// iterate over all entries and store charges and types in the
		// corresponding hash maps
		StringHashMap<Index>::Iterator	it;
		for (it = section_entries_.begin(); it != section_entries_.end(); ++it)
		{
			type_names_[it->first] = getValue(it->first, "type");
			charges_[it->first] = getValue(it->first, "q").toFloat();
		}
		
		return true;
	}

	bool FFPSTemplates::has(const String& name) const 
	{
		return type_names_.has(name);
	}

	float FFPSTemplates::getCharge(const String& name) const 
	{
		if (charges_.has(name)) 
		{
			return (*charges_.find(name)).second;
		} else {
			return 0.0;
		}
	}

	String FFPSTemplates::getTypeName(const String& name) const 
	{
		if (type_names_.has(name)) 
		{
			return (*type_names_.find(name)).second;
		} else {
			return "";
		}
	}
	
	void FFPSTemplates::assign(System& system, bool overwrite_existing_type_names, bool overwrite_non_zero_charges) const
	{
		// remember the current parent to avoid
		// the recalculation of the parent`s name
		String		parent_name(":");

		// iterate over all atoms
		AtomIterator it = system.beginAtom();
		for (; +it; ++it)
		{
			String name(it->getFullName());
			if (overwrite_non_zero_charges || (it->getCharge() == 0.0))
			{
				if (charges_.has(name))
				{
					it->setCharge(charges_[name]);
				} else {
					Log.warn() << "FFPSTemplates::assign: cannot assign charge for atom " << name << endl;
				}
			}
			if (overwrite_existing_type_names || (it->getTypeName() == BALL_ATOM_DEFAULT_TYPE_NAME))
			{
				if (type_names_.has(name))
				{
					it->setTypeName(type_names_[name]);
				} else {
{'fraction_non_alphanumeric': 0.1445819049038605, 'fraction_numerical': 0.006707407959457445, 'mean_word_length': 3.837779379956741, 'pattern_counts': {'":': 2, '<': 65, '<?xml version=': 0, '>': 27, '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': '7468811', 'n_tokens_mistral': 2615, 'n_tokens_neox': 2296, 'n_words': 493}