Index: include/IMP/decorators/MolecularHierarchyDecorator.h =================================================================== --- include/IMP/decorators/MolecularHierarchyDecorator.h (revision 630) +++ include/IMP/decorators/MolecularHierarchyDecorator.h (working copy) @@ -42,7 +42,7 @@ - UNIVERSES is a set of universes - TRAJECTORY is an ordered set of UNIVERSES */ - enum Type {UNKNOWN=-1, ATOM, RESIDUE, NUCLEICACID, + enum Type {UNKNOWN=-1, ATOM, RESIDUE, NUCLEICACID, FRAGMENT, CHAIN, PROTEIN, NUCLEOTIDE, MOLECULE, UNIVERSE, UNIVERSES, TRAJECTORY }; Index: include/IMP/decorators/utility.h =================================================================== --- include/IMP/decorators/utility.h (revision 630) +++ include/IMP/decorators/utility.h (working copy) @@ -33,16 +33,16 @@ protected: \ static bool decorator_keys_initialized_; \ static void decorator_initialize_static_data(); \ - static bool has_required_attributes(Particle *p) { \ + static bool has_required_attributes(::IMP::Particle *p) { \ if (!Parent::has_required_attributes(p)) return false; \ check_required; \ } \ - static void add_required_attributes(Particle *p) { \ + static void add_required_attributes(::IMP::Particle *p) { \ Parent::add_required_attributes(p); \ add_required; \ } \ friend class DecoratorBase; \ - Name(Particle* p): Parent(p) { \ + Name(::IMP::Particle* p): Parent(p) { \ IMP_assert(has_required_attributes(p), \ "This is not a particle of type " \ << #Name << *p); \ @@ -52,15 +52,15 @@ /** The default constructor. This is used as a null value */ \ Name(): Parent(){} \ /** Add the necessary attributes to p and return a decorator. */ \ - static Name create(Particle *p) { \ - return DecoratorBase::create(p); \ + static Name create(::IMP::Particle *p) { \ + return IMP::DecoratorBase::create(p); \ } \ /** Check that p has the necessary attributes and return a decorator. \ \throws InvalidStateException if some required attributes are \ missing \ */ \ - static Name cast(Particle *p) { \ - return DecoratorBase::cast(p); \ + static Name cast(::IMP::Particle *p) { \ + return IMP::DecoratorBase::cast(p); \ } \ /** Write information about this decorator to out. Each line should \ prefixed by prefix*/ \ @@ -224,4 +224,5 @@ #define IMP_DECORATOR_ARRAY_INIT(DecoratorType, name, Type) \ number_of_##name##_key_= IntKey(#DecoratorType " num " #name); + #endif /* __IMP_DECORATOR_UTILITY_H */ Index: include/IMP/decorators/XYZDecorator.h =================================================================== --- include/IMP/decorators/XYZDecorator.h (revision 630) +++ include/IMP/decorators/XYZDecorator.h (working copy) @@ -24,48 +24,47 @@ class IMPDLLEXPORT XYZDecorator: public DecoratorBase { IMP_DECORATOR(XYZDecorator, DecoratorBase, - return p->has_attribute(x_key_) && p->has_attribute(y_key_) - && p->has_attribute(z_key_), - { p->add_attribute(x_key_, + return p->has_attribute(key_[0]) && p->has_attribute(key_[1]) + && p->has_attribute(key_[2]), + { p->add_attribute(key_[0], std::numeric_limits::infinity()); - p->add_attribute(y_key_, + p->add_attribute(key_[1], std::numeric_limits::infinity()); - p->add_attribute(z_key_, + p->add_attribute(key_[2], std::numeric_limits::infinity()); }); protected: - static FloatKey x_key_; - static FloatKey y_key_; - static FloatKey z_key_; + static FloatKey key_[3]; public: - IMP_DECORATOR_GET_SET(x, x_key_, Float, Float); - IMP_DECORATOR_GET_SET(y, y_key_, Float, Float); - IMP_DECORATOR_GET_SET(z, z_key_, Float, Float); - - void set_coordinate(int i, Float v) { - switch (i) { - case 0: set_x(v); break; - case 1: set_y(v); break; - case 2: set_z(v); break; - default: - throw IndexException("invalid coordinate"); - } + IMP_DECORATOR_GET_SET(x, key_[0], Float, Float); + IMP_DECORATOR_GET_SET(y, key_[1], Float, Float); + IMP_DECORATOR_GET_SET(z, key_[2], Float, Float); + //! set the ith coordinate + void set_coordinate(unsigned int i, Float v) { + get_particle()->set_value(get_coordinate_key(i), v); } + //! Get the ith coordinate Float get_coordinate(int i) const { - switch (i) { - case 0: return get_x(); - case 1: return get_y(); - case 2: return get_z(); - default: - throw IndexException("invalid coordinate"); - return 0; - } + return get_particle()->get_value(get_coordinate_key(i)); } - + //! Add something to the derivative of the ith coordinate + void add_to_coordinate_derivative(int i, Float v, + DerivativeAccumulator &d) { + get_particle()->add_to_derivative(get_coordinate_key(i), v, d); + } + //! Get a FloatKey to access the ith coordinate + static FloatKey get_coordinate_key(unsigned int i) { + decorator_initialize_static_data(); + IMP_check(i <3, "Out of range coordinate", + IndexException("Out of range coordinate")); + return key_[i]; + } }; + + IMP_OUTPUT_OPERATOR(XYZDecorator); //! Compute the distance between a pair of particles Index: src/decorators/AtomDecorator.cpp =================================================================== --- src/decorators/AtomDecorator.cpp (revision 630) +++ src/decorators/AtomDecorator.cpp (working copy) @@ -209,30 +209,6 @@ // ultimate the secondary info should be set from a // better source. But this is good enough for now. get_particle()->set_value(type_key_, t.get_index()); - /*std::string str=t.get_string(); - if (str.find("N") != std::string::npos) { - set_element(N); - set_van_der_waals_raidus(1.55); - } else if (str.find("O") != std::string::npos) { - set_element(O); - set_van_der_waals_raidus(1.52); - } else if (str.find("P") != std::string::npos) { - set_element(P); - set_van_der_waals_raidus(1.9); - } else if (str.find("C") != std::string::npos) { - set_element(C); - set_van_der_waals_raidus(1.7); - } else if (str.find("S") != std::string::npos) { - set_element(S); - set_van_der_waals_raidus(1.85); - } else if (str.find("OH") != std::string::npos) { - set_element(OH); - } else if (str.find("H2O") != std::string::npos) { - set_element(H2O); - } else if (str.find("H") != std::string::npos) { - set_element(H); - set_van_der_waals_radius(1.20); - }*/ } IMP_DECORATOR_INITIALIZE(AtomDecorator, XYZDecorator, @@ -244,69 +220,4 @@ type_key_ = IntKey("atom type"); }) - /*void AtomDecorator::set_element(std::string cp) -{ - if (std::strchr(cp.c_str(), 'C') != NULL) set_element(C); - else if (std::strchr(cp.c_str(),'N') != NULL) set_element( N); - else if (std::strchr(cp.c_str(),'S') != NULL) set_element( S); - else if (std::strchr(cp.c_str(),'O') != NULL) set_element( O); - else if (std::strchr(cp.c_str(),'H') != NULL) set_element( H); - else if (std::strstr(cp.c_str(),"FE") != NULL) set_element( FE); - else if (std::strstr(cp.c_str(),"P") != NULL) set_element( P); - else if (std::strstr(cp.c_str(),"PT") != NULL) set_element( PT); - else { - IMP_WARN("Unknown atom element string "<< cp.c_str() << std::endl); - } -} - -std::string AtomDecorator::get_element_string(int e) -{ - switch (e) { - case C: - return "C"; - case N: - return "N"; - case H: - return "H"; - case O: - return "O"; - case S: - return "S"; - case P: - return "P"; - case FE: - return "FE"; - case PT: - return "PT"; - default: - std::ostringstream oss; - oss << "Element " << e; - return oss.str().c_str(); - } -} - -void AtomDecorator::set_type(std::string e) -{ - if (string_to_type_.find(e) != string_to_type_.end()) { - set_type(string_to_type_.find(e)->second); - } else { - IMP_WARN("Unknown type string "<< - e << " perhaps it is not space-padded"); - } -} - -std::string AtomDecorator::get_type_string(Int t) -{ - if (type_to_string_.find(t) != type_to_string_.end()) { - return type_to_string_.find(t)->second.c_str(); - } else if (t== AT_UNKNOWN) { - return "Unknown"; - } else { - IMP_failure("Unknown type passed for getting string", - IndexException("Unknown type")); - return "Unknown"; - } - -}*/ - } // namespace IMP Index: src/decorators/XYZDecorator.cpp =================================================================== --- src/decorators/XYZDecorator.cpp (revision 630) +++ src/decorators/XYZDecorator.cpp (working copy) @@ -12,13 +12,10 @@ namespace IMP { -FloatKey XYZDecorator::x_key_; -FloatKey XYZDecorator::y_key_; -FloatKey XYZDecorator::z_key_; +FloatKey XYZDecorator::key_[3]; - void XYZDecorator::show(std::ostream &out, std::string prefix) const { out << prefix << "(" << get_x()<< ", " @@ -31,9 +28,9 @@ IMP_DECORATOR_INITIALIZE(XYZDecorator, DecoratorBase, { - x_key_= FloatKey("x"); - y_key_= FloatKey("y"); - z_key_= FloatKey("z"); + key_[0]= FloatKey("x"); + key_[1]= FloatKey("y"); + key_[2]= FloatKey("z"); }) namespace { template