9 #ifndef IMPRMF_SIMPLE_LINKS_H
10 #define IMPRMF_SIMPLE_LINKS_H
12 #include <IMP/rmf/rmf_config.h>
20 #include <RMF/RestoreCurrentFrame.h>
21 #include <RMF/SetCurrentFrame.h>
22 #include <RMF/names.h>
23 #include <RMF/decorators.h>
25 IMPRMF_BEGIN_NAMESPACE
37 virtual void do_load_one(RMF::NodeConstHandle nh, O *o) = 0;
40 for (
unsigned int i = 0; i < os_.size(); ++i) {
42 do_load_one(fh.get_node(nhs_[i]), os_[i]);
45 virtual void do_add_link(O *, RMF::NodeConstHandle) {};
46 void add_link(O *o, RMF::NodeConstHandle nh) {
48 nhs_.push_back(nh.get_id());
49 set_association(nh, o,
true);
51 virtual bool get_is(RMF::NodeConstHandle nh)
const = 0;
52 virtual O *do_create(RMF::NodeConstHandle) {
IMP_FAILURE(
"Wrong create"); }
53 virtual O *do_create(RMF::NodeConstHandle,
Model *) {
62 IMP_LOG_TERSE(
"Creating IMP objects from " << rt << std::endl);
63 RMF::SetCurrentFrame sf(rt.get_file(), RMF::FrameID(0));
64 RMF::NodeConstHandles ch = rt.get_children();
66 for (
unsigned int i = 0; i < ch.size(); ++i) {
73 o->set_was_used(
true);
83 IMP_LOG_TERSE(
"Creating Model objects from " << rt << std::endl);
84 RMF::SetCurrentFrame sf(rt.get_file(), RMF::FrameID(0));
85 RMF::NodeConstHandles ch = rt.get_children();
87 for (
unsigned int i = 0; i < ch.size(); ++i) {
94 o->set_was_used(
true);
100 void link(RMF::NodeConstHandle rt,
103 IMP_LOG_TERSE(
"Linking " << rt <<
" to " << ps << std::endl);
105 RMF::RestoreCurrentFrame sf(rt.get_file());
107 RMF::NodeConstHandles chs = rt.get_children();
108 RMF::NodeConstHandles matching_chs;
109 IMP_FOREACH(RMF::NodeConstHandle ch, rt.get_children()) {
111 if (get_is(ch)) matching_chs.push_back(ch);
113 if (matching_chs.size() != ps.size()) {
114 IMP_THROW(
"Founding " << matching_chs.size() <<
" matching nodes "
115 <<
"but passed " << ps.size() <<
" to match with.",
118 for (
unsigned int i = 0; i < matching_chs.size(); ++i) {
120 add_link(ps[i], matching_chs[i]);
121 ps[i]->set_was_used(
true);
122 do_add_link(ps[i], matching_chs[i]);
137 virtual void do_save_one(O *o, RMF::NodeHandle nh) = 0;
139 for (
unsigned int i = 0; i < os_.size(); ++i) {
142 os_[i]->set_was_used(
true);
144 do_save_one(os_[i], fh.get_node(nhs_[i]));
147 virtual void do_add(O *o, RMF::NodeHandle c) { add_link(o, c); }
148 virtual RMF::NodeType get_type(O *o)
const = 0;
149 void add_link(O *o, RMF::NodeConstHandle nh) {
151 nhs_.push_back(nh.get_id());
152 set_association(nh, o,
true);
160 RMF::FileHandle file = parent.get_file();
161 RMF::decorator::AliasFactory af(file);
162 for (
unsigned int i = 0; i < os.size(); ++i) {
163 std::string nicename = RMF::get_as_node_name(os[i]->get_name());
164 if (get_has_associated_node(file, os[i])) {
165 RMF::NodeHandle c = parent.add_child(nicename, RMF::ALIAS);
166 af.get(c).set_aliased(get_node_from_association(file, os[i]));
168 RMF::NodeHandle c = parent.add_child(nicename, get_type(os[i]));
170 os[i]->set_was_used(
true);
Helper macros for implementing IMP Objects.
#define IMP_FAILURE(message)
A runtime failure for IMP.
#define IMP_OBJECT_LOG
Set the log level to the object's log level.
Storage of a model, its restraints, constraints and particles.
#define IMP_LOG_VERBOSE(expr)
A more IMP-like version of the std::vector.
#define IMP_LOG_TERSE(expr)
A smart pointer to a reference counted object.
Class for storing model, its restraints, constraints, and particles.
#define IMP_FOREACH(v, r)
Manage links between IMP objects and a part of the RMF file.
Logging and error reporting support.
#define IMP_THROW(message, exception_name)
Throw an exception with a message.
Track associations between an RMF file and native objects.
A nullptr-initialized pointer to an IMP Object.
A shared base class to help in debugging and things.
Vector< Pointer< O > > create(RMF::NodeConstHandle rt, Model *m)
Vector< Pointer< O > > create(RMF::NodeConstHandle rt)
An exception for an invalid value being passed to IMP.
Helper class to aid in output of IMP classes to streams.
#define IMP_OVERRIDE
Cause a compile error if this method does not override a parent method.