C++ API

class bson_oid_t
#include <MongoObject.h>

Return

Parameters
  • oid_string:

  • oid:

class bson_oid_t
#include <MongoObject.h>

Return

Parameters
  • oid_string:

  • oid:

class bson_t

is inspected

Return

string contained under the

Parameters
  • key:

Parameters
  • key:

class bson_t

is inspected

Return

string contained under the

Parameters
  • key:

Parameters
  • key:

class Curve
#include <Curve.h>

This method multiplies to the y-values of the current instance of a object the y-values of another

Parameters
  • v: An object of the type

  • valid: If this parameter is false (default value) the y-values are directly multiplied without check for overlap. If this parameter is true only the overlapping y-values are multiplied. The overlap is judged by the values of the x-axis (TODO).

Public Functions

void set_x(double *input, int n_input)
void set_x(std::vector<double> x_)
void set_ex(double *input, int n_input)
void set_x_name(std::string v)
void set_y(double *input, int n_input)
void set_y(std::vector<double> y_)
void set_ey(double *input, int n_input)
void set_y_name(std::string v)
void get_x(double **output, int *n_output)
void get_y(double **output, int *n_output)
std::vector<double> get_x()
std::vector<double> get_y()
double sum()
size_t size()
std::vector<double> get_dx()

Calculates the difference between the x-Axis values

Return

std::vector<double> get_dy()

Calculates the difference between the y-Axis values

Return

Curve(double *x, unsigned int nx, double *y, unsigned int ny, double *ey, unsigned int ney, std::string name_x, std::string name_y)
Curve(double *x, unsigned int nx, double *y, unsigned int ny, std::string name_x, std::string name_y)
Curve(double *x, unsigned int nx, double *y, unsigned int ny, double *ey, unsigned int ney)
Curve(double *x, unsigned int nx, double *y, unsigned int ny)
Curve(double dt, unsigned int nx)
Curve()
~Curve()
void shift(double value)

Shifts the x Axis by a floating point number.

Parameters
  • value:

Curve operator+(Curve &v)
Curve operator+(double v)
Curve operator-(Curve &v)
Curve operator-(double v)
Curve operator*(Curve &v)
Curve operator*(double v)
Curve operator/(Curve &v)
Curve operator/(double v)
void resize(size_t v)
virtual void to_json(std::string filename)
virtual void from_json(std::string filename)

Protected Attributes

std::string name_x
std::string name_y
std::vector<double> x
std::vector<double> ex
std::vector<double> y
std::vector<double> ey

Private Members

bool valid_op = false
bool inplace_op = true
bson_t document

Friends

friend Curve::Decay
class get_value_vector

This attribute can point to another Port (default value nullptr). If the attribute points to another port, the value returned by the method the value the other Port.

class MongoObject : public std::enable_shared_from_this<MongoObject>
#include <MongoObject.h>

The object identification number of the.

Disconnects the the DB.

Connects the instance of database.

The BSON document of the

A BSON document containing the document excluding a set of keys

Returns true if the instance of the to the DB

Return

Return

a bson_t document

Parameters
  • first: is the first key to exclude.

  • ...: more keys to exclude

Writes connected MongoDB

Return

Subclassed by Node, Port, Session

Public Functions

MongoObject(std::string name = "")
~MongoObject()
bool connect_to_db(const std::string &uri_string, const std::string &db_string, const std::string &app_string, const std::string &collection_string)

Return

True if connected successfully

Parameters
  • uri_string:

  • db_string:

  • app_string:

  • collection_string:

template<typename T>
bool connect_object_to_db(T o)

Connects other object to the same MongoDB

Return

True if connected successfully

Template Parameters
  • T:

Parameters
  • o: The object that is connected to the same MongoDB

void disconnect_from_db()
bool is_connected_to_db()
void register_instance(std::shared_ptr<MongoObject>)
void unregister_instance(std::shared_ptr<MongoObject>)
virtual bool write_to_db()
std::string create_copy_in_db()

Creates a copy of the object in the connected MongoDB with a new OID.

Return

The OID of the copy

virtual bool read_from_db(const std::string &oid_string)

Read the content of an existing BSON document into the current object

Return

True if successful otherwise false

Parameters
  • oid_string: Object identifier of the queried document in the DB

bool read_json(std::string json_string)

Read the content of a JSON string into a MongoObject

Return

Parameters
  • json_string:

std::string get_own_oid()

The own object identifier

Return

void set_own_oid(std::string oid_str)

Set the own object identifier without duplicate check

Parameters
  • oid_str:

void set_name(std::string name)
virtual std::string get_name()
std::shared_ptr<MongoObject> get_ptr()
void set_string(std::string key, std::string str)

Create and / or set a string in the MongoObject accessed by

Parameters
  • key:

  • key: the key to access the content

  • str: The content

virtual std::string get_string()
template<typename T>
T get_singleton(const char *key)
template<typename T>
void set_singleton(const char *key, T value)
void set_oid(const char *key, bson_oid_t value)
template<typename T>
std::vector<T> get_array(const char *key)
template<typename T>
void set_array(const char *key, std::vector<T> value)
std::string get_json(int indent = 4)
std::string get_json_of_key(std::string key)
std::string show()
virtual std::shared_ptr<MongoObject> operator[](std::string key)
bool operator==(MongoObject const &b)

Public Static Functions

static std::list<std::shared_ptr<MongoObject>> get_instances()

Protected Functions

bson_oid_t get_bson_oid()

get_own_bson_oid() Returns the object’s ObjectId value (see: https://docs.mongodb.com/manual/reference/bson-types/#objectid)

Return

virtual bson_t get_bson()
bson_t get_bson_excluding(const char *first, ...)
const bson_t *get_document()

Pointer to the BSON document of the MongoObject

Return

void set_document(bson_t b)

Set the

Parameters
  • b:

void set_document(bson_t *doc)
bool write_to_db(const bson_t &doc, int write_option = 0)

Writes a BSON document to the connected MongoDB.

Return

true in case of a successful write.

Parameters
  • doc: a pointer to the BSON document that is written to the MongoDB

  • write_option: integer specifying the write mode - 1: replaces the document (no upsert), 2: insert the document das a new document, default: updates an existing document.

bool read_from_db()
template<typename T>
void create_oid_dict_in_doc(bson_t *doc, std::string key, const std::map<std::string, std::shared_ptr<T>> &mongo_obj_array)
template<typename T>
void append_number_array(bson_t *doc, std::string key, T &values)
template<typename T>
void create_oid_array_in_doc(bson_t *doc, std::string target_field_name, const std::map<std::string, std::shared_ptr<T>> &mongo_obj_array)
template<typename T>
bool create_and_connect_objects_from_oid_doc(const bson_t *doc, const char *document_name, std::map<std::string, std::shared_ptr<T>> *target_map)
template<typename T>
bool create_and_connect_objects_from_oid_array(const bson_t *doc, const char *array_name, std::map<std::string, std::shared_ptr<T>> *target_map)

Protected Attributes

std::string object_name
bson_t document
std::string uri_string
std::string db_string
std::string app_string
std::string collection_string
bson_oid_t oid_document
bson_oid_t oid_precursor
uint64_t time_of_death

Protected Static Functions

static void append_string(bson_t *dst, std::string key, std::string content, size_t size = 0)

Append a string to a BSON document

Parameters
  • dst: pointer to the target BSON document

  • key: the key of the string int the target BSON document

  • content: the string that will be written to the BSON document

  • size: optional parameter for the string size in the BSON document.

static const std::string get_string_by_key(bson_t *doc, std::string key)
static std::string oid_to_string(bson_oid_t oid)
static bool string_to_oid(const std::string &oid_string, bson_oid_t *oid)

Private Members

bool is_connected_to_db_
mongoc_uri_t *uri
mongoc_client_t *client
bson_error_t error
mongoc_collection_t *collection

Private Static Attributes

std::list<std::shared_ptr<MongoObject>> registered_objects

Friends

std::ostream &operator<<(std::ostream &out, MongoObject &o)
class Node : public MongoObject
#include <CNode.h>

Public Functions

Node(std::string name = "", const std::map<std::string, std::shared_ptr<Port>> &ports = std::map<std::string, std::shared_ptr<Port>>(), std::shared_ptr<NodeCallback> callback_class = nullptr)
~Node()
bool read_from_db(const std::string &oid_string)

Read the content of an existing BSON document into the current object

Return

True if successful otherwise false

Parameters
  • oid_string: Object identifier of the queried document in the DB

void evaluate()
bool is_valid()
bool inputs_valid()
bool write_to_db()
bson_t get_bson()
std::string get_name()
std::map<std::string, std::shared_ptr<Port>> get_input_ports()
std::map<std::string, std::shared_ptr<Port>> get_output_ports()
std::map<std::string, std::shared_ptr<Port>> get_ports()
void set_ports(const std::map<std::string, std::shared_ptr<Port>> &ports)
Port *get_port(const std::string &port_name)
void add_port(const std::string &key, std::shared_ptr<Port>, bool is_source, bool fill_in_out = true)
void add_input_port(const std::string &key, std::shared_ptr<Port> port)
void add_output_port(const std::string &key, std::shared_ptr<Port> port)
Port *get_input_port(const std::string &port_name)
Port *get_output_port(const std::string &port_name)
void set_callback(std::shared_ptr<NodeCallback> cb)
void set_callback(std::string callback, std::string callback_type)
void set_valid(bool is_valid = false)

Public Members

std::shared_ptr<NodeCallback> callback_class

A pointer to a function that operates on an input Port instance (first argument) and writes to an output Port instance (second argument)

Protected Functions

void fill_input_output_port_lookups()

Protected Attributes

rttr::method meth_ = rttr::type::get_global_method("nothing")
std::map<std::string, std::shared_ptr<Port>> in_
std::map<std::string, std::shared_ptr<Port>> out_
std::string callback
std::string callback_type_string
int callback_type

Private Members

friend Node::Port
bool node_valid_ = false
std::map<std::string, std::shared_ptr<Port>> ports
class NodeCallback
#include <NodeCallback.h>

Public Functions

virtual void run(std::map<std::string, std::shared_ptr<Port>>, std::map<std::string, std::shared_ptr<Port>>)
NodeCallback()
virtual ~NodeCallback()
class Port : public MongoObject, private std::enable_shared_from_this<Port>
#include <Port.h>

Public Functions

std::shared_ptr<Port> getptr()
size_t current_size()
~Port()
Port(bool fixed = false, bool is_output = false, bool is_reactive = false, bool is_bounded = false, double lb = 0, double ub = 0, int value_type = 1, std::string name = "")
void set_node(Node *node_ptr)
Node *get_node()
int get_value_type()
void set_value_type(int v)
template<typename T>
void set_value(T *input, int n_input, bool copy_values = true)
template<typename T>
void update_buffer()
template<typename T>
void get_own_value(T **output, int *n_output, bool update_local_buffer = false)
template<typename T>
void get_value(T **output, int *n_output)
virtual bson_t get_bson()
void update_attached_node()
void set_bounded(bool bounded)
bool bound_is_valid()
bool is_bounded()
void set_bounds(double *input, int n_input)
void get_bounds(double **output, int *n_output)
bool is_fixed()
void set_fixed(bool fixed)
bool is_output()
void set_port_type(bool is_output)
bool is_reactive()
bool is_float()
void set_reactive(bool reactive)
bool write_to_db()
bool read_from_db(const std::string &oid_string)

Read the content of an existing BSON document into the current object

Return

True if successful otherwise false

Parameters
  • oid_string: Object identifier of the queried document in the DB

void get_bytes(unsigned char **output, int *n_output, bool copy = false)
void set_bytes(unsigned char *input, int n_input)
void set_buffer_ptr(size_t ptr, int n_elements, int element_size)
size_t get_buffer_ptr()
void set_link(std::shared_ptr<Port> v)
bool unlink()
bool is_linked()
std::vector<Port *> get_linked_ports()
std::shared_ptr<Port> get_link()
std::shared_ptr<Port> operator+(std::shared_ptr<Port> v)
std::shared_ptr<Port> operator*(std::shared_ptr<Port> v)

Public Members

int value_type = 0

Private Functions

template<typename T>
void set_value_of_dependents(T *input, int n_input)

Private Members

std::shared_ptr<Port> shared_this
void *buffer_
bool own_buffer = false
int n_buffer_elements_ = 0
int buffer_element_size_ = 1
std::vector<double> bounds_ = {}
Node *node_ = nullptr
std::vector<Port *> linked_to_

This attribute stores the Ports that are dependent on the value of this Port object. If this Port object is reactive a change of the value of this Port object is propagated to the dependent Ports.

class Session : public MongoObject
#include <Session.h>

Public Functions

Session()
Session(std::map<std::string, std::shared_ptr<Node>> nodes)
void add_node(std::string name, std::shared_ptr<Node> object)
std::map<std::string, std::shared_ptr<Node>> get_nodes()
bool write_to_db()
bool read_from_db(const std::string &oid_string)

Read the content of an existing BSON document into the current object

Return

True if successful otherwise false

Parameters
  • oid_string: Object identifier of the queried document in the DB

std::shared_ptr<Port> create_port(json port_template, std::string port_key)
std::shared_ptr<Port> create_port(char *port_template, char *port_key)
std::shared_ptr<Node> create_node(json node_template, std::string node_key)
std::shared_ptr<Node> create_node(char *node_template, char *charnode_key)
bool read_session_template(const std::string &json_string)
std::string get_session_template()

Public Members

std::map<std::string, std::shared_ptr<Node>> nodes

Protected Functions

bson_t get_bson()
class string
#include <MongoObject.h>

Return

Parameters
  • oid:

class string
#include <MongoObject.h>

Return

Parameters
  • oid:

namespace FluorescenceDecay
namespace Functions

Functions

void shift(double value, std::vector<double> &x)

Shifts a vector by a floating number.

This function shifts the y-axis and consider non-integer values by determining the integer part of the shift and the floating part of the shift value, e.g., for the shift 4.66 the integer part is 4 and the floating part is 0.66. Next the array is shifted by the integer part and a copy of the array is shifted by the integer part + 1. Finally, the weighted sum of the both arrays is calculated.

Parameters
  • value:

  • x:

void roll(int value, std::vector<double> &y)

Rolls a vector by an integer

Parameters
  • value:

  • y:

void copy_vector_to_array(std::vector<double> &v, double **out, int *nout)

Allocates memory on a pointer to an array and copies the content of a vector to the newly allocated memory.

This function is mainly used for numpy array SWIGs

Parameters
  • v:

  • out:

  • nout:

void copy_vector_to_array(std::vector<double> &v, double *out, int nout)

Copy an array and copies the content of a vector to already allocated memory.

This function is mainly used for numpy array SWIGs

Parameters
  • v:

  • out:

  • nout:

void copy_array_to_vector(double *in, int nin, std::vector<double> &v)

Parameters
  • in:

  • nin:

  • v:

void copy_two_vectors_to_interleaved_array(std::vector<double> &v1, std::vector<double> &v2, double **out, int *nout)

This function copies two vectors of equal size to an interleaved array

Parameters
  • v1:

  • v2:

  • out:

  • nout:

template<typename T>
void value2internal(T *values, int n_values, double lower_bound, double upper_bound)

Maps the array of values \( max(bound_1, bound_2) - abs(bound_1-bound_2)/(exp(value / abs(bound_1-bound_2))+1) \)

Parameters
  • in: place to values to the interval (min, max) determined by the parameters

  • bound_1: and

  • bound_2.: The values are mapped to the interval by:

Template Parameters
  • T: The type of the values

Parameters
  • values: (InOut)

  • n_values: (In)

  • lower_bound: (In)

  • upper_bound: (In)

template<typename T>
void internal2value(T *values, int n_values, double lower_bound, double upper_bound)
template<typename T>
void bound_values(T *values, int n_values, double lower_bound, double upper_bound)
void convolve_sum_of_exponentials(double *out, int n_out, const double *lifetime_spectrum, int n_lifetime_spectrum, const double *irf, int n_irf, int convolution_stop, double dt)

This function convolves a sum of exponential decays with an instrument response function (IRF)

The sum of exponential decays is passed by the lifetime array

Parameters
  • lifetime_spectrum: that contains the amplitudes and the corresponding fluorescence lifetimes in an interleaved array (amplitude_1, lifetime_1, amplitude_2, lifetime_2, …). The instrument response function is passed by the array

  • irf.: The IRF and the and the sum of exponential decays are convolved up to the index

  • convolution_stop.: In this convolution, the time axis is uniform an linear with a time interval specified by the parameter

  • dt.:

  • out: The array to which the convoluted decay is written to

  • n_out: The number of elements in the output array

  • lifetime_spectrum: The array containing the fluorescence lifetimes and the amplitudes

  • n_lifetime_spectrum: The number of fluorescence lifetimes

  • irf: The array containing the instrument response function

  • n_irf: The number of elements of the instrument response function

  • convolution_stop: The stop of the convolution

  • dt: The time resolution

void convolve_sum_of_exponentials_periodic(double *out, int n_out, const double *lifetime, int n_lifetimes, const double *irf, int n_irf, int start, int stop, double dt, double period)

This function convolves a sum of exponential decays with an instrument response function (IRF)

The sum of exponential decays is passed by the lifetime array

Parameters
  • lifetime: that contains the amplitudes and the corresponding fluorescence lifetimes in an interleaved array (amplitude_1, lifetime_1, amplitude_2, lifetime_2, …). The instrument response function is passed by the array

  • irf.: The IRF and the and the sum of exponential decays are convolved up to the index

  • convolution_stop.: In this convolution, the time axis is uniform an linear with a time interval specified by the parameter

  • dt.:

  • out: The array to which the convoluted decay is written to

  • n_out: The number of elements in the output array

  • lifetime: The array containing the fluorescence lifetimes and the amplitudes

  • n_lifetimes: The number of fluorescence lifetimes

  • irf: The array containing the instrument response function

  • n_irf: The number of elements of the instrument response function

  • start: The start index of the convolution

  • stop: The stop index of the convolution

  • dt: The time resolution

  • period: The time between repeated excitation intervals

std::vector<double> diff(std::vector<double> v)

Calculates the discrete difference for an vector

Return

Parameters
  • v:

uint64_t get_time()

Returns the current time in milliseconds as a uint64

Return

void add_documents(bson_t *src, bson_t *dst, std::vector<std::string> skip)

Adds the content in the bson_t document src to the document dst omitting the keys provided by the vector skip.

bool bson_iter_skip(bson_iter_t *iter, std::vector<std::string> *skip)

Returns true if the key associated to

Parameters
  • iter: is in the list of vectors

  • skip:

  • iter: pointer to a bson_iter_t

  • skip: vector of strings containing keys that are skipped by iter

template<typename T>
std::vector<T> get_vector_of_min_size(std::vector<T> a, std::vector<T> b)

Returns a vector with a size that is is min(a.size(), b.size())

Return

a vector of size min(a.size(), b.size())

Template Parameters
  • T: The type of the vectors

Parameters
  • a:

  • b:

namespace std

STL namespace.

file Curve.h
#include <vector>#include <algorithm>#include <string>#include <Functions.h>#include <fstream>#include <bson.h>
file CNode.h
#include <string>#include <vector>#include <memory>#include <map>#include <algorithm>#include <rttr/registration>#include “MongoObject.h”#include “Port.h”#include “NodeCallback.h”

Defines

VERSION
file Functions.h
#include <vector>#include <algorithm>#include <math.h>#include <iostream>#include <chrono>#include <bson.h>

Defines

MAX(a, b)
MIN(a, b)
file MongoObject.h
#include <iostream>#include <map>#include <set>#include <vector>#include <list>#include <memory>#include <cmath>#include <iterator>#include <string>#include <sstream>#include <nlohmann/json.hpp>#include <mongoc.h>#include “Functions.h”

Typedefs

using json = nlohmann::json
file NodeCallback.h
#include <functional>#include <rttr/registration>#include <Port.h>#include <CNode.h>#include <Functions.h>#include <FlexLabel/FlexLabel.h>
file Port.h
#include <cstdint>#include <memory>#include <algorithm>#include <cmath>#include <cstdlib>#include <CNode.h>
file Session.h
#include <map>#include <memory>#include <nlohmann/json.hpp>#include “MongoObject.h”#include “CNode.h”#include “Port.h”
file README.md
dir /home/docs/checkouts/readthedocs.org/user_builds/chinet/checkouts/development/include/_old
dir /home/docs/checkouts/readthedocs.org/user_builds/chinet/checkouts/development/include
page index

General description

chinet is a C++ library to create optimize, sample, and archive global models. A global model is a model, that unites multiple data-sets and seeks for a joint description of the united dataset.

Global models can unite datasets of the same kind or datasets of different types. A typical examples of a global model in fluorescence experiments is the joint description of multiple fluorescence correlation curves in a titration and the joint description of multiple fluorescence decay curves reporting on FRET in a biomolecular structure by a single structural model.

Computing a global model with a large diverse set of different data can be computationally expensive. To reduce the computational costs and to decrease the evaluation time of a global model defined by chinet, the mutual dependencies of the model parameters are modeled by a graph structure that connects “computing nodes”. When a a set of parameters is changed only computing nodes that are affected by these changes are evaluated. Independent nodes are evaluated in parallel.

The state of the evaluation graph can be written to a database for documentation purposes and reconstructed using unique identifies provided by the database.

chinet is NOT intended as ready-to-use software for specific application purposes.

Goals

  • reactive dataflow model framework

  • fast inter computation node communication

  • define and store models jointly with associated data identifies in data base.

  • Platform independent C/C++ library with interfaces for scripting libraries

Building and Installation

C++ shared library

The C++ shared library can be installed from source with cmake:

git clone --recursive https://github.com/tpeulen/chinet.git
mkdir chinet/build; cd chinet/build
cmake ..
sudo make install

On Linux you can build and install a package instead (prefered):

Python bindings

The Python bindings can be either be installed by downloading and compiling the source code or by using a precompiled distribution for Python anaconda environment.

The following commands can be used to download and compile the source code:

git clone --recursive https://github.com/tpeulen/chinet.git
cd chinet
sudo python setup.py install

In an anaconda environment the library can be installed by the following command:

conda install -c tpeulen chinet

For most users the later approach is recommended. Currently, pre-compiled packages for the anaconda distribution system are available for:

  • Windows: Python 3.7

  • Linux: Python 3.7

  • macOS: Python 3.7

Legacy 32-bit platforms and the deprecated Python 2.7 are not supported.

Examples

import chinet as cn

v1 = 23.0
v2 = 29.0
p1 = cn.Port()
p1.value = v1
p2 = cn.Port(v1)
p3 = cn.Port(
    value=v1,
    fixed=True
)
p4 = cn.Port(
    value=v1,
    fixed=False
)
p5 = cn.Port(v2)
p5.link = p4
print(p4.value == p1.value)

License

chinet is released under the open source MIT license.