void 
  GVolumetricPotential::operator<<(const magnet::xml::Node& XML) {
    globName = XML.getAttribute("Name");
    _fileName = XML.getAttribute("RawFile");
    _sampleBytes = XML.getAttribute("SampleBytes").as<size_t>();


    //Load the dimensions of the data set (and its subset of data if
    //only processing a smaller section)
    auto XMLdim = XML.getNode("Dimensions");
    _imageDimensions = std::array<size_t, 3>{{XMLdim.getAttribute("x").as<size_t>(), XMLdim.getAttribute("y").as<size_t>(), XMLdim.getAttribute("z").as<size_t>()}};
    
    _offset = std::array<size_t, 3>{{0, 0, 0}};
    if (XML.hasNode("Offset"))
      {
	auto XMLdim = XML.getNode("Offset");
	_offset = std::array<size_t, 3>{{XMLdim.getAttribute("x").as<size_t>(), XMLdim.getAttribute("y").as<size_t>(), XMLdim.getAttribute("z").as<size_t>()}};
      }

    std::array<size_t, 3> sampleDimensions = _imageDimensions;
    if (XML.hasNode("SampleDimensions"))
      {
	auto XMLdim = XML.getNode("SampleDimensions");
	sampleDimensions = std::array<size_t, 3>{{XMLdim.getAttribute("x").as<size_t>(), XMLdim.getAttribute("y").as<size_t>(), XMLdim.getAttribute("z").as<size_t>()}};
      }

    Ordering fileOrdering(_imageDimensions);
    std::vector<unsigned char> fileData(fileOrdering.size() * _sampleBytes);
    dout << "Opening " << _fileName << std::endl;
    std::ifstream file(_fileName.c_str(), std::ifstream::binary);

    if (!file.good())
      M_throw() << "Failed open the file " << _fileName;
    dout << "Reading " << fileOrdering.size() * _sampleBytes << " bytes of data into memory" <<  std::endl;
    file.read(reinterpret_cast<char*>(fileData.data()), fileOrdering.size() * _sampleBytes);
    
    if (!file)
      M_throw() << "Failed reading volumetric data (read " << file.gcount() << " bytes of an expected " << fileOrdering.size() * _sampleBytes << "  from " << _fileName << ")";
    file.close();

    _ordering = Ordering(sampleDimensions);
    _volumeData.resize(_ordering.size());

    dout << "Resampling " << _ordering.size() << " bytes of data from the file into the simulation" <<  std::endl;
    if (_sampleBytes == 1)
      {
	if (sampleDimensions == _imageDimensions)
	  std::swap(_volumeData, fileData);
	else
	  for (size_t z = 0; z < sampleDimensions[2]; ++z)
	    for (size_t y = 0; y < sampleDimensions[1]; ++y)
	      {
		size_t startindex = fileOrdering.toIndex(std::array<size_t, 3>{{_offset[0], y + _offset[1], z + _offset[2]}});
		std::copy(fileData.begin() + startindex, fileData.begin() + startindex + sampleDimensions[0], _volumeData.begin() + _ordering.toIndex(std::array<size_t, 3>{{0, y, z}}));
	      }
      }
    else
      M_throw() << "Do not have an optimised loader for resampling data yet";
    dout << "Loading complete" <<  std::endl;
  }
Beispiel #2
0
void 
IStepped::operator<<(const magnet::xml::Node& XML)
{
  if (strcmp(XML.getAttribute("Type"),"Stepped"))
    M_throw() << "Attempting to load Stepped from non Stepped entry";
  
  range.set_ptr(C2Range::getClass(XML,Sim));
  
  try {
    intName = XML.getAttribute("Name");

    if (!XML.hasNode("Step"))
      M_throw() << "No steppings defined for stepped potential " 
		<< intName;

    for (magnet::xml::Node node = XML.fastGetNode("Step"); node.valid(); ++node)
      steps.push_back(steppair(node.getAttribute("R").as<double>(),
			       node.getAttribute("E").as<double>()));
    
    std::sort(steps.rbegin(), steps.rend());

    IMultiCapture::loadCaptureMap(XML);
  }
  catch (boost::bad_lexical_cast &)
    {
      M_throw() << "Failed a lexical cast in CIStepped";
    }

  if (steps.empty())
    M_throw() << "No steps defined in SteppedPotential Interaction with name " 
	      << getName();
}
Beispiel #3
0
 void 
 Topology::operator<<(const magnet::xml::Node& XML)
 {
   _name = XML.getAttribute("Name");
   
   if (!XML.hasNode("Molecule"))
     M_throw() << "Cannot load a Topology which has no molecules!";
 }
Beispiel #4
0
  void 
  ICapture::loadCaptureMap(const magnet::xml::Node& XML)
  {
    if (XML.hasNode("CaptureMap"))
      {
	_mapUninitialised = false;
	clear();

	for (magnet::xml::Node node = XML.getNode("CaptureMap").findNode("Pair"); node.valid(); ++node)
	  Map::operator[](Map::key_type(node.getAttribute("ID1").as<size_t>(), node.getAttribute("ID2").as<size_t>()))
	    = node.getAttribute("val").as<size_t>();
      }
  }
Beispiel #5
0
LNewtonianMC::LNewtonianMC(dynamo::SimData* tmp, const magnet::xml::Node& XML):
  LNewtonian(tmp),
  EnergyPotentialStep(1)
{
  if (strcmp(XML.getAttribute("Type"),"NewtonianMC"))
    M_throw() << "Attempting to load NewtonianMC from " 
	      << XML.getAttribute("Type")
	      << " entry";
  try 
    {     
      if (XML.hasNode("PotentialDeformation"))
	if (XML.getNode("PotentialDeformation").hasAttribute("EnergyStep"))
	  EnergyPotentialStep 
	    = XML.getNode("PotentialDeformation").getAttribute("EnergyStep").as<double>();
      
      EnergyPotentialStep /= Sim->dynamics.units().unitEnergy();
      
      if (dynamic_cast<const dynamo::EnsembleNVT*>(Sim->ensemble.get()) == NULL)
	M_throw() << "Multi-canonical simulations require an NVT ensemble";

      if (XML.hasNode("PotentialDeformation"))
	for (magnet::xml::Node node = XML.getNode("PotentialDeformation").fastGetNode("W"); 
	     node.valid(); ++node)
	  {
	    double energy = node.getAttribute("Energy").as<double>() / Sim->dynamics.units().unitEnergy();	    
	    double Wval = node.getAttribute("Value").as<double>();
	    
	    //Here, the Wval needs to be multiplied by kT to turn it
	    //into an Energy, but the Ensemble is not yet initialised,
	    //we must do this conversion later, when we actually use the W val.
	    _W[lrint(energy / EnergyPotentialStep)] = Wval;
	  }
    }
  catch (boost::bad_lexical_cast &)
    { M_throw() << "Failed a lexical cast in LNewtonianMC"; }
}
Beispiel #6
0
void
IMultiCapture::loadCaptureMap(const magnet::xml::Node& XML)
{
    if (XML.hasNode("CaptureMap"))
    {
        noXmlLoad = false;
        clear();

        for (magnet::xml::Node node = XML.getNode("CaptureMap").fastGetNode("Pair");
                node.valid(); ++node)
            captureMap[cMapKey(node.getAttribute("ID1").as<size_t>(),
                               node.getAttribute("ID2").as<size_t>())]
                = node.getAttribute("val").as<size_t>();
    }
}
Beispiel #7
0
  void 
  Topology::operator<<(const magnet::xml::Node& XML)
  {
    try { spName = XML.getAttribute("Name"); } 
    catch (boost::bad_lexical_cast &)
      {
	M_throw() << "Failed a lexical cast in CTopology";
      }
    
    if (!XML.hasNode("Molecule"))
      M_throw() << "Cannot load a Topology which has no molecules!";

    for (magnet::xml::Node node = XML.fastGetNode("Molecule"); node.valid(); ++node)
      ranges.push_back(shared_ptr<IDRange>(IDRange::getClass(node.getNode("IDRange"), Sim)));
  }
Beispiel #8
0
  void 
  LBoundary::operator<<(const magnet::xml::Node& XML)
  {
    range = shared_ptr<IDRange>(IDRange::getClass(XML.getNode("IDRange"),Sim));
    localName = XML.getAttribute("Name");

    _oscillationData._origin << XML.getNode("Origin");
    _oscillationData._origin *= Sim->units.unitLength();
    _diameter = Sim->_properties.getProperty(XML.getAttribute("Diameter"), Property::Units::Length());
    if (_diameter->getMaxValue() == 0)
      M_throw() << "Cannot have a boundary with a diameter of zero";

    _oscillationData._amplitude = Vector();
    _oscillationData._freq = 0;
    _oscillationData._t_shift = 0;
    
    const size_t data_count = XML.hasNode("Amplitude") + XML.hasAttribute("Frequency") + XML.hasAttribute("Phase");
    if ((data_count != 3) && (data_count != 0))
      M_throw() << "For oscillating walls you must have an Amplitude, Frequency, and Phase specified."
		<< XML.getPath();

    if (data_count == 3) {
      _oscillationData._freq = XML.getAttribute("Frequency").as<double>() / Sim->units.unitTime();
      _oscillationData._t_shift = XML.getAttribute("Phase").as<double>() * Sim->units.unitTime();
      _oscillationData._amplitude << XML.getNode("Amplitude");
      _oscillationData._amplitude *= Sim->units.unitLength();
    }

    _kT = 0;
    if (XML.hasAttribute("kT")) {
      if (data_count == 3)
	M_throw() << "Cannot have both a thermalised wall and a oscillating wall" 
		  << XML.getPath();
      
      _kT = XML.getAttribute("kT").as<double>() * Sim->units.unitEnergy();
    }

    if (_kT < 0)
      M_throw() << "Temperature is less than zero" << XML.getPath();

    for (magnet::xml::Node node = XML.findNode("Object"); node.valid(); ++node)
      _objects.push_back(boundary::Object::getClass(node, Sim, _oscillationData));

    if (_objects.empty())
      M_throw() << "Boundary Locals must have at least one Object.\n" << XML.getPath();
  }
Beispiel #9
0
  void 
  GSOCells::operator<<(const magnet::xml::Node& XML)
  {
    globName = XML.getAttribute("Name");
    
    if (XML.hasNode("CellOrigins")) {
      Vector pos;
      for (magnet::xml::Node node = XML.getNode("CellOrigins").findNode("Origin"); node.valid(); ++node) {
	pos << node;
	pos *= Sim->units.unitLength();
	cell_origins.push_back(pos);
      }

      if (cell_origins.size() != Sim->N())
	M_throw() << "Number of CellOrigins (" << cell_origins.size() << ") does not match number of particles (" << Sim->N() << ")\n" << XML.getPath();
    }

    if (XML.hasAttribute("Diameter"))
      _cellD = XML.getAttribute("Diameter").as<double>() * Sim->units.unitLength();
  }
DynNewtonianMCCMap::DynNewtonianMCCMap(dynamo::Simulation* tmp, const magnet::xml::Node& XML):
    DynNewtonian(tmp)
{
    _interaction_name = XML.getAttribute("Interaction");

    if (XML.hasNode("Potential"))
    {
        for (magnet::xml::Node map_node = XML.getNode("Potential").findNode("Map");
                map_node.valid(); ++map_node)
        {
            double Wval = map_node.getAttribute("W").as<double>();
            size_t distance = map_node.getAttribute("Distance").as<size_t>();

            detail::CaptureMap map;
            for (magnet::xml::Node entry_node = map_node.findNode("Contact"); entry_node.valid(); ++entry_node)
                map[detail::CaptureMap::key_type(entry_node.getAttribute("ID1").as<size_t>(), entry_node.getAttribute("ID2").as<size_t>())]
                    = entry_node.getAttribute("State").as<size_t>();
            _W.push_back(std::make_pair(map, WData(distance, Wval)));
        }
    }
}
Beispiel #11
0
  DynNewtonianMC::DynNewtonianMC(dynamo::Simulation* tmp, const magnet::xml::Node& XML):
    DynNewtonian(tmp),
    EnergyPotentialStep(1)
  {
    if (XML.hasNode("PotentialDeformation"))
      {
	EnergyPotentialStep 
	  = XML.getNode("PotentialDeformation").getAttribute("EnergyStep").as<double>()
	  / Sim->units.unitEnergy();

	for (magnet::xml::Node node = XML.getNode("PotentialDeformation").fastGetNode("W"); 
	     node.valid(); ++node)
	  {
	    double energy = node.getAttribute("Energy").as<double>() / Sim->units.unitEnergy();	    
	    double Wval = node.getAttribute("Value").as<double>();
		
	    //Here, the Wval needs to be multiplied by kT to turn it
	    //into an Energy, but the Ensemble is not yet initialised,
	    //we must do this conversion later, when we actually use the W val.
	    _W[lrint(energy / EnergyPotentialStep)] = Wval;
	  }
      }
  }