From 7957a2eefd030a1eb4fef301b9006679b267f6d2 Mon Sep 17 00:00:00 2001 From: Daniele Rapetti <5535617+Iximiel@users.noreply.github.com> Date: Wed, 20 Nov 2024 08:48:50 +0100 Subject: [PATCH] parseAtomList is a MULTICOLVAR needed function --- src/colvar/Angle.cpp | 5 ++--- src/colvar/DihedralCorrelation.cpp | 5 ++--- src/colvar/Dipole.cpp | 6 ++--- src/colvar/Distance.cpp | 5 ++--- src/colvar/MultiColvarTemplate.h | 36 ++++++++++++++++++++---------- src/colvar/Plane.cpp | 6 ++--- src/colvar/Position.cpp | 5 ++--- src/colvar/SelectMassCharge.cpp | 5 ++--- src/colvar/Torsion.cpp | 5 ++--- src/crystdistrib/Quaternion.cpp | 2 +- 10 files changed, 41 insertions(+), 39 deletions(-) diff --git a/src/colvar/Angle.cpp b/src/colvar/Angle.cpp index 0a6579cd00..ac005ac0fa 100644 --- a/src/colvar/Angle.cpp +++ b/src/colvar/Angle.cpp @@ -104,12 +104,11 @@ class Angle : public Colvar { std::vector > derivs; std::vector 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& t, ActionAtomistic* aa ); }; @@ -126,7 +125,7 @@ void Angle::registerKeywords( Keywords& keys ) { keys.setValueDescription("the ANGLE involving these atoms"); } -void Angle::parseAtomList( const int& num, std::vector& atoms, ActionAtomistic* aa ) { +void Angle::parseAtomList( int const num, std::vector& 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()); diff --git a/src/colvar/DihedralCorrelation.cpp b/src/colvar/DihedralCorrelation.cpp index 28ff787af9..913e661594 100644 --- a/src/colvar/DihedralCorrelation.cpp +++ b/src/colvar/DihedralCorrelation.cpp @@ -68,10 +68,9 @@ class DihedralCorrelation : public Colvar { std::vector > derivs; std::vector 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& t, ActionAtomistic* aa ); void calculate() override; }; @@ -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& t, ActionAtomistic* aa ) { +void DihedralCorrelation::parseAtomList( int const num, std::vector& 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 ) { diff --git a/src/colvar/Dipole.cpp b/src/colvar/Dipole.cpp index 10873ca79c..a42de3f65f 100644 --- a/src/colvar/Dipole.cpp +++ b/src/colvar/Dipole.cpp @@ -90,11 +90,9 @@ class Dipole : public Colvar { Value* valuez=nullptr; public: explicit Dipole(const ActionOptions&); - static void parseAtomList( const int& num, std::vector& 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& masses, @@ -149,7 +147,7 @@ Dipole::Dipole(const ActionOptions&ao): requestAtoms(ga_lista); } -void Dipole::parseAtomList( const int& num, std::vector& t, ActionAtomistic* aa ) { +void Dipole::parseAtomList( int num, std::vector& t, ActionAtomistic* aa ) { aa->parseAtomList("GROUP",num,t); if( t.size()>0 ) { aa->log.printf(" of %u atoms\n",static_cast(t.size())); diff --git a/src/colvar/Distance.cpp b/src/colvar/Distance.cpp index 7145707e36..6f5ad0e551 100644 --- a/src/colvar/Distance.cpp +++ b/src/colvar/Distance.cpp @@ -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& t, ActionAtomistic* aa ); // active methods: void calculate() override; - MULTICOLVAR_SETTINGS(multiColvars::scaledComponents); + MULTICOLVAR_DEFAULT(multiColvars::scaledComponents); }; typedef ColvarShortcut DistanceShortcut; @@ -199,7 +198,7 @@ Distance::Distance(const ActionOptions&ao): requestAtoms(atoms); } -void Distance::parseAtomList( const int& num, std::vector& t, ActionAtomistic* aa ) { +void Distance::parseAtomList( int const num, std::vector& 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()); } diff --git a/src/colvar/MultiColvarTemplate.h b/src/colvar/MultiColvarTemplate.h index 578aedcbc7..998ae5cc77 100644 --- a/src/colvar/MultiColvarTemplate.h +++ b/src/colvar/MultiColvarTemplate.h @@ -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& t, ActionAtomistic* aa ); \ + static Modetype getModeAndSetupValues( ActionWithValue* av ) #define MULTICOLVAR_SETTINGS_CALCULATE_CONST() static void calculateCV( Modetype mode, \ const std::vector& masses, \ const std::vector& charges, \ @@ -54,8 +55,7 @@ enum class scaledComponents { std::vector& 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() @@ -106,34 +106,46 @@ MultiColvarTemplate::MultiColvarTemplate(const ActionOptions&ao): std::vector 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 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& t, ActionAtomistic* aa ); - // active methods: void calculate() override; - MULTICOLVAR_SETTINGS(multiColvars::emptyMode); + MULTICOLVAR_DEFAULT(multiColvars::emptyMode); }; typedef ColvarShortcut PlaneShortcut; @@ -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& atoms, ActionAtomistic* aa ) { +void Plane::parseAtomList( int const num, std::vector& 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()); diff --git a/src/colvar/Position.cpp b/src/colvar/Position.cpp index b9cf37ce10..53dd180bbb 100644 --- a/src/colvar/Position.cpp +++ b/src/colvar/Position.cpp @@ -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& t, ActionAtomistic* aa ); // active methods: void calculate() override; - MULTICOLVAR_SETTINGS(multiColvars::plainOrScaled); + MULTICOLVAR_DEFAULT(multiColvars::plainOrScaled); }; typedef ColvarShortcut PositionShortcut; @@ -152,7 +151,7 @@ Position::Position(const ActionOptions&ao): requestAtoms(atoms); } -void Position::parseAtomList( const int& num, std::vector& t, ActionAtomistic* aa ) { +void Position::parseAtomList(int const num, std::vector& 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"); diff --git a/src/colvar/SelectMassCharge.cpp b/src/colvar/SelectMassCharge.cpp index 53039e9f26..e3e98cccac 100644 --- a/src/colvar/SelectMassCharge.cpp +++ b/src/colvar/SelectMassCharge.cpp @@ -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& t, ActionAtomistic* aa ); // active methods: void calculate() override; - MULTICOLVAR_SETTINGS(multiColvars::emptyMode); + MULTICOLVAR_DEFAULT(multiColvars::emptyMode); }; typedef ColvarShortcut MQShortcut; @@ -119,7 +118,7 @@ SelectMassCharge::SelectMassCharge(const ActionOptions&ao): requestAtoms(atoms); } -void SelectMassCharge::parseAtomList( const int& num, std::vector& t, ActionAtomistic* aa ) { +void SelectMassCharge::parseAtomList( int const num, std::vector& 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"); diff --git a/src/colvar/Torsion.cpp b/src/colvar/Torsion.cpp index e22848390d..2efc5f2b2e 100644 --- a/src/colvar/Torsion.cpp +++ b/src/colvar/Torsion.cpp @@ -115,14 +115,13 @@ class Torsion : public Colvar { std::vector virial; public: explicit Torsion(const ActionOptions&); - static void parseAtomList( const int& num, std::vector& 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 TorsionShortcut; @@ -183,7 +182,7 @@ Torsion::Torsion(const ActionOptions&ao): requestAtoms(atoms); } -void Torsion::parseAtomList( const int& num, std::vector& t, ActionAtomistic* aa ) { +void Torsion::parseAtomList( int const num, std::vector& t, ActionAtomistic* aa ) { std::vector v1,v2,axis; aa->parseAtomList("ATOMS",num,t); aa->parseAtomList("VECTORA",num,v1); diff --git a/src/crystdistrib/Quaternion.cpp b/src/crystdistrib/Quaternion.cpp index 574ef3524c..4029abd40d 100644 --- a/src/crystdistrib/Quaternion.cpp +++ b/src/crystdistrib/Quaternion.cpp @@ -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 QuaternionShortcut;