<commit_before>// $Id: forceField.C,v 1.11 2000/01/10 15:51:12 oliver Exp $

#include <BALL/MOLMEC/COMMON/forceField.h>

#include <BALL/MOLMEC/COMMON/forceFieldComponent.h>
#include <BALL/MOLMEC/COMMON/periodicBoundary.h>
#include <BALL/KERNEL/bond.h>
#include <BALL/KERNEL/forEach.h>

using namespace std;

namespace BALL 
{

	// default constructor
	ForceField::ForceField()
		:	periodic_boundary(*this),
			system_( 0 ),
			valid_(true),
			name_("Force Field"),
			number_of_movable_atoms_(0),
			use_selection_(false)
	{
	}


	// copy constructor 
	ForceField::ForceField(const ForceField& force_field, bool /* deep */)
	{
		// Copy the attributes
		name_   = force_field.name_;
		energy_ = force_field.energy_;
		options = force_field.options;
		system_ = force_field.system_;
		atoms_  = force_field.atoms_;
		number_of_movable_atoms_ = force_field.number_of_movable_atoms_;
		parameters_ = force_field.parameters_;
		periodic_boundary = force_field.periodic_boundary;
		use_selection_ = force_field.use_selection_;
		valid_ = force_field.valid_;

		
		// Copy the component vector
		for (Size i = 0; i < force_field.components_.size(); i++) 
		{
			components_.push_back((ForceFieldComponent*)force_field.components_[i]->create());
		}
	}

	// assignment operator
	ForceField& ForceField::operator = (const ForceField& force_field)
	{

		// guard against self assignment
		if (&force_field != this) 
		{ 	
			atoms_.clear();
			atoms_  = force_field.atoms_;
			number_of_movable_atoms_ = force_field.number_of_movable_atoms_;

			name_   = force_field.name_;
			energy_ = force_field.energy_;
			options = force_field.options;
			system_ = force_field.system_;
			parameters_ = force_field.parameters_;
			periodic_boundary = force_field.periodic_boundary;
			use_selection_ = force_field.use_selection_;
			valid_ = force_field.valid_;

			Size i;
			for (i = 0; i < components_.size(); i++) 
			{
				delete components_[i];
			}
			components_.clear();

			for (i = 0; i < force_field.components_.size(); i++) 
			{
				components_.push_back((ForceFieldComponent*)force_field.components_[i]->create());
			}
	
		}
		return (*this);
	}

	// Constructor initialized with a system
	ForceField::ForceField(System& system)
		:	periodic_boundary(*this)
	{
		bool result = setup(system);

		if (!result) 
		{
			Log.level(LogStream::ERROR) << "Force Field setup failed! " << endl;
			valid_ = false;
		}
	}
	
	// Constructor intialized with a system and a set of options
	ForceField::ForceField(System& system, const Options& new_options)
		:	periodic_boundary(*this)
	{
		bool result = setup(system, new_options);

		if (!result) 
		{
			Log.level(LogStream::ERROR) << "Force Field setup failed! " << endl;
			valid_ = false;
		}
	}
	

	// destructor
	ForceField::~ForceField()
	{
		// clear pointers 

		system_ = 0;

		// remove all force field components from the list after
		// calling their destructors
		vector<ForceFieldComponent*>::iterator  it;
		for (it = components_.begin(); it != components_.end(); ++it)
		{
			delete (*it);
		}
		components_.clear();
	}
		
	// Is the force field valid
	bool  ForceField::isValid()
	{
		return valid_;
	}

	// setup methods
	bool  ForceField::setup(System& system)
	{
		bool  success = true;

		// store the specified system
		system_ = &system;

		// Setup periodic boundary
		if(!periodic_boundary.setup()) 
		{
			Log.error() << "setup of periodic boundary failed" << endl;
			return false;
		}
			

		// clear existing atoms entries
		atoms_.clear();


		// check for selected atoms
		// if any of the atoms is selected, the atoms_ array holds
		// the selected atoms first (0 < i < number_of_movable_atoms_) 
		use_selection_ = system.containsSelection();
		number_of_movable_atoms_ = 0;
		AtomIterator atom_it = system.beginAtom();
		if (use_selection_ == true)
		{
			for (; +atom_it; ++atom_it)
			{
				if (atom_it->isSelected() == true)
				{
					atoms_.push_back(&(*atom_it));
				}
			}
		} else {
			for (; +atom_it; ++atom_it)
			{
				atoms_.push_back(&(*atom_it));
			}
		}
		number_of_movable_atoms_ = atoms_.size();

		// force field specific parts
		success = specificSetup();
		if (!success) 
		{
			Log.error() << "Force Field specificSetup failed!" << endl;
			return false;
		}

		// call the setup method for each force field component
		vector<ForceFieldComponent*>::iterator  it;
		for (it = components_.begin(); (it != components_.end()) && success; ++it)
		{
			success = (*(*it)).setup();
			if (!success) 
			{
				Log.error() << "Force Field Component setup of " 
										<< (*it)->name_ <<  " failed!" << endl;
			}
		}

		return success;
	}

	// Setup with a system and a set of options
	bool ForceField::setup(System& system, const Options& new_options)
	{
		options = new_options;
		return setup(system);
	}


	// Returns the name of the force field
	String ForceField::getName() const
	{
		return name_;
	}

	// Sets the name of force field to name
	void ForceField::setName(const String& name)
	{
		name_ = name;
	}<commit_msg>fixed: generation of molecule vector<commit_after>// $Id: forceField.C,v 1.12 2000/02/02 09:52:09 len Exp $

#include <BALL/MOLMEC/COMMON/forceField.h>

#include <BALL/MOLMEC/COMMON/forceFieldComponent.h>
#include <BALL/MOLMEC/COMMON/periodicBoundary.h>
#include <BALL/KERNEL/bond.h>
#include <BALL/KERNEL/forEach.h>

using namespace std;

namespace BALL 
{

	// default constructor
	ForceField::ForceField()
		:	periodic_boundary(*this),
			system_( 0 ),
			valid_(true),
			name_("Force Field"),
			number_of_movable_atoms_(0),
			use_selection_(false)
	{
	}


	// copy constructor 
	ForceField::ForceField(const ForceField& force_field, bool /* deep */)
	{
		// Copy the attributes
		name_   = force_field.name_;
		energy_ = force_field.energy_;
		options = force_field.options;
		system_ = force_field.system_;
		atoms_  = force_field.atoms_;
		number_of_movable_atoms_ = force_field.number_of_movable_atoms_;
		parameters_ = force_field.parameters_;
		periodic_boundary = force_field.periodic_boundary;
		use_selection_ = force_field.use_selection_;
		valid_ = force_field.valid_;

		
		// Copy the component vector
		for (Size i = 0; i < force_field.components_.size(); i++) 
		{
			components_.push_back((ForceFieldComponent*)force_field.components_[i]->create());
		}
	}

	// assignment operator
	ForceField& ForceField::operator = (const ForceField& force_field)
	{

		// guard against self assignment
		if (&force_field != this) 
		{ 	
			atoms_.clear();
			atoms_  = force_field.atoms_;
			number_of_movable_atoms_ = force_field.number_of_movable_atoms_;

			name_   = force_field.name_;
			energy_ = force_field.energy_;
			options = force_field.options;
			system_ = force_field.system_;
			parameters_ = force_field.parameters_;
			periodic_boundary = force_field.periodic_boundary;
			use_selection_ = force_field.use_selection_;
			valid_ = force_field.valid_;

			Size i;
			for (i = 0; i < components_.size(); i++) 
			{
				delete components_[i];
			}
			components_.clear();

			for (i = 0; i < force_field.components_.size(); i++) 
			{
				components_.push_back((ForceFieldComponent*)force_field.components_[i]->create());
			}
	
		}
		return (*this);
	}

	// Constructor initialized with a system
	ForceField::ForceField(System& system)
		:	periodic_boundary(*this)
	{
		bool result = setup(system);

		if (!result) 
		{
			Log.level(LogStream::ERROR) << "Force Field setup failed! " << endl;
			valid_ = false;
		}
	}
	
	// Constructor intialized with a system and a set of options
	ForceField::ForceField(System& system, const Options& new_options)
		:	periodic_boundary(*this)
	{
		bool result = setup(system, new_options);

		if (!result) 
		{
			Log.level(LogStream::ERROR) << "Force Field setup failed! " << endl;
			valid_ = false;
		}
	}
	

	// destructor
	ForceField::~ForceField()
	{
		// clear pointers 

		system_ = 0;

		// remove all force field components from the list after
		// calling their destructors
		vector<ForceFieldComponent*>::iterator  it;
		for (it = components_.begin(); it != components_.end(); ++it)
		{
			delete (*it);
		}
		components_.clear();
	}
		
	// Is the force field valid
	bool  ForceField::isValid()
	{
		return valid_;
	}

	// setup methods
	bool  ForceField::setup(System& system)
	{
		bool  success = true;

		// store the specified system
		system_ = &system;

		// Setup periodic boundary
		if(!periodic_boundary.setup()) 
		{
			Log.error() << "setup of periodic boundary failed" << endl;
			return false;
		}
			

		// clear existing atoms entries
		atoms_.clear();


		// check for selected atoms
		// if any of the atoms is selected, the atoms_ array holds
		// the selected atoms first (0 < i < number_of_movable_atoms_) 
		use_selection_ = system.containsSelection();
		number_of_movable_atoms_ = 0;
		AtomIterator atom_it = system.beginAtom();
		if (use_selection_ == true)
		{
			for (; +atom_it; ++atom_it)
			{
				if (atom_it->isSelected() == true)
				{
					atoms_.push_back(&(*atom_it));
				}
			}
		} else {
			for (; +atom_it; ++atom_it)
			{
				atoms_.push_back(&(*atom_it));
			}
		}


		number_of_movable_atoms_ = atoms_.size();

		// generate the vector of molecules if periodic boundary is enabled
		if (periodic_boundary.isEnabled())
		{
			periodic_boundary.generateMoleculesVector();
		}

		// force field specific parts
		success = specificSetup();
		if (!success) 
		{
			Log.error() << "Force Field specificSetup failed!" << endl;
			return false;
		}

		// call the setup method for each force field component
		vector<ForceFieldComponent*>::iterator  it;
		for (it = components_.begin(); (it != components_.end()) && success; ++it)
		{
			success = (*(*it)).setup();
			if (!success) 
			{
				Log.error() << "Force Field Component setup of " 
					<< (*it)->name_ <<  " failed!" << endl;
			}
		}

		return success;
	}

	// Setup with a system and a set of options
	bool ForceField::setup(System& system, const Options& new_options)
	{
		options = new_options;
		return setup(system);
	}


	// Returns the name of the force field
	String ForceField::getName() const
	{
		return name_;
	}

	// Sets the name of force field to name
	void ForceField::setName(const String& name)
	{
		name_ = name;
	}
{'fraction_non_alphanumeric': 0.12777614714802857, 'fraction_numerical': 0.004891889247627434, 'mean_word_length': 3.4794040315512706, 'pattern_counts': {'":': 0, '<': 75, '<?xml version=': 0, '>': 25, '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': '4020285', 'n_tokens_mistral': 3943, 'n_tokens_neox': 3369, 'n_words': 801}