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 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451
|
// -*- Mode: C++; tab-width: 2; -*-
// vi: set ts=2:
//
// $Id: forceField.h,v 1.33 2005/12/23 17:01:51 amoll Exp $
//
#ifndef BALL_MOLMEC_COMMON_FORCEFIELD_H
#define BALL_MOLMEC_COMMON_FORCEFIELD_H
#ifndef BALL_COMMON_H
# include <BALL/common.h>
#endif
#ifndef BALL_KERNEL_SYSTEM_H
# include <BALL/KERNEL/system.h>
#endif
#ifndef BALL_DATATYPE_OPTIONS_H
# include <BALL/DATATYPE/options.h>
#endif
#ifndef BALL_CONCEPT_TIMESTAMP_H
# include <BALL/CONCEPT/timeStamp.h>
#endif
#ifndef BALL_MOLMEC_PARAMETER_FORCEFIELDPARAMETERS_H
# include <BALL/MOLMEC/PARAMETER/forceFieldParameters.h>
#endif
#ifndef BALL_MOLMEC_PARAMETER_ATOMTYPES_H
# include <BALL/MOLMEC/PARAMETER/atomTypes.h>
#endif
#ifndef BALL_MOLMEC_COMMON_PERIODIC_BOUNDARY_H
# include <BALL/MOLMEC/COMMON/periodicBoundary.h>
#endif
#ifndef BALL_MOLMEC_COMMON_ATOMVECTOR_H
# include <BALL/MOLMEC/COMMON/atomVector.h>
#endif
#include <vector>
namespace BALL
{
class ForceFieldComponent;
/** Force field class.
This class is used to represent a general force field.
Each force field by itself is composed by several
different force field components which are represented
by \link ForceFieldComponent ForceFieldComponent \endlink objects. \par
Each ForceField object provides a list of components
which may be manipulated by the user to generate the
force field he needs. \par
ForceField only represents a baseclass to the specific force field
implementations (e.g. \link AMBER AMBER \endlink ) and implements the common interface
and the neccessary mechanisms to administer the force field components. \par
A typical force field contains a small number of components (e.g. bond stretch,
bend, torsion and non-bonding interactions).
A specialized forcefield has to implement each of these components (by deriving them
from \link ForceFieldComponent ForceFieldComponent \endlink and must be derived from ForceField.
Basically only the default constructor for the new forcefield has to
be modified to create an instance of each of the components and
register them by calling \link insertComponent insertComponent \endlink . But in order to implement
the setup methods of the force field components efficiently,
jobs like assigning atom types, reading parameter files and the such should be
provided for all force field components by the corrseponding ForceField
object. This should be implemented in the force field-specific \link specificSetup specificSetup \endlink
method. \par
For an efficient and easy to use implementation of a forcefield
parameter file, please refer to \link ForceFieldParameters ForceFieldParameters \endlink and its
related objects. \par
Each force field provides as well energy and its derivatives, the force
on each atom. A calculation of the energy is done by calling
\link updateEnergy updateEnergy \endlink . This method iterates over the list of force field
components and invokes the updateEnergy method of each of these components.
The total energy may then be retrieved by calling \link getEnergy getEnergy \endlink . \par
Analogously, a force calculation is performed by invoking \link updateForces updateForces \endlink .
\link getForces getForces \endlink returns a pointer to an array containing the forces
for each atom. \par
\ingroup MolmecCommon
*/
class BALL_EXPORT ForceField
{
public:
friend class ForceFieldComponent;
/** @name Type Definitions
*/
//@{
/** Atom pair vector.
This type is used to represent "pair lists". In fact, it is
a <tt>vector</tt> of <tt>pair</tt>s of atom pointers.
*/
typedef std::vector<std::pair<Atom*, Atom*> > PairVector;
//@}
/** @name Constructors and Destructors
*/
//@{
BALL_CREATE(ForceField)
/** Default constructor.
A default-constructed force field is not valid!
It becomes valid after a successful call to setup.
*/
ForceField();
/** Constructor.
The successful setup of the force field can be verified
by the \link isValid isValid \endlink method.
*/
ForceField(System& system);
/** Constructor.
The successful setup of the force field can be verified
by the \link isValid isValid \endlink method.
*/
ForceField(System& system, const Options& options);
/** Copy constructor
*/
ForceField(const ForceField& force_field);
/** Destructor.
*/
virtual ~ForceField();
/** Clear method.
*/
virtual void clear()
;
//@}
/** @name Assignments
*/
//@{
/** Assignment operator
*/
ForceField& operator = (const ForceField& force_field);
//@}
/** @name Debugging and Diagnostics
*/
//@{
/** Check the force field's validity.
A force field is valid if it is bound to a system
and \link setup setup \endlink was successful.
*/
bool isValid() const
;
//@}
/** @name Setup methods
*/
//@{
/** Sets up the force field and its components.
*/
bool setup(System& system);
/** Sets up the force field and its components.
*/
bool setup(System& system, const Options& options);
/** Force field specific setup.
This method is called by setup.
@throws BALL::Exception::TooManyErrors
*/
virtual bool specificSetup();
/** Set the number of atoms, for which the setup of the forcefield can
fail, until the setup() methods aborts and return false.
By default, there is no limit set.
*/
void setMaximumNumberOfErrors(Size nr);
/** Get the number of atoms, for which the setup of the forcefield can
fail, until the setup() methods aborts and return false.
*/
Size getMaximumNumberOfErrors() const;
/// Get the atoms, for which the force field setup failed.
HashSet<const Atom*>& getUnassignedAtoms();
//@}
/** @name Accessors
*/
//@{
/** Sets the force field name.
*/
void setName(const String& name);
/** Returns the force field name
*/
String getName() const;
/** Returns the number of atoms stored in the force field
*/
Size getNumberOfAtoms() const;
/** Returns the number of non-fixed atoms stored in the force field.
If the option <tt>SELECTION_FIXED</tt> is set to <b>true</b> or
<tt>SELECTION_MOVABLE</tt> is set to <b>true</b> the atom array
is split. The first section (indices 0 to \link getNumberOfMovableAtoms getNumberOfMovableAtoms \endlink )
contains the atoms that are to be moved, the rest of the array contains
the fixed atoms.
*/
Size getNumberOfMovableAtoms() const;
/** Returns a reference to the atom vector
*/
BALL_INLINE
const AtomVector& getAtoms() const ;
/** Returns a pointer to the system
*/
BALL_INLINE
System* getSystem() ;
/** Returns a const pointer to the system
*/
BALL_INLINE
const System* getSystem() const ;
/** Return the status of the selection mechanism
*/
BALL_INLINE
bool getUseSelection() const ;
/** Set the status of the selection mechanism
*/
BALL_INLINE
void disableSelection() ;
/** Set the status of the selection mechanism
*/
BALL_INLINE
void enableSelection() ;
/** Return the status of the selection mechanism */
BALL_INLINE
bool isSelectionEnabled() const ;
/** Returns a pointer to the parameter file
*/
ForceFieldParameters& getParameters();
/** Returns the number of components registered by the force field.
*/
Size countComponents() const;
/** Return the point of time of the last call to update.
ForceField contains a time stamp which is used to determine
whether the selection or even the topology of the system
has changed. Every time update is called, the
\link update_time_stamp_ update_time_stamp_ \endlink is updated. Similarly, all setup methods
update the \link setup_time_stamp_ setup_time_stamp_ \endlink
*/
const TimeStamp& getUpdateTime() const
;
/** Return the point of time of the last call to setup.
ForceField contains a time stamp which is used to determine
whether the selection or even the topology of the system
has changed. Every time update is called, the
\link update_time_stamp_ update_time_stamp_ \endlink is updated. Similarly, all setup methods
update the \link setup_time_stamp_ setup_time_stamp_ \endlink
*/
const TimeStamp& getSetupTime() const
;
/** Insert a new component into the force field's component list.
Responsability for the destruction of the component is passed on to
the ForceField instance.
*/
void insertComponent(ForceFieldComponent* force_field_component);
/** Remove a component from the force field's component list.
The ForceFieldComponent will be destructed and removed from the component list.
*/
void removeComponent(const ForceFieldComponent* force_field_component);
/** Remove a component from the force field's component list.
*/
void removeComponent(const String& name);
/** Return a pointer to the specified force field component.
If the specified index does not exist, 0 is returned.
The given index should be smaller than the value returned by
countComponents. The first component in the list has the index zero.
*/
ForceFieldComponent* getComponent(const Size index) const;
/** Return a pointer to the specified force field component.
If a component with the specified name does not exist, 0 is returned.
*/
ForceFieldComponent* getComponent(const String& name) const;
/** Return the sum of energies of all registered force field components.
No calculation will be performed. This method simply returns the
last value for the total energy calculated by updateEnergy.
@return double - energy in kJ/mol
*/
double getEnergy() const;
/** Calculate the sum of energies of all force field components and returns its value.
*/
double updateEnergy();
/** Calculate the forces caused by each component and updates the current forces.
*/
void updateForces();
/** Calculates the RMS of the current gradient
*/
double getRMSGradient() const;
/** Return the update frequency for pair lists etc.
This method is used by minimizers or the MD simulation to determine the number
of iterations between two calls to \link update update \endlink .
*/
virtual Size getUpdateFrequency() const;
/** Update internal data structures.
The force field may use this method to update internal data structures
(e.g. pair lists) periodically. The MD simulation class as well as the minimizer classes
use \link getUpdateFrequency getUpdateFrequency \endlink to determine the number of iterations
between two calls to update. \par
The default implementation calls \link ForceFieldComponent::update ForceFieldComponent::update \endlink for
each component in the force field.
@throws BALL::Exception::TooManyErrors
*/
virtual void update();
/** Get the current results in String form
(Generic function to be overloaded in derived classes.)
*/
virtual String getResults() const
{ return "undefined";}
//_ Report an error and increase the error counter
std::ostream& error();
//@}
/** @name Public Attributes
*/
//@{
/** Force field options
*/
Options options;
/** Periodic boundary
*/
PeriodicBoundary periodic_boundary;
//@}
protected:
/*_ Collect all atoms into the atoms_ vector.
*/
void collectAtoms_(const System& system);
/*_ Sort the atom vector wrt selection.
*/
void sortSelectedAtomVector_();
/**
* Check whether the force field needs to be updated and perform the necessary steps
*/
virtual void performRequiredUpdates_();
/*_ @name Protected Attributes
*/
//_@{
/*_ The system the force field is bound to
*/
System* system_;
/*_ The atoms in the simulated system
*/
AtomVector atoms_;
/*_ An object containing the force field parameters read from a file
*/
ForceFieldParameters parameters_;
/*_ The boolean variable indicates if the setup of the force field was successful
*/
bool valid_;
/*_ The force field name
*/
String name_;
/*_ The total energy
*/
double energy_;
/*_ The components of the force field
*/
vector<ForceFieldComponent*> components_;
/*_ The number of movable atoms in the force field
*/
Size number_of_movable_atoms_;
/*_ Do we have to check whether atoms are selected?
*/
bool use_selection_;
/*_ This flag can temporarily disable the selection.
*/
bool selection_enabled_;
/*_ The time of the last call to update.
*/
TimeStamp update_time_stamp_;
/*_ The time of the last call to setup.
*/
TimeStamp setup_time_stamp_;
//_ Atoms, for which the setup of the force field fails
HashSet<const Atom*> unassigned_atoms_;
//_ max number of unassigned atoms
Size max_number_of_errors_;
Size number_of_errors_;
//_@}
};
# ifndef BALL_NO_INLINE_FUNCTIONS
# include <BALL/MOLMEC/COMMON/forceField.iC>
# endif
} // namespace BALL
#endif // BALL_MOLMEC_COMMON_FORCEFIELD_H
|