16 #include <ObjexxFCL/format.hh>
17 #include <numeric/xyzMatrix.hh>
26 namespace chemical_shift {
35 Size const realatomdata_index){
40 Real const r_length = r_vector.length();
42 Real const r_length2 = r_length * r_length;
44 Real const r_length5 = std::pow(r_length,5);
46 Real const x_length = dot(r_vector , base_coordinate_matrix.col_x());
47 Real const y_length = dot(r_vector , base_coordinate_matrix.col_y());
48 Real const z_length = dot(r_vector , base_coordinate_matrix.col_z());
53 Real const coeff_xx = ( ma_r * source_rsd_CS_params.
atom_data(realatomdata_index,
marx) ) - ( ma_q * source_rsd_CS_params.
atom_data(realatomdata_index,
maqx) );
55 Real const coeff_yy = ( ma_r * source_rsd_CS_params.
atom_data(realatomdata_index,
mary) ) - ( ma_q * source_rsd_CS_params.
atom_data(realatomdata_index,
maqy) );
57 Real const coeff_zz = ( ma_r * source_rsd_CS_params.
atom_data(realatomdata_index,
marz) ) - ( ma_q * source_rsd_CS_params.
atom_data(realatomdata_index,
maqz) );
59 Real const coeff_xy = 0.0 - ( ma_q * source_rsd_CS_params.
atom_data(realatomdata_index,
maqw) );
62 Real const termxx = ( ( 3.0 * x_length * x_length ) - r_length2 ) * ( coeff_xx );
65 Real const termyy = ( ( 3.0 * y_length * y_length ) - r_length2 ) * ( coeff_yy );
68 Real const termzz = ( ( 3.0 * z_length * z_length ) - r_length2 ) * ( coeff_zz );
71 Real const termxy = ( ( 3.0 * x_length * y_length ) ) * ( coeff_xy );
74 Real const termr = -1.0 / (3.0 * r_length5);
77 Real const chem_shift_MA = ( termr ) * ( termxx + termyy + termzz + termxy );
92 Size const realatomdata_index){
108 Real const r_length = r_vector.length();
110 Real const r_length2 = r_length * r_length;
112 Real const r_length5 = std::pow(r_length,5);
121 Real const x_length = dot(r_vector , x_norm);
122 Real const y_length = dot(r_vector , y_norm);
123 Real const z_length = dot(r_vector , z_norm);
124 Real const yprime_length = dot(r_vector , yprime_norm);
132 Real const coeff_xx = ( ma_r * source_rsd_CS_params.
atom_data(realatomdata_index,
marx) ) - ( ma_q * source_rsd_CS_params.
atom_data(realatomdata_index,
maqx) );
134 Real const coeff_yy = ( ma_r * source_rsd_CS_params.
atom_data(realatomdata_index,
mary) ) - ( ma_q * source_rsd_CS_params.
atom_data(realatomdata_index,
maqy) );
136 Real const coeff_zz = ( ma_r * source_rsd_CS_params.
atom_data(realatomdata_index,
marz) ) - ( ma_q * source_rsd_CS_params.
atom_data(realatomdata_index,
maqz) );
138 Real const coeff_xy = 0.0 - ( ma_q * source_rsd_CS_params.
atom_data(realatomdata_index,
maqw) );
141 Real const termxx = ( ( 3.0 * x_length * x_length ) - r_length2 ) * ( coeff_xx );
144 Real const termyy = ( ( 3.0 * y_length * y_length ) - r_length2 ) * ( coeff_yy );
147 Real const termzz = ( ( 3.0 * z_length * z_length ) - r_length2 ) * ( coeff_zz );
150 Real const termxy = ( ( 3.0 * x_length * y_length ) ) * ( coeff_xy );
153 Real const termr = -1.0 / (3.0 * r_length5);
155 Real const dtermr_dr = ( -5.0 / r_length ) * (termr);
159 Real const dy_dx = dot(y_norm, x_norm);
161 Real const dy_dyprime=dot(y_norm, yprime_norm);
169 Real const dr_dx = ( x_length / r_length );
171 Real const dtermr_dx = dr_dx * dtermr_dr;
173 Real const dtermxx_dx = ( ( 6.0 * x_length ) - ( 2.0 * x_length ) ) * ( coeff_xx );
175 Real const dtermyy_dx = ( ( 6.0 * y_length * dy_dx ) - ( 2.0 * x_length ) ) * ( coeff_yy );
177 Real const dtermzz_dx = ( ( 0.0 ) - ( 2.0 * x_length ) ) * ( coeff_zz );
179 Real const dtermxy_dx = ( ( ( 3.0 * y_length ) + ( 3.0 * x_length * dy_dx) ) - ( 0.0 ) ) * ( coeff_xy );
181 Real const dchem_shift_MA_dx = ( (dtermr_dx) * (termxx + termyy + termzz + termxy ) ) + ( (termr) * (dtermxx_dx + dtermyy_dx + dtermzz_dx + dtermxy_dx) );
190 Real const dr_dyprime = ( yprime_length / r_length );
192 Real const dtermr_dyprime = dr_dyprime * dtermr_dr;
194 Real const dtermxx_dyprime = ( ( 0.0 ) - ( 2.0 * yprime_length ) ) * ( coeff_xx );
196 Real const dtermyy_dyprime = ( ( 6.0 * y_length * dy_dyprime ) - ( 2.0 * yprime_length ) ) * ( coeff_yy );
198 Real const dtermzz_dyprime = ( ( 0.0 ) - ( 2.0 * yprime_length ) ) * ( coeff_zz );
200 Real const dtermxy_dyprime = ( ( 3.0 * x_length * dy_dyprime ) - ( 0.0 ) ) * ( coeff_xy );
202 Real const dchem_shift_MA_dyprime = ( (dtermr_dyprime) * (termxx + termyy + termzz + termxy ) ) + ( (termr) * (dtermxx_dyprime + dtermyy_dyprime + dtermzz_dyprime + dtermxy_dyprime) );
210 Real const dr_dz = ( z_length / r_length );
212 Real const dtermr_dz = dr_dz * dtermr_dr;
214 Real const dtermxx_dz = ( ( 0.0 ) - ( 2.0 * z_length ) ) * ( coeff_xx );
216 Real const dtermyy_dz = ( ( 0.0 ) - ( 2.0 * z_length ) ) * ( coeff_yy );
218 Real const dtermzz_dz = ( ( 6.0 * z_length ) - ( 2.0 * z_length ) ) * ( coeff_zz );
220 Real const dtermxy_dz = ( ( 0.0 ) - ( 0.0 ) ) * ( coeff_xy );
222 Real const dchem_shift_MA_dz = ( (dtermr_dz) * (termxx + termyy + termzz + termxy ) ) + ( (termr) * (dtermxx_dz + dtermyy_dz + dtermzz_dz + dtermxy_dz) );
227 numeric::xyzVector<core::Real> const analytical_gradient=(dchem_shift_MA_dx * x_norm) + (dchem_shift_MA_dyprime * yprime_norm) + (dchem_shift_MA_dz * z_norm);
231 return analytical_gradient;
239 //dchem_shift_MA_dy = ( (dtermr_dy) * (termxx + termyy + termzz + termxy ) ) + ( (termr) * (dtermxx_dy + dtermyy_dy + dtermzz_dy + dtermxy_dy) ) //Chain rule.
241 Real const dr_dy = ( y_length / r_length );
243 Real const dtermr_dy = dr_dy * dtermr_dr;
245 Real const dtermxx_dy = ( ( 0.0 ) - ( 2.0 * y_length ) ) * ( coeff_xx );
247 Real const dtermyy_dy = ( ( 6.0 * y_length ) - ( 2.0 * y_length ) ) * ( coeff_yy );
249 Real const dtermzz_dy = ( ( 0.0 ) - ( 2.0 * y_length ) ) * ( coeff_zz );
251 Real const dtermxy_dy = ( ( 3.0 * x_length ) - ( 0.0 ) ) * ( coeff_xy );
253 Real const dchem_shift_MA_dy = ( (dtermr_dy) * (termxx + termyy + termzz + termxy ) ) + ( (termr) * (dtermxx_dy + dtermyy_dy + dtermzz_dy + dtermxy_dy) );
256 //dchem_shift_MA_dyprime
258 //dchem_shift_MA_dy = y_norm * gradient = ( dot(y_norm, x_norm) * dchem_shift_MA_dx ) + ( dot(y_norm, yprime_norm) * dchem_shift_MA_dyprime )
259 //dchem_shift_MA_dyprime = ( 1/ dot(y_norm, yprime_norm) ) * ( dchem_shift_MA_dy - ( dot(y_norm, x_norm) * dchem_shift_MA_dx ) )
260 //NOTE: this assumes dot(z_norm, y_norm)=0 which is true since in RNA_CS_Util.cc z_norm = cross(x_norm, y_norm);
261 // Real const dchem_shift_MA_dyprime = ( 1 / dot(y_norm, yprime_norm) ) * ( dchem_shift_MA_dy - ( dot(y_norm, x_norm) * dchem_shift_MA_dx ) );
286 numeric::xyzVector<core::Real> const rosetta_frame_y_plus_xyz= CS_data_atom_xyz + (rosetta_frame_y_vector*increment);
287 numeric::xyzVector<core::Real> const rosetta_frame_y_minus_xyz= CS_data_atom_xyz - (rosetta_frame_y_vector*increment);
289 Real const rosetta_frame_y_plus_effect = delta_magnetic_anisotropy( rosetta_frame_y_plus_xyz, source_atom_xyz, base_coordinate_matrix, source_rsd_CS_params, realatomdata_index);
290 Real const rosetta_frame_y_minus_effect = delta_magnetic_anisotropy( rosetta_frame_y_minus_xyz, source_atom_xyz, base_coordinate_matrix, source_rsd_CS_params, realatomdata_index);
292 Real const deffect_drosettay_numerical = (rosetta_frame_y_plus_effect - rosetta_frame_y_minus_effect ) / ( 2 * increment );
295 numeric::xyzVector<core::Real> const rosetta_frame_z_plus_xyz= CS_data_atom_xyz + (rosetta_frame_z_vector*increment);
296 numeric::xyzVector<core::Real> const rosetta_frame_z_minus_xyz= CS_data_atom_xyz - (rosetta_frame_z_vector*increment);
298 Real const rosetta_frame_z_plus_effect = delta_magnetic_anisotropy( rosetta_frame_z_plus_xyz, source_atom_xyz, base_coordinate_matrix, source_rsd_CS_params, realatomdata_index);
299 Real const rosetta_frame_z_minus_effect = delta_magnetic_anisotropy( rosetta_frame_z_minus_xyz, source_atom_xyz, base_coordinate_matrix, source_rsd_CS_params, realatomdata_index);
301 Real const deffect_drosettaz_numerical = (rosetta_frame_z_plus_effect - rosetta_frame_z_minus_effect ) / ( 2 * increment );
304 numeric::xyzVector<core::Real> const numerical_gradient=(deffect_drosettax_numerical * rosetta_frame_x_vector) + (deffect_drosettay_numerical * rosetta_frame_y_vector) + (deffect_drosettaz_numerical * rosetta_frame_z_vector);
306 std::cout << "---------------------------------------------------------------------" << std::endl;
307 std::cout << " | x_norm =(" << x_norm.x() << ", " << x_norm.y() << ", " << x_norm.z() << ") x_norm.length()=" << x_norm.length();
308 std::cout << " | yprime_norm =(" << yprime_norm.x() << ", " << yprime_norm.y() << ", " << yprime_norm.z() << ") yprime_norm.length()=" << yprime_norm.length();
309 std::cout << " | z_norm =(" << z_norm.x() << ", " << z_norm.y() << ", " << z_norm.z() << ") z_norm.length()=" << z_norm.length();
310 std::cout << " | dot(x_norm, yprime_norm)= " << dot(x_norm, yprime_norm);
311 std::cout << " | dot(x_norm, z_norm)= " << dot(x_norm, z_norm);
312 std::cout << " | dot(yprime_norm, z_norm)= " << dot(yprime_norm, z_norm) << std::endl;
314 std::cout << "analytical_gradient=( " << analytical_gradient.x() << " , " << analytical_gradient.y() << " , " << analytical_gradient.z() << " )";
315 std::cout << " | numerical_gradient=( " << numerical_gradient.x() << " , " << numerical_gradient.y() << " , " << numerical_gradient.z() << " )" << std::endl;
316 std::cout << "---------------------------------------------------------------------" << std::endl;
318 if(use_numerical_deriv) return numerical_gradient;
329 if( source_rsd.
aa()!= source_rsd_CS_params.
aa() ) utility_exit_with_message(
"rsd.aa()!= source_rsd_CS_params.aa()!");
331 Real ma_effect = 0.0;
337 for (
Size realatomdata_index = 1; realatomdata_index < maxatoms; realatomdata_index++){
343 ma_effect +=
delta_magnetic_anisotropy(atom_xyz, source_rsd.
xyz(atom_index), base_coordinate_matrix, source_rsd_CS_params, realatomdata_index);