IMP logo
IMP Reference Guide  develop.7482b7c7af, 2026/12/05
The Integrative Modeling Platform
util.h
1/**
2# * \file util.h
3# * \brief utility methods for npctransport
4
5Simulate an fg and a kap interacting
6#
7# * Copyright 2007-2022 IMP Inventors. All rights reserved.
8# */
9
10#ifndef IMPNPCTRANSPORT_UTIL_H
11#define IMPNPCTRANSPORT_UTIL_H
12
13#include "npctransport_config.h"
15#include <IMP/npctransport/internal/util.h>
16#include <IMP/core/Typed.h>
21#include "typedefs.h"
22#include <IMP/base_types.h>
23#include <algorithm>
24#include <string>
25//#include <boost/range/algorithm_ext/is_sorted.hpp>
26//#include <boost/algorithm/cxx11/is_sorted.hpp>
27IMPNPCTRANSPORT_BEGIN_NAMESPACE
28
29class SimulationData;
30
31/** returns particles with optimizable coordinates from particles */
32IMPNPCTRANSPORTEXPORT
34(ParticlesTemp const& particles);
35
36/** returns particles with non-optimizable coordinates from particles */
37IMPNPCTRANSPORTEXPORT
39(ParticlesTemp const& particles);
40
41/** returns particle indexes from a list of particles */
42IMPNPCTRANSPORTEXPORT
44(ParticlesTemp const& particles);
45
46/**
47 Converts protobuf configuration file config_txt (which is in pretty
48 protobuf textual output format) to binary protobuf format
49 (in file config_pb)
50
51 @param config_txt the input textual protobuf config file
52 @param config_pb the output binary protobuf file
53*/
54IMPNPCTRANSPORTEXPORT void get_protobuf_configuration_from_text
55(std::string config_txt, std::string config_pb);
56
57
58#ifndef SWIG
59
60/** finds the index of s.fgs() whose type equals pt.get_string()
61 if it does not exist, add it to s
62 @param s the statistics message for searching the fg
63 @param pt the type of fg to look for
64*/
65IMPNPCTRANSPORTEXPORT
66unsigned int find_or_add_fg_chain_of_type(::npctransport_proto::Statistics* s,
68
69/** finds the index of s.fg_beads() whose type equals pt.get_string()
70 if it does not exist, add it to s
71 @param s the statistics message for searching the fg
72 @param pt the type of fg to look for
73*/
74IMPNPCTRANSPORTEXPORT
75unsigned int find_or_add_fg_bead_of_type(::npctransport_proto::Statistics* s,
77
78
79/** finds the index of s->floaters() whose type equals pt.get_string()
80 if it does not exist, add it to s
81 @param s the statistics message for searching t
82 @param pt the type to look for
83*/
84IMPNPCTRANSPORTEXPORT
85unsigned int find_or_add_floater_of_type(::npctransport_proto::Statistics* s,
87
88
89/** finds the index of s.interactions() whose type0 and type1 particle
90 type equivalents are equale to it. If it does not exist, add it to s
91 @param s the statistics message for searching t
92 @param it the type to look for
93 @return the index of the interaction type in s.interaction()
94*/
95IMPNPCTRANSPORTEXPORT
97( ::npctransport_proto::Statistics* s,
99
100/**
101 @param p a rigid body particle
102 @param local the vector in local coordinates
103
104 @return the global coordinates of local based on the reference frame of the
105 rigid body p
106*/
108 const algebra::Vector3D& local);
109
110
112 const algebra::Vector3D& local)
113{
114 IMP_USAGE_CHECK(core::RigidBody::get_is_setup(p),
115 "Particle must be rigid body in order to use"
116 " its ref frame in get_global_from_local_v3");
117 core::RigidBody rb(p);
118 algebra::ReferenceFrame3D rf = rb.get_reference_frame();
120 return t.get_transformed(local);
121}
122
123#endif // SWIG
124
125#ifndef SWIG
126
127
128/**
129 returns |old/core| and |cur/old|, i.e., the number of
130 items lost from old, and the ones gained in cur.
131
132 @note it is assumed that old and cur are ordered iterable objects
133 (e.g. std::set) whose begin() and end() methods qualify as valid inputs
134 for std::set_difference
135*/
136template<class t_ordered_set>
137inline boost::tuple<unsigned int, unsigned int>
138 get_n_lost_and_gained(t_ordered_set old, t_ordered_set cur)
139{
140 t_ordered_set lost, gained;
142 (//boost::algorithm::is_sorted(old.begin(), old.end()),
143 internal::is_sorted(old),
144 "get_n_lost_and_gained() is expecting an ordered set only");
146 (//boost::algorithm::is_sorted(cur.begin(), cur.end()),
147 internal::is_sorted(cur),
148 "get_n_lost_and_gained() is expecting an ordered set only");
149 std::set_difference(old.begin(), old.end(), cur.begin(), cur.end(),
150 std::inserter(lost, lost.begin()) );
151 std::set_difference(cur.begin(), cur.end(), old.begin(), old.end(),
152 std::inserter(gained, gained.begin()) );
153 return boost::make_tuple(lost.size(), gained.size());
154}
155#endif // SWIG
156
157//! Canonize such that v0>=v1 so order doesn't matter
158template<class t_value>
159inline std::pair<t_value, t_value>
160 make_unordered_pair(t_value v0, t_value v1)
161{
162 return (v0 >= v1) ? std::make_pair(v0,v1) : std::make_pair(v1,v0);
163}
164
165#ifndef SWIG
166//! convert vectors to spheres of passed radius
167template<typename V3iter>
169(V3iter first, V3iter last, double radius)
170{
172 for(V3iter it = first;it != last; it++) {
173 algebra::Vector3D v3(*it);
174 ret.push_back(algebra::Sphere3D(v3, radius));
175 }
176 return ret;
177}
178#endif
179
180//! convert vectors to spheres of passed radius
181IMPNPCTRANSPORTEXPORT
183(algebra::Vector3Ds const& vs, double radius);
184
185// return the center of each sphere is spheres, in same order
186IMPNPCTRANSPORTEXPORT
187algebra::Vector3Ds get_spheres_centers
188(algebra::Sphere3Ds const & spheres);
189
190
191//! Copy XYZ coordinates or RigidBody reference frame from src_p to
192//! trg_p, if it is decorated with XYZ or RigidBody. Do nothing
193//! otherwise.
194IMPNPCTRANSPORTEXPORT
196 Particle* trg_p );
197
198//! Copy XYZ coordinates or RigidBody reference frame from src_pi to trg_pi if applicable,
199//! and if src_pi and trg_pi are an atom hierarchy, proceed recursively to their children.
200//! If so, assumes identical topology of hierarchies for src_pi and trg_pi
201IMPNPCTRANSPORTEXPORT
203 Particle* trg_p );
204
205//! copy coordinates of src_sd to trg_sd for FG repeats only
206IMPNPCTRANSPORTEXPORT
207void copy_FGs_coordinates(SimulationData const* src_sd,
208 SimulationData* trg_sd);
209
210IMPNPCTRANSPORT_END_NAMESPACE
211
212
213#endif /* IMPNPCTRANSPORT_UTIL_H */
A reference frame in 3D.
Simple 3D transformation class.
A particle with a user-defined type.
Simple 3D vector class.
Basic types used by IMP.
#define IMP_USAGE_CHECK(expr, message)
A runtime test for incorrect usage of a class or method.
Class to handle individual particles of a Model object.
Definition Particle.h:45
A reference frame in 3D.
const Transformation3D & get_transformation_to() const
Return transformation from local to global coordinates.
Simple 3D transformation class.
A decorator for a rigid body.
Store all parameters for a simulation.
SphereD< 3 > Sphere3D
Typedef for Python.
Definition SphereD.h:103
IMP::Vector< Sphere3D > Sphere3Ds
Definition SphereD.h:103
Key< 34897493 > ParticleType
An IMP::Key object for identifying types of particles by strings.
Definition Typed.h:28
algebra::Vector3D get_global_from_local_v3(Particle *p, const algebra::Vector3D &local)
Definition util.h:111
unsigned int find_or_add_floater_of_type(::npctransport_proto::Statistics *s, IMP::core::ParticleType pt)
void copy_hierarchy_reference_frame_recursive(Particle *src_p, Particle *trg_p)
std::pair< t_value, t_value > make_unordered_pair(t_value v0, t_value v1)
Canonize such that v0>=v1 so order doesn't matter.
Definition util.h:158
void get_protobuf_configuration_from_text(std::string config_txt, std::string config_pb)
unsigned int find_or_add_interaction_of_type(::npctransport_proto::Statistics *s, IMP::npctransport::InteractionType it)
boost::tuple< unsigned int, unsigned int > get_n_lost_and_gained(t_ordered_set old, t_ordered_set cur)
Definition util.h:138
std::pair< IMP::core::ParticleType, IMP::core::ParticleType > InteractionType
an interaction that involves particles of two types
Definition typedefs.h:21
ParticlesTemp get_non_optimizable_particles(ParticlesTemp const &particles)
void copy_FGs_coordinates(SimulationData const *src_sd, SimulationData *trg_sd)
copy coordinates of src_sd to trg_sd for FG repeats only
void copy_particle_reference_frame_if_applicable(Particle *src_p, Particle *trg_p)
unsigned int find_or_add_fg_bead_of_type(::npctransport_proto::Statistics *s, IMP::core::ParticleType pt)
unsigned int find_or_add_fg_chain_of_type(::npctransport_proto::Statistics *s, IMP::core::ParticleType pt)
ParticlesTemp get_optimizable_particles(ParticlesTemp const &particles)
algebra::Sphere3Ds get_spheres_from_vectors(V3iter first, V3iter last, double radius)
convert vectors to spheres of passed radius
Definition util.h:167
ParticleIndexes get_particle_indexes(ParticlesTemp const &particles)
Vector< VectorD< 3 > > Vector3Ds
Definition VectorD.h:409
Vector< ParticleIndex, std::allocator< ParticleIndex > > ParticleIndexes
A list of particles, each identified by its ParticleIndex.
Definition base_types.h:199
VectorD< 3 > Vector3D
Definition VectorD.h:407
forward declaration of incomplete protobuf files for the main data structures used
functionality for defining rigid bodies
description