Victor
 All Data Structures Functions Variables Friends Pages
LoopModel.h
1 /* This file is part of Victor.
2 
3  Victor is free software: you can redistribute it and/or modify
4  it under the terms of the GNU General Public License as published by
5  the Free Software Foundation, either version 3 of the License, or
6  (at your option) any later version.
7 
8  Victor is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  GNU General Public License for more details.
12 
13  You should have received a copy of the GNU General Public License
14  along with Victor. If not, see <http://www.gnu.org/licenses/>.
15  */
16 
17 #ifndef _LOOPMODEL_H_
18 #define _LOOPMODEL_H_
19 
20 // Includes:
21 #include <Debug.h>
22 #include <string.h>
23 #include <LoopTable.h>
24 #include <VectorTransformation.h>
25 #include <Spacer.h>
26 #include <SeqConstructor.h>
27 #include <set>
28 #include <ranking_helper.h>
29 #include <ranking_helper2.h>
30 #include <SolvationPotential.h>
31 #include <RapdfPotential.h>
32 #include <PhiPsi.h>
33 #include <ctype.h>
34 
35 namespace Victor { namespace Lobo {
36 
37  // Global constants, typedefs, etc. (to avoid):
38 
39  class LoopModel {
40  public:
41 
42  // CONSTRUCTORS/DESTRUCTOR:
43  LoopModel();
44  LoopModel(const LoopModel& orig);
45  virtual ~LoopModel();
46 
47  // PREDICATES:
48  vector<string>& getTableFileName();
49 
50  vector<int> vdwValues(Spacer& sp, unsigned int index1,
51  unsigned int index2, vector<Spacer>& solVec);
52 
53  void rankRawScore(Spacer& sp, unsigned int index1, unsigned int index2,
54  vector<Spacer>& solVec, unsigned int maxWrite = 9999);
55 
56  void doScatterPlot(Spacer& sp, unsigned int index1, unsigned int index2,
57  vector<Spacer>& solVec, bool withOxygen = true);
58 
59  void refineModel(Spacer& sp, unsigned int index1, unsigned int index2,
60  vector<Spacer>& solVec);
61 
62  void optimizeModel(Spacer& sp, unsigned int index1, unsigned int index2,
63  vector<Spacer>& solVec, bool verbose = true);
64 
65  vector<double> rankRms2(Spacer& sp, unsigned int index1, unsigned int index2,
66  vector<Spacer>& solVec);
67 
68  double calcOrigEnergy(const Spacer& sp, unsigned int index1,
69  unsigned int index2);
70  double calculateEndRms(const Spacer& sp, unsigned int index1,
71  unsigned int index2, const Spacer& sp2);
72  double calculateRms(const Spacer& sp, unsigned int index1,
73  unsigned int index2, const Spacer& sp2,
74  bool output = true, bool withOxygen = false);
75  double calculateRms2(const Spacer& sp, unsigned int index1,
76  unsigned int index2, const Spacer& sp2, bool output,
77  bool withOxygen = false);
78  void setStructure(Spacer& sp, Spacer& sp2, unsigned int index1,
79  unsigned int index2);
80 
81  vector<int> consistencyValues(Spacer& sp, unsigned int index1,
82  unsigned int index2, vector<Spacer>& solVec);
83 
84  double calculatePropensities(Spacer& sp);
85  double calculatePropensities(const Spacer& sp, unsigned int index1,
86  unsigned int index2, Spacer& sp2);
87 
88  double getENDRMS_WEIGHT(unsigned int len = 0);
89  void saveENDRMS_WEIGHT(ostream& output);
90 
91  static string getSCWRLConservedSequence(const Spacer& sp,
92  unsigned int index1, unsigned int index2);
93 
94  void defineLoopAnchors(Spacer& sp, unsigned int& index1,
95  unsigned int& index2, bool isDeletion);
96 
97  // MODIFIERS:
98 
99  void setInterpolated() {
100  pInter = true;
101  }
102 
103  void setNotInterpolated() {
104  pInter = false;
105  }
106 
107  void setLimitedVerbose() {
108  pVerbose = 1;
109  }
110 
111  void setVerbose(unsigned int _verb = 10) {
112  pVerbose = _verb;
113  }
114 
115  void setQuiet() {
116  pVerbose = 0;
117  pPlot = false;
118  }
119 
120  void setScatterPlot(ostream* _sc) {
121  pPlot = true;
122  pScatter = _sc;
123  }
124 
125  void releaseTables(unsigned int index = 0); // releases memory occupied by loop tables
126  void setTableFileName(string basename, string ending = ".lt");
127  void setTableFileName(vector<string>& _tFN);
128  vector<Spacer> createLoopModel(const AminoAcid& start,
129  const vgVector3<double>& startN, const AminoAcid& end,
130  const vgVector3<double>& endNAtom, unsigned int indexS,
131  unsigned int indexE, unsigned int numLoops,
132  unsigned int numLoops2, vector<string> typeVec);
133  void clusterLoops(vector<Spacer>& vsp);
134 
135  void copy(const LoopModel& orig);
136 
137  int amino_amino_collision(AminoAcid& aa1, AminoAcid& aa2, int pos1,
138  int pos2, double distance);
139  double compactness(Spacer& loop, unsigned int index1, unsigned int index2,
140  Spacer& proteine);
141 
142  double calculateEnergy(const Spacer& sp, unsigned int index1,
143  unsigned int index2, Spacer& sp2);
144  double calculateSecondaryPreference(const Spacer& sp, unsigned int index1,
145  unsigned int index2, Spacer& sp2);
146  double calculatePacking(const Spacer& sp, unsigned int index1,
147  unsigned int index2, Spacer& sp2);
148  double calculateSolvation(const Spacer& sp, unsigned int index1,
149  unsigned int index2, Spacer& sp2);
150  double calculateHydrogen(const Spacer& sp, unsigned int index1,
151  unsigned int index2, Spacer& sp2);
152  double calculateCompactness(const Spacer& sp, unsigned int index1,
153  unsigned int index2, Spacer& sp2);
154  double calculateFlankingConformation(const Spacer& sp, unsigned int index1,
155  unsigned int index2, Spacer& sp2);
156  double calculateConsistency(Spacer& sp, unsigned int index1,
157  unsigned int index2, Spacer& sp2);
158 
159  void setENDRMS_WEIGHT(double val, unsigned int len = 0);
160  void setAllENDRMS_WEIGHT(double val, unsigned int max = 13);
161  void loadENDRMS_WEIGHT(istream& input);
162 
163  // OPERATORS:
164  LoopModel& operator=(const LoopModel& orig);
165 
166  static unsigned int OPT_MAX1;
167  static unsigned int OPT_MAX2;
168  static unsigned int OPT_NUM;
169  static double VDW_LIMIT;
170  static double SIM_LIMIT;
171  static double ENERGY_LIMIT;
172  static double ENERGY_WEIGTH;
173  static double SECPREF_WEIGTH;
174  static double SECPREF_TOL;
175  static double PACKING_WEIGTH;
176 
177  //ATTRIBUTES
178  static unsigned int MAX_SPAN;
179  static unsigned int MAX_ITER_SOL;
180  static string TABLE_PARAM_FILE;
181 
182  static SolvationPotential solv;
183  static RapdfPotential rapdf;
184  static PhiPsi tor;
185 
186  protected:
187  // HELPERS:
188  // converts the input coords to something processable:
189  void convertCoords(AminoAcid start, vgVector3<float> startN, AminoAcid end,
190  vgVector3<float> endN, LoopTableEntry& startEntry,
191  LoopTableEntry& endEntry, VectorTransformation& vt,
192  unsigned int nAmino);
193  // tries to find a ring closure between to locations:
194  bool ringClosureBase(const LoopTableEntry&, const LoopTableEntry&,
195  unsigned int, unsigned int, double,
196  VectorTransformation vt, unsigned int num,
197  unsigned int depth,
198  vector<vgVector3<float> >& partialSolution);
199  bool ringClosure(const LoopTableEntry&, const LoopTableEntry&, unsigned int,
200  unsigned int, double, VectorTransformation vt,
201  vector<vgVector3<float> >& partialSolution,
202  unsigned int currentSelection = 1);
203  // claculates the actual coordinates for output:
204  vector<Spacer> calculateLoop(const vgVector3<float>& startN,
205  unsigned int length, vector<string> typeVec);
206 
207  private:
208  // HELPERS:
209  void pAddRot(AminoAcid& start, vgVector3<float>& startN,
210  AminoAcid& end, vgVector3<float>& endN,
211  const vgMatrix3<float>& rotMat);
212  void pAddTrans(AminoAcid& start, vgVector3<float>& startN,
213  AminoAcid& end, vgVector3<float>& endN,
214  const vgVector3<float>& trans);
215  void loadTables(unsigned int nAmino);
216  void pAminoAcidSetup(AminoAcid* aa, string type, double bfac = 90.0);
217  void pSetSideChain(AminoAcid& aa);
218  double pCalculateLoopRms(Spacer& sp1, Spacer& sp2);
219 
220  int loop_loop_vdw(Spacer& sp, unsigned int index1);
221  int loop_spacer_vdw(Spacer& loop, unsigned int index1, unsigned int index2,
222  Spacer& proteine);
223 
224  double sCalcEn(AminoAcid& aa, AminoAcid& aa2);
225  double sICalcEn(AminoAcid& aa, AminoAcid& aa2);
226  double sCalcEnInt(AminoAcid& aa, AminoAcid& aa2);
227  double sICalcEnInt(AminoAcid& aa, AminoAcid& aa2);
228 
229  // ATTRIBUTES:
230  bool pInter, pPlot;
231  unsigned int pVerbose;
232  ostream* pScatter;
233  vector<LoopTable*> table;
234  vector<string> tableFileName;
235  vector<vgVector3<float> > solution;
236  static unsigned int MAX_CHAIN_LENGTH;
237  static double BOND_ANGLE_N_TO_CB;
238  static double BOND_ANGLE_CB_TO_C;
239  static double BOND_LENGTH_CA_TO_CB;
240 
241  vector<double> ENDRMS_WEIGTH;
242 
243  };
244 
245  // ---------------------------------------------------------------------------
246  // LoopModel
247  // -----------------x-------------------x-------------------x-----------------
248 
249 
250  // PREDICATES:
251 
252  inline vector<string>&
253  LoopModel::getTableFileName() {
254  return tableFileName;
255  }
256 
257  // MODIFIERS:
258 
259  inline void
260  LoopModel::setTableFileName(string basename, string ending) {
261  // PRECOND( _tFN.size() == MAX_CHAIN_LENGTH, exception);
262  tableFileName.clear();
263  for (unsigned int i = 0; i < MAX_CHAIN_LENGTH; i++)
264  tableFileName.push_back(basename + (uitos(i)).c_str() + ending);
265  }
266 
267  inline void
268  LoopModel::setTableFileName(vector<string>& _tFN) {
269  PRECOND(_tFN.size() == MAX_CHAIN_LENGTH, exception);
270  tableFileName.clear();
271  for (unsigned int i = 0; i < _tFN.size(); i++)
272  tableFileName.push_back(_tFN[i]);
273  }
274 
275  inline void
276  LoopModel::pAddRot(AminoAcid& start, vgVector3<float>& startN,
277  AminoAcid& end, vgVector3<float>& endN, const vgMatrix3<float>& rotMat) {
278  for (unsigned int i = 0; i < start.sizeBackbone(); i++)
279  start[i].setCoords(convert(rotMat) * start[i].getCoords());
280  startN = rotMat * startN;
281  for (unsigned int i = 0; i < end.sizeBackbone(); i++)
282  end[i].setCoords(convert(rotMat) * end[i].getCoords());
283  endN = rotMat * endN;
284  }
285 
286  inline void
287  LoopModel::pAddTrans(AminoAcid& start, vgVector3<float>& startN,
288  AminoAcid& end, vgVector3<float>& endN, const vgVector3<float>& trans) {
289  for (unsigned int i = 0; i < start.sizeBackbone(); i++)
290  start[i].setCoords(start[i].getCoords() - convert(trans));
291  for (unsigned int i = 0; i < end.sizeBackbone(); i++)
292  end[i].setCoords(end[i].getCoords() - convert(trans));
293  startN -= trans;
294  endN -= trans;
295  }
296 
297  inline double
298  LoopModel::pCalculateLoopRms(Spacer& sp1, Spacer& sp2) {
299  if (sp1.sizeAmino() != sp2.sizeAmino())
300  ERROR("Arguments do not match.", exception);
301 
302  double res = 0.0;
303  for (unsigned int i = 0; i < sp1.sizeAmino(); i++)
304  res += sqr(sp1.getAmino(i)[N].distance(sp2.getAmino(i)[N]))
305  + sqr(sp1.getAmino(i)[CA].distance(sp2.getAmino(i)[CA]))
306  + sqr(sp1.getAmino(i)[C].distance(sp2.getAmino(i)[C]));
307 
308  return sqrt(res / (3 * sp1.sizeAmino()));
309  }
310 
311  inline string
312  LoopModel::getSCWRLConservedSequence(const Spacer& sp, unsigned int index1,
313  unsigned int index2) {
314  string tmp = "";
315 
316  for (unsigned int i = 0; i <= index1; i++)
317  tmp += static_cast<char> (tolower(threeLetter2OneLetter(
318  sp.getAmino(i).getType())));
319 
320  for (unsigned int i = index1 + 1; i <= index2; i++)
321  tmp += threeLetter2OneLetter(sp.getAmino(i).getType());
322 
323  for (unsigned int i = index2 + 1; i < sp.sizeAmino(); i++)
324  tmp += static_cast<char> (tolower(threeLetter2OneLetter(
325  sp.getAmino(i).getType())));
326 
327  return tmp;
328  }
329 
330 }} // namespace
331 
332 #endif //_LOOPMODEL_H_
333 
334 
335 
Includes methods that allow to calculate solvation, energy and propensity.
Definition: SolvationPotential.h:44
AminoAcid & getAmino(unsigned int n)
Definition: Spacer.cc:962
class manages the angle qualities and the energy
Definition: PhiPsi.h:41
virtual string getType() const
Definition: SimpleBond.h:114
const unsigned int sizeAmino() const
Definition: Spacer.cc:197
Distance-dependent residue-specific all-atom probability discriminatory function. ...
Definition: RapdfPotential.h:39
It mplements a simple amino acid.
Definition: AminoAcid.h:43
Implements a "Spacer" for a protein chain. Includes methods to obtain values from the atoms and its p...
Definition: Spacer.h:42