6The set of objects that can be involved in the graph are ones derived from IMP::ModelObject. The IMP::ModelObject::get_inputs() and IMP::ModelObject::get_outputs() return the input and output model objects. These lists of inputs and outputs are used to build an IMP::DependencyGraph, a DAG that relates the data flow between IMP::ModelObject instances. As the most important type of IMP::ModelObject is IMP::ScoreState, IMP::ModelObject::get_required_score_states() returns all the score states that are upstream in the DAG from that IMP::ModelObject.
7
8Dependencies are needed when restraints are evaluated. To get them, call IMP::Model::set_has_dependencies(true) (undocumented). That goes over all known IMP::ModelObject, asks them for their inputs and outputs and builds the graph. It then flows over the graph to compute the IMP::ScoreState that is upstream from each each IMP::ModelObject. These are stored in each IMP::ModelObject using the (private) IMP::ModelObject::set_has_dependencies(true, score_states) call.
9
10When the graph changes, it must be updated. This is done by simply invalidating the graph when necessary. This invalidation occurs when
11- a new IMP::ModelObject is created that has a non-empty IMP::ModelObject::get_outputs().
12- when IMP::Model::set_has_dependencies(false) is called to deliberately invalidate all dependencies
13
14Each IMP::ModelObject has a bit for whether its dependencies are valid (IMP::ModelObject::get_has_dependencies()). Its dependencies will be updated any time they are needed (particularly when its IMP::ModelObject::get_required_score_states() method is called. This occurs by having the IMP::Model create the dependency graph if needed and then for each input
15- add its IMP::ModelObject::get_required_score_state() to the list
16- if it is an IMP::ScoreState, add it to the list.
17
18Code can often be made more efficient by caching any data structures that are
19derived from the dependency graph, since this graph rarely changes in many
20common workflows. To aid in this, use the IMP::Model::get_dependencies_updated()
21method, which returns the model age when the graph was last updated.