Skip to content

Commit

Permalink
restyled v2.10
Browse files Browse the repository at this point in the history
  • Loading branch information
Iximiel committed Oct 4, 2024
1 parent 473fe65 commit d80912c
Show file tree
Hide file tree
Showing 545 changed files with 34,537 additions and 16,698 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
441 changes: 326 additions & 115 deletions src/adjmat/AdjacencyMatrixBase.cpp

Large diffs are not rendered by default.

23 changes: 17 additions & 6 deletions src/adjmat/AdjacencyMatrixBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ class AdjacencyMatrixBase : public ActionWithMatrix {
public:
static void registerKeywords( Keywords& keys );
explicit AdjacencyMatrixBase(const ActionOptions&);
bool isAdjacencyMatrix() const override { return true; }
bool isAdjacencyMatrix() const override {
return true;
}
unsigned getNumberOfDerivatives() override ;
unsigned getNumberOfColumns() const override;
void prepare() override;
Expand All @@ -72,9 +74,14 @@ Vector AdjacencyMatrixBase::getPosition( const unsigned& indno, MultiValue& myva

inline
void AdjacencyMatrixBase::addAtomDerivatives( const unsigned& indno, const Vector& der, MultiValue& myvals ) const {
if( doNotCalculateDerivatives() ) return;
plumed_dbg_assert( indno<2 ); unsigned index = myvals.getTaskIndex();
if( indno==1 ) index = myvals.getSecondTaskIndex();
if( doNotCalculateDerivatives() ) {
return;
}
plumed_dbg_assert( indno<2 );
unsigned index = myvals.getTaskIndex();
if( indno==1 ) {
index = myvals.getSecondTaskIndex();
}
unsigned w_index = getConstPntrToComponent(0)->getPositionInStream();
myvals.addDerivative( w_index, 3*index+0, der[0] );
myvals.addDerivative( w_index, 3*index+1, der[1] );
Expand All @@ -83,7 +90,9 @@ void AdjacencyMatrixBase::addAtomDerivatives( const unsigned& indno, const Vecto

inline
void AdjacencyMatrixBase::addThirdAtomDerivatives( const unsigned& indno, const Vector& der, MultiValue& myvals ) const {
if( doNotCalculateDerivatives() ) return;
if( doNotCalculateDerivatives() ) {
return;
}
unsigned index = myvals.getIndices()[ indno + myvals.getSplitIndex() ];
unsigned w_index = getConstPntrToComponent(0)->getPositionInStream();
myvals.addDerivative( w_index, 3*index+0, der[0] );
Expand All @@ -93,7 +102,9 @@ void AdjacencyMatrixBase::addThirdAtomDerivatives( const unsigned& indno, const

inline
void AdjacencyMatrixBase::addBoxDerivatives( const Tensor& vir, MultiValue& myvals ) const {
if( doNotCalculateDerivatives() ) return;
if( doNotCalculateDerivatives() ) {
return;
}
unsigned nbase = 3*getNumberOfAtoms();
unsigned w_index = getConstPntrToComponent(0)->getPositionInStream();
myvals.addDerivative( w_index, nbase+0, vir(0,0) );
Expand Down
24 changes: 18 additions & 6 deletions src/adjmat/Bridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,30 @@ void Bridge::registerKeywords(Keywords& keys) {
"group A");
keys.add("optional","SWITCHB","The switchingfunction on the distance between the bridging atoms and the atoms in "
"group B");
keys.needsAction("BRIDGE_MATRIX"); keys.needsAction("SUM");
keys.needsAction("BRIDGE_MATRIX");
keys.needsAction("SUM");
keys.setValueDescription("the number of bridging atoms between the two groups");
}

Bridge::Bridge(const ActionOptions& ao):
Action(ao),
ActionShortcut(ao)
{
ActionShortcut(ao) {
// Need to read in switch
std::string s_inp, sfinput; parse("SWITCH",sfinput); if( sfinput.length()>0 ) s_inp += "SWITCH={" + sfinput +"} ";
std::string sfinputa; parse("SWITCHA",sfinputa); if( sfinputa.length()>0 ) s_inp += "SWITCHA={" + sfinputa +"} ";
std::string sfinputb; parse("SWITCHB",sfinputb); if( sfinputb.length()>0 ) s_inp += "SWITCHB={" + sfinputb +"} ";
std::string s_inp, sfinput;
parse("SWITCH",sfinput);
if( sfinput.length()>0 ) {
s_inp += "SWITCH={" + sfinput +"} ";
}
std::string sfinputa;
parse("SWITCHA",sfinputa);
if( sfinputa.length()>0 ) {
s_inp += "SWITCHA={" + sfinputa +"} ";
}
std::string sfinputb;
parse("SWITCHB",sfinputb);
if( sfinputb.length()>0 ) {
s_inp += "SWITCHB={" + sfinputb +"} ";
}
// Create the matrix object
readInputLine( getShortcutLabel() + "_mat: BRIDGE_MATRIX " + s_inp + convertInputLineToString() );
// Add all the elements of the matrix together
Expand Down
59 changes: 43 additions & 16 deletions src/adjmat/BridgeMatrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,23 +83,37 @@ void BridgeMatrix::registerKeywords( Keywords& keys ) {

BridgeMatrix::BridgeMatrix(const ActionOptions&ao):
Action(ao),
AdjacencyMatrixBase(ao)
{
bool oneswitch; std::string sfinput,errors; parse("SWITCH",sfinput);
AdjacencyMatrixBase(ao) {
bool oneswitch;
std::string sfinput,errors;
parse("SWITCH",sfinput);
if( sfinput.length()>0 ) {
sf1.set(sfinput,errors); oneswitch=true;
if( errors.length()!=0 ) error("problem reading SWITCH keyword : " + errors );
sf1.set(sfinput,errors);
oneswitch=true;
if( errors.length()!=0 ) {
error("problem reading SWITCH keyword : " + errors );
}
sf2.set(sfinput,errors);
if( errors.length()!=0 ) error("problem reading SWITCH keyword : " + errors );
if( errors.length()!=0 ) {
error("problem reading SWITCH keyword : " + errors );
}
} else {
parse("SWITCHA",sfinput);
if(sfinput.length()>0) {
sf1.set(sfinput,errors); oneswitch=false;
if( errors.length()!=0 ) error("problem reading SWITCHA keyword : " + errors );
sfinput.clear(); parse("SWITCHB",sfinput);
if(sfinput.length()==0) error("found SWITCHA keyword without SWITCHB");
sf1.set(sfinput,errors);
oneswitch=false;
if( errors.length()!=0 ) {
error("problem reading SWITCHA keyword : " + errors );
}
sfinput.clear();
parse("SWITCHB",sfinput);
if(sfinput.length()==0) {
error("found SWITCHA keyword without SWITCHB");
}
sf2.set(sfinput,errors);
if( errors.length()!=0 ) error("problem reading SWITCHB keyword : " + errors );
if( errors.length()!=0 ) {
error("problem reading SWITCHB keyword : " + errors );
}
} else {
error("missing definition of switching functions");
}
Expand All @@ -115,12 +129,25 @@ BridgeMatrix::BridgeMatrix(const ActionOptions&ao):
}

double BridgeMatrix::calculateWeight( const Vector& pos1, const Vector& pos2, const unsigned& natoms, MultiValue& myvals ) const {
double tot=0; if( pos2.modulo2()<epsilon ) return 0.0;
double tot=0;
if( pos2.modulo2()<epsilon ) {
return 0.0;
}
for(unsigned i=0; i<natoms; ++i) {
Vector dij= getPosition(i,myvals); double dijm = dij.modulo2();
double dw1, w1=sf1.calculateSqr( dijm, dw1 ); if( dijm<epsilon ) { w1=0.0; dw1=0.0; }
Vector dik=pbcDistance( getPosition(i,myvals), pos2 ); double dikm=dik.modulo2();
double dw2, w2=sf2.calculateSqr( dikm, dw2 ); if( dikm<epsilon ) { w2=0.0; dw2=0.0; }
Vector dij= getPosition(i,myvals);
double dijm = dij.modulo2();
double dw1, w1=sf1.calculateSqr( dijm, dw1 );
if( dijm<epsilon ) {
w1=0.0;
dw1=0.0;
}
Vector dik=pbcDistance( getPosition(i,myvals), pos2 );
double dikm=dik.modulo2();
double dw2, w2=sf2.calculateSqr( dikm, dw2 );
if( dikm<epsilon ) {
w2=0.0;
dw2=0.0;
}

tot += w1*w2;
// And finish the calculation
Expand Down
45 changes: 31 additions & 14 deletions src/adjmat/ContactMatrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,16 @@ class ContactMatrix : public AdjacencyMatrixBase {
/// This does nothing
double calculateWeight( const Vector& pos1, const Vector& pos2, const unsigned& natoms, MultiValue& myvals ) const override;
/// Override this so we write the graph properly
std::string writeInGraph() const override { return "CONTACT_MATRIX"; }
std::string writeInGraph() const override {
return "CONTACT_MATRIX";
}
};

PLUMED_REGISTER_ACTION(ContactMatrix,"CONTACT_MATRIX_PROPER")

void ContactMatrix::registerKeywords( Keywords& keys ) {
AdjacencyMatrixBase::registerKeywords( keys ); keys.setDisplayName("CONTACT_MATRIX");
AdjacencyMatrixBase::registerKeywords( keys );
keys.setDisplayName("CONTACT_MATRIX");
keys.add("compulsory","NN","6","The n parameter of the switching function ");
keys.add("compulsory","MM","0","The m parameter of the switching function; 0 implies 2*NN");
keys.add("compulsory","D_0","0.0","The d_0 parameter of the switching function");
Expand All @@ -90,17 +93,24 @@ void ContactMatrix::registerKeywords( Keywords& keys ) {

ContactMatrix::ContactMatrix( const ActionOptions& ao ):
Action(ao),
AdjacencyMatrixBase(ao)
{
std::string errors, input; parse("SWITCH",input);
AdjacencyMatrixBase(ao) {
std::string errors, input;
parse("SWITCH",input);
if( input.length()>0 ) {
switchingFunction.set( input, errors );
if( errors.length()!=0 ) error("problem reading switching function description " + errors);
if( errors.length()!=0 ) {
error("problem reading switching function description " + errors);
}
} else {
double r_0=-1.0, d_0; int nn, mm;
parse("NN",nn); parse("MM",mm);
parse("R_0",r_0); parse("D_0",d_0);
if( r_0<0.0 ) error("you must set a value for R_0");
double r_0=-1.0, d_0;
int nn, mm;
parse("NN",nn);
parse("MM",mm);
parse("R_0",r_0);
parse("D_0",d_0);
if( r_0<0.0 ) {
error("you must set a value for R_0");
}
switchingFunction.set(nn,mm,r_0,d_0);
}
// And set the link cell cutoff
Expand All @@ -109,11 +119,18 @@ ContactMatrix::ContactMatrix( const ActionOptions& ao ):
}

double ContactMatrix::calculateWeight( const Vector& pos1, const Vector& pos2, const unsigned& natoms, MultiValue& myvals ) const {
Vector distance = pos2; double mod2 = distance.modulo2();
if( mod2<epsilon ) return 0.0; // Atoms can't be bonded to themselves
Vector distance = pos2;
double mod2 = distance.modulo2();
if( mod2<epsilon ) {
return 0.0; // Atoms can't be bonded to themselves
}
double dfunc, val = switchingFunction.calculateSqr( mod2, dfunc );
if( val<epsilon ) return 0.0;
if( doNotCalculateDerivatives() ) return val;
if( val<epsilon ) {
return 0.0;
}
if( doNotCalculateDerivatives() ) {
return val;
}
addAtomDerivatives( 0, (-dfunc)*distance, myvals );
addAtomDerivatives( 1, (+dfunc)*distance, myvals );
addBoxDerivatives( (-dfunc)*Tensor(distance,distance), myvals );
Expand Down
67 changes: 48 additions & 19 deletions src/adjmat/ContactMatrixShortcut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,58 +71,87 @@ PLUMED_REGISTER_ACTION(ContactMatrixShortcut,"CONTACT_MATRIX")

void ContactMatrixShortcut::registerKeywords(Keywords& keys) {
AdjacencyMatrixBase::registerKeywords( keys );
keys.remove("GROUP"); keys.add("numbered","GROUP","specifies the list of atoms that should be assumed indistinguishable");
keys.remove("GROUP");
keys.add("numbered","GROUP","specifies the list of atoms that should be assumed indistinguishable");
keys.add("compulsory","NN","6","The n parameter of the switching function ");
keys.add("compulsory","MM","0","The m parameter of the switching function; 0 implies 2*NN");
keys.add("compulsory","D_0","0.0","The d_0 parameter of the switching function");
keys.add("compulsory","R_0","The r_0 parameter of the switching function");
keys.add("numbered","SWITCH","specify the switching function to use between two sets of indistinguishable atoms");
keys.addActionNameSuffix("_PROPER"); keys.needsAction("TRANSPOSE"); keys.needsAction("CONCATENATE");
keys.addActionNameSuffix("_PROPER");
keys.needsAction("TRANSPOSE");
keys.needsAction("CONCATENATE");
}

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);
ActionShortcut(ao) {
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( 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];
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;
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; }
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;
}

for(unsigned i=0; i<grp_str.size(); ++i) {
std::string sw_str, num; Tools::convert( i+1, num ); parseNumbered("SWITCH", (i+1)*10 + 1 + i, sw_str );
if( sw_str.length()==0 ) error("missing SWITCH" + num + num + " keyword");
std::string sw_str, num;
Tools::convert( i+1, num );
parseNumbered("SWITCH", (i+1)*10 + 1 + i, sw_str );
if( sw_str.length()==0 ) {
error("missing SWITCH" + num + num + " keyword");
}
readInputLine( getShortcutLabel() + num + num + ": CONTACT_MATRIX_PROPER GROUP=" + grp_str[i] + " SWITCH={" + sw_str + "}" );
for(unsigned j=0; j<i; ++j) {
std::string sw_str2, jnum; Tools::convert( j+1, jnum ); parseNumbered("SWITCH", (j+1)*10 + 1 + i, sw_str2);
if( sw_str2.length()==0 ) error("missing SWITCH" + jnum + num + " keyword");
std::string sw_str2, jnum;
Tools::convert( j+1, jnum );
parseNumbered("SWITCH", (j+1)*10 + 1 + i, sw_str2);
if( sw_str2.length()==0 ) {
error("missing SWITCH" + jnum + num + " keyword");
}
readInputLine( getShortcutLabel() + jnum + num + ": CONTACT_MATRIX_PROPER GROUPA=" + grp_str[j] + " GROUPB=" + grp_str[i] + " SWITCH={" + sw_str2 +"}");
readInputLine( getShortcutLabel() + num + jnum + ": TRANSPOSE ARG=" + getShortcutLabel() + jnum + num );
}
}
std::string join_matrices = getShortcutLabel() + ": CONCATENATE";
for(unsigned i=0; i<grp_str.size(); ++i) {
std::string inum; Tools::convert(i+1,inum);
std::string inum;
Tools::convert(i+1,inum);
for(unsigned j=0; j<grp_str.size(); ++j) {
std::string jnum; Tools::convert(j+1,jnum);
if( i>j ) join_matrices += " MATRIX" + inum + jnum + "=" + getShortcutLabel() + inum + jnum;
else join_matrices += " MATRIX" + inum + jnum + "=" + getShortcutLabel() + inum + jnum;
std::string jnum;
Tools::convert(j+1,jnum);
if( i>j ) {
join_matrices += " MATRIX" + inum + jnum + "=" + getShortcutLabel() + inum + jnum;
} else {
join_matrices += " MATRIX" + inum + jnum + "=" + getShortcutLabel() + inum + jnum;
}
}
}
readInputLine( join_matrices );
Expand Down
6 changes: 3 additions & 3 deletions src/adjmat/DistanceMatrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ void DistanceMatrix::registerKeywords( Keywords& keys ) {

DistanceMatrix::DistanceMatrix( const ActionOptions& ao ):
Action(ao),
AdjacencyMatrixBase(ao)
{
AdjacencyMatrixBase(ao) {
// And set the link cell cutoff
log.printf(" weight is distance between atoms \n");
parse("CUTOFF",cutoff);
Expand All @@ -72,7 +71,8 @@ DistanceMatrix::DistanceMatrix( const ActionOptions& ao ):
}

double DistanceMatrix::calculateWeight( const Vector& pos1, const Vector& pos2, const unsigned& natoms, MultiValue& myvals ) const {
Vector distance = pos2; double mod = distance.modulo();
Vector distance = pos2;
double mod = distance.modulo();
if( cutoff<0 || mod<cutoff ) {
double invd = 1.0/mod;
addAtomDerivatives( 0, (-invd)*distance, myvals );
Expand Down
Loading

0 comments on commit d80912c

Please sign in to comment.