Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
AtomicDistanceFilter.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 sw=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 protocols/filters/AtomicDistanceFilter.cc
11 /// @brief Filter for looking at specific atom distances
12 /// @author Rocco Moretti (rmoretti@uw.edu)
13 
16 
17 // Project Headers
18 #include <core/types.hh>
19 #include <core/pose/Pose.hh>
20 
21 //parsing
22 #include <utility/tag/Tag.hh>
28 #include <core/pose/selection.hh>
29 #include <basic/Tracer.hh>
30 
31 #include <utility/vector0.hh>
32 #include <utility/excn/Exceptions.hh>
33 #include <utility/vector1.hh>
34 
35 namespace protocols {
36 namespace simple_filters {
37 
38 static basic::Tracer TR( "protocols.filters.AtomicDistanceFilter" );
39 
40 ///@brief default ctor
42  parent( "AtomicDistance" )
43 {}
44 
45 ///@brief
46 AtomicDistanceFilter::AtomicDistanceFilter( core::Size const res1, core::Size const res2, std::string atom_desig1, std::string atom_desig2, bool as_type1, bool as_type2, core::Real distance) :
47  parent( "AtomicDistance" ),
48  residue1_( res1 ),
49  residue2_( res2 ),
50  atomdesg1_( atom_desig1 ),
51  atomdesg2_( atom_desig2 ),
52  astype1_( as_type1 ),
53  astype2_( as_type2 ),
54  distance_( distance )
55 {}
56 
57 /// @return Whether the atom pair is within the cutoff
59 {
60  core::Real const dist( compute( pose ) );
61  report( TR.Debug, pose );
62  if( dist <= distance_ ) return true;
63  return false;
64 }
65 
68 {
69  using namespace core::conformation;
70 
71  core::Real nearest_distance( 999999 );
72 
73  assert(residue1_ <= pose.n_residue() && residue2_ <= pose.n_residue());
74  Residue const& res1( pose.residue( residue1_ ) );
75  Residue const& res2( pose.residue( residue2_ ) );
76 
77  core::Size a1start(1), a1end(res1.natoms());
78  if ( ! astype1_ ) { // If given by name, look only at the single atom
79  if ( ! res1.type().has(atomdesg1_) ) {
80  TR << "WARNING! Residue "<<residue1_<<" of type "<<res1.type().name()<<" does not have atom with name "<<atomdesg1_<<std::endl;
81  return nearest_distance;
82  }
83  a1start = a1end = res1.atom_index(atomdesg1_);
84  }
85  core::Size a2start(1), a2end(res2.natoms());
86  if ( ! astype2_ ) { // If given by name, look only at the single atom
87  if ( ! res2.type().has(atomdesg2_) ) {
88  TR << "WARNING! Residue "<<residue2_<<" of type "<<res2.type().name()<<" does not have atom with name "<<atomdesg2_<<std::endl;
89  return nearest_distance;
90  }
91  a2start = a2end = res2.atom_index(atomdesg2_);
92  }
93 
94  bool found1(false), found2(false);
95  for ( core::Size ii(a1start); ii <= a1end; ++ii) {
96  if ( !astype1_ || res1.atom_type(ii).name() == atomdesg1_ ) {
97  found1 = true;
98  for ( core::Size jj(a2start); jj <= a2end; ++jj) {
99  if ( !astype2_ || res2.atom_type(jj).name() == atomdesg2_ ) {
100  found2 = true;
101  core::Real const dist( res1.atom(ii).xyz().distance( res2.atom(jj).xyz() ) );
102  if ( dist < nearest_distance ) {
103  nearest_distance = dist;
104  }
105  }
106  }
107  }
108  }
109 
110  if ( ! found1 ) {
111  TR << "WARNING! Residue "<<residue1_<<" of type "<<res1.type().name()<<" does not have atom with "<<(astype1_?"type ":"name ")<<atomdesg1_<<std::endl;
112  }
113  else if ( ! found2 ) { // elseif because the inner loop doesn't run if the outer loop doesn't trip. (if found1 is false, found2 is always false)
114  TR << "WARNING! Residue "<<residue2_<<" of type "<<res2.type().name()<<" does not have atom with "<<(astype2_?"type ":"name ")<<atomdesg2_<<std::endl;
115  }
116  return( nearest_distance );
117 }
118 
121 {
122  core::Real const dist( compute( pose ) );
123  return( dist );
124 }
125 
126 void AtomicDistanceFilter::report( std::ostream & out, core::pose::Pose const & pose ) const
127 {
128  core::Real const dist( compute( pose ) );
129  out<<"Minimal distance between residue "<<residue1_<<" atom "<<(astype1_?"type ":"name ")<<atomdesg1_<<" and residue "<<residue2_<<" atom "<<(astype2_?"type ":"name ")<<atomdesg2_<<" is "<<dist<<std::endl;
130 }
131 
136  core::pose::Pose const & pose)
137 {
138  distance_ = tag->getOption< core::Real >( "distance", 4.0 );
139 
140  std::string const res1( tag->getOption< std::string >( "residue1" ) );
141  std::string const res2( tag->getOption< std::string >( "residue2" ) );
142  residue1_ = core::pose::parse_resnum( res1, pose );
143  residue2_ = core::pose::parse_resnum( res2, pose );
144 
145  if (residue1_ == 0) {
146  TR << "Residue number "<<res1<<" not found in pose."<<std::endl;
147  throw utility::excn::EXCN_RosettaScriptsOption("Residue number not found. Check xml file");
148  }
149  if (residue2_ == 0) {
150  TR << "Residue number "<<res2<<" not found in pose."<<std::endl;
151  throw utility::excn::EXCN_RosettaScriptsOption("Residue number not found. Check xml file");
152  }
153 
154  if( tag->hasOption( "atomtype1" ) ) {
155  if( tag->hasOption( "atomname1" ) ) {
156  throw utility::excn::EXCN_RosettaScriptsOption("Can't set both atomname1 and atomtype1. Check xml file");
157  }
158  atomdesg1_ = tag->getOption< std::string >( "atomtype1" );
159  astype1_ = true;
160  }
161  else {
162  atomdesg1_ = tag->getOption< std::string >( "atomname1", "CB" );
163  astype1_ = false;
164  }
165 
166  if( tag->hasOption( "atomtype2" ) ) {
167  if( tag->hasOption( "atomname2" ) ) {
168  throw utility::excn::EXCN_RosettaScriptsOption("Can't set both atomname2 and atomtype2. Check xml file");
169  }
170  atomdesg2_ = tag->getOption< std::string >( "atomtype2" );
171  astype2_ = true;
172  }
173  else {
174  atomdesg2_ = tag->getOption< std::string >( "atomname2", "CB" );
175  astype2_ = false;
176  }
177 
178  TR<<"AtomicDistance filter between residue "<<residue1_<<" atom "<<(astype1_?"type ":"name ")<<atomdesg1_<<" and residue "<<residue2_<<" atom "<<(astype2_?"type ":"name ")<<atomdesg2_<<" with distance cutoff of "<<distance_<<std::endl;
179 }
180 
183 
185 AtomicDistanceFilterCreator::keyname() const { return "AtomicDistance"; }
186 
187 
188 
189 } // filters
190 } // protocols