Skip to content

Commit

Permalink
parseAtomList is a MULTICOLVAR needed function
Browse files Browse the repository at this point in the history
  • Loading branch information
Iximiel committed Nov 20, 2024
1 parent 8f1acce commit 7957a2e
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 39 deletions.
5 changes: 2 additions & 3 deletions src/colvar/Angle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,11 @@ class Angle : public Colvar {
std::vector<std::vector<Vector> > derivs;
std::vector<Tensor> virial;
public:
MULTICOLVAR_SETTINGS(multiColvars::emptyMode);
MULTICOLVAR_DEFAULT(multiColvars::emptyMode);
explicit Angle(const ActionOptions&);
// active methods:
void calculate() override;
static void registerKeywords( Keywords& keys );
static void parseAtomList( const int& num, std::vector<AtomNumber>& t, ActionAtomistic* aa );

};

Expand All @@ -126,7 +125,7 @@ void Angle::registerKeywords( Keywords& keys ) {
keys.setValueDescription("the ANGLE involving these atoms");
}

void Angle::parseAtomList( const int& num, std::vector<AtomNumber>& atoms, ActionAtomistic* aa ) {
void Angle::parseAtomList( int const num, std::vector<AtomNumber>& atoms, ActionAtomistic* aa ) {
aa->parseAtomList("ATOMS",num,atoms);
if(atoms.size()==3) {
aa->log.printf(" between atoms %d %d %d\n",atoms[0].serial(),atoms[1].serial(),atoms[2].serial());
Expand Down
5 changes: 2 additions & 3 deletions src/colvar/DihedralCorrelation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,9 @@ class DihedralCorrelation : public Colvar {
std::vector<std::vector<Vector> > derivs;
std::vector<Tensor> virial;
public:
MULTICOLVAR_SETTINGS(multiColvars::emptyMode);
MULTICOLVAR_DEFAULT(multiColvars::emptyMode);
static void registerKeywords( Keywords& keys );
explicit DihedralCorrelation(const ActionOptions&);
static void parseAtomList( const int& num, std::vector<AtomNumber>& t, ActionAtomistic* aa );
void calculate() override;
};

Expand Down Expand Up @@ -107,7 +106,7 @@ DihedralCorrelation::DihedralCorrelation(const ActionOptions&ao):
else log.printf(" without periodic boundary conditions\n");
}

void DihedralCorrelation::parseAtomList( const int& num, std::vector<AtomNumber>& t, ActionAtomistic* aa ) {
void DihedralCorrelation::parseAtomList( int const num, std::vector<AtomNumber>& t, ActionAtomistic* aa ) {
aa->parseAtomList("ATOMS",num,t);
if( num<0 && t.size()!=8 ) aa->error("Number of specified atoms should be 8");
if( t.size()==8 ) {
Expand Down
6 changes: 2 additions & 4 deletions src/colvar/Dipole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,9 @@ class Dipole : public Colvar {
Value* valuez=nullptr;
public:
explicit Dipole(const ActionOptions&);
static void parseAtomList( const int& num, std::vector<AtomNumber>& t, ActionAtomistic* aa );
void calculate() override;
static void registerKeywords(Keywords& keys);
MULTICOLVAR_SETTINGS_MODE(multiColvars::components);
MULTICOLVAR_SETTINGS_SETUPF();
MULTICOLVAR_SETTINGS_BASE(multiColvars::components);
//Declaring this playinly becasue we are using modifying the charges
static void calculateCV( Modetype mode,
const std::vector<double>& masses,
Expand Down Expand Up @@ -149,7 +147,7 @@ Dipole::Dipole(const ActionOptions&ao):
requestAtoms(ga_lista);
}

void Dipole::parseAtomList( const int& num, std::vector<AtomNumber>& t, ActionAtomistic* aa ) {
void Dipole::parseAtomList( int num, std::vector<AtomNumber>& t, ActionAtomistic* aa ) {
aa->parseAtomList("GROUP",num,t);
if( t.size()>0 ) {
aa->log.printf(" of %u atoms\n",static_cast<unsigned>(t.size()));
Expand Down
5 changes: 2 additions & 3 deletions src/colvar/Distance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,9 @@ class Distance : public Colvar {
public:
static void registerKeywords( Keywords& keys );
explicit Distance(const ActionOptions&);
static void parseAtomList( const int& num, std::vector<AtomNumber>& t, ActionAtomistic* aa );
// active methods:
void calculate() override;
MULTICOLVAR_SETTINGS(multiColvars::scaledComponents);
MULTICOLVAR_DEFAULT(multiColvars::scaledComponents);
};

typedef ColvarShortcut<Distance> DistanceShortcut;
Expand Down Expand Up @@ -199,7 +198,7 @@ Distance::Distance(const ActionOptions&ao):
requestAtoms(atoms);
}

void Distance::parseAtomList( const int& num, std::vector<AtomNumber>& t, ActionAtomistic* aa ) {
void Distance::parseAtomList( int const num, std::vector<AtomNumber>& t, ActionAtomistic* aa ) {
aa->parseAtomList("ATOMS",num,t);
if( t.size()==2 ) aa->log.printf(" between atoms %d %d\n",t[0].serial(),t[1].serial());
}
Expand Down
36 changes: 24 additions & 12 deletions src/colvar/MultiColvarTemplate.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ enum class scaledComponents {
noComponents
};
}
#define MULTICOLVAR_SETTINGS_MODE(type) using Modetype=type
#define MULTICOLVAR_SETTINGS_SETUPF() static Modetype getModeAndSetupValues( ActionWithValue* av )
#define MULTICOLVAR_SETTINGS_BASE(type) using Modetype=type; \
static void parseAtomList( int num, std::vector<AtomNumber>& t, ActionAtomistic* aa ); \
static Modetype getModeAndSetupValues( ActionWithValue* av )
#define MULTICOLVAR_SETTINGS_CALCULATE_CONST() static void calculateCV( Modetype mode, \
const std::vector<double>& masses, \
const std::vector<double>& charges, \
Expand All @@ -54,8 +55,7 @@ enum class scaledComponents {
std::vector<Tensor>& virial, \
const ActionAtomistic* aa )

#define MULTICOLVAR_SETTINGS(type) MULTICOLVAR_SETTINGS_MODE(type); \
MULTICOLVAR_SETTINGS_SETUPF(); \
#define MULTICOLVAR_DEFAULT(type) MULTICOLVAR_SETTINGS_BASE(type); \
MULTICOLVAR_SETTINGS_CALCULATE_CONST()


Expand Down Expand Up @@ -106,34 +106,46 @@ MultiColvarTemplate<Colvar>::MultiColvarTemplate(const ActionOptions&ao):
std::vector<AtomNumber> all_atoms;
if( getName()=="POSITION_VECTOR" || getName()=="MASS_VECTOR" || getName()=="CHARGE_VECTOR" ) parseAtomList( "ATOMS", all_atoms );
if( all_atoms.size()>0 ) {
ablocks.resize(1); ablocks[0].resize( all_atoms.size() );
for(unsigned i=0; i<all_atoms.size(); ++i) ablocks[0][i] = i;
ablocks.resize(1);
ablocks[0].resize( all_atoms.size() );
for(unsigned i=0; i<all_atoms.size(); ++i) {
ablocks[0][i] = i;
}
} else {
std::vector<AtomNumber> t;
for(int i=1;; ++i ) {
Colvar::parseAtomList( i, t, this );
if( t.empty() ) break;

if( i==1 ) { ablocks.resize(t.size()); }
if( i==1 ) {
ablocks.resize(t.size());
}
if( t.size()!=ablocks.size() ) {
std::string ss; Tools::convert(i,ss);
std::string ss;
Tools::convert(i,ss);
error("ATOMS" + ss + " keyword has the wrong number of atoms");
}
for(unsigned j=0; j<ablocks.size(); ++j) {
ablocks[j].push_back( ablocks.size()*(i-1)+j ); all_atoms.push_back( t[j] );
ablocks[j].push_back( ablocks.size()*(i-1)+j );
all_atoms.push_back( t[j] );
}
t.resize(0);
}
}
if( all_atoms.size()==0 ) error("No atoms have been specified");
if( all_atoms.size()==0 ) {
error("No atoms have been specified");
}
requestAtoms(all_atoms);
if( keywords.exists("NOPBC") ) {
bool nopbc=!usepbc; parseFlag("NOPBC",nopbc);
bool nopbc=!usepbc;
parseFlag("NOPBC",nopbc);
usepbc=!nopbc;
}
if( keywords.exists("WHOLEMOLECULES") ) {
parseFlag("WHOLEMOLECULES",wholemolecules);
if( wholemolecules ) usepbc=false;
if( wholemolecules ) {
usepbc=false;
}
}
if( usepbc ) log.printf(" using periodic boundary conditions\n");
else log.printf(" without periodic boundary conditions\n");
Expand Down
6 changes: 2 additions & 4 deletions src/colvar/Plane.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,9 @@ class Plane : public Colvar {
public:
static void registerKeywords( Keywords& keys );
explicit Plane(const ActionOptions&);
static void parseAtomList( const int& num, std::vector<AtomNumber>& t, ActionAtomistic* aa );

// active methods:
void calculate() override;
MULTICOLVAR_SETTINGS(multiColvars::emptyMode);
MULTICOLVAR_DEFAULT(multiColvars::emptyMode);
};

typedef ColvarShortcut<Plane> PlaneShortcut;
Expand All @@ -90,7 +88,7 @@ void Plane::registerKeywords( Keywords& keys ) {
keys.add("hidden","NO_ACTION_LOG","suppresses printing from action on the log");
}

void Plane::parseAtomList( const int& num, std::vector<AtomNumber>& atoms, ActionAtomistic* aa ) {
void Plane::parseAtomList( int const num, std::vector<AtomNumber>& atoms, ActionAtomistic* aa ) {
aa->parseAtomList("ATOMS",num,atoms);
if(atoms.size()==3) {
aa->log.printf(" containing atoms %d %d %d\n",atoms[0].serial(),atoms[1].serial(),atoms[2].serial());
Expand Down
5 changes: 2 additions & 3 deletions src/colvar/Position.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,9 @@ class Position : public Colvar {
public:
static void registerKeywords( Keywords& keys );
explicit Position(const ActionOptions&);
static void parseAtomList( const int& num, std::vector<AtomNumber>& t, ActionAtomistic* aa );
// active methods:
void calculate() override;
MULTICOLVAR_SETTINGS(multiColvars::plainOrScaled);
MULTICOLVAR_DEFAULT(multiColvars::plainOrScaled);
};

typedef ColvarShortcut<Position> PositionShortcut;
Expand Down Expand Up @@ -152,7 +151,7 @@ Position::Position(const ActionOptions&ao):
requestAtoms(atoms);
}

void Position::parseAtomList( const int& num, std::vector<AtomNumber>& t, ActionAtomistic* aa ) {
void Position::parseAtomList(int const num, std::vector<AtomNumber>& t, ActionAtomistic* aa ) {
aa->parseAtomList("ATOM",num,t);
if( t.size()==1 ) aa->log.printf(" for atom %d\n",t[0].serial());
else if( num<0 || t.size()!=0 ) aa->error("Number of specified atoms should be 1");
Expand Down
5 changes: 2 additions & 3 deletions src/colvar/SelectMassCharge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,9 @@ class SelectMassCharge : public Colvar {
public:
static void registerKeywords( Keywords& keys );
explicit SelectMassCharge(const ActionOptions&);
static void parseAtomList( const int& num, std::vector<AtomNumber>& t, ActionAtomistic* aa );
// active methods:
void calculate() override;
MULTICOLVAR_SETTINGS(multiColvars::emptyMode);
MULTICOLVAR_DEFAULT(multiColvars::emptyMode);
};

typedef ColvarShortcut<SelectMassCharge> MQShortcut;
Expand Down Expand Up @@ -119,7 +118,7 @@ SelectMassCharge::SelectMassCharge(const ActionOptions&ao):
requestAtoms(atoms);
}

void SelectMassCharge::parseAtomList( const int& num, std::vector<AtomNumber>& t, ActionAtomistic* aa ) {
void SelectMassCharge::parseAtomList( int const num, std::vector<AtomNumber>& t, ActionAtomistic* aa ) {
aa->parseAtomList("ATOM",num,t);
if( t.size()==1 ) aa->log.printf(" for atom %d\n",t[0].serial());
else if( num<0 || t.size()!=0 ) aa->error("Number of specified atoms should be 1");
Expand Down
5 changes: 2 additions & 3 deletions src/colvar/Torsion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,13 @@ class Torsion : public Colvar {
std::vector<Tensor> virial;
public:
explicit Torsion(const ActionOptions&);
static void parseAtomList( const int& num, std::vector<AtomNumber>& t, ActionAtomistic* aa );
// active methods:
void calculate() override;
static void registerKeywords(Keywords& keys);
enum class torsionModes {
torsion,cosine
};
MULTICOLVAR_SETTINGS(torsionModes);
MULTICOLVAR_DEFAULT(torsionModes);
};

typedef ColvarShortcut<Torsion> TorsionShortcut;
Expand Down Expand Up @@ -183,7 +182,7 @@ Torsion::Torsion(const ActionOptions&ao):
requestAtoms(atoms);
}

void Torsion::parseAtomList( const int& num, std::vector<AtomNumber>& t, ActionAtomistic* aa ) {
void Torsion::parseAtomList( int const num, std::vector<AtomNumber>& t, ActionAtomistic* aa ) {
std::vector<AtomNumber> v1,v2,axis;
aa->parseAtomList("ATOMS",num,t);
aa->parseAtomList("VECTORA",num,v1);
Expand Down
2 changes: 1 addition & 1 deletion src/crystdistrib/Quaternion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class Quaternion : public Colvar {

// active methods:
void calculate() override;
MULTICOLVAR_SETTINGS(::PLMD::colvar::multiColvars::emptyMode);
MULTICOLVAR_DEFAULT(::PLMD::colvar::multiColvars::emptyMode);
};

typedef colvar::ColvarShortcut<Quaternion> QuaternionShortcut;
Expand Down

0 comments on commit 7957a2e

Please sign in to comment.