Пример #1
0
void MultiDomainRMSD::setupPCAStorage( ReferenceValuePack& mypack ) {
  plumed_dbg_assert( pcaIsEnabledForThisReference() );
  mypack.switchOnPCAOption();
  mypack.displacement.resize( getNumberOfAtoms() );
  mypack.centeredpos.resize( getNumberOfAtoms() );
  mypack.DRotDPos.resize(3,3); mypack.rot.resize( domains.size() );
  for(unsigned i=0; i<3; ++i) for(unsigned j=0; j<3; ++j) mypack.DRotDPos(i,j).resize( getNumberOfAtoms() );
}
Пример #2
0
double MultiDomainRMSD::calculate( const std::vector<Vector>& pos, const Pbc& pbc, ReferenceValuePack& myder, const bool& squared ) const {
  double totd=0.; Tensor tvirial; std::vector<Vector> mypos; MultiValue tvals( 1, 3*pos.size()+9 );
  ReferenceValuePack tder( 0, getNumberOfAtoms(), tvals ); myder.clear();

  for(unsigned i=0; i<domains.size(); ++i) {
    // Must extract appropriate positions here
    mypos.resize( blocks[i+1] - blocks[i] );
    if( myder.calcUsingPCAOption() ) domains[i]->setupPCAStorage( tder );
    unsigned n=0; for(unsigned j=blocks[i]; j<blocks[i+1]; ++j) { tder.setAtomIndex(n,j); mypos[n]=pos[j]; n++; }
    for(unsigned k=n; k<getNumberOfAtoms(); ++k) tder.setAtomIndex(k,3*pos.size()+10);
    // This actually does the calculation
    totd += weights[i]*domains[i]->calculate( mypos, pbc, tder, true );
    // Now merge the derivative
    myder.copyScaledDerivatives( 0, weights[i], tvals );
    // If PCA copy PCA stuff
    if( myder.calcUsingPCAOption() ) {
      unsigned n=0;
      if( tder.centeredpos.size()>0 ) myder.rot[i]=tder.rot[0];
      for(unsigned j=blocks[i]; j<blocks[i+1]; ++j) {
        myder.displacement[j]=weights[i]*tder.displacement[n];  // Multiplication by weights here ensures that normalisation is done correctly
        if( tder.centeredpos.size()>0 ) {
          myder.centeredpos[j]=tder.centeredpos[n];
          for(unsigned p=0; p<3; ++p) for(unsigned q=0; q<3; ++q) myder.DRotDPos(p,q)[j]=tder.DRotDPos(p,q)[n];
        }
        n++;
      }
    }
    // Make sure virial status is set correctly in output derivative pack
    // This is only done here so I do this by using class friendship
    if( tder.virialWasSet() ) myder.boxWasSet=true;
  }
  if( !myder.updateComplete() ) myder.updateDynamicLists();

  if( !squared ) {
    totd=sqrt(totd); double xx=0.5/totd;
    myder.scaleAllDerivatives( xx );
  }
  return totd;
}
Пример #3
0
double MultiDomainRMSD::projectAtomicDisplacementOnVector( const bool& normalized, const std::vector<Vector>& vecs, ReferenceValuePack& mypack ) const {
  double totd=0.; std::vector<Vector> tvecs; mypack.clear();
  MultiValue tvals( 1, mypack.getNumberOfDerivatives() ); ReferenceValuePack tder( 0, getNumberOfAtoms(), tvals );
  for(unsigned i=0; i<domains.size(); ++i) {
    // Must extract appropriate positions here
    tvecs.resize( blocks[i+1] - blocks[i] ); domains[i]->setupPCAStorage( tder );
    if( tder.centeredpos.size()>0 ) {
      for(unsigned p=0; p<3; ++p) for(unsigned q=0; q<3; ++q) tder.DRotDPos(p,q).resize( tvecs.size() );
    }
    // Extract information from storage pack and put in local pack
    if( tder.centeredpos.size()>0 ) tder.rot[0]=mypack.rot[i];
    unsigned n=0;
    for(unsigned j=blocks[i]; j<blocks[i+1]; ++j) {
      tder.setAtomIndex(n,j); tvecs[n] = vecs[j]; tder.displacement[n]=mypack.displacement[j] / weights[i];
      if( tder.centeredpos.size()>0 ) {
        tder.centeredpos[n]=mypack.centeredpos[j];
        for(unsigned p=0; p<3; ++p) for(unsigned q=0; q<3; ++q) tder.DRotDPos(p,q)[n]=mypack.DRotDPos(p,q)[j];
      }
      n++;
    }
    for(unsigned k=n; k<getNumberOfAtoms(); ++k) tder.setAtomIndex(k,3*vecs.size()+10);

    // Do the calculations
    totd += weights[i]*domains[i]->projectAtomicDisplacementOnVector( normalized, tvecs, tder );

    // And derivatives
    mypack.copyScaledDerivatives( 0, weights[i], tvals );
  }
  if( !mypack.updateComplete() ) mypack.updateDynamicLists();

  return totd;
}