| 3 |
|
|
| 4 |
|
The absence of modern software development practices has been a |
| 5 |
|
bottleneck limiting progress in the Scientific Computing |
| 6 |
< |
community\cite{Wilson2006}. In the last 20 years , a large number of |
| 6 |
> |
community\cite{Wilson2006}. In the last 20 years, a large number of |
| 7 |
|
few MD packages\cite{Brooks1983, Vincent1995, Kale1999} were |
| 8 |
|
developed to solve common MD problems and perform robust simulations |
| 9 |
|
. Most of these are commercial programs that are either poorly |
| 35 |
|
|
| 36 |
|
Mainly written by C++ and Fortran90, {\sc OOPSE} uses C++ Standard |
| 37 |
|
Template Library (STL) and fortran modules as a foundation. As an |
| 38 |
< |
extensive set of the STL and Fortran90 modules, {\sc Base Classes} |
| 39 |
< |
provide generic implementations of mathematical objects (e.g., |
| 40 |
< |
matrices, vectors, polynomials, random number generators) and |
| 38 |
> |
extensive set of the STL and Fortran90 modules, the {\sc Base |
| 39 |
> |
Classes} provide generic implementations of mathematical objects |
| 40 |
> |
(e.g., matrices, vectors, polynomials, random number generators) and |
| 41 |
|
advanced data structures and algorithms(e.g., tuple, bitset, generic |
| 42 |
|
data and string manipulation). The molecular data structures for the |
| 43 |
|
representation of atoms, bonds, bends, torsions, rigid bodies and |
| 52 |
|
meta-data files, which has been implemented using the ANother Tool |
| 53 |
|
for Language Recognition(ANTLR)\cite{Parr1995, Schaps1999} syntax. |
| 54 |
|
The Molecular Mechanics module consists of energy minimization and a |
| 55 |
< |
wide varieties of integration methods(see |
| 55 |
> |
wide variety of integration methods(see |
| 56 |
|
Chap.~\ref{chapt:methodology}). The structure module contains a |
| 57 |
|
flexible and powerful selection library which syntax is elaborated |
| 58 |
|
in Sec.~\ref{appendixSection:syntax}. The top layer is made of the |
| 59 |
|
main program of the package, \texttt{oopse} and it corresponding |
| 60 |
|
parallel version \texttt{oopse\_MPI}, as well as other useful |
| 61 |
< |
utilities, such as \texttt{StatProps} (see |
| 61 |
> |
utilities, such as \texttt{StaticProps} (see |
| 62 |
|
Sec.~\ref{appendixSection:StaticProps}), \texttt{DynamicProps} (see |
| 63 |
|
Sec.~\ref{appendixSection:DynamicProps}), \texttt{Dump2XYZ} (see |
| 64 |
|
Sec.~\ref{appendixSection:Dump2XYZ}), \texttt{Hydro} (see |
| 74 |
|
\section{\label{appendixSection:desginPattern}Design Patterns} |
| 75 |
|
|
| 76 |
|
Design patterns are optimal solutions to commonly-occurring problems |
| 77 |
< |
in software design. Although originated as an architectural concept |
| 78 |
< |
for buildings and towns by Christopher Alexander |
| 79 |
< |
\cite{Alexander1987}, software patterns first became popular with |
| 80 |
< |
the wide acceptance of the book, Design Patterns: Elements of |
| 81 |
< |
Reusable Object-Oriented Software \cite{Gamma1994}. Patterns reflect |
| 82 |
< |
the experience, knowledge and insights of developers who have |
| 83 |
< |
successfully used these patterns in their own work. Patterns are |
| 84 |
< |
reusable. They provide a ready-made solution that can be adapted to |
| 85 |
< |
different problems as necessary. As one of the latest advanced |
| 86 |
< |
techniques to emerge from object-oriented community, design patterns |
| 87 |
< |
were applied in some of the modern scientific software applications, |
| 88 |
< |
such as JMol, {\sc OOPSE}\cite{Meineke2005} and |
| 89 |
< |
PROTOMOL\cite{Matthey2004} \textit{etc}. The following sections |
| 90 |
< |
enumerates some of the patterns used in {\sc OOPSE}. |
| 77 |
> |
in software design. Although they originated as an architectural |
| 78 |
> |
concept for buildings and towns by Christopher Alexander |
| 79 |
> |
\cite{Alexander1987}, design patterns first became popular in |
| 80 |
> |
software engineering with the wide acceptance of the book, Design |
| 81 |
> |
Patterns: Elements of Reusable Object-Oriented Software |
| 82 |
> |
\cite{Gamma1994}. Patterns reflect the experience, knowledge and |
| 83 |
> |
insights of developers who have successfully used these patterns in |
| 84 |
> |
their own work. Patterns are reusable. They provide a ready-made |
| 85 |
> |
solution that can be adapted to different problems as necessary. As |
| 86 |
> |
one of the latest advanced techniques to emerge from object-oriented |
| 87 |
> |
community, design patterns were applied in some of the modern |
| 88 |
> |
scientific software applications, such as JMol, {\sc |
| 89 |
> |
OOPSE}\cite{Meineke2005} and PROTOMOL\cite{Matthey2004} |
| 90 |
> |
\textit{etc}. The following sections enumerates some of the patterns |
| 91 |
> |
used in {\sc OOPSE}. |
| 92 |
|
|
| 93 |
|
\subsection{\label{appendixSection:singleton}Singletons} |
| 94 |
|
|
| 96 |
|
instantiation of a class to one object, but also provides a global |
| 97 |
|
point of access to the object. Although the singleton pattern can be |
| 98 |
|
implemented in various ways to account for different aspects of the |
| 99 |
< |
software designs, such as lifespan control \textit{etc}, we only use |
| 99 |
> |
software design, such as lifespan control \textit{etc}, we only use |
| 100 |
|
the static data approach in {\sc OOPSE}. The declaration and |
| 101 |
|
implementation of IntegratorFactory class are given by declared in |
| 102 |
|
List.~\ref{appendixScheme:singletonDeclaration} and |
| 126 |
|
\subsection{\label{appendixSection:visitorPattern}Visitor} |
| 127 |
|
|
| 128 |
|
The visitor pattern is designed to decouple the data structure and |
| 129 |
< |
algorithms used upon them by collecting related operation from |
| 129 |
> |
algorithms used upon them by collecting related operations from |
| 130 |
|
element classes into other visitor classes, which is equivalent to |
| 131 |
|
adding virtual functions into a set of classes without modifying |
| 132 |
|
their interfaces. Fig.~\ref{appendixFig:visitorUML} demonstrates the |
| 133 |
|
structure of a Visitor pattern which is used extensively in {\tt |
| 134 |
|
Dump2XYZ}. In order to convert an OOPSE dump file, a series of |
| 135 |
|
distinct operations are performed on different StuntDoubles (See the |
| 136 |
< |
class hierarchy in Fig.~\ref{oopseFig:hierarchy} and the declaration |
| 137 |
< |
in Scheme.~\ref{appendixScheme:element}). Since the hierarchies |
| 138 |
< |
remain stable, it is easy to define a visit operation (see |
| 139 |
< |
Scheme.~\ref{appendixScheme:visitor}) for each class of StuntDouble. |
| 140 |
< |
Note that using Composite pattern\cite{Gamma1994}, CompositeVisitor |
| 141 |
< |
manages a priority visitor list and handles the execution of every |
| 142 |
< |
visitor in the priority list on different StuntDoubles. |
| 136 |
> |
class hierarchy in Scheme.~\ref{oopseFig:hierarchy} and the |
| 137 |
> |
declaration in Scheme.~\ref{appendixScheme:element}). Since the |
| 138 |
> |
hierarchies remain stable, it is easy to define a visit operation |
| 139 |
> |
(see Scheme.~\ref{appendixScheme:visitor}) for each class of |
| 140 |
> |
StuntDouble. Note that by using the Composite |
| 141 |
> |
pattern\cite{Gamma1994}, CompositeVisitor manages a priority visitor |
| 142 |
> |
list and handles the execution of every visitor in the priority list |
| 143 |
> |
on different StuntDoubles. |
| 144 |
|
|
| 145 |
< |
\begin{lstlisting}[float,caption={[A classic Singleton design pattern implementation(I)] The declaration of of simple Singleton pattern.},label={appendixScheme:singletonDeclaration}] |
| 145 |
> |
\begin{figure} |
| 146 |
> |
\centering |
| 147 |
> |
\includegraphics[width=\linewidth]{visitor.eps} |
| 148 |
> |
\caption[The UML class diagram of Visitor patten] {The UML class |
| 149 |
> |
diagram of Visitor patten.} \label{appendixFig:visitorUML} |
| 150 |
> |
\end{figure} |
| 151 |
|
|
| 152 |
< |
class IntegratorFactory { public: |
| 153 |
< |
static IntegratorFactory* getInstance(); protected: |
| 152 |
> |
\begin{figure} |
| 153 |
> |
\centering |
| 154 |
> |
\includegraphics[width=\linewidth]{hierarchy.eps} |
| 155 |
> |
\caption[Class hierarchy for ojects in {\sc OOPSE}]{ A diagram of |
| 156 |
> |
the class hierarchy. Objects below others on the diagram inherit |
| 157 |
> |
data structures and functions from their parent classes above them.} |
| 158 |
> |
\label{oopseFig:hierarchy} |
| 159 |
> |
\end{figure} |
| 160 |
> |
|
| 161 |
> |
\begin{lstlisting}[float,basicstyle=\ttfamily,caption={[A classic Singleton design pattern implementation(I)] The declaration of of simple Singleton pattern.},label={appendixScheme:singletonDeclaration}] |
| 162 |
> |
|
| 163 |
> |
class IntegratorFactory { |
| 164 |
> |
public: |
| 165 |
> |
static IntegratorFactory* getInstance(); |
| 166 |
> |
protected: |
| 167 |
|
IntegratorFactory(); |
| 168 |
< |
private: |
| 169 |
< |
static IntegratorFactory* instance_; |
| 150 |
< |
}; |
| 168 |
> |
private: |
| 169 |
> |
static IntegratorFactory* instance_; }; |
| 170 |
|
|
| 171 |
|
\end{lstlisting} |
| 172 |
|
|
| 185 |
|
|
| 186 |
|
\begin{lstlisting}[float,caption={[The implementation of Parameterized Factory pattern (I)]Source code of IntegratorFactory class.},label={appendixScheme:factoryDeclaration}] |
| 187 |
|
|
| 188 |
< |
class IntegratorFactory { public: |
| 188 |
> |
class IntegratorFactory { |
| 189 |
> |
public: |
| 190 |
|
typedef std::map<string, IntegratorCreator*> CreatorMapType; |
| 191 |
|
|
| 192 |
< |
bool registerIntegrator(IntegratorCreator* creator) { |
| 193 |
< |
return creatorMap_.insert(creator->getIdent(), creator).second; |
| 192 |
> |
bool registerIntegrator(IntegratorCreator* creator){ |
| 193 |
> |
return creatorMap_.insert(creator->getIdent(),creator).second; |
| 194 |
|
} |
| 195 |
|
|
| 196 |
|
Integrator* createIntegrator(const string& id, SimInfo* info) { |
| 211 |
|
|
| 212 |
|
class IntegratorCreator { |
| 213 |
|
public: |
| 214 |
< |
IntegratorCreator(const string& ident) : ident_(ident) {} |
| 214 |
> |
IntegratorCreator(const string& ident) : ident_(ident) {} |
| 215 |
|
|
| 216 |
< |
const string& getIdent() const { return ident_; } |
| 216 |
> |
const string& getIdent() const { return ident_; } |
| 217 |
|
|
| 218 |
< |
virtual Integrator* create(SimInfo* info) const = 0; |
| 218 |
> |
virtual Integrator* create(SimInfo* info) const = 0; |
| 219 |
|
|
| 220 |
< |
private: |
| 221 |
< |
string ident_; |
| 220 |
> |
private: |
| 221 |
> |
string ident_; |
| 222 |
|
}; |
| 223 |
|
|
| 224 |
< |
template<class ConcreteIntegrator> class IntegratorBuilder : public |
| 225 |
< |
IntegratorCreator { |
| 224 |
> |
template<class ConcreteIntegrator> class IntegratorBuilder : |
| 225 |
> |
public IntegratorCreator { |
| 226 |
|
public: |
| 227 |
< |
IntegratorBuilder(const string& ident) |
| 227 |
> |
IntegratorBuilder(const string& ident) |
| 228 |
|
: IntegratorCreator(ident) {} |
| 229 |
< |
virtual Integrator* create(SimInfo* info) const { |
| 230 |
< |
return new ConcreteIntegrator(info); |
| 231 |
< |
} |
| 229 |
> |
virtual Integrator* create(SimInfo* info) const { |
| 230 |
> |
return new ConcreteIntegrator(info); |
| 231 |
> |
} |
| 232 |
|
}; |
| 233 |
|
\end{lstlisting} |
| 234 |
|
|
| 236 |
|
|
| 237 |
|
class StuntDouble { |
| 238 |
|
public: |
| 239 |
< |
virtual void accept(BaseVisitor* v) = 0; |
| 239 |
> |
virtual void accept(BaseVisitor* v) = 0; |
| 240 |
|
}; |
| 241 |
|
|
| 242 |
|
class Atom: public StuntDouble { |
| 243 |
|
public: |
| 244 |
< |
virtual void accept{BaseVisitor* v*} { |
| 245 |
< |
v->visit(this); |
| 246 |
< |
} |
| 244 |
> |
virtual void accept{BaseVisitor* v*} { |
| 245 |
> |
v->visit(this); |
| 246 |
> |
} |
| 247 |
|
}; |
| 248 |
|
|
| 249 |
|
class DirectionalAtom: public Atom { |
| 250 |
|
public: |
| 251 |
< |
virtual void accept{BaseVisitor* v*} { |
| 252 |
< |
v->visit(this); |
| 253 |
< |
} |
| 251 |
> |
virtual void accept{BaseVisitor* v*} { |
| 252 |
> |
v->visit(this); |
| 253 |
> |
} |
| 254 |
|
}; |
| 255 |
|
|
| 256 |
|
class RigidBody: public StuntDouble { |
| 257 |
|
public: |
| 258 |
< |
virtual void accept{BaseVisitor* v*} { |
| 259 |
< |
v->visit(this); |
| 260 |
< |
} |
| 258 |
> |
virtual void accept{BaseVisitor* v*} { |
| 259 |
> |
v->visit(this); |
| 260 |
> |
} |
| 261 |
|
}; |
| 262 |
|
|
| 263 |
|
\end{lstlisting} |
| 264 |
|
|
| 265 |
|
\begin{lstlisting}[float,caption={[The implementation of Visitor pattern (I)]Source code of the visitor classes.},label={appendixScheme:visitor}] |
| 246 |
– |
|
| 266 |
|
class BaseVisitor{ |
| 267 |
|
public: |
| 268 |
< |
virtual void visit(Atom* atom); |
| 269 |
< |
virtual void visit(DirectionalAtom* datom); |
| 270 |
< |
virtual void visit(RigidBody* rb); |
| 268 |
> |
virtual void visit(Atom* atom); |
| 269 |
> |
virtual void visit(DirectionalAtom* datom); |
| 270 |
> |
virtual void visit(RigidBody* rb); |
| 271 |
|
}; |
| 253 |
– |
|
| 272 |
|
class BaseAtomVisitor:public BaseVisitor{ |
| 273 |
|
public: |
| 274 |
< |
virtual void visit(Atom* atom); |
| 275 |
< |
virtual void visit(DirectionalAtom* datom); |
| 276 |
< |
virtual void visit(RigidBody* rb); |
| 274 |
> |
virtual void visit(Atom* atom); |
| 275 |
> |
virtual void visit(DirectionalAtom* datom); |
| 276 |
> |
virtual void visit(RigidBody* rb); |
| 277 |
|
}; |
| 260 |
– |
|
| 278 |
|
class CompositeVisitor: public BaseVisitor { |
| 279 |
|
public: |
| 280 |
|
typedef list<pair<BaseVisitor*, int> > VistorListType; |
| 282 |
|
virtual void visit(Atom* atom) { |
| 283 |
|
VisitorListIterator i; |
| 284 |
|
BaseVisitor* curVisitor; |
| 285 |
< |
for(i = visitorScheme.begin();i != visitorScheme.end();++i) { |
| 285 |
> |
for(i = visitorScheme.begin();i != visitorScheme.end();++i) |
| 286 |
|
atom->accept(*i); |
| 270 |
– |
} |
| 287 |
|
} |
| 272 |
– |
|
| 288 |
|
virtual void visit(DirectionalAtom* datom) { |
| 289 |
|
VisitorListIterator i; |
| 290 |
|
BaseVisitor* curVisitor; |
| 291 |
< |
for(i = visitorScheme.begin();i != visitorScheme.end();++i) { |
| 291 |
> |
for(i = visitorList.begin();i != visitorList.end();++i) |
| 292 |
|
atom->accept(*i); |
| 278 |
– |
} |
| 293 |
|
} |
| 280 |
– |
|
| 294 |
|
virtual void visit(RigidBody* rb) { |
| 295 |
|
VisitorListIterator i; |
| 296 |
|
std::vector<Atom*> myAtoms; |
| 297 |
|
std::vector<Atom*>::iterator ai; |
| 298 |
|
myAtoms = rb->getAtoms(); |
| 299 |
< |
for(i = visitorScheme.begin();i != visitorScheme.end();++i) { |
| 299 |
> |
for(i = visitorList.begin();i != visitorList.end();++i) { |
| 300 |
|
rb->accept(*i); |
| 301 |
< |
for(ai = myAtoms.begin(); ai != myAtoms.end(); ++ai){ |
| 301 |
> |
for(ai = myAtoms.begin(); ai != myAtoms.end(); ++ai) |
| 302 |
|
(*ai)->accept(*i); |
| 290 |
– |
} |
| 303 |
|
} |
| 292 |
– |
|
| 304 |
|
void addVisitor(BaseVisitor* v, int priority); |
| 305 |
|
protected: |
| 306 |
< |
VistorListType visitorList; |
| 306 |
> |
VistorListType visitorList; |
| 307 |
|
}; |
| 308 |
|
\end{lstlisting} |
| 298 |
– |
|
| 299 |
– |
\begin{figure} |
| 300 |
– |
\centering |
| 301 |
– |
\includegraphics[width=\linewidth]{visitor.eps} |
| 302 |
– |
\caption[The UML class diagram of Visitor patten] {The UML class |
| 303 |
– |
diagram of Visitor patten.} \label{appendixFig:visitorUML} |
| 304 |
– |
\end{figure} |
| 309 |
|
|
| 306 |
– |
\begin{figure} |
| 307 |
– |
\centering |
| 308 |
– |
\includegraphics[width=\linewidth]{hierarchy.eps} |
| 309 |
– |
\caption[Class hierarchy for ojects in {\sc OOPSE}]{ A diagram of |
| 310 |
– |
the class hierarchy. Objects below others on the diagram inherit |
| 311 |
– |
data structures and functions from their parent classes above them.} |
| 312 |
– |
\label{oopseFig:hierarchy} |
| 313 |
– |
\end{figure} |
| 314 |
– |
|
| 310 |
|
\section{\label{appendixSection:concepts}Concepts} |
| 311 |
|
|
| 312 |
|
OOPSE manipulates both traditional atoms as well as some objects |