RMF
physics.h
Go to the documentation of this file.
1 /**
2  * \file RMF/decorator/physics.h
3  * \brief Helper functions for manipulating RMF files.
4  *
5  * Copyright 2007-2022 IMP Inventors. All rights reserved.
6  *
7  */
8 
9 #ifndef RMF_PHYSICS_DECORATORS_H
10 #define RMF_PHYSICS_DECORATORS_H
11 
12 #include <RMF/config.h>
14 #include <RMF/NodeHandle.h>
15 #include <RMF/FileHandle.h>
16 #include <RMF/Decorator.h>
17 #include <RMF/constants.h>
18 #include <RMF/Vector.h>
19 #include <RMF/internal/paths.h>
20 #include <array>
21 #include <boost/lexical_cast.hpp>
22 #include "alias.h"
23 
24 RMF_ENABLE_WARNINGS
25 namespace RMF {
26 namespace decorator {
27 
28 
29  /** See also Particle and ParticleFactory.
30  */
31  class ParticleConst: public Decorator {
32  friend class ParticleFactory;
33  protected:
34  FloatKey mass_;
35 Vector3Key coordinates_;
36 FloatKey radius_;
38  FloatKey mass,
39 Vector3Key coordinates,
40 FloatKey radius):
41  Decorator(nh),
42 mass_(mass),
43 coordinates_(coordinates),
44 radius_(radius) {
45  }
46  public:
47 
48  Float get_mass() const {
49  try {
50  return get_node().get_value(mass_);
51  } RMF_DECORATOR_CATCH( );
52  }
53  Float get_frame_mass() const {
54  try {
55  return get_node().get_frame_value(mass_);
56  } RMF_DECORATOR_CATCH( );
57  }
58  Float get_static_mass() const {
59  try {
60  return get_node().get_static_value(mass_);
61  } RMF_DECORATOR_CATCH( );
62  }
63 
64 
65  Vector3 get_coordinates() const {
66  try {
67  return get_node().get_value(coordinates_);
68  } RMF_DECORATOR_CATCH( );
69  }
70  Vector3 get_frame_coordinates() const {
71  try {
72  return get_node().get_frame_value(coordinates_);
73  } RMF_DECORATOR_CATCH( );
74  }
75  Vector3 get_static_coordinates() const {
76  try {
77  return get_node().get_static_value(coordinates_);
78  } RMF_DECORATOR_CATCH( );
79  }
80 
81 
82  Float get_radius() const {
83  try {
84  return get_node().get_value(radius_);
85  } RMF_DECORATOR_CATCH( );
86  }
87  Float get_frame_radius() const {
88  try {
89  return get_node().get_frame_value(radius_);
90  } RMF_DECORATOR_CATCH( );
91  }
92  Float get_static_radius() const {
93  try {
94  return get_node().get_static_value(radius_);
95  } RMF_DECORATOR_CATCH( );
96  }
97 
98  static std::string get_decorator_type_name() {
99  return "ParticleConst";
100  }
101  RMF_SHOWABLE(ParticleConst, "Particle: " << get_node());
102  };
103  /** See also ParticleFactory.
104  */
105  class Particle: public ParticleConst {
106  friend class ParticleFactory;
107  Particle(NodeHandle nh,
108  FloatKey mass,
109 Vector3Key coordinates,
110 FloatKey radius):
111  ParticleConst(nh, mass,
112 coordinates,
113 radius) {
114  }
115  public:
116 
117  void set_mass(Float v) {
118  try {
119  get_node().set_value(mass_, v);
120  } RMF_DECORATOR_CATCH( );
121  }
122  void set_frame_mass(Float v) {
123  try {
124  get_node().set_frame_value(mass_, v);
125  } RMF_DECORATOR_CATCH( );
126  }
127  void set_static_mass(Float v) {
128  try {
129  get_node().set_static_value(mass_, v);
130  } RMF_DECORATOR_CATCH( );
131  }
132 
133 
134  void set_coordinates(Vector3 v) {
135  try {
136  get_node().set_value(coordinates_, v);
137  } RMF_DECORATOR_CATCH( );
138  }
139  void set_frame_coordinates(Vector3 v) {
140  try {
141  get_node().set_frame_value(coordinates_, v);
142  } RMF_DECORATOR_CATCH( );
143  }
144  void set_static_coordinates(Vector3 v) {
145  try {
146  get_node().set_static_value(coordinates_, v);
147  } RMF_DECORATOR_CATCH( );
148  }
149 
150 
151  void set_radius(Float v) {
152  try {
153  get_node().set_value(radius_, v);
154  } RMF_DECORATOR_CATCH( );
155  }
156  void set_frame_radius(Float v) {
157  try {
158  get_node().set_frame_value(radius_, v);
159  } RMF_DECORATOR_CATCH( );
160  }
161  void set_static_radius(Float v) {
162  try {
163  get_node().set_static_value(radius_, v);
164  } RMF_DECORATOR_CATCH( );
165  }
166 
167  static std::string get_decorator_type_name() {
168  return "Particle";
169  }
170  };
171 
172 
173  /** Create decorators of type Particle.
174  */
175  class ParticleFactory: public Factory {
176  Category cat_;
177 FloatKey mass_;
178 Vector3Key coordinates_;
179 FloatKey radius_;
180 
181 
182 
183  public:
185  cat_(fh.get_category("physics")),
186  mass_(fh.get_key<FloatTag>(cat_, "mass")), coordinates_(fh.get_key<Vector3Tag>(cat_, "coordinates")), radius_(fh.get_key<FloatTag>(cat_, "radius")) {
187  }
189  cat_(fh.get_category("physics")),
190  mass_(fh.get_key<FloatTag>(cat_, "mass")), coordinates_(fh.get_key<Vector3Tag>(cat_, "coordinates")), radius_(fh.get_key<FloatTag>(cat_, "radius")) {
191  }
192  /** Get a ParticleConst for nh.*/
194  RMF_USAGE_CHECK((nh.get_type() == RMF::REPRESENTATION), std::string("Bad node type. Got \"")
195  + boost::lexical_cast<std::string>(nh.get_type())
196  + "\" in decorator type Particle");
197  return ParticleConst(nh, mass_,
198 coordinates_,
199 radius_);
200  }
201  /** Get a Particle for nh.*/
202  Particle get(NodeHandle nh) const {
203  RMF_USAGE_CHECK((nh.get_type() == RMF::REPRESENTATION), std::string("Bad node type. Got \"")
204  + boost::lexical_cast<std::string>(nh.get_type())
205  + "\" in decorator type Particle");
206  return Particle(nh, mass_,
207 coordinates_,
208 radius_);
209  }
210  /** Check whether nh has all the attributes required to be a
211  ParticleConst.*/
212  bool get_is(NodeConstHandle nh) const {
213  return (nh.get_type() == RMF::REPRESENTATION)
214  && !nh.get_value(mass_).get_is_null();
215  }
216  bool get_is_static(NodeConstHandle nh) const {
217  return (nh.get_type() == RMF::REPRESENTATION)
218  && !nh.get_static_value(mass_).get_is_null()
219  && !nh.get_static_value(coordinates_).get_is_null()
220  && !nh.get_static_value(radius_).get_is_null();
221  }
222  RMF_SHOWABLE(ParticleFactory, "ParticleFactory");
223  };
224  #ifndef RMF_DOXYGEN
225 struct ParticleConstFactory: public ParticleFactory {
226  ParticleConstFactory(FileConstHandle fh):
227  ParticleFactory(fh) {
228  }
229  ParticleConstFactory(FileHandle fh):
230  ParticleFactory(fh) {
231  }
232 
233 };
234  #endif
235 
236 
237 
238 
239  /** See also IntermediateParticle and IntermediateParticleFactory.
240  */
242  friend class IntermediateParticleFactory;
243  protected:
244  FloatKey radius_;
245 Vector3Key coordinates_;
247  FloatKey radius,
248 Vector3Key coordinates):
249  Decorator(nh),
250 radius_(radius),
251 coordinates_(coordinates) {
252  }
253  public:
254 
255  Float get_radius() const {
256  try {
257  return get_node().get_value(radius_);
258  } RMF_DECORATOR_CATCH( );
259  }
260  Float get_frame_radius() const {
261  try {
262  return get_node().get_frame_value(radius_);
263  } RMF_DECORATOR_CATCH( );
264  }
265  Float get_static_radius() const {
266  try {
267  return get_node().get_static_value(radius_);
268  } RMF_DECORATOR_CATCH( );
269  }
270 
271 
272  Vector3 get_coordinates() const {
273  try {
274  return get_node().get_value(coordinates_);
275  } RMF_DECORATOR_CATCH( );
276  }
277  Vector3 get_frame_coordinates() const {
278  try {
279  return get_node().get_frame_value(coordinates_);
280  } RMF_DECORATOR_CATCH( );
281  }
282  Vector3 get_static_coordinates() const {
283  try {
284  return get_node().get_static_value(coordinates_);
285  } RMF_DECORATOR_CATCH( );
286  }
287 
288  static std::string get_decorator_type_name() {
289  return "IntermediateParticleConst";
290  }
291  RMF_SHOWABLE(IntermediateParticleConst, "IntermediateParticle: " << get_node());
292  };
293  /** See also IntermediateParticleFactory.
294  */
296  friend class IntermediateParticleFactory;
298  FloatKey radius,
299 Vector3Key coordinates):
300  IntermediateParticleConst(nh, radius,
301 coordinates) {
302  }
303  public:
304 
305  void set_radius(Float v) {
306  try {
307  get_node().set_value(radius_, v);
308  } RMF_DECORATOR_CATCH( );
309  }
310  void set_frame_radius(Float v) {
311  try {
312  get_node().set_frame_value(radius_, v);
313  } RMF_DECORATOR_CATCH( );
314  }
315  void set_static_radius(Float v) {
316  try {
317  get_node().set_static_value(radius_, v);
318  } RMF_DECORATOR_CATCH( );
319  }
320 
321 
322  void set_coordinates(Vector3 v) {
323  try {
324  get_node().set_value(coordinates_, v);
325  } RMF_DECORATOR_CATCH( );
326  }
327  void set_frame_coordinates(Vector3 v) {
328  try {
329  get_node().set_frame_value(coordinates_, v);
330  } RMF_DECORATOR_CATCH( );
331  }
332  void set_static_coordinates(Vector3 v) {
333  try {
334  get_node().set_static_value(coordinates_, v);
335  } RMF_DECORATOR_CATCH( );
336  }
337 
338  static std::string get_decorator_type_name() {
339  return "IntermediateParticle";
340  }
341  };
342 
343 
344  /** Create decorators of type IntermediateParticle.
345  */
347  Category cat_;
348 FloatKey radius_;
349 Vector3Key coordinates_;
350 
351 
352  public:
354  cat_(fh.get_category("physics")),
355  radius_(fh.get_key<FloatTag>(cat_, "radius")), coordinates_(fh.get_key<Vector3Tag>(cat_, "coordinates")) {
356  }
358  cat_(fh.get_category("physics")),
359  radius_(fh.get_key<FloatTag>(cat_, "radius")), coordinates_(fh.get_key<Vector3Tag>(cat_, "coordinates")) {
360  }
361  /** Get a IntermediateParticleConst for nh.*/
363  RMF_USAGE_CHECK((nh.get_type() == RMF::REPRESENTATION), std::string("Bad node type. Got \"")
364  + boost::lexical_cast<std::string>(nh.get_type())
365  + "\" in decorator type IntermediateParticle");
366  return IntermediateParticleConst(nh, radius_,
367 coordinates_);
368  }
369  /** Get a IntermediateParticle for nh.*/
371  RMF_USAGE_CHECK((nh.get_type() == RMF::REPRESENTATION), std::string("Bad node type. Got \"")
372  + boost::lexical_cast<std::string>(nh.get_type())
373  + "\" in decorator type IntermediateParticle");
374  return IntermediateParticle(nh, radius_,
375 coordinates_);
376  }
377  /** Check whether nh has all the attributes required to be a
378  IntermediateParticleConst.*/
379  bool get_is(NodeConstHandle nh) const {
380  return (nh.get_type() == RMF::REPRESENTATION)
381  && !nh.get_value(radius_).get_is_null();
382  }
383  bool get_is_static(NodeConstHandle nh) const {
384  return (nh.get_type() == RMF::REPRESENTATION)
385  && !nh.get_static_value(radius_).get_is_null()
386  && !nh.get_static_value(coordinates_).get_is_null();
387  }
388  RMF_SHOWABLE(IntermediateParticleFactory, "IntermediateParticleFactory");
389  };
390  #ifndef RMF_DOXYGEN
391 struct IntermediateParticleConstFactory: public IntermediateParticleFactory {
392  IntermediateParticleConstFactory(FileConstHandle fh):
393  IntermediateParticleFactory(fh) {
394  }
395  IntermediateParticleConstFactory(FileHandle fh):
396  IntermediateParticleFactory(fh) {
397  }
398 
399 };
400  #endif
401 
402 
403 
404 
405  /** See also GaussianParticle and GaussianParticleFactory.
406  */
408  friend class GaussianParticleFactory;
409  protected:
410  Vector3Key variances_;
411 FloatKey mass_;
413  Vector3Key variances,
414 FloatKey mass):
415  Decorator(nh),
416 variances_(variances),
417 mass_(mass) {
418  }
419  public:
420 
421  Vector3 get_variances() const {
422  try {
423  return get_node().get_value(variances_);
424  } RMF_DECORATOR_CATCH( );
425  }
426  Vector3 get_frame_variances() const {
427  try {
428  return get_node().get_frame_value(variances_);
429  } RMF_DECORATOR_CATCH( );
430  }
431  Vector3 get_static_variances() const {
432  try {
433  return get_node().get_static_value(variances_);
434  } RMF_DECORATOR_CATCH( );
435  }
436 
437 
438  Float get_mass() const {
439  try {
440  return get_node().get_value(mass_);
441  } RMF_DECORATOR_CATCH( );
442  }
443  Float get_frame_mass() const {
444  try {
445  return get_node().get_frame_value(mass_);
446  } RMF_DECORATOR_CATCH( );
447  }
448  Float get_static_mass() const {
449  try {
450  return get_node().get_static_value(mass_);
451  } RMF_DECORATOR_CATCH( );
452  }
453 
454  static std::string get_decorator_type_name() {
455  return "GaussianParticleConst";
456  }
457  RMF_SHOWABLE(GaussianParticleConst, "GaussianParticle: " << get_node());
458  };
459  /** See also GaussianParticleFactory.
460  */
462  friend class GaussianParticleFactory;
464  Vector3Key variances,
465 FloatKey mass):
466  GaussianParticleConst(nh, variances,
467 mass) {
468  }
469  public:
470 
471  void set_variances(Vector3 v) {
472  try {
473  get_node().set_value(variances_, v);
474  } RMF_DECORATOR_CATCH( );
475  }
476  void set_frame_variances(Vector3 v) {
477  try {
478  get_node().set_frame_value(variances_, v);
479  } RMF_DECORATOR_CATCH( );
480  }
481  void set_static_variances(Vector3 v) {
482  try {
483  get_node().set_static_value(variances_, v);
484  } RMF_DECORATOR_CATCH( );
485  }
486 
487 
488  void set_mass(Float v) {
489  try {
490  get_node().set_value(mass_, v);
491  } RMF_DECORATOR_CATCH( );
492  }
493  void set_frame_mass(Float v) {
494  try {
495  get_node().set_frame_value(mass_, v);
496  } RMF_DECORATOR_CATCH( );
497  }
498  void set_static_mass(Float v) {
499  try {
500  get_node().set_static_value(mass_, v);
501  } RMF_DECORATOR_CATCH( );
502  }
503 
504  static std::string get_decorator_type_name() {
505  return "GaussianParticle";
506  }
507  };
508 
509 
510  /** Create decorators of type GaussianParticle.
511  */
513  Category cat_;
514 Vector3Key variances_;
515 FloatKey mass_;
516 
517 
518  public:
520  cat_(fh.get_category("physics")),
521  variances_(fh.get_key<Vector3Tag>(cat_, "variances")), mass_(fh.get_key<FloatTag>(cat_, "mass")) {
522  }
524  cat_(fh.get_category("physics")),
525  variances_(fh.get_key<Vector3Tag>(cat_, "variances")), mass_(fh.get_key<FloatTag>(cat_, "mass")) {
526  }
527  /** Get a GaussianParticleConst for nh.*/
529  RMF_USAGE_CHECK((nh.get_type() == RMF::REPRESENTATION), std::string("Bad node type. Got \"")
530  + boost::lexical_cast<std::string>(nh.get_type())
531  + "\" in decorator type GaussianParticle");
532  return GaussianParticleConst(nh, variances_,
533 mass_);
534  }
535  /** Get a GaussianParticle for nh.*/
536  GaussianParticle get(NodeHandle nh) const {
537  RMF_USAGE_CHECK((nh.get_type() == RMF::REPRESENTATION), std::string("Bad node type. Got \"")
538  + boost::lexical_cast<std::string>(nh.get_type())
539  + "\" in decorator type GaussianParticle");
540  return GaussianParticle(nh, variances_,
541 mass_);
542  }
543  /** Check whether nh has all the attributes required to be a
544  GaussianParticleConst.*/
545  bool get_is(NodeConstHandle nh) const {
546  return (nh.get_type() == RMF::REPRESENTATION)
547  && !nh.get_value(variances_).get_is_null();
548  }
549  bool get_is_static(NodeConstHandle nh) const {
550  return (nh.get_type() == RMF::REPRESENTATION)
551  && !nh.get_static_value(variances_).get_is_null()
552  && !nh.get_static_value(mass_).get_is_null();
553  }
554  RMF_SHOWABLE(GaussianParticleFactory, "GaussianParticleFactory");
555  };
556  #ifndef RMF_DOXYGEN
557 struct GaussianParticleConstFactory: public GaussianParticleFactory {
558  GaussianParticleConstFactory(FileConstHandle fh):
559  GaussianParticleFactory(fh) {
560  }
561  GaussianParticleConstFactory(FileHandle fh):
562  GaussianParticleFactory(fh) {
563  }
564 
565 };
566  #endif
567 
568 
569 
570 
571  /** See also RigidParticle and RigidParticleFactory.
572  */
574  friend class RigidParticleFactory;
575  protected:
576  Vector4Key orientation_;
577 Vector3Key coordinates_;
579  Vector4Key orientation,
580 Vector3Key coordinates):
581  Decorator(nh),
582 orientation_(orientation),
583 coordinates_(coordinates) {
584  }
585  public:
586 
587  Vector4 get_orientation() const {
588  try {
589  return get_node().get_value(orientation_);
590  } RMF_DECORATOR_CATCH( );
591  }
592  Vector4 get_frame_orientation() const {
593  try {
594  return get_node().get_frame_value(orientation_);
595  } RMF_DECORATOR_CATCH( );
596  }
597  Vector4 get_static_orientation() const {
598  try {
599  return get_node().get_static_value(orientation_);
600  } RMF_DECORATOR_CATCH( );
601  }
602 
603 
604  Vector3 get_coordinates() const {
605  try {
606  return get_node().get_value(coordinates_);
607  } RMF_DECORATOR_CATCH( );
608  }
609  Vector3 get_frame_coordinates() const {
610  try {
611  return get_node().get_frame_value(coordinates_);
612  } RMF_DECORATOR_CATCH( );
613  }
614  Vector3 get_static_coordinates() const {
615  try {
616  return get_node().get_static_value(coordinates_);
617  } RMF_DECORATOR_CATCH( );
618  }
619 
620  static std::string get_decorator_type_name() {
621  return "RigidParticleConst";
622  }
623  RMF_SHOWABLE(RigidParticleConst, "RigidParticle: " << get_node());
624  };
625  /** See also RigidParticleFactory.
626  */
628  friend class RigidParticleFactory;
630  Vector4Key orientation,
631 Vector3Key coordinates):
632  RigidParticleConst(nh, orientation,
633 coordinates) {
634  }
635  public:
636 
637  void set_orientation(Vector4 v) {
638  try {
639  get_node().set_value(orientation_, v);
640  } RMF_DECORATOR_CATCH( );
641  }
642  void set_frame_orientation(Vector4 v) {
643  try {
644  get_node().set_frame_value(orientation_, v);
645  } RMF_DECORATOR_CATCH( );
646  }
647  void set_static_orientation(Vector4 v) {
648  try {
649  get_node().set_static_value(orientation_, v);
650  } RMF_DECORATOR_CATCH( );
651  }
652 
653 
654  void set_coordinates(Vector3 v) {
655  try {
656  get_node().set_value(coordinates_, v);
657  } RMF_DECORATOR_CATCH( );
658  }
659  void set_frame_coordinates(Vector3 v) {
660  try {
661  get_node().set_frame_value(coordinates_, v);
662  } RMF_DECORATOR_CATCH( );
663  }
664  void set_static_coordinates(Vector3 v) {
665  try {
666  get_node().set_static_value(coordinates_, v);
667  } RMF_DECORATOR_CATCH( );
668  }
669 
670  static std::string get_decorator_type_name() {
671  return "RigidParticle";
672  }
673  };
674 
675 
676  /** Create decorators of type RigidParticle.
677  */
679  Category cat_;
680 Vector4Key orientation_;
681 Vector3Key coordinates_;
682 
683 
684  public:
686  cat_(fh.get_category("physics")),
687  orientation_(fh.get_key<Vector4Tag>(cat_, "orientation")), coordinates_(fh.get_key<Vector3Tag>(cat_, "coordinates")) {
688  }
690  cat_(fh.get_category("physics")),
691  orientation_(fh.get_key<Vector4Tag>(cat_, "orientation")), coordinates_(fh.get_key<Vector3Tag>(cat_, "coordinates")) {
692  }
693  /** Get a RigidParticleConst for nh.*/
695  RMF_USAGE_CHECK((nh.get_type() == RMF::REPRESENTATION), std::string("Bad node type. Got \"")
696  + boost::lexical_cast<std::string>(nh.get_type())
697  + "\" in decorator type RigidParticle");
698  return RigidParticleConst(nh, orientation_,
699 coordinates_);
700  }
701  /** Get a RigidParticle for nh.*/
702  RigidParticle get(NodeHandle nh) const {
703  RMF_USAGE_CHECK((nh.get_type() == RMF::REPRESENTATION), std::string("Bad node type. Got \"")
704  + boost::lexical_cast<std::string>(nh.get_type())
705  + "\" in decorator type RigidParticle");
706  return RigidParticle(nh, orientation_,
707 coordinates_);
708  }
709  /** Check whether nh has all the attributes required to be a
710  RigidParticleConst.*/
711  bool get_is(NodeConstHandle nh) const {
712  return (nh.get_type() == RMF::REPRESENTATION)
713  && !nh.get_value(orientation_).get_is_null();
714  }
715  bool get_is_static(NodeConstHandle nh) const {
716  return (nh.get_type() == RMF::REPRESENTATION)
717  && !nh.get_static_value(orientation_).get_is_null()
718  && !nh.get_static_value(coordinates_).get_is_null();
719  }
720  RMF_SHOWABLE(RigidParticleFactory, "RigidParticleFactory");
721  };
722  #ifndef RMF_DOXYGEN
723 struct RigidParticleConstFactory: public RigidParticleFactory {
724  RigidParticleConstFactory(FileConstHandle fh):
725  RigidParticleFactory(fh) {
726  }
727  RigidParticleConstFactory(FileHandle fh):
728  RigidParticleFactory(fh) {
729  }
730 
731 };
732  #endif
733 
734 
735 
736 
737  /** See also Diffuser and DiffuserFactory.
738  */
739  class DiffuserConst: public Decorator {
740  friend class DiffuserFactory;
741  protected:
742  FloatKey diffusion_coefficient_;
744  FloatKey diffusion_coefficient):
745  Decorator(nh),
746 diffusion_coefficient_(diffusion_coefficient) {
747  }
748  public:
749 
750  Float get_diffusion_coefficient() const {
751  try {
752  return get_node().get_value(diffusion_coefficient_);
753  } RMF_DECORATOR_CATCH( );
754  }
755  Float get_frame_diffusion_coefficient() const {
756  try {
757  return get_node().get_frame_value(diffusion_coefficient_);
758  } RMF_DECORATOR_CATCH( );
759  }
760  Float get_static_diffusion_coefficient() const {
761  try {
762  return get_node().get_static_value(diffusion_coefficient_);
763  } RMF_DECORATOR_CATCH( );
764  }
765 
766  static std::string get_decorator_type_name() {
767  return "DiffuserConst";
768  }
769  RMF_SHOWABLE(DiffuserConst, "Diffuser: " << get_node());
770  };
771  /** See also DiffuserFactory.
772  */
773  class Diffuser: public DiffuserConst {
774  friend class DiffuserFactory;
775  Diffuser(NodeHandle nh,
776  FloatKey diffusion_coefficient):
777  DiffuserConst(nh, diffusion_coefficient) {
778  }
779  public:
780 
781  void set_diffusion_coefficient(Float v) {
782  try {
783  get_node().set_value(diffusion_coefficient_, v);
784  } RMF_DECORATOR_CATCH( );
785  }
786  void set_frame_diffusion_coefficient(Float v) {
787  try {
788  get_node().set_frame_value(diffusion_coefficient_, v);
789  } RMF_DECORATOR_CATCH( );
790  }
791  void set_static_diffusion_coefficient(Float v) {
792  try {
793  get_node().set_static_value(diffusion_coefficient_, v);
794  } RMF_DECORATOR_CATCH( );
795  }
796 
797  static std::string get_decorator_type_name() {
798  return "Diffuser";
799  }
800  };
801 
802 
803  /** Create decorators of type Diffuser.
804  */
805  class DiffuserFactory: public Factory {
806  Category cat_;
807 FloatKey diffusion_coefficient_;
808 
809  public:
811  cat_(fh.get_category("physics")),
812  diffusion_coefficient_(fh.get_key<FloatTag>(cat_, "diffusion coefficient")) {
813  }
815  cat_(fh.get_category("physics")),
816  diffusion_coefficient_(fh.get_key<FloatTag>(cat_, "diffusion coefficient")) {
817  }
818  /** Get a DiffuserConst for nh.*/
820  RMF_USAGE_CHECK((nh.get_type() == RMF::REPRESENTATION), std::string("Bad node type. Got \"")
821  + boost::lexical_cast<std::string>(nh.get_type())
822  + "\" in decorator type Diffuser");
823  return DiffuserConst(nh, diffusion_coefficient_);
824  }
825  /** Get a Diffuser for nh.*/
826  Diffuser get(NodeHandle nh) const {
827  RMF_USAGE_CHECK((nh.get_type() == RMF::REPRESENTATION), std::string("Bad node type. Got \"")
828  + boost::lexical_cast<std::string>(nh.get_type())
829  + "\" in decorator type Diffuser");
830  return Diffuser(nh, diffusion_coefficient_);
831  }
832  /** Check whether nh has all the attributes required to be a
833  DiffuserConst.*/
834  bool get_is(NodeConstHandle nh) const {
835  return (nh.get_type() == RMF::REPRESENTATION)
836  && !nh.get_value(diffusion_coefficient_).get_is_null();
837  }
838  bool get_is_static(NodeConstHandle nh) const {
839  return (nh.get_type() == RMF::REPRESENTATION)
840  && !nh.get_static_value(diffusion_coefficient_).get_is_null();
841  }
842  RMF_SHOWABLE(DiffuserFactory, "DiffuserFactory");
843  };
844  #ifndef RMF_DOXYGEN
845 struct DiffuserConstFactory: public DiffuserFactory {
846  DiffuserConstFactory(FileConstHandle fh):
847  DiffuserFactory(fh) {
848  }
849  DiffuserConstFactory(FileHandle fh):
850  DiffuserFactory(fh) {
851  }
852 
853 };
854  #endif
855 
856 
857 
858 
859  /** See also Atom and AtomFactory.
860  */
861  class AtomConst: public Decorator {
862  friend class AtomFactory;
863  protected:
864  IntKey element_;
865 FloatKey mass_;
866 FloatKey radius_;
868  IntKey element,
869 FloatKey mass,
870 FloatKey radius):
871  Decorator(nh),
872 element_(element),
873 mass_(mass),
874 radius_(radius) {
875  }
876  public:
877 
878  Int get_element() const {
879  try {
880  return get_node().get_value(element_);
881  } RMF_DECORATOR_CATCH( );
882  }
883  Int get_frame_element() const {
884  try {
885  return get_node().get_frame_value(element_);
886  } RMF_DECORATOR_CATCH( );
887  }
888  Int get_static_element() const {
889  try {
890  return get_node().get_static_value(element_);
891  } RMF_DECORATOR_CATCH( );
892  }
893 
894 
895  Float get_mass() const {
896  try {
897  return get_node().get_value(mass_);
898  } RMF_DECORATOR_CATCH( );
899  }
900  Float get_frame_mass() const {
901  try {
902  return get_node().get_frame_value(mass_);
903  } RMF_DECORATOR_CATCH( );
904  }
905  Float get_static_mass() const {
906  try {
907  return get_node().get_static_value(mass_);
908  } RMF_DECORATOR_CATCH( );
909  }
910 
911 
912  Float get_radius() const {
913  try {
914  return get_node().get_value(radius_);
915  } RMF_DECORATOR_CATCH( );
916  }
917  Float get_frame_radius() const {
918  try {
919  return get_node().get_frame_value(radius_);
920  } RMF_DECORATOR_CATCH( );
921  }
922  Float get_static_radius() const {
923  try {
924  return get_node().get_static_value(radius_);
925  } RMF_DECORATOR_CATCH( );
926  }
927 
928  static std::string get_decorator_type_name() {
929  return "AtomConst";
930  }
931  RMF_SHOWABLE(AtomConst, "Atom: " << get_node());
932  };
933  /** See also AtomFactory.
934  */
935  class Atom: public AtomConst {
936  friend class AtomFactory;
937  Atom(NodeHandle nh,
938  IntKey element,
939 FloatKey mass,
940 FloatKey radius):
941  AtomConst(nh, element,
942 mass,
943 radius) {
944  }
945  public:
946 
947  void set_element(Int v) {
948  try {
949  get_node().set_value(element_, v);
950  } RMF_DECORATOR_CATCH( );
951  }
952  void set_frame_element(Int v) {
953  try {
954  get_node().set_frame_value(element_, v);
955  } RMF_DECORATOR_CATCH( );
956  }
957  void set_static_element(Int v) {
958  try {
959  get_node().set_static_value(element_, v);
960  } RMF_DECORATOR_CATCH( );
961  }
962 
963 
964  void set_mass(Float v) {
965  try {
966  get_node().set_value(mass_, v);
967  } RMF_DECORATOR_CATCH( );
968  }
969  void set_frame_mass(Float v) {
970  try {
971  get_node().set_frame_value(mass_, v);
972  } RMF_DECORATOR_CATCH( );
973  }
974  void set_static_mass(Float v) {
975  try {
976  get_node().set_static_value(mass_, v);
977  } RMF_DECORATOR_CATCH( );
978  }
979 
980 
981  void set_radius(Float v) {
982  try {
983  get_node().set_value(radius_, v);
984  } RMF_DECORATOR_CATCH( );
985  }
986  void set_frame_radius(Float v) {
987  try {
988  get_node().set_frame_value(radius_, v);
989  } RMF_DECORATOR_CATCH( );
990  }
991  void set_static_radius(Float v) {
992  try {
993  get_node().set_static_value(radius_, v);
994  } RMF_DECORATOR_CATCH( );
995  }
996 
997  static std::string get_decorator_type_name() {
998  return "Atom";
999  }
1000  };
1001 
1002 
1003  /** Create decorators of type Atom.
1004  */
1005  class AtomFactory: public Factory {
1006  Category cat_;
1007 IntKey element_;
1008 FloatKey mass_;
1009 FloatKey radius_;
1010 
1011 
1012 
1013  public:
1015  cat_(fh.get_category("physics")),
1016  element_(fh.get_key<IntTag>(cat_, "element")), mass_(fh.get_key<FloatTag>(cat_, "mass")), radius_(fh.get_key<FloatTag>(cat_, "radius")) {
1017  }
1018  AtomFactory(FileHandle fh):
1019  cat_(fh.get_category("physics")),
1020  element_(fh.get_key<IntTag>(cat_, "element")), mass_(fh.get_key<FloatTag>(cat_, "mass")), radius_(fh.get_key<FloatTag>(cat_, "radius")) {
1021  }
1022  /** Get a AtomConst for nh.*/
1023  AtomConst get(NodeConstHandle nh) const {
1024  RMF_USAGE_CHECK((nh.get_type() == RMF::REPRESENTATION), std::string("Bad node type. Got \"")
1025  + boost::lexical_cast<std::string>(nh.get_type())
1026  + "\" in decorator type Atom");
1027  return AtomConst(nh, element_,
1028 mass_,
1029 radius_);
1030  }
1031  /** Get a Atom for nh.*/
1032  Atom get(NodeHandle nh) const {
1033  RMF_USAGE_CHECK((nh.get_type() == RMF::REPRESENTATION), std::string("Bad node type. Got \"")
1034  + boost::lexical_cast<std::string>(nh.get_type())
1035  + "\" in decorator type Atom");
1036  return Atom(nh, element_,
1037 mass_,
1038 radius_);
1039  }
1040  /** Check whether nh has all the attributes required to be a
1041  AtomConst.*/
1042  bool get_is(NodeConstHandle nh) const {
1043  return (nh.get_type() == RMF::REPRESENTATION)
1044  && !nh.get_value(element_).get_is_null();
1045  }
1046  bool get_is_static(NodeConstHandle nh) const {
1047  return (nh.get_type() == RMF::REPRESENTATION)
1048  && !nh.get_static_value(element_).get_is_null()
1049  && !nh.get_static_value(mass_).get_is_null()
1050  && !nh.get_static_value(radius_).get_is_null();
1051  }
1052  RMF_SHOWABLE(AtomFactory, "AtomFactory");
1053  };
1054  #ifndef RMF_DOXYGEN
1055 struct AtomConstFactory: public AtomFactory {
1056  AtomConstFactory(FileConstHandle fh):
1057  AtomFactory(fh) {
1058  }
1059  AtomConstFactory(FileHandle fh):
1060  AtomFactory(fh) {
1061  }
1062 
1063 };
1064  #endif
1065 
1066 
1067 
1068 
1069  /** See also ReferenceFrame and ReferenceFrameFactory.
1070  */
1072  friend class ReferenceFrameFactory;
1073  protected:
1074  Vector4Key rotation_;
1075 Vector3Key translation_;
1077  Vector4Key rotation,
1078 Vector3Key translation):
1079  Decorator(nh),
1080 rotation_(rotation),
1081 translation_(translation) {
1082  }
1083  public:
1084 
1085  Vector4 get_rotation() const {
1086  try {
1087  return get_node().get_value(rotation_);
1088  } RMF_DECORATOR_CATCH( );
1089  }
1090  Vector4 get_frame_rotation() const {
1091  try {
1092  return get_node().get_frame_value(rotation_);
1093  } RMF_DECORATOR_CATCH( );
1094  }
1095  Vector4 get_static_rotation() const {
1096  try {
1097  return get_node().get_static_value(rotation_);
1098  } RMF_DECORATOR_CATCH( );
1099  }
1100 
1101 
1102  Vector3 get_translation() const {
1103  try {
1104  return get_node().get_value(translation_);
1105  } RMF_DECORATOR_CATCH( );
1106  }
1107  Vector3 get_frame_translation() const {
1108  try {
1109  return get_node().get_frame_value(translation_);
1110  } RMF_DECORATOR_CATCH( );
1111  }
1112  Vector3 get_static_translation() const {
1113  try {
1114  return get_node().get_static_value(translation_);
1115  } RMF_DECORATOR_CATCH( );
1116  }
1117 
1118  static std::string get_decorator_type_name() {
1119  return "ReferenceFrameConst";
1120  }
1121  RMF_SHOWABLE(ReferenceFrameConst, "ReferenceFrame: " << get_node());
1122  };
1123  /** See also ReferenceFrameFactory.
1124  */
1126  friend class ReferenceFrameFactory;
1128  Vector4Key rotation,
1129 Vector3Key translation):
1130  ReferenceFrameConst(nh, rotation,
1131 translation) {
1132  }
1133  public:
1134 
1135  void set_rotation(Vector4 v) {
1136  try {
1137  get_node().set_value(rotation_, v);
1138  } RMF_DECORATOR_CATCH( );
1139  }
1140  void set_frame_rotation(Vector4 v) {
1141  try {
1142  get_node().set_frame_value(rotation_, v);
1143  } RMF_DECORATOR_CATCH( );
1144  }
1145  void set_static_rotation(Vector4 v) {
1146  try {
1147  get_node().set_static_value(rotation_, v);
1148  } RMF_DECORATOR_CATCH( );
1149  }
1150 
1151 
1152  void set_translation(Vector3 v) {
1153  try {
1154  get_node().set_value(translation_, v);
1155  } RMF_DECORATOR_CATCH( );
1156  }
1157  void set_frame_translation(Vector3 v) {
1158  try {
1159  get_node().set_frame_value(translation_, v);
1160  } RMF_DECORATOR_CATCH( );
1161  }
1162  void set_static_translation(Vector3 v) {
1163  try {
1164  get_node().set_static_value(translation_, v);
1165  } RMF_DECORATOR_CATCH( );
1166  }
1167 
1168  static std::string get_decorator_type_name() {
1169  return "ReferenceFrame";
1170  }
1171  };
1172 
1173 
1174  /** Create decorators of type ReferenceFrame.
1175  */
1177  Category cat_;
1178 Vector4Key rotation_;
1179 Vector3Key translation_;
1180 
1181 
1182  public:
1184  cat_(fh.get_category("physics")),
1185  rotation_(fh.get_key<Vector4Tag>(cat_, "rotation")), translation_(fh.get_key<Vector3Tag>(cat_, "translation")) {
1186  }
1188  cat_(fh.get_category("physics")),
1189  rotation_(fh.get_key<Vector4Tag>(cat_, "rotation")), translation_(fh.get_key<Vector3Tag>(cat_, "translation")) {
1190  }
1191  /** Get a ReferenceFrameConst for nh.*/
1193  RMF_USAGE_CHECK((nh.get_type() == RMF::REPRESENTATION||nh.get_type() == RMF::ORGANIZATIONAL), std::string("Bad node type. Got \"")
1194  + boost::lexical_cast<std::string>(nh.get_type())
1195  + "\" in decorator type ReferenceFrame");
1196  return ReferenceFrameConst(nh, rotation_,
1197 translation_);
1198  }
1199  /** Get a ReferenceFrame for nh.*/
1200  ReferenceFrame get(NodeHandle nh) const {
1201  RMF_USAGE_CHECK((nh.get_type() == RMF::REPRESENTATION||nh.get_type() == RMF::ORGANIZATIONAL), std::string("Bad node type. Got \"")
1202  + boost::lexical_cast<std::string>(nh.get_type())
1203  + "\" in decorator type ReferenceFrame");
1204  return ReferenceFrame(nh, rotation_,
1205 translation_);
1206  }
1207  /** Check whether nh has all the attributes required to be a
1208  ReferenceFrameConst.*/
1209  bool get_is(NodeConstHandle nh) const {
1210  return (nh.get_type() == RMF::REPRESENTATION||nh.get_type() == RMF::ORGANIZATIONAL)
1211  && !nh.get_value(rotation_).get_is_null();
1212  }
1213  bool get_is_static(NodeConstHandle nh) const {
1214  return (nh.get_type() == RMF::REPRESENTATION||nh.get_type() == RMF::ORGANIZATIONAL)
1215  && !nh.get_static_value(rotation_).get_is_null()
1216  && !nh.get_static_value(translation_).get_is_null();
1217  }
1218  RMF_SHOWABLE(ReferenceFrameFactory, "ReferenceFrameFactory");
1219  };
1220  #ifndef RMF_DOXYGEN
1221 struct ReferenceFrameConstFactory: public ReferenceFrameFactory {
1222  ReferenceFrameConstFactory(FileConstHandle fh):
1223  ReferenceFrameFactory(fh) {
1224  }
1225  ReferenceFrameConstFactory(FileHandle fh):
1226  ReferenceFrameFactory(fh) {
1227  }
1228 
1229 };
1230  #endif
1231 
1232 
1233 
1234 } /* namespace decorator */
1235 } /* namespace RMF */
1236 RMF_DISABLE_WARNINGS
1237 
1238 #endif /* RMF_PHYSICS_DECORATORS_H */
Mostly empty base classes for decorators and factories.
bool get_is(NodeConstHandle nh) const
Definition: physics.h:545
const NodeType REPRESENTATION
Represent part of a molecule.
bool get_is(NodeConstHandle nh) const
Definition: physics.h:1209
A handle for a particular node in the hierarchy.
Definition: NodeHandle.h:60
bool get_is(NodeConstHandle nh) const
Definition: physics.h:1042
float Float
Definition: types.h:33
The base class for decorators.
Definition: Decorator.h:29
NodeType get_type() const
get the type of this node
Various constants.
bool get_is(NodeConstHandle nh) const
Definition: physics.h:834
A handle for a particular node in a read-only hierarchy.
Helper functions for manipulating RMF files.
A handle for a read-only RMF file.
void set_value(ID< Tag > k, typename Tag::ArgumentType v) const
Definition: NodeHandle.h:115
A handle for an RMF file.
Definition: FileHandle.h:54
bool get_is(NodeConstHandle nh) const
Definition: physics.h:711
The base class for Factories.
Definition: Decorator.h:46
Declaration for RMF::FileHandle.
Represent coordinates.
Declaration of NodeHandle.
bool get_is(NodeConstHandle nh) const
Definition: physics.h:212
void set_static_value(ID< Tag > k, typename Tag::ArgumentType v) const
set the value of the attribute k for all frames.
Definition: NodeHandle.h:122
ID< Tag > get_key(Category category, std::string name) const
int Int
Definition: types.h:29
bool get_is(NodeConstHandle nh) const
Definition: physics.h:379
Various general useful macros for IMP.
const NodeType ORGANIZATIONAL
A node that is purely there for organizational purposes.
void set_frame_value(ID< Tag > k, typename Tag::ArgumentType v) const
set the value of the attribute k for this node on the current frame.
Definition: NodeHandle.h:103
Traits classes describing how RMF uses types for storing data.
Definition: traits.h:31