Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
AmbiguousNMRDistanceConstraint.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/constraints/AmbiguousNMRDistanceConstraint.cc
11 ///
12 /// @brief
13 /// @author Oliver Lange
14 
15 // Unit Headers
17 
18 // Package Headers
24 // Project Headers
26 // AUTO-REMOVED #include <core/conformation/Conformation.hh>
27 #include <core/id/NamedAtomID.hh>
28 #include <core/id/AtomID.hh>
29 #include <core/pose/Pose.hh>
30 #include <core/pose/util.hh>
31 #include <core/chemical/AA.hh>
32 // Utility Headers
33 #include <basic/Tracer.hh>
34 #include <ObjexxFCL/string.functions.hh>
35 #include <basic/prof.hh>
36 // Numeric Headers
37 #include <numeric/deriv/distance_deriv.hh>
38 
39 //Auto Headers
42 #include <utility/vector1.hh>
43 
44 
45 static basic::Tracer tr("core.io.constraints");
46 
47 
48 namespace core {
49 namespace scoring {
50 namespace constraints {
51 
52 
53 /// @brief Copies the data from this Constraint into a new object and returns an OP
54 /// atoms are mapped to atoms with the same name in dest pose ( e.g. for switch from centroid to fullatom )
55 /// if a sequence_mapping is present it is used to map residue numbers .. NULL = identity mapping
56 /// to the new object. Intended to be implemented by derived classes.
58  Atoms ids1, ids2;
59  for ( Atoms::const_iterator it = atoms1_.begin(); it != atoms1_.end(); ++it ) {
61  if ( smap ) {
62  atom.rsd() = (*smap)[ it->rsd() ];
63  }
65  if ( !id1.valid() ) return NULL;
66  ids1.push_back( id1 );
67  }
68  for ( Atoms::const_iterator it = atoms2_.begin(); it != atoms2_.end(); ++it ) {
70  if ( smap ) {
71  atom.rsd() = (*smap)[ it->rsd() ];
72  }
74  if ( !id2.valid() ) return NULL;
75  ids2.push_back( id2 );
76  }
77  return new AmbiguousNMRDistanceConstraint( ids1, ids2, func_, score_type() );
78 }
79 
80 void AmbiguousNMRDistanceConstraint::show( std::ostream& out ) const {
81  out << "AmbiguousNMRDistanceConstraint (";
82  for ( Atoms::const_iterator it = atoms1_.begin(); it != atoms1_.end(); ++it ) {
83  out << it->atomno() << "," << it->rsd() << "||";
84  }
85  out << " - ";
86  for ( Atoms::const_iterator it = atoms2_.begin(); it != atoms2_.end(); ++it ) {
87  out << it->atomno() << "," << it->rsd();
88  }
89  func_->show( out );
90 }
91 
92 inline bool is_aromatic( pose::Pose const& pose, core::Size res ) {
93  using namespace core::chemical;
94  return pose.residue_type( res ).aa() == aa_phe
95  || pose.residue_type( res ).aa() == aa_tyr
96  || pose.residue_type( res ).aa() == aa_trp ;
97 }
98 
100  using core::chemical::AA;
101  using namespace core::chemical;
102  return ( aa == aa_trp || aa == aa_phe || aa == aa_tyr || aa == aa_his );
103 }
104 
106  using core::chemical::AA;
107  using namespace core::chemical;
108  using core::id::NamedAtomID;
109  ///now fix all the problems with atomnames:
110  if ( (name.substr(0,2) == "QA" || name == "HA") && ( aa == aa_gly )) {
111  atoms.push_back( NamedAtomID( "1HA", res ) );
112  atoms.push_back( NamedAtomID( "2HA", res ) );
113  } else if ( ( name == "QB" || name == "HB" ) && (
114  aa == aa_ala
115  || aa == aa_leu
116  || aa == aa_ser
117  || aa == aa_asn
118  || aa == aa_gln
119  || aa == aa_pro
120  || aa == aa_lys
121  || aa == aa_cys
122  || aa == aa_asp
123  || aa == aa_glu
124  || aa == aa_arg
125  || aa == aa_tyr
126  || aa == aa_phe
127  || aa == aa_trp
128  || aa == aa_his
129  || aa == aa_met ) ) {
130  atoms.push_back( NamedAtomID( "1HB", res ) );
131  atoms.push_back( NamedAtomID( "2HB", res ) );
132  if ( aa == aa_ala ) atoms.push_back( NamedAtomID( "3HB", res ) );
133  } else if ( ( name == "QD1" || name == "HD1" ) && (
134  aa == aa_ile
135  || aa == aa_leu )) {
136  atoms.push_back( NamedAtomID( "1HD1", res ) );
137  atoms.push_back( NamedAtomID( "2HD1", res ) );
138  atoms.push_back( NamedAtomID( "3HD1", res ) );
139  } else if ( ( name == "QD2" || name == "HD2" ) && (
140  aa == aa_leu
141  ||aa == aa_asn )) {
142  atoms.push_back( NamedAtomID( "1HD2", res ) );
143  atoms.push_back( NamedAtomID( "2HD2", res ) );
144  if ( aa == aa_leu ) atoms.push_back( NamedAtomID( "3HD2", res ) );
145  } else if ( ( name == "QQD" || name == "QD" ) && aa == aa_leu ) {
146  atoms.push_back( NamedAtomID( "1HD2", res ) );
147  atoms.push_back( NamedAtomID( "2HD2", res ) );
148  atoms.push_back( NamedAtomID( "3HD2", res ) );
149  atoms.push_back( NamedAtomID( "1HD1", res ) );
150  atoms.push_back( NamedAtomID( "2HD1", res ) );
151  atoms.push_back( NamedAtomID( "3HD1", res ) );
152  } else if ( ( name == "QD" || name == "HD" ) && (
153  aa == aa_pro
154  || aa == aa_lys
155  || aa == aa_arg
156  || aa == aa_tyr
157  || aa == aa_phe
158  || aa == aa_his ) ) {
159  if ( aa == aa_arg || aa == aa_lys || aa == aa_pro ) {
160  atoms.push_back( NamedAtomID( "1HD", res ) );
161  atoms.push_back( NamedAtomID( "2HD", res ) );
162  } else { // tyr, phe, his (his doesn't get down here... )
163  atoms.push_back( NamedAtomID( "HD1", res ) );
164  atoms.push_back( NamedAtomID( "HD2", res ) );
165  }
166  } else if ( ( name == "QE" || name == "HE" ) && (
167  aa == aa_tyr
168  || aa == aa_phe
169  || aa == aa_trp
170  || aa == aa_met
171  || aa == aa_lys ) ){
172  if ( aa == aa_phe || aa == aa_tyr ) {
173  atoms.push_back( NamedAtomID( "HE1", res ) );
174  atoms.push_back( NamedAtomID( "HE2", res ) );
175  } else if ( aa == aa_trp ) {
176  atoms.push_back( NamedAtomID( "HE1", res ) );
177  atoms.push_back( NamedAtomID( "HE3", res ) );
178  } else if ( aa == aa_met || aa == aa_lys ) { //MET LYS
179  atoms.push_back( NamedAtomID( "1HE", res ) );
180  atoms.push_back( NamedAtomID( "2HE", res ) );
181  if ( aa == aa_met ) {
182  atoms.push_back( NamedAtomID( "3HE", res ) );
183  }
184  } //QE MET LYS
185  } else if ( ( name == "QG" || name == "HG" ) && (
186  aa == aa_met
187  || aa == aa_gln
188  || aa == aa_pro
189  || aa == aa_lys
190  || aa == aa_glu
191  || aa == aa_arg )) {
192  atoms.push_back( NamedAtomID( "1HG", res ) );
193  atoms.push_back( NamedAtomID( "2HG", res ) );
194  // atoms.push_back( NamedAtomID( "3HE", res ) );
195  } else if (( name == "QG2" || name == "HG2" ) && (
196  aa == aa_ile
197  || aa == aa_thr
198  || aa == aa_val ) ) {
199  atoms.push_back( NamedAtomID( "1HG2", res ) );
200  atoms.push_back( NamedAtomID( "2HG2", res ) );
201  atoms.push_back( NamedAtomID( "3HG2", res ) );
202  } else if ( ( name == "QQG" || name == "HG" ) && (
203  aa == aa_ile
204  || aa == aa_val ) ) {
205  atoms.push_back( NamedAtomID( "1HG2", res ) );
206  atoms.push_back( NamedAtomID( "2HG2", res ) );
207  atoms.push_back( NamedAtomID( "3HG2", res ) );
208  atoms.push_back( NamedAtomID( "1HG1", res ) );
209  atoms.push_back( NamedAtomID( "2HG1", res ) );
210  if ( aa != aa_ile ) atoms.push_back( NamedAtomID( "3HG1", res ) );
211  } else if (( name == "QG1" || name == "HG1" ) && (
212  aa == aa_ile
213  || aa == aa_val ) ) {
214  atoms.push_back( NamedAtomID( "1HG1", res ) );
215  atoms.push_back( NamedAtomID( "2HG1", res ) );
216  if ( aa != aa_ile ) atoms.push_back( NamedAtomID( "3HG1", res ) );
217  } else if (( name == "QE2" || name == "HE2" || name =="HE" ) && aa == aa_gln ) {
218  atoms.push_back( NamedAtomID( "1HE2", res ) );
219  atoms.push_back( NamedAtomID( "2HE2", res ) );
220  } else if (( name == "HZ" || name == "QZ" ) && ( aa == aa_trp || aa == aa_lys ) ) {
221  if ( aa == aa_lys ) {
222  atoms.push_back( NamedAtomID( "1HZ", res ) );
223  atoms.push_back( NamedAtomID( "2HZ", res ) );
224  atoms.push_back( NamedAtomID( "3HZ", res ) );
225  } else { //aa==trp
226  atoms.push_back( NamedAtomID( "HZ2", res ) );
227  atoms.push_back( NamedAtomID( "HZ3", res ) );
228  }
229  } else if ( name == "HB1" ) {
230  atoms.push_back( NamedAtomID( "1HB", res ) );
231  } else if ( name == "HB2" ) {
232  atoms.push_back( NamedAtomID( "2HB", res ) );
233  } else if ( name == "HB3" ) {
234  if ( aa != aa_ala ) {
235  atoms.push_back( NamedAtomID( "1HB", res ) ); //yeah they call it 2HB and 3HB...
236  } else {
237  atoms.push_back( NamedAtomID( "3HB", res ) );
238  }
239  } else if ( name == "HD1" && !is_aromatic( aa ) ) {
240  atoms.push_back( NamedAtomID( "1HD", res ) );
241  } else if ( name == "HD2" && !is_aromatic( aa ) ) {
242  atoms.push_back( NamedAtomID( "2HD", res ) );
243  } else if ( name == "HD3" ) { //LYS, PRO, ARG no other has HD3
244  atoms.push_back( NamedAtomID( "1HD", res ) );
245 
246  } else if ( name == "HG1" && aa != aa_thr ) {
247  atoms.push_back( NamedAtomID( "1HG", res ) );
248  } else if ( name == "HG2" ) {
249  atoms.push_back( NamedAtomID( "2HG", res ) );
250  } else if ( name == "HG3" ) { //GLU, ARG, GLN, MET
251  atoms.push_back( NamedAtomID( "1HG", res ) );
252 
253  } else if ( name == "HA1" ) {
254  atoms.push_back( NamedAtomID( "1HA", res ) );
255  } else if ( name == "HA2" ) {
256  atoms.push_back( NamedAtomID( "2HA", res ) );
257  } else if ( name == "HA3" ) { //GLY
258  atoms.push_back( NamedAtomID( "1HA", res ) );
259 
260  } else if ( name == "HZ1" && aa == aa_lys ) {
261  atoms.push_back( NamedAtomID( "1HZ", res ) );
262  } else if ( name == "HZ2" && aa == aa_lys ) {
263  atoms.push_back( NamedAtomID( "2HZ", res ) );
264  } else if ( name == "HZ3" && aa == aa_lys ) {
265  atoms.push_back( NamedAtomID( "3HZ", res ) );
266  }
267  else if (( name == "HE1" || name == "HE2" || name=="HE3" ) && !is_aromatic( aa ) ) //trp and similar is already done
268  {
269  if ( ( name == "HE3" && aa != aa_met ) || name == "HE1" ) {
270  atoms.push_back( NamedAtomID( "1HE", res ) ); //e.g. LYS
271  } else if ( name == "HE2" ) {
272  atoms.push_back( NamedAtomID( "2HE", res ) );
273  // atoms.push_back( id::AtomID( pose.residue_type(res).atom_index(name.substr(2,1)+name.substr(0,2)), res ) );
274  } else if ( name == "HE3" ) {
275  atoms.push_back( NamedAtomID( "3HE", res ) );
276  }
277  }
278 
279  else if ( name == "HD11" ) {
280  atoms.push_back( NamedAtomID( "1HD1", res ) );
281  } else if ( name == "HD12" ) {
282  atoms.push_back( NamedAtomID( "2HD1", res ) );
283  } else if ( name == "HD13" ) {
284  atoms.push_back( NamedAtomID( "3HD1", res ) );
285  } else if ( name == "HD21" ) {
286  atoms.push_back( NamedAtomID( "1HD2", res ) );
287  } else if ( name == "HD22" ) {
288  atoms.push_back( NamedAtomID( "2HD2", res ) );
289  } else if ( name == "HD23" ) {
290  atoms.push_back( NamedAtomID( "3HD2", res ) );
291  } else if ( name == "HG11" ) {
292  atoms.push_back( NamedAtomID( "1HG1", res ) );
293  } else if ( name == "HG12" ) {
294  atoms.push_back( NamedAtomID( "2HG1", res ) );
295  } else if ( name == "HG13" ) {
296  if ( aa == aa_ile ) {
297  atoms.push_back( NamedAtomID( "1HG1", res ) );
298  } else {
299  atoms.push_back( NamedAtomID( "3HG1", res ) );
300  }
301  } else if ( name == "HG21" ) {
302  atoms.push_back( NamedAtomID( "1HG2", res ) );
303  } else if ( name == "HG22" ) {
304  atoms.push_back( NamedAtomID( "2HG2", res ) );
305  } else if ( name == "HG23" ) {
306  atoms.push_back( NamedAtomID( "3HG2", res ) );
307  } else if ( name == "HE11" ) {
308  atoms.push_back( NamedAtomID( "1HE1", res ) );
309  } else if ( name == "HE12" ) {
310  atoms.push_back( NamedAtomID( "2HE1", res ) );
311  } else if ( name == "HE13" ) {
312  atoms.push_back( NamedAtomID( "3HE1", res ) );
313  } else if ( name == "HE21" ) {
314  atoms.push_back( NamedAtomID( "1HE2", res ) );
315  } else if ( name == "HE22" ) {
316  atoms.push_back( NamedAtomID( "2HE2", res ) );
317  } else if ( name == "HH11" ) {
318  atoms.push_back( NamedAtomID( "1HH1", res ) );
319  } else if ( name == "HH12" ) {
320  atoms.push_back( NamedAtomID( "2HH1", res ) );
321  } else if ( name == "HH21" ) {
322  atoms.push_back( NamedAtomID( "1HH2", res ) );
323  } else if ( name == "HH22" ) {
324  atoms.push_back( NamedAtomID( "2HH2", res ) );
325  } else if ( (name == "HH1" || name == "QH1" ) && aa == aa_arg ) {
326  atoms.push_back( NamedAtomID( "1HH1", res ) );
327  atoms.push_back( NamedAtomID( "2HH1", res ) );
328  } else if ( (name == "HH2" || name == "QH2" ) && aa == aa_arg ) {
329  atoms.push_back( NamedAtomID( "1HH2", res ) );
330  atoms.push_back( NamedAtomID( "2HH2", res ) );
331  } else if ( (name == "HH" || name == "QQH" ) && aa == aa_arg ) {
332  atoms.push_back( NamedAtomID( "1HH1", res ) );
333  atoms.push_back( NamedAtomID( "2HH1", res ) );
334  atoms.push_back( NamedAtomID( "1HH2", res ) );
335  atoms.push_back( NamedAtomID( "2HH2", res ) );
336  } else {
337  atoms.push_back( NamedAtomID( name, res ) );
338  }
339 }
340 
341 
343  using core::chemical::AA;
344  using namespace core::chemical;
345  using core::id::NamedAtomID;
347  runtime_assert( res >= 1 || res <= pose.total_residue() );
348  AA const aa( pose.residue_type( res ).aa() );
349 
350  if ( ( name.substr(0,2) == "HD" ) && aa == aa_his ) {
351  atoms.push_back( named_atom_id_to_atom_id( NamedAtomID( "CD2", res ), pose ) );
352  return;
353  }
354  if ( ( name.substr(0,2) == "HE" ) && aa == aa_his ) {
355  atoms.push_back( named_atom_id_to_atom_id( NamedAtomID( "CE1", res ), pose ) );
356  return;
357  }
358 
359  ///now fix terminus problems
360  if ( name == "H" && res == 1 && pose.is_fullatom() ) {
361  atoms.push_back( named_atom_id_to_atom_id( NamedAtomID( "1H", res ), pose ) );
362  atoms.push_back( named_atom_id_to_atom_id( NamedAtomID( "2H", res ), pose ) );
363  atoms.push_back( named_atom_id_to_atom_id( NamedAtomID( "3H", res ), pose ) );
364  return;
365  }
366 
367  NamedAtoms named_atoms;
368  parse_NMR_name( name, res, aa, named_atoms );
369 
370  for ( NamedAtoms::const_iterator it= named_atoms.begin(); it!=named_atoms.end(); ++it ) {
371  atoms.push_back( named_atom_id_to_atom_id( *it, pose ) );
372  }
373  while ( atoms.size() && !atoms.back().valid() ) atoms.pop_back();
374 }
375 
376 
378  using core::chemical::AA;
379  using namespace core::chemical;
380  using core::id::NamedAtomID;
382  runtime_assert( res >= 1 || res <= pose.total_residue() );
383  AA const aa( pose.residue_type( res ).aa() );
384  //tr.Debug << "[ERROR]: name is " << name << " res " << res << " and name " << pose.residue( res ).name3() << std::endl;
385  //use named_atom_id_to_atom_id because it can throw an exception if atoms are missing instead of hard-exit...
386 
387  //put histidine protons onto the the respective Carbon atom... it is just unpredictable if the respective H is present...
388  if ( ( name.substr(0,2) == "HD" ) && aa == aa_his ) {
389  atoms.push_back( named_atom_id_to_atom_id( NamedAtomID( "CD2", res ), pose ) );
390  return;
391  }
392  if ( ( name.substr(0,2) == "HE" ) && aa == aa_his ) {
393  atoms.push_back( named_atom_id_to_atom_id( NamedAtomID( "CE1", res ), pose ) );
394  return;
395  }
396 
397  ///now fix all the problems with atomnames:
398  if ( name == "H" && res == 1 && pose.is_fullatom() ) {
399  atoms.push_back( named_atom_id_to_atom_id( NamedAtomID( "1H", res ), pose ) );
400  atoms.push_back( named_atom_id_to_atom_id( NamedAtomID( "2H", res ), pose ) );
401  atoms.push_back( named_atom_id_to_atom_id( NamedAtomID( "3H", res ), pose ) );
402  } else if ( (name.substr(0,2) == "QA" || name == "HA") && ( aa == aa_gly )) {
403  atoms.push_back( named_atom_id_to_atom_id( NamedAtomID( "1HA", res ), pose ) );
404  atoms.push_back( named_atom_id_to_atom_id( NamedAtomID( "2HA", res ), pose ) );
405  } else if ( ( name == "QB" || name == "HB" ) && (
406  aa == aa_ala
407  || aa == aa_leu
408  || aa == aa_ser
409  || aa == aa_asn
410  || aa == aa_gln
411  || aa == aa_pro
412  || aa == aa_lys
413  || aa == aa_cys
414  || aa == aa_asp
415  || aa == aa_glu
416  || aa == aa_arg
417  || aa == aa_tyr
418  || aa == aa_phe
419  || aa == aa_trp
420  || aa == aa_his
421  || aa == aa_met ) ) {
422  atoms.push_back( named_atom_id_to_atom_id( NamedAtomID( "1HB", res ), pose ) );
423  atoms.push_back( named_atom_id_to_atom_id( NamedAtomID( "2HB", res ), pose ) );
424  if ( aa == aa_ala ) atoms.push_back( named_atom_id_to_atom_id( NamedAtomID( "3HB", res ), pose ) );
425  } else if ( ( name == "QD1" || name == "HD1" ) && (
426  aa == aa_ile
427  || aa == aa_leu )) {
428  atoms.push_back( named_atom_id_to_atom_id( NamedAtomID( "1HD1", res ), pose ) );
429  atoms.push_back( named_atom_id_to_atom_id( NamedAtomID( "2HD1", res ), pose ) );
430  atoms.push_back( named_atom_id_to_atom_id( NamedAtomID( "3HD1", res ), pose ) );
431  } else if ( ( name == "QD2" || name == "HD2" ) && (
432  aa == aa_leu
433  ||aa == aa_asn )) {
434  atoms.push_back( named_atom_id_to_atom_id( NamedAtomID( "1HD2", res ), pose ) );
435  atoms.push_back( named_atom_id_to_atom_id( NamedAtomID( "2HD2", res ), pose ) );
436  if ( aa == aa_leu ) atoms.push_back( named_atom_id_to_atom_id( NamedAtomID( "3HD2", res ), pose ) );
437  } else if ( ( name == "QQD" || name == "QD" ) && aa == aa_leu ) {
438  atoms.push_back( named_atom_id_to_atom_id( NamedAtomID( "1HD2", res ), pose ) );
439  atoms.push_back( named_atom_id_to_atom_id( NamedAtomID( "2HD2", res ), pose ) );
440  atoms.push_back( named_atom_id_to_atom_id( NamedAtomID( "3HD2", res ), pose ) );
441  atoms.push_back( named_atom_id_to_atom_id( NamedAtomID( "1HD1", res ), pose ) );
442  atoms.push_back( named_atom_id_to_atom_id( NamedAtomID( "2HD1", res ), pose ) );
443  atoms.push_back( named_atom_id_to_atom_id( NamedAtomID( "3HD1", res ), pose ) );
444  } else if ( ( name == "QD" || name == "HD" ) && (
445  aa == aa_pro
446  || aa == aa_lys
447  || aa == aa_arg
448  || aa == aa_tyr
449  || aa == aa_phe
450  || aa == aa_his ) ) {
451  if ( aa == aa_arg || aa == aa_lys || aa == aa_pro ) {
452  atoms.push_back( named_atom_id_to_atom_id( NamedAtomID( "1HD", res ), pose ) );
453  atoms.push_back( named_atom_id_to_atom_id( NamedAtomID( "2HD", res ), pose ) );
454  } else { // tyr, phe, his (his doesn't get down here... )
455  atoms.push_back( named_atom_id_to_atom_id( NamedAtomID( "HD1", res ), pose ) );
456  atoms.push_back( named_atom_id_to_atom_id( NamedAtomID( "HD2", res ), pose ) );
457  }
458  } else if ( ( name == "QE" || name == "HE" ) && (
459  aa == aa_tyr
460  || aa == aa_phe
461  || aa == aa_trp
462  || aa == aa_met
463  || aa == aa_lys ) ){
464  if ( aa == aa_phe || aa == aa_tyr ) {
465  atoms.push_back( named_atom_id_to_atom_id( NamedAtomID( "HE1", res ), pose ) );
466  atoms.push_back( named_atom_id_to_atom_id( NamedAtomID( "HE2", res ), pose ) );
467  } else if ( aa == aa_trp ) {
468  atoms.push_back( named_atom_id_to_atom_id( NamedAtomID( "HE1", res ), pose ) );
469  atoms.push_back( named_atom_id_to_atom_id( NamedAtomID( "HE3", res ), pose ) );
470  } else if ( aa == aa_met || aa == aa_lys ) { //MET LYS
471  atoms.push_back( named_atom_id_to_atom_id( NamedAtomID( "1HE", res ), pose ) );
472  atoms.push_back( named_atom_id_to_atom_id( NamedAtomID( "2HE", res ), pose ) );
473  if ( aa == aa_met ) {
474  atoms.push_back( named_atom_id_to_atom_id( NamedAtomID( "3HE", res ), pose ) );
475  }
476  } //QE MET LYS
477  } else if ( ( name == "QG" || name == "HG" ) && (
478  aa == aa_met
479  || aa == aa_gln
480  || aa == aa_pro
481  || aa == aa_lys
482  || aa == aa_glu
483  || aa == aa_arg )) {
484  atoms.push_back( named_atom_id_to_atom_id( NamedAtomID( "1HG", res ), pose ) );
485  atoms.push_back( named_atom_id_to_atom_id( NamedAtomID( "2HG", res ), pose ) );
486  // atoms.push_back( named_atom_id_to_atom_id( NamedAtomID( "3HE", res ), pose ) );
487  } else if (( name == "QG2" || name == "HG2" ) && (
488  aa == aa_ile
489  || aa == aa_thr
490  || aa == aa_val ) ) {
491  atoms.push_back( named_atom_id_to_atom_id( NamedAtomID( "1HG2", res ), pose ) );
492  atoms.push_back( named_atom_id_to_atom_id( NamedAtomID( "2HG2", res ), pose ) );
493  atoms.push_back( named_atom_id_to_atom_id( NamedAtomID( "3HG2", res ), pose ) );
494  } else if ( ( name == "QQG" || name == "HG" ) && (
495  aa == aa_ile
496  || aa == aa_val ) ) {
497  atoms.push_back( named_atom_id_to_atom_id( NamedAtomID( "1HG2", res ), pose ) );
498  atoms.push_back( named_atom_id_to_atom_id( NamedAtomID( "2HG2", res ), pose ) );
499  atoms.push_back( named_atom_id_to_atom_id( NamedAtomID( "3HG2", res ), pose ) );
500  atoms.push_back( named_atom_id_to_atom_id( NamedAtomID( "1HG1", res ), pose ) );
501  atoms.push_back( named_atom_id_to_atom_id( NamedAtomID( "2HG1", res ), pose ) );
502  if ( aa != aa_ile ) atoms.push_back( named_atom_id_to_atom_id( NamedAtomID( "3HG1", res ), pose ) );
503  } else if (( name == "QG1" || name == "HG1" ) && (
504  aa == aa_ile
505  || aa == aa_val ) ) {
506  atoms.push_back( named_atom_id_to_atom_id( NamedAtomID( "1HG1", res ), pose ) );
507  atoms.push_back( named_atom_id_to_atom_id( NamedAtomID( "2HG1", res ), pose ) );
508  if ( aa != aa_ile ) atoms.push_back( named_atom_id_to_atom_id( NamedAtomID( "3HG1", res ), pose ) );
509  } else if (( name == "QE2" || name == "HE2" || name =="HE" ) && aa == aa_gln ) {
510  atoms.push_back( named_atom_id_to_atom_id( NamedAtomID( "1HE2", res ), pose ) );
511  atoms.push_back( named_atom_id_to_atom_id( NamedAtomID( "2HE2", res ), pose ) );
512  } else if (( name == "HZ" || name == "QZ" ) && ( aa == aa_trp || aa == aa_lys ) ) {
513  if ( aa == aa_lys ) {
514  atoms.push_back( named_atom_id_to_atom_id( NamedAtomID( "1HZ", res ), pose ) );
515  atoms.push_back( named_atom_id_to_atom_id( NamedAtomID( "2HZ", res ), pose ) );
516  atoms.push_back( named_atom_id_to_atom_id( NamedAtomID( "3HZ", res ), pose ) );
517  } else { //aa==trp
518  atoms.push_back( named_atom_id_to_atom_id( NamedAtomID( "HZ2", res ), pose ) );
519  atoms.push_back( named_atom_id_to_atom_id( NamedAtomID( "HZ3", res ), pose ) );
520  }
521  } else if ( name == "HB1" ) {
522  atoms.push_back( named_atom_id_to_atom_id( NamedAtomID( "1HB", res ), pose ) );
523  } else if ( name == "HB2" ) {
524  atoms.push_back( named_atom_id_to_atom_id( NamedAtomID( "2HB", res ), pose ) );
525  } else if ( name == "HB3" ) {
526  if ( aa != aa_ala ) {
527  atoms.push_back( named_atom_id_to_atom_id( NamedAtomID( "1HB", res ), pose ) ); //yeah they call it 2HB and 3HB...
528  } else {
529  atoms.push_back( named_atom_id_to_atom_id( NamedAtomID( "3HB", res ), pose ) );
530  }
531  } else if ( name == "HD1" && !is_aromatic( pose, res ) ) {
532  atoms.push_back( named_atom_id_to_atom_id( NamedAtomID( "1HD", res ), pose ) );
533  } else if ( name == "HD2" && !is_aromatic( pose, res ) ) {
534  atoms.push_back( named_atom_id_to_atom_id( NamedAtomID( "2HD", res ), pose ) );
535  } else if ( name == "HD3" ) { //LYS, PRO, ARG no other has HD3
536  atoms.push_back( named_atom_id_to_atom_id( NamedAtomID( "1HD", res ), pose ) );
537 
538  } else if ( name == "HG1" && aa != aa_thr ) {
539  atoms.push_back( named_atom_id_to_atom_id( NamedAtomID( "1HG", res ), pose ) );
540  } else if ( name == "HG2" ) {
541  atoms.push_back( named_atom_id_to_atom_id( NamedAtomID( "2HG", res ), pose ) );
542  } else if ( name == "HG3" ) { //GLU, ARG, GLN, MET
543  atoms.push_back( named_atom_id_to_atom_id( NamedAtomID( "1HG", res ), pose ) );
544 
545  } else if ( name == "HA1" ) {
546  atoms.push_back( named_atom_id_to_atom_id( NamedAtomID( "1HA", res ), pose ) );
547  } else if ( name == "HA2" ) {
548  atoms.push_back( named_atom_id_to_atom_id( NamedAtomID( "2HA", res ), pose ) );
549  } else if ( name == "HA3" ) { //GLY
550  atoms.push_back( named_atom_id_to_atom_id( NamedAtomID( "1HA", res ), pose ) );
551  }
552 
553  else if (( name == "HE1" || name == "HE2" || name=="HE3" ) && !is_aromatic( pose, res ) )
554  {
555  if ( name == "HE3" && aa != aa_met ) {
556  atoms.push_back( named_atom_id_to_atom_id( NamedAtomID( "1HE", res ), pose ) ); //e.g. LYS
557  } else {
558  atoms.push_back( id::AtomID( pose.residue_type(res).atom_index(name.substr(2,1)+name.substr(0,2)), res ) );
559  }
560  }
561 
562  else if ( name == "HD11" ) {
563  atoms.push_back( named_atom_id_to_atom_id( NamedAtomID( "1HD1", res ), pose ) );
564  } else if ( name == "HD12" ) {
565  atoms.push_back( named_atom_id_to_atom_id( NamedAtomID( "2HD1", res ), pose ) );
566  } else if ( name == "HD13" ) {
567  atoms.push_back( named_atom_id_to_atom_id( NamedAtomID( "3HD1", res ), pose ) );
568  } else if ( name == "HD21" ) {
569  atoms.push_back( named_atom_id_to_atom_id( NamedAtomID( "1HD2", res ), pose ) );
570  } else if ( name == "HD22" ) {
571  atoms.push_back( named_atom_id_to_atom_id( NamedAtomID( "2HD2", res ), pose ) );
572  } else if ( name == "HD23" ) {
573  atoms.push_back( named_atom_id_to_atom_id( NamedAtomID( "3HD2", res ), pose ) );
574  } else if ( name == "HG11" ) {
575  atoms.push_back( named_atom_id_to_atom_id( NamedAtomID( "1HG1", res ), pose ) );
576  } else if ( name == "HG12" ) {
577  atoms.push_back( named_atom_id_to_atom_id( NamedAtomID( "2HG1", res ), pose ) );
578  } else if ( name == "HG13" ) {
579  if ( aa == aa_ile ) {
580  atoms.push_back( named_atom_id_to_atom_id( NamedAtomID( "1HG1", res ), pose ) );
581  } else {
582  atoms.push_back( named_atom_id_to_atom_id( NamedAtomID( "3HG1", res ), pose ) );
583  }
584  } else if ( name == "HG21" ) {
585  atoms.push_back( named_atom_id_to_atom_id( NamedAtomID( "1HG2", res ), pose ) );
586  } else if ( name == "HG22" ) {
587  atoms.push_back( named_atom_id_to_atom_id( NamedAtomID( "2HG2", res ), pose ) );
588  } else if ( name == "HG23" ) {
589  atoms.push_back( named_atom_id_to_atom_id( NamedAtomID( "3HG2", res ), pose ) );
590  } else if ( name == "HE11" ) {
591  atoms.push_back( named_atom_id_to_atom_id( NamedAtomID( "1HE1", res ), pose ) );
592  } else if ( name == "HE12" ) {
593  atoms.push_back( named_atom_id_to_atom_id( NamedAtomID( "2HE1", res ), pose ) );
594  } else if ( name == "HE13" ) {
595  atoms.push_back( named_atom_id_to_atom_id( NamedAtomID( "3HE1", res ), pose ) );
596  } else if ( name == "HE21" ) {
597  atoms.push_back( named_atom_id_to_atom_id( NamedAtomID( "1HE2", res ), pose ) );
598  } else if ( name == "HE22" ) {
599  atoms.push_back( named_atom_id_to_atom_id( NamedAtomID( "2HE2", res ), pose ) );
600  } else if ( name == "HH11" ) {
601  atoms.push_back( named_atom_id_to_atom_id( NamedAtomID( "1HH1", res ), pose ) );
602  } else if ( name == "HH12" ) {
603  atoms.push_back( named_atom_id_to_atom_id( NamedAtomID( "2HH1", res ), pose ) );
604  } else if ( name == "HH21" ) {
605  atoms.push_back( named_atom_id_to_atom_id( NamedAtomID( "1HH2", res ), pose ) );
606  } else if ( name == "HH22" ) {
607  atoms.push_back( named_atom_id_to_atom_id( NamedAtomID( "2HH2", res ), pose ) );
608  } else if ( (name == "HH1" || name == "QH1" ) && aa == aa_arg ) {
609  atoms.push_back( named_atom_id_to_atom_id( NamedAtomID( "1HH1", res ), pose ) );
610  atoms.push_back( named_atom_id_to_atom_id( NamedAtomID( "2HH1", res ), pose ) );
611  } else if ( (name == "HH2" || name == "QH2" ) && aa == aa_arg ) {
612  atoms.push_back( named_atom_id_to_atom_id( NamedAtomID( "1HH2", res ), pose ) );
613  atoms.push_back( named_atom_id_to_atom_id( NamedAtomID( "2HH2", res ), pose ) );
614  } else if ( (name == "HH" || name == "QQH" ) && aa == aa_arg ) {
615  atoms.push_back( named_atom_id_to_atom_id( NamedAtomID( "1HH1", res ), pose ) );
616  atoms.push_back( named_atom_id_to_atom_id( NamedAtomID( "2HH1", res ), pose ) );
617  atoms.push_back( named_atom_id_to_atom_id( NamedAtomID( "1HH2", res ), pose ) );
618  atoms.push_back( named_atom_id_to_atom_id( NamedAtomID( "2HH2", res ), pose ) );
619  } else {
620  tr.Trace << "adding " << id::NamedAtomID( name, res ) << " "
621  << pose.residue_type( res ).name3() << std::endl;
622  atoms.push_back( named_atom_id_to_atom_id( NamedAtomID( name, res ), pose ) );
623  tr.Trace << "as atom: " << atoms.back();
624  }
625 
626  while ( atoms.size() && !atoms.back().valid() ) atoms.pop_back();
627 }
628 
630  basic::ProfileThis doit( basic::NOESY_ASSIGN_REQUIRES_CB_MAPPING );
631  using core::chemical::AA;
632  using namespace core::chemical;
633  Size ct_backbone( 0 );
634  for ( Size i=1; i<=atoms.size(); ++i ) {
635  chemical::ResidueType const& res_type( pose.residue_type( atoms[ i ].rsd() ) );
636  ct_backbone += res_type.atom_is_backbone( atoms[ i ].atomno() );
637  }
638  chemical::ResidueType const& res_type( pose.residue_type( atoms[ 1 ].rsd() ) );
639  ct_backbone -= ( ct_backbone == 1 && res_type.aa() != aa_gly && res_type.atom_index( "CB" ) == atoms[ 1 ].atomno() );
640  if ( ct_backbone == 0 ) return true;
641  if ( ct_backbone == atoms.size() ) return false;
642  runtime_assert( 0 ); //this should not happen, as there should only be methyl-Hs combined into one constraint
643  return false;
644 }
645 
646 
647  ///
648 
650  basic::ProfileThis doit( basic::NOESY_ASSIGN_NMR_STRING );
651  atom_str = " BOGUS ";
652  if ( atoms.size() == 1 ) {
653  atom_str = pose.residue( atoms[ 1 ].rsd() ).atom_name( atoms[ 1 ].atomno() );
654  } else if ( atoms.size() == 2 && atoms[ 1 ].rsd() == atoms[ 2 ].rsd()
655  && pose.residue( atoms[ 1 ].rsd() ).atom_name( atoms[ 1 ].atomno() ).substr( 1, 2 ) == "HB"
656  && pose.residue( atoms[ 2 ].rsd() ).atom_name( atoms[ 2 ].atomno() ).substr( 1, 2 ) == "HB" ) {
657  atom_str = "QB";
658  } else if ( atoms.size() == 3
659  && atoms[ 1 ].rsd() == atoms[ 2 ].rsd() && atoms[ 1 ].rsd() == atoms[ 3 ].rsd() ) {
660  std::string methyl = pose.residue( atoms[ 1 ].rsd() ).atom_name( atoms[ 1 ].atomno() ).substr( 1, 3 );
661  if ( pose.residue( atoms[ 2 ].rsd() ).atom_name( atoms[ 2 ].atomno() ).substr( 1, 3 ) == methyl
662  && pose.residue( atoms[ 3 ].rsd() ).atom_name( atoms[ 3 ].atomno() ).substr( 1, 3 ) == methyl ) {
663  if ( atoms[ 1 ].rsd() == 1 ) { //1H, 2H, 3H Nterminus
664  atom_str = "H";
665  } else {
666  atom_str = "Q"+methyl.substr(1);
667  }
668  } else {
669  atom_str = " untranslatable-3-atom-combi";
670  tr.Trace << "could not translate: "
671  << pose.residue( atoms[ 1 ].rsd() ).atom_name( atoms[ 1 ].atomno() ) << " "
672  << pose.residue( atoms[ 2 ].rsd() ).atom_name( atoms[ 2 ].atomno() ) << " "
673  << pose.residue( atoms[ 3 ].rsd() ).atom_name( atoms[ 3 ].atomno() ) << std::endl;
674  }
675  } else if ( atoms.size() == 2 //QE or QE2 or QD/PHE
676  && atoms[ 1 ].rsd() == atoms[ 2 ].rsd() ) {
677  if ( pose.residue( atoms[ 1 ].rsd() ).atom_name( atoms[ 1 ].atomno() ).substr(0,2)==" H" ) {
678  atom_str = "Q"+pose.residue( atoms[ 1 ].rsd() ).atom_name( atoms[ 1 ].atomno() ).substr(2,1);
679  } else {
680  std::string methyl = pose.residue( atoms[ 1 ].rsd() ).atom_name( atoms[ 1 ].atomno() ).substr( 1, 3 );
681  if ( pose.residue( atoms[ 2 ].rsd() ).atom_name( atoms[ 2 ].atomno() ).substr( 1, 3 ) == methyl ) {
682  atom_str = "Q"+methyl.substr(1);
683  } else {
684  atom_str = " untranslatable-2-methyl-atom-combi ";
685  tr.Trace << "could not translate: " << pose.residue( atoms[ 1 ].rsd() ).atom_name( atoms[ 1 ].atomno() ) << " " << pose.residue( atoms[ 2 ].rsd() ).atom_name( atoms[ 2 ].atomno() ) << std::endl;
686  }
687  }
688  } else if ( atoms.size() == 6
689  && atoms[ 1 ].rsd() == atoms[ 2 ].rsd() && atoms[ 1 ].rsd() == atoms[ 3 ].rsd()
690  && atoms[ 1 ].rsd() == atoms[ 4 ].rsd() && atoms[ 1 ].rsd() == atoms[ 5 ].rsd()
691  && atoms[ 1 ].rsd() == atoms[ 6 ].rsd() ) {
692  std::string methyl = pose.residue( atoms[ 1 ].rsd() ).atom_name( atoms[ 1 ].atomno() ).substr( 1, 2 );
693  if ( pose.residue( atoms[ 2 ].rsd() ).atom_name( atoms[ 2 ].atomno() ).substr( 1, 2 ) == methyl
694  && pose.residue( atoms[ 3 ].rsd() ).atom_name( atoms[ 3 ].atomno() ).substr( 1, 2 ) == methyl ) {
695  atom_str = "QQ"+methyl.substr(1);
696  } else {
697  atom_str = " untranslatable-6-atom-combi ";
698  tr.Trace << "could not translate: "
699  << pose.residue( atoms[ 1 ].rsd() ).atom_name( atoms[ 1 ].atomno() ) << " "
700  << pose.residue( atoms[ 2 ].rsd() ).atom_name( atoms[ 2 ].atomno() ) << " "
701  << pose.residue( atoms[ 3 ].rsd() ).atom_name( atoms[ 3 ].atomno() ) << " "
702  << pose.residue( atoms[ 4 ].rsd() ).atom_name( atoms[ 4 ].atomno() ) << " "
703  << pose.residue( atoms[ 5 ].rsd() ).atom_name( atoms[ 5 ].atomno() ) << " "
704  << pose.residue( atoms[ 6 ].rsd() ).atom_name( atoms[ 6 ].atomno() ) << std::endl;
705  }
706  }
707  std::istringstream eat_white_space( atom_str );
708  eat_white_space >> atom_str;
709 }
710 
711 void AmbiguousNMRDistanceConstraint::show_def( std::ostream& out, pose::Pose const& pose ) const {
712  std::string def_atoms1;
713  std::string def_atoms2;
714  combine_NMR_atom_string( atoms1_, def_atoms1, pose);
715  combine_NMR_atom_string( atoms2_, def_atoms2, pose);
716  out << type() << " "
717  << def_atoms1 << " " << atoms1_[ 1 ].rsd() << " "
718  << def_atoms2 << " " << atoms2_[ 1 ].rsd() << " ";
719  if ( func_ ) func_->show_definition( out );
720  else out << std::endl;
721 }
722 
723 ConstraintOP AmbiguousNMRDistanceConstraint::map_to_CEN( pose::Pose const& fa_pose, pose::Pose const& centroid, core::Size &mapped, std::string const& map_atom ) const {
724  bool still_ambiguous( false );
725  std::string atom1,atom2;
726  basic::ProfileThis doit( basic::NOESY_ASSIGN_MAP2CB );
727  using core::id::NamedAtomID;
729  mapped = 2;
730  if ( requires_CB_mapping( atoms1_, fa_pose) ) atom1 = map_atom;
731  else {
732  --mapped;
733  combine_NMR_atom_string( atoms1_, atom1, fa_pose );
734  still_ambiguous |= ( atoms1_.size() > 1 );
735  }
736  if ( requires_CB_mapping( atoms2_, fa_pose) ) atom2 = map_atom;
737  else {
738  --mapped;
739  combine_NMR_atom_string( atoms2_, atom2, fa_pose );
740  still_ambiguous |= ( atoms2_.size() > 1 );
741  }
742  tr.Debug << "map_to_CEN: " << atom1 << " " << resid( 1 ) << " --> " << atom2 << " " << resid( 2 ) << (still_ambiguous ? " ambiguous " : " straight ") << std::endl;
743  { //scope for profile
744  basic::ProfileThis doit( basic::NOESY_ASSIGN_MAP2CB_NEW );
745  if ( still_ambiguous ) {
746  return new AmbiguousNMRDistanceConstraint( id::NamedAtomID( atom1, resid( 1 ) ), id::NamedAtomID( atom2, resid( 2 ) ), centroid, func_, score_type() );
747  } else {
748  return new AtomPairConstraint( named_atom_id_to_atom_id( NamedAtomID( atom1, resid( 1 ) ), centroid ),
749  named_atom_id_to_atom_id( NamedAtomID( atom2, resid( 2 ) ), centroid ), func_, score_type() );
750  }
751  } //scope
752  return NULL; // cannot be reached
753 }
754 
755 Real
757 
758  // tr.Trace << "compute distance for ";
759  // if ( tr.Trace.visible() ) show_def( tr.Trace, pose );
760  // tr.Trace << std::endl;
761 
762  //conformation::Conformation const & conformation( pose.conformation() );
763  return dist( ConformationXYZ( pose.conformation() ) );
764  /*
765  Real cum_dist( 0.0 );
766  for ( Atoms::const_iterator it1 = atoms1_.begin(); it1 != atoms1_.end(); ++it1 ) {
767  for (Atoms::const_iterator it2 = atoms2_.begin(); it2 != atoms2_.end(); ++it2 ) {
768  Vector const & xyz1( conformation.xyz( *it1 ) ), xyz2( conformation.xyz( *it2 ) );
769  Vector const f2( xyz1 - xyz2 );
770  Real const dist( f2.length() );
771  Real const inv_dist( 1.0/dist );
772  Real const inv_dist2( inv_dist*inv_dist );
773  Real const inv_dist6( inv_dist2 * inv_dist2 * inv_dist2 );
774  cum_dist += inv_dist6;
775  tr.Trace << *it1 << " " << *it2 << " " << dist << " " << pow(cum_dist, -1.0/6) << std::endl;
776  }
777  }
778  tr.Trace << "finished distance" << std::endl;
779  return pow(cum_dist, -1.0/6 );
780  */
781 }
782 
783 Real
785  XYZ_Func const & xyz
786 ) const
787 {
788  return pow( inv_dist6( xyz ), -1.0/6 );
789 }
790 
791 Real
793  XYZ_Func const & xyz
794 ) const
795 {
796  Real cum_dist( 0.0 );
797  for ( Atoms::const_iterator it1 = atoms1_.begin(); it1 != atoms1_.end(); ++it1 ) {
798  for (Atoms::const_iterator it2 = atoms2_.begin(); it2 != atoms2_.end(); ++it2 ) {
799  Vector const & xyz1( xyz( *it1 ) ), xyz2( xyz( *it2 ) );
800  Vector const f2( xyz1 - xyz2 );
801  Real const dist( f2.length() );
802  Real const inv_dist( 1.0/dist );
803  Real const inv_dist2( inv_dist*inv_dist );
804  Real const inv_dist6( inv_dist2 * inv_dist2 * inv_dist2 );
805  cum_dist += inv_dist6;
806  // tr.Trace << *it1 << " " << *it2 << " " << dist << " " << pow(cum_dist, -1.0/6) << std::endl;
807  }
808  }
809  // tr.Trace << "finished distance" << std::endl;
810  return cum_dist;
811 }
812 
813 /*Real
814 AmbiguousNMRDistanceConstraint::dist( conformation::Conformation const & conformation ) const {
815  return pow( inv_dist6( conformation ), -1.0/6 );
816 }*/
817 
818 /*Real AmbiguousNMRDistanceConstraint::inv_dist6( XYZ_Func const & xyz ) const {
819  Real cum_dist( 0.0 );
820  for ( Atoms::const_iterator it1 = atoms1_.begin(); it1 != atoms1_.end(); ++it1 ) {
821  for (Atoms::const_iterator it2 = atoms2_.begin(); it2 != atoms2_.end(); ++it2 ) {
822  Vector const & xyz1( xyz( *it1 ) ), xyz2( xyz( *it2 ) );
823  Vector const f2( xyz1 - xyz2 );
824  Real const dist( f2.length() );
825  Real const inv_dist( 1.0/dist );
826  Real const inv_dist2( inv_dist*inv_dist );
827  cum_dist += inv_dist2 * inv_dist2 * inv_dist2;
828  }
829  }
830  return cum_dist;
831 }*/
832 
833 void AmbiguousNMRDistanceConstraint::score( XYZ_Func const & xyz, EnergyMap const &, EnergyMap & emap ) const {
834  Real eff_dist = pow( inv_dist6( xyz ), -1.0/6 );
835  emap[ this->score_type() ] += func( eff_dist );
836 }
837 
839  std::ostream& out,
840  pose::Pose const& pose,
841  Size verbose_level,
842  Real threshold
843 ) const {
844 
845  if ( verbose_level > 80 ) {
846  out << "\nAmbiguousNMRDistanceConstraint ( "
847  << pose.residue_type(atoms1_.front().rsd() ).atom_name( atoms1_.front().atomno() ) << " : "
848  << atoms1_.front().rsd() << " - "
849  << pose.residue_type(atoms2_.front().rsd() ).atom_name( atoms2_.front().atomno() ) << " : "
850  << atoms2_.front().rsd() << " ) ";
851  }
852 // if ( verbose_level > 120 ) { //don't ask but I had a really weird bug to track down!
853 // conformation::Conformation const & conformation( pose.conformation() );
854 // Vector const & xyz1( conformation.xyz( atom1_ ) ), xyz2( conformation.xyz( atom2_ ) );
855 // out << "\ncoords1: " << xyz1[ 1 ] << " " << xyz1[ 2 ] << " " << xyz1[ 3 ] << " --- ";
856 // out << "coords1: " << xyz2[ 1 ] << " " << xyz2[ 2 ] << " " << xyz2[ 3 ] << "\n";
857 // }
858 
859  return func_->show_violations( out, dist( pose ), verbose_level, threshold );
860 }
861 
862 // atom deriv
863 void
865  AtomID const & atom,
866  XYZ_Func const & xyz,
867  Vector & F1,
868  Vector & F2,
869  EnergyMap const & weights
870 ) const
871 {
872 
873  bool not_methyl_1 = std::find( atoms1_.begin() , atoms1_.end() , atom ) == atoms1_.end();
874  bool not_methyl_2 = std::find( atoms2_.begin() , atoms2_.end() , atom ) == atoms2_.end();
875  if ( not_methyl_1 && not_methyl_2 ) {
876  // tr.Trace << "atom " << atom << " not found " << std::endl;
877  return;
878  }
879 
880 // if ( !not_methyl_1 && !not_methyl_2 ) {
881 // tr.Error << "atom " << atom << " has been found in both atom arrays of AmbiguousNMRDistanceConstraint " << std::endl;
882 // }
883 
884  Real eff_dist = dist( xyz );
885  Real out_wderiv( weights[ this->score_type() ] * dfunc( eff_dist ));
886  Real in_deriv = -1.0/6.0 * pow( eff_dist, 7.0 );
887  // tr.Trace << "deriv for atom " << atom << eff_dist << " " << out_wderiv << " " << in_deriv << std::endl;
888 
889  Atoms const& the_other_atoms( not_methyl_1 ? atoms1_ : atoms2_ );
890  // tr.Trace << "the_other_atoms: " << the_other_atoms.size() << " " << the_other_atoms.front() << std::endl;
891  for (Atoms::const_iterator it = the_other_atoms.begin(); it != the_other_atoms.end(); ++it ) {
892  AtomID other_atom = *it;
893  // tr.Trace << "contribution from " << other_atom << " to " << atom << std::endl;
894  Real rdist(0.0);
895  Vector f1(0.0), f2(0.0);
896  numeric::deriv::distance_f1_f2_deriv( xyz( atom ), xyz( other_atom ), rdist, f1, f2 );
897  Real wderiv = -6.0*pow(rdist,-7.0) * in_deriv * out_wderiv ;
898  // tr.Trace << "wderiv " << wderiv << std::endl;
899  F1 += wderiv * f1;
900  F2 += wderiv * f2;
901 
902  }
903 
904 }
905 
908 {
909  // runtime_assert( 0 );
910  Atoms ids1, ids2;
911  for ( Atoms::const_iterator it = atoms1_.begin(); it != atoms1_.end(); ++it ) {
912  id::AtomID atom( it->atomno(), smap[ it->rsd() ] );
913  if ( !atom.valid() ) return NULL;
914  ids1.push_back( atom );
915  }
916  for ( Atoms::const_iterator it = atoms2_.begin(); it != atoms2_.end(); ++it ) {
917  id::AtomID atom( it->atomno(), smap[ it->rsd() ] );
918  if ( !atom.valid() ) return NULL;
919  ids2.push_back( atom );
920  }
921  return new AmbiguousNMRDistanceConstraint( ids1, ids2, func_, score_type() );
922 }
923 
924 
925 
927  id::NamedAtomID const & a1, //digests names like "QG1"
928  id::NamedAtomID const & a2,
929  core::pose::Pose const& pose,
930  FuncOP func,
931  ScoreType scoretype
932 ) : Constraint( scoretype ),
933  func_( func )
934 {
935  parse_NMR_name( a1.atom(), a1.rsd(), atoms1_, pose );
936  parse_NMR_name( a2.atom(), a2.rsd(), atoms2_, pose );
937  // } catch ( EXCN_AtomNotFound &excn ) {
938 // tr.Error << "AmbiguousNMRDistanceConstraint cannot parse input atoms: " << excn << std::endl;
939 // atoms1_.clear();
940 // atoms2_.clear();
941 // }
942 
943  if ( atoms1_.size() == 0 || atoms2_.size() == 0 ) {
944  tr.Warning << "Error constructing from atoms: read in atom names("
945  << a1.atom() << "," << a2.atom() << "), " << std::endl;
946  }
947 }
948 
949 ///@details one line definition "AmbiguousNMRDistance atom1 res1 atom2 res2 function_type function_definition"
950 void
952  std::istream & data,
953  core::pose::Pose const & pose,
954  FuncFactory const & func_factory
955 ) {
956  Size res1, res2;
957  std::string tempres1, tempres2;
958  std::string name1, name2;
959  std::string func_type;
961 
962  data
963  >> name1 >> tempres1
964  >> name2 >> tempres2
965  >> func_type;
966 
967  ConstraintIO::parse_residue( pose, tempres1, res1 );
968  ConstraintIO::parse_residue( pose, tempres2, res2 );
969 
970  tr.Debug << "read: " << name1 << " " << name2 << " " << res1 << " " << res2 << " func: " << func_type << std::endl;
971  if ( res1 > pose.total_residue() || res2 > pose.total_residue() ) {
972  tr.Warning << "ignored constraint (residue number to high for pose: " << pose.total_residue() << " !)"
973  << name1 << " " << name2 << " " << res1 << " " << res2 << std::endl;
974  data.setstate( std::ios_base::failbit );
975  return;
976  }
977 
978  parse_NMR_name( name1, res1, atoms1_, pose );
979  parse_NMR_name( name2, res2, atoms2_, pose );
980 
981  if ( atoms1_.size() == 0 || atoms2_.size() == 0 ) {
982  tr.Warning << "Error reading atoms: read in atom names("
983  << name1 << "," << name2 << "), " << std::endl;
984  // << "and found AtomIDs (" << atom1_ << "," << atom2_ << ")" << std::endl;
985  data.setstate( std::ios_base::failbit );
986  return;
987  }
988 
989  func_ = func_factory.new_func( func_type );
990  func_->read_data( data );
991 
992  if ( data.good() ) {
993  //chu skip the rest of line since this is a single line defintion.
994  while( data.good() && (data.get() != '\n') ) {}
995  if ( !data.good() ) data.setstate( std::ios_base::eofbit );
996  }
997 
998  if ( tr.Debug.visible() ) {
999  func_->show_definition( tr.Debug );
1000  tr.Debug << std::endl;
1001  }
1002 } // read_def
1003 
1004 core::Size
1006  return sp.dist( resid( 1 ), resid( 2 ) );
1007 }
1008 
1009 } // constraints
1010 } // scoring
1011 } // core