Currently, we have routines to evaluate the force according to the Lennard-Jones potential. What if we wanted put a charge on the atoms? Or, we might want to define some periodic bounds, or cells, such that very large structures can be simulated using minimal calculations. In either of these cases, the functions would need to be rewritten in each subject, and we'd then have multiple sets of subjects, some for the Lennard-Jones potential, some for a charged system, and some for a system subject to periodic bounds.
The solution to this problem is to use the template pattern. We implement a
template class, MDTemplate
. This class has several deferred methods,
including evalForce
, evalPotential
and updateVelocity
. For each
type of function that we want to use to calculate the potential, we implement a
class that inherits from the MDTemplate
class. Currently, we only have
one, MDUtils
, but more classes could easily be written and substituted.
To use our new implementation, we add a method, setUtils
, to the Subject
class. The subject class can then transparently use whatever utilities are
given to it. It can be simulating or minimising the atoms subject to their
charges, or the weak atomic forces between them, without having any knowledge
of these formulae.