27 #include <boost/unordered_map.hpp>
34 #include <basic/Tracer.hh>
35 #include <utility/vector0.hh>
36 #include <utility/vector1.hh>
37 #include <ObjexxFCL/string.functions.hh>
54 static basic::Tracer
tr(
"protocols.sparta");
64 boost::unordered_map< int, std::string > & atom_names,
70 using boost::unordered_map;
77 COMP_Tab.
VARS_str_parser(
" RESID RESNAME ATOMNAME CS_OBS SHIFT RC_SHIFT CS_DIFF SIGMA W");
80 boost::unordered_map< int, string >::iterator itN;
81 boost::unordered_map< int, boost::unordered_map< string, string > >::iterator it;
86 for ( itN = atom_names.begin(); itN != atom_names.end(); itN++ ) {
87 string aName = itN->second;
88 if ( aName ==
"H" ) aName=
"HN";
89 bool floating_sign( REF_CS_Tab.
isVarFloat(
"SHIFT2") );
90 if ( floating_sign )
tr.Info <<
" use floating sign1 " << std::endl;
91 else tr.Info <<
" no floating sign " << std::endl;
92 for ( it = REF_CS_Tab.
Entries.begin(); it != REF_CS_Tab.
Entries.end(); it++ ) {
93 float obs_shift, pred_shift, obs_shift2( 0.0 );
94 string aName_ref = it->second[
"ATOMNAME"];
95 if ( aName_ref ==
"H" ) aName_ref =
"HN";
97 if ( aName ==
"HA" && aName_ref ==
"G") {
98 if ( aName_ref.find(
"HA") != 0 )
continue;
99 }
else if ( aName_ref != aName )
continue;
101 GDB_Entry temp = Pred_Sum.
getEntry(
"RESID",it->second[
"RESID"],
"ATOMNAME",aName,1);
103 if (temp[
"SHIFT"].length() <= 0)
continue;
105 obs_shift = atof( (it->second[
"SHIFT"]).c_str() );
106 if ( floating_sign ) obs_shift2 = atof( (it->second[
"SHIFT2"]).c_str() );
108 pred_shift = atof( (temp[
"SHIFT"]).c_str() );
110 if ( aName ==
"HA" && it->second[
"RESNAME"] ==
"G") {
111 if ( aName_ref ==
"HA2" ) {
112 float shift_HA3 = 9999.000;
113 float shift_HA3_2 = 9999;
114 GDB_Entry HA3 = REF_CS_Tab.
getEntry(
"RESID",it->second[
"RESID"],
"ATOMNAME",
"HA3",1);
115 if ( HA3[
"ATOMNAME"] ==
"HA3") shift_HA3 = atof( (HA3[
"SHIFT"]).c_str() );
116 if ( floating_sign && HA3[
"ATOMNAME"] ==
"HA3") shift_HA3_2 = atof( (HA3[
"SHIFT2"]).c_str() );
118 if ( shift_HA3 < obs_shift) obs_shift = shift_HA3;
119 if ( floating_sign && shift_HA3_2 < obs_shift2 ) obs_shift2 = shift_HA3_2;
121 shift_HA3 = 9999.000;
122 HA3 = Pred_Sum.
getEntry(
"RESID",it->second[
"RESID"],
"ATOMNAME",
"HA3",1);
123 if ( HA3[
"ATOMNAME"] ==
"HA3") shift_HA3 = atof( (HA3[
"SHIFT"]).c_str() );
125 if ( shift_HA3 < pred_shift) pred_shift = shift_HA3;
126 }
else if ( aName_ref ==
"HA3" ) {
128 float shift_HA2 = -9999.000;
129 float shift_HA2_2 = -9999;
130 GDB_Entry HA2 = REF_CS_Tab.
getEntry(
"RESID",it->second[
"RESID"],
"ATOMNAME",
"HA2",1);
131 if ( HA2[
"ATOMNAME"] ==
"HA2") shift_HA2 = atof( (HA2[
"SHIFT"]).c_str() );
132 if ( floating_sign && HA2[
"ATOMNAME"] ==
"HA2") shift_HA2_2 = atof( (HA2[
"SHIFT2"]).c_str() );
134 if ( shift_HA2 > obs_shift) obs_shift = shift_HA2;
135 if ( floating_sign && shift_HA2_2 > obs_shift2 ) obs_shift2 = shift_HA2_2;
137 shift_HA2 = -9999.000;
138 HA2 = Pred_Sum.
getEntry(
"RESID",it->second[
"RESID"],
"ATOMNAME",
"HA2",1);
139 if ( HA2[
"ATOMNAME"] ==
"HA2") shift_HA2 = atof( (HA2[
"SHIFT"]).c_str() );
141 if ( shift_HA2 > pred_shift) pred_shift = shift_HA2;
145 if ( pred_shift > 999.0 )
continue;
147 if ( std::fabs( pred_shift-obs_shift ) > std::fabs( pred_shift-obs_shift2 ) ) {
148 obs_shift=obs_shift2;
150 OBS_V.push_back( obs_shift );
151 PRED_V.push_back( pred_shift );
152 DIFF_V.push_back( pred_shift-obs_shift );
154 Real sigma( atof( (temp[
"SIGMA"]).c_str() ) );
156 Size const res_id( ObjexxFCL::ulong_of( it->second[
"RESID"] ) );
158 (obs_shift-pred_shift)*(obs_shift-pred_shift)/(sigma*sigma)
167 if ( per_residue_scores.size() > res_id ) {
169 per_residue_scores[res_id] += score;
174 if (
tr.Info.visible() ) {
175 tr.Info <<
"RMS(OBS, PRED) for " << aName <<
" (n=" << OBS_V.size() <<
"): "
176 <<
getRMS(OBS_V, PRED_V) <<
" ppm " << std::endl;
179 float avg_diff =
getAVG(DIFF_V);
180 for(
Size i = 0; i< OBS_V.size(); i++) {
181 OBS_V_CORRECTED.push_back( OBS_V[i] + avg_diff );
184 OBS_V.clear(); PRED_V.clear(); DIFF_V.clear(); OBS_V_CORRECTED.clear();
187 if (
tr.Debug.visible() ) {
188 tr.Debug <<
" ============== COMP_Tab ==================== " << std::endl;
190 tr.Debug <<
" ============== END COMP_Tab ==================== " << std::endl;
191 tr.Debug <<
" ============== REF_CS_TAB ==================== " << std::endl;
193 tr.Debug <<
" ============== END_CS_TAB ==================== " << std::endl;
198 boost::unordered_map< int, std::string > & names,
210 for ( iter it = scores.begin(),
end = scores.end(); it !=
end; ++it ) {
217 float a = fabs(ang1-ang2);
219 if ( a < 180 )
return a;
220 else if ( a > 180 && a < 360.1 && ang1*ang2 < 0 ) {
233 for(
int i = 0; i < n; i++) {
246 for (
int i = 0; i < n; i++) {
247 sum += (v1[i]-avg)*(v1[i]-avg);
250 return sqrt(sum/(
float)(n-1));
254 if (v1.size() != v2.size() )
return -1.0;
260 for(
int i = 0; i < n; i++) {
261 sum += ( (v1[i]-v2[i])*(v1[i]-v2[i]) );
264 return sqrt(sum/(
float)(n-1));
268 char *
itoa(
int n,
char *buff,
int )
270 sprintf(buff,
"%d", n);
276 char *
ftoa(
float n,
char *buff,
char f,
int prec )
278 if ( !(f==
'f' || f==
'F' || f==
'e' || f==
'E' || f==
'g' || f==
'G') ) {
289 *fs++ = prec / 10 +
'0';
290 *fs++ = prec % 10 +
'0';
298 sprintf( buff, format, n );
305 #ifndef __native_client__
307 return mkdir(dirName);
310 return mkdir(dirName, 0777);
318 if ( NULL == getcwd(oldDir, _MAX_PATH) )
return false;
320 if ( chdir( Dir.c_str() ) == -1 )
return false;
322 if ( chdir( oldDir ) == -1 )
return false;
327 dp = opendir(Dir.c_str());
329 (void) closedir (dp);