void colvarvalue::set_random() { size_t ic; switch (this->type()) { case colvarvalue::type_scalar: this->real_value = cvm::rand_gaussian(); break; case colvarvalue::type_3vector: case colvarvalue::type_unit3vector: case colvarvalue::type_unit3vectorderiv: this->rvector_value.x = cvm::rand_gaussian(); this->rvector_value.y = cvm::rand_gaussian(); this->rvector_value.z = cvm::rand_gaussian(); break; case colvarvalue::type_quaternion: case colvarvalue::type_quaternionderiv: this->quaternion_value.q0 = cvm::rand_gaussian(); this->quaternion_value.q1 = cvm::rand_gaussian(); this->quaternion_value.q2 = cvm::rand_gaussian(); this->quaternion_value.q3 = cvm::rand_gaussian(); break; case colvarvalue::type_vector: for (ic = 0; ic < this->vector1d_value.size(); ic++) { this->vector1d_value[ic] = cvm::rand_gaussian(); } break; case colvarvalue::type_notset: default: undef_op(); break; } }
std::string colvarvalue::to_simple_string() const { switch (type()) { case colvarvalue::type_scalar: return cvm::to_str(real_value, 0, cvm::cv_prec); break; case colvarvalue::type_3vector: case colvarvalue::type_unit3vector: case colvarvalue::type_unit3vectorderiv: return rvector_value.to_simple_string(); break; case colvarvalue::type_quaternion: case colvarvalue::type_quaternionderiv: return quaternion_value.to_simple_string(); break; case colvarvalue::type_vector: return vector1d_value.to_simple_string(); break; case colvarvalue::type_notset: default: undef_op(); break; } return std::string(); }
int colvarvalue::from_simple_string(std::string const &s) { switch (type()) { case colvarvalue::type_scalar: return ((std::istringstream(s) >> real_value) ? COLVARS_OK : COLVARS_ERROR); break; case colvarvalue::type_3vector: case colvarvalue::type_unit3vector: case colvarvalue::type_unit3vectorderiv: return rvector_value.from_simple_string(s); break; case colvarvalue::type_quaternion: case colvarvalue::type_quaternionderiv: return quaternion_value.from_simple_string(s); break; case colvarvalue::type_vector: return vector1d_value.from_simple_string(s); break; case colvarvalue::type_notset: default: undef_op(); break; } return COLVARS_ERROR; }
void colvarvalue::set_ones(cvm::real assigned_value) { size_t ic; switch (this->type()) { case colvarvalue::type_scalar: this->real_value = assigned_value; break; case colvarvalue::type_3vector: case colvarvalue::type_unit3vector: case colvarvalue::type_unit3vectorderiv: this->rvector_value.x = assigned_value; this->rvector_value.y = assigned_value; this->rvector_value.z = assigned_value; break; case colvarvalue::type_quaternion: case colvarvalue::type_quaternionderiv: this->quaternion_value.q0 = assigned_value; this->quaternion_value.q1 = assigned_value; this->quaternion_value.q2 = assigned_value; this->quaternion_value.q3 = assigned_value; break; case colvarvalue::type_vector: for (ic = 0; ic < this->vector1d_value.size(); ic++) { this->vector1d_value[ic] = assigned_value; } break; case colvarvalue::type_notset: default: undef_op(); break; } }