/** * \file CMMLogOptimizerState.h * \brief A state which writes a series of CMM files. * * Copyright 2007-8 Sali Lab. All rights reserved. * */ #include #include #include "IMP/optimizers/states/CMMLogOptimizerState.h" #include "IMP/decorators/XYZDecorator.h" namespace IMP { CMMLogOptimizerState::CMMLogOptimizerState(std::string filename, const Particles &pis) : pis_(pis), filename_(filename), file_number_(0), call_number_(0), skip_steps_(0) { } void CMMLogOptimizerState::update() { // std::cout << " CMMLogOptimizerState::update skip_steps_: " << skip_steps_ << " call_number_: " << call_number_ << std::endl; if (skip_steps_ == 0 || (call_number_ % skip_steps_) == 0) { char buf[1000]; sprintf(buf, filename_.c_str(), file_number_); ++file_number_; write(buf); } ++call_number_; } void CMMLogOptimizerState::write(std::string buf) const { std::ofstream out(buf.c_str()); if (!out) { IMP_WARN("Error opening CMM log file " << buf); } else { IMP_LOG(VERBOSE, "Writing " << pis_.size() << " particles to file " << buf << "..." << std::flush); std::stringstream filename; filename << "optimization_step_" << call_number_; write(pis_, filename.str() ,radius_, r_, g_, b_, out); //IMP_LOG(TERSE, "done" << std::endl); } } static Float snap(Float f) { if (f < 0) return 0; if (f > 1) return 1; return f; } void CMMLogOptimizerState::write(const Particles &pis, const std::string &marker_set_name, FloatKey radius_key, FloatKey r_key, FloatKey g_key, FloatKey b_key, std::ostream &out) { out << ""<has_attribute(r_key) && p->has_attribute(g_key) && p->has_attribute(b_key)) { rv = snap(p->get_value(r_key)); gv = snap(p->get_value(g_key)); bv = snap(p->get_value(b_key)); } Float radius = 5.; if (radius_key != FloatKey() && p->has_attribute(radius_key)) { radius = p->get_value(radius_key); } out <<""<< std::endl; } catch (InvalidStateException &e) { IMP_WARN("Particle " << pis[i] << " does not have " << " cartesian coordinates"); } } out << "" << std::endl; } void CMMLogOptimizerState::show(std::ostream &out) const { out << "Writing CMM files " << filename_ << std::endl; } } // namespace IMP