RMF
sequence.h
Go to the documentation of this file.
1 /**
2  * \file RMF/decorator/sequence.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_SEQUENCE_DECORATORS_H
10 #define RMF_SEQUENCE_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 
23 RMF_ENABLE_WARNINGS
24 namespace RMF {
25 namespace decorator {
26 
27 
28  /** See also Residue and ResidueFactory.
29  */
30  class ResidueConst: public Decorator {
31  friend class ResidueFactory;
32  protected:
33  IntKey residue_index_;
34 StringKey residue_type_;
36  IntKey residue_index,
37 StringKey residue_type):
38  Decorator(nh),
39 residue_index_(residue_index),
40 residue_type_(residue_type) {
41  }
42  public:
43 
44  Int get_residue_index() const {
45  try {
46  return get_node().get_value(residue_index_);
47  } RMF_DECORATOR_CATCH( );
48  }
49  Int get_frame_residue_index() const {
50  try {
51  return get_node().get_frame_value(residue_index_);
52  } RMF_DECORATOR_CATCH( );
53  }
54  Int get_static_residue_index() const {
55  try {
56  return get_node().get_static_value(residue_index_);
57  } RMF_DECORATOR_CATCH( );
58  }
59 
60 
61  String get_residue_type() const {
62  try {
63  return get_node().get_value(residue_type_);
64  } RMF_DECORATOR_CATCH( );
65  }
66  String get_frame_residue_type() const {
67  try {
68  return get_node().get_frame_value(residue_type_);
69  } RMF_DECORATOR_CATCH( );
70  }
71  String get_static_residue_type() const {
72  try {
73  return get_node().get_static_value(residue_type_);
74  } RMF_DECORATOR_CATCH( );
75  }
76 
77  static std::string get_decorator_type_name() {
78  return "ResidueConst";
79  }
80  RMF_SHOWABLE(ResidueConst, "Residue: " << get_node());
81  };
82  /** See also ResidueFactory.
83  */
84  class Residue: public ResidueConst {
85  friend class ResidueFactory;
87  IntKey residue_index,
88 StringKey residue_type):
89  ResidueConst(nh, residue_index,
90 residue_type) {
91  }
92  public:
93 
94  void set_residue_index(Int v) {
95  try {
96  get_node().set_value(residue_index_, v);
97  } RMF_DECORATOR_CATCH( );
98  }
99  void set_frame_residue_index(Int v) {
100  try {
101  get_node().set_frame_value(residue_index_, v);
102  } RMF_DECORATOR_CATCH( );
103  }
104  void set_static_residue_index(Int v) {
105  try {
106  get_node().set_static_value(residue_index_, v);
107  } RMF_DECORATOR_CATCH( );
108  }
109 
110 
111  void set_residue_type(String v) {
112  try {
113  get_node().set_value(residue_type_, v);
114  } RMF_DECORATOR_CATCH( );
115  }
116  void set_frame_residue_type(String v) {
117  try {
118  get_node().set_frame_value(residue_type_, v);
119  } RMF_DECORATOR_CATCH( );
120  }
121  void set_static_residue_type(String v) {
122  try {
123  get_node().set_static_value(residue_type_, v);
124  } RMF_DECORATOR_CATCH( );
125  }
126 
127  static std::string get_decorator_type_name() {
128  return "Residue";
129  }
130  };
131 
132 
133  /** Create decorators of type Residue.
134  */
135  class ResidueFactory: public Factory {
136  Category cat_;
137 IntKey residue_index_;
138 StringKey residue_type_;
139 
140 
141  public:
143  cat_(fh.get_category("sequence")),
144  residue_index_(fh.get_key<IntTag>(cat_, "residue index")), residue_type_(fh.get_key<StringTag>(cat_, "residue type")) {
145  }
147  cat_(fh.get_category("sequence")),
148  residue_index_(fh.get_key<IntTag>(cat_, "residue index")), residue_type_(fh.get_key<StringTag>(cat_, "residue type")) {
149  }
150  /** Get a ResidueConst for nh.*/
152  RMF_USAGE_CHECK((nh.get_type() == RMF::REPRESENTATION), std::string("Bad node type. Got \"")
153  + boost::lexical_cast<std::string>(nh.get_type())
154  + "\" in decorator type Residue");
155  return ResidueConst(nh, residue_index_,
156 residue_type_);
157  }
158  /** Get a Residue for nh.*/
159  Residue get(NodeHandle nh) const {
160  RMF_USAGE_CHECK((nh.get_type() == RMF::REPRESENTATION), std::string("Bad node type. Got \"")
161  + boost::lexical_cast<std::string>(nh.get_type())
162  + "\" in decorator type Residue");
163  return Residue(nh, residue_index_,
164 residue_type_);
165  }
166  /** Check whether nh has all the attributes required to be a
167  ResidueConst.*/
168  bool get_is(NodeConstHandle nh) const {
169  return (nh.get_type() == RMF::REPRESENTATION)
170  && !nh.get_value(residue_index_).get_is_null();
171  }
172  bool get_is_static(NodeConstHandle nh) const {
173  return (nh.get_type() == RMF::REPRESENTATION)
174  && !nh.get_static_value(residue_index_).get_is_null()
175  && !nh.get_static_value(residue_type_).get_is_null();
176  }
177  RMF_SHOWABLE(ResidueFactory, "ResidueFactory");
178  };
179  #ifndef RMF_DOXYGEN
180 struct ResidueConstFactory: public ResidueFactory {
181  ResidueConstFactory(FileConstHandle fh):
182  ResidueFactory(fh) {
183  }
184  ResidueConstFactory(FileHandle fh):
185  ResidueFactory(fh) {
186  }
187 
188 };
189  #endif
190 
191 
192 
193 
194  /** See also Chain and ChainFactory.
195  */
196  class ChainConst: public Decorator {
197  friend class ChainFactory;
198  protected:
199  StringKey chain_id_;
200 StringKey sequence_;
201 IntKey sequence_offset_;
202 StringKey uniprot_accession_;
203 StringKey chain_type_;
205  StringKey chain_id,
206 StringKey sequence,
207 IntKey sequence_offset,
208 StringKey uniprot_accession,
209 StringKey chain_type):
210  Decorator(nh),
211 chain_id_(chain_id),
212 sequence_(sequence),
213 sequence_offset_(sequence_offset),
214 uniprot_accession_(uniprot_accession),
215 chain_type_(chain_type) {
216  }
217  public:
218 
219  String get_chain_id() const {
220  try {
221  return get_node().get_value(chain_id_);
222  } RMF_DECORATOR_CATCH( );
223  }
224  String get_frame_chain_id() const {
225  try {
226  return get_node().get_frame_value(chain_id_);
227  } RMF_DECORATOR_CATCH( );
228  }
229  String get_static_chain_id() const {
230  try {
231  return get_node().get_static_value(chain_id_);
232  } RMF_DECORATOR_CATCH( );
233  }
234 
235 
236  String get_sequence() const {
237  try {
238  if (!get_node().get_has_value(sequence_)) return "";
239 return get_node().get_value(sequence_);
240  } RMF_DECORATOR_CATCH( );
241  }
242  String get_frame_sequence() const {
243  try {
244  if (!get_node().get_has_value(sequence_)) return "";
245 return get_node().get_frame_value(sequence_);
246  } RMF_DECORATOR_CATCH( );
247  }
248  String get_static_sequence() const {
249  try {
250  if (!get_node().get_has_value(sequence_)) return "";
251 return get_node().get_static_value(sequence_);
252  } RMF_DECORATOR_CATCH( );
253  }
254 
255 
256  Int get_sequence_offset() const {
257  try {
258  if (!get_node().get_has_value(sequence_offset_)) return 0;
259 return get_node().get_value(sequence_offset_);
260  } RMF_DECORATOR_CATCH( );
261  }
262  Int get_frame_sequence_offset() const {
263  try {
264  if (!get_node().get_has_value(sequence_offset_)) return 0;
265 return get_node().get_frame_value(sequence_offset_);
266  } RMF_DECORATOR_CATCH( );
267  }
268  Int get_static_sequence_offset() const {
269  try {
270  if (!get_node().get_has_value(sequence_offset_)) return 0;
271 return get_node().get_static_value(sequence_offset_);
272  } RMF_DECORATOR_CATCH( );
273  }
274 
275 
276  String get_uniprot_accession() const {
277  try {
278  if (!get_node().get_has_value(uniprot_accession_)) return "";
279 return get_node().get_value(uniprot_accession_);
280  } RMF_DECORATOR_CATCH( );
281  }
282  String get_frame_uniprot_accession() const {
283  try {
284  if (!get_node().get_has_value(uniprot_accession_)) return "";
285 return get_node().get_frame_value(uniprot_accession_);
286  } RMF_DECORATOR_CATCH( );
287  }
288  String get_static_uniprot_accession() const {
289  try {
290  if (!get_node().get_has_value(uniprot_accession_)) return "";
291 return get_node().get_static_value(uniprot_accession_);
292  } RMF_DECORATOR_CATCH( );
293  }
294 
295 
296  String get_chain_type() const {
297  try {
298  if (!get_node().get_has_value(chain_type_)) return "UnknownChainType";
299 return get_node().get_value(chain_type_);
300  } RMF_DECORATOR_CATCH( );
301  }
302  String get_frame_chain_type() const {
303  try {
304  if (!get_node().get_has_value(chain_type_)) return "UnknownChainType";
305 return get_node().get_frame_value(chain_type_);
306  } RMF_DECORATOR_CATCH( );
307  }
308  String get_static_chain_type() const {
309  try {
310  if (!get_node().get_has_value(chain_type_)) return "UnknownChainType";
311 return get_node().get_static_value(chain_type_);
312  } RMF_DECORATOR_CATCH( );
313  }
314 
315  static std::string get_decorator_type_name() {
316  return "ChainConst";
317  }
318  RMF_SHOWABLE(ChainConst, "Chain: " << get_node());
319  };
320  /** See also ChainFactory.
321  */
322  class Chain: public ChainConst {
323  friend class ChainFactory;
324  Chain(NodeHandle nh,
325  StringKey chain_id,
326 StringKey sequence,
327 IntKey sequence_offset,
328 StringKey uniprot_accession,
329 StringKey chain_type):
330  ChainConst(nh, chain_id,
331 sequence,
332 sequence_offset,
333 uniprot_accession,
334 chain_type) {
335  }
336  public:
337 
338  void set_chain_id(String v) {
339  try {
340  get_node().set_value(chain_id_, v);
341  } RMF_DECORATOR_CATCH( );
342  }
343  void set_frame_chain_id(String v) {
344  try {
345  get_node().set_frame_value(chain_id_, v);
346  } RMF_DECORATOR_CATCH( );
347  }
348  void set_static_chain_id(String v) {
349  try {
350  get_node().set_static_value(chain_id_, v);
351  } RMF_DECORATOR_CATCH( );
352  }
353 
354 
355  void set_sequence(String v) {
356  try {
357  get_node().set_value(sequence_, v);
358  } RMF_DECORATOR_CATCH( );
359  }
360  void set_frame_sequence(String v) {
361  try {
362  get_node().set_frame_value(sequence_, v);
363  } RMF_DECORATOR_CATCH( );
364  }
365  void set_static_sequence(String v) {
366  try {
367  get_node().set_static_value(sequence_, v);
368  } RMF_DECORATOR_CATCH( );
369  }
370 
371 
372  void set_sequence_offset(Int v) {
373  try {
374  get_node().set_value(sequence_offset_, v);
375  } RMF_DECORATOR_CATCH( );
376  }
377  void set_frame_sequence_offset(Int v) {
378  try {
379  get_node().set_frame_value(sequence_offset_, v);
380  } RMF_DECORATOR_CATCH( );
381  }
382  void set_static_sequence_offset(Int v) {
383  try {
384  get_node().set_static_value(sequence_offset_, v);
385  } RMF_DECORATOR_CATCH( );
386  }
387 
388 
389  void set_uniprot_accession(String v) {
390  try {
391  get_node().set_value(uniprot_accession_, v);
392  } RMF_DECORATOR_CATCH( );
393  }
394  void set_frame_uniprot_accession(String v) {
395  try {
396  get_node().set_frame_value(uniprot_accession_, v);
397  } RMF_DECORATOR_CATCH( );
398  }
399  void set_static_uniprot_accession(String v) {
400  try {
401  get_node().set_static_value(uniprot_accession_, v);
402  } RMF_DECORATOR_CATCH( );
403  }
404 
405 
406  void set_chain_type(String v) {
407  try {
408  get_node().set_value(chain_type_, v);
409  } RMF_DECORATOR_CATCH( );
410  }
411  void set_frame_chain_type(String v) {
412  try {
413  get_node().set_frame_value(chain_type_, v);
414  } RMF_DECORATOR_CATCH( );
415  }
416  void set_static_chain_type(String v) {
417  try {
418  get_node().set_static_value(chain_type_, v);
419  } RMF_DECORATOR_CATCH( );
420  }
421 
422  static std::string get_decorator_type_name() {
423  return "Chain";
424  }
425  };
426 
427 
428  /** Create decorators of type Chain.
429  */
430  class ChainFactory: public Factory {
431  Category cat_;
432 StringKey chain_id_;
433 StringKey sequence_;
434 IntKey sequence_offset_;
435 StringKey uniprot_accession_;
436 StringKey chain_type_;
437 
438 
439 
440 
441 
442  public:
444  cat_(fh.get_category("sequence")),
445  chain_id_(fh.get_key<StringTag>(cat_, "chain id")), sequence_(fh.get_key<StringTag>(cat_, "sequence")), sequence_offset_(fh.get_key<IntTag>(cat_, "sequence offset")), uniprot_accession_(fh.get_key<StringTag>(cat_, "uniprot accession")), chain_type_(fh.get_key<StringTag>(cat_, "chain type")) {
446  }
448  cat_(fh.get_category("sequence")),
449  chain_id_(fh.get_key<StringTag>(cat_, "chain id")), sequence_(fh.get_key<StringTag>(cat_, "sequence")), sequence_offset_(fh.get_key<IntTag>(cat_, "sequence offset")), uniprot_accession_(fh.get_key<StringTag>(cat_, "uniprot accession")), chain_type_(fh.get_key<StringTag>(cat_, "chain type")) {
450  }
451  /** Get a ChainConst for nh.*/
452  ChainConst get(NodeConstHandle nh) const {
453  RMF_USAGE_CHECK((nh.get_type() == RMF::REPRESENTATION), std::string("Bad node type. Got \"")
454  + boost::lexical_cast<std::string>(nh.get_type())
455  + "\" in decorator type Chain");
456  return ChainConst(nh, chain_id_,
457 sequence_,
458 sequence_offset_,
459 uniprot_accession_,
460 chain_type_);
461  }
462  /** Get a Chain for nh.*/
463  Chain get(NodeHandle nh) const {
464  RMF_USAGE_CHECK((nh.get_type() == RMF::REPRESENTATION), std::string("Bad node type. Got \"")
465  + boost::lexical_cast<std::string>(nh.get_type())
466  + "\" in decorator type Chain");
467  return Chain(nh, chain_id_,
468 sequence_,
469 sequence_offset_,
470 uniprot_accession_,
471 chain_type_);
472  }
473  /** Check whether nh has all the attributes required to be a
474  ChainConst.*/
475  bool get_is(NodeConstHandle nh) const {
476  return (nh.get_type() == RMF::REPRESENTATION)
477  && !nh.get_value(chain_id_).get_is_null();
478  }
479  bool get_is_static(NodeConstHandle nh) const {
480  return (nh.get_type() == RMF::REPRESENTATION)
481  && !nh.get_static_value(chain_id_).get_is_null();
482  }
483  RMF_SHOWABLE(ChainFactory, "ChainFactory");
484  };
485  #ifndef RMF_DOXYGEN
486 struct ChainConstFactory: public ChainFactory {
487  ChainConstFactory(FileConstHandle fh):
488  ChainFactory(fh) {
489  }
490  ChainConstFactory(FileHandle fh):
491  ChainFactory(fh) {
492  }
493 
494 };
495  #endif
496 
497 
498 
499 
500  /** See also Fragment and FragmentFactory.
501  */
502  class FragmentConst: public Decorator {
503  friend class FragmentFactory;
504  protected:
505  IntsKey residue_indexes_;
507  IntsKey residue_indexes):
508  Decorator(nh),
509 residue_indexes_(residue_indexes) {
510  }
511  public:
512 
513  Ints get_residue_indexes() const {
514  try {
515  return get_node().get_value(residue_indexes_);
516  } RMF_DECORATOR_CATCH( );
517  }
518  Ints get_frame_residue_indexes() const {
519  try {
520  return get_node().get_frame_value(residue_indexes_);
521  } RMF_DECORATOR_CATCH( );
522  }
523  Ints get_static_residue_indexes() const {
524  try {
525  return get_node().get_static_value(residue_indexes_);
526  } RMF_DECORATOR_CATCH( );
527  }
528 
529  static std::string get_decorator_type_name() {
530  return "FragmentConst";
531  }
532  RMF_SHOWABLE(FragmentConst, "Fragment: " << get_node());
533  };
534  /** See also FragmentFactory.
535  */
536  class Fragment: public FragmentConst {
537  friend class FragmentFactory;
538  Fragment(NodeHandle nh,
539  IntsKey residue_indexes):
540  FragmentConst(nh, residue_indexes) {
541  }
542  public:
543 
544  void set_residue_indexes(Ints v) {
545  try {
546  get_node().set_value(residue_indexes_, v);
547  } RMF_DECORATOR_CATCH( );
548  }
549  void set_frame_residue_indexes(Ints v) {
550  try {
551  get_node().set_frame_value(residue_indexes_, v);
552  } RMF_DECORATOR_CATCH( );
553  }
554  void set_static_residue_indexes(Ints v) {
555  try {
556  get_node().set_static_value(residue_indexes_, v);
557  } RMF_DECORATOR_CATCH( );
558  }
559 
560  static std::string get_decorator_type_name() {
561  return "Fragment";
562  }
563  };
564 
565 
566  /** Create decorators of type Fragment.
567  */
568  class FragmentFactory: public Factory {
569  Category cat_;
570 IntsKey residue_indexes_;
571 
572  public:
574  cat_(fh.get_category("sequence")),
575  residue_indexes_(fh.get_key<IntsTag>(cat_, "residue indexes")) {
576  }
578  cat_(fh.get_category("sequence")),
579  residue_indexes_(fh.get_key<IntsTag>(cat_, "residue indexes")) {
580  }
581  /** Get a FragmentConst for nh.*/
583  RMF_USAGE_CHECK((nh.get_type() == RMF::REPRESENTATION), std::string("Bad node type. Got \"")
584  + boost::lexical_cast<std::string>(nh.get_type())
585  + "\" in decorator type Fragment");
586  return FragmentConst(nh, residue_indexes_);
587  }
588  /** Get a Fragment for nh.*/
589  Fragment get(NodeHandle nh) const {
590  RMF_USAGE_CHECK((nh.get_type() == RMF::REPRESENTATION), std::string("Bad node type. Got \"")
591  + boost::lexical_cast<std::string>(nh.get_type())
592  + "\" in decorator type Fragment");
593  return Fragment(nh, residue_indexes_);
594  }
595  /** Check whether nh has all the attributes required to be a
596  FragmentConst.*/
597  bool get_is(NodeConstHandle nh) const {
598  return (nh.get_type() == RMF::REPRESENTATION)
599  && !nh.get_value(residue_indexes_).get_is_null();
600  }
601  bool get_is_static(NodeConstHandle nh) const {
602  return (nh.get_type() == RMF::REPRESENTATION)
603  && !nh.get_static_value(residue_indexes_).get_is_null();
604  }
605  RMF_SHOWABLE(FragmentFactory, "FragmentFactory");
606  };
607  #ifndef RMF_DOXYGEN
608 struct FragmentConstFactory: public FragmentFactory {
609  FragmentConstFactory(FileConstHandle fh):
610  FragmentFactory(fh) {
611  }
612  FragmentConstFactory(FileHandle fh):
613  FragmentFactory(fh) {
614  }
615 
616 };
617  #endif
618 
619 
620 
621 
622  /** See also BackwardsCompatibilityFragment and BackwardsCompatibilityFragmentFactory.
623  */
626  protected:
627  IntsKey indexes_;
629  IntsKey indexes):
630  Decorator(nh),
631 indexes_(indexes) {
632  }
633  public:
634 
635  Ints get_indexes() const {
636  try {
637  return get_node().get_value(indexes_);
638  } RMF_DECORATOR_CATCH( );
639  }
640  Ints get_frame_indexes() const {
641  try {
642  return get_node().get_frame_value(indexes_);
643  } RMF_DECORATOR_CATCH( );
644  }
645  Ints get_static_indexes() const {
646  try {
647  return get_node().get_static_value(indexes_);
648  } RMF_DECORATOR_CATCH( );
649  }
650 
651  static std::string get_decorator_type_name() {
652  return "BackwardsCompatibilityFragmentConst";
653  }
654  RMF_SHOWABLE(BackwardsCompatibilityFragmentConst, "BackwardsCompatibilityFragment: " << get_node());
655  };
656  /** See also BackwardsCompatibilityFragmentFactory.
657  */
661  IntsKey indexes):
663  }
664  public:
665 
666  void set_indexes(Ints v) {
667  try {
668  get_node().set_value(indexes_, v);
669  } RMF_DECORATOR_CATCH( );
670  }
671  void set_frame_indexes(Ints v) {
672  try {
673  get_node().set_frame_value(indexes_, v);
674  } RMF_DECORATOR_CATCH( );
675  }
676  void set_static_indexes(Ints v) {
677  try {
678  get_node().set_static_value(indexes_, v);
679  } RMF_DECORATOR_CATCH( );
680  }
681 
682  static std::string get_decorator_type_name() {
683  return "BackwardsCompatibilityFragment";
684  }
685  };
686 
687 
688  /** Create decorators of type BackwardsCompatibilityFragment.
689  */
691  Category cat_;
692 IntsKey indexes_;
693 
694  public:
696  cat_(fh.get_category("sequence")),
697  indexes_(fh.get_key<IntsTag>(cat_, "indexes")) {
698  }
700  cat_(fh.get_category("sequence")),
701  indexes_(fh.get_key<IntsTag>(cat_, "indexes")) {
702  }
703  /** Get a BackwardsCompatibilityFragmentConst for nh.*/
705  RMF_USAGE_CHECK((nh.get_type() == RMF::REPRESENTATION), std::string("Bad node type. Got \"")
706  + boost::lexical_cast<std::string>(nh.get_type())
707  + "\" in decorator type BackwardsCompatibilityFragment");
708  return BackwardsCompatibilityFragmentConst(nh, indexes_);
709  }
710  /** Get a BackwardsCompatibilityFragment for nh.*/
712  RMF_USAGE_CHECK((nh.get_type() == RMF::REPRESENTATION), std::string("Bad node type. Got \"")
713  + boost::lexical_cast<std::string>(nh.get_type())
714  + "\" in decorator type BackwardsCompatibilityFragment");
715  return BackwardsCompatibilityFragment(nh, indexes_);
716  }
717  /** Check whether nh has all the attributes required to be a
718  BackwardsCompatibilityFragmentConst.*/
719  bool get_is(NodeConstHandle nh) const {
720  return (nh.get_type() == RMF::REPRESENTATION)
721  && !nh.get_value(indexes_).get_is_null();
722  }
723  bool get_is_static(NodeConstHandle nh) const {
724  return (nh.get_type() == RMF::REPRESENTATION)
725  && !nh.get_static_value(indexes_).get_is_null();
726  }
727  RMF_SHOWABLE(BackwardsCompatibilityFragmentFactory, "BackwardsCompatibilityFragmentFactory");
728  };
729  #ifndef RMF_DOXYGEN
730 struct BackwardsCompatibilityFragmentConstFactory: public BackwardsCompatibilityFragmentFactory {
731  BackwardsCompatibilityFragmentConstFactory(FileConstHandle fh):
732  BackwardsCompatibilityFragmentFactory(fh) {
733  }
734  BackwardsCompatibilityFragmentConstFactory(FileHandle fh):
735  BackwardsCompatibilityFragmentFactory(fh) {
736  }
737 
738 };
739  #endif
740 
741 
742 
743 
744  /** See also Domain and DomainFactory.
745  */
746  class DomainConst: public Decorator {
747  friend class DomainFactory;
748  protected:
749  std::array<IntKey, 2> residue_indexes_;
751  std::array<IntKey, 2> residue_indexes):
752  Decorator(nh),
753 residue_indexes_(residue_indexes) {
754  }
755  public:
756 
757  IntRange get_residue_indexes() const {
758  try {
759  IntRange ret;
760  ret[0] = get_node().get_value(residue_indexes_[0]);
761  ret[1] = get_node().get_value(residue_indexes_[1]);
762  return ret;
763  } RMF_DECORATOR_CATCH( );
764  }
765  IntRange get_static_residue_indexes() const {
766  try {
767  IntRange ret;
768  ret[0] = get_node().get_static_value(residue_indexes_[0]);
769  ret[1] = get_node().get_static_value(residue_indexes_[1]);
770  return ret;
771  } RMF_DECORATOR_CATCH( );
772  }
773  IntRange get_frame_residue_indexes() const {
774  try {
775  IntRange ret;
776  ret[0] = get_node().get_frame_value(residue_indexes_[0]);
777  ret[1] = get_node().get_frame_value(residue_indexes_[1]);
778  return ret;
779  } RMF_DECORATOR_CATCH( );
780  }
781 
782  static std::string get_decorator_type_name() {
783  return "DomainConst";
784  }
785  RMF_SHOWABLE(DomainConst, "Domain: " << get_node());
786  };
787  /** See also DomainFactory.
788  */
789  class Domain: public DomainConst {
790  friend class DomainFactory;
791  Domain(NodeHandle nh,
792  std::array<IntKey, 2> residue_indexes):
793  DomainConst(nh, residue_indexes) {
794  }
795  public:
796 
797  void set_residue_indexes(Int v0, Int v1) {
798  try {
799  get_node().set_value(residue_indexes_[0], v0);
800  get_node().set_value(residue_indexes_[1], v1);
801  } RMF_DECORATOR_CATCH( );
802  }
803  void set_frame_residue_indexes(Int v0, Int v1) {
804  try {
805  get_node().set_frame_value(residue_indexes_[0], v0);
806  get_node().set_frame_value(residue_indexes_[1], v1);
807  } RMF_DECORATOR_CATCH( );
808  }
809  void set_static_residue_indexes(Int v0, Int v1) {
810  try {
811  get_node().set_static_value(residue_indexes_[0], v0);
812  get_node().set_static_value(residue_indexes_[1], v1);
813  } RMF_DECORATOR_CATCH( );
814  }
815 
816  static std::string get_decorator_type_name() {
817  return "Domain";
818  }
819  };
820 
821 
822  /** Create decorators of type Domain.
823  */
824  class DomainFactory: public Factory {
825  Category cat_;
826 std::array<IntKey, 2> residue_indexes_;
827  template <class H> std::array<IntKey, 2> get_residue_indexes_keys(H fh) const {
828  std::array<IntKey, 2> ret;
829  ret[0] = fh.template get_key<IntTag>(cat_, "first residue index");
830  ret[1] = fh.template get_key<IntTag>(cat_, "last residue index");
831  return ret;
832  }
833 
834  public:
836  cat_(fh.get_category("sequence")),
837  residue_indexes_(get_residue_indexes_keys(fh)) {
838  }
840  cat_(fh.get_category("sequence")),
841  residue_indexes_(get_residue_indexes_keys(fh)) {
842  }
843  /** Get a DomainConst for nh.*/
844  DomainConst get(NodeConstHandle nh) const {
845  RMF_USAGE_CHECK((nh.get_type() == RMF::REPRESENTATION), std::string("Bad node type. Got \"")
846  + boost::lexical_cast<std::string>(nh.get_type())
847  + "\" in decorator type Domain");
848  return DomainConst(nh, residue_indexes_);
849  }
850  /** Get a Domain for nh.*/
851  Domain get(NodeHandle nh) const {
852  RMF_USAGE_CHECK((nh.get_type() == RMF::REPRESENTATION), std::string("Bad node type. Got \"")
853  + boost::lexical_cast<std::string>(nh.get_type())
854  + "\" in decorator type Domain");
855  return Domain(nh, residue_indexes_);
856  }
857  /** Check whether nh has all the attributes required to be a
858  DomainConst.*/
859  bool get_is(NodeConstHandle nh) const {
860  return (nh.get_type() == RMF::REPRESENTATION)
861  && !nh.get_value(residue_indexes_[0]).get_is_null() && !nh.get_value(residue_indexes_[1]).get_is_null() && nh.get_value(residue_indexes_[0]) < nh.get_value(residue_indexes_[1]);
862  }
863  bool get_is_static(NodeConstHandle nh) const {
864  return (nh.get_type() == RMF::REPRESENTATION)
865  && !nh.get_static_value(residue_indexes_[0]).get_is_null() && !nh.get_static_value(residue_indexes_[1]).get_is_null() && nh.get_value(residue_indexes_[0]) < nh.get_value(residue_indexes_[1]);
866  }
867  RMF_SHOWABLE(DomainFactory, "DomainFactory");
868  };
869  #ifndef RMF_DOXYGEN
870 struct DomainConstFactory: public DomainFactory {
871  DomainConstFactory(FileConstHandle fh):
872  DomainFactory(fh) {
873  }
874  DomainConstFactory(FileHandle fh):
875  DomainFactory(fh) {
876  }
877 
878 };
879  #endif
880 
881 
882 
883 
884  /** See also Typed and TypedFactory.
885  */
886  class TypedConst: public Decorator {
887  friend class TypedFactory;
888  protected:
889  StringKey type_name_;
891  StringKey type_name):
892  Decorator(nh),
893 type_name_(type_name) {
894  }
895  public:
896 
897  String get_type_name() const {
898  try {
899  return get_node().get_value(type_name_);
900  } RMF_DECORATOR_CATCH( );
901  }
902  String get_frame_type_name() const {
903  try {
904  return get_node().get_frame_value(type_name_);
905  } RMF_DECORATOR_CATCH( );
906  }
907  String get_static_type_name() const {
908  try {
909  return get_node().get_static_value(type_name_);
910  } RMF_DECORATOR_CATCH( );
911  }
912 
913  static std::string get_decorator_type_name() {
914  return "TypedConst";
915  }
916  RMF_SHOWABLE(TypedConst, "Typed: " << get_node());
917  };
918  /** See also TypedFactory.
919  */
920  class Typed: public TypedConst {
921  friend class TypedFactory;
922  Typed(NodeHandle nh,
923  StringKey type_name):
924  TypedConst(nh, type_name) {
925  }
926  public:
927 
928  void set_type_name(String v) {
929  try {
930  get_node().set_value(type_name_, v);
931  } RMF_DECORATOR_CATCH( );
932  }
933  void set_frame_type_name(String v) {
934  try {
935  get_node().set_frame_value(type_name_, v);
936  } RMF_DECORATOR_CATCH( );
937  }
938  void set_static_type_name(String v) {
939  try {
940  get_node().set_static_value(type_name_, v);
941  } RMF_DECORATOR_CATCH( );
942  }
943 
944  static std::string get_decorator_type_name() {
945  return "Typed";
946  }
947  };
948 
949 
950  /** Create decorators of type Typed.
951  */
952  class TypedFactory: public Factory {
953  Category cat_;
954 StringKey type_name_;
955 
956  public:
958  cat_(fh.get_category("sequence")),
959  type_name_(fh.get_key<StringTag>(cat_, "type name")) {
960  }
962  cat_(fh.get_category("sequence")),
963  type_name_(fh.get_key<StringTag>(cat_, "type name")) {
964  }
965  /** Get a TypedConst for nh.*/
966  TypedConst get(NodeConstHandle nh) const {
967  RMF_USAGE_CHECK((nh.get_type() == RMF::REPRESENTATION), std::string("Bad node type. Got \"")
968  + boost::lexical_cast<std::string>(nh.get_type())
969  + "\" in decorator type Typed");
970  return TypedConst(nh, type_name_);
971  }
972  /** Get a Typed for nh.*/
973  Typed get(NodeHandle nh) const {
974  RMF_USAGE_CHECK((nh.get_type() == RMF::REPRESENTATION), std::string("Bad node type. Got \"")
975  + boost::lexical_cast<std::string>(nh.get_type())
976  + "\" in decorator type Typed");
977  return Typed(nh, type_name_);
978  }
979  /** Check whether nh has all the attributes required to be a
980  TypedConst.*/
981  bool get_is(NodeConstHandle nh) const {
982  return (nh.get_type() == RMF::REPRESENTATION)
983  && !nh.get_value(type_name_).get_is_null();
984  }
985  bool get_is_static(NodeConstHandle nh) const {
986  return (nh.get_type() == RMF::REPRESENTATION)
987  && !nh.get_static_value(type_name_).get_is_null();
988  }
989  RMF_SHOWABLE(TypedFactory, "TypedFactory");
990  };
991  #ifndef RMF_DOXYGEN
992 struct TypedConstFactory: public TypedFactory {
993  TypedConstFactory(FileConstHandle fh):
994  TypedFactory(fh) {
995  }
996  TypedConstFactory(FileHandle fh):
997  TypedFactory(fh) {
998  }
999 
1000 };
1001  #endif
1002 
1003 
1004 
1005 
1006  /** See also Copy and CopyFactory.
1007  */
1008  class CopyConst: public Decorator {
1009  friend class CopyFactory;
1010  protected:
1011  IntKey copy_index_;
1013  IntKey copy_index):
1014  Decorator(nh),
1015 copy_index_(copy_index) {
1016  }
1017  public:
1018 
1019  Int get_copy_index() const {
1020  try {
1021  return get_node().get_value(copy_index_);
1022  } RMF_DECORATOR_CATCH( );
1023  }
1024  Int get_frame_copy_index() const {
1025  try {
1026  return get_node().get_frame_value(copy_index_);
1027  } RMF_DECORATOR_CATCH( );
1028  }
1029  Int get_static_copy_index() const {
1030  try {
1031  return get_node().get_static_value(copy_index_);
1032  } RMF_DECORATOR_CATCH( );
1033  }
1034 
1035  static std::string get_decorator_type_name() {
1036  return "CopyConst";
1037  }
1038  RMF_SHOWABLE(CopyConst, "Copy: " << get_node());
1039  };
1040  /** See also CopyFactory.
1041  */
1042  class Copy: public CopyConst {
1043  friend class CopyFactory;
1044  Copy(NodeHandle nh,
1045  IntKey copy_index):
1046  CopyConst(nh, copy_index) {
1047  }
1048  public:
1049 
1050  void set_copy_index(Int v) {
1051  try {
1052  get_node().set_value(copy_index_, v);
1053  } RMF_DECORATOR_CATCH( );
1054  }
1055  void set_frame_copy_index(Int v) {
1056  try {
1057  get_node().set_frame_value(copy_index_, v);
1058  } RMF_DECORATOR_CATCH( );
1059  }
1060  void set_static_copy_index(Int v) {
1061  try {
1062  get_node().set_static_value(copy_index_, v);
1063  } RMF_DECORATOR_CATCH( );
1064  }
1065 
1066  static std::string get_decorator_type_name() {
1067  return "Copy";
1068  }
1069  };
1070 
1071 
1072  /** Create decorators of type Copy.
1073  */
1074  class CopyFactory: public Factory {
1075  Category cat_;
1076 IntKey copy_index_;
1077 
1078  public:
1080  cat_(fh.get_category("sequence")),
1081  copy_index_(fh.get_key<IntTag>(cat_, "copy index")) {
1082  }
1083  CopyFactory(FileHandle fh):
1084  cat_(fh.get_category("sequence")),
1085  copy_index_(fh.get_key<IntTag>(cat_, "copy index")) {
1086  }
1087  /** Get a CopyConst for nh.*/
1088  CopyConst get(NodeConstHandle nh) const {
1089  RMF_USAGE_CHECK((nh.get_type() == RMF::REPRESENTATION), std::string("Bad node type. Got \"")
1090  + boost::lexical_cast<std::string>(nh.get_type())
1091  + "\" in decorator type Copy");
1092  return CopyConst(nh, copy_index_);
1093  }
1094  /** Get a Copy for nh.*/
1095  Copy get(NodeHandle nh) const {
1096  RMF_USAGE_CHECK((nh.get_type() == RMF::REPRESENTATION), std::string("Bad node type. Got \"")
1097  + boost::lexical_cast<std::string>(nh.get_type())
1098  + "\" in decorator type Copy");
1099  return Copy(nh, copy_index_);
1100  }
1101  /** Check whether nh has all the attributes required to be a
1102  CopyConst.*/
1103  bool get_is(NodeConstHandle nh) const {
1104  return (nh.get_type() == RMF::REPRESENTATION)
1105  && !nh.get_value(copy_index_).get_is_null();
1106  }
1107  bool get_is_static(NodeConstHandle nh) const {
1108  return (nh.get_type() == RMF::REPRESENTATION)
1109  && !nh.get_static_value(copy_index_).get_is_null();
1110  }
1111  RMF_SHOWABLE(CopyFactory, "CopyFactory");
1112  };
1113  #ifndef RMF_DOXYGEN
1114 struct CopyConstFactory: public CopyFactory {
1115  CopyConstFactory(FileConstHandle fh):
1116  CopyFactory(fh) {
1117  }
1118  CopyConstFactory(FileHandle fh):
1119  CopyFactory(fh) {
1120  }
1121 
1122 };
1123  #endif
1124 
1125 
1126 
1127 
1128  /** See also State and StateFactory.
1129  */
1130  class StateConst: public Decorator {
1131  friend class StateFactory;
1132  protected:
1133  IntKey state_index_;
1135  IntKey state_index):
1136  Decorator(nh),
1137 state_index_(state_index) {
1138  }
1139  public:
1140 
1141  Int get_state_index() const {
1142  try {
1143  return get_node().get_value(state_index_);
1144  } RMF_DECORATOR_CATCH( );
1145  }
1146  Int get_frame_state_index() const {
1147  try {
1148  return get_node().get_frame_value(state_index_);
1149  } RMF_DECORATOR_CATCH( );
1150  }
1151  Int get_static_state_index() const {
1152  try {
1153  return get_node().get_static_value(state_index_);
1154  } RMF_DECORATOR_CATCH( );
1155  }
1156 
1157  static std::string get_decorator_type_name() {
1158  return "StateConst";
1159  }
1160  RMF_SHOWABLE(StateConst, "State: " << get_node());
1161  };
1162  /** See also StateFactory.
1163  */
1164  class State: public StateConst {
1165  friend class StateFactory;
1166  State(NodeHandle nh,
1167  IntKey state_index):
1168  StateConst(nh, state_index) {
1169  }
1170  public:
1171 
1172  void set_state_index(Int v) {
1173  try {
1174  get_node().set_value(state_index_, v);
1175  } RMF_DECORATOR_CATCH( );
1176  }
1177  void set_frame_state_index(Int v) {
1178  try {
1179  get_node().set_frame_value(state_index_, v);
1180  } RMF_DECORATOR_CATCH( );
1181  }
1182  void set_static_state_index(Int v) {
1183  try {
1184  get_node().set_static_value(state_index_, v);
1185  } RMF_DECORATOR_CATCH( );
1186  }
1187 
1188  static std::string get_decorator_type_name() {
1189  return "State";
1190  }
1191  };
1192 
1193 
1194  /** Create decorators of type State.
1195  */
1196  class StateFactory: public Factory {
1197  Category cat_;
1198 IntKey state_index_;
1199 
1200  public:
1202  cat_(fh.get_category("sequence")),
1203  state_index_(fh.get_key<IntTag>(cat_, "state index")) {
1204  }
1206  cat_(fh.get_category("sequence")),
1207  state_index_(fh.get_key<IntTag>(cat_, "state index")) {
1208  }
1209  /** Get a StateConst for nh.*/
1210  StateConst get(NodeConstHandle nh) const {
1211  RMF_USAGE_CHECK((nh.get_type() == RMF::REPRESENTATION), std::string("Bad node type. Got \"")
1212  + boost::lexical_cast<std::string>(nh.get_type())
1213  + "\" in decorator type State");
1214  return StateConst(nh, state_index_);
1215  }
1216  /** Get a State for nh.*/
1217  State get(NodeHandle nh) const {
1218  RMF_USAGE_CHECK((nh.get_type() == RMF::REPRESENTATION), std::string("Bad node type. Got \"")
1219  + boost::lexical_cast<std::string>(nh.get_type())
1220  + "\" in decorator type State");
1221  return State(nh, state_index_);
1222  }
1223  /** Check whether nh has all the attributes required to be a
1224  StateConst.*/
1225  bool get_is(NodeConstHandle nh) const {
1226  return (nh.get_type() == RMF::REPRESENTATION)
1227  && !nh.get_value(state_index_).get_is_null();
1228  }
1229  bool get_is_static(NodeConstHandle nh) const {
1230  return (nh.get_type() == RMF::REPRESENTATION)
1231  && !nh.get_static_value(state_index_).get_is_null();
1232  }
1233  RMF_SHOWABLE(StateFactory, "StateFactory");
1234  };
1235  #ifndef RMF_DOXYGEN
1236 struct StateConstFactory: public StateFactory {
1237  StateConstFactory(FileConstHandle fh):
1238  StateFactory(fh) {
1239  }
1240  StateConstFactory(FileHandle fh):
1241  StateFactory(fh) {
1242  }
1243 
1244 };
1245  #endif
1246 
1247 
1248 
1249 
1250  /** See also ExplicitResolution and ExplicitResolutionFactory.
1251  */
1253  friend class ExplicitResolutionFactory;
1254  protected:
1255  FloatKey explicit_resolution_;
1257  FloatKey explicit_resolution):
1258  Decorator(nh),
1259 explicit_resolution_(explicit_resolution) {
1260  }
1261  public:
1262 
1263  Float get_explicit_resolution() const {
1264  try {
1265  return get_node().get_value(explicit_resolution_);
1266  } RMF_DECORATOR_CATCH( );
1267  }
1268  Float get_frame_explicit_resolution() const {
1269  try {
1270  return get_node().get_frame_value(explicit_resolution_);
1271  } RMF_DECORATOR_CATCH( );
1272  }
1273  Float get_static_explicit_resolution() const {
1274  try {
1275  return get_node().get_static_value(explicit_resolution_);
1276  } RMF_DECORATOR_CATCH( );
1277  }
1278 
1279  static std::string get_decorator_type_name() {
1280  return "ExplicitResolutionConst";
1281  }
1282  RMF_SHOWABLE(ExplicitResolutionConst, "ExplicitResolution: " << get_node());
1283  };
1284  /** See also ExplicitResolutionFactory.
1285  */
1287  friend class ExplicitResolutionFactory;
1289  FloatKey explicit_resolution):
1290  ExplicitResolutionConst(nh, explicit_resolution) {
1291  }
1292  public:
1293 
1294  void set_explicit_resolution(Float v) {
1295  try {
1296  get_node().set_value(explicit_resolution_, v);
1297  } RMF_DECORATOR_CATCH( );
1298  }
1299  void set_frame_explicit_resolution(Float v) {
1300  try {
1301  get_node().set_frame_value(explicit_resolution_, v);
1302  } RMF_DECORATOR_CATCH( );
1303  }
1304  void set_static_explicit_resolution(Float v) {
1305  try {
1306  get_node().set_static_value(explicit_resolution_, v);
1307  } RMF_DECORATOR_CATCH( );
1308  }
1309 
1310  static std::string get_decorator_type_name() {
1311  return "ExplicitResolution";
1312  }
1313  };
1314 
1315 
1316  /** Create decorators of type ExplicitResolution.
1317  */
1319  Category cat_;
1320 FloatKey explicit_resolution_;
1321 
1322  public:
1324  cat_(fh.get_category("sequence")),
1325  explicit_resolution_(fh.get_key<FloatTag>(cat_, "explicit resolution")) {
1326  }
1328  cat_(fh.get_category("sequence")),
1329  explicit_resolution_(fh.get_key<FloatTag>(cat_, "explicit resolution")) {
1330  }
1331  /** Get a ExplicitResolutionConst for nh.*/
1333  RMF_USAGE_CHECK((nh.get_type() == RMF::REPRESENTATION), std::string("Bad node type. Got \"")
1334  + boost::lexical_cast<std::string>(nh.get_type())
1335  + "\" in decorator type ExplicitResolution");
1336  return ExplicitResolutionConst(nh, explicit_resolution_);
1337  }
1338  /** Get a ExplicitResolution for nh.*/
1340  RMF_USAGE_CHECK((nh.get_type() == RMF::REPRESENTATION), std::string("Bad node type. Got \"")
1341  + boost::lexical_cast<std::string>(nh.get_type())
1342  + "\" in decorator type ExplicitResolution");
1343  return ExplicitResolution(nh, explicit_resolution_);
1344  }
1345  /** Check whether nh has all the attributes required to be a
1346  ExplicitResolutionConst.*/
1347  bool get_is(NodeConstHandle nh) const {
1348  return (nh.get_type() == RMF::REPRESENTATION)
1349  && !nh.get_value(explicit_resolution_).get_is_null();
1350  }
1351  bool get_is_static(NodeConstHandle nh) const {
1352  return (nh.get_type() == RMF::REPRESENTATION)
1353  && !nh.get_static_value(explicit_resolution_).get_is_null();
1354  }
1355  RMF_SHOWABLE(ExplicitResolutionFactory, "ExplicitResolutionFactory");
1356  };
1357  #ifndef RMF_DOXYGEN
1358 struct ExplicitResolutionConstFactory: public ExplicitResolutionFactory {
1359  ExplicitResolutionConstFactory(FileConstHandle fh):
1360  ExplicitResolutionFactory(fh) {
1361  }
1362  ExplicitResolutionConstFactory(FileHandle fh):
1363  ExplicitResolutionFactory(fh) {
1364  }
1365 
1366 };
1367  #endif
1368 
1369 
1370 
1371 } /* namespace decorator */
1372 } /* namespace RMF */
1373 RMF_DISABLE_WARNINGS
1374 
1375 #endif /* RMF_SEQUENCE_DECORATORS_H */
Mostly empty base classes for decorators and factories.
const NodeType REPRESENTATION
Represent part of a molecule.
bool get_is(NodeConstHandle nh) const
Definition: sequence.h:1103
A handle for a particular node in the hierarchy.
Definition: NodeHandle.h:60
float Float
Definition: types.h:33
bool get_is(NodeConstHandle nh) const
Definition: sequence.h:859
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: sequence.h:1347
bool get_is(NodeConstHandle nh) const
Definition: sequence.h:981
A handle for a particular node in a read-only hierarchy.
bool get_is(NodeConstHandle nh) const
Definition: sequence.h:1225
A handle for a read-only RMF file.
void set_value(ID< Tag > k, typename Tag::ArgumentType v) const
Definition: NodeHandle.h:115
std::vector< Int > Ints
Definition: types.h:31
A handle for an RMF file.
Definition: FileHandle.h:54
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: sequence.h:719
bool get_is(NodeConstHandle nh) const
Definition: sequence.h:597
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
bool get_is(NodeConstHandle nh) const
Definition: sequence.h:168
std::string String
Definition: types.h:39
ID< Tag > get_key(Category category, std::string name) const
int Int
Definition: types.h:29
Various general useful macros for IMP.
bool get_is(NodeConstHandle nh) const
Definition: sequence.h:475
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