28 #include <basic/Tracer.hh>
30 #include <utility/vector1.hh>
31 #include <numeric/xyzVector.hh>
32 #include <numeric/xyz.functions.hh>
33 #include <utility/io/izstream.hh>
37 #include <basic/options/option.hh>
39 #include <basic/options/keys/OptionKeys.hh>
40 #include <basic/options/keys/constraints.OptionKeys.gen.hh>
42 #include <basic/prof.hh>
45 namespace frag_picker {
49 "fragment.picking.scores.DihedralConstraintsScore");
52 Real lowest_acceptable_value,
bool use_lowest,
std::string constraints_file_name,
55 constrainable_atoms,
"DihedralConstraintsScore") {
65 Real lowest_acceptable_value,
bool use_lowest,
std::string constraints_file_name,
68 "DihedralConstraintsScore") {
80 PROF_START( basic::FRAGMENTPICKING_DIHEDRALCONSTR_SCORE );
81 Size frag_len = fragment->get_length();
82 Size vi = fragment->get_first_index_in_vall();
83 Size qi = fragment->get_first_index_in_query();
86 for (
Size i = 0; i < frag_len; ++i) {
88 Size firstQueryResidueIndex = qi + i;
89 Size firstVallResidueIndex = vi + i;
91 if (r->get_second_offset() >= frag_len - i)
93 if (r->get_third_offset() >= frag_len - i)
95 if (r->get_fourth_offset() >= frag_len - i)
97 Size secondVallResidueIndex = firstVallResidueIndex
98 + r->get_second_offset();
99 Size thirdVallResidueIndex = firstVallResidueIndex
100 + r->get_third_offset();
101 Size fourthVallResidueIndex = firstVallResidueIndex
102 + r->get_fourth_offset();
103 if (!
has_atom(firstVallResidueIndex, r->get_first_atom()))
105 if (!
has_atom(secondVallResidueIndex, r->get_second_atom()))
107 if (!
has_atom(thirdVallResidueIndex, r->get_third_atom()))
109 if (!
has_atom(fourthVallResidueIndex, r->get_fourth_atom()))
113 firstVallResidueIndex, r->get_first_atom());
115 secondVallResidueIndex, r->get_second_atom());
117 thirdVallResidueIndex, r->get_third_atom());
119 fourthVallResidueIndex, r->get_fourth_atom());
121 double torsion = dihedral_degrees(v1, v2, v3, v4);
122 total_score += r->get_function()->func(torsion);
125 total_score /= (
Real) frag_len;
126 scores->set_score_component(total_score,
id_);
127 PROF_STOP( basic::FRAGMENTPICKING_DIHEDRALCONSTR_SCORE );
131 << *fragment <<
" because its score is: " << total_score
141 utility::io::izstream data(constraints_file_name.c_str());
143 << constraints_file_name << std::endl;
145 utility_exit_with_message(
"[ERROR] Unable to open constraints file: "
146 + constraints_file_name);
153 while (!data.fail()) {
154 char c = data.peek();
155 if (c ==
'#' || c ==
'\n') {
162 <<
" end of file reached" << std::endl;
165 if (tag ==
"Dihedral") {
166 Size res1, res2, res3, res4;
171 data >> name1 >> res1 >> name2 >> res2 >> name3 >> res3 >> name4
172 >> res4 >> func_type;
175 << name2 <<
" " << name3 <<
" " << name4 <<
" " << res1
176 <<
" " << res2 <<
" " << res3 <<
" " << res4 <<
" func: "
177 << func_type << std::endl;
180 func->read_data(data);
181 std::map<std::string, Size> constr_atoms =
183 std::map<std::string, Size>::iterator it = constr_atoms.find(name1);
184 if (it == constr_atoms.end()) {
186 <<
"\nThe following constraint will NOT be used:\n"
187 << line << std::endl;
190 Size a1 = it->second;
191 it = constr_atoms.find(name2);
192 if (it == constr_atoms.end()) {
195 <<
"\nThe following constraint will NOT be used:\n"
196 << line << std::endl;
199 Size a2 = it->second;
200 it = constr_atoms.find(name3);
201 if (it == constr_atoms.end()) {
203 <<
"\nThe following constraint will NOT be used:\n"
204 << line << std::endl;
207 Size a3 = it->second;
208 it = constr_atoms.find(name4);
209 if (it == constr_atoms.end()) {
212 <<
"\nThe following constraint will NOT be used:\n"
213 << line << std::endl;
216 Size a4 = it->second;
217 Size o2 = res2 - res1;
218 Size o3 = res3 - res1;
219 Size o4 = res4 - res1;
220 if ((res2 < res1) || (res3 < res1) || (res4 < res1)) {
222 <<
"The residue of the first constrained atoms must precede all the other three.\n\t\t"
223 <<
"Check residue indexes && redefine the constraint if necessary.\n\t\t"
224 <<
"The following constraint will NOT be used:\n"
225 << line << std::endl;
231 if (res1 >
data_.size()) {
233 <<
"Skipping a constraint that involves residue "
234 << res1 <<
" that does not exist in a query"
238 data_[res1].push_back(dat);
249 using namespace basic::options;
250 using namespace basic::options::OptionKeys;
252 if (option[constraints::cst_file].user()) {
254 << option[constraints::cst_file]()[1] << std::endl;
257 lowest_acceptable_value, use_lowest, option[constraints::cst_file]()[1],
258 picker->size_of_query());
260 utility_exit_with_message(
261 "Can't read a constraints file. Provide it with constraints::cst_file flag");