Ejemplo n.º 1
0
Frames CompartmentReportCommon::loadFrames(double start, double end) const
{
    const auto startTime = getStartTime();
    if (start >= getEndTime() || end < startTime || end <= start)
        return Frames();

    const double timestep = getTimestep();
    const size_t startFrame = _getFrameNumber(start);
    end = std::nextafter(end, -INFINITY);
    const size_t count = _getFrameNumber(end) - startFrame + 1;

    Frames frames;

    frames.timeStamps.reset(new std::vector<double>);
    for (size_t i = 0; i < count; ++i)
        frames.timeStamps->push_back(startTime + (i + startFrame) * timestep);

    const auto frameSize = getFrameSize();
    frames.data.reset(new floats(frameSize * count));
    if (frameSize == 0)
        return frames;

    if (!_loadFrames(startFrame, count, frames.data->data()))
        return Frames();

    return frames;
}
Ejemplo n.º 2
0
H5::DataSet CompartmentReportHDF5::_createDataset( const uint32_t gid,
                                                   const size_t compCount )
{
    LBASSERT( compCount > 0 );
    LBASSERT( !_reportName.empty( ));

    std::ostringstream neuronName;
    neuronName << "a" << gid;

    H5::Group neuronGroup = _file.createGroup( neuronName.str().c_str( ));
    H5::Group reportGroup = neuronGroup.createGroup( _reportName );

    const int dims = 2;
    const size_t numSteps = (getEndTime() - getStartTime()) / getTimestep();
    const hsize_t mappingDim[dims] = { 1, compCount };
    const hsize_t dataDim[dims] = { numSteps, compCount };
    LBASSERT( numSteps > 0 );

    H5::DataSpace mappingDataspace( dims, mappingDim );
    H5::DataSpace dataDataspace( dims, dataDim );

    H5::DataSet mappingDataset = reportGroup.createDataSet(
             mappingDatasetName, H5::PredType::NATIVE_FLOAT, mappingDataspace );
    H5::DataSet dataDataset = reportGroup.createDataSet( dataDatasetName,
                                    H5::PredType::NATIVE_FLOAT, dataDataspace );

    _datas[gid] = dataDataset;

    _createMappingAttributes( mappingDataset );
    _createDataAttributes( dataDataset );

    return mappingDataset;
}
Ejemplo n.º 3
0
  void NormalModeLangLf::run(int numTimesteps) {
    //Real h = getTimestep() * Constant::INV_TIMEFACTOR;
    Real actTime;

    if( numTimesteps < 1 )
      return;

    //check valid eigenvectors
    if(*Q == NULL)
        report << error << "No Eigenvectors for NormalMode integrator."<<endr;
    //
    //time calculated in forces! so fix here
    actTime = app->topology->time + numTimesteps * getTimestep();
    //
    //main loop
    for( int i = 0; i < numTimesteps; i++ ) {
      //****main loop*************************************
      preStepModify();
      genProjGauss(&gaussRandCoord1, app->topology);
      doHalfKick();
      //
      //nmlDrift(&app->positions, &app->velocities, h, app->topology);
      doDrift();
      //constraints?
      app->energies.clear();
      //run minimizer if any remaining modes
      if(testRemainingModes()) myNextIntegrator->run(myCycleLength); //cyclelength 
      if(app->eigenInfo.reDiagonalize){	//rediagonalize?
            app->topology->time = actTime + (i - numTimesteps) * getTimestep();
            if(myPreviousIntegrator == NULL) 
                report << error << "[NormalModeLangLf::Run] Re-diagonalization forced with NormalModeLangLf as outermost Integrator. Aborting."<<endr;
            return;
      }
      //calculate sub space forces
      app->energies.clear();
      calculateForces();
      //
      genProjGauss(&gaussRandCoord1, app->topology);
      doHalfKick();
      //
      postStepModify();
    }
    //fix time
    app->topology->time = actTime;
    //
  }  
Ejemplo n.º 4
0
void fluidControlWidget::updateTimeStep()
{
	if(mySimulation == NULL){
		initSimulation();
	}
	stepSize = getTimestep();

	stringstream ss;
	ss << "Timestep Size (" << stepSize << ")";
	this->stepSliderLabel->setText(ss.str().c_str());

	this->mySimulation->setStepSize(stepSize);
//	this->mySimulation->pathTraceAndShow(stepSize);
}
Ejemplo n.º 5
0
size_t CompartmentReportCommon::_getFrameNumber(double timestamp) const
{
    const auto startTime = getStartTime();
    const auto endTime = getEndTime();
    assert(endTime > startTime);
    const auto step = getTimestep();

    timestamp =
        std::max(std::min(timestamp, std::nextafter(endTime, -INFINITY)),
                 startTime) -
        startTime;

    return size_t(timestamp / step);
}
Ejemplo n.º 6
0
  void NormalModeLangLf::doHalfKick() {
    const Real dt = getTimestep() * Constant::INV_TIMEFACTOR; // in fs
    const Real fdt = ( 1.0 - exp( -0.5 * myGamma * dt ) ) / myGamma;
    const Real vdt = exp(-0.5*myGamma*dt);
    const Real ndt = sqrt( ( 1.0 - exp( -myGamma * dt ) ) / (2.0 * myGamma) ); //was sqrt( fdt );
    const Real sqrtFCoverM = sqrt( 2.0 * Constant::BOLTZMANN * myTemp * myGamma );

    for( int i = 0; i < _N; i++ ) {
        // semi-update velocities
        app->velocities[i] = app->velocities[i]*vdt
                                +(*myForces)[i] * fdt / app->topology->atoms[i].scaledMass
                                    +gaussRandCoord1[i]*sqrtFCoverM*ndt;
    }
    subspaceVelocity(&app->velocities, &app->velocities);
    buildMolecularMomentum(&app->velocities, app->topology);
  }
Ejemplo n.º 7
0
void CompartmentReportHDF5::_createDataAttributes( H5::DataSet& dataset )
{
    const int rank = 0;
    const double startTime = getStartTime();
    const double endTime = getEndTime();
    const double timestep = getTimestep();

    H5::Attribute rankAttr = dataset.createAttribute( dataAttributes[0],
                                     H5::PredType::NATIVE_INT, H5S_SCALAR );
    H5::Attribute tstartAttr = dataset.createAttribute( dataAttributes[1],
                                  H5::PredType::NATIVE_DOUBLE, H5S_SCALAR );
    H5::Attribute tstopAttr = dataset.createAttribute( dataAttributes[2],
                                  H5::PredType::NATIVE_DOUBLE, H5S_SCALAR );
    H5::Attribute dtAttr = dataset.createAttribute( dataAttributes[3],
                                  H5::PredType::NATIVE_DOUBLE, H5S_SCALAR );

    rankAttr.write( H5::PredType::NATIVE_INT, &rank );
    tstartAttr.write( H5::PredType::NATIVE_DOUBLE, &startTime );
    tstopAttr.write( H5::PredType::NATIVE_DOUBLE, &endTime );
    dtAttr.write( H5::PredType::NATIVE_DOUBLE, &timestep );
    detail::addStringAttribute( dataset, dataAttributes[4], _dunit );
    detail::addStringAttribute( dataset, dataAttributes[5], _tunit );
}
Ejemplo n.º 8
0
  long NormalModeMori::run(const long numTimesteps) {
    Real h = getTimestep() * Constant::INV_TIMEFACTOR;
    Real actTime;

    if( numTimesteps < 1 ) return 0;

    //check valid eigenvectors
    if(*Q == NULL)
        report << error << "No Eigenvectors for NormalMode integrator."<<endr;
    //
    //time calculated in forces! so fix here
    actTime = app->topology->time + numTimesteps * getTimestep();
    //
    //main loop
    for( int i = 0; i < numTimesteps; i++ ) {
      //****main loop*************************************
      preStepModify();
      doHalfKick();
      //
      nmlDrift(&app->positions, &app->velocities, h, app->topology);
      //constraints?
      app->energies.clear();
      //run minimizer if any remaining modes
      if(testRemainingModes()) myNextIntegrator->run(myCycleLength); //cyclelength 
      if(*Q == NULL){	//rediagonalize?
            app->topology->time = actTime - (i - numTimesteps) * getTimestep();
            if(myPreviousIntegrator == NULL) 
                report << error << "[NormalModeMori::Run] Re-diagonalization forced with NormalModeMori as outermost Integrator. Aborting."<<endr;
            return i;
      }
      //#################Put averaged force code here##############################
      //calculate sub space forces, just do this for the energy
      Real minPotEnergy = (app->energies)[ScalarStructure::OTHER];	//save minimum potential energy
      app->energies.clear();
      calculateForces();
      //transfer the real average force, Note: force fields must be identical
      if(!instForce){
        for( unsigned int i=0;i < app->positions.size(); i++) (*myForces)[i] = myBottomNormalMode->tempV3DBlk[i];
      }
      (app->energies)[ScalarStructure::OTHER] = minPotEnergy;			//restore minimum potential energy
      //###########################################################################
      //
      doHalfKick();
      //
      postStepModify();
    }	
    //####diagnostics
    //output modes?
    if(modeOutput != ""){
        //get modes
        modeSpaceProj(tmpC, &app->positions, ex0);
        //Output modes for analysis
        ofstream myFile;
        myFile.open(modeOutput.c_str(),ofstream::app);
        myFile.precision(10);
        for(int ii=0;ii<_rfM-1;ii++) myFile << tmpC[ii] << ", ";
        myFile << tmpC[_rfM-1] << endl; //last
        //close file
        myFile.close();
    }
    //####
    //fix time
    app->topology->time = actTime;
    
    return numTimesteps;
  }  
Ejemplo n.º 9
0
 void NormalModeLangLf::doDrift() {
     const Real h = getTimestep() * Constant::INV_TIMEFACTOR;
     app->positions.intoWeightedAdd(h, app->velocities);
     buildMolecularCenterOfMass(&app->positions, app->topology);
 }
Ejemplo n.º 10
0
void fluidControlWidget::pathtrace()
{
	if(mySimulation != NULL){
		mySimulation->pathTraceAndShow(getTimestep());
	}
}
Ejemplo n.º 11
0
	void NormalModeOpenMM::run( int numTimesteps ) {
		if( numTimesteps < 1 ) {
			return;
		}

		//check valid eigenvectors
		if( mProtomolDiagonalize && *Q == NULL ) {
			report << error << "No Eigenvectors for NormalMode integrator." << endr;
		}

		if( mProtomolDiagonalize && app->eigenInfo.myEigVecChanged && myPreviousIntegrator != NULL ) {
			OpenMM::LTMD::Integrator *integ = dynamic_cast<OpenMM::LTMD::Integrator *>( integrator );
			if( integ ) {
				const unsigned int count = app->eigenInfo.myNumUsedEigenvectors;
				const unsigned int length = app->eigenInfo.myEigenvectorLength * 3;

				std::vector<EigenVector> vectors( count );

				for( unsigned int i = 0; i < count; i++ ) {
					vectors[i].resize( length / 3 );

					for( unsigned int j = 0; j < length; j++ ) {
						vectors[i][j / 3][j % 3] = app->eigenInfo.myEigenvectors[i * length + j];
					}
				}

				integ->setProjectionVectors( vectors );
			}

			app->eigenInfo.myEigVecChanged = false;
		}
		
		if( mLTMDParameters.ShouldProtoMolDiagonalize && app->eigenInfo.havePositionsChanged ){
			const unsigned int sz = app->positions.size();
			
			std::vector<OpenMM::Vec3> positions;
			positions.reserve( sz );
			
			OpenMM::Vec3 openMMvecp;
			for( unsigned int i = 0; i < sz; ++i ) {
				for( int j = 0; j < 3; j++ ) {
					openMMvecp[j] = app->positions[i].c[j] * Constant::ANGSTROM_NM;
				}
				positions.push_back( openMMvecp );
			}
			
			context->setPositions( positions );
			
			app->eigenInfo.havePositionsChanged = false;
		}
		
		OpenMMIntegrator::run( numTimesteps );
		
		if( mLTMDParameters.ShouldProtoMolDiagonalize && mLTMDParameters.ShouldForceRediagOnMinFail ){
			OpenMM::LTMD::Integrator *ltmd = dynamic_cast<OpenMM::LTMD::Integrator*>( integrator );
			if( ltmd ){
				const unsigned int completed = ltmd->CompletedSteps();
				const unsigned int remaining = numTimesteps - completed;
				
				if( completed != numTimesteps ) {
					app->eigenInfo.reDiagonalize = true;
					
					//fix time as no forces calculated
					app->topology->time -= remaining * getTimestep();
					
					//Fix steps
					app->currentStep -= remaining;
					std::cout << "OpenMM Failed Minimization" << std::endl;
				}
			}
		}
	}
Ejemplo n.º 12
0
  void NormalModeQuadratic::run( int numTimesteps )
  {

    //check valid eigenvectors
    if ( *Q == NULL ){
      report << error << "No Eigenvectors for NormalMode integrator." << endr;
    }

    if ( app->eigenInfo.myEigenvalues.size() <
         (unsigned)firstMode + numMode - 1 ){
      report << error << "Insufficient Eigenvalues for Quadratic integrator (" << app->eigenInfo.myEigenvalues.size() << "." << endr;
    }

    if ( numTimesteps < 1 ){
      return;
    }

    //timestep
    Real h = getTimestep() * Constant::INV_TIMEFACTOR;

    //time calculated in forces! so fix here
    Real actTime = app->topology->time + numTimesteps * getTimestep();

    Real tempFrq;
    Real tempKt = sqrt( 2.0 * myTemp * Constant::BOLTZMANN );

    //find ex0 if re-diag present
    if ( myPreviousNormalMode && myPreviousNormalMode->newDiag ) {
      //reset ex0 and restart time for \omega t if new diagonalization
      *ex0 = myPreviousNormalMode->diagAt;

      total_time = 0;
    }

    //main loop
    for ( int i = 0; i < numTimesteps; i++ ) {
      preStepModify();

      numSteps++;
      if ( stepModes ) {

        //set mode
        if ( !( numSteps % cycleSteps ) ) {
          cPos[currMode++] = 0.0;
          app->positions = *ex0;

          if ( currMode >= firstMode + numMode - 1 ) {
            currMode = firstMode - 1;
          }
        }

        app->eigenInfo.currentMode = currMode + 1;

        //****Analytical mode integrator loop*****
        tempFrq = sqrt( fabs( app->eigenInfo.myEigenvalues[currMode] ) );
        cPos[currMode] = tempKt * sin( ( double )( numSteps % cycleSteps ) / ( double )cycleSteps * 2.0 * M_PI );

        cPos[currMode] /= fScale ? tempFrq : sqrt( tempFrq );

        subspaceProj( cPos, &app->positions );
      } else {
        //full dynamics here
        int startm = firstMode - 1;
        if ( startm < 7 ) {
          startm = 7;
        }

        for ( int i = startm; i < firstMode + numMode - 1;i++ ) {
          //****Analytical mode integrator loop*****
          tempFrq = sqrt( fabs( app->eigenInfo.myEigenvalues[i] ) );
          cPos[i] = tempKt * sin( total_time * tempFrq );

          cPos[i] /= fScale ? tempFrq : sqrt( tempFrq );
        }

        subspaceProj( cPos, &app->positions );
      }

      postStepModify();
      total_time += h;
    }

    //fix time
    app->topology->time = actTime;

  }