Skip to content

Commit

Permalink
Fixes to make inputs from tutorial pages work with master version of …
Browse files Browse the repository at this point in the history
…code.

This fix includes addition of code to read the NORMALIZATION keyword in AVERAGE.  The user is shown a warning if they use this keyword and recommended to use the new (Simpler) syntax.

I also added the functionaility to use the atom selection tools from ActionAtomistic to specify the ATOM_INDICES in DUMPPDB.  In doing this I made interpretAtomList a static function so
I can reuse it in actions that do not inherit from ActionAtomistic.
  • Loading branch information
Gareth Aneurin Tribello authored and Gareth Aneurin Tribello committed May 12, 2024
1 parent 13b42fc commit f489f42
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 29 deletions.
34 changes: 19 additions & 15 deletions src/core/ActionAtomistic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ ActionAtomistic::ActionAtomistic(const ActionOptions&ao):
ActionWithValue* bv = plumed.getActionSet().selectWithLabel<ActionWithValue*>("Box");
if( bv ) boxValue=bv->copyOutput(0);
// We now get all the information about atoms that are lying about
getAtomValuesFromPlumedObject( plumed, xpos, ypos, zpos, masv, chargev );
if( xpos.size()!=ypos.size() || xpos.size()!=zpos.size() || xpos.size()!=masv.size() || xpos.size()!=chargev.size() )
error("mismatch between value arrays");
}

void ActionAtomistic::getAtomValuesFromPlumedObject( const PlumedMain& plumed, std::vector<Value*>& xpos, std::vector<Value*>& ypos, std::vector<Value*>& zpos, std::vector<Value*>& masv, std::vector<Value*>& chargev ) {
std::vector<ActionWithValue*> vatoms = plumed.getActionSet().select<ActionWithValue*>();
for(const auto & vv : vatoms ) {
plumed_assert(vv); // needed for following calls, see #1046
Expand All @@ -71,8 +77,6 @@ ActionAtomistic::ActionAtomistic(const ActionOptions&ao):
chargev.push_back( vv->copyOutput( vv->getLabel() + ".charge") );
}
}
if( xpos.size()!=ypos.size() || xpos.size()!=zpos.size() || xpos.size()!=masv.size() || xpos.size()!=chargev.size() )
error("mismatch between value arrays");
}

void ActionAtomistic::registerKeywords( Keywords& keys ) {
Expand Down Expand Up @@ -218,10 +222,10 @@ void ActionAtomistic::parseAtomList(const std::string&key,const int num, std::ve
} else {
if ( !parseNumberedVector(key,num,strings) ) return;
}
t.resize(0); interpretAtomList( strings, t );
t.resize(0); interpretAtomList( strings, xpos, this, t );
}

void ActionAtomistic::interpretAtomList(std::vector<std::string>& strings, std::vector<AtomNumber> &t) {
void ActionAtomistic::interpretAtomList(std::vector<std::string>& strings, const std::vector<Value*>& xpos, Action* action, std::vector<AtomNumber> &t) {
Tools::interpretRanges(strings);
for(unsigned i=0; i<strings.size(); ++i) {
AtomNumber atom;
Expand Down Expand Up @@ -249,9 +253,9 @@ void ActionAtomistic::interpretAtomList(std::vector<std::string>& strings, std::
ndxgroup=words[1];
} else plumed_error()<<"Cannot intepret selection "<<symbol;

if(ndxgroup.size()>0) log<<" importing group '"+ndxgroup+"'";
else log<<" importing first group";
log<<" from index file "<<ndxfile<<"\n";
if(ndxgroup.size()>0) action->log<<" importing group '"+ndxgroup+"'";
else action->log<<" importing first group";
action->log<<" from index file "<<ndxfile<<"\n";

IFile ifile;
ifile.open(ndxfile);
Expand All @@ -275,27 +279,27 @@ void ActionAtomistic::interpretAtomList(std::vector<std::string>& strings, std::
if(!groupfound) plumed_error()<<"group has not been found in index file";
ok=true;
} else {
auto* moldat=plumed.getActionSet().selectLatest<GenericMolInfo*>(this);
auto* moldat=action->plumed.getActionSet().selectLatest<GenericMolInfo*>(action);
if( moldat ) {
std::vector<AtomNumber> atom_list; moldat->interpretSymbol( symbol, atom_list );
if( atom_list.size()>0 ) { ok=true; t.insert(t.end(),atom_list.begin(),atom_list.end()); }
else { error(strings[i] + " is not a label plumed knows"); }
else { action->error(strings[i] + " is not a label plumed knows"); }
} else {
error("atoms specified using @ symbol but no MOLINFO was available");
action->error("atoms specified using @ symbol but no MOLINFO was available");
}
}
}
// here we check if the atom name is the name of a group
if(!ok) {
Group* mygrp=plumed.getActionSet().selectWithLabel<Group*>(strings[i]);
Group* mygrp=action->plumed.getActionSet().selectWithLabel<Group*>(strings[i]);
if(mygrp) {
std::vector<std::string> grp_str( mygrp->getGroupAtoms() );
interpretAtomList( grp_str, t ); ok=true;
interpretAtomList( grp_str, xpos, action, t ); ok=true;
} else {
Group* mygrp2=plumed.getActionSet().selectWithLabel<Group*>(strings[i]+"_grp");
Group* mygrp2=action->plumed.getActionSet().selectWithLabel<Group*>(strings[i]+"_grp");
if(mygrp2) {
std::vector<std::string> grp_str( mygrp2->getGroupAtoms() );
interpretAtomList( grp_str, t ); ok=true;
interpretAtomList( grp_str, xpos, action, t ); ok=true;
}
}
}
Expand All @@ -309,7 +313,7 @@ void ActionAtomistic::interpretAtomList(std::vector<std::string>& strings, std::
ind = ind + xpos[j]->getNumberOfValues();
}
}
if(!ok) error("it was not possible to interpret atom name " + strings[i]);
if(!ok) action->error("it was not possible to interpret atom name " + strings[i]);
// plumed_massert(ok,"it was not possible to interpret atom name " + strings[i]);
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/core/ActionAtomistic.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,9 @@ class ActionAtomistic :
/// Parse an list of atom with a numbred keyword
void parseAtomList(const std::string&key,const int num, std::vector<AtomNumber> &t);
/// Convert a set of read in strings into an atom list (this is used in parseAtomList)
void interpretAtomList( std::vector<std::string>& strings, std::vector<AtomNumber> &t);
static void interpretAtomList( std::vector<std::string>& strings, const std::vector<Value*>& xpos, Action* action, std::vector<AtomNumber> &t);
/// This gets std::vector that contain the PLMD::Value objects that contain xpositions, ypositions, zpositions, masses and charges
static void getAtomValuesFromPlumedObject( const PlumedMain& plumed, std::vector<Value*>& xpos, std::vector<Value*>& ypos, std::vector<Value*>& zpos, std::vector<Value*>& masv, std::vector<Value*>& chargev );
/// Change the box shape
void changeBox( const Tensor& newbox );
/// Get reference to Pbc
Expand Down
2 changes: 1 addition & 1 deletion src/core/Group.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ Group::Group(const ActionOptions&ao):
std::vector<AtomNumber> add;
std::vector<std::string> words;
words.emplace_back("@ndx: " + ndxfile + " " + ndxgroup);
interpretAtomList(words,add);
interpretAtomList(words,xpos,this,add);
atoms.insert(atoms.end(),add.begin(),add.end());
}

Expand Down
11 changes: 9 additions & 2 deletions src/generic/Average.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ void Average::registerKeywords( Keywords& keys ) {
keys.add("optional","LOGWEIGHTS","the logarithm of the quantity to use as the weights when calculating averages");
keys.add("compulsory","STRIDE","1","the frequency with which to store data for averaging");
keys.add("compulsory","CLEAR","0","the frequency with whihc to clear the data that is being averaged");
keys.add("optional","NORMALIZATION","keyword for old version of the code that is there to maintain back compatibility only. Adding this keyword does nothing");
keys.needsAction("COMBINE"); keys.needsAction("CUSTOM"); keys.needsAction("ONES"); keys.needsAction("ACCUMULATE");
}

Expand Down Expand Up @@ -131,9 +132,15 @@ Average::Average( const ActionOptions& ao ):
readInputLine( getShortcutLabel() + "_cossum: ACCUMULATE ARG=" + getShortcutLabel() + "_cos STRIDE=" + stride + " CLEAR=" + clearstride );
readInputLine( getShortcutLabel() + ": CUSTOM ARG=" + getShortcutLabel() + "_sinsum," + getShortcutLabel() + "_cossum," + getShortcutLabel() + "_denom FUNC=" + lbound + "+" + pfactor + "*atan2(x/z,y/z) PERIODIC=" + lbound +"," + ubound);
} else {
std::string normstr; parse("NORMALIZATION",normstr);
if( normstr=="true" || normstr=="false" ) warning("NORMALIZATION is deprecated. You are advised to take this out of input files in future and use the new syntax with ACCUMULATE for unormalized data rather than the shortcut AVERAGE");
else if( normstr.length()>0 ) error("NORMALIZATION=" + normstr + " is not valid PLUMED input. If you want an unormalised 'average' use ACCUMULATE");
readInputLine( getShortcutLabel() + "_prod: CUSTOM ARG=" + arg[0] + "," + getShortcutLabel() + "_weight FUNC=x*y PERIODIC=NO");
readInputLine( getShortcutLabel() + "_numer: ACCUMULATE ARG=" + getShortcutLabel() + "_prod STRIDE=" + stride + " CLEAR=" + clearstride );
readInputLine( getShortcutLabel() + ": CUSTOM ARG=" + getShortcutLabel() + "_numer," + getShortcutLabel() + "_denom FUNC=x/y PERIODIC=NO");
if( normstr.length()==0 || normstr=="true" ) {
readInputLine( getShortcutLabel() + "_numer: ACCUMULATE ARG=" + getShortcutLabel() + "_prod STRIDE=" + stride + " CLEAR=" + clearstride );
readInputLine( getShortcutLabel() + ": CUSTOM ARG=" + getShortcutLabel() + "_numer," + getShortcutLabel() + "_denom FUNC=x/y PERIODIC=NO");
} else if( normstr=="false" ) readInputLine( getShortcutLabel() + ": ACCUMULATE ARG=" + getShortcutLabel() + "_prod STRIDE=" + stride + " CLEAR=" + clearstride );
else plumed_error();
}
}

Expand Down
5 changes: 3 additions & 2 deletions src/generic/DumpMassCharge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,9 @@ DumpMassCharge::DumpMassCharge(const ActionOptions&ao):
parseAtomList("ATOMS",atoms);

if(atoms.size()==0) {
std::vector<std::string> strvec(1);
strvec[0]="@mdatoms"; interpretAtomList( strvec, atoms );
std::vector<Value*> xvals,yvals,zvals,masv,chargev;
std::vector<std::string> strvec(1); ActionAtomistic::getAtomValuesFromPlumedObject(plumed,xvals,yvals,zvals,masv,chargev);
strvec[0]="@mdatoms"; interpretAtomList( strvec,xvals,this,atoms );
}

bool only_masses = false;
Expand Down
15 changes: 7 additions & 8 deletions src/generic/DumpPDB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
#include "core/ActionWithArguments.h"
#include "core/ActionWithValue.h"
#include "core/ActionAtomistic.h"
#include "core/ActionPilot.h"
#include "core/ActionRegister.h"
#include "core/PlumedMain.h"
Expand Down Expand Up @@ -48,7 +49,7 @@ class DumpPDB :
std::string file;
std::string description;
std::vector<std::string> argnames;
std::vector<unsigned> pdb_atom_indices;
std::vector<AtomNumber> pdb_atom_indices;
void buildArgnames();
void printAtom( OFile& opdbf, const unsigned& anum, const Vector& pos, const double& m, const double& q ) const ;
public:
Expand Down Expand Up @@ -86,13 +87,11 @@ DumpPDB::DumpPDB(const ActionOptions&ao):
std::vector<Value*> atom_args; interpretArgumentList( atoms, plumed.getActionSet(), this, atom_args );
if( atom_args.size()!=1 ) error("only one action should appear in input to atom args");
std::vector<Value*> args( getArguments() ); args.push_back( atom_args[0] ); requestArguments( args );
std::vector<std::string> indices; parseVector("ATOM_INDICES",indices); Tools::interpretRanges(indices);
std::vector<std::string> indices; parseVector("ATOM_INDICES",indices); std::vector<Value*> xvals,yvals,zvals,masv,chargev;
ActionAtomistic::getAtomValuesFromPlumedObject(plumed,xvals,yvals,zvals,masv,chargev);
ActionAtomistic::interpretAtomList( indices, xvals, this, pdb_atom_indices );
log.printf(" printing atoms : ");
for(unsigned i=0; i<indices.size(); ++i) {
AtomNumber atom; bool ok=Tools::convertNoexcept(indices[i],atom);
if( !ok ) error("count not interpret atom " + indices[i] );
pdb_atom_indices.push_back(atom.serial()); log.printf("%d ", pdb_atom_indices[i] );
}
for(unsigned i=0; i<indices.size(); ++i) log.printf("%d ", pdb_atom_indices[i].serial() );
log.printf("\n");
if( pdb_atom_indices.size()!=atom_args[0]->getShape()[1]/3 ) error("mismatch between size of matrix containing positions and vector of atom indices");
}
Expand Down Expand Up @@ -173,7 +172,7 @@ void DumpPDB::update() {
pos[0]=getPntrToArgument(atomarg)->get(npos*(3*i+0) + k);
pos[1]=getPntrToArgument(atomarg)->get(npos*(3*i+1) + k);
pos[2]=getPntrToArgument(atomarg)->get(npos*(3*i+2) + k);
printAtom( opdbf, pdb_atom_indices[k], pos, 1.0, 1.0 );
printAtom( opdbf, pdb_atom_indices[k].serial(), pos, 1.0, 1.0 );
}
}
opdbf.printf("END\n");
Expand Down

1 comment on commit f489f42

@PlumedBot
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found broken examples in automatic/ANGLES.tmp
Found broken examples in automatic/ANN.tmp
Found broken examples in automatic/CAVITY.tmp
Found broken examples in automatic/CLASSICAL_MDS.tmp
Found broken examples in automatic/CLUSTER_DIAMETER.tmp
Found broken examples in automatic/CLUSTER_DISTRIBUTION.tmp
Found broken examples in automatic/CLUSTER_PROPERTIES.tmp
Found broken examples in automatic/CONSTANT.tmp
Found broken examples in automatic/CONTACT_MATRIX.tmp
Found broken examples in automatic/CONTACT_MATRIX_PROPER.tmp
Found broken examples in automatic/COORDINATIONNUMBER.tmp
Found broken examples in automatic/DFSCLUSTERING.tmp
Found broken examples in automatic/DISTANCE_FROM_CONTOUR.tmp
Found broken examples in automatic/EDS.tmp
Found broken examples in automatic/EMMI.tmp
Found broken examples in automatic/ENVIRONMENTSIMILARITY.tmp
Found broken examples in automatic/FIND_CONTOUR.tmp
Found broken examples in automatic/FIND_CONTOUR_SURFACE.tmp
Found broken examples in automatic/FIND_SPHERICAL_CONTOUR.tmp
Found broken examples in automatic/FOURIER_TRANSFORM.tmp
Found broken examples in automatic/FUNCPATHGENERAL.tmp
Found broken examples in automatic/FUNCPATHMSD.tmp
Found broken examples in automatic/FUNNEL.tmp
Found broken examples in automatic/FUNNEL_PS.tmp
Found broken examples in automatic/GHBFIX.tmp
Found broken examples in automatic/GPROPERTYMAP.tmp
Found broken examples in automatic/HBOND_MATRIX.tmp
Found broken examples in automatic/INCLUDE.tmp
Found broken examples in automatic/INCYLINDER.tmp
Found broken examples in automatic/INENVELOPE.tmp
Found broken examples in automatic/INTERPOLATE_GRID.tmp
Found broken examples in automatic/LOCAL_AVERAGE.tmp
Found broken examples in automatic/MAZE_OPTIMIZER_BIAS.tmp
Found broken examples in automatic/MAZE_RANDOM_ACCELERATION_MD.tmp
Found broken examples in automatic/MAZE_SIMULATED_ANNEALING.tmp
Found broken examples in automatic/MAZE_STEERED_MD.tmp
Found broken examples in automatic/MULTICOLVARDENS.tmp
Found broken examples in automatic/OUTPUT_CLUSTER.tmp
Found broken examples in automatic/PAMM.tmp
Found broken examples in automatic/PCA.tmp
Found broken examples in automatic/PCAVARS.tmp
Found broken examples in automatic/PIV.tmp
Found broken examples in automatic/PLUMED.tmp
Found broken examples in automatic/PYCVINTERFACE.tmp
Found broken examples in automatic/PYTHONFUNCTION.tmp
Found broken examples in automatic/Q3.tmp
Found broken examples in automatic/Q4.tmp
Found broken examples in automatic/Q6.tmp
Found broken examples in automatic/QUATERNION.tmp
Found broken examples in automatic/SPRINT.tmp
Found broken examples in automatic/TETRAHEDRALPORE.tmp
Found broken examples in automatic/TORSIONS.tmp
Found broken examples in automatic/WHAM_WEIGHTS.tmp
Found broken examples in AnalysisPP.md
Found broken examples in CollectiveVariablesPP.md
Found broken examples in MiscelaneousPP.md

Please sign in to comment.