Skip to content

Commit

Permalink
restyle v2.9
Browse files Browse the repository at this point in the history
  • Loading branch information
Iximiel committed Oct 4, 2024
1 parent 91e9329 commit 0ddbdcb
Show file tree
Hide file tree
Showing 566 changed files with 26,842 additions and 13,041 deletions.
14 changes: 13 additions & 1 deletion .astyle.options
Original file line number Diff line number Diff line change
@@ -1 +1,13 @@
-n --indent=spaces=2 --keep-one-line-statements --keep-one-line-blocks
# long options can be written without the preceding '--'
suffix=none #equivalent to "-n"
style=attach
add-braces
indent=spaces=2
break-one-line-headers

# old options
#suffix=none
#indent=spaces=2
#keep-one-line-statements
#keep-one-line-blocks
# end old options
66 changes: 47 additions & 19 deletions src/adjmat/ActionWithInputMatrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,25 +38,38 @@ void ActionWithInputMatrix::registerKeywords( Keywords& keys ) {
ActionWithInputMatrix::ActionWithInputMatrix(const ActionOptions& ao):
Action(ao),
MultiColvarBase(ao),
mymatrix(NULL)
{
mymatrix(NULL) {
matsums=true;
if( keywords.exists("MATRIX") ) {
std::vector<AtomNumber> fake_atoms;
if( !parseMultiColvarAtomList("MATRIX",-1,fake_atoms ) ) error("unable to interpret input matrix");
if( mybasemulticolvars.size()!=1 ) error("should be exactly one matrix input");
if( !parseMultiColvarAtomList("MATRIX",-1,fake_atoms ) ) {
error("unable to interpret input matrix");
}
if( mybasemulticolvars.size()!=1 ) {
error("should be exactly one matrix input");
}

// Retrieve the adjacency matrix of interest
for(unsigned i=0; i<mybasemulticolvars[0]->getNumberOfVessels(); ++i) {
mymatrix = dynamic_cast<AdjacencyMatrixVessel*>( mybasemulticolvars[0]->getPntrToVessel(i) );
if( mymatrix ) break ;
if( mymatrix ) {
break ;
}
}
if( !mymatrix ) {
error( mybasemulticolvars[0]->getLabel() + " does not calculate an adjacency matrix");
}
if( !mymatrix ) error( mybasemulticolvars[0]->getLabel() + " does not calculate an adjacency matrix");

atom_lab.resize(0); unsigned nnodes; // Delete all the atom labels that have been created
if( mymatrix->undirectedGraph() ) nnodes = (mymatrix->function)->ablocks[0].size();
else nnodes = (mymatrix->function)->ablocks[0].size() + (mymatrix->function)->ablocks[1].size();
for(unsigned i=0; i<nnodes; ++i) atom_lab.push_back( std::pair<unsigned,unsigned>( 1, i ) );
atom_lab.resize(0);
unsigned nnodes; // Delete all the atom labels that have been created
if( mymatrix->undirectedGraph() ) {
nnodes = (mymatrix->function)->ablocks[0].size();
} else {
nnodes = (mymatrix->function)->ablocks[0].size() + (mymatrix->function)->ablocks[1].size();
}
for(unsigned i=0; i<nnodes; ++i) {
atom_lab.push_back( std::pair<unsigned,unsigned>( 1, i ) );
}
}
}

Expand All @@ -77,7 +90,9 @@ AtomNumber ActionWithInputMatrix::getAbsoluteIndexOfCentralAtom(const unsigned&
}

double ActionWithInputMatrix::retrieveConnectionValue( const unsigned& i, const unsigned& j, std::vector<double>& vals ) const {
if( !mymatrix->matrixElementIsActive( i, j ) ) return 0;
if( !mymatrix->matrixElementIsActive( i, j ) ) {
return 0;
}
unsigned myelem = mymatrix->getStoreIndexFromMatrixIndices( i, j );

// unsigned vi; double df;
Expand All @@ -87,18 +102,24 @@ double ActionWithInputMatrix::retrieveConnectionValue( const unsigned& i, const

void ActionWithInputMatrix::getInputData( const unsigned& ind, const bool& normed, const multicolvar::AtomValuePack& myatoms, std::vector<double>& orient0 ) const {
if( (mymatrix->function)->mybasemulticolvars.size()==0 ) {
std::vector<double> tvals( mymatrix->getNumberOfComponents() ); orient0.assign(orient0.size(),0);
std::vector<double> tvals( mymatrix->getNumberOfComponents() );
orient0.assign(orient0.size(),0);
for(unsigned i=0; i<mymatrix->getNumberOfColumns(); ++i) {
if( mymatrix->undirectedGraph() && ind==i ) continue;
if( mymatrix->undirectedGraph() && ind==i ) {
continue;
}
orient0[1]+=retrieveConnectionValue( ind, i, tvals );
}
orient0[0]=1.0; return;
orient0[0]=1.0;
return;
}
(mymatrix->function)->getInputData( ind, normed, myatoms, orient0 );
}

void ActionWithInputMatrix::addConnectionDerivatives( const unsigned& i, const unsigned& j, MultiValue& myvals, MultiValue& myvout ) const {
if( !mymatrix->matrixElementIsActive( i, j ) ) return;
if( !mymatrix->matrixElementIsActive( i, j ) ) {
return;
}
unsigned myelem = mymatrix->getStoreIndexFromMatrixIndices( i, j );
// Get derivatives and add
mymatrix->retrieveDerivatives( myelem, false, myvals );
Expand All @@ -117,22 +138,29 @@ MultiValue& ActionWithInputMatrix::getInputDerivatives( const unsigned& ind, con
myder.clearAll();
MultiValue myvals( (mymatrix->function)->getNumberOfQuantities(), (mymatrix->function)->getNumberOfDerivatives() );
for(unsigned i=0; i<mymatrix->getNumberOfColumns(); ++i) {
if( mymatrix->undirectedGraph() && ind==i ) continue;
if( mymatrix->undirectedGraph() && ind==i ) {
continue;
}
addConnectionDerivatives( ind, i, myvals, myder );
}
myder.updateDynamicList(); return myder;
myder.updateDynamicList();
return myder;
}
return (mymatrix->function)->getInputDerivatives( ind, normed, myatoms );
}

unsigned ActionWithInputMatrix::getNumberOfNodeTypes() const {
unsigned size = (mymatrix->function)->mybasemulticolvars.size();
if( size==0 ) return 1;
if( size==0 ) {
return 1;
}
return size;
}

unsigned ActionWithInputMatrix::getNumberOfQuantities() const {
if( (mymatrix->function)->mybasemulticolvars.size()==0 ) return 2;
if( (mymatrix->function)->mybasemulticolvars.size()==0 ) {
return 2;
}
return (mymatrix->function)->mybasemulticolvars[0]->getNumberOfQuantities();
}

Expand Down
8 changes: 6 additions & 2 deletions src/adjmat/ActionWithInputMatrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,16 @@ class ActionWithInputMatrix : public multicolvar::MultiColvarBase {
unsigned getNumberOfDerivatives() override;
/// Get the number of rows/cols in the adjacency matrix vessel
virtual unsigned getNumberOfNodes() const;
bool isPeriodic() override { return false; }
bool isPeriodic() override {
return false;
}
unsigned getNumberOfQuantities() const override;
///
AtomNumber getAbsoluteIndexOfCentralAtom(const unsigned& i) const override;
/// No loop over tasks for ActionWithInputMatrix
double compute( const unsigned& tindex, multicolvar::AtomValuePack& myatoms ) const override { plumed_error(); }
double compute( const unsigned& tindex, multicolvar::AtomValuePack& myatoms ) const override {
plumed_error();
}
///
Vector getPositionOfAtomForLinkCells( const unsigned& iatom ) const override;
};
Expand Down
120 changes: 87 additions & 33 deletions src/adjmat/AdjacencyMatrixBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,40 +31,48 @@ namespace adjmat {

void AdjacencyMatrixBase::registerKeywords( Keywords& keys ) {
multicolvar::MultiColvarBase::registerKeywords( keys );
keys.remove("LOWMEM"); keys.use("HIGHMEM");
keys.remove("LOWMEM");
keys.use("HIGHMEM");
}

AdjacencyMatrixBase::AdjacencyMatrixBase(const ActionOptions& ao):
Action(ao),
MultiColvarBase(ao),
connect_id(0),
no_third_dim_accum(true),
mat(NULL)
{
mat(NULL) {
log<<" Bibliography "<<plumed.cite("Tribello, Giberti, Sosso, Salvalaglio and Parrinello, J. Chem. Theory Comput. 13, 1317 (2017)")<<"\n";
}

void AdjacencyMatrixBase::parseConnectionDescriptions( const std::string& key, const bool& multiple, const unsigned& nrow_t ) {
if( getNumberOfNodeTypes()==1 || (getNumberOfNodeTypes()==2 && nrow_t==1) ) {
std::vector<std::string> sw;
if( !multiple ) {
sw.resize(1); parse(key,sw[0]);
if(sw[0].length()==0) error("could not find " + key + " keyword");
sw.resize(1);
parse(key,sw[0]);
if(sw[0].length()==0) {
error("could not find " + key + " keyword");
}
} else {
std::string input;
for(int i=1;; i++) {
if( !parseNumbered(key, i, input ) ) break;
if( !parseNumbered(key, i, input ) ) {
break;
}
sw.push_back( input );
}
}
setupConnector( connect_id, 0, 0, sw );
} else {
if( multiple ) error("keyword " + key + " does not work with multiple input strings");
if( multiple ) {
error("keyword " + key + " does not work with multiple input strings");
}
unsigned nr, nc;
if( nrow_t==0 ) {
nr=nc=getNumberOfNodeTypes();
} else {
nr=nrow_t; nc = getNumberOfNodeTypes() - nr;
nr=nrow_t;
nc = getNumberOfNodeTypes() - nr;
}
for(unsigned i=0; i<nr; ++i) {
// Retrieve the base number
Expand All @@ -78,9 +86,11 @@ void AdjacencyMatrixBase::parseConnectionDescriptions( const std::string& key, c
}

for(unsigned j=i; j<nc; ++j) {
std::vector<std::string> sw(1); parseNumbered(key,ibase+j+1,sw[0]);
std::vector<std::string> sw(1);
parseNumbered(key,ibase+j+1,sw[0]);
if(sw[0].length()==0) {
std::string num; Tools::convert(ibase+j+1,num);
std::string num;
Tools::convert(ibase+j+1,num);
error("could not find " + key + num + " keyword. Need one " + key + " keyword for each distinct base-multicolvar-pair type");
}
setupConnector( connect_id, i, j, sw );
Expand All @@ -91,89 +101,130 @@ void AdjacencyMatrixBase::parseConnectionDescriptions( const std::string& key, c
}

unsigned AdjacencyMatrixBase::getSizeOfInputVectors() const {
if( mybasemulticolvars.size()==0 ) return 2;
if( mybasemulticolvars.size()==0 ) {
return 2;
}

unsigned nq = mybasemulticolvars[0]->getNumberOfQuantities();
for(unsigned i=1; i<mybasemulticolvars.size(); ++i) {
if( mybasemulticolvars[i]->getNumberOfQuantities()!=nq ) error("mismatch between vectors in base colvars");
if( mybasemulticolvars[i]->getNumberOfQuantities()!=nq ) {
error("mismatch between vectors in base colvars");
}
}
return nq;
}

unsigned AdjacencyMatrixBase::getNumberOfNodeTypes() const {
unsigned size=mybasemulticolvars.size();
if( size==0 ) return 1;
if( size==0 ) {
return 1;
}
return size;
}

void AdjacencyMatrixBase::retrieveTypeDimensions( unsigned& nrows, unsigned& ncols, unsigned& ntype ) const {
bool allsame=(ablocks[0].size()==ablocks[1].size());
if( allsame ) {
for(unsigned i=0; i<ablocks[0].size(); ++i) {
if( ablocks[0][i]!=ablocks[1][i] ) allsame=false;
if( ablocks[0][i]!=ablocks[1][i] ) {
allsame=false;
}
}
}

if( allsame ) {
std::vector<unsigned> types(1); types[0]=atom_lab[ablocks[0][0]].first;
std::vector<unsigned> types(1);
types[0]=atom_lab[ablocks[0][0]].first;
for(unsigned i=1; i<ablocks[0].size(); ++i) {
bool found = false;
for(unsigned j=0; j<types.size(); ++j) {
if( atom_lab[ablocks[0][i]].first==types[j] ) { found=true; break; }
if( atom_lab[ablocks[0][i]].first==types[j] ) {
found=true;
break;
}
}
if( !found ) {
types.push_back( atom_lab[ablocks[0][i]].first );
}
if( !found ) types.push_back( atom_lab[ablocks[0][i]].first );
}
ntype=0; nrows=ncols=types.size();
ntype=0;
nrows=ncols=types.size();
} else {
std::vector<unsigned> types(1); types[0]=atom_lab[ablocks[0][0]].first;
std::vector<unsigned> types(1);
types[0]=atom_lab[ablocks[0][0]].first;
for(unsigned i=1; i<ablocks[0].size(); ++i) {
bool found = false;
for(unsigned j=0; j<types.size(); ++j) {
if( atom_lab[ablocks[0][i]].first==types[j] ) { found=true; break; }
if( atom_lab[ablocks[0][i]].first==types[j] ) {
found=true;
break;
}
}
if( !found ) {
types.push_back( atom_lab[ablocks[0][i]].first );
}
if( !found ) types.push_back( atom_lab[ablocks[0][i]].first );
}
nrows=ntype=types.size();
for(unsigned i=0; i<ablocks[1].size(); ++i) {
bool found = false;
for(unsigned j=0; j<types.size(); ++j) {
if( atom_lab[ablocks[1][i]].first==types[j] ) { found=true; break; }
if( atom_lab[ablocks[1][i]].first==types[j] ) {
found=true;
break;
}
}
if( !found ) {
types.push_back( atom_lab[ablocks[1][i]].first );
}
if( !found ) types.push_back( atom_lab[ablocks[1][i]].first );
}
if( types.size()==nrows ) { ntype=0; ncols=1; plumed_assert( types.size()==1 && atom_lab[ablocks[0][0]].first==0 ); }
else ncols = types.size() - ntype;
if( types.size()==nrows ) {
ntype=0;
ncols=1;
plumed_assert( types.size()==1 && atom_lab[ablocks[0][0]].first==0 );
} else {
ncols = types.size() - ntype;
}
}
}

void AdjacencyMatrixBase::finishMatrixSetup( const bool& symmetric, const std::vector<AtomNumber>& all_atoms ) {
std::string param;
if( symmetric && ablocks[0].size()==ablocks[1].size() ) param="SYMMETRIC";
if( symmetric && ablocks[0].size()==ablocks[1].size() ) {
param="SYMMETRIC";
}
if( !symmetric ) {
bool usehbonds=( ablocks[0].size()==ablocks[1].size() );
if( usehbonds ) {
for(unsigned i=0; i<ablocks[0].size(); ++i) {
if( ablocks[0][i]!=ablocks[1][i] ) { usehbonds = false; break; }
if( ablocks[0][i]!=ablocks[1][i] ) {
usehbonds = false;
break;
}
}
if( usehbonds ) {
param="HBONDS";
}
if( usehbonds ) param="HBONDS";
}
}

vesselbase::VesselOptions da("","",0,param,this);
Keywords keys; AdjacencyMatrixVessel::registerKeywords( keys );
Keywords keys;
AdjacencyMatrixVessel::registerKeywords( keys );
vesselbase::VesselOptions da2(da,keys);
auto ves=Tools::make_unique<AdjacencyMatrixVessel>(da2);
addVessel( std::move( ves ) );
setupMultiColvarBase( all_atoms );
}

void AdjacencyMatrixBase::readMaxTwoSpeciesMatrix( const std::string& key0, const std::string& key1, const std::string& key2, const bool& symmetric ) {
std::vector<AtomNumber> all_atoms; readTwoGroups( key0, key1, key2, all_atoms );
std::vector<AtomNumber> all_atoms;
readTwoGroups( key0, key1, key2, all_atoms );
finishMatrixSetup( symmetric, all_atoms );
}

void AdjacencyMatrixBase::readMaxThreeSpeciesMatrix( const std::string& key0, const std::string& key1, const std::string& key2, const std::string& keym, const bool& symmetric ) {
std::vector<AtomNumber> all_atoms; readGroupKeywords( key0, key1, key2, keym, true, symmetric, all_atoms );
std::vector<AtomNumber> all_atoms;
readGroupKeywords( key0, key1, key2, keym, true, symmetric, all_atoms );
finishMatrixSetup( symmetric, all_atoms );
}

Expand All @@ -185,10 +236,13 @@ void AdjacencyMatrixBase::readMaxThreeSpeciesMatrix( const std::string& key0, co
// }

void AdjacencyMatrixBase::recalculateMatrixElement( const unsigned& myelem, MultiValue& myvals ) {
std::vector<unsigned> myatoms; decodeIndexToAtoms( getTaskCode( myelem ), myatoms );
std::vector<unsigned> myatoms;
decodeIndexToAtoms( getTaskCode( myelem ), myatoms );
unsigned i=myatoms[0], j=myatoms[1];
for(unsigned k=bookeeping(i,j).first; k<bookeeping(i,j).second; ++k) {
if( !taskIsCurrentlyActive(k) ) continue;
if( !taskIsCurrentlyActive(k) ) {
continue;
}
performTask( k, getTaskCode(k), myvals ); // This may not accumulate as we would like GAT
}
}
Expand Down
Loading

0 comments on commit 0ddbdcb

Please sign in to comment.