double VectorMultiColvar::doCalculation(){ // Now calculate the vector calculateVector(); // Sort out the active derivatives updateActiveAtoms(); // Now calculate the norm of the vector (this is what we return here) double norm=0, inorm; if(complexvec){ for(unsigned i=0;i<ncomponents;++i) norm += getComponent(i)*getComponent(i) + getImaginaryComponent(i)*getImaginaryComponent(i); norm=sqrt(norm); inorm = 1.0 / norm; for(unsigned i=0;i<ncomponents;++i){ dervec[i] = inorm*getComponent(i); dervec[ncomponents+i] = inorm*getImaginaryComponent(i); } } else { for(unsigned i=0;i<ncomponents;++i) norm += getComponent(i)*getComponent(i); norm=sqrt(norm); inorm = 1.0 / norm; for(unsigned i=0;i<ncomponents;++i) dervec[i] = inorm*getComponent(i); } if( usingLowMem() ){ vecs->storeDerivativesLowMem( 0 ); vecs->chainRule( 0, dervec ); } else { vecs->storeDerivativesHighMem( getCurrentPositionInTaskList() ); vecs->chainRule( getCurrentPositionInTaskList(), dervec ); } // Add derivatives to base multicolvars Vector tmpd; for(unsigned i=0;i<atoms_with_derivatives.getNumberActive();++i){ unsigned k=atoms_with_derivatives[i]; tmpd[0]=vecs->getFinalDerivative(3*i+0); tmpd[1]=vecs->getFinalDerivative(3*i+1); tmpd[2]=vecs->getFinalDerivative(3*i+2); MultiColvarBase::addAtomsDerivatives( 0, k, tmpd ); } unsigned vvbase=3*atoms_with_derivatives.getNumberActive(); Tensor tmpv; for(unsigned i=0;i<3;++i){ for(unsigned j=0;j<3;++j){ tmpv(i,j) = vecs->getFinalDerivative( vvbase+3*i+j ); } } MultiColvarBase::addBoxDerivatives( 0, tmpv ); return norm; }
double VectorMultiColvar::doCalculation( const unsigned& taskIndex, multicolvar::AtomValuePack& myatoms ) const { // Now calculate the vector calculateVector( myatoms ); // Sort out the active derivatives updateActiveAtoms( myatoms ); // Now calculate the norm of the vector (this is what we return here) double norm=0; for(unsigned i=0;i<ncomponents;++i) norm += myatoms.getValue(2+i)*myatoms.getValue(2+i); norm=sqrt(norm); if( !doNotCalculateDerivatives() ){ double inorm = 1.0 / norm; std::vector<double> dervec( ncomponents ); for(unsigned i=0;i<ncomponents;++i) dervec[i] = inorm*myatoms.getValue(2+i); MultiValue& myvals=myatoms.getUnderlyingMultiValue(); for(unsigned j=0;j<myvals.getNumberActive();++j){ unsigned jder=myvals.getActiveIndex(j); for(unsigned i=0;i<ncomponents;++i) myvals.addDerivative( 1, jder, dervec[i]*myvals.getDerivative( 2+i, jder ) ); } } return norm; }
Radians WayHeading::calculateHeading(const WayLocation& loc, Meters delta) { Coordinate v = calculateVector(loc, delta); return atan2(v.x, v.y); }