<commit_before>// $Id: RDFParameter.C,v 1.4 2000/09/25 11:19:21 anker Exp $

#include <BALL/STRUCTURE/RDFParameter.h>
#include <BALL/STRUCTURE/RDFSection.h>
#include <BALL/MOLMEC/PARAMETER/forceFieldParameters.h>

using namespace std;

namespace BALL
{

	RDFParameter::RDFParameter()
		:	rdf_list_(),
			rdf_indices_()
	{
	}


	RDFParameter::RDFParameter(const RDFParameter& rdf_parameter)
		:	ParameterSection(rdf_parameter),
			rdf_list_(rdf_parameter.rdf_list_),
			rdf_indices_(rdf_parameter.rdf_indices_)
	{
	}


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


	void RDFParameter::destroy()
	{
		clear();
	}


	void RDFParameter::clear()
	{
		rdf_list_.clear();
		rdf_indices_.clear();
	}


	bool RDFParameter::hasRDF(Atom::Type solvent_atom_type,
			Atom::Type solute_atom_type) const
	{
		if (rdf_indices_.has(solvent_atom_type))
		{
			if (rdf_indices_[solvent_atom_type].has(solute_atom_type))
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		else 
		{
			return false;
		}
	}


	bool RDFParameter::hasParameters(Atom::Type solvent_atom_type,
			Atom::Type solute_atom_type) const
	{
		return hasRDF(solvent_atom_type, solute_atom_type);
	}
	

	Position RDFParameter::getIndex(Atom::Type type_i, Atom::Type type_j) const
	{
		if (hasRDF(type_i, type_j))
		{
			return rdf_indices_[type_i][type_j];
		}
		else 
		{
			return INVALID_POSITION;
		}
	}


	const RadialDistributionFunction& RDFParameter::getRDF(Position index) const
	{
		if (index < rdf_list_.size())
		{
			return rdf_list_[index];
		}
		else
		{
			Log.error() << "RDFParameter::getRDF(): "
				<< "Index out of range." <<endl;
			return RTTI::getDefault<RadialDistributionFunction>();
		}
	}


	const RadialDistributionFunction& RDFParameter::getRDF(Atom::Type type_i,
			Atom::Type type_j) const
	{
		if (hasRDF(type_i, type_j))
		{
			Position index = getIndex(type_i, type_j);
			if (index != INVALID_POSITION)
			{
				return getRDF(index);
			}
			else
			{
				Log.error() << "RDFParameter::getRDF(): "
					<< "RDf for type combination  (" << type_i << "," << type_j 
					<< ") could not be found." << endl 
					<< "Something went terribly wrong." << endl;
				return RTTI::getDefault<RadialDistributionFunction>();
			}
		}
		else
		{
			Log.error() << "RDFParameter::getRDF(): "
				<< "no RDf defined for type combination  (" << type_i << "," 
				<< type_j << ")" << endl;
			return RTTI::getDefault<RadialDistributionFunction>();
		}
	}


	bool RDFParameter::extractSection(ForceFieldParameters& parameters,
			const String& section_name)
	{

		if (!parameters.isValid())
		{
			return false;
		}

		ParameterSection::extractSection(parameters, section_name);

		Size index_name = getColumnIndex("RDF");
		String key;
		String type_name_i;
		String type_name_j;
		Atom::Type type_i;
		Atom::Type type_j;
		Size number_of_keys = getNumberOfKeys();
		AtomTypes& atom_types = parameters.getAtomTypes();         

		for (Size i = 0; i < number_of_keys; ++i)
		{
			key = getKey(i);
			if ((key.size() > 0) && (key.find_first_of(" ", 0) > 0)) <commit_msg>changed: canonified interface fixed: added a missing clear() in extractSection<commit_after>// $Id: RDFParameter.C,v 1.5 2000/10/17 17:19:50 anker Exp $

#include <BALL/STRUCTURE/RDFParameter.h>
#include <BALL/STRUCTURE/RDFSection.h>
#include <BALL/MOLMEC/PARAMETER/forceFieldParameters.h>

using namespace std;

namespace BALL
{

	RDFParameter::RDFParameter() throw()
		:	ParameterSection(),
			rdf_list_(),
			rdf_indices_()
	{
	}


	RDFParameter::RDFParameter(const RDFParameter& rdf_parameter) throw()
		:	ParameterSection(rdf_parameter),
			rdf_list_(rdf_parameter.rdf_list_),
			rdf_indices_(rdf_parameter.rdf_indices_)
	{
	}


	RDFParameter::~RDFParameter() throw()
	{
		clear();

		valid_ = false;
	}


	const RDFParameter& RDFParameter::operator = (const RDFParameter& parameter) 
		throw()
	{
		ParameterSection::operator = (parameter);
		rdf_list_ = parameter.rdf_list_;
		rdf_indices_ = parameter.rdf_indices_;

		return *this;
	}


	void RDFParameter::clear() throw()
	{
		ParameterSection::clear();
		rdf_list_.clear();
		rdf_indices_.clear();
		
		valid_ = false;
	}


	bool RDFParameter::hasRDF(Atom::Type solvent_atom_type,
			Atom::Type solute_atom_type) const throw()
	{
		if (rdf_indices_.has(solvent_atom_type))
		{
			if (rdf_indices_[solvent_atom_type].has(solute_atom_type))
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		else 
		{
			return false;
		}
	}


	bool RDFParameter::hasParameters(Atom::Type solvent_atom_type,
			Atom::Type solute_atom_type) const throw()
	{
		return hasRDF(solvent_atom_type, solute_atom_type);
	}
	

	Position RDFParameter::getIndex(Atom::Type type_i, Atom::Type type_j)
		const throw()
	{
		if (hasRDF(type_i, type_j))
		{
			return rdf_indices_[type_i][type_j];
		}
		else 
		{
			return INVALID_POSITION;
		}
	}


	const RadialDistributionFunction& RDFParameter::getRDF(Position index)
		const throw()
	{
		if (index < rdf_list_.size())
		{
			return rdf_list_[index];
		}
		else
		{
			Log.error() << "RDFParameter::getRDF(): "
				<< "Index out of range." <<endl;
			return RTTI::getDefault<RadialDistributionFunction>();
		}
	}


	const RadialDistributionFunction& RDFParameter::getRDF(Atom::Type type_i,
			Atom::Type type_j) const throw()
	{
		if (hasRDF(type_i, type_j))
		{
			Position index = getIndex(type_i, type_j);
			if (index != INVALID_POSITION)
			{
				return getRDF(index);
			}
			else
			{
				Log.error() << "RDFParameter::getRDF(): "
					<< "RDf for type combination  (" << type_i << "," << type_j 
					<< ") could not be found." << endl 
					<< "Something went terribly wrong." << endl;
				return RTTI::getDefault<RadialDistributionFunction>();
			}
		}
		else
		{
			Log.error() << "RDFParameter::getRDF(): "
				<< "no RDf defined for type combination  (" << type_i << "," 
				<< type_j << ")" << endl;
			return RTTI::getDefault<RadialDistributionFunction>();
		}
	}


	bool RDFParameter::extractSection(ForceFieldParameters& parameters,
			const String& section_name) throw()
	{

		if (!parameters.isValid())
		{
			return false;
		}

		// first clear the instance, just in case there is something left from
		// before

		clear();

		ParameterSection::extractSection(parameters, section_name);

		Size index_name = getColumnIndex("RDF");
		String key;
		String type_name_i;
		String type_name_j;
		Atom::Type type_i;
		Atom::Type type_j;
		Size number_of_keys = getNumberOfKeys();
		AtomTypes& atom_types = parameters.getAtomTypes();         

		for (Size i = 0; i < number_of_keys; ++i)
		{
			key = getKey(i);
			if ((key.size() > 0) && (key.find_first_of(" ", 0) > 0)) 
{'fraction_non_alphanumeric': 0.13778580024067388, 'fraction_numerical': 0.006016847172081829, 'mean_word_length': 3.8853783982365906, 'pattern_counts': {'":': 0, '<': 95, '<?xml version=': 0, '>': 19, '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': '3605318', 'n_tokens_mistral': 2834, 'n_tokens_neox': 2447, 'n_words': 447}