Skip to content

Commit

Permalink
added "add-braces"
Browse files Browse the repository at this point in the history
  • Loading branch information
Iximiel committed Oct 1, 2024
1 parent 68cd27b commit ebcb1cf
Show file tree
Hide file tree
Showing 169 changed files with 4,945 additions and 2,489 deletions.
3 changes: 2 additions & 1 deletion .astyle.options
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# long options can be written without the preceding '--'
suffix=none #was "-n"
indent=spaces=2
break-one-line-headers #"add-braces" is too aggressive, this has the same effect, but does not add braces
break-one-line-headers
add-braces

# old options
#suffix=none
Expand Down
39 changes: 26 additions & 13 deletions src/adjmat/ActionWithInputMatrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,29 +43,36 @@ ActionWithInputMatrix::ActionWithInputMatrix(const ActionOptions& ao):
matsums=true;
if( keywords.exists("MATRIX") ) {
std::vector<AtomNumber> fake_atoms;
if( !parseMultiColvarAtomList("MATRIX",-1,fake_atoms ) )
if( !parseMultiColvarAtomList("MATRIX",-1,fake_atoms ) ) {
error("unable to interpret input matrix");
if( mybasemulticolvars.size()!=1 )
}
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 )
if( mymatrix ) {
break ;
}
}
if( !mymatrix )
if( !mymatrix ) {
error( mybasemulticolvars[0]->getLabel() + " does not calculate an adjacency matrix");
}

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

Expand All @@ -86,8 +93,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 ) )
if( !mymatrix->matrixElementIsActive( i, j ) ) {
return 0;
}
unsigned myelem = mymatrix->getStoreIndexFromMatrixIndices( i, j );

// unsigned vi; double df;
Expand All @@ -100,8 +108,9 @@ void ActionWithInputMatrix::getInputData( const unsigned& ind, const bool& norme
std::vector<double> tvals( mymatrix->getNumberOfComponents() );
orient0.assign(orient0.size(),0);
for(unsigned i=0; i<mymatrix->getNumberOfColumns(); ++i) {
if( mymatrix->undirectedGraph() && ind==i )
if( mymatrix->undirectedGraph() && ind==i ) {
continue;
}
orient0[1]+=retrieveConnectionValue( ind, i, tvals );
}
orient0[0]=1.0;
Expand All @@ -111,8 +120,9 @@ void ActionWithInputMatrix::getInputData( const unsigned& ind, const bool& norme
}

void ActionWithInputMatrix::addConnectionDerivatives( const unsigned& i, const unsigned& j, MultiValue& myvals, MultiValue& myvout ) const {
if( !mymatrix->matrixElementIsActive( i, j ) )
if( !mymatrix->matrixElementIsActive( i, j ) ) {
return;
}
unsigned myelem = mymatrix->getStoreIndexFromMatrixIndices( i, j );
// Get derivatives and add
mymatrix->retrieveDerivatives( myelem, false, myvals );
Expand All @@ -131,8 +141,9 @@ 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 )
if( mymatrix->undirectedGraph() && ind==i ) {
continue;
}
addConnectionDerivatives( ind, i, myvals, myder );
}
myder.updateDynamicList();
Expand All @@ -143,14 +154,16 @@ MultiValue& ActionWithInputMatrix::getInputDerivatives( const unsigned& ind, con

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

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

Expand Down
42 changes: 28 additions & 14 deletions src/adjmat/AdjacencyMatrixBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,23 @@ void AdjacencyMatrixBase::parseConnectionDescriptions( const std::string& key, c
if( !multiple ) {
sw.resize(1);
parse(key,sw[0]);
if(sw[0].length()==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 ) )
if( !parseNumbered(key, i, input ) ) {
break;
}
sw.push_back( input );
}
}
setupConnector( connect_id, 0, 0, sw );
} else {
if( multiple )
if( multiple ) {
error("keyword " + key + " does not work with multiple input strings");
}
unsigned nr, nc;
if( nrow_t==0 ) {
nr=nc=getNumberOfNodeTypes();
Expand Down Expand Up @@ -99,30 +102,34 @@ void AdjacencyMatrixBase::parseConnectionDescriptions( const std::string& key, c
}

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

unsigned nq = mybasemulticolvars[0]->getNumberOfQuantities();
for(unsigned i=1; i<mybasemulticolvars.size(); ++i) {
if( mybasemulticolvars[i]->getNumberOfQuantities()!=nq )
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 )
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] )
if( ablocks[0][i]!=ablocks[1][i] ) {
allsame=false;
}
}
}

Expand All @@ -138,8 +145,9 @@ void AdjacencyMatrixBase::retrieveTypeDimensions( unsigned& nrows, unsigned& nco
break;
}
}
if( !found )
if( !found ) {
types.push_back( atom_lab[ablocks[0][i]].first );
}
}
ntype=0;
nrows=ncols=types.size();
Expand All @@ -154,8 +162,9 @@ void AdjacencyMatrixBase::retrieveTypeDimensions( unsigned& nrows, unsigned& nco
break;
}
}
if( !found )
if( !found ) {
types.push_back( atom_lab[ablocks[0][i]].first );
}
}
nrows=ntype=types.size();
for(unsigned i=0; i<ablocks[1].size(); ++i) {
Expand All @@ -166,23 +175,26 @@ void AdjacencyMatrixBase::retrieveTypeDimensions( unsigned& nrows, unsigned& nco
break;
}
}
if( !found )
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
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() )
if( symmetric && ablocks[0].size()==ablocks[1].size() ) {
param="SYMMETRIC";
}
if( !symmetric ) {
bool usehbonds=( ablocks[0].size()==ablocks[1].size() );
if( usehbonds ) {
Expand All @@ -192,8 +204,9 @@ void AdjacencyMatrixBase::finishMatrixSetup( const bool& symmetric, const std::v
break;
}
}
if( usehbonds )
if( usehbonds ) {
param="HBONDS";
}
}
}

Expand Down Expand Up @@ -230,8 +243,9 @@ void AdjacencyMatrixBase::recalculateMatrixElement( const unsigned& myelem, Mult
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) )
if( !taskIsCurrentlyActive(k) ) {
continue;
}
performTask( k, getTaskCode(k), myvals ); // This may not accumulate as we would like GAT
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/adjmat/AdjacencyMatrixBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,9 @@ AdjacencyMatrixVessel* AdjacencyMatrixBase::getAdjacencyVessel() {

inline
unsigned AdjacencyMatrixBase::getBaseColvarNumber( const unsigned& inum ) const {
if( atom_lab[inum].first>0 )
if( atom_lab[inum].first>0 ) {
return atom_lab[inum].first-1;
}
return 0;
}

Expand Down
45 changes: 30 additions & 15 deletions src/adjmat/AdjacencyMatrixVessel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,15 @@ AdjacencyMatrixVessel::AdjacencyMatrixVessel( const vesselbase::VesselOptions& d
plumed_assert( function );
parseFlag("SYMMETRIC",symmetric);
parseFlag("HBONDS",hbonds);
if( symmetric && hbonds )
if( symmetric && hbonds ) {
error("matrix should be either symmetric or hbonds");
if( symmetric && function->ablocks[0].size()!=function->ablocks[1].size() )
}
if( symmetric && function->ablocks[0].size()!=function->ablocks[1].size() ) {
error("matrix is supposed to be symmetric but nrows!=ncols");
if( hbonds && function->ablocks[0].size()!=function->ablocks[1].size() )
}
if( hbonds && function->ablocks[0].size()!=function->ablocks[1].size() ) {
error("matrix is supposed to be hbonds but nrows!=ncols");
}
}

bool AdjacencyMatrixVessel::isSymmetric() const {
Expand All @@ -68,16 +71,19 @@ bool AdjacencyMatrixVessel::matrixElementIsActive( const unsigned& ielem, const
}

unsigned AdjacencyMatrixVessel::getStoreIndexFromMatrixIndices( const unsigned& ielem, const unsigned& jelem ) const {
if( !symmetric && !hbonds )
if( !symmetric && !hbonds ) {
return (function->ablocks[1].size())*ielem + jelem;
}
if( !symmetric ) {
plumed_dbg_assert( ielem!=jelem );
if( jelem<ielem )
if( jelem<ielem ) {
return (function->ablocks[1].size()-1)*ielem + jelem;
}
return (function->ablocks[1].size()-1)*ielem + jelem - 1;
}
if( ielem>jelem )
if( ielem>jelem ) {
return 0.5*ielem*(ielem-1)+jelem;
}
return 0.5*jelem*(jelem-1) + ielem;
}

Expand All @@ -101,40 +107,46 @@ void AdjacencyMatrixVessel::retrieveMatrix( DynamicList<unsigned>& myactive_elem
std::vector<double> vals( getNumberOfComponents() );
for(unsigned i=0; i<getNumberOfStoredValues(); ++i) {
retrieveSequentialValue( i, false, vals );
if( vals[0]<epsilon )
if( vals[0]<epsilon ) {
continue ;
}

myactive_elements.activate(i);
unsigned j, k;
getMatrixIndices( function->getPositionInFullTaskList(i), k, j );

if( symmetric )
if( symmetric ) {
mymatrix(k,j)=mymatrix(j,k)=vals[0]*vals[1];
else
}
else {
mymatrix(k,j)=vals[0]*vals[1];
}
}
myactive_elements.updateActiveMembers();
}

void AdjacencyMatrixVessel::retrieveAdjacencyLists( std::vector<unsigned>& nneigh, Matrix<unsigned>& adj_list ) {
plumed_dbg_assert( undirectedGraph() );
// Currently everything has zero neighbors
for(unsigned i=0; i<nneigh.size(); ++i)
for(unsigned i=0; i<nneigh.size(); ++i) {
nneigh[i]=0;
}

// And set up the adjacency list
std::vector<double> myvals( getNumberOfComponents() );
for(unsigned i=0; i<getNumberOfStoredValues(); ++i) {
// Check if atoms are connected
retrieveSequentialValue( i, false, myvals );
if( myvals[0]<epsilon || myvals[1]<epsilon )
if( myvals[0]<epsilon || myvals[1]<epsilon ) {
continue ;
}

unsigned j, k;
getMatrixIndices( function->getPositionInFullTaskList(i), k, j );

if( nneigh[j]>=adj_list.ncols() || nneigh[k]>=adj_list.ncols() )
if( nneigh[j]>=adj_list.ncols() || nneigh[k]>=adj_list.ncols() ) {
error("adjacency lists are not large enough, increase maxconnections");
}
// Store if atoms are connected
// unsigned j, k; getMatrixIndices( i, k, j );
adj_list(k,nneigh[k])=j;
Expand All @@ -148,23 +160,26 @@ void AdjacencyMatrixVessel::retrieveEdgeList( unsigned& nedge, std::vector<std::
plumed_dbg_assert( undirectedGraph() );
nedge=0;
std::vector<double> myvals( getNumberOfComponents() );
if( getNumberOfStoredValues()>edge_list.size() )
if( getNumberOfStoredValues()>edge_list.size() ) {
error("adjacency lists are not large enough, increase maxconnections");
}

for(unsigned i=0; i<getNumberOfStoredValues(); ++i) {
// Check if atoms are connected
retrieveSequentialValue( i, false, myvals );
if( myvals[0]<epsilon || myvals[1]<epsilon )
if( myvals[0]<epsilon || myvals[1]<epsilon ) {
continue ;
}

getMatrixIndices( function->getPositionInFullTaskList(i), edge_list[nedge].first, edge_list[nedge].second );
nedge++;
}
}

bool AdjacencyMatrixVessel::nodesAreConnected( const unsigned& iatom, const unsigned& jatom ) const {
if( !matrixElementIsActive( iatom, jatom ) )
if( !matrixElementIsActive( iatom, jatom ) ) {
return false;
}
unsigned ind=getStoreIndexFromMatrixIndices( iatom, jatom );

std::vector<double> myvals( getNumberOfComponents() );
Expand Down
Loading

0 comments on commit ebcb1cf

Please sign in to comment.