Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
adduct_util.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
11 /// @brief
12 /// @author Jim Havranek
13 
14 
15 // Unit header
17 #include <core/chemical/Patch.hh>
18 // Commented by inclean daemon #include <core/chemical/VariantType.hh>
19 
20 // Rosetta headers
21 // Commented by inclean daemon #include <core/conformation/Residue.hh>
22 
23 // ObjexxFCL headers
24 
25 // Numeric headers
26 #include <numeric/conversions.hh>
27 
28 // Utility headers
29 //#include <utility/io/izstream.hh>
30 // Commented by inclean daemon #include <utility/options/StringVectorOption.hh>
31 
32 // C++ headers
33 // Commented by inclean daemon #include <string>
34 // Commented by inclean daemon #include <map>
35 
36 #include <basic/Tracer.hh>
37 
39 #include <utility/vector1.hh>
40 #include <utility/options/StringVectorOption.hh>
41 
42 static basic::Tracer TR("core.chemical.adduct_util");
43 
44 namespace core {
45 namespace chemical {
46 
47 /// @brief Convert input string to map of adducts->max usage
48 std::map< std::string, int >
50  utility::options::StringVectorOption & add_vec
51 )
52 {
53  std::map< std::string, int > add_map;
54  // walk via an index, plucking a second string each time if
55  // it is an integer
56  Size index( 1 );
57  Size over_index( add_vec.size() + 1 );
58  while( index != over_index ) {
59  // Always store as lower for ease of comparison
60  std::string this_adduct( add_vec[ index ] );
61  ObjexxFCL::lowercase( this_adduct );
62  index++;
63  int max_uses_for_this_adduct( 9999 );
64  if( index != over_index && ObjexxFCL::is_int( add_vec[ index ] ) ) {
65  max_uses_for_this_adduct = ObjexxFCL::int_of( add_vec[ index ] );
66  index++;
67  }
68  // Add to the map
69  add_map[ this_adduct ] = max_uses_for_this_adduct;
70  }
71 
72  // Debug - remove later
73 // for( std::map< std::string, int >::iterator iter = add_map.begin() ;
74 // iter != add_map.end() ; iter++ ) {
75 // TR << "Adduct map " << iter->first << "\t" << iter->second << std::endl;
76 // }
77 
78 
79  return add_map;
80 }
81 
82 
83 /// @brief Make sure any adducts requested actually exist
84 void
85 error_check_requested_adducts( std::map< std::string, int > const & add_map,
86  ResidueTypeCOPs const & rsd_types ) {
87 
88  for( std::map< std::string, int >::const_iterator this_add = add_map.begin() ;
89  this_add != add_map.end() ; ++this_add ) {
90  bool not_found( true );
91 
92  for ( ResidueTypeCOPs::const_iterator this_rsd = rsd_types.begin(),
93  end_rsd = rsd_types.end(); this_rsd != end_rsd ; ++this_rsd ) {
94  // shortcircuit if we've already found an instance of the adduct
95  ResidueType const & rsd( **this_rsd );
96  if( not_found == false ) break;
97 
98  for ( utility::vector1< Adduct >::const_iterator rsd_add = rsd.defined_adducts().begin(),
99  end_rsd_add = rsd.defined_adducts().end() ;
100  rsd_add != end_rsd_add ; ++rsd_add ) {
101  std::string check_name( rsd_add->adduct_name() );
102  // compare case-insensitively for convenience
103  if( ObjexxFCL::equali( this_add->first, check_name ) ) {
104  not_found = false;
105  break;
106  }
107  }
108  }
109 
110  if( not_found ) {
111  utility_exit_with_message( "Requested undefined adduct: " + this_add->first + '\n' );
112  }
113  } // Done with adduct name error-checking
114 }
115 
116 /// @brief Apply adducts to residue using a boolean mask
118  utility::vector1< bool > & add_mask
119 )
120 {
121  using numeric::conversions::radians;
122 
123  // Use the patching machinery to apply the adducts
124  PatchCase temp_patch_case;
125 
126  // Starting name
127  std::string new_rsd_name( rsd.name() );
128 
129  // Throw in all the applicable adducts
130  utility::vector1< bool >::iterator mask_iter = add_mask.begin();
131  for( utility::vector1< Adduct >::const_iterator add_iter = rsd.defined_adducts().begin() ,
132  end_add_iter = rsd.defined_adducts().end() ; add_iter != end_add_iter ;
133  ++add_iter, ++mask_iter ) {
134 
135  // Skip adducts if dictated by the mask
136  if( !(*mask_iter) ) continue;
137 
138  // Add the adduct and it's information
139  PatchOperationOP poop1 = new AddAtom( add_iter->atom_name(), add_iter->atom_type_name(),
140  add_iter->mm_atom_type_name(), add_iter->atom_charge() );
141  temp_patch_case.add_operation( poop1 );
142  PatchOperationOP poop2 = new AddBond( add_iter->atom_name(), add_iter->stub_atom1() );
143  temp_patch_case.add_operation( poop2 );
144  PatchOperationOP poop3 = new SetICoor( add_iter->atom_name(), radians( add_iter->phi() ),
145  radians( add_iter->theta() ), add_iter->d(), add_iter->stub_atom1(), add_iter->stub_atom2(),
146  add_iter->stub_atom3() );
147  TR.Debug << "Making a patch op for residue " << rsd.name() << " adduct " << add_iter->adduct_name() <<
148  " phi raw " << add_iter->phi() << " theta raw " << add_iter->theta() << " d raw " << add_iter->d() << std::endl;
149  TR.Debug << "Using stub atoms " << add_iter->stub_atom1() << " , " << add_iter->stub_atom2() << " , " <<
150  add_iter->stub_atom3() << std::endl;
151  temp_patch_case.add_operation( poop3 );
152 
153  // Append the adduct name
154  new_rsd_name = new_rsd_name + "_adduct:" + add_iter->atom_name();
155  }
156 
157  // Apply the Patch operations
158  ResidueTypeOP new_rsd_type( temp_patch_case.apply( rsd ) );
159 
160  // Set the full name
161  TR << "Setting new rsd name to " << new_rsd_name << std::endl;
162  new_rsd_type->name( new_rsd_name );
163 
164  // Set the variant type
165  new_rsd_type->add_variant_type( ADDUCT );
166 
167  // Set as an adduct-modified type, which is helpful to know
168  // in rotamer-building, as adduct variants are generally allowed,
169  // while non-adduct variants are in general disallowed
170  new_rsd_type->set_adduct_flag( true );
171 
172  return new_rsd_type;
173 }
174 
175 
176 
177 } // chemical
178 } // core