Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PatchOperation.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 src/core/chemical/Residue_.cc
11 /// @brief implementation class for abstract class Residue if you want to see what it actually does, look at comments in Patch.cc
12 /// @author Phil Bradley
13 // Unit headers
15 #include <core/chemical/Atom.hh>
16 
17 // Package Headers
18 
19 
20 // ObjexxFCL headers
21 
22 // Numeric headers
23 #include <numeric/conversions.hh>
24 
25 // Utility headers
26 #include <basic/Tracer.hh>
27 
28 #include <utility/vector1.hh>
29 
30 
31 // Commented by inclean daemon #include <ObjexxFCL/string.functions.hh>
32 
33 // C++ headers
34 // Commented by inclean daemon #include <sstream>
35 
36 namespace core {
37 namespace chemical {
38 
39 /// @details Auto-generated virtual destructor
41 
42 static basic::Tracer tr("core.chemical");
43 
44 bool
46 {
47  if ( !rsd.has( atom_name_ ) ) {
48  TR_PatchOperations.Debug << "SetAtomicCharge::apply failed: " << rsd.name() << " is missing atom: " << atom_name_ << std::endl;
49  return true; // failure
50  } else {
51  //std::cout << "SetAtomicCharge::apply: " << atom_name_ << ' ' << charge_ << std::endl;
52  rsd.atom( atom_name_ ).charge( charge_ );
53  }
54  return false;
55 }
56 
57 /// helper function
60 {
61  std::string const nconn_tag( "%NCONN" );
62  Size pos( name.find( nconn_tag ) );
63  if ( pos < name.size() ) {
64  //std::cout << "name before replace: " << name << std::endl;
65  name.replace( pos, nconn_tag.size(), ObjexxFCL::string_of( rsd.n_residue_connections() ) );
66  //std::cout << "name after replace: " << name << std::endl;
67  }
68  return name;
69 
70 }
71 
72 bool
74 {
75  //std::cout << "SetICoor::apply: " << atom_ << ' ' << stub1_ << ' ' << stub2_ << ' ' << stub3_ <<
76  // std::endl;
77  std::string const atom ( expand_icoor_atom_name( atom_ , rsd ) );
78  std::string const stub1( expand_icoor_atom_name( stub1_, rsd ) );
79  std::string const stub2( expand_icoor_atom_name( stub2_, rsd ) );
80  std::string const stub3( expand_icoor_atom_name( stub3_, rsd ) );
81  // bool const rebuild_icoor_xyz( ICoorAtomID( stub1, rsd ).is_internal() &&
82  // ICoorAtomID( stub2, rsd ).is_internal() &&
83  // ICoorAtomID( stub3, rsd ).is_internal() );
84  bool const rebuild_icoor_xyz( true );
85  rsd.set_icoor( atom, phi_, theta_, d_, stub1, stub2, stub3, rebuild_icoor_xyz );
86  return false;
87 }
88 
91  using numeric::conversions::radians;
92  std::istringstream l( line );
93  std::string tag, atom1, atom2, atom3, atom4, atom_name, atom_type_name, mm_atom_type_name, property;
94  Real charge, mean, sdev, radius;
95  Size chino;
96  l >> tag;
97  if ( l.fail() || tag[0] == '#' ) return 0;
98  if ( tag == "ADD_ATOM" ) {
99  if ( line.size() < 25 ) return 0;
100  atom_name = line.substr( 9,4); l >> tag;
101  l >> atom_type_name; // = line.substr( 14,4);
102  l >> mm_atom_type_name; // = line.substr( 19,4);
103  l >> charge;
104  if ( l.fail() ) return 0;
105  return new AddAtom( atom_name, atom_type_name, mm_atom_type_name, charge );
106  } else if ( tag == "DELETE_ATOM" ) {
107  l >> atom_name;
108  if ( l.fail() ) return 0;
109  return new DeleteAtom( atom_name );
110  } else if ( tag == "SET_BACKBONE_HEAVYATOM" ) {
111  l >> atom_name;
112  if ( l.fail() ) return 0;
113  return new SetBackboneHeavyatom( atom_name );
114  } else if ( tag == "SET_IO_STRING" ) { // 13 character tag
115  // NOTE - USE FIXED WIDTH IO SINCE NAME3 CAN CONTAIN INTERNAL WHITESPACE (EG DNA,RNA)
116  if ( line.size() < 19 ) return 0;
117  std::string const three_letter_code( line.substr(14,3) ), one_letter_code( line.substr(18,1) );
118  return new SetIO_String( three_letter_code, one_letter_code[0] );
119  } else if ( tag == "NBR_ATOM" ) {
120  l >> atom_name;
121  if ( l.fail() ) return 0;
122  return new SetNbrAtom( atom_name );
123  } else if ( tag == "NBR_RADIUS" ) {
124  Real radius;
125  l >> radius;
126  return new SetNbrRadius( radius );
127  } else if ( tag == "ADD_PROPERTY" ) {
128  l >> property;
129  if ( l.fail() ) return 0;
130  return new AddProperty( property );
131  } else if ( tag == "DELETE_PROPERTY" ) {
132  l >> property;
133  if ( l.fail() ) return 0;
134  return new DeleteProperty( property );
135  //Added by Andy M. Chen in June 2009
136  // This is needed for deleting properties, which occurs in certain PTM's
137  } else if ( tag == "ADD_CHI" ) {
138  l >> chino >> atom1 >> atom2 >> atom3 >> atom4;
139  if ( l.fail() ) return 0;
140  return new AddChi( chino, atom1, atom2, atom3, atom4 );
141  //Added by Andy M. Chen in June 2009
142  // This is needed for PTM's, which often result in one or more extra chi angles
143  } else if ( tag == "ADD_PROTON_CHI") {
144  Size chino, nsamples, nextra_samples;
145  std::string dummy;
146  l >> chino;
147  l >> dummy; // should be "SAMPLES"
148  l >> nsamples;
149  utility::vector1< Real > samples( nsamples );
150  for ( Size ii = 1; ii <= nsamples; ++ii ) {
151  l >> samples[ ii ];
152  }
153  l >> dummy; // should be "EXTRA"
154  l >> nextra_samples;
155  utility::vector1< Real > extra_samples( nextra_samples );
156  for ( Size ii = 1; ii <= nextra_samples; ++ii ) {
157  l >> extra_samples[ ii ];
158  }
159  if ( l.fail() ) return 0;
160  return new AddProtonChi( chino, samples, extra_samples );
161 
162  } else if ( tag == "REDEFINE_CHI" ) {
163  l >> chino >> atom1 >> atom2 >> atom3 >> atom4;
164  if ( l.fail() ) return 0;
165  return new RedefineChi( chino, atom1, atom2, atom3, atom4 );
166  //Added by Andy M. Chen in June 2009
167  // This is needed for PTM's
168  } else if ( tag == "ADD_CHI_ROTAMER" ) {
169  l >> chino >> mean >> sdev;
170  if ( l.fail() ) return 0;
171  return new AddChiRotamer( chino, mean, sdev );
172  //Added by Andy M. Chen in June 2009
173  // This is needed for PTM's
174  } else if ( tag == "ADD_BOND" ) {
175  l >> atom1 >> atom2;
176  if ( l.fail() ) return 0;
177  return new AddBond( atom1, atom2 );
178  } else if ( tag == "ADD_CONNECT" ) {
179  std::string connect_atom;
180  l >> connect_atom;
181  if ( l.fail() ) return 0;
182  l >> tag;
183  if ( l.fail() ) {
184  return new AddConnect( connect_atom, 0.0, 0.0, 0.0, connect_atom, connect_atom, connect_atom );
185  } else {
186  Real phi, theta, d;
187  std::string parent_atom, angle_atom, torsion_atom;
188  l >> phi >> theta >> d >> parent_atom >> angle_atom >> torsion_atom;
189  if ( l.fail() || tag != "ICOOR" ) {
190  utility_exit_with_message( "bad line in patchfile: "+line );
191  }
192  return new AddConnect( connect_atom, radians(phi), radians(theta), d, parent_atom, angle_atom, torsion_atom );
193  }
194  } else if ( tag == "SET_ATOM_TYPE" ) {
195  l >> atom_name >> atom_type_name;
196  if ( l.fail() ) return 0;
197  return new SetAtomType( atom_name, atom_type_name );
198  } else if ( tag == "SET_MM_ATOM_TYPE" ) {
199  l >> atom_name >> mm_atom_type_name;
200  if ( l.fail() ) return 0;
201  return new SetMMAtomType( atom_name, mm_atom_type_name );
202  } else if ( tag == "SET_ATOMIC_CHARGE" ) {
203  l >> atom_name >> charge;
204  if ( l.fail() ) return 0;
205  return new SetAtomicCharge( atom_name, charge );
206  } else if ( tag == "SET_POLYMER_CONNECT" ) {
207  l >> tag >> atom_name; // tag should be "UPPER" or "LOWER"
208  if ( l.fail() ) return 0;
209  return new SetPolymerConnectAtom( atom_name, tag );
210  } else if ( tag == "SET_ICOOR" ) {
211  Real phi,theta,d;
212  std::string stub1, stub2, stub3;
213  l >> atom_name >> phi >> theta >> d >> stub1 >> stub2 >> stub3;
214  if ( l.fail() ) return 0;
215  return new SetICoor( atom_name, radians(phi), radians(theta), d, stub1, stub2, stub3 );
216  } else if ( tag == "PREPEND_MAINCHAIN_ATOM" ) {
217  l >> atom_name;
218  return new PrependMainchainAtom( atom_name );
219  } else if ( tag == "APPEND_MAINCHAIN_ATOM" ) {
220  l >> atom_name;
221  return new AppendMainchainAtom( atom_name );
222  } else if ( tag == "NCAA_ROTLIB_PATH" ) {
223  std::string path;
224  l >> path;
225  return new NCAARotLibPath( path );
226  }
227  else if ( tag == "SET_NBR_ATOM") {
228  l >> atom_name;
229  if ( l.fail() ) return 0;
230  return new SetNbrAtom( atom_name );
231  }
232  else if ( tag == "SET_NBR_RADIUS") {
233  l >> radius;
234  if ( l.fail() ) return 0;
235  return new SetNbrRadius( radius );
236  }
237  else if ( tag == "SET_ORIENT_ATOM") {
238  l >> tag;
239  if ( tag == "NBR" ) {
240  return new SetOrientAtom(true);
241  } else if ( tag == "DEFAULT" ) {
242  return new SetOrientAtom(false);
243  } else {
244  tr.Warning << "Unknown SET_ORIENT ATOM tag: " << tag << std::endl;
245  return 0;
246  }
247  }
248  tr.Warning << "patch_operation_from_patch_file_line: bad line: " << line << std::endl;
249 
250  return 0;
251 }
252 
253 
254 } // chemical
255 } // core