Exemplo n.º 1
0
void Value::setGradients(){
  gradients.clear();
  ActionAtomistic*aa=dynamic_cast<ActionAtomistic*>(action);
  ActionWithArguments*aw=dynamic_cast<ActionWithArguments*>(action);
  if(aa){
    Atoms&atoms((aa->plumed).getAtoms());
    for(unsigned j=0;j<aa->getNumberOfAtoms();++j){
      AtomNumber an=aa->getAbsoluteIndex(j);
      if(atoms.isVirtualAtom(an)){
        const ActionWithVirtualAtom* a=atoms.getVirtualAtomsAction(an);
        for(std::map<AtomNumber,Tensor>::const_iterator p=a->getGradients().begin();p!=a->getGradients().end();++p){
// controllare l'ordine del matmul:
          gradients[(*p).first]+=matmul(Vector(derivatives[3*j],derivatives[3*j+1],derivatives[3*j+2]),(*p).second);
        }
      } else {
        for(unsigned i=0;i<3;i++) gradients[an][i]+=derivatives[3*j+i];
      }
    }
  } else if(aw){
    std::vector<Value*> values=aw->getArguments();
    for(unsigned j=0;j<derivatives.size();j++){
      for(std::map<AtomNumber,Vector>::const_iterator p=values[j]->gradients.begin();p!=values[j]->gradients.end();++p){
        AtomNumber iatom=(*p).first;
        gradients[iatom]+=(*p).second*derivatives[j];
      }
    }
  } else plumed_error();
}
Exemplo n.º 2
0
void Value::setGradients() {
  // Can't do gradients if we don't have derivatives
  if( !hasDeriv ) return;
  gradients.clear();
  ActionAtomistic*aa=dynamic_cast<ActionAtomistic*>(action);
  ActionWithArguments*aw=dynamic_cast<ActionWithArguments*>(action);
  if(aa) {
    Atoms&atoms((aa->plumed).getAtoms());
    for(unsigned j=0; j<aa->getNumberOfAtoms(); ++j) {
      AtomNumber an=aa->getAbsoluteIndex(j);
      if(atoms.isVirtualAtom(an)) {
        const ActionWithVirtualAtom* a=atoms.getVirtualAtomsAction(an);
        for(const auto & p : a->getGradients()) {
// controllare l'ordine del matmul:
          gradients[p.first]+=matmul(Vector(derivatives[3*j],derivatives[3*j+1],derivatives[3*j+2]),p.second);
        }
      } else {
        for(unsigned i=0; i<3; i++) gradients[an][i]+=derivatives[3*j+i];
      }
    }
  } else if(aw) {
    std::vector<Value*> values=aw->getArguments();
    for(unsigned j=0; j<derivatives.size(); j++) {
      for(const auto & p : values[j]->gradients) {
        AtomNumber iatom=p.first;
        gradients[iatom]+=p.second*derivatives[j];
      }
    }
  } else plumed_error();
}
Exemplo n.º 3
0
void HistogramBead::set( double l, double h, double w) {
  init=true; lowb=l; highb=h; width=w;
  const double DP2CUTOFF=6.25;
  if( type==gaussian ) cutoff=sqrt(2.0*DP2CUTOFF);
  else if( type==triangular ) cutoff=1.;
  else plumed_error();
}
void ActionWithInputVessel::readArgument( const std::string& type ) {
  std::string mlab;
  if( keywords.exists("DATA") && type!="grid" ) parse("DATA",mlab);
  ActionWithVessel* mves= plumed.getActionSet().selectWithLabel<ActionWithVessel*>(mlab);
  if(!mves) error("action labelled " +  mlab + " does not exist or does not have vessels");
  addDependency(mves);

  ActionWithValue* aval=dynamic_cast<ActionWithValue*>( this );
  if(aval) {
    if( aval->checkNumericalDerivatives() ) {
      ActionWithValue* aval2=dynamic_cast<ActionWithValue*>( mves );
      plumed_assert( aval2 ); aval2->useNumericalDerivatives();
    }
  }

  if( type=="bridge" ) {
    ActionWithVessel* aves=dynamic_cast<ActionWithVessel*>( this );
    plumed_assert(aves); myBridgeVessel = mves->addBridgingVessel( aves );
    arguments = dynamic_cast<Vessel*>( myBridgeVessel );
  } else  if( type=="store" ) {
    arguments = dynamic_cast<Vessel*>( mves->buildDataStashes( NULL ) );
  } else {
    plumed_error();
  }
}
Exemplo n.º 5
0
void CLTool::parseFlag( const std::string&key, bool&t ){
  plumed_massert(keywords.exists(key),"keyword " + key + " has not been registered");
  plumed_massert(keywords.style(key,"flag"),"keyword " + key + " has not been registered as a flag");
  plumed_assert(inputData.count(key)>0); 
  if( inputData[key]=="true") t=true;
  else if( inputData[key]=="false") t=false;
  else plumed_error();
}
Exemplo n.º 6
0
void ReferenceArguments::extractArgumentDisplacement( const std::vector<Value*>& vals, const std::vector<double>& arg, std::vector<double>& dirout ) const {
  if( hasmetric ) {
    plumed_error();
  } else {
    for(unsigned j=0; j<reference_args.size(); ++j) {
      unsigned jk=arg_der_index[j]; dirout[jk]=sqrtweight[j]*vals[jk]->difference( reference_args[j], arg[jk] );
    }
  }
}
Exemplo n.º 7
0
double ReferenceArguments::projectArgDisplacementOnVector( const std::vector<double>& eigv, const std::vector<Value*>& vals, const std::vector<double>& arg, ReferenceValuePack& mypack ) const {
  if( hasmetric ) {
    plumed_error();
  } else {
    double proj=0;
    for(unsigned j=0; j<reference_args.size(); ++j) {
      unsigned jk=arg_der_index[j];
      proj += eigv[j]*sqrtweight[j]*vals[jk]->difference( reference_args[j], arg[jk] );
      mypack.setArgumentDerivatives( jk, eigv[j]*sqrtweight[j] );
    }
    return proj;
  }
}
Exemplo n.º 8
0
double HistogramBead::lboundDerivative( const double& x ) const {
  double lowB;
  if( type==gaussian ) {
    lowB = difference( x, lowb ) / ( sqrt(2.0) * width );
    return exp( -lowB*lowB ) / ( sqrt(2*pi)*width );
  } else if ( type==triangular ) {
    plumed_error();
//      lowB = fabs( difference( x, lowb ) / width );
//      if( lowB<1 ) return ( 1 - (lowB) ) / 2*width;
//      else return 0;
  } else {
    plumed_merror("function type does not exist");
  }
  return 0;
}
Exemplo n.º 9
0
double HistogramBead::uboundDerivative( const double& x ) const {
  plumed_dbg_assert(init && periodicity!=unset );
  double upperB;
  if( type==gaussian ) {
    upperB = difference( x, highb ) / ( sqrt(2.0) * width );
    return exp( -upperB*upperB ) / ( sqrt(2*pi)*width );
  } else if ( type==triangular ) {
    plumed_error();
//      upperB = fabs( difference( x, highb ) / width );
//      if( upperB<1 ) return ( 1 - (upperB) ) / 2*width;
//      else return 0;
  } else {
    plumed_merror("function type does not exist");
  }
  return 0;
}
Exemplo n.º 10
0
void CLTool::setRemainingToDefault(FILE* out){
  std::string def, thiskey;
  for(unsigned k=0;k<keywords.size();++k){
      thiskey=keywords.get(k);
      if( keywords.style(thiskey,"compulsory") ){
          if( inputData.count(thiskey)==0 ){
             if( keywords.getDefaultValue(thiskey,def) ){
                 plumed_assert( def.length()>0 );
                 inputData.insert(std::pair<std::string,std::string>(thiskey,def));
             } else {
                 fprintf(out,"ERROR : argument %s is compulsory. Use --help option for help\n",thiskey.c_str() );
                 plumed_error();
             }
          }
      }
  }
}
Exemplo n.º 11
0
void Action::parseFlag(const std::string&key,bool & t) {
  // Check keyword has been registered
  plumed_massert(keywords.exists(key), "keyword " + key + " has not been registered");
  // Check keyword is a flag
  if(!keywords.style(key,"nohtml")) {
    plumed_massert( keywords.style(key,"vessel") || keywords.style(key,"flag") || keywords.style(key,"hidden"), "keyword " + key + " is not a flag");
  }

  // Read in the flag otherwise get the default value from the keywords object
  if(!Tools::parseFlag(line,key,t)) {
    if( keywords.style(key,"nohtml") || keywords.style(key,"vessel") ) {
      t=false;
    } else if ( !keywords.getLogicalDefault(key,t) ) {
      log.printf("ERROR in action %s with label %s : flag %s has no default",name.c_str(),label.c_str(),key.c_str() );
      plumed_error();
    }
  }
}
Exemplo n.º 12
0
/*! hybrid-36 decoder: converts string s to integer result

      width: must be 4 (e.g. for residue sequence numbers)
                  or 5 (e.g. for atom serial numbers)

      s: string to be converted
         does not have to be null-terminated

      s_size: size of s
              must be equal to width, or an error message is
              returned otherwise

      result: integer holding the conversion result

      return value: pointer to error message, if any,
                    or 0 on success

    Example usage (from C++):
      int result;
      const char* errmsg = hy36decode(width, "A1T5", 4, &result);
      if (errmsg) throw std::runtime_error(errmsg);
 */
const char*
hy36decode(unsigned width, const char* s, unsigned s_size, int* result)
{
  static const std::vector<int> digits_values_upper_vector([]() {
    std::vector<int> ret(128U,-1);
    for(unsigned i=0; i<36U; i++) {
      int di = digits_upper()[i];
      if (di < 0 || di > 127) {
        plumed_error()<<"internal error hy36decode: integer value out of range";
      }
      ret[di] = i;
    }
    return ret;
  }());
  static const int* digits_values_upper=digits_values_upper_vector.data();
  static const std::vector<int> digits_values_lower_vector([]() {
    std::vector<int> ret(128U,-1);
    for(unsigned i=0; i<36U; i++) {
      int di = digits_lower()[i];
      if (di < 0 || di > 127) {
        plumed_error()<<"internal error hy36decode: integer value out of range";
      }
      ret[di] = i;
    }
    return ret;
  }());
  static const int* digits_values_lower=digits_values_lower_vector.data();
  int di;
  const char* errmsg;
  if (s_size == width) {
    di = s[0];
    if (di >= 0 && di <= 127) {
      if (digits_values_upper[di] >= 10) {
        errmsg = decode_pure(digits_values_upper, 36U, s, s_size, result);
        if (errmsg == 0) {
          /* result - 10*36**(width-1) + 10**width */
          if      (width == 4U) (*result) -= 456560;
          else if (width == 5U) (*result) -= 16696160;
          else {
            *result = 0;
            return unsupported_width();
          }
          return 0;
        }
      }
      else if (digits_values_lower[di] >= 10) {
        errmsg = decode_pure(digits_values_lower, 36U, s, s_size, result);
        if (errmsg == 0) {
          /* result + 16*36**(width-1) + 10**width */
          if      (width == 4U) (*result) += 756496;
          else if (width == 5U) (*result) += 26973856;
          else {
            *result = 0;
            return unsupported_width();
          }
          return 0;
        }
      }
      else {
        errmsg = decode_pure(digits_values_upper, 10U, s, s_size, result);
        if (errmsg) return errmsg;
        if (!(width == 4U || width == 5U)) {
          *result = 0;
          return unsupported_width();
        }
        return 0;
      }
    }
  }
  *result = 0;
  return invalid_number_literal();
}
Exemplo n.º 13
0
void MultiColvarBase::setupLinkCells(){
  if( !linkcells.enabled() ) return ;

  unsigned iblock, jblock;
  if( usespecies ){
      iblock=0; 
  } else if( current_atoms.size()<4 ){ 
      iblock=1;  
  } else {
      plumed_error();
  }
 
  // Count number of currently active atoms
  unsigned nactive_atoms=0;
  for(unsigned i=0;i<ablocks[iblock].size();++i){
      if( isCurrentlyActive( ablocks[iblock][i] ) ) nactive_atoms++;
  }

  std::vector<Vector> ltmp_pos( nactive_atoms ); 
  std::vector<unsigned> ltmp_ind( nactive_atoms );

  nactive_atoms=0;
  if( usespecies ){
     ltmp_pos.resize( ablocks[0].size() ); ltmp_ind.resize( ablocks[0].size() );
     for(unsigned i=0;i<ablocks[0].size();++i){
        if( !isCurrentlyActive( ablocks[0][i] ) ) continue; 
        ltmp_ind[nactive_atoms]=ablocks[0][i];
        ltmp_pos[nactive_atoms]=getPositionOfAtomForLinkCells( ltmp_ind[nactive_atoms] );
        nactive_atoms++;
     }
  } else {
     ltmp_pos.resize( ablocks[1].size() ); ltmp_ind.resize( ablocks[1].size() ); 
     for(unsigned i=0;i<ablocks[1].size();++i){
        if( !isCurrentlyActive( ablocks[1][i] ) ) continue;
        ltmp_ind[nactive_atoms]=i; 
        ltmp_pos[nactive_atoms]=getPositionOfAtomForLinkCells( ablocks[1][i] );
        nactive_atoms++; 
     }
  }

  // Build the lists for the link cells
  linkcells.buildCellLists( ltmp_pos, ltmp_ind, getPbc() );

  if( !usespecies ){
     // Get some parallel info
     unsigned stride=comm.Get_size();
     unsigned rank=comm.Get_rank(); 
     if( serialCalculation() ){ stride=1; rank=0; }

     // Ensure we only do tasks where atoms are in appropriate link cells
     std::vector<unsigned> linked_atoms( 1+ablocks[1].size() );
     std::vector<unsigned>  active_tasks( getFullNumberOfTasks(), 0 );
     for(unsigned i=rank;i<ablocks[0].size();i+=stride){
         if( !isCurrentlyActive( ablocks[0][i] ) ) continue;
         natomsper=1; linked_atoms[0]=ltmp_ind[0];  // Note we always check atom 0 because it is simpler than changing LinkCells.cpp
         linkcells.retrieveNeighboringAtoms( getPositionOfAtomForLinkCells( ablocks[0][i] ), natomsper, linked_atoms );
         for(unsigned j=0;j<natomsper;++j){
             for(unsigned k=bookeeping(i,linked_atoms[j]).first;k<bookeeping(i,linked_atoms[j]).second;++k) active_tasks[k]=1;
         }
     }
     if( !serialCalculation() ) comm.Sum( active_tasks ); 

     deactivateAllTasks(); 
     activateTheseTasks( active_tasks );
     contributorsAreUnlocked=false;
  }
}
Exemplo n.º 14
0
void Pbc::test(){
  Random r;
  r.setSeed(-20);
  for(int i=0;i<1000;i++){
// random matrix with some zero element
    Tensor box;
    for(int j=0;j<3;j++) for(int k=0;k<3;k++) if(r.U01()>0.2){
      box[j][k]=2.0*r.U01()-1.0;
    }
    int boxtype=i%10;
    switch(boxtype){
    case 0:
// cubic
      for(int j=0;j<3;j++) for(int k=0;k<3;k++) if(j!=k) box[j][k]=0.0;
      for(int j=1;j<3;j++) box[j][j]=box[0][0];
      break;
    case 1:
// orthorombic
      for(int j=0;j<3;j++) for(int k=0;k<3;k++) if(j!=k) box[j][k]=0.0;
      break;
    case 2:
// hexagonal
      {
      int perm=r.U01()*100;
      Vector a;
      a(0)=r.U01()*2-2; a(1)=0.0;a(2)=0.0;
      double d=r.U01()*2-2;
      Vector b(0.0,d,0.0);
      Vector c(0.0,0.5*d,sqrt(3.0)*d*0.5);
      box.setRow((perm+0)%3,a);
      box.setRow((perm+1)%3,b);
      box.setRow((perm+2)%3,c);
      }
      break;
    case 3:
// bcc
      {
      int perm=r.U01()*100;
      double d=r.U01()*2-2;
      Vector a(d,d,d);
      Vector b(d,-d,d);
      Vector c(d,d,-d);
      box.setRow((perm+0)%3,a);
      box.setRow((perm+1)%3,b);
      box.setRow((perm+2)%3,c);
      }
      break;
    case 4:
// fcc
      {
      int perm=r.U01()*100;
      double d=r.U01()*2-2;
      Vector a(d,d,0);
      Vector b(d,0,d);
      Vector c(0,d,d);
      box.setRow((perm+0)%3,a);
      box.setRow((perm+1)%3,b);
      box.setRow((perm+2)%3,c);
      }
      break;
    default:
// triclinic
      break;
    }

    Pbc pbc;
    pbc.setBox(box);
    std::cerr<<"( "<<boxtype<<" )\n";
    std::cerr<<"Box:";
    for(int j=0;j<3;j++) for(int k=0;k<3;k++) std::cerr<<" "<<box[j][k];
    std::cerr<<"\n";
    std::cerr<<"Determinant: "<<determinant(box)<<"\n";
    std::cerr<<"Shifts:";
    for(int j=0;j<2;j++) for(int k=0;k<2;k++) for(int l=0;l<2;l++) std::cerr<<" "<<pbc.shifts[j][k][l].size();
    std::cerr<<"\n";
    int nshifts=0;
    int ntot=10000;
    for(int j=0;j<ntot;j++){
      Vector v(r.U01()-0.5,r.U01()-0.5,r.U01()-0.5);
      v*=5;
      for(int j=0;j<3;j++) if(r.U01()>0.2) v(j)=0.0;
      Vector full(v);
      Vector fast=pbc.distance(Vector(0,0,0),v,&nshifts);
      full=fast;

      pbc.fullSearch(full);
  
     if(modulo2(fast-full)>1e-10) {
        std::cerr<<"orig "<<v[0]<<" "<<v[1]<<" "<<v[2]<<"\n";
        std::cerr<<"fast "<<fast[0]<<" "<<fast[1]<<" "<<fast[2]<<"\n";
        std::cerr<<"full "<<full[0]<<" "<<full[1]<<" "<<full[2]<<"\n";
        std::cerr<<"diff "<<modulo2(fast)-modulo2(full)<<std::endl;
        if(std::fabs(modulo2(fast)-modulo2(full))>1e-15) plumed_error();
     }
    }
    std::cerr<<"Average number of shifts: "<<double(nshifts)/double(ntot)<<"\n";
  }
}
Exemplo n.º 15
0
void ActionWithAveraging::performOperations( const bool& from_update ) { plumed_error(); }
Exemplo n.º 16
0
double FunctionVessel::calcTransform( const double& , double& ) const { 
  plumed_error(); return 1.0; 
}
Exemplo n.º 17
0
void IMD::receive(){

  if(!connected) return;

  if(clientsock){
    IMDType type;
    int length;
    int itype;
    while (vmdsock_selread(clientsock,0) > 0) {
      type = imd_recv_header(clientsock, &length);
      if(type==IMD_MDCOMM){
        int32* vmd_atoms = new int32[length];
        float* vmd_forces = new float[3*length];
        imd_recv_mdcomm(clientsock, length, vmd_atoms, vmd_forces);
        for(int i=0;i<length;i++){
          forces[3*vmd_atoms[i]+0]=vmd_forces[3*i+0];
          forces[3*vmd_atoms[i]+1]=vmd_forces[3*i+1];
          forces[3*vmd_atoms[i]+2]=vmd_forces[3*i+2];
        }
        delete [] vmd_atoms;
        delete [] vmd_forces;
        itype=0;
        comm.Bcast(&itype,1,0);
        comm.Bcast(&forces[0],forces.size(),0);
      }else if(type==IMD_DISCONNECT){
        vmdsock_destroy(clientsock);
        clientsock=NULL;
        for(unsigned i=0;i<forces.size();i++) forces[i]=0.0;
        connected=false;
        itype=1;
        comm.Bcast(&itype,1,0);
        break;
      }else if(type==IMD_TRATE){
        if(length<1) length=1;
        itype=2;
        log.printf("IMD: setting transfer rate to %d\n",length);
        transferRate=length;
        comm.Bcast(&itype,1,0);
        comm.Bcast(&transferRate,1,0);
      }else if(type==IMD_KILL){
        log.printf("IMD: killing simulation\n");
        itype=3;
        comm.Bcast(&itype,1,0);
        plumed.exit();
      }
    }
    itype=-1;
    comm.Bcast(&itype,1,0);
  }

  if(comm.Get_rank()!=0){
    int itype;
    while(true){
      comm.Bcast(&itype,1,0);
      if(itype==-1)break;
      else if(itype==0) comm.Bcast(&forces[0],forces.size(),0);
      else if(itype==1) {
        for(unsigned i=0;i<forces.size();i++) forces[i]=0.0;
        connected=false;
      }
      else if(itype==2) comm.Bcast(&transferRate,1,0);
      else if(itype==3) plumed.exit();
      else plumed_error();
    }
  }

}
Exemplo n.º 18
0
int PREFIX read_alpharmsd(char **word, int count, t_plumed_input *input, FILE *fplog)
{
// Coordinates N CA C O CB (Angstrom) of alpha 6-res block from the representative pdbs of
// each of the 5 architecture entries in class "mainly alpha" of CATH database
// (1oai 1mz9 1jdh 1ppr 1h12)
  static rvec ref_alpha[30]={   
    { 0.733,  0.519,  5.298}, // N    i
    { 1.763,  0.810,  4.301}, // CA
    { 1.527, -0.045,  3.053}, // C
    { 1.646,  0.436,  1.928}, // O
    { 3.166,  0.543,  4.881}, // CB
    { 1.180, -1.312,  3.254}, // N    i+1
    { 0.924, -2.203,  2.126}, // CA
    {-0.239, -1.711,  1.261}, // C
    {-0.190, -1.815,  0.032}, // O
    { 0.650, -3.626,  2.626}, // CB
    {-1.280, -1.172,  1.891}, // N    i+2
    {-2.416, -0.661,  1.127}, // CA
    {-1.964,  0.529,  0.276}, // C
    {-2.364,  0.659, -0.880}, // O
    {-3.548, -0.217,  2.056}, // CB
    {-1.130,  1.391,  0.856}, // N    i+3
    {-0.620,  2.565,  0.148}, // CA
    { 0.231,  2.129, -1.032}, // C
    { 0.179,  2.733, -2.099}, // O
    { 0.228,  3.439,  1.077}, // CB
    { 1.028,  1.084, -0.833}, // N    i+4
    { 1.872,  0.593, -1.919}, // CA
    { 1.020,  0.020, -3.049}, // C
    { 1.317,  0.227, -4.224}, // O
    { 2.850, -0.462, -1.397}, // CB
    {-0.051, -0.684, -2.696}, // N    i+5
    {-0.927, -1.261, -3.713}, // CA
    {-1.663, -0.171, -4.475}, // C
    {-1.916, -0.296, -5.673}, // O
    {-1.933, -2.219, -3.074}  // CB
  };

  int i, iw, iat, j, help, ix;
  double r_0, d_0, d;
  double delta = 0.0;
  double angstrom_scale;
  char string[400];
  real threshold, value;

  help=0;
  d_0=0.;

  colvar.cell_pbc[count]=1; // default is PBC

  iw = seek_word(word,"LIST");
  if(iw>=0){
             j=plumed_get_group(word[iw+1],&colvar.cvatoms[count],colvar.natoms[count],input,fplog);
             colvar.natoms[count]+=j;
             colvar.list[count][0]=j;
  } else{ fprintf(fplog,"|- NEEDED LIST KEYWORD FOR ALPHARMSD\n"); help=1;}

  if(colvar.natoms[count]%5!=0){ fprintf(fplog,"|- ERROR: TOTAL NUMBER OF ATOMS MUST BE MULTIPLE OF 5\n"); help=1; }

  iw=seek_word(word,"SIGMA");
  if(iw>=0){ sscanf(word[iw+1],"%lf", &delta);
             colvar.delta_r[count]  = (real) delta; }
  iw=seek_word(word,"NN");
  if(iw>=0) { sscanf(word[iw+1],"%i", &colvar.nn[count]); } else { fprintf(fplog,"|- NEEDED NN KEYWORD FOR ALPHARMSD\n"); help=1;}
  iw=seek_word(word,"MM");
  if(iw>=0) { sscanf(word[iw+1],"%i", &colvar.mm[count]);} else { fprintf(fplog,"|- NEEDED MM KEYWORD FOR ALPHARMSD\n"); help=1;}
  iw=seek_word(word,"R_0");
  if(iw>=0) { sscanf(word[iw+1],"%lf", &r_0); } else { fprintf(fplog,"|- NEEDED R_0 KEYWORD FOR ALPHARMSD\n"); help=1;}
  iw=seek_word(word,"D_0");
  if(iw>=0) { sscanf(word[iw+1],"%lf", &d_0); }
  iw=seek_word(word,"NOPBC");
  if(iw>=0) {colvar.cell_pbc[count] = 0;}
  iw=seek_word(word,"PBC");
  if(iw>=0) {colvar.cell_pbc[count] = 1;}
  iw=seek_word(word,"ANGSTROM_SCALE");
  if(iw>=0) { sscanf(word[iw+1],"%lf", &angstrom_scale); } else { fprintf(fplog,"|- NEEDED ANGSTROM_SCALE KEYWORD FOR ALPHARMSD\n"); help=1;}

  if(help){
          fprintf(fplog, "\n-ALPHARMSD CV: WRONG SYNTAX\n");
          fprintf(fplog, "e.g.:     \n");
          fprintf(fplog, "ALPHARMSD LIST <g1> NN 8 MM 12 R_0 0.08 SIGMA 1.0 ANGSTROM_SCALE 0.1 NOPBC\n");
          fprintf(fplog, "         g1->    \n");
          fprintf(fplog, "            7     9    26    27    11 \n");
          fprintf(fplog, "           28    30    45    46    32 \n");
          fprintf(fplog, "           47    49    56    57    51 \n");
          fprintf(fplog, "           58    60    71    72    62 \n");
          fprintf(fplog, "           73    75    88    89    77 \n");
          fprintf(fplog, "           90    92   100   101    94 \n");
          fprintf(fplog, "          102   104   120   121   106 \n");
          fprintf(fplog, "          122   124   136   137   126 \n");
          fprintf(fplog, "          138   140   147   148   142 \n");
          fprintf(fplog, "          149   151   163   164   153 \n");
          fprintf(fplog, "          165   167   183   184   169 \n");
          fprintf(fplog, "          185   187   190   191   189 \n");
          fprintf(fplog, "          192   194   209   210   196    \n");
          fprintf(fplog, "         g1<-    \n");
          fprintf(fplog, "       \n");
          fprintf(fplog, " (where each row contains N CA C O CB of consecutive residues)\n");
          fprintf(fplog, "       \n");
          plumed_error("PluMed dead with errors: check log file");
  }

  colvar.r_0[count]      = (real) r_0;
  colvar.d_0[count]      = (real) d_0;
  colvar.type_s[count]   = 37;

  fprintf(fplog, "%1i-ALPHARMSD; ATOMS INVOLVED: %i; ", count+1, colvar.natoms[count]);
  if(colvar.cell_pbc[count]) fprintf(fplog, " PBC ON");
  else                       fprintf(fplog, " PBC OFF");
  if (logical.do_hills) fprintf(fplog," SIGMA %f\n",colvar.delta_r[count]);
  else fprintf(fplog,"\n"); 
  fprintf(fplog, "|--FUNCTIONAL FORM: (1-((dist_mat_rmsd-d_0)/r_0)^n) / (1-((dist_mat_rmsd-d_0)/r_0)^m) \n");
  fprintf(fplog, "|--PARAMETERS: n= %i m= %i r_0= %f d_0= %f\n", colvar.nn[count], colvar.mm[count], colvar.r_0[count], colvar.d_0[count]);
  threshold=pow(0.00001,1./(colvar.nn[count]-colvar.mm[count]));
  value=(1.-pow(threshold,colvar.nn[count]))/(1.-pow(threshold,colvar.mm[count]));
  fprintf(fplog, "|--CUTOFF VALUE: %f\n",value);
  fprintf(fplog, "|--CUTOFF DISTANCE: %f\n",threshold*r_0+d_0);

  iat=0;
  fprintf(fplog,"|- SET MEMBERS: ");
  for(i=0;i<colvar.natoms[count];i++){fprintf(fplog," %d ",colvar.cvatoms[count][i]+1);if((i+1)%20==0)fprintf(fplog,"\n               ");}fprintf(fplog,"\n\n");

  fprintf(fplog,"|- IMPORTANT NOTE: THIS CV REQUIRES ALIGN_ATOMS (FOR ALL BACKBONE) ON SOME CODES LIKE GROMACS4 !!!\n");

  snew(colvar.myder[count], colvar.natoms[count]);

  // storing reference distance matrix (converted from angstrom to angstrom*angstrom_scale)
  ref_dist_mat.alpha_pairs=0.; // pairs without covalent bond
  for (i=0;i<29;i++) {
    for (j=i+1;j<30;j++) {
      d=0.;
      for (ix=0;ix<3;ix++) {
        d += pow((ref_alpha[i][ix]-ref_alpha[j][ix]),2);
      }
      d=sqrt(d);
      // here d is in angstrom: covalent bonds among N CA C O CB are maximum 1.54 A
      if(d>1.7) {
        // convert d in length units of the MD program
        d=d*angstrom_scale;
        ref_dist_mat.alpha_pairs+=1.;
      } else {
        // exclude covalent bonds
        d=-999.;
      }
      ref_dist_mat.alpha[i][j]=d;
      ref_dist_mat.alpha[j][i]=d;
    }
  }
 
  return colvar.natoms[count]; 
}
Exemplo n.º 19
0
int PREFIX read_angle(char **word, int count, t_plumed_input *input, FILE *fplog)
{
  int i,j, iat, iw, help;
  double delta = 0.0;
  char string[400];
  
  help = 0;

  colvar.doTrig[count]=0;    // Default is to do no trigonometry (raw angle)

  iw = seek_word(word,"LIST");
  if(iw>=0) {
             j=plumed_get_group(word[iw+1],&colvar.cvatoms[count],colvar.natoms[count],input,fplog);
             colvar.natoms[count]+=j;
             colvar.list[count][0]=j;
             j=plumed_get_group(word[iw+2],&colvar.cvatoms[count],colvar.natoms[count],input,fplog);
             colvar.natoms[count]+=j;
             colvar.list[count][1]=j;
             j=plumed_get_group(word[iw+3],&colvar.cvatoms[count],colvar.natoms[count],input,fplog);
             colvar.natoms[count]+=j;
             colvar.list[count][2]=j;
  } else { fprintf(fplog,"|- NEEDED LIST KEYWORD FOR ANGLE\n"); help=1;}

  iw=seek_word(word,"SIGMA");
  if(iw>=0){ sscanf(word[iw+1],"%lf", &delta);  
             colvar.delta_r[count]  = (real) delta; }
 
  if(help){
          fprintf(fplog, "\n-ANGLE CV: WRONG SYNTAX\n");
          fprintf(fplog, "e.g.:     \n");
          fprintf(fplog, "      ANGLE LIST 12 17 20 SIGMA 1.0 \n");
          fprintf(fplog, "              \n");
          fprintf(fplog, "or in case of group: \n");
          fprintf(fplog, "      ANGLE LIST <g1> <g2> <g3> SIGMA 1.0  \n");
          fprintf(fplog, "         g1->    \n");
          fprintf(fplog, "         6 10    \n");
          fprintf(fplog, "         g1<-    \n");
          fprintf(fplog, "                 \n");
          fprintf(fplog, "         g2->    \n");
          fprintf(fplog, "         8 15 21 \n");
          fprintf(fplog, "         g2<-    \n");
          fprintf(fplog, "                 \n"); 
          fprintf(fplog, "         g3->    \n");
          fprintf(fplog, "         23 29 31\n");
          fprintf(fplog, "         g3<-    \n");
          fprintf(fplog, "   \n");
          plumed_error("PluMeD dead with errors: check log file");
  }

  iw=seek_word(word,"SIN");
  if(iw>=0){ colvar.doTrig[count]=1; }
  iw=seek_word(word,"COS");
  if(iw>=0){ colvar.doTrig[count]=2; }

  colvar.type_s[count]   = 4;

  if(colvar.doTrig[count]==0){
	  fprintf(fplog, "\n%1i-ANGLE: (1st SET: %i ATOMS), (2nd SET: %i ATOMS), (3rd SET: %i ATOMS); ", count+1,
	    colvar.list[count][0], colvar.list[count][1], colvar.list[count][2]);
  }

  if(colvar.doTrig[count]==1){
	  fprintf(fplog, "\n%1i-SINE OF ANGLE: (1st SET: %i ATOMS), (2nd SET: %i ATOMS), (3rd SET: %i ATOMS); ", count+1,
	    colvar.list[count][0], colvar.list[count][1], colvar.list[count][2]);
  }

  if(colvar.doTrig[count]==1){
	  fprintf(fplog, "\n%1i-COSINE OF ANGLE: (1st SET: %i ATOMS), (2nd SET: %i ATOMS), (3rd SET: %i ATOMS); ", count+1,
	    colvar.list[count][0], colvar.list[count][1], colvar.list[count][2]);
  }

  if (logical.do_hills) fprintf(fplog," SIGMA %f\n",colvar.delta_r[count]);
  else fprintf(fplog,"\n");
 
  iat=0;
  fprintf(fplog,"|- 1st SET MEMBERS: ");
  for(i=0;i<colvar.list[count][0];i++){fprintf(fplog," %d ",colvar.cvatoms[count][iat++]+1);if((i+1)%20==0)fprintf(fplog,"\n                    ");}fprintf(fplog,"\n");
  fprintf(fplog,"|- 2nd SET MEMBERS: ");
  for(i=0;i<colvar.list[count][1];i++){fprintf(fplog," %d ",colvar.cvatoms[count][iat++]+1);if((i+1)%20==0)fprintf(fplog,"\n                    ");}fprintf(fplog,"\n");
  fprintf(fplog,"|- 3rd SET MEMBERS: ");
  for(i=0;i<colvar.list[count][2];i++){fprintf(fplog," %d ",colvar.cvatoms[count][iat++]+1);if((i+1)%20==0)fprintf(fplog,"\n                    ");}fprintf(fplog,"\n\n");

  snew(colvar.myder[count], colvar.natoms[count]);

  return colvar.natoms[count];
}
Exemplo n.º 20
0
void CLTool::error( const std::string& msg ){
  fprintf(stderr,"ERROR : in input for command line tool %s : %s\n",name.c_str(),msg.c_str());
  plumed_error();  
}
Exemplo n.º 21
0
void PREFIX angle_restraint(int i_c, struct mtd_data_s *mtd_data)
{
  int i, j, iat, k, ix;
  real myp[3][3], totmasse[3], d[3][3];
  rvec rij, sij, tij;
  real mod_rij, mod_sij;
  real eps, sign0;
  real caa, cbb, cab, ccc, sab;
  real ac, Vac, bc, dVac, cos_psi, sin_psi;

  totmasse[0] = totmasse[1] = totmasse[2] = 0.;
  myp[0][0] = myp[0][1] = myp[0][2] = 0.;
  myp[1][0] = myp[1][1] = myp[1][2] = 0.;
  myp[2][0] = myp[2][1] = myp[2][2] = 0.;
  k = 0;

  for(j=0;j<3;j++) {
    for(i=0;i<colvar.list[i_c][j];i++){
      iat = colvar.cvatoms[i_c][k];
      myp[j][0] += mtd_data->mass[iat]*mtd_data->pos[iat][0];
      myp[j][1] += mtd_data->mass[iat]*mtd_data->pos[iat][1];
      myp[j][2] += mtd_data->mass[iat]*mtd_data->pos[iat][2];
      totmasse[j] += mtd_data->mass[iat];
      k++;
    }
    myp[j][0] /= totmasse[j];
    myp[j][1] /= totmasse[j];
    myp[j][2] /= totmasse[j];
  }

  minimal_image(myp[1], myp[0], &mod_rij, rij);
  minimal_image(myp[1], myp[2], &mod_sij, sij);
  
  caa = norm2(rij);
  cab = iprod(rij,sij);
  cbb = norm2(sij);

  oprod(rij,sij,tij);
  sab = norm(tij);
  ccc = 1.0/sqrt(caa*cbb);
  ac = cab*ccc; // cosine of teta
  Vac = acos(ac);
  dVac = -ccc/sqrt(1.-ac*ac);

  for(ix=0;ix<3;ix++) {
    d[0][ix] = -dVac*(-cab/caa*rij[ix]+sij[ix]);
    d[1][ix] = dVac*(-cab/caa*rij[ix]-cab/cbb*sij[ix]+rij[ix]+sij[ix]);
    d[2][ix] = dVac*(cab/cbb*sij[ix]-rij[ix]);
  }

  // Now we do appropriate multiplication of the derivatives to get what we are interested in
  if( colvar.doTrig[i_c]==0 ){ colvar.ss0[i_c] = Vac; }
  else if( colvar.doTrig[i_c]==1 ){
     cos_psi=cos( Vac );
     for(i=0;i<3;++i){d[0][i]*= cos_psi;  d[1][i]*= cos_psi; d[2][i]*= cos_psi;}
     colvar.ss0[i_c] = sin( Vac );
  }
  else if( colvar.doTrig[i_c]==2 ){
     sin_psi=-sin( Vac );
     for(i=0;i<3;++i){d[0][i]*= sin_psi;  d[1][i]*= sin_psi; d[2][i]*= sin_psi;}
     colvar.ss0[i_c] = cos( Vac );
  }
  else{ plumed_error("No trigonometric mode defined in torsion restraint"); }



  k=0;
  for(j=0;j<3;j++) {
    for(i=0;i<colvar.list[i_c][j];i++){
      iat = colvar.cvatoms[i_c][k];
      for(ix=0;ix<3;ix++) colvar.myder[i_c][k][ix] = d[j][ix]*mtd_data->mass[iat]/totmasse[j];
      k++;
    }
  }

  //colvar.ss0[i_c] = Vac;
}
Exemplo n.º 22
0
int PREFIX read_position(char **word, int count, t_plumed_input *input, FILE *fplog)
{
  int i, iw, j;
  double delta = 0.0;
  char string[400];
  char chr[3];
  int help;
  int i1, i2, i3;
  double rtmp;

  help=0;
  chr[0]=chr[1]=chr[2]=' ';

  iw = seek_word(word,"LIST");
  if(iw>=0){   
             j=plumed_get_group(word[iw+1],&colvar.cvatoms[count],colvar.natoms[count],input,fplog);
             colvar.natoms[count]+=j;
             colvar.list[count][0]=j;
  } else{ fprintf(fplog,"|- NEEDED LIST KEYWORD FOR POSITION\n"); help=1;}

  iw=seek_word(word,"SIGMA");
  if(iw>=0){ sscanf(word[iw+1],"%lf", &delta);
             colvar.delta_r[count]  = (real) delta; }	

  iw=seek_word(word,"DIR");
  if(iw>=0) { 
    sscanf(word[iw+1],"%s", chr); 
    if(!strcmp(chr,"X") || !strcmp(chr,"x"))
      colvar.intpar[count][0] = 0;
    else if(!strcmp(chr,"Y") || !strcmp(chr,"y"))
      colvar.intpar[count][0] = 1;
    else if(!strcmp(chr,"Z") || !strcmp(chr,"z"))
      colvar.intpar[count][0] = 2;
  }

  iw=seek_word(word,"LINE_POS");
  if(iw>=0) { 
    colvar.intpar[count][0] = 3;
    sscanf(word[++iw],"%s", chr); 
    if     (!strcmp(chr,"X")){
      colvar.intpar[count][1] = 0;
      colvar.intpar[count][2] = 1;
      colvar.intpar[count][3] = 1;
    }else if(!strcmp(chr,"Y")){
      colvar.intpar[count][1] = 1;
      colvar.intpar[count][2] = 2;
      colvar.intpar[count][3] = 1;
    }else if(!strcmp(chr,"Z")){
      colvar.intpar[count][1] = 2;
      colvar.intpar[count][2] = 3;
      colvar.intpar[count][3] = 1;
    }else if(!strcmp(chr,"XY")){
      colvar.intpar[count][1] = 0;
      colvar.intpar[count][2] = 2;
      colvar.intpar[count][3] = 1;
    }else if(!strcmp(chr,"XZ")){
      colvar.intpar[count][1] = 0;
      colvar.intpar[count][2] = 3;
      colvar.intpar[count][3] = 2;
    }else if(!strcmp(chr,"YZ")){
      colvar.intpar[count][1] = 1;
      colvar.intpar[count][2] = 3;
      colvar.intpar[count][3] = 1;
    }else if(!strcmp(chr,"XYZ")){
      colvar.intpar[count][1] = 0;
      colvar.intpar[count][2] = 3;
      colvar.intpar[count][3] = 1;
    }else{
      help=1;
    }

    i1=colvar.intpar[count][1];
    i2=colvar.intpar[count][2];
    i3=colvar.intpar[count][3];
    for(i=i1;i<i2;i+=i3){
      sscanf(word[++iw],"%lf", &rtmp); 
      colvar.vecpar[count][0][i]= (real) rtmp; 
    }
    for(i=i1;i<i2;i+=i3){
      sscanf(word[++iw],"%lf", &rtmp); 
      colvar.vecpar[count][1][i]= (real) rtmp; 
    }
  } 

  iw=seek_word(word,"LINE_DIST");
  if(iw>=0) { 
    colvar.intpar[count][0] = 4;
    sscanf(word[++iw],"%s", chr); 
    if     (!strcmp(chr,"X")){
      colvar.intpar[count][1] = 0;
      colvar.intpar[count][2] = 1;
      colvar.intpar[count][3] = 1;
    }else if(!strcmp(chr,"Y")){
      colvar.intpar[count][1] = 1;
      colvar.intpar[count][2] = 2;
      colvar.intpar[count][3] = 1;
    }else if(!strcmp(chr,"Z")){
      colvar.intpar[count][1] = 2;
      colvar.intpar[count][2] = 3;
      colvar.intpar[count][3] = 1;
    }else if(!strcmp(chr,"XY")){
      colvar.intpar[count][1] = 0;
      colvar.intpar[count][2] = 2;
      colvar.intpar[count][3] = 1;
    }else if(!strcmp(chr,"XZ")){
      colvar.intpar[count][1] = 0;
      colvar.intpar[count][2] = 3;
      colvar.intpar[count][3] = 2;
    }else if(!strcmp(chr,"YZ")){
      colvar.intpar[count][1] = 1;
      colvar.intpar[count][2] = 3;
      colvar.intpar[count][3] = 1;
    }else if(!strcmp(chr,"XYZ")){
      colvar.intpar[count][1] = 0;
      colvar.intpar[count][2] = 3;
      colvar.intpar[count][3] = 1;
    }else{
      help=1;
    }

    i1=colvar.intpar[count][1];
    i2=colvar.intpar[count][2];
    i3=colvar.intpar[count][3];
    for(i=i1;i<i2;i+=i3){
      sscanf(word[++iw],"%lf", &rtmp); 
      colvar.vecpar[count][0][i]= (real) rtmp; 
    }
    for(i=i1;i<i2;i+=i3){
      sscanf(word[++iw],"%lf", &rtmp); 
      colvar.vecpar[count][1][i]= (real) rtmp; 
    }
  } 

  if(chr[0]==' ')help=1;

  if(help){
          fprintf(fplog, "\n-POSIION CV: WRONG SYNTAX\n");
          fprintf(fplog, "e.g.:     \n");
          fprintf(fplog, "      POSITION LIST 42 {TYPE} SIGMA 1.0 \n");
          fprintf(fplog, "or in case of groups    \n");
          fprintf(fplog, "      POSITION LIST <g1> {TYPE} SIGMA 1.0 \n");
          fprintf(fplog, "         g1->    \n");
          fprintf(fplog, "         6 10    \n");
          fprintf(fplog, "         g1<-    \n");
          fprintf(fplog, "                 \n");
          fprintf(fplog, " TYPE can be either DIR, LINE_POS or LINE_DIST\n");
          fprintf(fplog, " possible flags for DIR are X, Y and Z\n");
          fprintf(fplog, " possible flags for LINE_POS and LINE_DIST are X, Y, Z, XY, XZ, YZ or XYZ\n");
          plumed_error("PluMeD dead with errors: check log file");
  }

  colvar.type_s[count]   = 32;

  snew(colvar.myder[count], colvar.natoms[count]);

  fprintf(fplog, "%i-%1s POSITION OF %i ATOMS; ", count+1,chr,colvar.natoms[count]);
  if (logical.do_hills) fprintf(fplog," SIGMA %f\n",colvar.delta_r[count]);
  else fprintf(fplog,"\n"); 
  fprintf(fplog,"|- SET MEMBERS: ");
  for(i=0;i<colvar.natoms[count];i++){fprintf(fplog," %d ",colvar.cvatoms[count][i]+1);if((i+1)%20==0)fprintf(fplog,"\n               ");}fprintf(fplog,"\n\n");

  return 0;
}
Exemplo n.º 23
0
int PREFIX read_histogram( char **word, int count, t_plumed_input *input, FILE *fplog ) {
  int i, j, k, iw, ncolvar, ngrid, nspline;  int* cvlist;
  double smooth, delta = 0.0; int help=0;

  ncolvar=0; cvlist=NULL;

  // This reads in all the CVs used for histogram collective coordinates
  iw = seek_word(word,"CV_LIST"); 
  if(iw>=0){  ncolvar=plumed_get_group(word[iw+1],&cvlist,0,input,fplog); 
             if( ncolvar>count ){ plumed_error("NUMBER OF CVS USED TO CALCULATE HISTOGRAM"); }
  } 
  else{ fprintf(fplog,"|- NEEDED CV_LIST KEYWORD FOR HISTOGRAM\n"); help=1;}

  colvar.histo_ncv[count]=ncolvar; 
  snew( colvar.histo_cvlist[count], colvar.histo_ncv[count] );
  for(i=0;i<colvar.histo_ncv[count];++i){ colvar.histo_cvlist[count][i]=cvlist[i]; }

  // This is the sanity check for CV_LIST ( part 2 : check all the cvs used to construct histogram cvs are declared before any BESPOKE cvs)
  for(i=0;i<colvar.histo_ncv[count];i++){
     if( colvar.histo_cvlist[count][i]>count ){fprintf(fplog,"HISTOGRAM COMMAND MUST COME AFTER ALL CVS USED TO CREATE HISTOGRAM CV \n"); help=1; }
     // Number of atoms involved in this CV (sum of number of atoms involved in all other cvs)
     colvar.natoms[count]+=colvar.natoms[ colvar.histo_cvlist[count][i] ];
  }

  iw = seek_word(word,"RANGE");
  if(iw>=0) { 
     sscanf(word[iw+1], "%lf", &delta ); colvar.histo_low[count] = (real) delta; 
     sscanf(word[iw+2], "%lf", &delta ); colvar.histo_high[count] = (real) delta; 
  } 
  else{ fprintf(fplog,"|- NEEDED RANGE KEYWORD FOR HISTOGRAM\n"); help=1; }

  iw = seek_word(word,"WIDTH");
  if(iw>=0) { sscanf(word[iw+1], "%lf", &delta ); colvar.histo_width[count] = (real) delta; }
  else{ fprintf(fplog,"|- NEEDED WIDTH KEYWORD FOR HISTOGRAM\n"); help=1; }

  // Setup array of atoms involved in this cv
  snew( colvar.cvatoms[count], colvar.natoms[count] ); k=0;
  for(i=0;i<colvar.histo_ncv[count];i++){
     for(j=0;j<colvar.natoms[ colvar.histo_cvlist[count][i] ];j++){
        colvar.cvatoms[count][k]=colvar.cvatoms[ colvar.histo_cvlist[count][i] ][j];
        k++;
     }
  }
  // Setup derivatives array
  snew( colvar.myder[count], colvar.natoms[count] );

  if(help){ 
     fprintf(fplog,"\n-HISTOGRAM CV: WRONG SYNTAX\n");
     fprintf(fplog,"e.g.:    \n");
     fprintf(fplog,"TORSION LIST <g1> <g2> <g3> <g4>    \n");
     fprintf(fplog,"TORSION LIST <g2> <g3> <g4> <g5>    \n");
     fprintf(fplog,"TORSION LIST <g3> <g4> <g5> <g6>    \n");
     fprintf(fplog,"TORSION LIST <g4> <g5> <g6> <g7>    \n");
     fprintf(fplog,"HISTOGRAM CV_LIST <cv_list> RANGE 2.0 3.0 WIDTH 0.5\n");
     fprintf(fplog,"cvlist-> \n");
     fprintf(fplog,"1 2 3 4  \n");
     fprintf(fplog,"cvlist<- \n");
     fprintf(fplog,"         \n"); 
     plumed_error("PluMed dead with errors: check log file");
  }

  iw=seek_word(word,"SIGMA");
  if(iw>=0){ sscanf(word[iw+1],"%lf", &delta);
             colvar.delta_r[count]  = (real) delta; }

  fprintf(fplog, "%1i-HISTOGRAM COLLECTIVE COORDINATE CREATED FROM %i OTHER CVS \n", count+1, colvar.histo_ncv[count]);
  fprintf(fplog, "|--PARAMETERS: RANGE OF DESIRED VALUE = %f %f.  WIDTH OF GAUSSIAN FOR SMOOTHING %f. \n", colvar.histo_low[count], colvar.histo_high[count],colvar.histo_width[count] );
  fprintf(fplog,"|- COLVARS USED IN HISTOGRAM CV:");
  for(i=0;i<colvar.histo_ncv[count];i++){fprintf(fplog," %d ",colvar.histo_cvlist[count][i]+1);if((i+1)%20==0)fprintf(fplog,"\n                    ");}fprintf(fplog,"\n\n");

  return colvar.natoms[count];
}
Exemplo n.º 24
0
void MultiColvarBase::setupLinkCells(){
  if( !linkcells.enabled() ) return ;

  unsigned iblock;
  if( usespecies ){
      iblock=0; 
  } else if( ablocks.size()<4 ){ 
      iblock=1;  
  } else {
      plumed_error();
  }
 
  // Count number of currently active atoms
  unsigned nactive_atoms=0;
  for(unsigned i=0;i<ablocks[iblock].size();++i){
      if( isCurrentlyActive( iblock, ablocks[iblock][i] ) ) nactive_atoms++;
  }

  std::vector<Vector> ltmp_pos( nactive_atoms ); 
  std::vector<unsigned> ltmp_ind( nactive_atoms );

  nactive_atoms=0;
  if( usespecies ){
     for(unsigned i=0;i<ablocks[0].size();++i){
        if( !isCurrentlyActive( 0, ablocks[0][i] ) ) continue; 
        ltmp_ind[nactive_atoms]=ablocks[0][i];
        ltmp_pos[nactive_atoms]=getPositionOfAtomForLinkCells( ltmp_ind[nactive_atoms] );
        nactive_atoms++;
     }
  } else {
     for(unsigned i=0;i<ablocks[1].size();++i){
        if( !isCurrentlyActive( 1, ablocks[1][i] ) ) continue;
        ltmp_ind[nactive_atoms]=i; 
        ltmp_pos[nactive_atoms]=getPositionOfAtomForLinkCells( ablocks[1][i] );
        nactive_atoms++; 
     }
  }

  // Build the lists for the link cells
  linkcells.buildCellLists( ltmp_pos, ltmp_ind, getPbc() );

  if( !usespecies ){
     // Get some parallel info
     unsigned stride=comm.Get_size();
     unsigned rank=comm.Get_rank(); 
     if( serialCalculation() ){ stride=1; rank=0; }

     // Ensure we only do tasks where atoms are in appropriate link cells
     std::vector<unsigned> linked_atoms( 1+ablocks[1].size() );
     std::vector<unsigned>  active_tasks( getFullNumberOfTasks(), 0 );
     for(unsigned i=rank;i<ablocks[0].size();i+=stride){
         if( !isCurrentlyActive( 0, ablocks[0][i] ) ) continue;
         unsigned natomsper=1; linked_atoms[0]=ltmp_ind[0];  // Note we always check atom 0 because it is simpler than changing LinkCells.cpp
         linkcells.retrieveNeighboringAtoms( getPositionOfAtomForLinkCells( ablocks[0][i] ), natomsper, linked_atoms );
         for(unsigned j=0;j<natomsper;++j){
             for(unsigned k=bookeeping(i,linked_atoms[j]).first;k<bookeeping(i,linked_atoms[j]).second;++k) active_tasks[k]=1;
         }
     }
     if( !serialCalculation() ) comm.Sum( active_tasks ); 

     deactivateAllTasks(); 
     activateTheseTasks( active_tasks );
     contributorsAreUnlocked=false;
  } else {
     // Now check for calculating volumes (currently this is only done for usespecies style commands 
     // as it is difficult to do with things like DISTANCES or ANGLES and I think pointless
     bool justVolumes=true;
     for(unsigned i=0;i<getNumberOfVessels();++i){
         vesselbase::BridgeVessel* myb=dynamic_cast<vesselbase::BridgeVessel*>( getPntrToVessel(i) );
         if( !myb ){ justVolumes=false; break; }
         ActionVolume* myv=dynamic_cast<ActionVolume*>( myb->getOutputAction() ); 
         if( !myv ){ justVolumes=false; break; }
     }
     // Now ensure that we only do calculations for those atoms in the relevant volume
     if( justVolumes ){
         bool justVolumes=true;
         // Setup the regions in the action volume objects 
         for(unsigned i=0;i<getNumberOfVessels();++i){
             vesselbase::BridgeVessel* myb=dynamic_cast<vesselbase::BridgeVessel*>( getPntrToVessel(i) );
             ActionVolume* myv=dynamic_cast<ActionVolume*>( myb->getOutputAction() );
             myv->retrieveAtoms(); myv->setupRegions();
         } 

         unsigned stride=comm.Get_size();
         unsigned rank=comm.Get_rank();
         if( serialCalculation() ){ stride=1; rank=0; } 

         unsigned nactive=0;
         std::vector<unsigned>  active_tasks( getFullNumberOfTasks(), 0 );
         for(unsigned i=rank;i<getFullNumberOfTasks();i+=stride){
             bool invol=false;
             for(unsigned j=0;j<getNumberOfVessels();++j){
                 vesselbase::BridgeVessel* myb=dynamic_cast<vesselbase::BridgeVessel*>( getPntrToVessel(j) );
                 ActionVolume* myv=dynamic_cast<ActionVolume*>( myb->getOutputAction() );
                 if( myv->inVolumeOfInterest(i) ){ invol=true; }  
             }
             if( invol ){ nactive++; active_tasks[i]=1; }
         }

         if( !serialCalculation() ) comm.Sum( active_tasks );

         deactivateAllTasks();
         activateTheseTasks( active_tasks );
         contributorsAreUnlocked=false;
     }
  }

}
Exemplo n.º 25
0
int PREFIX read_adf( char **word, int count, t_plumed_input *input, FILE *fplog ) {
  int i, iw, j, iat, k, help, rdflab, checkLists, natoms1, natoms2; 
  double delta = 0.0, upBound, lowBound, width, r_0, d_0;

  help=0; d_0=0;

  // Deal with periodic boundary conditions
  colvar.cell_pbc[count]=1; // default is PBC

  iw=seek_word(word,"NOPBC");
  if(iw>=0) {colvar.cell_pbc[count] = 0;}
  iw=seek_word(word,"PBC");
  if(iw>=0) {colvar.cell_pbc[count] = 1;} 

  // This is the label for which rdf this bead is from
  iw = seek_word(word,"RDF_LABEL");
  if(iw>=0){ sscanf(word[iw+1],"%d",&rdflab); colvar.rdflab[count]=rdflab; }
  else{ fprintf(fplog,"|- NEEDED RDF_LABEL KEYWORD FOR ANGLE RDF\n"); help=1; }

  // Now we check whether there are other beads from this rdf that have been read in
  checkLists=-1; for(i=0;i<count;i++){ if( colvar.type_s[i]==52 && colvar.rdflab[i]==rdflab ){ checkLists=i; break; } }

  // Get atoms involved in the rdf
  iw = seek_word(word,"LIST");
  if(iw>=0){
             j=plumed_get_group(word[iw+1],&colvar.cvatoms[count],colvar.natoms[count],input,fplog);
             colvar.natoms[count]+=j;
             colvar.list[count][0]=j;
             j=plumed_get_group(word[iw+2],&colvar.cvatoms[count],colvar.natoms[count],input,fplog);
             colvar.natoms[count]+=j;
             colvar.list[count][1]=j;
             j=plumed_get_group(word[iw+3],&colvar.cvatoms[count],colvar.natoms[count],input,fplog);
             colvar.natoms[count]+=j;
             colvar.list[count][2]=j;
  } else{ fprintf(fplog,"|- NEEDED LIST KEYWORD FOR ADF\n"); help=1; }

  // Get the parameters for the switching function
  iw=seek_word(word,"NN");
  if(iw>=0) { sscanf(word[iw+1],"%i", &colvar.nn[count]); } else { fprintf(fplog,"|- NEEDED NN KEYWORD FOR ADF\n"); help=1;}
  iw=seek_word(word,"MM");
  if(iw>=0) { sscanf(word[iw+1],"%i", &colvar.mm[count]);} else { fprintf(fplog,"|- NEEDED MM KEYWORD FOR ADF\n"); help=1;}
  iw=seek_word(word,"R_0");
  if(iw>=0) { sscanf(word[iw+1],"%lf", &r_0); } else { fprintf(fplog,"|- NEEDED R_0 KEYWORD FOR ADF\n"); help=1;}
  iw=seek_word(word,"D_0");
  if(iw>=0) { sscanf(word[iw+1],"%lf", &d_0); }
   
  // Store the values
  colvar.r_0[count]      = (real) r_0; 
  colvar.d_0[count]      = (real) d_0; 

  // Check that the everything is consistent with other rdfs of this type
  if( checkLists!=-1){
    
    // Check the lists
    if( colvar.natoms[count]!=colvar.natoms[checkLists] ){
      fprintf(fplog,"|- MISLABELED ADF: ATOM LIST SIZES DO NOT MATCH\n"); help=1;  
    } else{
      for(i=0;i<colvar.natoms[count];i++){
         if( colvar.cvatoms[count][i]!=colvar.cvatoms[checkLists][i] ){
            fprintf(fplog,"|- MISLABELED ADF: ATOM LISTS DO NOT MATCH\n"); help=1;
         }
      }
    }
    
    // Now check the parameters for the switching functions 
    if( colvar.nn[count]!=colvar.nn[checkLists] ){
      fprintf(fplog,"|- MISLABELED ADF: NN VALUES DO NOT MATCH\n"); help=1; 
    }
    if( colvar.mm[count]!=colvar.mm[checkLists] ){
      fprintf(fplog,"|- MISLABELED ADF: MM  VALUES DO NOT MATCH\n"); help=1; 
    }
    if( colvar.r_0[count]!=colvar.r_0[checkLists] ){
      fprintf(fplog,"|- MISLABELED ADF: R_0 VALUES DO NOT MATCH\n"); help=1; 
    }
    if( colvar.d_0[count]!=colvar.d_0[checkLists] ){
      fprintf(fplog,"|- MISLABELED ADF: D_0 VALUES DO NOT MATCH\n"); help=1; 
    }
  }

  // Check whether or not lists 2 and 3 are the same
  colvar.rdfNorm[count]=1;
  natoms2=colvar.list[count][1] - colvar.list[count][0];
  natoms1=colvar.list[count][1] - colvar.list[count][0];   
  if( natoms1==natoms2 ){
    for(i=0;i<natoms1;i++){ 
       j=colvar.cvatoms[count][colvar.list[count][0]+i]; k=colvar.cvatoms[count][colvar.list[count][1]+i];
       if( j!=k ){ colvar.rdfNorm[count]=0; break; }
    }
  } else{ colvar.rdfNorm[count]=0; }

  // Get the start and end of this particular bead
  iw = seek_word(word,"RANGE");
  if(iw>=0){ sscanf(word[iw+1],"%lf",&lowBound); sscanf(word[iw+2],"%lf", &upBound); 
     colvar.rdfBeadLower[count]=lowBound; colvar.rdfBeadUpper[count]=upBound;
  } else{ fprintf(fplog,"|- NEEDED RANGE KEYWORD FOR RDF\n"); help=1;}

  // Get the width of this bead
  iw = seek_word(word,"WIDTH");
  if(iw>=0){ sscanf(word[iw+1],"%lf",&width); 
     colvar.rdfBeadWidth[count]=width;
  } else{ fprintf(fplog,"|- NEEDED WIDTH KEYWORD FOR RDF\n"); help=1;}

  if(help){
     fprintf(fplog,"\n-ADF CV: WRONG SYNTAX\n");
     fprintf(fplog,"e.g.:    \n");
     fprintf(fplog,"ADF RDF_LABEL 1 LIST <gr1> <gr2> <gr2> RANGE 2.0 3.0 WIDTH 1.5 R_0 1.0 D_0 0.0 NN 6 MM 12 \n");
     fprintf(fplog,"ADF RDF_LABEL 1 LIST <gr1> <gr2> <gr2> RANGE 2.0 3.0 WIDTH 1.5 R_0 1.0 D_0 0.0 NN 6 MM 12 \n");
     fprintf(fplog,"gr1-> \n");
     fprintf(fplog,"1 2 3 4  \n");
     fprintf(fplog,"gr1<- \n");
     fprintf(fplog,"gr2-> \n");
     fprintf(fplog,"1 2 3 4  \n");
     fprintf(fplog,"gr2<- \n");
     fprintf(fplog,"gr3-> \n");
     fprintf(fplog,"1 2 3 4  \n");
     fprintf(fplog,"gr3<- \n");
     fprintf(fplog,"         \n");
     plumed_error("PluMed dead with errors: check log file");
  }

  // Resize derivatives array
  snew(colvar.myder[count], colvar.natoms[count]);

  iw=seek_word(word,"SIGMA");
  if(iw>=0){ sscanf(word[iw+1],"%lf", &delta);
             colvar.delta_r[count]  = (real) delta; }

  fprintf(fplog, "%1i-BEAD FROM DISTRIBUTION OF ANGLES ABOUT (1st SET: %i ATOMS) ANGLES ARE BETWEEN (2nd SET: %i ATOMS) AND (3rd SET: %i ATOMS); \n", count+1, colvar.list[count][0], colvar.list[count][1], colvar.list[count][2]);
  if( colvar.rdfNorm[count]==1 ){ fprintf(fplog, "|--LISTS 2 AND 3 ARE IDENTICAL\n"); }
  fprintf(fplog, "|--LOWER BOUND %f, UPPER BOUND %f, WIDTH %f \n", colvar.rdfBeadLower[count], colvar.rdfBeadUpper[count], colvar.rdfBeadWidth[count]);
  fprintf(fplog, "|--PARAMETERS FOR SWITCHING FUNCTION : R_0 %f, D_0 %f, NN %d, MM %d \n", colvar.r_0[count], colvar.d_0[count], colvar.nn[count], colvar.mm[count] );  

  iat=0;
  fprintf(fplog,"|- 1st SET MEMBERS: ");
  for(i=0;i<colvar.list[count][0];i++){fprintf(fplog," %d ",colvar.cvatoms[count][iat++]+1);if((i+1)%20==0)fprintf(fplog,"\n                    ");}fprintf(fplog,"\n");
  fprintf(fplog,"|- 2nd SET MEMBERS: ");
  for(i=0;i<colvar.list[count][1];i++){fprintf(fplog," %d ",colvar.cvatoms[count][iat++]+1);if((i+1)%20==0)fprintf(fplog,"\n                    ");}fprintf(fplog,"\n");
  fprintf(fplog,"|- 3rd SET MEMBERS: ");
  for(i=0;i<colvar.list[count][2];i++){fprintf(fplog," %d ",colvar.cvatoms[count][iat++]+1);if((i+1)%20==0)fprintf(fplog,"\n                    ");}fprintf(fplog,"\n\n");

  return colvar.natoms[count];
}
Exemplo n.º 26
0
void MultiDomainRMSD::setReferenceAtoms( const std::vector<Vector>& conf, const std::vector<double>& align_in, const std::vector<double>& displace_in ) {
  plumed_error();
}
Exemplo n.º 27
0
void ActionWithVessel::transformBridgedDerivatives( const unsigned& current, MultiValue& invals, MultiValue& outvals ) const {
  plumed_error();
}
Exemplo n.º 28
0
int PREFIX read_cmap(char **word, int count,t_plumed_input *input,FILE *fplog)
{

  int i,iw;
  double sigma = 0.0;
  char file_maps[129];
  char file_group[129];
  struct sz_data *my_sz;
  int help;

  help=0; 
  colvar.cell_pbc[count]=1; // default is PBC

  my_sz=&(my_sz_list[nsz]);
  ic_to_sz[count]=nsz;

  my_sz->my_cmap_pack.logical_group = 0; // no GROUP

  iw=seek_word(word,"SIGMA");
  if(iw>=0){ sscanf(word[iw+1],"%lf", &sigma);
             colvar.delta_r[count]  = (real) sigma; }
  iw = seek_word(word,"INDEX");
  if(iw>=0) { sscanf(word[iw+1],"%s", file_maps);
  } else {
    fprintf(fplog,"|- NEEDED INDEX KEYWORD FOR CMAP\n");
    help=1;
  }
  iw=seek_word(word,"GROUP");
  if(iw>=0) {
   sscanf(word[iw+1],"%s",file_group);
   my_sz->my_cmap_pack.logical_group = 1;
  }
  iw=seek_word(word,"NOPBC");
  if(iw>=0) {colvar.cell_pbc[count] = 0;}
  iw=seek_word(word,"PBC");
  if(iw>=0) {colvar.cell_pbc[count] = 1;}

  if(help){
         fprintf(fplog,"|- CMAP SYNTAX:\n");
         fprintf(fplog,"|- INDEX              : contact definition file \n");
         fprintf(fplog,"|- GROUP              : group definition file \n");
         fprintf(fplog,"|- SIGMA              : hills width for this cv\n");
         fprintf(fplog,"|- e.g.\n");
         fprintf(fplog,"|- \n");
         fprintf(fplog,"|- CMAP INDEX cmap.index { GROUP cmap.group } { NOPBC } SIGMA 1.0 \n");
         fprintf(fplog,"|- \n");
         plumed_error("PluMeD dead with errors: check log file");
  } 

  
  fprintf(fplog, "\n%1i-CMAP: INDEX file %s ", count+1, file_maps);
  if(my_sz->my_cmap_pack.logical_group) fprintf(fplog, " GROUP file %s ", file_group); 
  if(colvar.cell_pbc[count]) fprintf(fplog, " PBC ON ");
  else                       fprintf(fplog, " PBC OFF ");
  if (logical.do_hills){
        if (colvar.delta_r[count]>0){
                 fprintf(fplog," SIGMA %f\n",colvar.delta_r[count]);
        }
  }
  else fprintf(fplog,"\n");


  read_sz_map(my_sz,file_maps,file_maps,file_group,0,fplog);

  colvar.natoms[count]   = my_sz->my_cmap_pack.atoms; 

  snew(colvar.myder[count], colvar.natoms[count]);
  snew(colvar.cvatoms[count], colvar.natoms[count]);

  for(i=0;i<colvar.natoms[count];i++)
    colvar.cvatoms[count][i] = my_sz->my_cmap_pack.list[i];
  
  nsz++;

  if(nsz==NMAX_PATH) plumed_error("TOO MANY PATH CVS. Increase NMAX_PATH in metadyn.h and recompile");

  fprintf(fplog,"\n");

  return colvar.natoms[count];
}