9 #ifndef IMPRMF_SIMPLE_LINKS_H
10 #define IMPRMF_SIMPLE_LINKS_H
12 #include <IMP/rmf/rmf_config.h>
20 #include <RMF/SetCurrentFrame.h>
21 #include <RMF/names.h>
22 #include <RMF/decorators.h>
24 IMPRMF_BEGIN_NAMESPACE
36 virtual void do_load_one(RMF::NodeConstHandle nh, O *o) = 0;
37 void do_load(RMF::FileConstHandle fh) {
39 for (
unsigned int i = 0; i < os_.size(); ++i) {
41 do_load_one(fh.get_node(nhs_[i]), os_[i]);
44 virtual void do_add_link(O *, RMF::NodeConstHandle) {};
45 void add_link(O *o, RMF::NodeConstHandle nh) {
47 nhs_.push_back(nh.get_id());
48 set_association(nh, o,
true);
50 virtual bool get_is(RMF::NodeConstHandle nh)
const = 0;
51 virtual O *do_create(RMF::NodeConstHandle nh) {
IMP_FAILURE(
"Wrong create");}
52 virtual O *do_create(RMF::NodeConstHandle nh,
kernel::Model *m) {
61 IMP_LOG_TERSE(
"Creating IMP objects from " << rt << std::endl);
62 RMF::SetCurrentFrame sf(rt.get_file(), RMF::ALL_FRAMES);
63 RMF::NodeConstHandles ch = rt.get_children();
65 for (
unsigned int i = 0; i < ch.size(); ++i) {
72 o->set_was_used(
true);
82 IMP_LOG_TERSE(
"Creating Model objects from " << rt << std::endl);
83 RMF::SetCurrentFrame sf(rt.get_file(), RMF::ALL_FRAMES);
84 RMF::NodeConstHandles ch = rt.get_children();
86 for (
unsigned int i = 0; i < ch.size(); ++i) {
93 o->set_was_used(
true);
99 void link(RMF::NodeConstHandle rt,
102 IMP_LOG_TERSE(
"Linking " << rt <<
" to " << ps << std::endl);
104 RMF::SetCurrentFrame sf(rt.get_file(), RMF::ALL_FRAMES);
106 RMF::NodeConstHandles ch = rt.get_children();
108 for (
unsigned int i = 0; i < ch.size(); ++i) {
112 if (ps.size() <=
static_cast<unsigned int>(links)) {
113 IMP_THROW(
"There are too many matching hierarchies in the rmf to "
114 <<
"link against " << ps,
117 add_link(ps[links], ch[i]);
118 ps[links]->set_was_used(
true);
119 do_add_link(ps[links], ch[i]);
124 "Didn't find enough matching things.");
126 "Didn't find enough matching things. Found "
127 << links <<
" wanted " << ps.size());
141 virtual void do_save_one(O *o, RMF::NodeHandle nh) = 0;
142 void do_save(RMF::FileHandle fh) {
143 for (
unsigned int i = 0; i < os_.size(); ++i) {
146 os_[i]->set_was_used(
true);
148 do_save_one(os_[i], fh.get_node(nhs_[i]));
151 virtual void do_add(O *o, RMF::NodeHandle c) { add_link(o, c); }
152 virtual RMF::NodeType get_type(O *o)
const = 0;
153 void add_link(O *o, RMF::NodeConstHandle nh) {
155 nhs_.push_back(nh.get_id());
156 set_association(nh, o,
true);
164 RMF::FileHandle file = parent.get_file();
165 RMF::AliasFactory af(file);
166 RMF::SetCurrentFrame sf(parent.get_file(), RMF::ALL_FRAMES);
167 for (
unsigned int i = 0; i < os.size(); ++i) {
168 std::string nicename = RMF::get_as_node_name(os[i]->get_name());
169 if (get_has_associated_node(file, os[i])) {
170 RMF::NodeHandle c = parent.add_child(nicename, RMF::ALIAS);
171 af.get(c).set_aliased(get_node_from_association(file, os[i]));
173 RMF::NodeHandle c = parent.add_child(nicename, get_type(os[i]));
175 os[i]->set_was_used(
true);
base::Vector< base::Pointer< O > > create(RMF::NodeConstHandle rt)
A nullptr-initialized pointer to an IMP Object.
A smart pointer to a reference counted object.
base::Vector< base::Pointer< O > > create(RMF::NodeConstHandle rt, kernel::Model *m)
#define IMP_USAGE_CHECK(expr, message)
A runtime test for incorrect usage of a class or method.
#define IMP_LOG_TERSE(expr)
Handle read/write of kernel::Model data from/to files.
Logging and error reporting support.
Storage of a model, its restraints, constraints and particles.
#define IMP_OBJECT_LOG
Set the log level to the object's log level.
Handle read/write of kernel::Model data from/to files.
#define IMP_THROW(message, exception_name)
Throw an exception with a message.
Various general useful macros for IMP.
#define IMP_FAILURE(message)
A runtime failure for IMP.
A shared base class to help in debugging and things.
#define IMP_LOG_VERBOSE(expr)
Class for storing model, its restraints, constraints, and particles.