Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ChemicalShiftAnisotropy.cc
Go to the documentation of this file.
1 // -*- mode:c++;tab-width:2;indent-tabs-mode:t;show-trailing-whitespace:t;rm-trailing-spaces:t -*-
2 // vi: set ts=2 noet:
3 //
4 // (c) Copyright Rosetta Commons Member Institutions.
5 // (c) This file is part of the Rosetta software suite and is made available under license.
6 // (c) The Rosetta software is developed by the contributing members of the Rosetta Commons.
7 // (c) For more information, see http://www.rosettacommons.org. Questions about this can be
8 // (c) addressed to University of Washington UW TechTransfer, email: license@u.washington.edu.
9 
10 /// @file core/scoring/ChemicalShiftAnisotropy.cc
11 /// @brief Uses NMR CSA for scoring (Bertram R et al J of Magn Reson 147, 9-16)
12 /// @author Lei Shi
13 
14 //Unit headers
16 
17 // Package headers
18 
19 // Project headers
22 
23 // AUTO-REMOVED #include <basic/options/after_opts.hh>
24 #include <basic/options/option.hh>
25 
26 #include <basic/datacache/BasicDataCache.hh>
28 #include <core/pose/Pose.hh>
29 #include <core/pose/util.hh>
30 
31 #include <basic/Tracer.hh>
32 
33 // ObjexxFCL headers
34 #include <ObjexxFCL/format.hh>
35 
36 //C++ headers
37 #include <iostream>
38 #include <fstream>
39 #include <string>
40 
41 /// Utility headers
42 #include <utility/excn/Exceptions.hh>
43 #include <utility/io/izstream.hh>
44 #include <utility/io/ozstream.hh>
45 // AUTO-REMOVED #include <basic/options/option_macros.hh>
46 
47 // option key includes
48 #include <basic/options/keys/in.OptionKeys.gen.hh>
49 #include <basic/options/keys/csa.OptionKeys.gen.hh>
50 
51 #include <numeric/random/random.hh>
52 // Numeric headers
53 #include <numeric/xyz.functions.hh>
54 #include <numeric/xyzVector.hh>
55 #include <numeric/xyzMatrix.hh>
56 
57 //Membrane code to find out membrane normal
61 
62 static basic::Tracer tr("core.scoring.ChemicalShiftAnisotropy");
63 
64 namespace core {
65 namespace scoring {
66 
67 //////////////////////////////////////////////////////
68 //@brief reads in CSA data file
69 //////////////////////////////////////////////////////
72 }
73 
76  return static_cast<ChemicalShiftAnisotropy const *> (pose.data().get_const_ptr(
78  };
79  return NULL;
80 }
81 
84  return static_cast<ChemicalShiftAnisotropy*> (pose.data().get_ptr(
86  };
87  return NULL;
88 }
89 
90 void ChemicalShiftAnisotropy::show(std::ostream& out) const {
91  Size ct=0;
92  for (CSA_lines::const_iterator it=All_CSA_lines_.begin();it!=All_CSA_lines_.end();it++){
93  out << "CSA "<<++ct << " ";
94  out << (*it) << std::endl;
95  }
96 }
97 
98 void CSA::show(std::ostream& out) const {
99  using namespace ObjexxFCL::fmt;
100  out << RJ(4, res1_) << RJ(5, CSAval_);
101 }
102 
103 std::ostream& operator<<(std::ostream& out, CSA const& csa) {
104  csa.show(out);
105  return out;
106 }
107 
108 std::ostream& operator<<(std::ostream& out, ChemicalShiftAnisotropy const& csa) {
109  csa.show(out);
110  return out;
111 }
112 
114  basic::datacache::CacheableData(other) {
116 }
117 
118 //explicit assignment operator to initialize buffers
121  basic::datacache::CacheableData::operator=(other);
123  return *this;
124 }
125 
127 
128  std::string line;
129  utility::io::izstream infile(filename.c_str());
130 
131  if ( !infile.good() ) {
132  throw( utility::excn::EXCN_FileNotFound( filename ) );
133  }
134 
135  //tr.Info << "Reading CSA file " << filename << std::endl;
136  while (getline(infile, line)) {
137  std::istringstream line_stream(line);
138  std::string atom1;
139  Size res1;
140  Real sigma1, sigma2, sigma3, weight;
141  Real CSAval,CSAerr;
142  line_stream >> res1 >> atom1 >> sigma1 >> sigma2 >> sigma3 >> CSAval >> CSAerr;
143  weight=3.0/(sigma1+sigma2+sigma3);
144 
145  if ( line_stream.fail() ) {
146  tr.Error << "couldn't read line " << line << " in csa-file " << filename << std::endl;
147  throw( utility::excn::EXCN_BadInput(" invalid line "+line+" in csa-file "+filename));
148  }
149 
150  if ( atom1=="N" && sigma1<=sigma2 && sigma2<=sigma3 && res1>1 ) {
151  All_CSA_lines_.push_back(CSA(res1,atom1,sigma1,sigma2,sigma3,CSAval,CSAerr,weight));
152  } else {
153  if (atom1!="N")
154  throw( utility::excn::EXCN_BadInput( "only N15 CSA is supported, not yet for " ));
155  if (res1<=1)
156  throw( utility::excn::EXCN_BadInput( "residue id needs to be greater than 1" ));
157  if ( sigma1>sigma2 || sigma1>sigma2 || sigma2>sigma3)
158  throw( utility::excn::EXCN_BadInput( "sigma1 < sigma2 < sigma3" ));
159  }
160 
161  } //end of readline
162 }//end of read file
163 
165  using namespace basic::options;
166  using namespace basic::options::OptionKeys;
167  if ( !option[ OptionKeys::in::file::csa ].user() ) {
168  tr.Warning << "no CSA file specified" << std::endl;
169  return;
170  } else {
172  read_CSA_file( filename);
173  }
174 }
175 
176 //compute csascore
178  Real total_dev=0.0;
179  numeric::xyzVector<Real> memnorm;
180 
181  //Should we use the membrane normal?
182  if ( basic::options::option[ basic::options::OptionKeys::csa::useZ].user() ) {
183  memnorm = numeric::xyzVector<Real> (0.0,0.0,1.0);
184  memnorm.normalize();
185  } else {
186  //add the membrane code here
187  // core::scoring::MembraneEmbed membrane_embed( core::scoring::MembraneEmbed_from_pose( pose ));
189  memnorm.normalize();
190  }
191  tr.Trace << "memnorm.x(): " << memnorm.x() << " memnorm.y() " << memnorm.y() << " memnorm.z() " << memnorm.z() << std::endl;
192 
193 
195 // tr.Trace << "it->res1(): " << it->res1() << " it->atom1() " << it->atom1() << std::endl;
196 // tr.Trace << "it->res2(): " << it->res2() << " it->atom2() " << it->atom2() << std::endl;
197 // tr.Trace << "it->res3(): " << it->res3() << " it->atom3() " << it->atom3() << std::endl;
198  numeric::xyzVector<Real> v1( pose.residue(it->res2()).atom(it->atom2()).xyz() - pose.residue(it->res1()).atom(it->atom1()).xyz());
199  numeric::xyzVector<Real> u1=v1.normalized();
200  numeric::xyzVector<Real> v2( pose.residue(it->res3()).atom(it->atom3()).xyz() - pose.residue(it->res1()).atom(it->atom1()).xyz());
201  numeric::xyzVector<Real> u2=v2.normalized();
202  //the cross product order is flipped
203  numeric::xyzVector<Real> b=(u2.cross_product(u1)).normalized();
204  numeric::xyzVector<Real> n=b.cross_product(u1);
205  numeric::xyzMatrix<Real> F(numeric::xyzMatrix<Real>::cols(u1.x(),u1.y(),u1.z(),n.x(),n.y(),n.z(),b.x(),b.y(),b.z()));
206 
207  //apply matrix rotation here
208  numeric::xyzMatrix< Real > malpha = numeric::x_rotation_matrix_degrees( it->alpha() );
209  numeric::xyzMatrix< Real > mbeta = numeric::z_rotation_matrix_degrees( it->beta() );
210 
211  numeric::xyzMatrix< Real > PAF(F*mbeta*malpha);
212 
213  numeric::xyzMatrix<Real> sigmas(numeric::xyzMatrix<Real>::cols(it->sigma3(),0,0,0,it->sigma1(),0,0,0,it->sigma2()));
214 
215 
216  //compute the observed CSA
217  Real compCSA=it->CSAval_computed_=dot_product(memnorm,numeric::product(PAF*sigmas*PAF.transposed(),memnorm));
218 
219  //compute the difference and then energy
220  Real devCSA = fabs(compCSA - it->CSAval()) < it->CSAerr() ? 0.0 : fabs(fabs(compCSA - it->CSAval())-it->CSAerr());
221  //Add weight to energy and derivatives
222  total_dev+=it->weight()*devCSA*devCSA;
223 
224  if ( tr.Trace.visible() ) {
225  tr.Trace << "resi: " << it->res1() << " compCSA: " << compCSA << " expCSA: " << it->CSAval() << " expErr " << it->CSAerr() << " devCSA: " << devCSA << " total_dev "<< total_dev << std::endl;
226  }
227 
228  //derivatives
233 
234  //temporary data structure to compute derivatives
235  numeric::xyzVector<Real> du1_dx(0.0);
236  numeric::xyzVector<Real> du2_dx(0.0);
237  Real p = 0.0;
238  Real q = 0.0;
239  Real r = 0.0;
241  numeric::xyzMatrix<Real> dF_dx(0.0);
242  numeric::xyzMatrix<Real> dPAF_dx(0.0);
243  Real dcompCSA_dx=0.0;
244 
245  //derivative values
246  Real dE_xA=0.0;
247  Real dE_yA=0.0;
248  Real dE_zA=0.0;
249  Real dE_xB=0.0;
250  Real dE_yB=0.0;
251  Real dE_zB=0.0;
252  Real dE_xC=0.0;
253  Real dE_yC=0.0;
254  Real dE_zC=0.0;
255 
256  CSA& csa = *it;
257  if ( fabs(compCSA - it->CSAval()) <= it->CSAerr() ) {
258  // tr.Info << "deri 0: " << fabs(compCSA - it->CSAval()) << " , " << it->CSAerr() << std::endl;
259  csa.f1ij_[0] = 0;
260  csa.f1ij_[1] = 0;
261  csa.f1ij_[2] = 0;
262  csa.f2ij_[0] = 0;
263  csa.f2ij_[1] = 0;
264  csa.f2ij_[2] = 0;
265  csa.f3ij_[0] = 0;
266  csa.f3ij_[1] = 0;
267  csa.f3ij_[2] = 0;
268  } else if ( compCSA - it->CSAval() > it->CSAerr() ) {
269  // tr.Info << "deri 1: " << compCSA - it->CSAval() << " , " << it->CSAerr() << std::endl;
270 
271  //xA
272  //swith order of u1 and u2 in the derivation
273  du1_dx=-vx/v1.length()-v1*(1/(v1.length()*v1.length()*v1.length()))*dot_product(v1,-vx);
274  du2_dx=-vx/v2.length()-v2*(1/(v2.length()*v2.length()*v2.length()))*dot_product(v2,-vx);
275  p=dot_product(u1,cross_product(b,du1_dx));
276  q=(1/cross_product(u2,u1).length())*dot_product(u1,cross_product(u2,du1_dx));
277  r=(1/cross_product(u2,u1).length())*dot_product(n,cross_product(du2_dx,u1)+cross_product(u2,du1_dx));
278  S=numeric::xyzMatrix<Real>::cols(0,-p,-q,p,0,-r,q,r,0);
279  dF_dx=F*S;
280  dPAF_dx=dF_dx*mbeta*malpha;
281  dcompCSA_dx=2*dot_product(memnorm,numeric::product(dPAF_dx*sigmas*PAF.transposed(),memnorm));
282  dE_xA=it->weight()*2*( compCSA - it->CSAval() - it->CSAerr() )*dcompCSA_dx;
283  csa.f1ij_[0]=dE_xA;
284  //tr.Info << "csa.f1ij_[0]: " << csa.f1ij_[0] << std::endl;
285 
286  //yA
287  //swith order of u1 and u2 in the derivation
288  du1_dx=-vy/v1.length()-v1*(1/(v1.length()*v1.length()*v1.length()))*dot_product(v1,-vy);
289  du2_dx=-vy/v2.length()-v2*(1/(v2.length()*v2.length()*v2.length()))*dot_product(v2,-vy);
290  p=dot_product(u1,cross_product(b,du1_dx));
291  q=(1/cross_product(u2,u1).length())*dot_product(u1,cross_product(u2,du1_dx));
292  r=(1/cross_product(u2,u1).length())*dot_product(n,cross_product(du2_dx,u1)+cross_product(u2,du1_dx));
293  S=numeric::xyzMatrix<Real>::cols(0,-p,-q,p,0,-r,q,r,0);
294  dF_dx=F*S;
295  dPAF_dx=dF_dx*mbeta*malpha;
296  dcompCSA_dx=2*dot_product(memnorm,numeric::product(dPAF_dx*sigmas*PAF.transposed(),memnorm));
297  dE_yA=it->weight()*2*( compCSA - it->CSAval() - it->CSAerr() )*dcompCSA_dx;
298  csa.f1ij_[1]=dE_yA;
299  //tr.Info << "csa.f1ij_[1]: " << csa.f1ij_[1] << std::endl;
300 
301  //zA
302  //swith order of u1 and u2 in the derivation
303  du1_dx=-vz/v1.length()-v1*(1/(v1.length()*v1.length()*v1.length()))*dot_product(v1,-vz);
304  du2_dx=-vz/v2.length()-v2*(1/(v2.length()*v2.length()*v2.length()))*dot_product(v2,-vz);
305  p=dot_product(u1,cross_product(b,du1_dx));
306  q=(1/cross_product(u2,u1).length())*dot_product(u1,cross_product(u2,du1_dx));
307  r=(1/cross_product(u2,u1).length())*dot_product(n,cross_product(du2_dx,u1)+cross_product(u2,du1_dx));
308  S=numeric::xyzMatrix<Real>::cols(0,-p,-q,p,0,-r,q,r,0);
309  dF_dx=F*S;
310  dPAF_dx=dF_dx*mbeta*malpha;
311  dcompCSA_dx=2*dot_product(memnorm,numeric::product(dPAF_dx*sigmas*PAF.transposed(),memnorm));
312  dE_zA=it->weight()*2*( compCSA - it->CSAval() - it->CSAerr() )*dcompCSA_dx;
313  csa.f1ij_[2]=dE_zA;
314  //tr.Info << "csa.f1ij_[2]: " << csa.f1ij_[2] << std::endl;
315 
316  //xB
317  //swith order of u1 and u2 in the derivation
318  du1_dx=vx/v1.length()-v1*(1/(v1.length()*v1.length()*v1.length()))*dot_product(v1,vx);
319  du2_dx=v0/v2.length()-v2*(1/(v2.length()*v2.length()*v2.length()))*dot_product(v2,v0);
320  p=dot_product(u1,cross_product(b,du1_dx));
321  q=(1/cross_product(u2,u1).length())*dot_product(u1,cross_product(u2,du1_dx));
322  r=(1/cross_product(u2,u1).length())*dot_product(n,cross_product(du2_dx,u1)+cross_product(u2,du1_dx));
323  S=numeric::xyzMatrix<Real>::cols(0,-p,-q,p,0,-r,q,r,0);
324  dF_dx=F*S;
325  dPAF_dx=dF_dx*mbeta*malpha;
326  dcompCSA_dx=2*dot_product(memnorm,numeric::product(dPAF_dx*sigmas*PAF.transposed(),memnorm));
327  dE_xB=it->weight()*2*( compCSA - it->CSAval() - it->CSAerr() )*dcompCSA_dx;
328  csa.f2ij_[0]=dE_xB;
329  //tr.Info << "csa.f2ij_[0]: " << csa.f2ij_[0] << std::endl;
330 
331  //yB
332  //swith order of u1 and u2 in the derivation
333  du1_dx=vy/v1.length()-v1*(1/(v1.length()*v1.length()*v1.length()))*dot_product(v1,vy);
334  du2_dx=v0/v2.length()-v2*(1/(v2.length()*v2.length()*v2.length()))*dot_product(v2,v0);
335  p=dot_product(u1,cross_product(b,du1_dx));
336  q=(1/cross_product(u2,u1).length())*dot_product(u1,cross_product(u2,du1_dx));
337  r=(1/cross_product(u2,u1).length())*dot_product(n,cross_product(du2_dx,u1)+cross_product(u2,du1_dx));
338  S=numeric::xyzMatrix<Real>::cols(0,-p,-q,p,0,-r,q,r,0);
339  dF_dx=F*S;
340  dPAF_dx=dF_dx*mbeta*malpha;
341  dcompCSA_dx=2*dot_product(memnorm,numeric::product(dPAF_dx*sigmas*PAF.transposed(),memnorm));
342  dE_yB=it->weight()*2*( compCSA - it->CSAval() - it->CSAerr() )*dcompCSA_dx;
343  csa.f2ij_[1]=dE_yB;
344  //tr.Info << "csa.f2ij_[1]: " << csa.f2ij_[1] << std::endl;
345 
346  //zB
347  //swith order of u1 and u2 in the derivation
348  du1_dx=vz/v1.length()-v1*(1/(v1.length()*v1.length()*v1.length()))*dot_product(v1,vz);
349  du2_dx=v0/v2.length()-v2*(1/(v2.length()*v2.length()*v2.length()))*dot_product(v2,v0);
350  p=dot_product(u1,cross_product(b,du1_dx));
351  q=(1/cross_product(u2,u1).length())*dot_product(u1,cross_product(u2,du1_dx));
352  r=(1/cross_product(u2,u1).length())*dot_product(n,cross_product(du2_dx,u1)+cross_product(u2,du1_dx));
353  S=numeric::xyzMatrix<Real>::cols(0,-p,-q,p,0,-r,q,r,0);
354  dF_dx=F*S;
355  dPAF_dx=dF_dx*mbeta*malpha;
356  dcompCSA_dx=2*dot_product(memnorm,numeric::product(dPAF_dx*sigmas*PAF.transposed(),memnorm));
357  dE_zB=it->weight()*2*( compCSA - it->CSAval() - it->CSAerr() )*dcompCSA_dx;
358  csa.f2ij_[2]=dE_zB;
359  //tr.Info << "csa.f2ij_[2]: " << csa.f2ij_[2] << std::endl;
360 
361  //xC
362  //swith order of u1 and u2 in the derivation
363  du1_dx=v0/v1.length()-v1*(1/(v1.length()*v1.length()*v1.length()))*dot_product(v1,v0);
364  du2_dx=vx/v2.length()-v2*(1/(v2.length()*v2.length()*v2.length()))*dot_product(v2,vx);
365  p=dot_product(u1,cross_product(b,du1_dx));
366  q=(1/cross_product(u2,u1).length())*dot_product(u1,cross_product(u2,du1_dx));
367  r=(1/cross_product(u2,u1).length())*dot_product(n,cross_product(du2_dx,u1)+cross_product(u2,du1_dx));
368  S=numeric::xyzMatrix<Real>::cols(0,-p,-q,p,0,-r,q,r,0);
369  dF_dx=F*S;
370  dPAF_dx=dF_dx*mbeta*malpha;
371  dcompCSA_dx=2*dot_product(memnorm,numeric::product(dPAF_dx*sigmas*PAF.transposed(),memnorm));
372  dE_xC=it->weight()*2*( compCSA - it->CSAval() - it->CSAerr() )*dcompCSA_dx;
373  csa.f3ij_[0]=dE_xC;
374  //tr.Info << "csa.f3ij_[0]: " << csa.f3ij_[0] << std::endl;
375 
376  //yC
377  //swith order of u1 and u2 in the derivation
378  du1_dx=v0/v1.length()-v1*(1/(v1.length()*v1.length()*v1.length()))*dot_product(v1,v0);
379  du2_dx=vy/v2.length()-v2*(1/(v2.length()*v2.length()*v2.length()))*dot_product(v2,vy);
380  p=dot_product(u1,cross_product(b,du1_dx));
381  q=(1/cross_product(u2,u1).length())*dot_product(u1,cross_product(u2,du1_dx));
382  r=(1/cross_product(u2,u1).length())*dot_product(n,cross_product(du2_dx,u1)+cross_product(u2,du1_dx));
383  S=numeric::xyzMatrix<Real>::cols(0,-p,-q,p,0,-r,q,r,0);
384  dF_dx=F*S;
385  dPAF_dx=dF_dx*mbeta*malpha;
386  dcompCSA_dx=2*dot_product(memnorm,numeric::product(dPAF_dx*sigmas*PAF.transposed(),memnorm));
387  dE_yC=it->weight()*2*( compCSA - it->CSAval() - it->CSAerr() )*dcompCSA_dx;
388  csa.f3ij_[1]=dE_yC;
389  //tr.Info << "csa.f3ij_[1]: " << csa.f3ij_[1] << std::endl;
390 
391  //zC
392  //swith order of u1 and u2 in the derivation
393  du1_dx=v0/v1.length()-v1*(1/(v1.length()*v1.length()*v1.length()))*dot_product(v1,v0);
394  du2_dx=vz/v2.length()-v2*(1/(v2.length()*v2.length()*v2.length()))*dot_product(v2,vz);
395  p=dot_product(u1,cross_product(b,du1_dx));
396  q=(1/cross_product(u2,u1).length())*dot_product(u1,cross_product(u2,du1_dx));
397  r=(1/cross_product(u2,u1).length())*dot_product(n,cross_product(du2_dx,u1)+cross_product(u2,du1_dx));
398  S=numeric::xyzMatrix<Real>::cols(0,-p,-q,p,0,-r,q,r,0);
399  dF_dx=F*S;
400  dPAF_dx=dF_dx*mbeta*malpha;
401  dcompCSA_dx=2*dot_product(memnorm,numeric::product(dPAF_dx*sigmas*PAF.transposed(),memnorm));
402  dE_zC=it->weight()*2*( compCSA - it->CSAval() - it->CSAerr() )*dcompCSA_dx;
403  csa.f3ij_[2]=dE_zC;
404  //tr.Info << "csa.f3ij_[2]: " << csa.f3ij_[2] << std::endl;
405 
406  } else {
407  //tr.Info << "deri 2: " << compCSA - it->CSAval() << " , " << it->CSAerr() << std::endl;
408 
409  //xA
410  //swith order of u1 and u2 in the derivation
411  du1_dx=-vx/v1.length()-v1*(1/(v1.length()*v1.length()*v1.length()))*dot_product(v1,-vx);
412  du2_dx=-vx/v2.length()-v2*(1/(v2.length()*v2.length()*v2.length()))*dot_product(v2,-vx);
413  p=dot_product(u1,cross_product(b,du1_dx));
414  q=(1/cross_product(u2,u1).length())*dot_product(u1,cross_product(u2,du1_dx));
415  r=(1/cross_product(u2,u1).length())*dot_product(n,cross_product(du2_dx,u1)+cross_product(u2,du1_dx));
416  S=numeric::xyzMatrix<Real>::cols(0,-p,-q,p,0,-r,q,r,0);
417  dF_dx=F*S;
418  dPAF_dx=dF_dx*mbeta*malpha;
419  dcompCSA_dx=2*dot_product(memnorm,numeric::product(dPAF_dx*sigmas*PAF.transposed(),memnorm));
420  dE_xA=it->weight()*2*( compCSA - it->CSAval() + it->CSAerr() )*dcompCSA_dx;
421  csa.f1ij_[0]=dE_xA;
422  //tr.Info << "csa.f1ij_[0]: " << csa.f1ij_[0] << std::endl;
423 
424  //yA
425  //swith order of u1 and u2 in the derivation
426  du1_dx=-vy/v1.length()-v1*(1/(v1.length()*v1.length()*v1.length()))*dot_product(v1,-vy);
427  du2_dx=-vy/v2.length()-v2*(1/(v2.length()*v2.length()*v2.length()))*dot_product(v2,-vy);
428  p=dot_product(u1,cross_product(b,du1_dx));
429  q=(1/cross_product(u2,u1).length())*dot_product(u1,cross_product(u2,du1_dx));
430  r=(1/cross_product(u2,u1).length())*dot_product(n,cross_product(du2_dx,u1)+cross_product(u2,du1_dx));
431  S=numeric::xyzMatrix<Real>::cols(0,-p,-q,p,0,-r,q,r,0);
432  dF_dx=F*S;
433  dPAF_dx=dF_dx*mbeta*malpha;
434  dcompCSA_dx=2*dot_product(memnorm,numeric::product(dPAF_dx*sigmas*PAF.transposed(),memnorm));
435  dE_yA=it->weight()*2*( compCSA - it->CSAval() + it->CSAerr() )*dcompCSA_dx;
436  csa.f1ij_[1]=dE_yA;
437  //tr.Info << "csa.f1ij_[1]: " << csa.f1ij_[1] << std::endl;
438 
439  //zA
440  //swith order of u1 and u2 in the derivation
441  du1_dx=-vz/v1.length()-v1*(1/(v1.length()*v1.length()*v1.length()))*dot_product(v1,-vz);
442  du2_dx=-vz/v2.length()-v2*(1/(v2.length()*v2.length()*v2.length()))*dot_product(v2,-vz);
443  p=dot_product(u1,cross_product(b,du1_dx));
444  q=(1/cross_product(u2,u1).length())*dot_product(u1,cross_product(u2,du1_dx));
445  r=(1/cross_product(u2,u1).length())*dot_product(n,cross_product(du2_dx,u1)+cross_product(u2,du1_dx));
446  S=numeric::xyzMatrix<Real>::cols(0,-p,-q,p,0,-r,q,r,0);
447  dF_dx=F*S;
448  dPAF_dx=dF_dx*mbeta*malpha;
449  dcompCSA_dx=2*dot_product(memnorm,numeric::product(dPAF_dx*sigmas*PAF.transposed(),memnorm));
450  dE_zA=it->weight()*2*( compCSA - it->CSAval() + it->CSAerr() )*dcompCSA_dx;
451  csa.f1ij_[2]=dE_zA;
452  //tr.Info << "csa.f1ij_[2]: " << csa.f1ij_[2] << std::endl;
453 
454  //xB
455  //swith order of u1 and u2 in the derivation
456  du1_dx=vx/v1.length()-v1*(1/(v1.length()*v1.length()*v1.length()))*dot_product(v1,vx);
457  du2_dx=v0/v2.length()-v2*(1/(v2.length()*v2.length()*v2.length()))*dot_product(v2,v0);
458  p=dot_product(u1,cross_product(b,du1_dx));
459  q=(1/cross_product(u2,u1).length())*dot_product(u1,cross_product(u2,du1_dx));
460  r=(1/cross_product(u2,u1).length())*dot_product(n,cross_product(du2_dx,u1)+cross_product(u2,du1_dx));
461  S=numeric::xyzMatrix<Real>::cols(0,-p,-q,p,0,-r,q,r,0);
462  dF_dx=F*S;
463  dPAF_dx=dF_dx*mbeta*malpha;
464  dcompCSA_dx=2*dot_product(memnorm,numeric::product(dPAF_dx*sigmas*PAF.transposed(),memnorm));
465  dE_xB=it->weight()*2*( compCSA - it->CSAval() + it->CSAerr() )*dcompCSA_dx;
466  csa.f2ij_[0]=dE_xB;
467  //tr.Info << "csa.f2ij_[0]: " << csa.f2ij_[0] << std::endl;
468 
469  //yB
470  //swith order of u1 and u2 in the derivation
471  du1_dx=vy/v1.length()-v1*(1/(v1.length()*v1.length()*v1.length()))*dot_product(v1,vy);
472  du2_dx=v0/v2.length()-v2*(1/(v2.length()*v2.length()*v2.length()))*dot_product(v2,v0);
473  p=dot_product(u1,cross_product(b,du1_dx));
474  q=(1/cross_product(u2,u1).length())*dot_product(u1,cross_product(u2,du1_dx));
475  r=(1/cross_product(u2,u1).length())*dot_product(n,cross_product(du2_dx,u1)+cross_product(u2,du1_dx));
476  S=numeric::xyzMatrix<Real>::cols(0,-p,-q,p,0,-r,q,r,0);
477  dF_dx=F*S;
478  dPAF_dx=dF_dx*mbeta*malpha;
479  dcompCSA_dx=2*dot_product(memnorm,numeric::product(dPAF_dx*sigmas*PAF.transposed(),memnorm));
480  dE_yB=it->weight()*2*( compCSA - it->CSAval() + it->CSAerr() )*dcompCSA_dx;
481  csa.f2ij_[1]=dE_yB;
482  //tr.Info << "csa.f2ij_[1]: " << csa.f2ij_[1] << std::endl;
483 
484  //zB
485  //swith order of u1 and u2 in the derivation
486  du1_dx=vz/v1.length()-v1*(1/(v1.length()*v1.length()*v1.length()))*dot_product(v1,vz);
487  du2_dx=v0/v2.length()-v2*(1/(v2.length()*v2.length()*v2.length()))*dot_product(v2,v0);
488  p=dot_product(u1,cross_product(b,du1_dx));
489  q=(1/cross_product(u2,u1).length())*dot_product(u1,cross_product(u2,du1_dx));
490  r=(1/cross_product(u2,u1).length())*dot_product(n,cross_product(du2_dx,u1)+cross_product(u2,du1_dx));
491  S=numeric::xyzMatrix<Real>::cols(0,-p,-q,p,0,-r,q,r,0);
492  dF_dx=F*S;
493  dPAF_dx=dF_dx*mbeta*malpha;
494  dcompCSA_dx=2*dot_product(memnorm,numeric::product(dPAF_dx*sigmas*PAF.transposed(),memnorm));
495  dE_zB=it->weight()*2*( compCSA - it->CSAval() + it->CSAerr() )*dcompCSA_dx;
496  csa.f2ij_[2]=dE_zB;
497  //tr.Info << "csa.f2ij_[2]: " << csa.f2ij_[2] << std::endl;
498 
499  //xC
500  //swith order of u1 and u2 in the derivation
501  du1_dx=v0/v1.length()-v1*(1/(v1.length()*v1.length()*v1.length()))*dot_product(v1,v0);
502  du2_dx=vx/v2.length()-v2*(1/(v2.length()*v2.length()*v2.length()))*dot_product(v2,vx);
503  p=dot_product(u1,cross_product(b,du1_dx));
504  q=(1/cross_product(u2,u1).length())*dot_product(u1,cross_product(u2,du1_dx));
505  r=(1/cross_product(u2,u1).length())*dot_product(n,cross_product(du2_dx,u1)+cross_product(u2,du1_dx));
506  S=numeric::xyzMatrix<Real>::cols(0,-p,-q,p,0,-r,q,r,0);
507  dF_dx=F*S;
508  dPAF_dx=dF_dx*mbeta*malpha;
509  dcompCSA_dx=2*dot_product(memnorm,numeric::product(dPAF_dx*sigmas*PAF.transposed(),memnorm));
510  dE_xC=it->weight()*2*( compCSA - it->CSAval() + it->CSAerr() )*dcompCSA_dx;
511  csa.f3ij_[0]=dE_xC;
512  //tr.Info << "csa.f3ij_[0]: " << csa.f3ij_[0] << std::endl;
513 
514  //yC
515  //swith order of u1 and u2 in the derivation
516  du1_dx=v0/v1.length()-v1*(1/(v1.length()*v1.length()*v1.length()))*dot_product(v1,v0);
517  du2_dx=vy/v2.length()-v2*(1/(v2.length()*v2.length()*v2.length()))*dot_product(v2,vy);
518  p=dot_product(u1,cross_product(b,du1_dx));
519  q=(1/cross_product(u2,u1).length())*dot_product(u1,cross_product(u2,du1_dx));
520  r=(1/cross_product(u2,u1).length())*dot_product(n,cross_product(du2_dx,u1)+cross_product(u2,du1_dx));
521  S=numeric::xyzMatrix<Real>::cols(0,-p,-q,p,0,-r,q,r,0);
522  dF_dx=F*S;
523  dPAF_dx=dF_dx*mbeta*malpha;
524  dcompCSA_dx=2*dot_product(memnorm,numeric::product(dPAF_dx*sigmas*PAF.transposed(),memnorm));
525  dE_yC=it->weight()*2*( compCSA - it->CSAval() + it->CSAerr() )*dcompCSA_dx;
526  csa.f3ij_[1]=dE_yC;
527  //tr.Info << "csa.f3ij_[1]: " << csa.f3ij_[1] << std::endl;
528 
529  //zC
530  //swith order of u1 and u2 in the derivation
531  du1_dx=v0/v1.length()-v1*(1/(v1.length()*v1.length()*v1.length()))*dot_product(v1,v0);
532  du2_dx=vz/v2.length()-v2*(1/(v2.length()*v2.length()*v2.length()))*dot_product(v2,vz);
533  p=dot_product(u1,cross_product(b,du1_dx));
534  q=(1/cross_product(u2,u1).length())*dot_product(u1,cross_product(u2,du1_dx));
535  r=(1/cross_product(u2,u1).length())*dot_product(n,cross_product(du2_dx,u1)+cross_product(u2,du1_dx));
536  S=numeric::xyzMatrix<Real>::cols(0,-p,-q,p,0,-r,q,r,0);
537  dF_dx=F*S;
538  dPAF_dx=dF_dx*mbeta*malpha;
539  dcompCSA_dx=2*dot_product(memnorm,numeric::product(dPAF_dx*sigmas*PAF.transposed(),memnorm));
540  dE_zC=it->weight()*2*( compCSA - it->CSAval() + it->CSAerr() )*dcompCSA_dx;
541  csa.f3ij_[2]=dE_zC;
542  //tr.Info << "csa.f3ij_[2]: " << csa.f3ij_[2] << std::endl;
543  }
544 
545  }
546  //tr.Info << "All_CSA_lines_.size(): " << All_CSA_lines_.size() << std::endl;
547 
548  //return energy
549  return total_dev;
550  //return total_dev/All_CSA_lines_.size();
551 
552 }//end of compute_csascore
553 
554 } //namespace Scoring
555 } //namespace core