23 #include "tools/NeighborList.h"
25 #include "tools/SwitchingFunction.h"
75 bool pbc, dosum, docmdist;
77 std::vector<SwitchingFunction>
sfs;
80 static void registerKeywords(
Keywords& keys );
84 virtual void calculate();
88 PLUMED_REGISTER_ACTION(ContactMap,
"CONTACTMAP")
91 Colvar::registerKeywords( keys );
92 keys.add(
"numbered",
"ATOMS",
"the atoms involved in each of the contacts you wish to calculate. "
93 "Keywords like ATOMS1, ATOMS2, ATOMS3,... should be listed and one contact will be "
94 "calculated for each ATOM keyword you specify.");
95 keys.reset_style(
"ATOMS",
"atoms");
96 keys.add(
"numbered",
"SWITCH",
"The switching functions to use for each of the contacts in your map. "
97 "You can either specify a global switching function using SWITCH or one "
98 "switching function for each contact. Details of the various switching "
99 "functions you can use are provided on \\ref switchingfunction.");
100 keys.add(
"numbered",
"REFERENCE",
"A reference value for a given contact, by default is 0.0 "
101 "You can either specify a global reference value using REFERENCE or one "
102 "reference value for each contact.");
103 keys.reset_style(
"SWITCH",
"compulsory");
104 keys.addFlag(
"SUM",
false,
"calculate the sum of all the contacts in the input");
105 keys.addFlag(
"CMDIST",
false,
"calculate the distance with respect to the provided reference contant map");
106 keys.addOutputComponent(
"contact",
"COMPONENTS",
"By not using SUM or CMDIST each contact will be stored in a component");
123 std::vector<AtomNumber> t, ga_lista, gb_lista;
126 if( t.empty() )
break;
130 error(
"ATOMS" + ss +
" keyword has the wrong number of atoms");
132 ga_lista.push_back(t[0]); gb_lista.push_back(t[1]);
143 std::string errors;
sfs.resize( ga_lista.size() );
unsigned nswitch=0;
144 for(
unsigned i=0;i<ga_lista.size();++i){
147 nswitch++;
sfs[i].set(sw1,errors);
148 if( errors.length()!=0 )
error(
"problem reading SWITCH" + num +
" keyword : " + errors );
151 std::string sw;
parse(
"SWITCH",sw);
152 if(sw.length()==0)
error(
"no switching function specified use SWITCH keyword");
153 for(
unsigned i=0;i<ga_lista.size();++i){
154 sfs[i].set(sw,errors);
155 if( errors.length()!=0 )
error(
"problem reading SWITCH keyword : " + errors );
157 }
else if( nswitch!=
sfs.size() ){
159 error(
"missing SWITCH" + num +
" keyword");
164 for(
unsigned i=0;i<ga_lista.size();++i)
reference[i]=0.;
165 for(
unsigned i=0;i<ga_lista.size();++i){
171 for(
unsigned i=1;i<ga_lista.size();++i){
174 nswitch = ga_lista.size();
176 if ( nswitch != ga_lista.size() )
error(
"missing REFERENCE keyword");
179 for(
unsigned i=0;i<
sfs.size();++i){
180 log.
printf(
" The %dth contact is calculated from atoms : %d %d. Inflection point of switching function is at %s. Reference contact value is %lf\n", i+1, ga_lista[i].serial(), gb_lista[i].serial() , (
sfs[i].description() ).c_str(),
reference[i] );
186 log.
printf(
" colvar is sum of all contacts in contact map\n");
190 log.
printf(
" colvar is distance between the contact map matrix and the provided reference matrix\n");
202 double ncoord=0., coord;
206 for(
unsigned int i=0;i<
nl->
size();i++) {
219 deriv[i0] = deriv[i0] + (-dfunc)*distance ;
220 deriv[i1] = deriv[i1] + dfunc*distance ;
221 virial=virial+(-dfunc)*
Tensor(distance,distance);
224 deriv[i0] = deriv[i0] + 2.*coord*(-dfunc)*distance ;
225 deriv[i1] = deriv[i1] + 2.*coord*dfunc*distance ;
226 virial=virial+2.*coord*(-dfunc)*
Tensor(distance,distance);
227 ncoord += coord*coord;
bool parseNumbered(const std::string &key, const int no, T &t)
Parse one numbered keyword as generic type.
const Vector & getPosition(int) const
Get position of i-th atom.
void parseFlag(const std::string &key, bool &t)
Parse one keyword as boolean flag.
void setNotPeriodic()
Set your default value to have no periodicity.
std::vector< PLMD::AtomNumber > & getFullAtomList()
Return the list of all atoms. These are needed to rebuild the neighbor list.
Log & log
Reference to the log stream.
double modulo() const
Compute the modulo.
void componentIsNotPeriodic(const std::string &name)
Set your value component to have no periodicity.
Class implementing fixed size matrices of doubles.
Class implementing fixed size vectors of doubles.
A class for holding the value of a function together with its derivatives.
void setAtomsDerivatives(int, const Vector &)
void error(const std::string &msg) const
Crash calculation and print documentation.
void checkRead()
Check if Action was properly read.
void parseAtomList(const std::string &key, std::vector< AtomNumber > &t)
Parse a list of atoms without a numbered keyword.
void addValueWithDerivatives()
Add a value with the name label that has derivatives.
void requestAtoms(const std::vector< AtomNumber > &a)
#define PLUMED_COLVAR_INIT(ao)
const Pbc & getPbc() const
Get reference to Pbc.
void setBoxDerivatives(const Tensor &)
void set(double)
Set the value of the function.
void parse(const std::string &key, T &t)
Parse one keyword as generic type.
This class holds the keywords and their documentation.
A class that implements neighbor lists from two lists or a single list of atoms.
This class is used to bring the relevant information to the Action constructor.
int printf(const char *fmt,...)
Formatted output with explicit format - a la printf.
This is the abstract base class to use for implementing new collective variables, within it there is ...
std::pair< unsigned, unsigned > getClosePair(unsigned i) const
Get the i-th pair of the neighbor list.
VectorGeneric< n > delta(const VectorGeneric< n > &v1, const VectorGeneric< n > &v2)
void setValue(const double &d)
Set the default value (the one without name)
Vector pbcDistance(const Vector &, const Vector &) const
Compute the pbc distance between two positions.
void addComponentWithDerivatives(const std::string &name)
Add a value with a name like label.name that has derivatives.
Value * getPntrToComponent(int i)
Return a pointer to the component by index.
unsigned getNumberOfAtoms() const
Get number of available atoms.
unsigned size() const
Get the size of the neighbor list.