Skip to content

Commit

Permalink
Fixed grids so that old style multicolvar still works.
Browse files Browse the repository at this point in the history
In old multicolvar label of argument containing less than is aa.lessthan.
This is changed now to aa_lessthan as aa_lessthan is from a different action than
aa multicolvar.  I added to grid something to check if there is a value called aa.lessthan
in the grid file if it finds a request for aa_lessthan.
  • Loading branch information
Gareth Aneurin Tribello authored and Gareth Aneurin Tribello committed Mar 25, 2024
1 parent 4ceefe1 commit cdb4e96
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 31 deletions.
4 changes: 2 additions & 2 deletions src/adjmat/AdjacencyMatrixBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ AdjacencyMatrixBase::AdjacencyMatrixBase(const ActionOptions& ao):
{
std::vector<unsigned> shape(2); std::vector<AtomNumber> t; parseAtomList("GROUP", t );
if( t.size()==0 ) {
parseAtomList("ATOMS", t);
if( t.size()>0 ) warning("using depracated syntax for contact matrix. You are strongly recommended to use GROUP instead of ATOMS");
parseAtomList("ATOMS", t);
if( t.size()>0 ) warning("using depracated syntax for contact matrix. You are strongly recommended to use GROUP instead of ATOMS");
}

if( t.size()==0 ) {
Expand Down
32 changes: 16 additions & 16 deletions src/adjmat/ContactMatrixShortcut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,23 +90,23 @@ ContactMatrixShortcut::ContactMatrixShortcut(const ActionOptions& ao):
Action(ao),
ActionShortcut(ao)
{
std::vector<std::string> grp_str; std::string atomsstr="";
std::vector<std::string> atomsvec; parseVector("ATOMS",atomsvec);
std::vector<std::string> grp_str; std::string atomsstr="";
std::vector<std::string> atomsvec; parseVector("ATOMS",atomsvec);
if( atomsvec.size()>0 ) {
for(unsigned i=0; i<atomsvec.size(); ++i) {
Group* gg = plumed.getActionSet().selectWithLabel<Group*>( atomsvec[i] );
if( gg ) grp_str.push_back( atomsvec[i] );
}
if( grp_str.size()!=atomsvec.size() ) {
grp_str.resize(0);
atomsstr = " ATOMS=" + atomsvec[0]; for(unsigned i=1; i<atomsvec.size(); ++i) atomsstr += "," + atomsvec[i];
}
} else {
std::string grp_inpt;
for(unsigned i=1;; ++i) {
if( !parseNumbered("GROUP",i,grp_inpt) ) break;
grp_str.push_back( grp_inpt );
}
for(unsigned i=0; i<atomsvec.size(); ++i) {
Group* gg = plumed.getActionSet().selectWithLabel<Group*>( atomsvec[i] );
if( gg ) grp_str.push_back( atomsvec[i] );
}
if( grp_str.size()!=atomsvec.size() ) {
grp_str.resize(0);
atomsstr = " ATOMS=" + atomsvec[0]; for(unsigned i=1; i<atomsvec.size(); ++i) atomsstr += "," + atomsvec[i];
}
} else {
std::string grp_inpt;
for(unsigned i=1;; ++i) {
if( !parseNumbered("GROUP",i,grp_inpt) ) break;
grp_str.push_back( grp_inpt );
}
}
if( grp_str.size()>9 ) error("cannot handle more than 9 groups");
if( grp_str.size()==0 ) { readInputLine( getShortcutLabel() + ": CONTACT_MATRIX_PROPER " + atomsstr + " " + convertInputLineToString() ); return; }
Expand Down
20 changes: 10 additions & 10 deletions src/adjmat/Sprint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,17 +103,17 @@ Sprint::Sprint(const ActionOptions& ao):
Action(ao),
ActionShortcut(ao)
{
std::string matinp; parse("MATRIX",matinp);
std::string matinp; parse("MATRIX",matinp);
if( matinp.length()==0 ) {
readInputLine( getShortcutLabel() + "_jmat: CONTACT_MATRIX " + convertInputLineToString() );
matinp = getShortcutLabel() + "_jmat";
}
readInputLine( getShortcutLabel() + "_jmat: CONTACT_MATRIX " + convertInputLineToString() );
matinp = getShortcutLabel() + "_jmat";
}
std::vector<unsigned> nin_group; unsigned ntot_atoms=0;
for(unsigned i=1;; ++i) {
std::string inum; Tools::convert( i, inum );
ActionWithValue* av = plumed.getActionSet().selectWithLabel<ActionWithValue*>( matinp + inum + inum );
if( !av ) break ;
unsigned natoms = (av->copyOutput(0))->getShape()[0]; nin_group.push_back( natoms ); ntot_atoms += natoms;
std::string inum; Tools::convert( i, inum );
ActionWithValue* av = plumed.getActionSet().selectWithLabel<ActionWithValue*>( matinp + inum + inum );
if( !av ) break ;
unsigned natoms = (av->copyOutput(0))->getShape()[0]; nin_group.push_back( natoms ); ntot_atoms += natoms;
}

// Diagonalization
Expand All @@ -133,8 +133,8 @@ Sprint::Sprint(const ActionOptions& ao):
readInputLine( sort_act );
readInputLine( getShortcutLabel() + jnum + ": SORT ARG=" + getShortcutLabel() + "_selection" + jnum );
for(unsigned n=0; n<nin_group[j]; ++n) {
std::string knum, nnum; Tools::convert( kk, knum ); Tools::convert( n+1, nnum ); kk++;
readInputLine( getShortcutLabel() + "_coord-" + knum + ": COMBINE ARG=" + getShortcutLabel() + jnum + "." + nnum + " PERIODIC=NO" );
std::string knum, nnum; Tools::convert( kk, knum ); Tools::convert( n+1, nnum ); kk++;
readInputLine( getShortcutLabel() + "_coord-" + knum + ": COMBINE ARG=" + getShortcutLabel() + jnum + "." + nnum + " PERIODIC=NO" );
}
}
}
Expand Down
20 changes: 17 additions & 3 deletions src/tools/Grid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -527,8 +527,22 @@ std::unique_ptr<GridBase> GridBase::create(const std::string& funcl, const std::
std::vector<int> gbin1(nvar); std::vector<unsigned> gbin(nvar);
std::vector<std::string> labels(nvar),gmin(nvar),gmax(nvar);
std::vector<std::string> fieldnames; ifile.scanFieldList( fieldnames );

// Retrieve names for fields
for(unsigned i=0; i<args.size(); ++i) labels[i]=args[i]->getName();
for(unsigned i=0; i<args.size(); ++i) {
labels[i]=args[i]->getName(); bool found=false;
for(unsigned j=0; j<fieldnames.size(); ++j) {
if( labels[i]==fieldnames[j] ) { found=true; break; }
}
// This is a change to ensure that we can deal with old style names for multicolvars
std::size_t und = labels[i].find_first_of("_");
if( !found && und!=std::string::npos ) {
labels[i] = labels[i].substr(0,und) + "." + labels[i].substr(und+1);
for(unsigned j=0; j<fieldnames.size(); ++j) {
if( labels[i]==fieldnames[j] ) { found=true; break; }
}
}
}
// And read the stuff from the header
plumed_massert( ifile.FieldExist( funcl ), "no column labelled " + funcl + " in in grid input");
for(unsigned i=0; i<args.size(); ++i) {
Expand All @@ -546,7 +560,7 @@ std::unique_ptr<GridBase> GridBase::create(const std::string& funcl, const std::
gbin[i]=gbin1[i]-1; // Note header in grid file indicates one more bin that there should be when data is not periodic
plumed_massert( pstring=="false", "input value is not periodic but grid is");
}
hasder=ifile.FieldExist( "der_" + args[i]->getName() );
hasder=ifile.FieldExist( "der_" + labels[i] );
if( doder && !hasder ) plumed_merror("missing derivatives from grid file");
for(unsigned j=0; j<fieldnames.size(); ++j) {
for(unsigned k=i+1; k<args.size(); ++k) {
Expand All @@ -570,7 +584,7 @@ std::unique_ptr<GridBase> GridBase::create(const std::string& funcl, const std::
ifile.scanField( "nbins_" + labels[i], gbin1[i]);
ifile.scanField( "periodic_" + labels[i], pstring );
}
if(hasder) { for(unsigned i=0; i<nvar; ++i) { ifile.scanField( "der_" + args[i]->getName(), dder[i] ); } }
if(hasder) { for(unsigned i=0; i<nvar; ++i) { ifile.scanField( "der_" + labels[i], dder[i] ); } }
index_t index=grid->getIndex(xx);
if(doder) {grid->setValueAndDerivatives(index,f,dder);}
else {grid->setValue(index,f);}
Expand Down

0 comments on commit cdb4e96

Please sign in to comment.