Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 // :noTabs=false:tabSize=4:indentSize=4:
4 //
5 // (c) Copyright Rosetta Commons Member Institutions.
6 // (c) This file is part of the Rosetta software suite and is made available under license.
7 // (c) The Rosetta software is developed by the contributing members of the Rosetta Commons.
8 // (c) For more information, see http://www.rosettacommons.org. Questions about this can be
9 // (c) addressed to University of Washington UW TechTransfer, email: license@u.washington.edu.
10 
11 /// @file core/chemical/util.cc
12 /// @brief Utilities for modifying and utilizing Residues and other core::chemical classes.
13 
14 
15 // Unit headers
16 #include <core/chemical/util.hh>
17 
18 // Package Headers
19 // AUTO-REMOVED #include <core/chemical/ResidueTypeSet.hh>
23 
24 // Project Headers
25 #include <core/types.hh>
26 #include <basic/options/option.hh>
27 #include <basic/options/keys/in.OptionKeys.gen.hh>
28 #include <basic/options/keys/chemical.OptionKeys.gen.hh>
29 #include <utility/vector1.hh>
30 #include <utility/file/file_sys_util.hh>
31 #include <basic/Tracer.hh>
32 
33 namespace core {
34 namespace chemical {
35 
36 static basic::Tracer TR("core.chemical.util");
37 
40  using namespace basic::options;
41  using namespace basic::options::OptionKeys;
42  using namespace core::chemical;
43 
44  std::string const type_set_name( option[ in::file::residue_type_set ]() );
46  type_set_name
47  );
48 
49  return set;
50 }
51 
52 
53 /// @brief Add additional parameter files not present in <atom-set-name>/extras.txt. Called by ChemicalManager at time of AtomTypeSet creation.
54 
55 void
57  std::string const & atom_type_set_tag,
58  AtomTypeSet & atom_type_set
59  )
60 {
61  if ( !( basic::options::option[ basic::options::OptionKeys::chemical::add_atom_type_set_parameters ].user() ) ) {
62  /// do nothing if flag not present
63  return;
64  }
66  ( basic::options::option[ basic::options::OptionKeys::chemical::add_atom_type_set_parameters ]() );
67  if ( paramstring.size()%2 != 0 ) {
68  utility_exit_with_message("bad format for -add_atom_type_set_parameters; should be: -add_atom_type_set_parameters <tag1> <filename1> <tag2> <filename2> ...");
69  }
70  Size const nparams( paramstring.size()/2 );
71  for ( Size i=0; i< nparams; ++i ) {
72  std::string const tag( paramstring[2*i+1] ), filename( paramstring[2*i+2] );
73  TR.Trace << "add_atom_type_set_parameters_from_command_line: desired_tag= " << atom_type_set_tag <<
74  " cmdline-tag= " << tag << " filename= " << filename << std::endl;
75  if ( tag == atom_type_set_tag ) {
76  if ( !utility::file::file_exists( filename ) ) {
77  utility_exit_with_message("unable to locate/open file: "+filename );
78  }
79  TR.Trace << "add_atom_type_set_parameters_from_command_line: tag= " << tag << " filename= " << filename <<
80  std::endl;
81  atom_type_set.add_parameters_from_file( filename );
82  }
83  }
84 }
85 
86 
87 /// @brief Modify atom_type properties from the command line. Called by ChemicalManager at time of AtomTypeSet creation.
88 void
90  std::string const & atom_type_set_tag,
91  AtomTypeSet & atom_type_set
92  )
93 {
94 
95 
96  if ( basic::options::option[ basic::options::OptionKeys::chemical::set_atom_properties ].user() ) {
98  ( basic::options::option[ basic::options::OptionKeys::chemical::set_atom_properties ]);
99 
100  std::string const errmsg( "-set_atom_properties format should be:: -set_atom_properties <set1>:<atom1>:<param1>:<setting1> <set2>:<atom2>:<param2>:<setting2> ...; for example: '-chemical:set_atom_properties fa_standard:OOC:LK_DGFREE:-5 fa_standard:ONH2:LJ_RADIUS:0.5' ");
101 
102  for ( Size i=1; i<= mods.size(); ++i ) {
103  ///
104  /// mod should look like (for example): "fa_standard:OOC:LK_RADIUS:4.5"
105  ///
106  std::string const & mod( mods[i] );
107 
108  Size const pos1( mod.find(":") );
109  if ( pos1 == std::string::npos ) utility_exit_with_message(errmsg);
110  std::string const atomset_tag( mod.substr(0,pos1) );
111  if ( atomset_tag != atom_type_set_tag ) continue;
112 
113  Size const pos2( mod.substr(pos1+1).find(":") );
114  if ( pos2 == std::string::npos ) utility_exit_with_message(errmsg);
115  std::string const atom_name( mod.substr(pos1+1,pos2) );
116  if ( !atom_type_set.has_atom( atom_name ) ) utility_exit_with_message(errmsg+". Nonexistent atomname: "+atom_name);
117 
118  Size const pos3( mod.substr(pos1+1+pos2+1).find(":") );
119  if ( pos3 == std::string::npos ) utility_exit_with_message(errmsg);
120  std::string const param( mod.substr(pos1+1+pos2+1,pos3) );
121 
122  std::string const stringsetting( mod.substr(pos1+1+pos2+1+pos3+1) );
123  if ( !ObjexxFCL::is_float( stringsetting ) ) utility_exit_with_message(errmsg);
124  Real const setting( ObjexxFCL::float_of( stringsetting ) );
125 
126  TR.Trace << "modify_atom_properties_from_command_line: setting " << atomset_tag << ' ' << atom_name << ' ' <<
127  param << ' ' << setting << std::endl;
128 
129  Size const atom_index( atom_type_set.atom_type_index( atom_name ) );
130 
131  /// I would like to uncomment the following if-check, but right now there is an extra parameter file
132  /// that defines a parameter with the name LK_DGFREE (memb_fa_params.txt). That's kind of confusing...
133  ///
134  // if ( atom_type_set.has_extra_parameter( param ) ) {
135  // Size const param_index( atom_type_set.extra_parameter_index( param ) );
136  // atom_type_set[ atom_index ].set_extra_parameter( param_index, setting );
137  // } else {
138  atom_type_set[ atom_index ].set_parameter( param, setting );
139  }
140  }
141 }
142 
143 } // namespace chemical
144 } // namespace core