IMP logo
IMP Reference Guide  2.20.2
The Integrative Modeling Platform
util.h
Go to the documentation of this file.
1 /**
2 # * \file util.h
3 # * \brief utility methods for npctransport
4 
5 Simulate 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>
17 #include <IMP/core/rigid_bodies.h>
18 #include <IMP/algebra/Vector3D.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>
27 IMPNPCTRANSPORT_BEGIN_NAMESPACE
28 
29 class SimulationData;
30 
31 /** returns particles with optimizable coordinates from particles */
32 IMPNPCTRANSPORTEXPORT
33 ParticlesTemp get_optimizable_particles
34 (ParticlesTemp const& particles);
35 
36 /** returns particles with non-optimizable coordinates from particles */
37 IMPNPCTRANSPORTEXPORT
39 (ParticlesTemp const& particles);
40 
41 /** returns particle indexes from a list of particles */
42 IMPNPCTRANSPORTEXPORT
43 ParticleIndexes get_particle_indexes
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 */
54 IMPNPCTRANSPORTEXPORT 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 */
65 IMPNPCTRANSPORTEXPORT
66 unsigned 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 */
74 IMPNPCTRANSPORTEXPORT
75 unsigned 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 */
84 IMPNPCTRANSPORTEXPORT
85 unsigned 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 */
95 IMPNPCTRANSPORTEXPORT
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 */
107 inline algebra::Vector3D get_global_from_local_v3( Particle* p,
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);
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 */
136 template<class t_ordered_set>
137 inline 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
158 template<class t_value>
159 inline 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
167 template<typename V3iter>
169 (V3iter first, V3iter last, double radius)
170 {
171  algebra::Sphere3Ds ret;
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
181 IMPNPCTRANSPORTEXPORT
183 (algebra::Vector3Ds const& vs, double radius);
184 
185 // return the center of each sphere is spheres, in same order
186 IMPNPCTRANSPORTEXPORT
187 algebra::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.
194 IMPNPCTRANSPORTEXPORT
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
201 IMPNPCTRANSPORTEXPORT
203  Particle* trg_p );
204 
205 //! copy coordinates of src_sd to trg_sd for FG repeats only
206 IMPNPCTRANSPORTEXPORT
207 void copy_FGs_coordinates(SimulationData const* src_sd,
208  SimulationData* trg_sd);
209 
210 IMPNPCTRANSPORT_END_NAMESPACE
211 
212 
213 #endif /* IMPNPCTRANSPORT_UTIL_H */
Simple 3D transformation class.
std::pair< IMP::core::ParticleType, IMP::core::ParticleType > InteractionType
an interaction that involves particles of two types
Definition: typedefs.h:21
Basic types used by IMP.
void copy_FGs_coordinates(SimulationData const *src_sd, SimulationData *trg_sd)
copy coordinates of src_sd to trg_sd for FG repeats only
algebra::Sphere3Ds get_spheres_from_vectors(algebra::Vector3Ds const &vs, double radius)
convert vectors to spheres of passed radius
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)
void copy_hierarchy_reference_frame_recursive(Particle *src_p, Particle *trg_p)
A particle with a user-defined type.
A reference frame in 3D.
ParticlesTemp get_non_optimizable_particles(ParticlesTemp const &particles)
void copy_particle_reference_frame_if_applicable(Particle *src_p, Particle *trg_p)
ParticleIndexes get_particle_indexes(ParticlesTemp const &particles)
functionality for defining rigid bodies
algebra::Vector3D get_global_from_local_v3(Particle *p, const algebra::Vector3D &local)
Definition: util.h:111
const Transformation3D & get_transformation_to() const
Return transformation from local to global coordinates.
Vector3D get_transformed(const Vector3D &o) const
Transform.
Simple 3D transformation class.
ParticlesTemp get_optimizable_particles(ParticlesTemp const &particles)
unsigned int find_or_add_fg_chain_of_type(::npctransport_proto::Statistics *s, IMP::core::ParticleType pt)
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:160
unsigned int find_or_add_fg_bead_of_type(::npctransport_proto::Statistics *s, IMP::core::ParticleType pt)
VectorD< 3 > Vector3D
Definition: VectorD.h:425
description
Simple 3D vector class.
Class to handle individual particles of a Model object.
Definition: Particle.h:43
#define IMP_USAGE_CHECK(expr, message)
A runtime test for incorrect usage of a class or method.
Definition: check_macros.h:168
unsigned int find_or_add_floater_of_type(::npctransport_proto::Statistics *s, IMP::core::ParticleType pt)
A reference frame in 3D.
boost::tuple< unsigned int, unsigned int > get_n_lost_and_gained(t_ordered_set old, t_ordered_set cur)
Definition: util.h:138
A decorator for a rigid body.
Definition: rigid_bodies.h:82
IMP::algebra::ReferenceFrame3D get_reference_frame() const
Definition: rigid_bodies.h:215
forward declaration of incomplete protobuf files for the main data structures used ...