File: RDFParameter.C

package info (click to toggle)
ball 1.5.0%2Bgit20180813.37fc53c-11.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 239,928 kB
  • sloc: cpp: 326,149; ansic: 4,208; python: 2,303; yacc: 1,778; lex: 1,099; xml: 958; sh: 322; javascript: 164; makefile: 88
file content (230 lines) | stat: -rw-r--r-- 5,059 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
// -*- Mode: C++; tab-width: 2; -*-
// vi: set ts=2:
//

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

using namespace std;

namespace BALL
{

	RDFParameter::RDFParameter() 
		:	ParameterSection(),
			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() 
	{
		clear();
		valid_ = false;
	}


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

		return *this;
	}


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


	bool RDFParameter::hasRDF(Atom::Type solvent_atom_type,
			Atom::Type solute_atom_type) const 
	{
		if (rdf_indices_.has(solvent_atom_type))
		{
			return rdf_indices_[solvent_atom_type].has(solute_atom_type);
		}
		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;
		}

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

		clear();

		ParameterSection::extractSection(parameters, section_name);

		Size index_name = getColumnIndex("name");
		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)) 
			{
				type_name_i = key.before(" ", 0);
				type_name_j = key.after(" ", 0); 
				/*
				Log.info() << "About to read RDF for combination " << type_name_i 
					<< " " << type_name_j << endl;
				*/
				if ((atom_types.hasType(type_name_i)) && 
						(atom_types.hasType(type_name_j)))
				{
					type_i = atom_types.getType(type_name_i);
					type_j = atom_types.getType(type_name_j);
					String name_ij = getValue(i, index_name);

					HashMap<Atom::Type, HashMap<Atom::Type, Position> >::Iterator it;

					RDFSection rdf_section;

					if (rdf_section.extractSection(parameters, name_ij))
					{
						rdf_list_.push_back(rdf_section.getRDF());
						Position index = (Position)rdf_list_.size() - 1;

						if (rdf_indices_.has(type_i))
						{
							it = rdf_indices_.find(type_i);
							if (it->second.has(type_j))
							{
								Log.error() << "RDFParameter::extractSection(): "
														<< "Trying to overwrite existing definition." << endl;
								return false;
							}
							else
							{
								// Hier wird der Typ klar.
								it->second.insert(std::pair<Atom::Type, Position>(type_j, index));
							}
						}
						else
						{
							HashMap<Atom::Type, Position> tmp;
							tmp[type_j] = index;
							rdf_indices_.insert(std::pair<Atom::Type,
							HashMap<Atom::Type, Position> >(type_i, tmp));
						}
					}
					else
					{
						Log.error() << "RDFParameter::extractSection(): "
												<< "Cannot read RDF section" << endl;
						return false;
					}
				}
				else
				{
					Log.error() << "RDFParameter::extractSection(): "
											<< "cannot assign atom types."<< endl;
					return false;
				}
			}
		}
		return true;
	}

}