Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
Plumed AlphaFold
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Martin Kurečka
Plumed AlphaFold
Commits
f7358f65
There was an error fetching the commit references. Please try again later.
Commit
f7358f65
authored
12 years ago
by
Gareth Tribello
Browse files
Options
Downloads
Patches
Plain Diff
Adjusted some of the text in here to make it clearer
parent
43391631
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
developer-doc/plmdIntro.txt
+34
-32
34 additions, 32 deletions
developer-doc/plmdIntro.txt
with
34 additions
and
32 deletions
developer-doc/plmdIntro.txt
+
34
−
32
View file @
f7358f65
...
@@ -24,8 +24,8 @@ us to acchieve these aims:
...
@@ -24,8 +24,8 @@ us to acchieve these aims:
To be clear though object oriented programming does not allow us to do things that
To be clear though object oriented programming does not allow us to do things that
would be impossible with other programming languages. All programs perform some set of
would be impossible with other programming languages. All programs perform some set of
mathematical operations
. A
ny programming language can be used to implement these mathematical
mathematical operations
and a
ny programming language can be used to implement these mathematical
operations.
The only advantage of C++ is that the advanced, object-oriented features of the
operations. The only advantage of C++ is that the advanced, object-oriented features of the
language make implementing things more straighforward.
language make implementing things more straighforward.
As you are no doubt aware, in C one can create structures to order the variables in your code.
As you are no doubt aware, in C one can create structures to order the variables in your code.
...
@@ -61,22 +61,30 @@ colvar and function that is implemented in plumed 2.0 is inside its own separate
...
@@ -61,22 +61,30 @@ colvar and function that is implemented in plumed 2.0 is inside its own separate
\section publicprivate Public and private members
\section publicprivate Public and private members
The variables in a C struct can be accessed anywhere in the code
. A
ny function in the code
The variables in a C struct can be accessed anywhere in the code
- a
ny function in the code
can copy the information from a structure or change the values of the variables in the structure. This
can copy the information from a structure or change the values of the variables in the structure. This
was a particularly fun feature of plumed 1.0
- a code in which every function
could change any of the variables
was a particularly fun feature of plumed 1.0
, every function in the old code
could change any of the variables
in the code!
Problems with this approach occurs when
a new function accidentally change
s
the
in the code!
Obviously this causes problems
a
s
new function
s can
accidentally change the
value of some variable in a widely used structure that should never have been changed. As one can imagine this can cause
value
s
of some variable in a widely used structure that should never have been changed. As one can imagine this can cause
drastic problems
in other areas of the code
. To prevent errors like this C++ provides a set of functionalities to
drastic problems. To prevent errors like this C++ provides a set of functionalities to
allow one to specify what any given function can do to the members of a class. This is not possible in
allow one to specify what any given function can do to the members of a class. This is not possible in
C and it was the ability to use this functionality to create flexible, easily-extendable code that motivated
C and it was the ability to use this functionality to create flexible, easily-extendable code that motivated
our choice of C++ for plumed 2. The example class below shows how this is done in practise:
our choice of C++ for plumed 2. The example class below shows how this is done in practise:
\verbatim
class myclass{
private:
bool b; //--This can only be accessed when you are in one of the methods in the class
public:
int i; //--This can be acessed by anywhere in the code
};
\section constructors Constructors
\section constructors Constructors
As someone who learnt to program in fortran it was this aspect of C++, more than any other, that confused me
As someone who learnt to program in fortran it was this aspect of C++, more than any other, that confused me
the most.
In actually though it is rather simple and I don't really know why I was confused.
In essence every
the most. In actually though it is rather simple and I don't really know why I was confused. In essence every
class must contain some method for creating it.
This class should set the initial values of all the variables
class must contain some method for creating it. This class should set the initial values of all the variables
inside the class.
Obviously the functions (or more correctly methods) that the class
inside the class. Obviously the functions (or more correctly methods) that the class
contains cannot be used untill an instance of the class has been created using the constructor.
contains cannot be used untill an instance of the class has been created using the constructor.
An example of how all this works in practise is given below:
An example of how all this works in practise is given below:
...
@@ -97,9 +105,9 @@ public:
...
@@ -97,9 +105,9 @@ public:
// I can run g however as it is a static member of the class - I run it using
// I can run g however as it is a static member of the class - I run it using
double d=myclass::g(j);
double d=myclass::g(j);
//
C
reate an instance of the class using the constructor
//
Now I c
reate an instance of the class using the constructor
myclass thisIsTheInstance(false, 3, 6.5);
myclass thisIsTheInstance(false, 3, 6.5);
//
R
un the method called f
//
so that I can r
un the method called f
double s=thisIsTheInstance.f(4.0);
double s=thisIsTheInstance.f(4.0);
\endverbatim
\endverbatim
...
@@ -151,7 +159,7 @@ double, int or whatever variable.
...
@@ -151,7 +159,7 @@ double, int or whatever variable.
<b>
<b>
This kind of inclusion is used extensively in plumed 1.0 and there are a huge number of classes that you
This kind of inclusion is used extensively in plumed 1.0 and there are a huge number of classes that you
can re-use in this way to create new colvars, functions or biases. For a full list of the classes that are
can re-use in this way to create new colvars, functions or biases. For a full list of the classes that are
available see \subpage
toolbox
.
available see \subpage
TOOLBOX
.
</b>
</b>
\section inheritance Including the functionality of one class in a second class 2: Inheritance
\section inheritance Including the functionality of one class in a second class 2: Inheritance
...
@@ -189,15 +197,14 @@ B* mynewB=new B(); // This is a special way of calling the constructor so you
...
@@ -189,15 +197,14 @@ B* mynewB=new B(); // This is a special way of calling the constructor so you
A* BpretendingToBeA=dynamic_cast<A*>(mynewB);
A* BpretendingToBeA=dynamic_cast<A*>(mynewB);
\endverbatim
\endverbatim
All the colvars and free energy methods of plumed use inheritence.
In fact all these methods are
All the colvars and free energy methods of plumed use inheritence. In fact all these methods are
built on a single base class called PLMD::Action.
This class contains all the functionality for
built on a single base class called PLMD::Action. This class contains all the functionality for
reading stuff from input, the stuff for controlling the dependencies Actions and a set of controls
reading stuff from input, the stuff for controlling the dependencies Actions and a set of controls
that decide which actions are performed when. All the functionality for the different methods is
that decide which actions are performed when. All the functionality for the different methods is
then built on this root. As you can see (PLMD::Action) the inheritence tree for the code is
then built on this root. As you can see (PLMD::Action) the inheritence tree for the code is
quite complicated. However, in practise your new class will in all probability inherit from one
quite complicated. However, in practise if you are implementing a CV, function, bias or virtual atom
of the following classes:
the correct start point is with one of the classes listed on this page \ref INHERIT all of which contain
detailed descriptions of how to use them.
\ref INHERIT
\section minheritance Including the functionality of one class in a second class 3: Multiple inheritance
\section minheritance Including the functionality of one class in a second class 3: Multiple inheritance
...
@@ -207,13 +214,9 @@ we are using multiple inheritance - the classes in the layer above inherit from
...
@@ -207,13 +214,9 @@ we are using multiple inheritance - the classes in the layer above inherit from
This way of incorporating functionality from classes is unique to C++ and brings with it a special set of
This way of incorporating functionality from classes is unique to C++ and brings with it a special set of
difficulties in programming. Its great advantage is though that one can
difficulties in programming. Its great advantage is though that one can
create classes that incorporate bring a set of particular attributes. This will perhaps be most clear
create classes that incorporate bring a set of particular attributes. This will perhaps be most clear
if you look at what each of the classes in the multiple inheritence layer is doing and see how these
if you look at what each of the classes in the multiple inheritence layer is doing (see \ref MULTIINHERIT) and see how these
functionalities are used in Colvars, Functions and Biases.
functionalities are used in Colvars, Functions and Biases. Please be aware that, unless you are doing something really wacky,
you should be able to implement whatever you need to implement without writing classes that take advantage of multiple inheritance. Furthermore,
\ref MULTIINHERIT
Please be aware that, unless you are doing something really wacky, you should be able to implement whatever
you need to implement without writing classes that take advantage of multiple inheritance. Furthermore,
you should not need to touch the classes in this region of the code. The information here is there for
you should not need to touch the classes in this region of the code. The information here is there for
completeness only. If you feel you really must change something in this part of the code please contact the
completeness only. If you feel you really must change something in this part of the code please contact the
developers before doing anything.
developers before doing anything.
...
@@ -244,8 +247,7 @@ visit \ref http://www.cplusplus.com/reference/
...
@@ -244,8 +247,7 @@ visit \ref http://www.cplusplus.com/reference/
When you run a calculation with plumed the code calculates a number of CVs. The bias and the forces
When you run a calculation with plumed the code calculates a number of CVs. The bias and the forces
due to the bias are then calculated and in the final step these forces are propegated back onto the
due to the bias are then calculated and in the final step these forces are propegated back onto the
atoms using the chain rule. As we have pointed out in information on how to calculate the various CVs
atoms using the chain rule. For example PLMD::ColvarDistance
and biases are provided in the classes for the individual action. For example PLMD::ColvarDistance
contains the function that calculates a distance between atoms, while PLMD::BiasMeTaD contains
contains the function that calculates a distance between atoms, while PLMD::BiasMeTaD contains
the function for doing metadynamics. What may thus seem remarkable to the programmer unfamiliar with
the function for doing metadynamics. What may thus seem remarkable to the programmer unfamiliar with
C++ is that the class that calls the functions that calculate the CVs, biases and so on only uses
C++ is that the class that calls the functions that calculate the CVs, biases and so on only uses
...
@@ -264,8 +266,8 @@ This kind of declaration promises two things to a class:
...
@@ -264,8 +266,8 @@ This kind of declaration promises two things to a class:
- That the class will only ever be used in derived classes. No PLMD::Action class is ever
- That the class will only ever be used in derived classes. No PLMD::Action class is ever
constructed in the code. The functionality in PLMD::Action is only ever used in the derived classes
constructed in the code. The functionality in PLMD::Action is only ever used in the derived classes
that inherit PLMD::Action.
Classes like PLMD::Action are called abstract base classes.
that inherit PLMD::Action. Classes like PLMD::Action are called abstract base classes.
- That in one of the classes that inherits PLMD::Action a method called calculate will be defined.
- That in one of the classes that inherits
from
PLMD::Action a method called calculate will be defined.
The great advantage of declaring calculate() inside PLMD::Action in this way is that the calculate
The great advantage of declaring calculate() inside PLMD::Action in this way is that the calculate
routine that we declare in the derived class is a member of PLMD::Action. We thus can thus write
routine that we declare in the derived class is a member of PLMD::Action. We thus can thus write
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment