33 #include <basic/Tracer.hh>
39 #include <utility/vector1.hh>
40 #include <utility/io/izstream.hh>
41 #include <basic/database/open.hh>
42 #include <basic/database/sql_utils.hh>
43 #include <basic/options/keys/chemical.OptionKeys.gen.hh>
44 #include <basic/options/option.hh>
50 static basic::Tracer
tr(
"core.chemical");
59 read_file( directory +
"/atom_properties.txt" );
61 utility::io::izstream data( ( directory+
"/extras.txt" ).c_str() );
64 while( getline( data, line ) ) {
65 if ( line.size() && line[0] ==
'#' )
continue;
71 if ( basic::options::option[ basic::options::OptionKeys::chemical::enlarge_H_lj ] ) {
78 utility::sql_database::sessionOP db_session) {
80 directory_ = basic::database::full_name(
"chemical/atom_type_sets/" + name);
84 "SELECT name FROM atom_types WHERE atom_type_set_name = ?;";
85 cppdb::statement stmt(
86 basic::database::safely_prepare_statement(stmt_string, db_session));
88 cppdb::result res(basic::database::safely_read_from_database(stmt));
92 res >> atom_type_name;
95 name, atom_type_name, db_session));
97 name, atom_type, db_session);
99 name, atom_type, db_session);
108 " atom_type_extra_parameters\n"
110 " atom_type_set_name = ?\n"
113 cppdb::statement stmt(
114 basic::database::safely_prepare_statement(stmt_string, db_session));
117 basic::database::safely_read_from_database(stmt));
122 res >> extra_parameter_name;
144 if(last_char_pos == std::string::npos || last_char_pos == 0)
return directory_;
146 Size first_char_pos(
directory_.find_last_of(
'/', last_char_pos - 1) + 1);
147 if(first_char_pos == std::string::npos) first_char_pos = 0;
149 return directory_.substr(first_char_pos, last_char_pos - first_char_pos + 1);
162 utility::io::izstream data( filename.c_str() );
164 if ( !data.good() ) utility_exit_with_message(
"Unable to open atomset file: "+filename );
170 getline( data, line );
171 std::istringstream l( line );
173 if ( tag !=
"NAME" || tag2 !=
"ATOM" ) {
174 utility_exit_with_message(
"AtomTypeSet::read_file: bad first line: "+ line );
177 while ( !l.fail() ) {
178 tags.push_back( tag );
184 Size const ntags( tags.size() );
186 using namespace basic;
189 while ( getline( data,line ) ) {
190 std::istringstream l( line );
191 l >> name_wo_whitespace;
192 if ( l.fail() || name_wo_whitespace.find(
"#",0) == 0 )
continue;
194 if ( l.fail() || tag.size() < 1 ) {
195 utility_exit_with_message(
"bad line: "+line);
203 for (
Size i=1; i<= ntags; ++i ) {
209 utility_exit_with_message(
"bad line: "+line);
214 while ( !l.fail() && tag.find(
"#",0) != 0) {
220 atoms_.push_back( atom_type_ptr );
223 utility_exit_with_message(
"AtomTypeSet:: duplicate atom name "+name_wo_whitespace);
226 tr.Debug <<
"New atom type: " << name_wo_whitespace <<
' ' << element << std::endl;
250 if ( param_name ==
"LJ_RADIUS" ) {
252 }
else if ( param_name ==
"LJ_WDEPTH" ) {
254 }
else if ( param_name ==
"LK_VOLUME" ) {
256 }
else if ( param_name ==
"LK_DGFREE" ) {
258 }
else if ( param_name ==
"LK_LAMBDA" ) {
262 utility_exit_with_message(
"unrecognized parameter type: "+param_name );
279 utility::io::izstream data( filename.c_str() );
281 if ( !data.good() ) utility_exit_with_message(
"Unable to open atomset parameter file: "+filename );
283 while ( getline( data,line ) ) {
284 std::istringstream l( line );
286 if ( l.fail() || tag.size() < 1 || tag[0] ==
'#' )
continue;
288 if ( tag ==
"NAME" ) {
290 while ( !l.fail() ) {
291 if ( tag[0] ==
'#' )
break;
292 tags.push_back( tag );
296 }
else if ( tag ==
"DEFAULT" ) {
298 while ( !l.fail() ) {
299 if ( tag[0] ==
'#' )
break;
300 default_parameter_names.push_back( tag );
304 lines.push_back( line );
310 if ( tags.empty() ) utility_exit_with_message(
"AtomTypeSet::read_file: missing NAME line");
311 if ( !default_parameter_names.empty() && default_parameter_names.size() != tags.size() ) {
312 std::cout <<
"AtomTypeSet:: number of params doesnt match number of defaults " <<
313 default_parameter_names.size() <<
' ' << tags.size() << std::endl;
318 Size const ntags( tags.size() );
319 std::map< std::string, utility::vector1< Real > > all_parameters;
322 for (
Size ii=1; ii<= lines.size(); ++ii ) {
324 std::istringstream l( line );
326 if ( tag.find(
"#",0) == 0 )
continue;
332 for (
Size i=1; i<= ntags; ++i ) {
335 parameters.push_back( setting );
337 if ( l.fail() || parameters.size() != tags.size() ) {
338 utility_exit_with_message(
"bad line: "+line);
341 all_parameters[ tag ] = parameters;
346 for ( std::map< std::string, int >::const_iterator
349 int const atom_index( iter->second );
352 std::map< std::string, utility::vector1< Real > >::const_iterator iter2( all_parameters.find( name ) );
356 if ( iter2 == all_parameters.end() ) {
357 if ( !default_parameter_names.empty() ) {
358 paramsrc =
"from_defaults";
359 for (
Size i=1; i<= default_parameter_names.size(); ++i ) {
362 basic::T(
"core.chemical.AtomTypeSet") <<
"Using default parameter " << default_parameter_names[i] <<
" = " <<
363 default_param <<
" in place of " << tags[i] <<
" for atomtype " << name <<
'\n';
364 params.push_back( default_param );
367 paramsrc =
"from_****";
368 iter2 = all_parameters.find(
"****" );
369 if ( iter2 == all_parameters.end() ) {
370 utility_exit_with_message(
"no parameters specified for atom type: "+name+
" in file "+filename );
372 params = iter2->second;
375 paramsrc =
"from_file";
376 params = iter2->second;
381 runtime_assert( params.size() == tags.size() );
382 for (
Size i=1; i<= tags.size(); ++i ) {
383 tr.Trace <<
"setting extra parameter: " << tags[i] <<
' ' <<
atoms_[ atom_index ]->name() <<
' ' <<
384 paramsrc <<
' ' << params[i] << std::endl;
385 atoms_[ atom_index ]->set_extra_parameter( i + index_offset, params[i] );
400 utility::sql_database::sessionOP db_session
405 " lennard_jones_radius REAL,\n"
406 " lennard_jones_well_depth REAL,\n"
407 " lazaridis_karplus_lambda REAL,\n"
408 " lazaridis_karplus_degrees_of_freedom REAL,\n"
409 " lazaridis_karplus_volume REAL\n"
413 " atom_type_set_name = ? AND name = ?;";
415 cppdb::statement stmt(
416 basic::database::safely_prepare_statement(stmt_string, db_session));
417 stmt.bind(1, atom_type_set_name);
418 stmt.bind(2, atom_type_name);
419 cppdb::result res(basic::database::safely_read_from_database(stmt));
422 utility_exit_with_message(
423 "could not find atom '" + atom_type_name +
"' in '" +
424 atom_type_set_name +
"'.");
428 Real lennard_jones_radius;
429 Real lennard_jones_well_depth;
430 Real lazaridis_karplus_lambda;
431 Real lazaridis_karplus_degrees_of_freedom;
432 Real lazaridis_karplus_volume;
436 >> lennard_jones_radius
437 >> lennard_jones_well_depth
438 >> lazaridis_karplus_lambda
439 >> lazaridis_karplus_degrees_of_freedom
440 >> lazaridis_karplus_volume;
443 atom_type_ptr->
set_parameter(
"LJ_RADIUS", lennard_jones_radius);
444 atom_type_ptr->
set_parameter(
"LJ_WDEPTH", lennard_jones_well_depth);
445 atom_type_ptr->
set_parameter(
"LK_LAMBDA", lazaridis_karplus_lambda);
446 atom_type_ptr->
set_parameter(
"LK_DGFREE", lazaridis_karplus_degrees_of_freedom);
447 atom_type_ptr->
set_parameter(
"LK_VOLUME", lazaridis_karplus_volume);
449 atoms_.push_back(atom_type_ptr);
451 return *atom_type_ptr;
459 utility::sql_database::sessionOP db_session
465 " atom_type_properties\n"
467 " atom_type_set_name = ? AND name = ?;";
469 cppdb::statement stmt(basic::database::safely_prepare_statement(stmt_string, db_session));
470 stmt.bind(1, atom_type_set_name);
471 stmt.bind(2, atom_type.
name());
472 cppdb::result res(basic::database::safely_read_from_database(stmt));
485 utility::sql_database::sessionOP db_session
491 " atom_type_extra_parameters\n"
493 " atom_type_set_name = ? AND name = ?\n"
497 cppdb::statement stmt(basic::database::safely_prepare_statement(stmt_string, db_session));
498 stmt.bind(1, atom_type_set_name);
499 stmt.bind(2, atom_type.
name());
500 cppdb::result res(basic::database::safely_read_from_database(stmt));
504 Size parameter_index(1);
517 Size const n_H_atom_type = 5;
518 Real const lj_wdepth = 0.15;
519 std::string const H_names [n_H_atom_type] = {
"Hpol",
"Hapo",
"Haro",
"HNbb",
"HOH"};
520 for (
Size i = 0; i != n_H_atom_type; ++i) {
522 atoms_[index] -> set_parameter(
"LJ_WDEPTH", lj_wdepth );