Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
AtomVDW.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/methods/AtomVDW.hh
11 /// @brief
12 /// @author Phil Bradley
13 
14 
15 // Unit Headers
16 #include <core/scoring/AtomVDW.hh>
17 
18 // Package headers
19 
20 
21 // Project headers
24 
25 #include <basic/database/open.hh>
26 #include <basic/Tracer.hh>
27 
28 // Utility headers
29 #include <utility/io/izstream.hh>
30 // AUTO-REMOVED #include <ObjexxFCL/format.hh>
31 
32 
33 #include <cmath>
34 
36 #include <utility/vector1.hh>
37 
38 //Auto using namespaces
39 namespace ObjexxFCL { namespace fmt { } } using namespace ObjexxFCL::fmt; // AUTO USING NS
40 //Auto using namespaces end
41 
42 
43 namespace core {
44 namespace scoring {
45 
46 static basic::Tracer TR("core.scoring.AtomVDW");
47 
48 
49 /// @details ctor, reads data file. Need to configure to allow alternate tables/atom_sets
50 AtomVDW::AtomVDW( std::string const & atom_type_set_name )
51 {
52  // get the relevant atomset
53  chemical::AtomTypeSet const & atom_set
54  ( *chemical::ChemicalManager::get_instance()->atom_type_set( atom_type_set_name ) );//chemical::CENTROID ) );
55 
56  // initialize the values
57  Size const n_atom_types( atom_set.n_atomtypes() );
58  atom_vdw_.clear();
59  atom_vdw_.resize( n_atom_types );
60  for ( Size j=1; j<= n_atom_types; ++j ) {
61  atom_vdw_[j].resize( n_atom_types, 0.0 ); // default value is 0.0 --> no clashes
62  }
63 
64  utility::io::izstream stream;
65  stream.open( atom_set.directory() + "/atom_vdw.txt" );
66 
67  if ( !stream.good() ) {
68  stream.clear();
69  if ( atom_type_set_name != chemical::CENTROID ) {
70  utility_exit_with_message( "cant find atom_vdw.txt in directory: "+ atom_set.directory() );
71  }
72  TR.Warning << "YOU NEED TO UPDATE YOUR MINIROSETTA DATABASE!" << std::endl;
73  basic::database::open( stream, "scoring/AtomVDW/atom_vdw.txt" );
74  if ( !stream.good() ) {
75  utility_exit_with_message( "Unable to open scoring/AtomVDW/atom_vdw.txt!" );
76  }
77  }
78 
79  // read the entire file and figure out what atom_types are present and in what order
81  utility::vector1< int > atom_type_index; // mapping from index in the file to index in atom_set
82 
83  std::string line, atom_type_name;
84  while ( getline( stream, line ) ) {
85  lines.push_back(line);
86  std::istringstream l(line);
87  l >> atom_type_name;
88  atom_type_index.push_back( atom_set.atom_type_index( atom_type_name ) ); // will fail if name is not recognized
89  }
90 
91  Size const natoms( lines.size() );
92  for ( Size i=1; i<= natoms; ++i ) {
93  std::istringstream l( lines[i] );
94  l >> atom_type_name;
95 
96  Size const i_atom_type_index( atom_type_index[i] );
97 
98  for ( Size j=1; j<= natoms; ++j ) {
99  Size const j_atom_type_index( atom_type_index[j] );
100  l >> atom_vdw_[ i_atom_type_index ][ j_atom_type_index ];
101  }
102  if ( l.fail() ) utility_exit_with_message( "bad format in atom_vdw.txt ");
103  }
104 
105  setup_approximate_vdw_radii( atom_type_index, atom_set );
106 }
107 
108 /// @details Calculates approximation to a single per-atom radius using the pairwise data from the file
109 /// For atoms not present in the file uses the lj_radius from atom_type_set
110 
111 void
112 AtomVDW::setup_approximate_vdw_radii(
113  utility::vector1< int > const & atom_type_index,
114  chemical::AtomTypeSet const & atom_type_set
115  )
116 {
117  using namespace ObjexxFCL::fmt;
118 
119  Size const natoms_full( atom_vdw_.size() );
120  Size const natoms( atom_type_index.size() ); // # atoms in the db file
121  assert( natoms_full == Size( atom_type_set.n_atomtypes() ) );
122 
123  // initialize
124  utility::vector1< Real > R( natoms_full );
125  for ( Size i=1; i<= natoms_full; ++i ) {
126  R[i] = atom_type_set[i].lj_radius();
127  }
128 
129  // just for the guys in the file
130  for ( Size i=1; i<= natoms; ++i ) {
131  Size const ii( atom_type_index[i] );
132  R[ii] = std::sqrt( atom_vdw_[ii][ii] );
133  }
134 
135  Size const niter( 10 );
136  for ( Size r=1; r<= niter; ++r ) {
137 
138  utility::vector1< Real > new_R( R );
139 
140  // calculate deviations
141  Real total_dev( 0.0 );
142 
143  for ( Size i=1; i<= natoms; ++i ) {
144  Size const ii( atom_type_index[i] );
145 
146  Real dev(0.0), abs_dev(0.0);
147  for ( Size j=1; j<= natoms; ++j ) {
148  Size const jj( atom_type_index[j] );
149 
150  Real const actual( std::sqrt( atom_vdw_[ii][jj] ) );
151  Real const expected( R[ii] + R[jj] );
152  dev += actual - expected;
153  total_dev += ( actual - expected ) * ( actual - expected );
154  abs_dev += ( actual - expected ) * ( actual - expected );
155  }
156  dev /= natoms;
157  abs_dev = std::sqrt( abs_dev / natoms );
158  new_R[ii] = R[ii] + dev/2;
159  //std::cout << "R " << I(4,i) << F(9,3,R[ii]) <<F(9,3,dev) << F(9,3,abs_dev ) << std::endl;
160  }
161 
162  R = new_R;
163  //std::cout << "round: " << r << ' ' << std::sqrt( total_dev / ( natoms * natoms ) ) << std::endl;
164  }
165 
166  /// now set the long-name guy
167  approximate_vdw_radii_ = R;
168 }
169 
170 
171 } // namespace scoring
172 } // namespace core
173