RNAMake
structure.h
1 //
2 // structure.h
3 // RNAMake
4 //
5 // Created by Joseph Yesselman on 1/25/15.
6 // Copyright (c) 2015 Joseph Yesselman. All rights reserved.
7 //
8 
9 #ifndef __RNAMake__structure__
10 #define __RNAMake__structure__
11 
12 #include <stdio.h>
13 
14 //RNAMake Headers
15 #include "base/types.h"
16 #include "math/transform.h"
17 #include "math/xyz_matrix.h"
18 #include "structure/chain.fwd.h"
19 #include "structure/chain.h"
20 #include "structure/residue.h"
21 #include "structure/pdb_parser.h"
22 
23 class Structure {
24 public:
25  inline
26  Structure():
27  chains_ (ChainOPs())
28  {}
29 
30  inline
31  Structure(
32  ChainOPs const & chains):
33  chains_ (chains)
34  {}
35 
36  Structure(
37  String const & path) {
38  PDBParser pdb_parser;
39  auto residues = pdb_parser.parse(path);
40  chains_ = ChainOPs();
41  connect_residues_into_chains(residues, chains_);
42  }
43 
44  Structure(
45  Structure const & s) {
46  chains_ = ChainOPs(s.chains_.size());
47  int i = 0;
48  for (auto const & c : s.chains_) {
49  chains_[i] = std::make_shared<Chain>(*c);
50  i++;
51  }
52  }
53 
54  Structure(
55  String const & s,
56  ResidueTypeSet const & rts) {
57  chains_ = ChainOPs();
58  Strings spl = split_str_by_delimiter(s, ":");
59  for( auto const & c_str : spl) {
60  chains_.push_back(std::make_shared<Chain>(c_str, rts));
61  }
62  }
63 
64  ~Structure() {}
65 
66 public:
67 
68  void
69  renumber();
70 
71  inline
72  Beads
73  get_beads(
74  ResidueOPs const & excluded_res) {
75  Beads beads;
76  int found = 0;
77  for ( auto const & r : residues()) {
78  found = 0;
79  for (auto const & er : excluded_res) {
80  if( r->uuid() == er->uuid()) {found = 1; break;}
81  }
82  if (found) { continue; }
83  for (auto const & b : r->get_beads()) {
84  beads.push_back(b);
85  }
86  }
87  return beads;
88  }
89 
90  ResidueOP const
91  get_residue(
92  int const & ,
93  String const & ,
94  String const & );
95 
96  ResidueOP const
97  get_residue(
98  Uuid const &);
99 
100  ResidueOPs const
101  residues();
102 
103  inline
104  AtomOPs const
105  atoms() {
106  AtomOPs atoms;
107  for (auto const & r : residues()) {
108  for (auto const & a : r->atoms()) {
109  if(a.get() != NULL) {
110  atoms.push_back(a);
111  }
112  }
113  }
114  return atoms;
115  }
116 
117  inline
118  void
119  move(Point const & p) {
120  for(auto & a : atoms()) {
121  a->coords(a->coords() + p);
122  }
123  }
124 
125  inline
126  void
127  transform(Transform const & t) {
128  Matrix r = t.rotation().transpose();
129  Point trans = t.translation();
130  for( auto & a : atoms() ) {
131  dot_vector(r, a->coords(), dummy_);
132  dummy_ += trans;
133  a->coords(dummy_);
134  }
135  }
136 
137  String
138  to_pdb_str(
139  int renumber = -1);
140 
141  String
142  to_str();
143 
144  void
145  to_pdb(
146  String const,
147  int renumber = -1);
148 
149 public: // getters
150 
151  inline
152  ChainOPs const &
153  chains() { return chains_; }
154 
155 
156 private:
157  ChainOPs chains_;
158  Point dummy_; // resuable place in memory
159  Points coords_;
160  Points org_coords_;
161 
162 };
163 
164 typedef std::shared_ptr<Structure> StructureOP;
165 
166 
167 #endif /* defined(__RNAMake__structure__) */
Definition: residue_type_set.h:15
Definition: pdb_parser.h:18
Definition: structure.h:23