autodock-vina-1.1.2/0000755000175000017500000000000011562571401014141 5ustar moellermoellerautodock-vina-1.1.2/src/0000755000175000017500000000000011562571440014733 5ustar moellermoellerautodock-vina-1.1.2/src/lib/0000755000175000017500000000000011562607744015510 5ustar moellermoellerautodock-vina-1.1.2/src/lib/grid.h0000744000175000017500000000434111562571364016607 0ustar moellermoeller/* Copyright (c) 2006-2010, The Scripps Research Institute Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Author: Dr. Oleg Trott , The Olson Lab, The Scripps Research Institute */ #ifndef VINA_GRID_H #define VINA_GRID_H #include "array3d.h" #include "grid_dim.h" #include "curl.h" class grid { // FIXME rm 'm_', consistent with my new style vec m_init; vec m_range; vec m_factor; vec m_dim_fl_minus_1; vec m_factor_inv; public: array3d m_data; // FIXME? - make cache a friend, and convert this back to private? grid() : m_init(0, 0, 0), m_range(1, 1, 1), m_factor(1, 1, 1), m_dim_fl_minus_1(-1, -1, -1), m_factor_inv(1, 1, 1) {} // not private grid(const grid_dims& gd) { init(gd); } void init(const grid_dims& gd); vec index_to_argument(sz x, sz y, sz z) const { return vec(m_init[0] + m_factor_inv[0] * x, m_init[1] + m_factor_inv[1] * y, m_init[2] + m_factor_inv[2] * z); } bool initialized() const { return m_data.dim0() > 0 && m_data.dim1() > 0 && m_data.dim2() > 0; } fl evaluate(const vec& location, fl slope, fl c) const { return evaluate_aux(location, slope, c, NULL); } fl evaluate(const vec& location, fl slope, fl c, vec& deriv) const { return evaluate_aux(location, slope, c, &deriv); } // sets deriv private: fl evaluate_aux(const vec& location, fl slope, fl v, vec* deriv) const; // sets *deriv if not NULL friend class boost::serialization::access; template void serialize(Archive& ar, const unsigned version) { ar & m_init; ar & m_data; ar & m_range; ar & m_factor; ar & m_dim_fl_minus_1; ar & m_factor_inv; } }; #endif autodock-vina-1.1.2/src/lib/incrementable.h0000744000175000017500000000157511562571364020500 0ustar moellermoeller/* Copyright (c) 2006-2010, The Scripps Research Institute Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Author: Dr. Oleg Trott , The Olson Lab, The Scripps Research Institute */ #ifndef VINA_INCREMENTABLE_H #define VINA_INCREMENTABLE_H struct incrementable { virtual void operator++() = 0; }; #endif autodock-vina-1.1.2/src/lib/scoring_function.h0000744000175000017500000000215511562571364021234 0ustar moellermoeller/* Copyright (c) 2006-2010, The Scripps Research Institute Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Author: Dr. Oleg Trott , The Olson Lab, The Scripps Research Institute */ #ifndef VINA_SCORING_FUNCTION_H #define VINA_SCORING_FUNCTION_H #include "atom_type.h" struct model; // forward declaration struct scoring_function { virtual atom_type::t atom_typing_used() const = 0; virtual fl cutoff() const = 0; virtual fl eval(sz t1, sz t2, fl r) const = 0; virtual fl conf_independent(const model& m, fl e) const = 0; }; #endif autodock-vina-1.1.2/src/lib/quasi_newton.h0000744000175000017500000000222311562571364020373 0ustar moellermoeller/* Copyright (c) 2006-2010, The Scripps Research Institute Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Author: Dr. Oleg Trott , The Olson Lab, The Scripps Research Institute */ #ifndef VINA_QUASI_NEWTON_H #define VINA_QUASI_NEWTON_H #include "model.h" struct quasi_newton { unsigned max_steps; fl average_required_improvement; quasi_newton() : max_steps(1000), average_required_improvement(0.0) {} // clean up void operator()(model& m, const precalculate& p, const igrid& ig, output_type& out, change& g, const vec& v) const; // g must have correct size }; #endif autodock-vina-1.1.2/src/lib/quasi_newton.cpp0000744000175000017500000000264411562571364020735 0ustar moellermoeller/* Copyright (c) 2006-2010, The Scripps Research Institute Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Author: Dr. Oleg Trott , The Olson Lab, The Scripps Research Institute */ #include "quasi_newton.h" #include "bfgs.h" struct quasi_newton_aux { model* m; const precalculate* p; const igrid* ig; const vec v; quasi_newton_aux(model* m_, const precalculate* p_, const igrid* ig_, const vec& v_) : m(m_), p(p_), ig(ig_), v(v_) {} fl operator()(const conf& c, change& g) { const fl tmp = m->eval_deriv(*p, *ig, v, c, g); return tmp; } }; void quasi_newton::operator()(model& m, const precalculate& p, const igrid& ig, output_type& out, change& g, const vec& v) const { // g must have correct size quasi_newton_aux aux(&m, &p, &ig, v); fl res = bfgs(aux, out.c, g, max_steps, average_required_improvement, 10); out.e = res; } autodock-vina-1.1.2/src/lib/recent_history.h0000744000175000017500000000306511562571364020725 0ustar moellermoeller/* Copyright (c) 2006-2010, The Scripps Research Institute Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Author: Dr. Oleg Trott , The Olson Lab, The Scripps Research Institute */ #ifndef VINA_RECENT_HISTORY_H #define VINA_RECENT_HISTORY_H // Used by manifold, which itself is only used in "design" #include "common.h" struct recent_history { recent_history(fl initial_x_estimate, fl initial_error_estimate, fl lifetime) : x_estimate(initial_x_estimate), error_estimate_sqr(sqr(initial_error_estimate)), weight(1/(std::max)(fl(1.5), lifetime)) {} void add(fl x) { fl this_error_sqr = sqr(x - x_estimate); error_estimate_sqr = weight * this_error_sqr + (1 - weight) * error_estimate_sqr; x_estimate = weight * x + (1 - weight) * x_estimate; } bool possibly_smaller_than(fl x) const { if(x_estimate < x) return true; return sqr(x - x_estimate) < 4 * error_estimate_sqr; } private: fl x_estimate; fl error_estimate_sqr; fl weight; }; #endif autodock-vina-1.1.2/src/lib/parse_pdbqt.h0000744000175000017500000000207611562571364020171 0ustar moellermoeller/* Copyright (c) 2006-2010, The Scripps Research Institute Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Author: Dr. Oleg Trott , The Olson Lab, The Scripps Research Institute */ #ifndef VINA_PARSE_PDBQT_H #define VINA_PARSE_PDBQT_H #include "model.h" model parse_receptor_pdbqt(const path& rigid, const path& flex); // can throw parse_error model parse_receptor_pdbqt(const path& rigid); // can throw parse_error model parse_ligand_pdbqt (const path& name); // can throw parse_error #endif autodock-vina-1.1.2/src/lib/parallel_progress.cpp0000744000175000017500000000155211562571364021736 0ustar moellermoeller/* Copyright (c) 2006-2010, The Scripps Research Institute Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Author: Dr. Oleg Trott , The Olson Lab, The Scripps Research Institute */ #include "parallel_progress.h" //#include // FIXME do we need this? // FIXME rmautodock-vina-1.1.2/src/lib/atom.h0000744000175000017500000000420011562571364016614 0ustar moellermoeller/* Copyright (c) 2006-2010, The Scripps Research Institute Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Author: Dr. Oleg Trott , The Olson Lab, The Scripps Research Institute */ #ifndef VINA_ATOM_H #define VINA_ATOM_H #include "atom_base.h" struct atom_index { sz i; bool in_grid; atom_index() : i(max_sz), in_grid(false) {} atom_index(sz i_, bool in_grid_) : i(i_), in_grid(in_grid_) {} private: friend class boost::serialization::access; template void serialize(Archive& ar, const unsigned version) { ar & i; ar & in_grid; } }; inline bool operator==(const atom_index& i, const atom_index& j) { return i.i == j.i && i.in_grid == j.in_grid; } struct bond { atom_index connected_atom_index; fl length; bool rotatable; bond() : length(0), rotatable(false) {} bond(const atom_index& connected_atom_index_, fl length_, bool rotatable_) : connected_atom_index(connected_atom_index_), length(length_), rotatable(rotatable_) {} private: friend class boost::serialization::access; template void serialize(Archive& ar, const unsigned version) { ar & connected_atom_index; ar & length; ar & rotatable; } }; struct atom : public atom_base { vec coords; std::vector bonds; atom() : coords(max_vec) {} private: friend class boost::serialization::access; template void serialize(Archive& ar, const unsigned version) { ar & boost::serialization::base_object(*this); ar & coords; ar & bonds; } }; typedef std::vector atomv; #endif autodock-vina-1.1.2/src/lib/int_pow.h0000744000175000017500000000204711562571364017342 0ustar moellermoeller/* Copyright (c) 2006-2010, The Scripps Research Institute Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Author: Dr. Oleg Trott , The Olson Lab, The Scripps Research Institute */ #ifndef VINA_INT_POW_H #define VINA_INT_POW_H #include "common.h" // for fl template inline fl int_pow(fl x) { return int_pow(x)*x; // tests seem to suggest that even for largish n's this optimizes well } template<> inline fl int_pow<0>(fl x) { return 1; } #endif autodock-vina-1.1.2/src/lib/parallel.h0000744000175000017500000001234311562571364017457 0ustar moellermoeller/* Copyright (c) 2006-2010, The Scripps Research Institute Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Author: Dr. Oleg Trott , The Olson Lab, The Scripps Research Institute */ #ifndef VINA_PARALLEL_H #define VINA_PARALLEL_H #include #include "common.h" #include #include #include #include template struct parallel_for : private boost::thread_group { parallel_for(const F* f, sz num_threads) : m_f(f), destructing(false), size(0), thread_finished(num_threads, true), count_finished(0), num_threads(num_threads) { VINA_FOR(i, num_threads) create_thread(aux(i, this)); } void run(sz size_) { boost::mutex::scoped_lock self_lk(self); size = size_; count_finished = 0; VINA_FOR_IN(i, thread_finished) thread_finished[i] = false; cond.notify_all(); // many things modified while(count_finished < num_threads) // wait until processing of all elements is thread_finished busy.wait(self_lk); } virtual ~parallel_for() { { boost::mutex::scoped_lock self_lk(self); destructing = true; cond.notify_all(); // destructing modified } join_all(); } private: void loop(sz offset) { while(boost::optional sz_option = get_size(offset)) { sz s = sz_option.get(); for(sz i = offset; i < s; i += num_threads) (*m_f)(i); { boost::mutex::scoped_lock self_lk(self); thread_finished[offset] = true; ++count_finished; busy.notify_one(); } } } struct aux { sz offset; parallel_for* par; aux(sz offset, parallel_for* par) : offset(offset), par(par) {} void operator()() const { par->loop(offset); } }; const F* m_f; // does not keep a local copy! boost::condition cond; boost::condition busy; bool destructing; // dtor called sz size; // size of the vector given to run() std::vector thread_finished; sz count_finished; sz num_threads; boost::mutex self; // any modification or reading of mutables should lock this first boost::optional get_size(sz offset) { boost::mutex::scoped_lock self_lk(self); while(!destructing && thread_finished[offset]) cond.wait(self_lk); if(destructing) return boost::optional(); // wrap it up! return size; } }; template struct parallel_for : private boost::thread_group { parallel_for(const F* f, sz num_threads) : m_f(f), destructing(false), size(0), started(0), finished(0) { a.par = this; // VC8 warning workaround VINA_FOR(i, num_threads) create_thread(boost::ref(a)); } void run(sz size_) { boost::mutex::scoped_lock self_lk(self); size = size_; finished = 0; started = 0; cond.notify_all(); // many things modified while(finished < size) // wait until processing of all elements is finished busy.wait(self_lk); } virtual ~parallel_for() { { boost::mutex::scoped_lock self_lk(self); destructing = true; cond.notify_all(); // destructing modified } join_all(); } private: void loop() { while(boost::optional i = get_next()) { (*m_f)(i.get()); { boost::mutex::scoped_lock self_lk(self); ++finished; busy.notify_one(); } } } struct aux { parallel_for* par; aux() : par(NULL) {} void operator()() const { par->loop(); } }; aux a; const F* m_f; // does not keep a local copy! boost::condition cond; boost::condition busy; bool destructing; // dtor called sz size; // size of the vector given to run() // FIXME? sz started; // the number of jobs given to run() the work started on sz finished; // the number of jobs given to run() the work finished on boost::mutex self; // any modification or reading of mutables should lock this first boost::optional get_next() { boost::mutex::scoped_lock self_lk(self); while(!destructing && started >= size) cond.wait(self_lk); if(destructing) return boost::optional(); // NOTHING sz tmp = started; ++started; return tmp; } }; template struct parallel_iter { parallel_iter(const F* f, sz num_threads) : a(f), pf(&a, num_threads) {} void run(Container& v) { a.v = &v; pf.run(v.size()); } private: struct aux { const F* f; Container* v; aux(const F* f) : f(f), v(NULL) {} void operator()(sz i) const { VINA_CHECK(v); (*f)((*v)[i]); } }; aux a; parallel_for pf; }; #endif autodock-vina-1.1.2/src/lib/coords.h0000744000175000017500000000211611562571364017151 0ustar moellermoeller/* Copyright (c) 2006-2010, The Scripps Research Institute Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Author: Dr. Oleg Trott , The Olson Lab, The Scripps Research Institute */ #ifndef VINA_COORDS_H #define VINA_COORDS_H #include "conf.h" #include "atom.h" // for atomv fl rmsd_upper_bound(const vecv& a, const vecv& b); std::pair find_closest(const vecv& a, const output_container& b); void add_to_output_container(output_container& out, const output_type& t, fl min_rmsd, sz max_size); #endif autodock-vina-1.1.2/src/lib/parse_pdbqt.cpp0000744000175000017500000005363011562571364020526 0ustar moellermoeller/* Copyright (c) 2006-2010, The Scripps Research Institute Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Author: Dr. Oleg Trott , The Olson Lab, The Scripps Research Institute */ #include // for getline ? #include // in parse_two_unsigneds #include // isspace #include // for noncopyable #include #include #include #include "parse_pdbqt.h" #include "atom_constants.h" #include "file.h" #include "convert_substring.h" #include "parse_error.h" struct stream_parse_error { unsigned line; std::string reason; stream_parse_error(unsigned line_, const std::string& reason_) : line(line_), reason(reason_) {} parse_error to_parse_error(const path& name) const { return parse_error(name, line, reason); } }; struct parsed_atom : public atom { unsigned number; parsed_atom(sz ad_, fl charge_, const vec& coords_, unsigned number_) : number(number_) { ad = ad_; charge = charge_; coords = coords_; } }; void add_context(context& c, std::string& str) { c.push_back(parsed_line(str, boost::optional())); } std::string omit_whitespace(const std::string& str, sz i, sz j) { if(i < 1) i = 1; if(j < i-1) j = i-1; // i >= 1 if(j < str.size()) j = str.size(); // omit leading whitespace while(i <= j && std::isspace(str[i-1])) ++i; // omit trailing whitespace while(i <= j && std::isspace(str[j-1])) --j; VINA_CHECK(i-1 < str.size()); VINA_CHECK(j-i+1 < str.size()); return str.substr(i-1, j-i+1); } struct atom_syntax_error { std::string nature; atom_syntax_error(const std::string& nature_) : nature(nature_) {} }; template T checked_convert_substring(const std::string& str, sz i, sz j, const std::string& dest_nature) { VINA_CHECK(i >= 1); VINA_CHECK(i <= j+1); if(j > str.size()) throw atom_syntax_error("The line is too short"); // omit leading whitespace while(i <= j && std::isspace(str[i-1])) ++i; const std::string substr = str.substr(i-1, j-i+1); try { return boost::lexical_cast(substr); } catch(...) { throw atom_syntax_error(std::string("\"") + substr + "\" is not a valid " + dest_nature); } } parsed_atom parse_pdbqt_atom_string(const std::string& str) { unsigned number = checked_convert_substring(str, 7, 11, "atom number"); vec coords(checked_convert_substring(str, 31, 38, "coordinate"), checked_convert_substring(str, 39, 46, "coordinate"), checked_convert_substring(str, 47, 54, "coordinate")); fl charge = 0; if(!substring_is_blank(str, 69, 76)) charge = checked_convert_substring(str, 69, 76, "charge"); std::string name = omit_whitespace(str, 78, 79); sz ad = string_to_ad_type(name); parsed_atom tmp(ad, charge, coords, number); if(is_non_ad_metal_name(name)) tmp.xs = XS_TYPE_Met_D; if(tmp.acceptable_type()) return tmp; else throw atom_syntax_error(std::string("\"") + name + "\" is not a valid AutoDock type. Note that AutoDock atom types are case-sensitive."); } struct atom_reference { sz index; bool inflex; atom_reference(sz index_, bool inflex_) : index(index_), inflex(inflex_) {} }; struct movable_atom : public atom { vec relative_coords; movable_atom(const atom& a, const vec& relative_coords_) : atom(a) { relative_coords = relative_coords_; } }; struct rigid { atomv atoms; }; typedef std::vector mav; struct non_rigid_parsed { vector_mutable ligands; vector_mutable flex; mav atoms; atomv inflex; distance_type_matrix atoms_atoms_bonds; matrix atoms_inflex_bonds; distance_type_matrix inflex_inflex_bonds; distance_type_matrix mobility_matrix() const { distance_type_matrix tmp(atoms_atoms_bonds); tmp.append(atoms_inflex_bonds, inflex_inflex_bonds); return tmp; } }; struct parsing_struct { // start reading after this class template // T == parsing_struct struct node_t { sz context_index; parsed_atom a; std::vector ps; node_t(const parsed_atom& a_, sz context_index_) : context_index(context_index_), a(a_) {} // inflex atom insertion void insert_inflex(non_rigid_parsed& nr) { VINA_FOR_IN(i, ps) ps[i].axis_begin = atom_reference(nr.inflex.size(), true); nr.inflex.push_back(a); } void insert_immobiles_inflex(non_rigid_parsed& nr) { VINA_FOR_IN(i, ps) ps[i].insert_immobile_inflex(nr); } // insertion into non_rigid_parsed void insert(non_rigid_parsed& nr, context& c, const vec& frame_origin) { VINA_FOR_IN(i, ps) ps[i].axis_begin = atom_reference(nr.atoms.size(), false); vec relative_coords; relative_coords = a.coords - frame_origin; c[context_index].second = nr.atoms.size(); nr.atoms.push_back(movable_atom(a, relative_coords)); } void insert_immobiles(non_rigid_parsed& nr, context& c, const vec& frame_origin) { VINA_FOR_IN(i, ps) ps[i].insert_immobile(nr, c, frame_origin); } }; typedef node_t node; boost::optional immobile_atom; // which of `atoms' is immobile, if any boost::optional axis_begin; // the index (in non_rigid_parsed::atoms) of the parent bound to immobile atom (if already known) boost::optional axis_end; // if immobile atom has been pushed into non_rigid_parsed::atoms, this is its index there std::vector atoms; void add(const parsed_atom& a, const context& c) { VINA_CHECK(c.size() > 0); atoms.push_back(node(a, c.size()-1)); } const vec& immobile_atom_coords() const { VINA_CHECK(immobile_atom); VINA_CHECK(immobile_atom.get() < atoms.size()); return atoms[immobile_atom.get()].a.coords; } // inflex insertion void insert_immobile_inflex(non_rigid_parsed& nr) { if(!atoms.empty()) { VINA_CHECK(immobile_atom); VINA_CHECK(immobile_atom.get() < atoms.size()); axis_end = atom_reference(nr.inflex.size(), true); atoms[immobile_atom.get()].insert_inflex(nr); } } // insertion into non_rigid_parsed void insert_immobile(non_rigid_parsed& nr, context& c, const vec& frame_origin) { if(!atoms.empty()) { VINA_CHECK(immobile_atom); VINA_CHECK(immobile_atom.get() < atoms.size()); axis_end = atom_reference(nr.atoms.size(), false); atoms[immobile_atom.get()].insert(nr, c, frame_origin); } } bool essentially_empty() const { // no sub-branches besides immobile atom, including sub-sub-branches, etc VINA_FOR_IN(i, atoms) { if(immobile_atom && immobile_atom.get() != i) return false; const node& nd = atoms[i]; if(!nd.ps.empty()) return false; // FIXME : iffy } return true; } }; unsigned parse_one_unsigned(const std::string& str, const std::string& start, unsigned count) { std::istringstream in_str(str.substr(start.size())); int tmp; in_str >> tmp; if(!in_str || tmp < 0) throw stream_parse_error(count, "Syntax error"); return unsigned(tmp); } void parse_two_unsigneds(const std::string& str, const std::string& start, unsigned count, unsigned& first, unsigned& second) { std::istringstream in_str(str.substr(start.size())); int tmp1, tmp2; in_str >> tmp1; in_str >> tmp2; if(!in_str || tmp1 < 0 || tmp2 < 0) throw stream_parse_error(count, "Syntax error"); first = unsigned(tmp1); second = unsigned(tmp2); } void parse_pdbqt_rigid(const path& name, rigid& r) { ifile in(name); unsigned count = 0; std::string str; while(std::getline(in, str)) { ++count; if(str.empty()) {} // ignore "" else if(starts_with(str, "TER")) {} // ignore else if(starts_with(str, "WARNING")) {} // ignore - AutoDockTools bug workaround else if(starts_with(str, "REMARK")) {} // ignore else if(starts_with(str, "ATOM ") || starts_with(str, "HETATM")) { try { r.atoms.push_back(parse_pdbqt_atom_string(str)); } catch(atom_syntax_error& e) { throw parse_error(name, count, "ATOM syntax incorrect: " + e.nature); } catch(...) { throw parse_error(name, count, "ATOM syntax incorrect"); } } else if(starts_with(str, "MODEL")) throw stream_parse_error(count, "Unexpected multi-MODEL input. Use \"vina_split\" first?"); else throw parse_error(name, count, "Unknown or inappropriate tag"); } } void parse_pdbqt_root_aux(std::istream& in, unsigned& count, parsing_struct& p, context& c) { std::string str; while(std::getline(in, str)) { add_context(c, str); ++count; if(str.empty()) {} // ignore "" else if(starts_with(str, "WARNING")) {} // ignore - AutoDockTools bug workaround else if(starts_with(str, "REMARK")) {} // ignore else if(starts_with(str, "ATOM ") || starts_with(str, "HETATM")) { try { p.add(parse_pdbqt_atom_string(str), c); } catch(atom_syntax_error& e) { throw stream_parse_error(count, "ATOM syntax incorrect: " + e.nature); } catch(...) { throw stream_parse_error(count, "ATOM syntax incorrect"); } } else if(starts_with(str, "ENDROOT")) return; else if(starts_with(str, "MODEL")) throw stream_parse_error(count, "Unexpected multi-MODEL input. Use \"vina_split\" first?"); else throw stream_parse_error(count, "Unknown or inappropriate tag"); } } void parse_pdbqt_root(std::istream& in, unsigned& count, parsing_struct& p, context& c) { std::string str; while(std::getline(in, str)) { add_context(c, str); ++count; if(str.empty()) {} // ignore else if(starts_with(str, "WARNING")) {} // ignore - AutoDockTools bug workaround else if(starts_with(str, "REMARK")) {} // ignore else if(starts_with(str, "ROOT")) { parse_pdbqt_root_aux(in, count, p, c); break; } else if(starts_with(str, "MODEL")) throw stream_parse_error(count, "Unexpected multi-MODEL input. Use \"vina_split\" first?"); else throw stream_parse_error(count, "Unknown or inappropriate tag"); } } void parse_pdbqt_branch(std::istream& in, unsigned& count, parsing_struct& p, context& c, unsigned from, unsigned to); // forward declaration void parse_pdbqt_branch_aux(std::istream& in, unsigned& count, const std::string& str, parsing_struct& p, context& c) { unsigned first, second; parse_two_unsigneds(str, "BRANCH", count, first, second); sz i = 0; for(; i < p.atoms.size(); ++i) if(p.atoms[i].a.number == first) { p.atoms[i].ps.push_back(parsing_struct()); parse_pdbqt_branch(in, count, p.atoms[i].ps.back(), c, first, second); break; } if(i == p.atoms.size()) throw stream_parse_error(count, "No atom number " + boost::lexical_cast(first) + " in this branch"); } void parse_pdbqt_aux(std::istream& in, unsigned& count, parsing_struct& p, context& c, boost::optional& torsdof, bool residue) { parse_pdbqt_root(in, count, p, c); std::string str; while(std::getline(in, str)) { add_context(c, str); ++count; if(str.empty()) {} // ignore "" else if(starts_with(str, "WARNING")) {} // ignore - AutoDockTools bug workaround else if(starts_with(str, "REMARK")) {} // ignore else if(starts_with(str, "BRANCH")) parse_pdbqt_branch_aux(in, count, str, p, c); else if(!residue && starts_with(str, "TORSDOF")) { if(torsdof) throw stream_parse_error(count, "TORSDOF can occur only once"); torsdof = parse_one_unsigned(str, "TORSDOF", count); } else if(residue && starts_with(str, "END_RES")) return; else if(starts_with(str, "MODEL")) throw stream_parse_error(count, "Unexpected multi-MODEL input. Use \"vina_split\" first?"); else throw stream_parse_error(count, "Unknown or inappropriate tag"); } } void add_bonds(non_rigid_parsed& nr, boost::optional atm, const atom_range& r) { if(atm) VINA_RANGE(i, r.begin, r.end) { atom_reference& ar = atm.get(); if(ar.inflex) nr.atoms_inflex_bonds(i, ar.index) = DISTANCE_FIXED; //(max_unsigned); // first index - atoms, second index - inflex else nr.atoms_atoms_bonds(ar.index, i) = DISTANCE_FIXED; // (max_unsigned); } } void set_rotor(non_rigid_parsed& nr, boost::optional axis_begin, boost::optional axis_end) { if(axis_begin && axis_end) { atom_reference& r1 = axis_begin.get(); atom_reference& r2 = axis_end .get(); if(r2.inflex) { VINA_CHECK(r1.inflex); // no atom-inflex rotors nr.inflex_inflex_bonds(r1.index, r2.index) = DISTANCE_ROTOR; } else if(r1.inflex) nr.atoms_inflex_bonds(r2.index, r1.index) = DISTANCE_ROTOR; // (atoms, inflex) else nr.atoms_atoms_bonds(r1.index, r2.index) = DISTANCE_ROTOR; } } typedef std::pair axis_numbers; typedef boost::optional axis_numbers_option; void nr_update_matrixes(non_rigid_parsed& nr) { // atoms with indexes p.axis_begin and p.axis_end can not move relative to [b.node.begin, b.node.end) nr.atoms_atoms_bonds.resize(nr.atoms.size(), DISTANCE_VARIABLE); nr.atoms_inflex_bonds.resize(nr.atoms.size(), nr.inflex.size(), DISTANCE_VARIABLE); // first index - inflex, second index - atoms nr.inflex_inflex_bonds.resize(nr.inflex.size(), DISTANCE_FIXED); // FIXME? } template // B == branch or main_branch or flexible_body void postprocess_branch(non_rigid_parsed& nr, parsing_struct& p, context& c, B& b) { b.node.begin = nr.atoms.size(); VINA_FOR_IN(i, p.atoms) { // postprocess atoms into 'b.node' parsing_struct::node& p_node = p.atoms[i]; if(p.immobile_atom && i == p.immobile_atom.get()) {} // skip immobile_atom - it's already inserted in "THERE" else p_node.insert(nr, c, b.node.get_origin()); p_node.insert_immobiles(nr, c, b.node.get_origin()); } b.node.end = nr.atoms.size(); nr_update_matrixes(nr); add_bonds(nr, p.axis_begin, b.node); // b.node is used as atom_range add_bonds(nr, p.axis_end , b.node); // b.node is used as atom_range set_rotor(nr, p.axis_begin, p.axis_end); VINA_RANGE(i, b.node.begin, b.node.end) VINA_RANGE(j, i+1, b.node.end) nr.atoms_atoms_bonds(i, j) = DISTANCE_FIXED; // FIXME VINA_FOR_IN(i, p.atoms) { // postprocess children parsing_struct::node& p_node = p.atoms[i]; VINA_FOR_IN(j, p_node.ps) { parsing_struct& ps = p_node.ps[j]; if(!ps.essentially_empty()) { // immobile already inserted // FIXME ?! b.children.push_back(segment(ps.immobile_atom_coords(), 0, 0, p_node.a.coords, b.node)); // postprocess_branch will assign begin and end postprocess_branch(nr, ps, c, b.children.back()); } } } VINA_CHECK(nr.atoms_atoms_bonds.dim() == nr.atoms.size()); VINA_CHECK(nr.atoms_inflex_bonds.dim_1() == nr.atoms.size()); VINA_CHECK(nr.atoms_inflex_bonds.dim_2() == nr.inflex.size()); } void postprocess_ligand(non_rigid_parsed& nr, parsing_struct& p, context& c, unsigned torsdof) { VINA_CHECK(!p.atoms.empty()); nr.ligands.push_back(ligand(flexible_body(rigid_body(p.atoms[0].a.coords, 0, 0)), torsdof)); // postprocess_branch will assign begin and end postprocess_branch(nr, p, c, nr.ligands.back()); nr_update_matrixes(nr); // FIXME ? } void postprocess_residue(non_rigid_parsed& nr, parsing_struct& p, context& c) { VINA_FOR_IN(i, p.atoms) { // iterate over "root" of a "residue" parsing_struct::node& p_node = p.atoms[i]; p_node.insert_inflex(nr); p_node.insert_immobiles_inflex(nr); } VINA_FOR_IN(i, p.atoms) { // iterate over "root" of a "residue" parsing_struct::node& p_node = p.atoms[i]; VINA_FOR_IN(j, p_node.ps) { parsing_struct& ps = p_node.ps[j]; if(!ps.essentially_empty()) { // immobile atom already inserted // FIXME ?! nr.flex.push_back(main_branch(first_segment(ps.immobile_atom_coords(), 0, 0, p_node.a.coords))); // postprocess_branch will assign begin and end postprocess_branch(nr, ps, c, nr.flex.back()); } } } nr_update_matrixes(nr); // FIXME ? VINA_CHECK(nr.atoms_atoms_bonds.dim() == nr.atoms.size()); VINA_CHECK(nr.atoms_inflex_bonds.dim_1() == nr.atoms.size()); VINA_CHECK(nr.atoms_inflex_bonds.dim_2() == nr.inflex.size()); } void parse_pdbqt_ligand(const path& name, non_rigid_parsed& nr, context& c) { ifile in(name); unsigned count = 0; parsing_struct p; boost::optional torsdof; try { parse_pdbqt_aux(in, count, p, c, torsdof, false); if(p.atoms.empty()) throw parse_error(name, count, "No atoms in the ligand"); if(!torsdof) throw parse_error(name, count, "Missing TORSDOF"); postprocess_ligand(nr, p, c, unsigned(torsdof.get())); // bizarre size_t -> unsigned compiler complaint } catch(stream_parse_error& e) { throw e.to_parse_error(name); } VINA_CHECK(nr.atoms_atoms_bonds.dim() == nr.atoms.size()); } void parse_pdbqt_residue(std::istream& in, unsigned& count, parsing_struct& p, context& c) { boost::optional dummy; parse_pdbqt_aux(in, count, p, c, dummy, true); } void parse_pdbqt_flex(const path& name, non_rigid_parsed& nr, context& c) { ifile in(name); unsigned count = 0; std::string str; while(std::getline(in, str)) { add_context(c, str); ++count; if(str.empty()) {} // ignore "" else if(starts_with(str, "WARNING")) {} // ignore - AutoDockTools bug workaround else if(starts_with(str, "REMARK")) {} // ignore else if(starts_with(str, "BEGIN_RES")) { try { parsing_struct p; parse_pdbqt_residue(in, count, p, c); postprocess_residue(nr, p, c); } catch(stream_parse_error& e) { throw e.to_parse_error(name); } } else if(starts_with(str, "MODEL")) throw stream_parse_error(count, "Unexpected multi-MODEL input. Use \"vina_split\" first?"); else throw parse_error(name, count, "Unknown or inappropriate tag"); } VINA_CHECK(nr.atoms_atoms_bonds.dim() == nr.atoms.size()); } void parse_pdbqt_branch(std::istream& in, unsigned& count, parsing_struct& p, context& c, unsigned from, unsigned to) { std::string str; while(std::getline(in, str)) { add_context(c, str); ++count; if(str.empty()) {} //ignore "" else if(starts_with(str, "WARNING")) {} // ignore - AutoDockTools bug workaround else if(starts_with(str, "REMARK")) {} // ignore else if(starts_with(str, "BRANCH")) parse_pdbqt_branch_aux(in, count, str, p, c); else if(starts_with(str, "ENDBRANCH")) { unsigned first, second; parse_two_unsigneds(str, "ENDBRANCH", count, first, second); if(first != from || second != to) throw stream_parse_error(count, "Inconsistent branch numbers"); if(!p.immobile_atom) throw stream_parse_error(count, "Atom " + boost::lexical_cast(to) + " has not been found in this branch"); return; } else if(starts_with(str, "ATOM ") || starts_with(str, "HETATM")) { try { parsed_atom a = parse_pdbqt_atom_string(str); if(a.number == to) p.immobile_atom = p.atoms.size(); p.add(a, c); } catch(atom_syntax_error& e) { throw stream_parse_error(count, "ATOM syntax incorrect: " + e.nature); } catch(...) { throw stream_parse_error(count, "ATOM syntax incorrect"); } } else if(starts_with(str, "MODEL")) throw stream_parse_error(count, "Unexpected multi-MODEL input. Use \"vina_split\" first?"); else throw stream_parse_error(count, "Unknown or inappropriate tag"); } } //////////// new stuff ////////////////// struct pdbqt_initializer { model m; void initialize_from_rigid(const rigid& r) { // static really VINA_CHECK(m.grid_atoms.empty()); m.grid_atoms = r.atoms; } void initialize_from_nrp(const non_rigid_parsed& nrp, const context& c, bool is_ligand) { // static really VINA_CHECK(m.ligands.empty()); VINA_CHECK(m.flex .empty()); m.ligands = nrp.ligands; m.flex = nrp.flex; VINA_CHECK(m.atoms.empty()); sz n = nrp.atoms.size() + nrp.inflex.size(); m.atoms.reserve(n); m.coords.reserve(n); VINA_FOR_IN(i, nrp.atoms) { const movable_atom& a = nrp.atoms[i]; atom b = static_cast(a); b.coords = a.relative_coords; m.atoms.push_back(b); m.coords.push_back(a.coords); } VINA_FOR_IN(i, nrp.inflex) { const atom& a = nrp.inflex[i]; atom b = a; b.coords = zero_vec; // to avoid any confusion; presumably these will never be looked at m.atoms.push_back(b); m.coords.push_back(a.coords); } VINA_CHECK(m.coords.size() == n); m.internal_coords.resize(m.coords.size(), zero_vec); // FIXME m.minus_forces = m.coords; m.m_num_movable_atoms = nrp.atoms.size(); if(is_ligand) { VINA_CHECK(m.ligands.size() == 1); m.ligands.front().cont = c; } else m.flex_context = c; } void initialize(const distance_type_matrix& mobility) { m.initialize(mobility); } }; model parse_ligand_pdbqt (const path& name) { // can throw parse_error non_rigid_parsed nrp; context c; parse_pdbqt_ligand(name, nrp, c); pdbqt_initializer tmp; tmp.initialize_from_nrp(nrp, c, true); tmp.initialize(nrp.mobility_matrix()); return tmp.m; } model parse_receptor_pdbqt(const path& rigid_name, const path& flex_name) { // can throw parse_error rigid r; non_rigid_parsed nrp; context c; parse_pdbqt_rigid(rigid_name, r); parse_pdbqt_flex(flex_name, nrp, c); pdbqt_initializer tmp; tmp.initialize_from_rigid(r); tmp.initialize_from_nrp(nrp, c, false); tmp.initialize(nrp.mobility_matrix()); return tmp.m; } model parse_receptor_pdbqt(const path& rigid_name) { // can throw parse_error rigid r; parse_pdbqt_rigid(rigid_name, r); pdbqt_initializer tmp; tmp.initialize_from_rigid(r); distance_type_matrix mobility_matrix; tmp.initialize(mobility_matrix); return tmp.m; } autodock-vina-1.1.2/src/lib/current_weights.h0000744000175000017500000000164611562571364021103 0ustar moellermoeller/* Copyright (c) 2006-2010, The Scripps Research Institute Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Author: Dr. Oleg Trott , The Olson Lab, The Scripps Research Institute */ #ifndef VINA_CURRENT_WEIGHTS_H #define VINA_CURRENT_WEIGHTS_H #include "terms.h" flv current_weights(const terms& t); // verifies size compatibility with t #endif autodock-vina-1.1.2/src/lib/monte_carlo.cpp0000744000175000017500000001073311562571364020521 0ustar moellermoeller/* Copyright (c) 2006-2010, The Scripps Research Institute Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Author: Dr. Oleg Trott , The Olson Lab, The Scripps Research Institute */ #include "monte_carlo.h" #include "coords.h" #include "mutate.h" #include "quasi_newton.h" output_type monte_carlo::operator()(model& m, const precalculate& p, const igrid& ig, const precalculate& p_widened, const igrid& ig_widened, const vec& corner1, const vec& corner2, incrementable* increment_me, rng& generator) const { output_container tmp; this->operator()(m, tmp, p, ig, p_widened, ig_widened, corner1, corner2, increment_me, generator); // call the version that produces the whole container VINA_CHECK(!tmp.empty()); return tmp.front(); } bool metropolis_accept(fl old_f, fl new_f, fl temperature, rng& generator) { if(new_f < old_f) return true; const fl acceptance_probability = std::exp((old_f - new_f) / temperature); return random_fl(0, 1, generator) < acceptance_probability; } void monte_carlo::single_run(model& m, output_type& out, const precalculate& p, const igrid& ig, rng& generator) const { conf_size s = m.get_size(); change g(s); vec authentic_v(1000, 1000, 1000); out.e = max_fl; output_type current(out); quasi_newton quasi_newton_par; quasi_newton_par.max_steps = ssd_par.evals; VINA_U_FOR(step, num_steps) { output_type candidate(current.c, max_fl); mutate_conf(candidate.c, m, mutation_amplitude, generator); quasi_newton_par(m, p, ig, candidate, g, hunt_cap); if(step == 0 || metropolis_accept(current.e, candidate.e, temperature, generator)) { quasi_newton_par(m, p, ig, candidate, g, authentic_v); current = candidate; if(current.e < out.e) out = current; } } quasi_newton_par(m, p, ig, out, g, authentic_v); } void monte_carlo::many_runs(model& m, output_container& out, const precalculate& p, const igrid& ig, const vec& corner1, const vec& corner2, sz num_runs, rng& generator) const { conf_size s = m.get_size(); VINA_FOR(run, num_runs) { output_type tmp(s, 0); tmp.c.randomize(corner1, corner2, generator); single_run(m, tmp, p, ig, generator); out.push_back(new output_type(tmp)); } out.sort(); } output_type monte_carlo::many_runs(model& m, const precalculate& p, const igrid& ig, const vec& corner1, const vec& corner2, sz num_runs, rng& generator) const { output_container tmp; many_runs(m, tmp, p, ig, corner1, corner2, num_runs, generator); VINA_CHECK(!tmp.empty()); return tmp.front(); } // out is sorted void monte_carlo::operator()(model& m, output_container& out, const precalculate& p, const igrid& ig, const precalculate& p_widened, const igrid& ig_widened, const vec& corner1, const vec& corner2, incrementable* increment_me, rng& generator) const { vec authentic_v(1000, 1000, 1000); // FIXME? this is here to avoid max_fl/max_fl conf_size s = m.get_size(); change g(s); output_type tmp(s, 0); tmp.c.randomize(corner1, corner2, generator); fl best_e = max_fl; quasi_newton quasi_newton_par; quasi_newton_par.max_steps = ssd_par.evals; VINA_U_FOR(step, num_steps) { if(increment_me) ++(*increment_me); output_type candidate = tmp; mutate_conf(candidate.c, m, mutation_amplitude, generator); quasi_newton_par(m, p, ig, candidate, g, hunt_cap); if(step == 0 || metropolis_accept(tmp.e, candidate.e, temperature, generator)) { tmp = candidate; m.set(tmp.c); // FIXME? useless? // FIXME only for very promising ones if(tmp.e < best_e || out.size() < num_saved_mins) { quasi_newton_par(m, p, ig, tmp, g, authentic_v); m.set(tmp.c); // FIXME? useless? tmp.coords = m.get_heavy_atom_movable_coords(); add_to_output_container(out, tmp, min_rmsd, num_saved_mins); // 20 - max size if(tmp.e < best_e) best_e = tmp.e; } } } VINA_CHECK(!out.empty()); VINA_CHECK(out.front().e <= out.back().e); // make sure the sorting worked in the correct order } autodock-vina-1.1.2/src/lib/statistics.h0000744000175000017500000000552711562571364020063 0ustar moellermoeller/* Copyright (c) 2006-2010, The Scripps Research Institute Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Author: Dr. Oleg Trott , The Olson Lab, The Scripps Research Institute */ #ifndef VINA_STATISTICS_H #define VINA_STATISTICS_H #include // sort #include // sqrt #include "common.h" // for flv // simple but inefficient implementations inline fl mean(const flv& v) { fl acc = 0; VINA_FOR_IN(i, v) acc += v[i]; return v.empty() ? 0 : (acc/v.size()); } inline fl deviation(const flv& v) { fl m = mean(v); fl acc = 0; VINA_FOR_IN(i, v) acc += sqr(v[i] - m); return v.empty() ? 0 : std::sqrt(acc/v.size()); } inline fl rmsd(const flv& a, const flv& b) { VINA_CHECK(a.size() == b.size()); fl acc = 0; VINA_FOR_IN(i, a) acc += sqr(a[i] - b[i]); return a.empty() ? 0 : std::sqrt(acc/a.size()); } inline fl average_difference(const flv& b, const flv& a) { // b - a VINA_CHECK(a.size() == b.size()); fl acc = 0; VINA_FOR_IN(i, a) acc += b[i] - a[i]; return a.empty() ? 0 : (acc/a.size()); } inline fl pearson(const flv& x, const flv& y) { sz n = x.size(); VINA_CHECK(n == y.size()); if(n == 0) return 0; // ? fl sum_x = 0; fl sum_y = 0; fl sum_x_sq = 0; fl sum_y_sq = 0; fl sum_prod = 0; VINA_FOR(i, n) { sum_x += x[i]; sum_y += y[i]; sum_x_sq += sqr(x[i]); sum_y_sq += sqr(y[i]); sum_prod += x[i] * y[i]; } fl sd_x = std::sqrt(sum_x_sq/n - sqr(sum_x/n)); // FIXME the argument is supposed to be >= 0, but ... fl sd_y = std::sqrt(sum_y_sq/n - sqr(sum_y/n)); fl cov = sum_prod/n - (sum_x/n) * (sum_y/n); fl tmp = sd_x * sd_y; if(std::abs(tmp) < epsilon_fl) return 0; // ? return cov / tmp; } struct spearman_aux { fl x; sz i; spearman_aux(fl x, sz i) : x(x), i(i) {} }; inline bool operator<(const spearman_aux& a, const spearman_aux& b) { return a.x < b.x; } inline flv get_rankings(const flv& x) { std::vector to_sort; VINA_FOR_IN(i, x) to_sort.push_back(spearman_aux(x[i], i)); std::sort(to_sort.begin(), to_sort.end()); flv tmp(x.size(), 0); VINA_FOR_IN(rank, to_sort) tmp[to_sort[rank].i] = rank; return tmp; } inline fl spearman(const flv& x, const flv& y) { return pearson(get_rankings(x), get_rankings(y)); } #endif autodock-vina-1.1.2/src/lib/current_weights.cpp0000744000175000017500000000513111562571364021427 0ustar moellermoeller/* Copyright (c) 2006-2010, The Scripps Research Institute Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Author: Dr. Oleg Trott , The Olson Lab, The Scripps Research Institute */ #include "current_weights.h" flv current_weights(const terms& t) { // verifies size compatibility with t const fl a[] = {-0.035579, -0.005156, 0.840245, -0.035069, -0.587439, 1.923}; // design.out227 //const fl a[] = {-0.035579, -0.005156, 0.840245, -0.035069, 0, -0.587439, 0.3, 0}; // FROM design.out227 (FIXME 0.37) //const fl a[] = {-0.035579, -0.005156, 0.840245, -0.035069, 0, -0.587439, 1.923}; // from design.out227 //const fl a[] = {-0.035579, -0.005156, 0.840245, -0.035069, 0, -0.587439, 0, 0}; // from design.out227 //const fl a[] = { -0.03729492, -0.00447574, 0.49765303, -0.01407780, 0.00604362, -0.37693501, -0.04244564, 0.41294104}; // some optimization //const fl a[] = { -0.06420507, -0.00321022, 0.53200870, -0.00858916, 0.01888147, -0.43265646, -0.15275852, 0.40187766}; //const fl a[] = { -0.26023247, 0.00995843, 3.22632287, -1.03265955, -2.17710460, 21.60339910}; // SOME DEBUGGING FIXME // {-0.059, -0.002, 0.732, -0.045, -0.574, 1.022} //{ -0.04001575, -0.00305351, 0.69244502, -0.05569879, -0.59632554, 1.30150720} //{ -0.05536152, -0.00219298, 0.84076170, -0.05453476, -0.61922654, 1.00723685} //{ -0.04174947, -0.00277397, 0.67397970, -0.05836878, -0.57969306, 1.13869379} // //{ -0.02008723, -0.00412019, 0.60584644, -0.05019072, -0.58100053, 1.30362853} sz n = sizeof(a) / sizeof(const fl); flv tmp; VINA_FOR(i, n) tmp.push_back(a[i]); // FIXME rm sz tmp_size = tmp.size(); sz conf_indep_size = t.size_conf_independent(true); sz t_size = t.size(); sz t_names_size = t.get_names(true).size(); VINA_CHECK(tmp.size() == t.size_conf_independent(true) + t.get_names(true).size()); return tmp; } autodock-vina-1.1.2/src/lib/mutate.cpp0000744000175000017500000000440111562571364017511 0ustar moellermoeller/* Copyright (c) 2006-2010, The Scripps Research Institute Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Author: Dr. Oleg Trott , The Olson Lab, The Scripps Research Institute */ #include "mutate.h" sz count_mutable_entities(const conf& c) { sz counter = 0; VINA_FOR_IN(i, c.ligands) counter += 2 + c.ligands[i].torsions.size(); VINA_FOR_IN(i, c.flex) counter += c.flex[i].torsions.size(); return counter; } // does not set model void mutate_conf(conf& c, const model& m, fl amplitude, rng& generator) { // ONE OF: 2A for position, similar amp for orientation, randomize torsion sz mutable_entities_num = count_mutable_entities(c); if(mutable_entities_num == 0) return; int which_int = random_int(0, int(mutable_entities_num - 1), generator); VINA_CHECK(which_int >= 0); sz which = sz(which_int); VINA_CHECK(which < mutable_entities_num); VINA_FOR_IN(i, c.ligands) { if(which == 0) { c.ligands[i].rigid.position += amplitude * random_inside_sphere(generator); return; } --which; if(which == 0) { fl gr = m.gyration_radius(i); if(gr > epsilon_fl) { // FIXME? just doing nothing for 0-radius molecules. do some other mutation? vec rotation; rotation = amplitude / gr * random_inside_sphere(generator); quaternion_increment(c.ligands[i].rigid.orientation, rotation); } return; } --which; if(which < c.ligands[i].torsions.size()) { c.ligands[i].torsions[which] = random_fl(-pi, pi, generator); return; } which -= c.ligands[i].torsions.size(); } VINA_FOR_IN(i, c.flex) { if(which < c.flex[i].torsions.size()) { c.flex[i].torsions[which] = random_fl(-pi, pi, generator); return; } which -= c.flex[i].torsions.size(); } } autodock-vina-1.1.2/src/lib/ssd.cpp0000744000175000017500000000262311562571364017007 0ustar moellermoeller/* Copyright (c) 2006-2010, The Scripps Research Institute Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Author: Dr. Oleg Trott , The Olson Lab, The Scripps Research Institute */ #include "ssd.h" // clean up void ssd::operator()(model& m, const precalculate& p, const igrid& ig, output_type& out, change& g, const vec& v) const { // g must have correct size out.e = m.eval_deriv(p, ig, v, out.c, g); fl factor = initial_factor; VINA_U_FOR(i, evals) { if(factor < min_factor) break; output_type candidate(out); candidate.c.increment(g, -factor); change candidate_g(g); candidate.e = m.eval_deriv(p, ig, v, candidate.c, candidate_g); if(candidate.e <= out.e) { out = candidate; g = candidate_g; factor *= up; } else { factor *= down; } } out.coords = m.get_heavy_atom_movable_coords(); } autodock-vina-1.1.2/src/lib/grid.cpp0000744000175000017500000001012211562571364017134 0ustar moellermoeller/* Copyright (c) 2006-2010, The Scripps Research Institute Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Author: Dr. Oleg Trott , The Olson Lab, The Scripps Research Institute */ #include "grid.h" void grid::init(const grid_dims& gd) { m_data.resize(gd[0].n+1, gd[1].n+1, gd[2].n+1); m_init = vec(gd[0].begin, gd[1].begin, gd[2].begin); m_range = vec(gd[0].span(), gd[1].span(), gd[2].span()); assert(m_range[0] > 0); assert(m_range[1] > 0); assert(m_range[2] > 0); m_dim_fl_minus_1 = vec(m_data.dim0() - 1.0, m_data.dim1() - 1.0, m_data.dim2() - 1.0); VINA_FOR(i, 3) { m_factor[i] = m_dim_fl_minus_1[i] / m_range[i]; m_factor_inv[i] = 1 / m_factor[i]; } } fl grid::evaluate_aux(const vec& location, fl slope, fl v, vec* deriv) const { // sets *deriv if not NULL vec s = elementwise_product(location - m_init, m_factor); vec miss(0, 0, 0); boost::array region; boost::array a; VINA_FOR(i, 3) { if(s[i] < 0) { miss[i] = -s[i]; region[i] = -1; a[i] = 0; s[i] = 0; } else if(s[i] >= m_dim_fl_minus_1[i]) { miss[i] = s[i] - m_dim_fl_minus_1[i]; region[i] = 1; assert(m_data.dim(i) >= 2); a[i] = m_data.dim(i) - 2; s[i] = 1; } else { region[i] = 0; // now that region is boost::array, it's not initialized a[i] = sz(s[i]); s[i] -= a[i]; } assert(s[i] >= 0); assert(s[i] <= 1); assert(a[i] >= 0); assert(a[i]+1 < m_data.dim(i)); } const fl penalty = slope * (miss * m_factor_inv); // FIXME check that inv_factor is correctly initialized and serialized assert(penalty > -epsilon_fl); const sz x0 = a[0]; const sz y0 = a[1]; const sz z0 = a[2]; const sz x1 = x0+1; const sz y1 = y0+1; const sz z1 = z0+1; const fl f000 = m_data(x0, y0, z0); const fl f100 = m_data(x1, y0, z0); const fl f010 = m_data(x0, y1, z0); const fl f110 = m_data(x1, y1, z0); const fl f001 = m_data(x0, y0, z1); const fl f101 = m_data(x1, y0, z1); const fl f011 = m_data(x0, y1, z1); const fl f111 = m_data(x1, y1, z1); const fl x = s[0]; const fl y = s[1]; const fl z = s[2]; const fl mx = 1-x; const fl my = 1-y; const fl mz = 1-z; fl f = f000 * mx * my * mz + f100 * x * my * mz + f010 * mx * y * mz + f110 * x * y * mz + f001 * mx * my * z + f101 * x * my * z + f011 * mx * y * z + f111 * x * y * z ; if(deriv) { // valid pointer const fl x_g = f000 * (-1)* my * mz + f100 * 1 * my * mz + f010 * (-1)* y * mz + f110 * 1 * y * mz + f001 * (-1)* my * z + f101 * 1 * my * z + f011 * (-1)* y * z + f111 * 1 * y * z ; const fl y_g = f000 * mx *(-1)* mz + f100 * x *(-1)* mz + f010 * mx * 1 * mz + f110 * x * 1 * mz + f001 * mx *(-1)* z + f101 * x *(-1)* z + f011 * mx * 1 * z + f111 * x * 1 * z ; const fl z_g = f000 * mx * my *(-1) + f100 * x * my *(-1) + f010 * mx * y *(-1) + f110 * x * y *(-1) + f001 * mx * my * 1 + f101 * x * my * 1 + f011 * mx * y * 1 + f111 * x * y * 1 ; vec gradient(x_g, y_g, z_g); curl(f, gradient, v); vec gradient_everywhere; VINA_FOR(i, 3) { gradient_everywhere[i] = ((region[i] == 0) ? gradient[i] : 0); (*deriv)[i] = m_factor[i] * gradient_everywhere[i] + slope * region[i]; } return f + penalty; } else { curl(f, v); return f + penalty; } } autodock-vina-1.1.2/src/lib/terms.h0000744000175000017500000001407711562571364017023 0ustar moellermoeller/* Copyright (c) 2006-2010, The Scripps Research Institute Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Author: Dr. Oleg Trott , The Olson Lab, The Scripps Research Institute */ #ifndef VINA_TERMS_H #define VINA_TERMS_H #include #include "model.h" struct term { std::string name; virtual ~term() {} }; struct distance_additive : public term { fl cutoff; distance_additive(fl cutoff_) : cutoff(cutoff_) {} virtual fl eval(const atom_base& a, const atom_base& b, fl r) const = 0; virtual ~distance_additive() {} }; struct usable : public distance_additive { atom_type::t atom_typing_used; usable(fl cutoff_) : distance_additive(cutoff_), atom_typing_used(atom_type::XS) {} fl eval(const atom_base& a, const atom_base& b, fl r) const { // should not be overriden return eval(a.get(atom_typing_used), b.get(atom_typing_used), r); } virtual fl eval(sz t1, sz t2, fl r) const { return 0; } virtual ~usable() {} }; struct additive : public term { fl cutoff; additive() : cutoff(max_fl) {} virtual fl eval(const model& m, const atom_index& i, const atom_index& j) const = 0; virtual ~additive() {} }; struct intermolecular : public term { virtual fl eval(const model& m) const = 0; }; struct conf_independent_inputs { fl num_tors; fl num_rotors; fl num_heavy_atoms; fl num_hydrophobic_atoms; fl ligand_max_num_h_bonds; fl num_ligands; fl ligand_lengths_sum; operator flv() const; conf_independent_inputs(const model& m); std::vector get_names() const; conf_independent_inputs(); private: unsigned num_bonded_heavy_atoms(const model& m, const atom_index& i) const; // FIXME? - could be static, but I don't feel like declaring function friends unsigned atom_rotors(const model& m, const atom_index& i) const; // the number of rotatable bonds to heavy ligand atoms friend class boost::serialization::access; template void serialize(Archive & ar, const unsigned version) { ar & num_tors; ar & num_rotors; ar & num_heavy_atoms; ar & num_hydrophobic_atoms; ar & ligand_max_num_h_bonds; ar & num_ligands; ar & ligand_lengths_sum; } }; struct conf_independent : public term { virtual fl eval(const conf_independent_inputs& in, fl x, flv::const_iterator& it) const = 0; virtual sz size() const = 0; // how many parameters does it take }; template struct term_set { std::vector enabled; boost::ptr_vector fun; // FIXME? const T? void add(unsigned e, T* f) { // FIXME? const T* ? enabled.push_back(e > 0); fun.push_back(f); } sz num_enabled() const { sz tmp = 0; VINA_FOR_IN(i, enabled) if(enabled[i]) ++tmp; return tmp; } void get_names(bool enabled_only, std::vector& out) const { // appends to "out" VINA_CHECK(enabled.size() == fun.size()); VINA_FOR_IN(i, fun) if(!enabled_only || enabled[i]) out.push_back(fun[i].name); } void filter(flv::const_iterator& in, flv& out) const { VINA_CHECK(enabled.size() == fun.size()); VINA_FOR_IN(i, enabled) { if(enabled[i]) out.push_back(*in); ++in; } } fl max_cutoff() const { fl tmp = 0; VINA_FOR_IN(i, fun) tmp = (std::max)(tmp, fun[i].cutoff); return tmp; } sz size() const { return fun.size(); } const T& operator[](sz i) const { return fun[i]; } }; struct factors { flv e; // external flv i; // internal sz size() const { return e.size() + i.size(); } //sz num_weights() const { return (std::max)(e.size(), i.size()); } // FIXME? compiler bug? getting warnings here sz num_weights() const { return (e.size() > i.size()) ? e.size() : i.size(); } fl eval(const flv& weights, bool include_internal) const; private: friend class boost::serialization::access; template void serialize(Archive & ar, const unsigned version) { ar & e; ar & i; } }; struct terms { term_set distance_additive_terms; term_set usable_terms; term_set additive_terms; term_set intermolecular_terms; term_set conf_independent_terms; // the class takes ownership of the pointer with 'add' void add(unsigned e, distance_additive* p) { distance_additive_terms.add(e, p); } void add(unsigned e, usable* p) { usable_terms.add(e, p); } void add(unsigned e, additive* p) { additive_terms.add(e, p); } void add(unsigned e, intermolecular* p) { intermolecular_terms.add(e, p); } void add(unsigned e, conf_independent* p) { conf_independent_terms.add(e, p); } std::vector get_names(bool enabled_only) const; // does not include conf-independent sz size_internal() const; sz size() const { return size_internal() + intermolecular_terms.size(); } sz size_conf_independent(bool enabled_only) const; // number of parameters does not necessarily equal the number of operators fl max_r_cutoff() const; flv evale(const model& m) const; flv evali(const model& m) const; flv evale_robust(const model& m) const; factors eval(const model& m) const; fl eval_conf_independent(const conf_independent_inputs& in, fl x, flv::const_iterator& it) const; flv filter_external(const flv& v) const; flv filter_internal(const flv& v) const; factors filter(const factors& f) const; void display_info() const; private: void eval_additive_aux(const model& m, const atom_index& i, const atom_index& j, fl r, flv& out) const; // out is added to }; #endif autodock-vina-1.1.2/src/lib/weighted_terms.h0000744000175000017500000000252311562571364020674 0ustar moellermoeller/* Copyright (c) 2006-2010, The Scripps Research Institute Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Author: Dr. Oleg Trott , The Olson Lab, The Scripps Research Institute */ #ifndef VINA_WEIGHTED_TERMS_H #define VINA_WEIGHTED_TERMS_H #include "terms.h" struct weighted_terms : public scoring_function { weighted_terms(const terms* t, const flv& weights); // does not own t atom_type::t atom_typing_used() const { return atom_typing_used_; } fl cutoff() const { return cutoff_; } fl eval(sz t1, sz t2, fl r) const; // intentionally not checking for cutoff fl conf_independent(const model& m, fl e) const; private: weighted_terms() {} const terms* t; flv weights; atom_type::t atom_typing_used_; fl cutoff_; szv enabled_usable_terms; }; #endif autodock-vina-1.1.2/src/lib/parallel_mc.cpp0000744000175000017500000000626711562571364020501 0ustar moellermoeller/* Copyright (c) 2006-2010, The Scripps Research Institute Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Author: Dr. Oleg Trott , The Olson Lab, The Scripps Research Institute */ #include "parallel.h" #include "parallel_mc.h" #include "coords.h" #include "parallel_progress.h" struct parallel_mc_task { model m; output_container out; rng generator; parallel_mc_task(const model& m_, int seed) : m(m_), generator(static_cast(seed)) {} }; typedef boost::ptr_vector parallel_mc_task_container; struct parallel_mc_aux { const monte_carlo* mc; const precalculate* p; const igrid* ig; const precalculate* p_widened; const igrid* ig_widened; const vec* corner1; const vec* corner2; parallel_progress* pg; parallel_mc_aux(const monte_carlo* mc_, const precalculate* p_, const igrid* ig_, const precalculate* p_widened_, const igrid* ig_widened_, const vec* corner1_, const vec* corner2_, parallel_progress* pg_) : mc(mc_), p(p_), ig(ig_), p_widened(p_widened_), ig_widened(ig_widened_), corner1(corner1_), corner2(corner2_), pg(pg_) {} void operator()(parallel_mc_task& t) const { (*mc)(t.m, t.out, *p, *ig, *p_widened, *ig_widened, *corner1, *corner2, pg, t.generator); } }; void merge_output_containers(const output_container& in, output_container& out, fl min_rmsd, sz max_size) { VINA_FOR_IN(i, in) add_to_output_container(out, in[i], min_rmsd, max_size); } void merge_output_containers(const parallel_mc_task_container& many, output_container& out, fl min_rmsd, sz max_size) { min_rmsd = 2; // FIXME? perhaps it's necessary to separate min_rmsd during search and during output? VINA_FOR_IN(i, many) merge_output_containers(many[i].out, out, min_rmsd, max_size); out.sort(); } void parallel_mc::operator()(const model& m, output_container& out, const precalculate& p, const igrid& ig, const precalculate& p_widened, const igrid& ig_widened, const vec& corner1, const vec& corner2, rng& generator) const { parallel_progress pp; parallel_mc_aux parallel_mc_aux_instance(&mc, &p, &ig, &p_widened, &ig_widened, &corner1, &corner2, (display_progress ? (&pp) : NULL)); parallel_mc_task_container task_container; VINA_FOR(i, num_tasks) task_container.push_back(new parallel_mc_task(m, random_int(0, 1000000, generator))); if(display_progress) pp.init(num_tasks * mc.num_steps); parallel_iter parallel_iter_instance(¶llel_mc_aux_instance, num_threads); parallel_iter_instance.run(task_container); merge_output_containers(task_container, out, mc.min_rmsd, mc.num_saved_mins); } autodock-vina-1.1.2/src/lib/random.cpp0000744000175000017500000000516011562571364017475 0ustar moellermoeller/* Copyright (c) 2006-2010, The Scripps Research Institute Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Author: Dr. Oleg Trott , The Olson Lab, The Scripps Research Institute */ #include // for time (for seeding) #include "random.h" #include "my_pid.h" fl random_fl(fl a, fl b, rng& generator) { // expects a < b, returns rand in [a, b] assert(a < b); // BOOST also asserts a < b typedef boost::uniform_real distr; boost::variate_generator r(generator, distr(a, b)); fl tmp = r(); assert(tmp >= a); assert(tmp <= b); return tmp; } fl random_normal(fl mean, fl sigma, rng& generator) { // expects sigma >= 0 assert(sigma >= 0); // BOOST asserts this as well typedef boost::normal_distribution distr; boost::variate_generator r(generator, distr(mean, sigma)); return r(); } int random_int(int a, int b, rng& generator) { // expects a <= b, returns rand in [a, b] assert(a <= b); // BOOST asserts this as well typedef boost::uniform_int distr; boost::variate_generator r(generator, distr(a, b)); int tmp = r(); assert(tmp >= a); assert(tmp <= b); return tmp; } sz random_sz(sz a, sz b, rng& generator) { // expects a <= b, returns rand in [a, b] assert(a <= b); assert(int(a) >= 0); assert(int(b) >= 0); int i = random_int(int(a), int(b), generator); assert(i >= 0); assert(i >= int(a)); assert(i <= int(b)); return static_cast(i); } vec random_inside_sphere(rng& generator) { while(true) { // on average, this will have to be run about twice fl r1 = random_fl(-1, 1, generator); fl r2 = random_fl(-1, 1, generator); fl r3 = random_fl(-1, 1, generator); vec tmp(r1, r2, r3); if(sqr(tmp) < 1) return tmp; } } vec random_in_box(const vec& corner1, const vec& corner2, rng& generator) { // expects corner1[i] < corner2[i] vec tmp; VINA_FOR_IN(i, tmp) tmp[i] = random_fl(corner1[i], corner2[i], generator); return tmp; } int auto_seed() { // make seed from PID and time return my_pid() * int(std::time(NULL)); } autodock-vina-1.1.2/src/lib/igrid.h0000744000175000017500000000216711562571364016764 0ustar moellermoeller/* Copyright (c) 2006-2010, The Scripps Research Institute Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Author: Dr. Oleg Trott , The Olson Lab, The Scripps Research Institute */ #ifndef VINA_IGRID_H #define VINA_IGRID_H #include "common.h" struct model; // forward declaration struct igrid { // grids interface (that cache, etc. conform to) virtual fl eval (const model& m, fl v) const = 0; // needs m.coords // clean up virtual fl eval_deriv( model& m, fl v) const = 0; // needs m.coords, sets m.minus_forces // clean up }; #endif autodock-vina-1.1.2/src/lib/triangular_matrix_index.h0000744000175000017500000000222311562571364022602 0ustar moellermoeller/* Copyright (c) 2006-2010, The Scripps Research Institute Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Author: Dr. Oleg Trott , The Olson Lab, The Scripps Research Institute */ #ifndef VINA_TRIANGULAR_MATRIX_INDEX_H #define VINA_TRIANGULAR_MATRIX_INDEX_H #include "common.h" inline sz triangular_matrix_index(sz n, sz i, sz j) { assert(j < n); assert(i <= j); return i + j*(j+1)/2; } inline sz triangular_matrix_index_permissive(sz n, sz i, sz j) { return (i <= j) ? triangular_matrix_index(n, i, j) : triangular_matrix_index(n, j, i); } #endif autodock-vina-1.1.2/src/lib/everything.h0000744000175000017500000000161011562571364020042 0ustar moellermoeller/* Copyright (c) 2006-2010, The Scripps Research Institute Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Author: Dr. Oleg Trott , The Olson Lab, The Scripps Research Institute */ #ifndef VINA_EVERYTHING_H #define VINA_EVERYTHING_H #include "terms.h" struct everything : public terms { everything(); }; #endif autodock-vina-1.1.2/src/lib/tree.h0000744000175000017500000002125111562571364016620 0ustar moellermoeller/* Copyright (c) 2006-2010, The Scripps Research Institute Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Author: Dr. Oleg Trott , The Olson Lab, The Scripps Research Institute */ #ifndef VINA_TREE_H #define VINA_TREE_H #include "conf.h" #include "atom.h" struct frame { frame(const vec& origin_) : origin(origin_), orientation_q(qt_identity), orientation_m(quaternion_to_r3(qt_identity)) {} vec local_to_lab(const vec& local_coords) const { vec tmp; tmp = origin + orientation_m*local_coords; return tmp; } vec local_to_lab_direction(const vec& local_direction) const { vec tmp; tmp = orientation_m * local_direction; return tmp; } const qt& orientation() const { return orientation_q; } const vec& get_origin() const { return origin; } protected: vec origin; void set_orientation(const qt& q) { // does not normalize the orientation orientation_q = q; orientation_m = quaternion_to_r3(orientation_q); } mat orientation_m; qt orientation_q; }; struct atom_range { sz begin; sz end; atom_range(sz begin_, sz end_) : begin(begin_), end(end_) {} template void transform(const F& f) { sz diff = end - begin; begin = f(begin); end = begin + diff; } }; struct atom_frame : public frame, public atom_range { atom_frame(const vec& origin_, sz begin_, sz end_) : frame(origin_), atom_range(begin_, end_) {} void set_coords(const atomv& atoms, vecv& coords) const { VINA_RANGE(i, begin, end) coords[i] = local_to_lab(atoms[i].coords); } vecp sum_force_and_torque(const vecv& coords, const vecv& forces) const { vecp tmp; tmp.first.assign(0); tmp.second.assign(0); VINA_RANGE(i, begin, end) { tmp.first += forces[i]; tmp.second += cross_product(coords[i] - origin, forces[i]); } return tmp; } }; struct rigid_body : public atom_frame { rigid_body(const vec& origin_, sz begin_, sz end_) : atom_frame(origin_, begin_, end_) {} void set_conf(const atomv& atoms, vecv& coords, const rigid_conf& c) { origin = c.position; set_orientation(c.orientation); set_coords(atoms, coords); } void count_torsions(sz& s) const {} // do nothing void set_derivative(const vecp& force_torque, rigid_change& c) const { c.position = force_torque.first; c.orientation = force_torque.second; } }; struct axis_frame : public atom_frame { axis_frame(const vec& origin_, sz begin_, sz end_, const vec& axis_root) : atom_frame(origin_, begin_, end_) { vec diff; diff = origin - axis_root; fl nrm = diff.norm(); VINA_CHECK(nrm >= epsilon_fl); axis = (1/nrm) * diff; } void set_derivative(const vecp& force_torque, fl& c) const { c = force_torque.second * axis; } protected: vec axis; }; struct segment : public axis_frame { segment(const vec& origin_, sz begin_, sz end_, const vec& axis_root, const frame& parent) : axis_frame(origin_, begin_, end_, axis_root) { VINA_CHECK(eq(parent.orientation(), qt_identity)); // the only initial parent orientation this c'tor supports relative_axis = axis; relative_origin = origin - parent.get_origin(); } void set_conf(const frame& parent, const atomv& atoms, vecv& coords, flv::const_iterator& c) { const fl torsion = *c; ++c; origin = parent.local_to_lab(relative_origin); axis = parent.local_to_lab_direction(relative_axis); qt tmp = angle_to_quaternion(axis, torsion) * parent.orientation(); quaternion_normalize_approx(tmp); // normalization added in 1.1.2 //quaternion_normalize(tmp); // normalization added in 1.1.2 set_orientation(tmp); set_coords(atoms, coords); } void count_torsions(sz& s) const { ++s; } private: vec relative_axis; vec relative_origin; }; struct first_segment : public axis_frame { first_segment(const segment& s) : axis_frame(s) {} first_segment(const vec& origin_, sz begin_, sz end_, const vec& axis_root) : axis_frame(origin_, begin_, end_, axis_root) {} void set_conf(const atomv& atoms, vecv& coords, fl torsion) { set_orientation(angle_to_quaternion(axis, torsion)); set_coords(atoms, coords); } void count_torsions(sz& s) const { ++s; } }; template // T == branch void branches_set_conf(std::vector& b, const frame& parent, const atomv& atoms, vecv& coords, flv::const_iterator& c) { VINA_FOR_IN(i, b) b[i].set_conf(parent, atoms, coords, c); } template // T == branch void branches_derivative(const std::vector& b, const vec& origin, const vecv& coords, const vecv& forces, vecp& out, flv::iterator& d) { // adds to out VINA_FOR_IN(i, b) { vecp force_torque = b[i].derivative(coords, forces, d); out.first += force_torque.first; vec r; r = b[i].node.get_origin() - origin; out.second += cross_product(r, force_torque.first) + force_torque.second; } } template // T == segment struct tree { T node; std::vector< tree > children; tree(const T& node_) : node(node_) {} void set_conf(const frame& parent, const atomv& atoms, vecv& coords, flv::const_iterator& c) { node.set_conf(parent, atoms, coords, c); branches_set_conf(children, node, atoms, coords, c); } vecp derivative(const vecv& coords, const vecv& forces, flv::iterator& p) const { vecp force_torque = node.sum_force_and_torque(coords, forces); fl& d = *p; // reference ++p; branches_derivative(children, node.get_origin(), coords, forces, force_torque, p); node.set_derivative(force_torque, d); return force_torque; } }; typedef tree branch; typedef std::vector branches; template // Node == first_segment || rigid_body struct heterotree { Node node; branches children; heterotree(const Node& node_) : node(node_) {} void set_conf(const atomv& atoms, vecv& coords, const ligand_conf& c) { node.set_conf(atoms, coords, c.rigid); flv::const_iterator p = c.torsions.begin(); branches_set_conf(children, node, atoms, coords, p); assert(p == c.torsions.end()); } void set_conf(const atomv& atoms, vecv& coords, const residue_conf& c) { flv::const_iterator p = c.torsions.begin(); node.set_conf(atoms, coords, *p); ++p; branches_set_conf(children, node, atoms, coords, p); assert(p == c.torsions.end()); } void derivative(const vecv& coords, const vecv& forces, ligand_change& c) const { vecp force_torque = node.sum_force_and_torque(coords, forces); flv::iterator p = c.torsions.begin(); branches_derivative(children, node.get_origin(), coords, forces, force_torque, p); node.set_derivative(force_torque, c.rigid); assert(p == c.torsions.end()); } void derivative(const vecv& coords, const vecv& forces, residue_change& c) const { vecp force_torque = node.sum_force_and_torque(coords, forces); flv::iterator p = c.torsions.begin(); fl& d = *p; // reference ++p; branches_derivative(children, node.get_origin(), coords, forces, force_torque, p); node.set_derivative(force_torque, d); assert(p == c.torsions.end()); } }; template // T = main_branch, branch, flexible_body void count_torsions(const T& t, sz& s) { t.node.count_torsions(s); VINA_FOR_IN(i, t.children) count_torsions(t.children[i], s); } typedef heterotree flexible_body; typedef heterotree main_branch; template // T == flexible_body || main_branch struct vector_mutable : public std::vector { template void set_conf(const atomv& atoms, vecv& coords, const std::vector& c) { // C == ligand_conf || residue_conf VINA_FOR_IN(i, (*this)) (*this)[i].set_conf(atoms, coords, c[i]); } szv count_torsions() const { szv tmp(this->size(), 0); VINA_FOR_IN(i, (*this)) ::count_torsions((*this)[i], tmp[i]); return tmp; } template void derivative(const vecv& coords, const vecv& forces, std::vector& c) const { // C == ligand_change || residue_change VINA_FOR_IN(i, (*this)) (*this)[i].derivative(coords, forces, c[i]); } }; template // tree or heterotree - like structure void transform_ranges(T& t, const F& f) { t.node.transform(f); VINA_FOR_IN(i, t.children) transform_ranges(t.children[i], f); } #endif autodock-vina-1.1.2/src/lib/weighted_terms.cpp0000744000175000017500000000400611562571364021225 0ustar moellermoeller/* Copyright (c) 2006-2010, The Scripps Research Institute Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Author: Dr. Oleg Trott , The Olson Lab, The Scripps Research Institute */ #include "weighted_terms.h" weighted_terms::weighted_terms(const terms* t, const flv& weights) : t(t), weights(weights), cutoff_(0) { // does not own t VINA_CHECK(t->distance_additive_terms.num_enabled() == 0); VINA_CHECK(t-> additive_terms.num_enabled() == 0); VINA_CHECK(t-> intermolecular_terms.num_enabled() == 0); VINA_FOR_IN(i, t->usable_terms) if(t->usable_terms.enabled[i]) { if(enabled_usable_terms.empty()) atom_typing_used_ = t->usable_terms[i].atom_typing_used; else VINA_CHECK(atom_typing_used_ == t->usable_terms[i].atom_typing_used); enabled_usable_terms.push_back(i); cutoff_ = (std::max)(cutoff_, t->usable_terms[i].cutoff); } } fl weighted_terms::eval(sz t1, sz t2, fl r) const { // intentionally not checking for cutoff fl acc = 0; VINA_FOR_IN(i, enabled_usable_terms) acc += weights[i] * t->usable_terms[enabled_usable_terms[i]].eval(t1, t2, r); return acc; } fl weighted_terms::conf_independent(const model& m, fl e) const { flv::const_iterator it = weights.begin() + enabled_usable_terms.size(); conf_independent_inputs in(m); // FIXME quite inefficient, but I think speed is irrelevant here, right? fl tmp = t->eval_conf_independent(in, e, it); assert(it == weights.end()); return tmp; } autodock-vina-1.1.2/src/lib/terms.cpp0000744000175000017500000002612111562571364017347 0ustar moellermoeller/* Copyright (c) 2006-2010, The Scripps Research Institute Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Author: Dr. Oleg Trott , The Olson Lab, The Scripps Research Institute */ #include "terms.h" #include "brick.h" conf_independent_inputs::operator flv() const { flv tmp; tmp.push_back(num_tors); tmp.push_back(num_rotors); tmp.push_back(num_heavy_atoms); tmp.push_back(num_hydrophobic_atoms); tmp.push_back(ligand_max_num_h_bonds); tmp.push_back(num_ligands); tmp.push_back(ligand_lengths_sum); return tmp; } unsigned conf_independent_inputs::num_bonded_heavy_atoms(const model& m, const atom_index& i) const { // FIXME? - could be static, but I don't feel like declaring function friends unsigned acc = 0; const std::vector& bonds = m.get_atom(i).bonds; VINA_FOR_IN(j, bonds) { const bond& b = bonds[j]; const atom& a = m.get_atom(b.connected_atom_index); if(!a.is_hydrogen()) ++acc; } return acc; } // FIXME? - could be static, but I don't feel like declaring function friends unsigned conf_independent_inputs::atom_rotors(const model& m, const atom_index& i) const { // the number of rotatable bonds to heavy ligand atoms unsigned acc = 0; const std::vector& bonds = m.get_atom(i).bonds; VINA_FOR_IN(j, bonds) { const bond& b = bonds[j]; const atom& a = m.get_atom(b.connected_atom_index); if(b.rotatable && !a.is_hydrogen() && num_bonded_heavy_atoms(m, b.connected_atom_index) > 1) // not counting CH_3, etc ++acc; } return acc; } conf_independent_inputs::conf_independent_inputs(const model& m) { num_tors = 0; num_rotors = 0; num_heavy_atoms = 0; num_hydrophobic_atoms = 0; ligand_max_num_h_bonds = 0; num_ligands = m.ligands.size(); ligand_lengths_sum = 0; VINA_FOR_IN(ligand_i, m.ligands) { const ligand& lig = m.ligands[ligand_i]; ligand_lengths_sum += m.ligand_length(ligand_i); VINA_RANGE(i, lig.begin, lig.end) { const atom& a = m.atoms[i]; if(a.el != EL_TYPE_H) { unsigned ar = atom_rotors(m, atom_index(i, false)); num_tors += 0.5 * ar; if(ar > 2) num_rotors += 0.5; else num_rotors += 0.5 * ar; ++num_heavy_atoms; if(xs_is_hydrophobic(a.xs)) ++num_hydrophobic_atoms; if(xs_is_acceptor(a.xs) || xs_is_donor(a.xs)) ++ligand_max_num_h_bonds; } } } } std::vector conf_independent_inputs::get_names() const { // FIXME should probably be static std::vector tmp; tmp.push_back("num_tors"); tmp.push_back("num_rotors"); tmp.push_back("num_heavy_atoms"); tmp.push_back("num_hydrophobic_atoms"); tmp.push_back("ligand_max_num_h_bonds"); tmp.push_back("num_ligands"); tmp.push_back("ligand_lengths_sum"); VINA_CHECK(static_cast(*this).size() == tmp.size()); // FIXME? return tmp; } conf_independent_inputs::conf_independent_inputs() : num_tors(0), num_rotors(0), num_heavy_atoms(0), num_hydrophobic_atoms(0), ligand_max_num_h_bonds(0), num_ligands(0), ligand_lengths_sum(0) {} inline fl inner_product_shortest(const flv& a, const flv& b) { sz n = (std::min)(a.size(), b.size()); fl acc = 0; VINA_FOR(i, n) acc += a[i] * b[i]; return acc; } fl factors::eval(const flv& weights, bool include_internal) const { fl tmp = inner_product_shortest(e, weights); if(include_internal) tmp += inner_product_shortest(i, weights); return tmp; } // terms std::vector terms::get_names(bool enabled_only) const { // does not include conf-independent std::vector tmp; distance_additive_terms.get_names(enabled_only, tmp); usable_terms.get_names(enabled_only, tmp); additive_terms.get_names(enabled_only, tmp); intermolecular_terms.get_names(enabled_only, tmp); return tmp; } sz terms::size_internal() const { return distance_additive_terms.size() + usable_terms.size() + additive_terms.size(); } sz terms::size_conf_independent(bool enabled_only) const { // number of parameters does not necessarily equal the number of operators sz acc = 0; VINA_FOR_IN(i, conf_independent_terms) if(!enabled_only || conf_independent_terms.enabled[i]) acc += conf_independent_terms[i].size(); return acc; } fl terms::max_r_cutoff() const { fl tmp = 0; tmp = (std::max)(tmp, distance_additive_terms.max_cutoff()); tmp = (std::max)(tmp, usable_terms.max_cutoff()); tmp = (std::max)(tmp, additive_terms.max_cutoff()); return tmp; } void terms::eval_additive_aux(const model& m, const atom_index& i, const atom_index& j, fl r, flv& out) const { // out is added to const atom& a = m.get_atom(i); const atom& b = m.get_atom(j); sz offset = 0; VINA_FOR_IN(k, distance_additive_terms) if(r < distance_additive_terms[k].cutoff) out[k] += distance_additive_terms[k].eval(a, b, r); offset += distance_additive_terms.size(); VINA_FOR_IN(k, usable_terms) if(r < usable_terms[k].cutoff) out[offset + k] += usable_terms[k].eval(a, b, r); offset += usable_terms.size(); VINA_FOR_IN(k, additive_terms) if(r < additive_terms[k].cutoff) out[offset + k] += additive_terms[k].eval(m, i, j); VINA_CHECK(offset + additive_terms.size() == size_internal()); } flv terms::evale(const model& m) const { VINA_CHECK(m.ligands.size() == 1); VINA_CHECK(m.flex.size() == 0); VINA_CHECK(m.atoms.size() == m.num_movable_atoms()); // no inflex flv tmp(size(), 0); fl max_r_cutoff_sqr = sqr(max_r_cutoff()); grid_dims box = m.movable_atoms_box(0); // add nothing vec box_begin = grid_dims_begin(box); vec box_end = grid_dims_end (box); szv relevant_atoms; VINA_FOR_IN(j, m.grid_atoms) if(brick_distance_sqr(box_begin, box_end, m.grid_atoms[j].coords) < max_r_cutoff_sqr) relevant_atoms.push_back(j); VINA_FOR(i, m.num_movable_atoms()) { const vec& coords = m.coords[i]; VINA_FOR_IN(relevant_j, relevant_atoms) { const sz j = relevant_atoms[relevant_j]; const atom& b = m.grid_atoms[j]; fl d2 = vec_distance_sqr(coords, b.coords); if(d2 > max_r_cutoff_sqr) continue; // most likely scenario fl d = std::sqrt(d2); eval_additive_aux(m, atom_index(i, false), atom_index(j, true), d, tmp); } } sz offset = size_internal(); VINA_FOR_IN(k, intermolecular_terms) tmp[offset + k] += intermolecular_terms[k].eval(m); VINA_CHECK(offset + intermolecular_terms.size() == tmp.size()); return tmp; } flv terms::evali(const model& m) const { VINA_CHECK(m.ligands.size() == 1); VINA_CHECK(m.flex.size() == 0); VINA_CHECK(m.atoms.size() == m.num_movable_atoms()); flv tmp(size_internal(), 0); fl max_r_cutoff_sqr = sqr(max_r_cutoff()); const interacting_pairs& pairs = m.ligands.front().pairs; VINA_FOR_IN(i, pairs) { const interacting_pair& ip = pairs[i]; fl d2 = vec_distance_sqr(m.coords[ip.a], m.coords[ip.b]); if(d2 > max_r_cutoff_sqr) continue; // most likely scenario fl d = std::sqrt(d2); eval_additive_aux(m, atom_index(ip.a, false), atom_index(ip.b, false), d, tmp); } return tmp; } flv terms::evale_robust(const model& m) const { VINA_CHECK(m.ligands.size() == 1); // only single-ligand systems are supported by this procedure flv tmp(size(), 0); fl max_r_cutoff_sqr = sqr(max_r_cutoff()); grid_dims box = m.movable_atoms_box(0); // add nothing vec box_begin = grid_dims_begin(box); vec box_end = grid_dims_end (box); const sz n = num_atom_types(m.atom_typing_used()); std::vector relevant_atoms; VINA_FOR_IN(j, m.grid_atoms) { const atom& a = m.grid_atoms[j]; const sz t = a.get(m.atom_typing_used()); if(brick_distance_sqr(box_begin, box_end, a.coords) < max_r_cutoff_sqr && t < n) // exclude, say, Hydrogens relevant_atoms.push_back(atom_index(j, true)); } VINA_FOR_IN(j, m.atoms) { const atom& a = m.atoms[j]; const vec& a_coords = m.coords[j]; if(m.find_ligand(j) < m.ligands.size()) continue; // skip ligand atoms, add only flex/inflex const sz t = a.get(m.atom_typing_used()); if(brick_distance_sqr(box_begin, box_end, a_coords) < max_r_cutoff_sqr && t < n) // exclude, say, Hydrogens relevant_atoms.push_back(atom_index(j, false)); } VINA_FOR_IN(lig_i, m.ligands) { const ligand& lig = m.ligands[lig_i]; VINA_RANGE(i, lig.begin, lig.end) { const vec& coords = m.coords[i]; const atom& a = m.atoms[i]; const sz t = a.get(m.atom_typing_used()); if(t < n) { // exclude, say, Hydrogens VINA_FOR_IN(relevant_j, relevant_atoms) { const atom_index& j = relevant_atoms[relevant_j]; fl d2 = vec_distance_sqr(coords, m.atom_coords(j)); if(d2 > max_r_cutoff_sqr) continue; // most likely scenario fl d = std::sqrt(d2); eval_additive_aux(m, atom_index(i, false), j, d, tmp); } } } } sz offset = size_internal(); VINA_CHECK(intermolecular_terms.size() == 0); VINA_CHECK(offset + intermolecular_terms.size() == tmp.size()); return tmp; } factors terms::eval(const model& m) const { factors tmp; tmp.e = evale(m); tmp.i = evali(m); return tmp; } fl terms::eval_conf_independent(const conf_independent_inputs& in, fl x, flv::const_iterator& it) const { // evaluates enabled only VINA_FOR_IN(i, conf_independent_terms) if(conf_independent_terms.enabled[i]) x = conf_independent_terms[i].eval(in, x, it); return x; } flv terms::filter_external(const flv& v) const { flv tmp; flv::const_iterator i = v.begin(); distance_additive_terms.filter(i, tmp); usable_terms.filter(i, tmp); additive_terms.filter(i, tmp); intermolecular_terms.filter(i, tmp); VINA_CHECK(i == v.end()); return tmp; } flv terms::filter_internal(const flv& v) const { flv tmp; flv::const_iterator i = v.begin(); distance_additive_terms.filter(i, tmp); usable_terms.filter(i, tmp); additive_terms.filter(i, tmp); VINA_CHECK(i == v.end()); return tmp; } factors terms::filter(const factors& f) const { factors tmp; tmp.e = filter_external(f.e); tmp.i = filter_internal(f.i); return tmp; } void terms::display_info() const { std::vector enabled_names = get_names(true); std::cout << "Enabled terms: \n"; VINA_FOR_IN(i, enabled_names) std::cout << enabled_names[i] << '\n'; std::cout << '\n'; std::vector enabled_operators; conf_independent_terms.get_names(true, enabled_operators); std::cout << "Enabled conf-independent operators: \n"; VINA_FOR_IN(i, enabled_operators) std::cout << enabled_operators[i] << '\n'; std::cout << '\n'; VINA_SHOW(size()); VINA_SHOW(size_internal()); VINA_SHOW(max_r_cutoff()); } autodock-vina-1.1.2/src/lib/bfgs.h0000744000175000017500000000766311562571364016615 0ustar moellermoeller/* Copyright (c) 2006-2010, The Scripps Research Institute Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Author: Dr. Oleg Trott , The Olson Lab, The Scripps Research Institute */ #ifndef VINA_BFGS_H #define VINA_BFGS_H #include "matrix.h" typedef triangular_matrix flmat; template void minus_mat_vec_product(const flmat& m, const Change& in, Change& out) { sz n = m.dim(); VINA_FOR(i, n) { fl sum = 0; VINA_FOR(j, n) sum += m(m.index_permissive(i, j)) * in(j); out(i) = -sum; } } template inline fl scalar_product(const Change& a, const Change& b, sz n) { fl tmp = 0; VINA_FOR(i, n) tmp += a(i) * b(i); return tmp; } template inline bool bfgs_update(flmat& h, const Change& p, const Change& y, const fl alpha) { const fl yp = scalar_product(y, p, h.dim()); if(alpha * yp < epsilon_fl) return false; // FIXME? Change minus_hy(y); minus_mat_vec_product(h, y, minus_hy); const fl yhy = - scalar_product(y, minus_hy, h.dim()); const fl r = 1 / (alpha * yp); // 1 / (s^T * y) , where s = alpha * p // FIXME ... < epsilon const sz n = p.num_floats(); VINA_FOR(i, n) VINA_RANGE(j, i, n) // includes i h(i, j) += alpha * r * (minus_hy(i) * p(j) + minus_hy(j) * p(i)) + + alpha * alpha * (r*r * yhy + r) * p(i) * p(j); // s * s == alpha * alpha * p * p return true; } template fl line_search(F& f, sz n, const Conf& x, const Change& g, const fl f0, const Change& p, Conf& x_new, Change& g_new, fl& f1) { // returns alpha const fl c0 = 0.0001; const unsigned max_trials = 10; const fl multiplier = 0.5; fl alpha = 1; const fl pg = scalar_product(p, g, n); VINA_U_FOR(trial, max_trials) { x_new = x; x_new.increment(p, alpha); f1 = f(x_new, g_new); if(f1 - f0 < c0 * alpha * pg) // FIXME check - div by norm(p) ? no? break; alpha *= multiplier; } return alpha; } inline void set_diagonal(flmat& m, fl x) { VINA_FOR(i, m.dim()) m(i, i) = x; } template void subtract_change(Change& b, const Change& a, sz n) { // b -= a VINA_FOR(i, n) b(i) -= a(i); } template fl bfgs(F& f, Conf& x, Change& g, const unsigned max_steps, const fl average_required_improvement, const sz over) { // x is I/O, final value is returned sz n = g.num_floats(); flmat h(n, 0); set_diagonal(h, 1); Change g_new(g); Conf x_new(x); fl f0 = f(x, g); fl f_orig = f0; Change g_orig(g); Conf x_orig(x); Change p(g); flv f_values; f_values.reserve(max_steps+1); f_values.push_back(f0); VINA_U_FOR(step, max_steps) { minus_mat_vec_product(h, g, p); fl f1 = 0; const fl alpha = line_search(f, n, x, g, f0, p, x_new, g_new, f1); Change y(g_new); subtract_change(y, g, n); f_values.push_back(f1); f0 = f1; x = x_new; if(!(std::sqrt(scalar_product(g, g, n)) >= 1e-5)) break; // breaks for nans too // FIXME !!?? g = g_new; // ? if(step == 0) { const fl yy = scalar_product(y, y, n); if(std::abs(yy) > epsilon_fl) set_diagonal(h, alpha * scalar_product(y, p, n) / yy); } bool h_updated = bfgs_update(h, p, y, alpha); } if(!(f0 <= f_orig)) { // succeeds for nans too f0 = f_orig; x = x_orig; g = g_orig; } return f0; } #endif autodock-vina-1.1.2/src/lib/macros.h0000744000175000017500000000350211562571364017144 0ustar moellermoeller/* Copyright (c) 2004-2010, Dr. Oleg Trott Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ #ifndef VINA_MACROS_H #define VINA_MACROS_H #define VINA_FOR_IN(i, v) for(std::size_t VINA_MACROS_TMP = (v).size(), (i) = 0; (i) < VINA_MACROS_TMP; ++(i)) #define VINA_FOR(i, n) for(std::size_t VINA_MACROS_TMP = (n), (i) = 0; (i) < VINA_MACROS_TMP; ++(i)) #define VINA_U_FOR(i, n) for(unsigned VINA_MACROS_TMP = (n), (i) = 0; (i) < VINA_MACROS_TMP; ++(i)) #define VINA_RANGE(i, a, b) for(std::size_t VINA_MACROS_TMP = (b), (i) = (a); (i) < VINA_MACROS_TMP; ++(i)) #define VINA_U_RANGE(i, a, b) for(unsigned VINA_MACROS_TMP = (b), (i) = (a); (i) < VINA_MACROS_TMP; ++(i)) #define VINA_I_RANGE(i, a, b) for(int VINA_MACROS_TMP = (b), (i) = (a); (i) < VINA_MACROS_TMP; ++(i)) #define VINA_LOOP_CONST(t, i, v) for(t::const_iterator (i) = (v).begin(); (i) != (v).end(); ++(i)) #define VINA_LOOP(t, i, v) for(t::iterator (i) = (v).begin(); (i) != (v).end(); ++(i)) #define VINA_SHOW(x) do { std::cout << #x << " = " << (x) << std::endl; } while(false) #define VINA_SHOW_FAST(x) do { std::cout << #x << " = " << (x) << '\n'; } while(false) #define VINA_ESHOW(x) do { std::cerr << #x << " = " << (x) << '\n'; } while(false) #endif autodock-vina-1.1.2/src/lib/atom_constants.h0000744000175000017500000002234311562571364020720 0ustar moellermoeller/* Copyright (c) 2006-2010, The Scripps Research Institute Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Author: Dr. Oleg Trott , The Olson Lab, The Scripps Research Institute */ #ifndef VINA_ATOM_CONSTANTS_H #define VINA_ATOM_CONSTANTS_H #include "common.h" // based on SY_TYPE_* but includes H const sz EL_TYPE_H = 0; const sz EL_TYPE_C = 1; const sz EL_TYPE_N = 2; const sz EL_TYPE_O = 3; const sz EL_TYPE_S = 4; const sz EL_TYPE_P = 5; const sz EL_TYPE_F = 6; const sz EL_TYPE_Cl = 7; const sz EL_TYPE_Br = 8; const sz EL_TYPE_I = 9; const sz EL_TYPE_Met = 10; const sz EL_TYPE_SIZE = 11; // AutoDock4 const sz AD_TYPE_C = 0; const sz AD_TYPE_A = 1; const sz AD_TYPE_N = 2; const sz AD_TYPE_O = 3; const sz AD_TYPE_P = 4; const sz AD_TYPE_S = 5; const sz AD_TYPE_H = 6; // non-polar hydrogen const sz AD_TYPE_F = 7; const sz AD_TYPE_I = 8; const sz AD_TYPE_NA = 9; const sz AD_TYPE_OA = 10; const sz AD_TYPE_SA = 11; const sz AD_TYPE_HD = 12; const sz AD_TYPE_Mg = 13; const sz AD_TYPE_Mn = 14; const sz AD_TYPE_Zn = 15; const sz AD_TYPE_Ca = 16; const sz AD_TYPE_Fe = 17; const sz AD_TYPE_Cl = 18; const sz AD_TYPE_Br = 19; const sz AD_TYPE_SIZE = 20; // X-Score const sz XS_TYPE_C_H = 0; const sz XS_TYPE_C_P = 1; const sz XS_TYPE_N_P = 2; const sz XS_TYPE_N_D = 3; const sz XS_TYPE_N_A = 4; const sz XS_TYPE_N_DA = 5; const sz XS_TYPE_O_P = 6; const sz XS_TYPE_O_D = 7; const sz XS_TYPE_O_A = 8; const sz XS_TYPE_O_DA = 9; const sz XS_TYPE_S_P = 10; const sz XS_TYPE_P_P = 11; const sz XS_TYPE_F_H = 12; const sz XS_TYPE_Cl_H = 13; const sz XS_TYPE_Br_H = 14; const sz XS_TYPE_I_H = 15; const sz XS_TYPE_Met_D = 16; const sz XS_TYPE_SIZE = 17; // DrugScore-CSD const sz SY_TYPE_C_3 = 0; const sz SY_TYPE_C_2 = 1; const sz SY_TYPE_C_ar = 2; const sz SY_TYPE_C_cat = 3; const sz SY_TYPE_N_3 = 4; const sz SY_TYPE_N_ar = 5; const sz SY_TYPE_N_am = 6; const sz SY_TYPE_N_pl3 = 7; const sz SY_TYPE_O_3 = 8; const sz SY_TYPE_O_2 = 9; const sz SY_TYPE_O_co2 = 10; const sz SY_TYPE_S = 11; const sz SY_TYPE_P = 12; const sz SY_TYPE_F = 13; const sz SY_TYPE_Cl = 14; const sz SY_TYPE_Br = 15; const sz SY_TYPE_I = 16; const sz SY_TYPE_Met = 17; const sz SY_TYPE_SIZE = 18; struct atom_kind { std::string name; fl radius; fl depth; fl solvation; fl volume; fl covalent_radius; // from http://en.wikipedia.org/wiki/Atomic_radii_of_the_elements_(data_page) }; // generated from edited AD4_parameters.data using a script, // then covalent radius added from en.wikipedia.org/wiki/Atomic_radii_of_the_elements_(data_page) const atom_kind atom_kind_data[] = { // name, radius, depth, solvation parameter, volume, covalent radius { "C", 2.00000, 0.15000, -0.00143, 33.51030, 0.77}, // 0 { "A", 2.00000, 0.15000, -0.00052, 33.51030, 0.77}, // 1 { "N", 1.75000, 0.16000, -0.00162, 22.44930, 0.75}, // 2 { "O", 1.60000, 0.20000, -0.00251, 17.15730, 0.73}, // 3 { "P", 2.10000, 0.20000, -0.00110, 38.79240, 1.06}, // 4 { "S", 2.00000, 0.20000, -0.00214, 33.51030, 1.02}, // 5 { "H", 1.00000, 0.02000, 0.00051, 0.00000, 0.37}, // 6 { "F", 1.54500, 0.08000, -0.00110, 15.44800, 0.71}, // 7 { "I", 2.36000, 0.55000, -0.00110, 55.05850, 1.33}, // 8 {"NA", 1.75000, 0.16000, -0.00162, 22.44930, 0.75}, // 9 {"OA", 1.60000, 0.20000, -0.00251, 17.15730, 0.73}, // 10 {"SA", 2.00000, 0.20000, -0.00214, 33.51030, 1.02}, // 11 {"HD", 1.00000, 0.02000, 0.00051, 0.00000, 0.37}, // 12 {"Mg", 0.65000, 0.87500, -0.00110, 1.56000, 1.30}, // 13 {"Mn", 0.65000, 0.87500, -0.00110, 2.14000, 1.39}, // 14 {"Zn", 0.74000, 0.55000, -0.00110, 1.70000, 1.31}, // 15 {"Ca", 0.99000, 0.55000, -0.00110, 2.77000, 1.74}, // 16 {"Fe", 0.65000, 0.01000, -0.00110, 1.84000, 1.25}, // 17 {"Cl", 2.04500, 0.27600, -0.00110, 35.82350, 0.99}, // 18 {"Br", 2.16500, 0.38900, -0.00110, 42.56610, 1.14} // 19 }; const fl metal_solvation_parameter = -0.00110; const fl metal_covalent_radius = 1.75; // for metals not on the list // FIXME this info should be moved to non_ad_metals const sz atom_kinds_size = sizeof(atom_kind_data) / sizeof(const atom_kind); struct atom_equivalence { std::string name; std::string to; }; const atom_equivalence atom_equivalence_data[] = { {"Se", "S"} }; const sz atom_equivalences_size = sizeof(atom_equivalence_data) / sizeof(const atom_equivalence); struct acceptor_kind { sz ad_type; fl radius; fl depth; }; const acceptor_kind acceptor_kind_data[] = { // ad_type, optimal length, depth {AD_TYPE_NA, 1.9, 5.0}, {AD_TYPE_OA, 1.9, 5.0}, {AD_TYPE_SA, 2.5, 1.0} }; const sz acceptor_kinds_size = sizeof(acceptor_kind_data) / sizeof(acceptor_kind); inline bool ad_is_hydrogen(sz ad) { return ad == AD_TYPE_H || ad == AD_TYPE_HD; } inline bool ad_is_heteroatom(sz ad) { // returns false for ad >= AD_TYPE_SIZE return ad != AD_TYPE_A && ad != AD_TYPE_C && ad != AD_TYPE_H && ad != AD_TYPE_HD && ad < AD_TYPE_SIZE; } inline sz ad_type_to_el_type(sz t) { switch(t) { case AD_TYPE_C : return EL_TYPE_C; case AD_TYPE_A : return EL_TYPE_C; case AD_TYPE_N : return EL_TYPE_N; case AD_TYPE_O : return EL_TYPE_O; case AD_TYPE_P : return EL_TYPE_P; case AD_TYPE_S : return EL_TYPE_S; case AD_TYPE_H : return EL_TYPE_H; case AD_TYPE_F : return EL_TYPE_F; case AD_TYPE_I : return EL_TYPE_I; case AD_TYPE_NA : return EL_TYPE_N; case AD_TYPE_OA : return EL_TYPE_O; case AD_TYPE_SA : return EL_TYPE_S; case AD_TYPE_HD : return EL_TYPE_H; case AD_TYPE_Mg : return EL_TYPE_Met; case AD_TYPE_Mn : return EL_TYPE_Met; case AD_TYPE_Zn : return EL_TYPE_Met; case AD_TYPE_Ca : return EL_TYPE_Met; case AD_TYPE_Fe : return EL_TYPE_Met; case AD_TYPE_Cl : return EL_TYPE_Cl; case AD_TYPE_Br : return EL_TYPE_Br; case AD_TYPE_SIZE : return EL_TYPE_SIZE; default: VINA_CHECK(false); } return EL_TYPE_SIZE; // to placate the compiler in case of warnings - it should never get here though } const fl xs_vdw_radii[] = { 1.9, // C_H 1.9, // C_P 1.8, // N_P 1.8, // N_D 1.8, // N_A 1.8, // N_DA 1.7, // O_P 1.7, // O_D 1.7, // O_A 1.7, // O_DA 2.0, // S_P 2.1, // P_P 1.5, // F_H 1.8, // Cl_H 2.0, // Br_H 2.2, // I_H 1.2 // Met_D }; inline fl xs_radius(sz t) { const sz n = sizeof(xs_vdw_radii) / sizeof(const fl); assert(n == XS_TYPE_SIZE); assert(t < n); return xs_vdw_radii[t]; } const std::string non_ad_metal_names[] = { // expand as necessary "Cu", "Fe", "Na", "K", "Hg", "Co", "U", "Cd", "Ni" }; inline bool is_non_ad_metal_name(const std::string& name) { const sz s = sizeof(non_ad_metal_names) / sizeof(const std::string); VINA_FOR(i, s) if(non_ad_metal_names[i] == name) return true; return false; } inline bool xs_is_hydrophobic(sz xs) { return xs == XS_TYPE_C_H || xs == XS_TYPE_F_H || xs == XS_TYPE_Cl_H || xs == XS_TYPE_Br_H || xs == XS_TYPE_I_H; } inline bool xs_is_acceptor(sz xs) { return xs == XS_TYPE_N_A || xs == XS_TYPE_N_DA || xs == XS_TYPE_O_A || xs == XS_TYPE_O_DA; } inline bool xs_is_donor(sz xs) { return xs == XS_TYPE_N_D || xs == XS_TYPE_N_DA || xs == XS_TYPE_O_D || xs == XS_TYPE_O_DA || xs == XS_TYPE_Met_D; } inline bool xs_donor_acceptor(sz t1, sz t2) { return xs_is_donor(t1) && xs_is_acceptor(t2); } inline bool xs_h_bond_possible(sz t1, sz t2) { return xs_donor_acceptor(t1, t2) || xs_donor_acceptor(t2, t1); } inline const atom_kind& ad_type_property(sz i) { assert(AD_TYPE_SIZE == atom_kinds_size); assert(i < atom_kinds_size); return atom_kind_data[i]; } inline sz string_to_ad_type(const std::string& name) { // returns AD_TYPE_SIZE if not found (no exceptions thrown, because metals unknown to AD4 are not exceptional) VINA_FOR(i, atom_kinds_size) if(atom_kind_data[i].name == name) return i; VINA_FOR(i, atom_equivalences_size) if(atom_equivalence_data[i].name == name) return string_to_ad_type(atom_equivalence_data[i].to); return AD_TYPE_SIZE; } inline fl max_covalent_radius() { fl tmp = 0; VINA_FOR(i, atom_kinds_size) if(atom_kind_data[i].covalent_radius > tmp) tmp = atom_kind_data[i].covalent_radius; return tmp; } #endif autodock-vina-1.1.2/src/lib/naive_non_cache.cpp0000744000175000017500000000321411562571364021312 0ustar moellermoeller/* Copyright (c) 2006-2010, The Scripps Research Institute Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Author: Dr. Oleg Trott , The Olson Lab, The Scripps Research Institute */ #include "naive_non_cache.h" #include "curl.h" naive_non_cache::naive_non_cache(const precalculate* p_) : p(p_) {} fl naive_non_cache::eval(const model& m, fl v) const { // needs m.coords fl e = 0; const fl cutoff_sqr = p->cutoff_sqr(); sz n = num_atom_types(p->atom_typing_used()); VINA_FOR(i, m.num_movable_atoms()) { fl this_e = 0; const atom& a = m.atoms[i]; sz t1 = a.get(p->atom_typing_used()); if(t1 >= n) continue; const vec& a_coords = m.coords[i]; VINA_FOR_IN(j, m.grid_atoms) { const atom& b = m.grid_atoms[j]; sz t2 = b.get(p->atom_typing_used()); if(t2 >= n) continue; vec r_ba; r_ba = a_coords - b.coords; fl r2 = sqr(r_ba); if(r2 < cutoff_sqr) { sz type_pair_index = get_type_pair_index(p->atom_typing_used(), a, b); this_e += p->eval_fast(type_pair_index, r2); } } curl(this_e, v); e += this_e; } return e; } autodock-vina-1.1.2/src/lib/matrix.h0000744000175000017500000001104311562571364017163 0ustar moellermoeller/* Copyright (c) 2006-2010, The Scripps Research Institute Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Author: Dr. Oleg Trott , The Olson Lab, The Scripps Research Institute */ #ifndef VINA_MATRIX_H #define VINA_MATRIX_H #include #include "triangular_matrix_index.h" // these 4 lines are used 3 times verbatim - defining a temp macro to ease the pain #define VINA_MATRIX_DEFINE_OPERATORS \ const T& operator()(sz i) const { return m_data[i]; } \ T& operator()(sz i) { return m_data[i]; } \ const T& operator()(sz i, sz j) const { return m_data[index(i, j)]; } \ T& operator()(sz i, sz j) { return m_data[index(i, j)]; } template class matrix { std::vector m_data; sz m_i, m_j; public: sz index(sz i, sz j) const { assert(j < m_j); assert(i < m_i); return i + m_i*j; // column-major } matrix() : m_i(0), m_j(0) {} matrix(sz i, sz j, const T& filler_val) : m_data(i*j, filler_val), m_i(i), m_j(j) {} void resize(sz m, sz n, const T& filler_val) { // new sizes should be the same or greater than the old if(m == dim_1() && n == dim_2()) return; // no-op VINA_CHECK(m >= dim_1()); VINA_CHECK(n >= dim_2()); std::vector tmp(m*n, filler_val); VINA_FOR(i, m_i) VINA_FOR(j, m_j) tmp[i+m*j] = (*this)(i, j); m_data = tmp; m_i = m; m_j = n; } void append(const matrix& x, const T& filler_val) { sz m = dim_1(); sz n = dim_2(); resize(m + x.dim_1(), n + x.dim_2(), filler_val); VINA_FOR(i, x.dim_1()) VINA_FOR(j, x.dim_2()) (*this)(i+m, j+n) = x(i, j); } VINA_MATRIX_DEFINE_OPERATORS // temp macro defined above sz dim_1() const { return m_i; } sz dim_2() const { return m_j; } }; template class triangular_matrix { std::vector m_data; sz m_dim; public: sz index(sz i, sz j) const { return triangular_matrix_index(m_dim, i, j); } sz index_permissive(sz i, sz j) const { return (i < j) ? index(i, j) : index(j, i); } triangular_matrix() : m_dim(0) {} triangular_matrix(sz n, const T& filler_val) : m_data(n*(n+1)/2, filler_val), m_dim(n) {} VINA_MATRIX_DEFINE_OPERATORS // temp macro defined above sz dim() const { return m_dim; } }; template class strictly_triangular_matrix { std::vector m_data; sz m_dim; public: sz index(sz i, sz j) const { assert(j < m_dim); assert(i < j); assert(j >= 1); // by implication, really return i + j*(j-1)/2; } sz index_permissive(sz i, sz j) const { return (i < j) ? index(i, j) : index(j, i); } strictly_triangular_matrix() : m_dim(0) {} strictly_triangular_matrix(sz n, const T& filler_val) : m_data(n*(n-1)/2, filler_val), m_dim(n) {} void resize(sz n, const T& filler_val) { if(n == m_dim) return; // no-op VINA_CHECK(n > m_dim); m_dim = n; m_data.resize(n*(n-1)/2, filler_val); // preserves original data } void append(const strictly_triangular_matrix& m, const T& filler_val) { sz n = dim(); resize(n + m.dim(), filler_val); VINA_FOR(i, m.dim()) VINA_RANGE(j, i+1, m.dim()) (*this)(i+n, j+n) = m(i, j); } void append(const matrix& rectangular, const strictly_triangular_matrix& triangular) { VINA_CHECK(dim() == rectangular.dim_1()); VINA_CHECK(rectangular.dim_2() == triangular.dim()); // a filler value is needed by append or resize // we will use a value from rectangular as the filler value // but it can not be obtained if dim_1 or dim_2 is 0 // these cases have to be considered separately if(rectangular.dim_2() == 0) return; if(rectangular.dim_1() == 0) { (*this) = triangular; return; } const T& filler_val = rectangular(0, 0); // needed by 'append below' sz n = dim(); append(triangular, filler_val); VINA_FOR(i, rectangular.dim_1()) VINA_FOR(j, rectangular.dim_2()) (*this)(i, n + j) = rectangular(i, j); } VINA_MATRIX_DEFINE_OPERATORS // temp macro defined above sz dim() const { return m_dim; } }; #undef VINA_MATRIX_DEFINE_OPERATORS #endif autodock-vina-1.1.2/src/lib/everything.cpp0000744000175000017500000003365711562571364020415 0ustar moellermoeller/* Copyright (c) 2006-2010, The Scripps Research Institute Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Author: Dr. Oleg Trott , The Olson Lab, The Scripps Research Institute */ #include "everything.h" #include "int_pow.h" inline fl gaussian(fl x, fl width) { return std::exp(-sqr(x/width)); } // distance_additive terms template struct electrostatic : public distance_additive { fl cap; electrostatic(fl cap_, fl cutoff_) : distance_additive(cutoff_), cap(cap_) { name = std::string("electrostatic(i=") + to_string(i) + ", ^=" + to_string(cap) + ", c=" + to_string(cutoff) + ")"; } fl eval(const atom_base& a, const atom_base& b, fl r) const { fl tmp = int_pow(r); fl q1q2 = a.charge * b.charge; if(tmp < epsilon_fl) return q1q2 * cap; else return q1q2 * (std::min)(cap, 1/int_pow(r)); } }; fl solvation_parameter(const atom_type& a) { if(a.ad < AD_TYPE_SIZE) return ad_type_property(a.ad).solvation; else if(a.xs == XS_TYPE_Met_D) return metal_solvation_parameter; VINA_CHECK(false); return 0; // placating the compiler } fl volume(const atom_type& a) { if(a.ad < AD_TYPE_SIZE) return ad_type_property(a.ad).volume; else if(a.xs < XS_TYPE_SIZE) return 4*pi / 3 * int_pow<3>(xs_radius(a.xs)); VINA_CHECK(false); return 0; // placating the compiler } struct ad4_solvation : public distance_additive { fl desolvation_sigma; fl solvation_q; bool charge_dependent; ad4_solvation(fl desolvation_sigma_, fl solvation_q_, bool charge_dependent_, fl cutoff_) : distance_additive(cutoff_), solvation_q(solvation_q_), charge_dependent(charge_dependent_), desolvation_sigma(desolvation_sigma_) { name = std::string("ad4_solvation(d-sigma=") + to_string(desolvation_sigma) + ", s/q=" + to_string(solvation_q) + ", q=" + to_string(charge_dependent) + ", c=" + to_string(cutoff) + ")"; } fl eval(const atom_base& a, const atom_base& b, fl r) const { fl q1 = a.charge; fl q2 = b.charge; VINA_CHECK(not_max(q1)); VINA_CHECK(not_max(q2)); sz t1 = a.ad; sz t2 = b.ad; fl solv1 = solvation_parameter(a); fl solv2 = solvation_parameter(b); fl volume1 = volume(a); fl volume2 = volume(b); fl my_solv = charge_dependent ? solvation_q : 0; fl tmp = ((solv1 + my_solv * std::abs(q1)) * volume2 + (solv2 + my_solv * std::abs(q2)) * volume1) * std::exp(-sqr(r/(2*desolvation_sigma))); VINA_CHECK(not_max(tmp)); return tmp; } }; inline fl optimal_distance(sz xs_t1, sz xs_t2) { return xs_radius(xs_t1) + xs_radius(xs_t2); } struct gauss : public usable { fl offset; // added to optimal distance fl width; gauss(fl offset_, fl width_, fl cutoff_) : usable(cutoff_), offset(offset_), width(width_) { name = std::string("gauss(o=") + to_string(offset) + ", w=" + to_string(width) + ", c=" + to_string(cutoff) + ")"; } fl eval(sz t1, sz t2, fl r) const { return gaussian(r - (optimal_distance(t1, t2) + offset), width); } }; struct repulsion : public usable { fl offset; // added to vdw repulsion(fl offset_, fl cutoff_) : usable(cutoff_), offset(offset_) { name = std::string("repulsion(o=") + to_string(offset) + ")"; } fl eval(sz t1, sz t2, fl r) const { fl d = r - (optimal_distance(t1, t2) + offset); if(d > 0) return 0; return d*d; } }; inline fl slope_step(fl x_bad, fl x_good, fl x) { if(x_bad < x_good) { if(x <= x_bad) return 0; if(x >= x_good) return 1; } else { if(x >= x_bad) return 0; if(x <= x_good) return 1; } return (x - x_bad) / (x_good - x_bad); } struct hydrophobic : public usable { fl good; fl bad; hydrophobic(fl good_, fl bad_, fl cutoff_) : usable(cutoff_), good(good_), bad(bad_) { name = "hydrophobic(g=" + to_string(good) + ", b=" + to_string(bad) + ", c=" + to_string(cutoff) + ")"; } fl eval(sz t1, sz t2, fl r) const { if(xs_is_hydrophobic(t1) && xs_is_hydrophobic(t2)) return slope_step(bad, good, r - optimal_distance(t1, t2)); else return 0; } }; struct non_hydrophobic : public usable { fl good; fl bad; non_hydrophobic(fl good_, fl bad_, fl cutoff_) : usable(cutoff_), good(good_), bad(bad_) { name = "non_hydrophobic(g=" + to_string(good) + ", b=" + to_string(bad) + ", c=" + to_string(cutoff) + ")"; } fl eval(sz t1, sz t2, fl r) const { if(!xs_is_hydrophobic(t1) && !xs_is_hydrophobic(t2)) return slope_step(bad, good, r - optimal_distance(t1, t2)); else return 0; } }; template void find_vdw_coefficients(fl position, fl depth, fl& c_n, fl& c_m) { BOOST_STATIC_ASSERT(n != m); c_n = int_pow(position) * depth * m / (fl(n)-fl(m)); c_m = int_pow(position) * depth * n / (fl(m)-fl(n)); } template struct vdw : public usable { fl smoothing; fl cap; vdw(fl smoothing_, fl cap_, fl cutoff_) : usable(cutoff_), smoothing(smoothing_), cap(cap_) { name = "vdw(i=" + to_string(i) + ", j=" + to_string(j) + ", s=" + to_string(smoothing) + ", ^=" + to_string(cap) + ", c=" + to_string(cutoff) + ")"; } fl eval(sz t1, sz t2, fl r) const { fl d0 = optimal_distance(t1, t2); fl depth = 1; fl c_i = 0; fl c_j = 0; find_vdw_coefficients(d0, depth, c_i, c_j); if (r > d0 + smoothing) r -= smoothing; else if(r < d0 - smoothing) r += smoothing; else r = d0; fl r_i = int_pow(r); fl r_j = int_pow(r); if(r_i > epsilon_fl && r_j > epsilon_fl) return (std::min)(cap, c_i / r_i + c_j / r_j); else return cap; } }; struct non_dir_h_bond : public usable { fl good; fl bad; non_dir_h_bond(fl good_, fl bad_, fl cutoff_) : usable(cutoff_), good(good_), bad(bad_) { name = std::string("non_dir_h_bond(g=") + to_string(good) + ", b=" + to_string(bad) + ")"; } fl eval(sz t1, sz t2, fl r) const { if(xs_h_bond_possible(t1, t2)) return slope_step(bad, good, r - optimal_distance(t1, t2)); return 0; } }; inline fl read_iterator(flv::const_iterator& i) { fl x = *i; ++i; return x; } fl smooth_div(fl x, fl y) { if(std::abs(x) < epsilon_fl) return 0; if(std::abs(y) < epsilon_fl) return ((x*y > 0) ? max_fl : -max_fl); // FIXME I hope -max_fl does not become NaN return x / y; } struct num_tors_add : public conf_independent { num_tors_add() { name = "num_tors_add"; } sz size() const { return 1; } fl eval(const conf_independent_inputs& in, fl x, flv::const_iterator& i) const { //fl w = 0.1 * read_iterator(i); // [-1 .. 1] fl w = read_iterator(i); // FIXME? return x + w * in.num_tors; } }; struct num_tors_sqr : public conf_independent { num_tors_sqr() { name = "num_tors_sqr"; } sz size() const { return 1; } fl eval(const conf_independent_inputs& in, fl x, flv::const_iterator& i) const { fl w = 0.1 * read_iterator(i); // [-1 .. 1] return x + w * sqr(fl(in.num_tors)) / 5; } }; struct num_tors_sqrt : public conf_independent { num_tors_sqrt() { name = "num_tors_sqrt"; } sz size() const { return 1; } fl eval(const conf_independent_inputs& in, fl x, flv::const_iterator& i) const { fl w = 0.1 * read_iterator(i); // [-1 .. 1] return x + w * std::sqrt(fl(in.num_tors)) / sqrt(5.0); } }; struct num_tors_div : public conf_independent { num_tors_div() { name = "num_tors_div"; } sz size() const { return 1; } fl eval(const conf_independent_inputs& in, fl x, flv::const_iterator& i) const { fl w = 0.1 * (read_iterator(i) + 1); // w is in [0..0.2] return smooth_div(x, 1 + w * in.num_tors/5.0); } }; struct ligand_length : public conf_independent { ligand_length() { name = "ligand_length"; } sz size() const { return 1; } fl eval(const conf_independent_inputs& in, fl x, flv::const_iterator& i) const { fl w = read_iterator(i); return x + w * in.ligand_lengths_sum; } }; struct num_ligands : public conf_independent { num_ligands() { name = "num_ligands"; } sz size() const { return 1; } fl eval(const conf_independent_inputs& in, fl x, flv::const_iterator& i) const { fl w = 1 * read_iterator(i); // w is in [-1.. 1] return x + w * in.num_ligands; } }; struct num_heavy_atoms_div : public conf_independent { num_heavy_atoms_div() { name = "num_heavy_atoms_div"; } sz size() const { return 1; } fl eval(const conf_independent_inputs& in, fl x, flv::const_iterator& i) const { fl w = 0.05 * read_iterator(i); return smooth_div(x, 1 + w * in.num_heavy_atoms); } }; struct num_heavy_atoms : public conf_independent { num_heavy_atoms() { name = "num_heavy_atoms"; } sz size() const { return 1; } fl eval(const conf_independent_inputs& in, fl x, flv::const_iterator& i) const { fl w = 0.05 * read_iterator(i); return x + w * in.num_heavy_atoms; } }; struct num_hydrophobic_atoms : public conf_independent { num_hydrophobic_atoms() { name = "num_hydrophobic_atoms"; } sz size() const { return 1; } fl eval(const conf_independent_inputs& in, fl x, flv::const_iterator& i) const { fl w = 0.05 * read_iterator(i); return x + w * in.num_hydrophobic_atoms; } }; everything::everything() { // enabled according to design.out227 const unsigned d = 0; // default const fl cutoff = 8; //6; // FIXME? enable some? //// distance_additive //add(d, new ad4_solvation(3.6, 0.01097, true, cutoff)); // desolvation_sigma, solvation_q, charge_dependent, cutoff //add(d, new ad4_solvation(3.6, 0.01097, false, cutoff)); // desolvation_sigma, solvation_q, charge_dependent, cutoff //add(d, new electrostatic<1>(100, cutoff)); // cap, cutoff //add(d, new electrostatic<2>(100, cutoff)); // cap, cutoff //add(d, new gauss(0, 0.3, cutoff)); // offset, width, cutoff //add(d, new gauss(0.5, 0.3, cutoff)); // offset, width, cutoff //add(d, new gauss(1, 0.3, cutoff)); // offset, width, cutoff //add(d, new gauss(1.5, 0.3, cutoff)); // offset, width, cutoff //add(d, new gauss(2, 0.3, cutoff)); // offset, width, cutoff //add(d, new gauss(2.5, 0.3, cutoff)); // offset, width, cutoff add(1, new gauss(0, 0.5, cutoff)); // offset, width, cutoff // WEIGHT: -0.035579 //add(d, new gauss(1, 0.5, cutoff)); // offset, width, cutoff //add(d, new gauss(2, 0.5, cutoff)); // offset, width, cutoff //add(d, new gauss(0, 0.7, cutoff)); // offset, width, cutoff //add(d, new gauss(1, 0.7, cutoff)); // offset, width, cutoff //add(d, new gauss(2, 0.7, cutoff)); // offset, width, cutoff //add(d, new gauss(0, 0.9, cutoff)); // offset, width, cutoff //add(d, new gauss(1, 0.9, cutoff)); // offset, width, cutoff //add(d, new gauss(2, 0.9, cutoff)); // offset, width, cutoff //add(d, new gauss(3, 0.9, cutoff)); // offset, width, cutoff //add(d, new gauss(0, 1.5, cutoff)); // offset, width, cutoff //add(d, new gauss(1, 1.5, cutoff)); // offset, width, cutoff //add(d, new gauss(2, 1.5, cutoff)); // offset, width, cutoff //add(d, new gauss(3, 1.5, cutoff)); // offset, width, cutoff //add(d, new gauss(4, 1.5, cutoff)); // offset, width, cutoff //add(d, new gauss(0, 2.0, cutoff)); // offset, width, cutoff //add(d, new gauss(1, 2.0, cutoff)); // offset, width, cutoff //add(d, new gauss(2, 2.0, cutoff)); // offset, width, cutoff add(1, new gauss(3, 2.0, cutoff)); // offset, width, cutoff // WEIGHT: -0.005156 //add(d, new gauss(4, 2.0, cutoff)); // offset, width, cutoff //add(d, new gauss(0, 3.0, cutoff)); // offset, width, cutoff //add(d, new gauss(1, 3.0, cutoff)); // offset, width, cutoff //add(d, new gauss(2, 3.0, cutoff)); // offset, width, cutoff //add(d, new gauss(3, 3.0, cutoff)); // offset, width, cutoff //add(d, new gauss(4, 3.0, cutoff)); // offset, width, cutoff //add(d, new repulsion( 0.4, cutoff)); // offset, cutoff //add(d, new repulsion( 0.2, cutoff)); // offset, cutoff add(1, new repulsion( 0.0, cutoff)); // offset, cutoff // WEIGHT: 0.840245 //add(d, new repulsion(-0.2, cutoff)); // offset, cutoff //add(d, new repulsion(-0.4, cutoff)); // offset, cutoff //add(d, new repulsion(-0.6, cutoff)); // offset, cutoff //add(d, new repulsion(-0.8, cutoff)); // offset, cutoff //add(d, new repulsion(-1.0, cutoff)); // offset, cutoff //add(d, new hydrophobic(0.5, 1, cutoff)); // good, bad, cutoff add(1, new hydrophobic(0.5, 1.5, cutoff)); // good, bad, cutoff // WEIGHT: -0.035069 //add(d, new hydrophobic(0.5, 2, cutoff)); // good, bad, cutoff //add(d, new hydrophobic(0.5, 3, cutoff)); // good, bad, cutoff //add(1, new non_hydrophobic(0.5, 1.5, cutoff)); //add(d, new vdw<4, 8>( 0, 100, cutoff)); // smoothing, cap, cutoff add(1, new non_dir_h_bond(-0.7, 0, cutoff)); // good, bad, cutoff // WEIGHT: -0.587439 //add(d, new non_dir_h_bond(-0.7, 0, cutoff)); // good, bad, cutoff //add(d, new non_dir_h_bond(-0.7, 0.2, cutoff)); // good, bad, cutoff //add(d, new non_dir_h_bond(-0.7, 0.4, cutoff)); // good, bad, cutoff // additive // conf-independent //add(d, new num_ligands()); add(1, new num_tors_div()); // WEIGHT: 1.923 -- FIXME too close to limit? //add(d, new num_heavy_atoms_div()); //add(d, new num_heavy_atoms()); //add(1, new num_tors_add()); //add(d, new num_tors_sqr()); //add(d, new num_tors_sqrt()); //add(d, new num_hydrophobic_atoms()); ///add(1, new ligand_length()); //add(d, new num_tors(100, 100, false)); // cap, past_cap, heavy_only //add(1, new num_tors(100, 100, true)); // cap, past_cap, heavy_only //add(d, new num_tors( 2, 1, true)); // cap, past_cap, heavy_only //add(d, new num_heavy_atoms()); //add(d, new ligand_max_num_h_bonds()); //add(1, new num_ligands()); } autodock-vina-1.1.2/src/lib/brick.h0000744000175000017500000000251211562571364016752 0ustar moellermoeller/* Copyright (c) 2006-2010, The Scripps Research Institute Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Author: Dr. Oleg Trott , The Olson Lab, The Scripps Research Institute */ #ifndef VINA_BRICK_H #define VINA_BRICK_H #include "common.h" inline fl closest_between(fl begin, fl end, fl x) { assert(begin <= end); if(x <= begin) return begin; else if(x >= end) return end; return x; } inline vec brick_closest(const vec& begin, const vec& end, const vec& v) { vec tmp; VINA_FOR_IN(i, tmp) tmp[i] = closest_between(begin[i], end[i], v[i]); return tmp; } inline fl brick_distance_sqr(const vec& begin, const vec& end, const vec& v) { vec closest; closest = brick_closest(begin, end, v); return vec_distance_sqr(closest, v); } #endif autodock-vina-1.1.2/src/lib/non_cache.h0000744000175000017500000000245111562571364017577 0ustar moellermoeller/* Copyright (c) 2006-2010, The Scripps Research Institute Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Author: Dr. Oleg Trott , The Olson Lab, The Scripps Research Institute */ #ifndef VINA_NON_CACHE_H #define VINA_NON_CACHE_H #include "igrid.h" #include "szv_grid.h" struct non_cache : public igrid { non_cache(const model& m, const grid_dims& gd_, const precalculate* p_, fl slope_); virtual fl eval (const model& m, fl v) const; // needs m.coords // clean up virtual fl eval_deriv( model& m, fl v) const; // needs m.coords, sets m.minus_forces // clean up bool within(const model& m, fl margin = 0.0001) const; fl slope; private: szv_grid sgrid; grid_dims gd; const precalculate* p; }; #endif autodock-vina-1.1.2/src/lib/monte_carlo.h0000744000175000017500000000417611562571364020172 0ustar moellermoeller/* Copyright (c) 2006-2010, The Scripps Research Institute Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Author: Dr. Oleg Trott , The Olson Lab, The Scripps Research Institute */ #ifndef VINA_MONTE_CARLO_H #define VINA_MONTE_CARLO_H #include "ssd.h" #include "incrementable.h" struct monte_carlo { unsigned num_steps; fl temperature; vec hunt_cap; fl min_rmsd; sz num_saved_mins; fl mutation_amplitude; ssd ssd_par; monte_carlo() : num_steps(2500), temperature(1.2), hunt_cap(10, 1.5, 10), min_rmsd(0.5), num_saved_mins(50), mutation_amplitude(2) {} // T = 600K, R = 2cal/(K*mol) -> temperature = RT = 1.2; num_steps = 50*lig_atoms = 2500 output_type operator()(model& m, const precalculate& p, const igrid& ig, const precalculate& p_widened, const igrid& ig_widened, const vec& corner1, const vec& corner2, incrementable* increment_me, rng& generator) const; output_type many_runs(model& m, const precalculate& p, const igrid& ig, const vec& corner1, const vec& corner2, sz num_runs, rng& generator) const; void single_run(model& m, output_type& out, const precalculate& p, const igrid& ig, rng& generator) const; // out is sorted void operator()(model& m, output_container& out, const precalculate& p, const igrid& ig, const precalculate& p_widened, const igrid& ig_widened, const vec& corner1, const vec& corner2, incrementable* increment_me, rng& generator) const; void many_runs(model& m, output_container& out, const precalculate& p, const igrid& ig, const vec& corner1, const vec& corner2, sz num_runs, rng& generator) const; }; #endif autodock-vina-1.1.2/src/lib/quaternion.cpp0000744000175000017500000001071211562571364020401 0ustar moellermoeller/* Copyright (c) 2006-2010, The Scripps Research Institute Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Author: Dr. Oleg Trott , The Olson Lab, The Scripps Research Institute */ #include "quaternion.h" bool quaternion_is_normalized(const qt& q) { // not in the interface, used in assertions return eq(quaternion_norm_sqr(q), 1) && eq(boost::math::abs(q), 1); } bool eq(const qt& a, const qt& b) { // elementwise approximate equality - may return false for equivalent rotations return eq(a.R_component_1(), b.R_component_1()) && \ eq(a.R_component_2(), b.R_component_2()) && \ eq(a.R_component_3(), b.R_component_3()) && \ eq(a.R_component_4(), b.R_component_4()); } qt angle_to_quaternion(const vec& axis, fl angle) { // axis is assumed to be a unit vector //assert(eq(tvmet::norm2(axis), 1)); assert(eq(axis.norm(), 1)); normalize_angle(angle); // this is probably only necessary if angles can be very big fl c = std::cos(angle/2); fl s = std::sin(angle/2); return qt(c, s*axis[0], s*axis[1], s*axis[2]); } qt angle_to_quaternion(const vec& rotation) { //fl angle = tvmet::norm2(rotation); fl angle = rotation.norm(); if(angle > epsilon_fl) { //vec axis; //axis = rotation / angle; vec axis = (1/angle) * rotation; return angle_to_quaternion(axis, angle); } return qt_identity; } vec quaternion_to_angle(const qt& q) { assert(quaternion_is_normalized(q)); const fl c = q.R_component_1(); if(c > -1 && c < 1) { // c may in theory be outside [-1, 1] even with approximately normalized q, due to rounding errors fl angle = 2*std::acos(c); // acos is in [0, pi] if(angle > pi) angle -= 2*pi; // now angle is in [-pi, pi] vec axis(q.R_component_2(), q.R_component_3(), q.R_component_4()); fl s = std::sin(angle/2); // perhaps not very efficient to calculate sin of acos if(std::abs(s) < epsilon_fl) return zero_vec; axis *= (angle / s); return axis; } else // when c = -1 or 1, angle/2 = 0 or pi, therefore angle = 0 return zero_vec; } mat quaternion_to_r3(const qt& q) { assert(quaternion_is_normalized(q)); const fl a = q.R_component_1(); const fl b = q.R_component_2(); const fl c = q.R_component_3(); const fl d = q.R_component_4(); const fl aa = a*a; const fl ab = a*b; const fl ac = a*c; const fl ad = a*d; const fl bb = b*b; const fl bc = b*c; const fl bd = b*d; const fl cc = c*c; const fl cd = c*d; const fl dd = d*d; assert(eq(aa+bb+cc+dd, 1)); mat tmp; // from http://www.boost.org/doc/libs/1_35_0/libs/math/quaternion/TQE.pdf tmp(0, 0) = (aa+bb-cc-dd); tmp(0, 1) = 2*(-ad+bc); tmp(0, 2) = 2*(ac+bd); tmp(1, 0) = 2*(ad+bc); tmp(1, 1) = (aa-bb+cc-dd); tmp(1, 2) = 2*(-ab+cd); tmp(2, 0) = 2*(-ac+bd); tmp(2, 1) = 2*(ab+cd); tmp(2, 2) = (aa-bb-cc+dd); return tmp; } qt random_orientation(rng& generator) { qt q(random_normal(0, 1, generator), random_normal(0, 1, generator), random_normal(0, 1, generator), random_normal(0, 1, generator)); fl nrm = boost::math::abs(q); if(nrm > epsilon_fl) { q /= nrm; assert(quaternion_is_normalized(q)); return q; } else return random_orientation(generator); // this call should almost never happen } void quaternion_increment(qt& q, const vec& rotation) { assert(quaternion_is_normalized(q)); q = angle_to_quaternion(rotation) * q; quaternion_normalize_approx(q); // normalization added in 1.1.2 //quaternion_normalize(q); // normalization added in 1.1.2 } vec quaternion_difference(const qt& b, const qt& a) { // rotation that needs to be applied to convert a to b quaternion_is_normalized(a); quaternion_is_normalized(b); qt tmp = b; tmp /= a; // b = tmp * a => b * inv(a) = tmp return quaternion_to_angle(tmp); // already assert normalization } void print(const qt& q, std::ostream& out) { // print as an angle print(quaternion_to_angle(q), out); } autodock-vina-1.1.2/src/lib/my_pid.cpp0000744000175000017500000000167611562571364017506 0ustar moellermoeller/* Copyright (c) 2006-2010, The Scripps Research Institute Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Author: Dr. Oleg Trott , The Olson Lab, The Scripps Research Institute */ #ifdef WIN32 #include #else #include #endif #include "my_pid.h" int my_pid() { #ifdef WIN32 return GetCurrentProcessId(); #else return getpid(); #endif } autodock-vina-1.1.2/src/lib/curl.h0000744000175000017500000000267211562571364016634 0ustar moellermoeller/* Copyright (c) 2006-2010, The Scripps Research Institute Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Author: Dr. Oleg Trott , The Olson Lab, The Scripps Research Institute */ #ifndef VINA_CURL_H #define VINA_CURL_H #include "common.h" #if 1 // prefer this to "hard curl"? template // T = fl or vec void curl(fl& e, T& deriv, fl v) { if(e > 0 && not_max(v)) { // FIXME authentic_v can be gotten rid of everywhere now fl tmp = (v < epsilon_fl) ? 0 : (v / (v + e)); e *= tmp; deriv *= sqr(tmp); } } inline void curl(fl& e, fl v) { if(e > 0 && not_max(v)) { fl tmp = (v < epsilon_fl) ? 0 : (v / (v + e)); e *= tmp; } } #else template // T = fl or vec void curl(fl& e, T& deriv, fl v) { if(e > v) { e = v; deriv = 0; } } inline void curl(fl& e, fl v) { if(e > v) { e = v; } } #endif #endif autodock-vina-1.1.2/src/lib/model.h0000744000175000017500000002117311562571364016764 0ustar moellermoeller/* Copyright (c) 2006-2010, The Scripps Research Institute Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Author: Dr. Oleg Trott , The Olson Lab, The Scripps Research Institute */ #ifndef VINA_MODEL_H #define VINA_MODEL_H #include // for context #include "file.h" #include "tree.h" #include "matrix.h" #include "precalculate.h" #include "igrid.h" #include "grid_dim.h" struct interacting_pair { sz type_pair_index; sz a; sz b; interacting_pair(sz type_pair_index_, sz a_, sz b_) : type_pair_index(type_pair_index_), a(a_), b(b_) {} }; typedef std::vector interacting_pairs; typedef std::pair > parsed_line; typedef std::vector context; struct ligand : public flexible_body, atom_range { unsigned degrees_of_freedom; // can be different from the apparent number of rotatable bonds, because of the disabled torsions interacting_pairs pairs; context cont; ligand(const flexible_body& f, unsigned degrees_of_freedom_) : flexible_body(f), atom_range(0, 0), degrees_of_freedom(degrees_of_freedom_) {} void set_range(); }; struct residue : public main_branch { residue(const main_branch& m) : main_branch(m) {} }; enum distance_type {DISTANCE_FIXED, DISTANCE_ROTOR, DISTANCE_VARIABLE}; typedef strictly_triangular_matrix distance_type_matrix; struct non_cache; // forward declaration struct naive_non_cache; // forward declaration struct cache; // forward declaration struct szv_grid; // forward declaration struct terms; // forward declaration struct conf_independent_inputs; // forward declaration struct pdbqt_initializer; // forward declaration - only declared in parse_pdbqt.cpp struct model_test; struct model { void append(const model& m); atom_type::t atom_typing_used() const { return m_atom_typing_used; } sz num_movable_atoms() const { return m_num_movable_atoms; } sz num_internal_pairs() const; sz num_other_pairs() const { return other_pairs.size(); } sz num_ligands() const { return ligands.size(); } sz num_flex() const { return flex.size(); } sz ligand_degrees_of_freedom(sz ligand_number) const { return ligands[ligand_number].degrees_of_freedom; } sz ligand_longest_branch(sz ligand_number) const; sz ligand_length(sz ligand_number) const; szv get_movable_atom_types(atom_type::t atom_typing_used_) const; conf_size get_size() const; conf get_initial_conf() const; // torsions = 0, orientations = identity, ligand positions = current grid_dims movable_atoms_box(fl add_to_each_dimension, fl granularity = 0.375) const; void write_flex ( const path& name, const std::string& remark) const { write_context(flex_context, name, remark); } void write_ligand(sz ligand_number, const path& name, const std::string& remark) const { VINA_CHECK(ligand_number < ligands.size()); write_context(ligands[ligand_number].cont, name, remark); } void write_structure(ofile& out) const { VINA_FOR_IN(i, ligands) write_context(ligands[i].cont, out); if(num_flex() > 0) // otherwise remark is written in vain write_context(flex_context, out); } void write_structure(ofile& out, const std::string& remark) const { out << remark; write_structure(out); } void write_structure(const path& name) const { ofile out(name); write_structure(out); } void write_model(ofile& out, sz model_number, const std::string& remark) const { out << "MODEL " << model_number << '\n'; write_structure(out, remark); out << "ENDMDL\n"; } void seti(const conf& c); void sete(const conf& c); void set (const conf& c); fl gyration_radius(sz ligand_number) const; // uses coords const atom_base& movable_atom (sz i) const { assert(i < m_num_movable_atoms); return atoms[i]; } const vec& movable_coords(sz i) const { assert(i < m_num_movable_atoms); return coords[i]; } const vec& atom_coords(const atom_index& i) const; fl distance_sqr_between(const atom_index& a, const atom_index& b) const; bool atom_exists_between(const distance_type_matrix& mobility, const atom_index& a, const atom_index& b, const szv& relevant_atoms) const; // there is an atom closer to both a and b then they are to each other and immobile relative to them distance_type distance_type_between(const distance_type_matrix& mobility, const atom_index& i, const atom_index& j) const; // clean up fl evali (const precalculate& p, const vec& v ) const; fl evale (const precalculate& p, const igrid& ig, const vec& v ) const; fl eval (const precalculate& p, const igrid& ig, const vec& v, const conf& c ); fl eval_deriv(const precalculate& p, const igrid& ig, const vec& v, const conf& c, change& g); fl eval_intramolecular( const precalculate& p, const vec& v, const conf& c); fl eval_adjusted (const scoring_function& sf, const precalculate& p, const igrid& ig, const vec& v, const conf& c, fl intramolecular_energy); fl rmsd_lower_bound(const model& m) const; // uses coords fl rmsd_upper_bound(const model& m) const; // uses coords fl rmsd_ligands_upper_bound(const model& m) const; // uses coords void verify_bond_lengths() const; void about() const; vecv get_ligand_internal_coords() const { // FIXME rm VINA_CHECK(ligands.size() == 1); vecv tmp; const ligand& lig = ligands.front(); VINA_RANGE(i, lig.begin, lig.end) tmp.push_back(internal_coords[i]); return tmp; } vecv get_ligand_coords() const { // FIXME rm VINA_CHECK(ligands.size() == 1); vecv tmp; const ligand& lig = ligands.front(); VINA_RANGE(i, lig.begin, lig.end) tmp.push_back(coords[i]); return tmp; } vecv get_heavy_atom_movable_coords() const { // FIXME mv vecv tmp; VINA_FOR(i, num_movable_atoms()) if(atoms[i].el != EL_TYPE_H) tmp.push_back(coords[i]); return tmp; } void check_internal_pairs() const; void print_stuff() const; // FIXME rm fl clash_penalty() const; private: friend struct non_cache; friend struct naive_non_cache; friend struct cache; friend struct szv_grid; friend struct terms; friend struct conf_independent_inputs; friend struct appender_info; friend struct pdbqt_initializer; friend struct model_test; model() : m_num_movable_atoms(0), m_atom_typing_used(atom_type::XS) {}; const atom& get_atom(const atom_index& i) const { return (i.in_grid ? grid_atoms[i.i] : atoms[i.i]); } atom& get_atom(const atom_index& i) { return (i.in_grid ? grid_atoms[i.i] : atoms[i.i]); } void write_context(const context& c, ofile& out) const; void write_context(const context& c, ofile& out, const std::string& remark) const { out << remark; } void write_context(const context& c, const path& name) const { ofile out(name); write_context(c, out); } void write_context(const context& c, const path& name, const std::string& remark) const { ofile out(name); write_context(c, out, remark); } fl rmsd_lower_bound_asymmetric(const model& x, const model& y) const; // actually static atom_index sz_to_atom_index(sz i) const; // grid_atoms, atoms bool bonded_to_HD(const atom& a) const; bool bonded_to_heteroatom(const atom& a) const; sz find_ligand(sz a) const; void bonded_to(sz a, sz n, szv& out) const; szv bonded_to(sz a, sz n) const; void assign_bonds(const distance_type_matrix& mobility); // assign bonds based on relative mobility, distance and covalent length void assign_types(); void initialize_pairs(const distance_type_matrix& mobility); void initialize(const distance_type_matrix& mobility); fl clash_penalty_aux(const interacting_pairs& pairs) const; vecv internal_coords; vecv coords; vecv minus_forces; atomv grid_atoms; atomv atoms; // movable, inflex vector_mutable ligands; vector_mutable flex; context flex_context; interacting_pairs other_pairs; // all except internal to one ligand: ligand-other ligands; ligand-flex/inflex; flex-flex/inflex sz m_num_movable_atoms; atom_type::t m_atom_typing_used; }; #endif autodock-vina-1.1.2/src/lib/quaternion.h0000744000175000017500000000605511562571364020053 0ustar moellermoeller/* Copyright (c) 2006-2010, The Scripps Research Institute Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Author: Dr. Oleg Trott , The Olson Lab, The Scripps Research Institute */ #ifndef VINA_QUATERNION_H #define VINA_QUATERNION_H #include #include #include "common.h" #include "random.h" typedef boost::math::quaternion qt; // non-intrusive free function split serialization namespace boost { namespace serialization { template void save(Archive& ar, const qt& q, const unsigned version) { fl q1 = q.R_component_1(); fl q2 = q.R_component_2(); fl q3 = q.R_component_3(); fl q4 = q.R_component_4(); ar & q1; ar & q2; ar & q3; ar & q4; } template void load(Archive& ar, qt& q, const unsigned version) { fl a, b, c, d; ar & a; ar & b; ar & c; ar & d; q = qt(a, b, c, d); } } } BOOST_SERIALIZATION_SPLIT_FREE(qt) bool eq(const qt& a, const qt& b); // elementwise approximate equality - may return false for equivalent rotations const qt qt_identity(1, 0, 0, 0); qt angle_to_quaternion(const vec& axis, fl angle); // axis is assumed to be a unit vector qt angle_to_quaternion(const vec& rotation); // rotation == angle * axis vec quaternion_to_angle(const qt& q); mat quaternion_to_r3(const qt& q); inline fl quaternion_norm_sqr(const qt& q) { // equivalent to sqr(boost::math::abs(const qt&)) return sqr(q.R_component_1()) + sqr(q.R_component_2()) + sqr(q.R_component_3()) + sqr(q.R_component_4()); } inline void quaternion_normalize(qt& q) { const fl s = quaternion_norm_sqr(q); assert(eq(s, sqr(boost::math::abs(q)))); const fl a = std::sqrt(s); assert(a > epsilon_fl); q *= 1/a; assert(quaternion_is_normalized(q)); } inline void quaternion_normalize_approx(qt& q, const fl tolerance = 1e-6) { const fl s = quaternion_norm_sqr(q); assert(eq(s, sqr(boost::math::abs(q)))); if(std::abs(s - 1) < tolerance) ; // most likely scenario else { const fl a = std::sqrt(s); assert(a > epsilon_fl); q *= 1/a; assert(quaternion_is_normalized(q)); } } qt random_orientation(rng& generator); void quaternion_increment(qt& q, const vec& rotation); vec quaternion_difference(const qt& b, const qt& a); // rotation that needs to be applied to convert a to b void print(const qt& q, std::ostream& out = std::cout); // print as an angle #endif autodock-vina-1.1.2/src/lib/conf.h0000744000175000017500000002624311562571364016614 0ustar moellermoeller/* Copyright (c) 2006-2010, The Scripps Research Institute Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Author: Dr. Oleg Trott , The Olson Lab, The Scripps Research Institute */ #ifndef VINA_CONF_H #define VINA_CONF_H #include // typedef output_container #include "quaternion.h" #include "random.h" struct scale { fl position; fl orientation; fl torsion; scale(fl position_, fl orientation_, fl torsion_) : position(position_), orientation(orientation_), torsion(torsion_) {} }; struct conf_size { szv ligands; szv flex; sz num_degrees_of_freedom() const { return sum(ligands) + sum(flex) + 6 * ligands.size(); } }; inline void torsions_set_to_null(flv& torsions) { VINA_FOR_IN(i, torsions) torsions[i] = 0; } inline void torsions_increment(flv& torsions, const flv& c, fl factor) { // new torsions are normalized VINA_FOR_IN(i, torsions) { torsions[i] += normalized_angle(factor * c[i]); normalize_angle(torsions[i]); } } inline void torsions_randomize(flv& torsions, rng& generator) { VINA_FOR_IN(i, torsions) torsions[i] = random_fl(-pi, pi, generator); } inline bool torsions_too_close(const flv& torsions1, const flv& torsions2, fl cutoff) { assert(torsions1.size() == torsions2.size()); VINA_FOR_IN(i, torsions1) if(std::abs(normalized_angle(torsions1[i] - torsions2[i])) > cutoff) return false; return true; } inline void torsions_generate(flv& torsions, fl spread, fl rp, const flv* rs, rng& generator) { assert(!rs || rs->size() == torsions.size()); // if present, rs should be the same size as torsions VINA_FOR_IN(i, torsions) if(rs && random_fl(0, 1, generator) < rp) torsions[i] = (*rs)[i]; else torsions[i] += random_fl(-spread, spread, generator); } struct rigid_change { vec position; vec orientation; rigid_change() : position(0, 0, 0), orientation(0, 0, 0) {} void print() const { ::print(position); ::print(orientation); } }; struct rigid_conf { vec position; qt orientation; rigid_conf() : position(0, 0, 0), orientation(qt_identity) {} void set_to_null() { position = zero_vec; orientation = qt_identity; } void increment(const rigid_change& c, fl factor) { position += factor * c.position; vec rotation; rotation = factor * c.orientation; quaternion_increment(orientation, rotation); // orientation does not get normalized; tests show rounding errors growing very slowly } void randomize(const vec& corner1, const vec& corner2, rng& generator) { position = random_in_box(corner1, corner2, generator); orientation = random_orientation(generator); } bool too_close(const rigid_conf& c, fl position_cutoff, fl orientation_cutoff) const { if(vec_distance_sqr(position, c.position) > sqr(position_cutoff)) return false; if(sqr(quaternion_difference(orientation, c.orientation)) > sqr(orientation_cutoff)) return false; return true; } void mutate_position(fl spread, rng& generator) { position += spread * random_inside_sphere(generator); } void mutate_orientation(fl spread, rng& generator) { vec tmp; tmp = spread * random_inside_sphere(generator); quaternion_increment(orientation, tmp); } void generate(fl position_spread, fl orientation_spread, fl rp, const rigid_conf* rs, rng& generator) { if(rs && random_fl(0, 1, generator) < rp) position = rs->position; else mutate_position(position_spread, generator); if(rs && random_fl(0, 1, generator) < rp) orientation = rs->orientation; else mutate_orientation(orientation_spread, generator); } void apply(const vecv& in, vecv& out, sz begin, sz end) const { assert(in.size() == out.size()); const mat m = quaternion_to_r3(orientation); VINA_RANGE(i, begin, end) out[i] = m * in[i] + position; } void print() const { ::print(position); ::print(orientation); } private: friend class boost::serialization::access; template void serialize(Archive & ar, const unsigned version) { ar & position; ar & orientation; } }; struct ligand_change { rigid_change rigid; flv torsions; void print() const { rigid.print(); printnl(torsions); } }; struct ligand_conf { rigid_conf rigid; flv torsions; void set_to_null() { rigid.set_to_null(); torsions_set_to_null(torsions); } void increment(const ligand_change& c, fl factor) { rigid.increment(c.rigid, factor); torsions_increment(torsions, c.torsions, factor); } void randomize(const vec& corner1, const vec& corner2, rng& generator) { rigid.randomize(corner1, corner2, generator); torsions_randomize(torsions, generator); } void print() const { rigid.print(); printnl(torsions); } private: friend class boost::serialization::access; template void serialize(Archive & ar, const unsigned version) { ar & rigid; ar & torsions; } }; struct residue_change { flv torsions; void print() const { printnl(torsions); } }; struct residue_conf { flv torsions; void set_to_null() { torsions_set_to_null(torsions); } void increment(const residue_change& c, fl factor) { torsions_increment(torsions, c.torsions, factor); } void randomize(rng& generator) { torsions_randomize(torsions, generator); } void print() const { printnl(torsions); } private: friend class boost::serialization::access; template void serialize(Archive & ar, const unsigned version) { ar & torsions; } }; struct change { std::vector ligands; std::vector flex; change(const conf_size& s) : ligands(s.ligands.size()), flex(s.flex.size()) { VINA_FOR_IN(i, ligands) ligands[i].torsions.resize(s.ligands[i], 0); VINA_FOR_IN(i, flex) flex[i].torsions.resize(s.flex[i], 0); } fl operator()(sz index) const { // returns by value VINA_FOR_IN(i, ligands) { const ligand_change& lig = ligands[i]; if(index < 3) return lig.rigid.position[index]; index -= 3; if(index < 3) return lig.rigid.orientation[index]; index -= 3; if(index < lig.torsions.size()) return lig.torsions[index]; index -= lig.torsions.size(); } VINA_FOR_IN(i, flex) { const residue_change& res = flex[i]; if(index < res.torsions.size()) return res.torsions[index]; index -= res.torsions.size(); } VINA_CHECK(false); return 0; // shouldn't happen, placating the compiler } fl& operator()(sz index) { VINA_FOR_IN(i, ligands) { ligand_change& lig = ligands[i]; if(index < 3) return lig.rigid.position[index]; index -= 3; if(index < 3) return lig.rigid.orientation[index]; index -= 3; if(index < lig.torsions.size()) return lig.torsions[index]; index -= lig.torsions.size(); } VINA_FOR_IN(i, flex) { residue_change& res = flex[i]; if(index < res.torsions.size()) return res.torsions[index]; index -= res.torsions.size(); } VINA_CHECK(false); return ligands[0].rigid.position[0]; // shouldn't happen, placating the compiler } sz num_floats() const { sz tmp = 0; VINA_FOR_IN(i, ligands) tmp += 6 + ligands[i].torsions.size(); VINA_FOR_IN(i, flex) tmp += flex[i].torsions.size(); return tmp; } void print() const { VINA_FOR_IN(i, ligands) ligands[i].print(); VINA_FOR_IN(i, flex) flex[i].print(); } }; struct conf { std::vector ligands; std::vector flex; conf() {} conf(const conf_size& s) : ligands(s.ligands.size()), flex(s.flex.size()) { VINA_FOR_IN(i, ligands) ligands[i].torsions.resize(s.ligands[i], 0); // FIXME? VINA_FOR_IN(i, flex) flex[i].torsions.resize(s.flex[i], 0); // FIXME? } void set_to_null() { VINA_FOR_IN(i, ligands) ligands[i].set_to_null(); VINA_FOR_IN(i, flex) flex[i].set_to_null(); } void increment(const change& c, fl factor) { // torsions get normalized, orientations do not VINA_FOR_IN(i, ligands) ligands[i].increment(c.ligands[i], factor); VINA_FOR_IN(i, flex) flex[i] .increment(c.flex[i], factor); } bool internal_too_close(const conf& c, fl torsions_cutoff) const { assert(ligands.size() == c.ligands.size()); VINA_FOR_IN(i, ligands) if(!torsions_too_close(ligands[i].torsions, c.ligands[i].torsions, torsions_cutoff)) return false; return true; } bool external_too_close(const conf& c, const scale& cutoff) const { assert(ligands.size() == c.ligands.size()); VINA_FOR_IN(i, ligands) if(!ligands[i].rigid.too_close(c.ligands[i].rigid, cutoff.position, cutoff.orientation)) return false; assert(flex.size() == c.flex.size()); VINA_FOR_IN(i, flex) if(!torsions_too_close(flex[i].torsions, c.flex[i].torsions, cutoff.torsion)) return false; return true; } bool too_close(const conf& c, const scale& cutoff) const { return internal_too_close(c, cutoff.torsion) && external_too_close(c, cutoff); // a more efficient implementation is possible, probably } void generate_internal(fl torsion_spread, fl rp, const conf* rs, rng& generator) { // torsions are not normalized after this VINA_FOR_IN(i, ligands) { ligands[i].rigid.position.assign(0); ligands[i].rigid.orientation = qt_identity; const flv* torsions_rs = rs ? (&rs->ligands[i].torsions) : NULL; torsions_generate(ligands[i].torsions, torsion_spread, rp, torsions_rs, generator); } } void generate_external(const scale& spread, fl rp, const conf* rs, rng& generator) { // torsions are not normalized after this VINA_FOR_IN(i, ligands) { const rigid_conf* rigid_conf_rs = rs ? (&rs->ligands[i].rigid) : NULL; ligands[i].rigid.generate(spread.position, spread.orientation, rp, rigid_conf_rs, generator); } VINA_FOR_IN(i, flex) { const flv* torsions_rs = rs ? (&rs->flex[i].torsions) : NULL; torsions_generate(flex[i].torsions, spread.torsion, rp, torsions_rs, generator); } } void randomize(const vec& corner1, const vec& corner2, rng& generator) { VINA_FOR_IN(i, ligands) ligands[i].randomize(corner1, corner2, generator); VINA_FOR_IN(i, flex) flex[i].randomize(generator); } void print() const { VINA_FOR_IN(i, ligands) ligands[i].print(); VINA_FOR_IN(i, flex) flex[i].print(); } private: friend class boost::serialization::access; template void serialize(Archive & ar, const unsigned version) { ar & ligands; ar & flex; } }; struct output_type { conf c; fl e; vecv coords; output_type(const conf& c_, fl e_) : c(c_), e(e_) {} }; typedef boost::ptr_vector output_container; inline bool operator<(const output_type& a, const output_type& b) { // for sorting output_container return a.e < b.e; } #endif autodock-vina-1.1.2/src/lib/random.h0000744000175000017500000000274411562571364017147 0ustar moellermoeller/* Copyright (c) 2006-2010, The Scripps Research Institute Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Author: Dr. Oleg Trott , The Olson Lab, The Scripps Research Institute */ #ifndef VINA_RANDOM_H #define VINA_RANDOM_H #include #include "common.h" typedef boost::mt19937 rng; fl random_fl(fl a, fl b, rng& generator); // expects a < b, returns rand in [a, b] fl random_normal(fl mean, fl sigma, rng& generator); // expects sigma >= 0 int random_int(int a, int b, rng& generator); // expects a <= b, returns rand in [a, b] sz random_sz(sz a, sz b, rng& generator); // expects a <= b, returns rand in [a, b] vec random_inside_sphere(rng& generator); // returns a random vec inside the sphere centered at 0 with radius 1 vec random_in_box(const vec& corner1, const vec& corner2, rng& generator); // expects corner1[i] < corner2[i] int auto_seed(); // make seed from PID and time #endif autodock-vina-1.1.2/src/lib/ssd.h0000744000175000017500000000247511562571364016461 0ustar moellermoeller/* Copyright (c) 2006-2010, The Scripps Research Institute Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Author: Dr. Oleg Trott , The Olson Lab, The Scripps Research Institute */ #ifndef VINA_SSD_H #define VINA_SSD_H #include "model.h" struct ssd { unsigned evals; fl initial_factor; fl min_factor; fl up; fl down; void print() const { std::cout << "evals=" << evals << ", initial_factor=" << initial_factor << ", min_factor=" << min_factor << ", up=" << up << ", down=" << down; } ssd() : evals(300), initial_factor(1e-4), min_factor(1e-6), up(1.6), down(0.5) {} // clean up void operator()(model& m, const precalculate& p, const igrid& ig, output_type& out, change& g, const vec& v) const; // g must have correct size }; #endif autodock-vina-1.1.2/src/lib/precalculate.h0000744000175000017500000001253511562571364020332 0ustar moellermoeller/* Copyright (c) 2006-2010, The Scripps Research Institute Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Author: Dr. Oleg Trott , The Olson Lab, The Scripps Research Institute */ #ifndef VINA_PRECALCULATE_H #define VINA_PRECALCULATE_H #include "scoring_function.h" #include "matrix.h" struct precalculate_element { precalculate_element(sz n, fl factor_) : fast(n, 0), smooth(n, pr(0, 0)), factor(factor_) {} fl eval_fast(fl r2) const { assert(r2 * factor < fast.size()); sz i = sz(factor * r2); // r2 is expected < cutoff_sqr, and cutoff_sqr * factor + 1 < n, so no overflow assert(i < fast.size()); return fast[i]; } pr eval_deriv(fl r2) const { fl r2_factored = factor * r2; assert(r2_factored + 1 < smooth.size()); sz i1 = sz(r2_factored); sz i2 = i1 + 1; // r2 is expected < cutoff_sqr, and cutoff_sqr * factor + 1 < n, so no overflow assert(i1 < smooth.size()); assert(i2 < smooth.size()); fl rem = r2_factored - i1; assert(rem >= -epsilon_fl); assert(rem < 1 + epsilon_fl); const pr& p1 = smooth[i1]; const pr& p2 = smooth[i2]; fl e = p1.first + rem * (p2.first - p1.first); fl dor = p1.second + rem * (p2.second - p1.second); return pr(e, dor); } void init_from_smooth_fst(const flv& rs) { sz n = smooth.size(); VINA_CHECK(rs.size() == n); VINA_CHECK(fast.size() == n); VINA_FOR(i, n) { // calculate dor's fl& dor = smooth[i].second; if(i == 0 || i == n-1) dor = 0; else { fl delta = rs[i+1] - rs[i-1]; fl r = rs[i]; dor = (smooth[i+1].first - smooth[i-1].first) / (delta * r); } // calculate fast's from smooth.first's fl f1 = smooth[i].first; fl f2 = (i+1 >= n) ? 0 : smooth[i+1].first; fast[i] = (f2 + f1) / 2; } } sz min_smooth_fst() const { sz tmp = 0; // returned if smooth.empty() VINA_FOR_IN(i_inv, smooth) { sz i = smooth.size() - i_inv - 1; // i_inv < smooth.size() => i_inv + 1 <= smooth.size() if(i_inv == 0 || smooth[i].first < smooth[tmp].first) tmp = i; } return tmp; } void widen_smooth_fst(const flv& rs, fl left, fl right) { flv tmp(smooth.size(), 0); // the new smooth[].first's sz min_index = min_smooth_fst(); VINA_CHECK(min_index < rs.size()); // won't hold for n == 0 VINA_CHECK(rs.size() == smooth.size()); fl optimal_r = rs[min_index]; VINA_FOR_IN(i, smooth) { fl r = rs[i]; if (r < optimal_r - left ) r += left; else if(r > optimal_r + right) r -= right; else r = optimal_r; if(r < 0) r = 0; if(r > rs.back()) r = rs.back(); tmp[i] = eval_deriv(sqr(r)).first; } VINA_FOR_IN(i, smooth) smooth[i].first = tmp[i]; } void widen(const flv& rs, fl left, fl right) { widen_smooth_fst(rs, left, right); init_from_smooth_fst(rs); } flv fast; prv smooth; // [(e, dor)] fl factor; }; struct precalculate { precalculate(const scoring_function& sf, fl v = max_fl, fl factor_ = 32) : // sf should not be discontinuous, even near cutoff, for the sake of the derivatives m_cutoff_sqr(sqr(sf.cutoff())), n(sz(factor_ * m_cutoff_sqr) + 3), // sz(factor * r^2) + 1 <= sz(factor * cutoff_sqr) + 2 <= n-1 < n // see assert below factor(factor_), data(num_atom_types(sf.atom_typing_used()), precalculate_element(n, factor_)), m_atom_typing_used(sf.atom_typing_used()) { VINA_CHECK(factor > epsilon_fl); VINA_CHECK(sz(m_cutoff_sqr*factor) + 1 < n); // cutoff_sqr * factor is the largest float we may end up converting into sz, then 1 can be added to the result VINA_CHECK(m_cutoff_sqr*factor + 1 < n); flv rs = calculate_rs(); VINA_FOR(t1, data.dim()) VINA_RANGE(t2, t1, data.dim()) { precalculate_element& p = data(t1, t2); // init smooth[].first VINA_FOR_IN(i, p.smooth) p.smooth[i].first = (std::min)(v, sf.eval(t1, t2, rs[i])); // init the rest p.init_from_smooth_fst(rs); } } fl eval_fast(sz type_pair_index, fl r2) const { assert(r2 <= m_cutoff_sqr); return data(type_pair_index).eval_fast(r2); } pr eval_deriv(sz type_pair_index, fl r2) const { assert(r2 <= m_cutoff_sqr); return data(type_pair_index).eval_deriv(r2); } sz index_permissive(sz t1, sz t2) const { return data.index_permissive(t1, t2); } atom_type::t atom_typing_used() const { return m_atom_typing_used; } fl cutoff_sqr() const { return m_cutoff_sqr; } void widen(fl left, fl right) { flv rs = calculate_rs(); VINA_FOR(t1, data.dim()) VINA_RANGE(t2, t1, data.dim()) data(t1, t2).widen(rs, left, right); } private: flv calculate_rs() const { flv tmp(n, 0); VINA_FOR(i, n) tmp[i] = std::sqrt(i / factor); return tmp; } fl m_cutoff_sqr; sz n; fl factor; atom_type::t m_atom_typing_used; triangular_matrix data; }; #endif autodock-vina-1.1.2/src/lib/file.h0000744000175000017500000000343711562571364016606 0ustar moellermoeller/* Copyright (c) 2006-2010, The Scripps Research Institute Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Author: Dr. Oleg Trott , The Olson Lab, The Scripps Research Institute */ #ifndef VINA_FILE_H #define VINA_FILE_H #include #include "common.h" struct file_error { path name; bool in; file_error(const path& name_, bool in_) : name(name_), in(in_) {} }; struct ifile : public boost::filesystem::ifstream { // never use ifstream pointer to destroy ifile - no virtual destructors, possibly ifile(const path& name) : boost::filesystem::ifstream(name) { if(!(*this)) throw file_error(name, true); } ifile(const path& name, std::ios_base::openmode mode) : boost::filesystem::ifstream(name, mode) { if(!(*this)) throw file_error(name, true); } }; struct ofile : public boost::filesystem::ofstream { // never use ofstream pointer to destroy ofile - no virtual destructors, possibly ofile(const path& name) : boost::filesystem::ofstream(name) { if(!(*this)) throw file_error(name, false); } ofile(const path& name, std::ios_base::openmode mode) : boost::filesystem::ofstream(name, mode) { if(!(*this)) throw file_error(name, false); } }; #endif autodock-vina-1.1.2/src/lib/my_pid.h0000744000175000017500000000150311562571364017140 0ustar moellermoeller/* Copyright (c) 2006-2010, The Scripps Research Institute Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Author: Dr. Oleg Trott , The Olson Lab, The Scripps Research Institute */ #ifndef VINA_MY_PID_H #define VINA_MY_PID_H int my_pid(); #endif autodock-vina-1.1.2/src/lib/szv_grid.h0000744000175000017500000000231411562571364017507 0ustar moellermoeller/* Copyright (c) 2006-2010, The Scripps Research Institute Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Author: Dr. Oleg Trott , The Olson Lab, The Scripps Research Institute */ #ifndef VINA_SZV_GRID_H #define VINA_SZV_GRID_H #include "model.h" #include "grid_dim.h" #include "array3d.h" struct szv_grid { szv_grid(const model& m, const grid_dims& gd, fl cutoff_sqr); const szv& possibilities(const vec& coords) const; fl average_num_possibilities() const; private: array3d m_data; vec m_init; vec m_range; vec index_to_coord(sz i, sz j, sz k) const; }; grid_dims szv_grid_dims(const grid_dims& gd); #endif autodock-vina-1.1.2/src/lib/non_cache.cpp0000744000175000017500000001070611562571364020134 0ustar moellermoeller/* Copyright (c) 2006-2010, The Scripps Research Institute Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Author: Dr. Oleg Trott , The Olson Lab, The Scripps Research Institute */ #include "non_cache.h" #include "curl.h" non_cache::non_cache(const model& m, const grid_dims& gd_, const precalculate* p_, fl slope_) : sgrid(m, szv_grid_dims(gd_), p_->cutoff_sqr()), gd(gd_), p(p_), slope(slope_) {} fl non_cache::eval (const model& m, fl v) const { // clean up fl e = 0; const fl cutoff_sqr = p->cutoff_sqr(); sz n = num_atom_types(p->atom_typing_used()); VINA_FOR(i, m.num_movable_atoms()) { fl this_e = 0; fl out_of_bounds_penalty = 0; const atom& a = m.atoms[i]; sz t1 = a.get(p->atom_typing_used()); if(t1 >= n) continue; const vec& a_coords = m.coords[i]; vec adjusted_a_coords; adjusted_a_coords = a_coords; VINA_FOR_IN(j, gd) { if(gd[j].n > 0) { if (a_coords[j] < gd[j].begin) { adjusted_a_coords[j] = gd[j].begin; out_of_bounds_penalty += std::abs(a_coords[j] - gd[j].begin); } else if(a_coords[j] > gd[j].end ) { adjusted_a_coords[j] = gd[j] .end; out_of_bounds_penalty += std::abs(a_coords[j] - gd[j] .end); } } } out_of_bounds_penalty *= slope; const szv& possibilities = sgrid.possibilities(adjusted_a_coords); VINA_FOR_IN(possibilities_j, possibilities) { const sz j = possibilities[possibilities_j]; const atom& b = m.grid_atoms[j]; sz t2 = b.get(p->atom_typing_used()); if(t2 >= n) continue; vec r_ba; r_ba = adjusted_a_coords - b.coords; // FIXME why b-a and not a-b ? fl r2 = sqr(r_ba); if(r2 < cutoff_sqr) { sz type_pair_index = get_type_pair_index(p->atom_typing_used(), a, b); this_e += p->eval_fast(type_pair_index, r2); } } curl(this_e, v); e += this_e + out_of_bounds_penalty; } return e; } bool non_cache::within(const model& m, fl margin) const { VINA_FOR(i, m.num_movable_atoms()) { if(m.atoms[i].is_hydrogen()) continue; const vec& a_coords = m.coords[i]; VINA_FOR_IN(j, gd) if(gd[j].n > 0) if(a_coords[j] < gd[j].begin - margin || a_coords[j] > gd[j].end + margin) return false; } return true; } fl non_cache::eval_deriv( model& m, fl v) const { // clean up fl e = 0; const fl cutoff_sqr = p->cutoff_sqr(); sz n = num_atom_types(p->atom_typing_used()); VINA_FOR(i, m.num_movable_atoms()) { fl this_e = 0; vec deriv(0, 0, 0); vec out_of_bounds_deriv(0, 0, 0); fl out_of_bounds_penalty = 0; const atom& a = m.atoms[i]; sz t1 = a.get(p->atom_typing_used()); if(t1 >= n) { m.minus_forces[i].assign(0); continue; } const vec& a_coords = m.coords[i]; vec adjusted_a_coords; adjusted_a_coords = a_coords; VINA_FOR_IN(j, gd) { if(gd[j].n > 0) { if (a_coords[j] < gd[j].begin) { adjusted_a_coords[j] = gd[j].begin; out_of_bounds_deriv[j] = -1; out_of_bounds_penalty += std::abs(a_coords[j] - gd[j].begin); } else if(a_coords[j] > gd[j].end ) { adjusted_a_coords[j] = gd[j] .end; out_of_bounds_deriv[j] = 1; out_of_bounds_penalty += std::abs(a_coords[j] - gd[j] .end); } } } out_of_bounds_penalty *= slope; out_of_bounds_deriv *= slope; const szv& possibilities = sgrid.possibilities(adjusted_a_coords); VINA_FOR_IN(possibilities_j, possibilities) { const sz j = possibilities[possibilities_j]; const atom& b = m.grid_atoms[j]; sz t2 = b.get(p->atom_typing_used()); if(t2 >= n) continue; vec r_ba; r_ba = adjusted_a_coords - b.coords; // FIXME why b-a and not a-b ? fl r2 = sqr(r_ba); if(r2 < cutoff_sqr) { sz type_pair_index = get_type_pair_index(p->atom_typing_used(), a, b); pr e_dor = p->eval_deriv(type_pair_index, r2); this_e += e_dor.first; deriv += e_dor.second * r_ba; } } curl(this_e, deriv, v); m.minus_forces[i] = deriv + out_of_bounds_deriv; e += this_e + out_of_bounds_penalty; } return e; } autodock-vina-1.1.2/src/lib/pdb.cpp0000744000175000017500000000500411562571364016757 0ustar moellermoeller/* Copyright (c) 2006-2010, The Scripps Research Institute Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Author: Dr. Oleg Trott , The Olson Lab, The Scripps Research Institute */ #include "pdb.h" #include "parse_error.h" #include "file.h" #include "convert_substring.h" void pdb::check(fl min_distance) const { VINA_FOR_IN(i, atoms) { const pdb_atom& a = atoms[i]; VINA_RANGE(j, i+1, atoms.size()) { const pdb_atom& b = atoms[j]; fl d2 = vec_distance_sqr(a.coords, b.coords); if(d2 < sqr(min_distance)) { std::cout << "The distance between " << a.id << ":" << a.name << ":" << a.element << " and " << b.id << ":" << b.name << ":" << b.element << " is " << std::sqrt(d2) << '\n'; } } } } pdb_atom string_to_pdb_atom(const std::string& str) { if(str.size() < 66) throw bad_conversion(); // b-factor is in 61-66 pdb_atom tmp; tmp.id = convert_substring (str, 7, 11); tmp.name = convert_substring(str, 13, 16); tmp.residue_id = convert_substring (str, 23, 26); tmp.residue_name = convert_substring(str, 18, 20); tmp.coords[0] = convert_substring (str, 31, 38); tmp.coords[1] = convert_substring (str, 39, 46); tmp.coords[2] = convert_substring (str, 47, 54); tmp.b_factor = convert_substring (str, 61, 66); tmp.element = convert_substring(str, 77, 78); return tmp; } pdb parse_pdb(const path& name) { ifile in(name); pdb tmp; std::string str; unsigned count = 0; while(std::getline(in, str)) { ++count; if(starts_with(str, "ATOM ") || starts_with(str, "HETATM")) { try { tmp.atoms.push_back(string_to_pdb_atom(str)); } catch(...) { // bad_conversion, presumably; but can lexical_cast throw its own errors? throw parse_error(name, count, "ATOM syntax incorrect"); } } } return tmp; } autodock-vina-1.1.2/src/lib/cache.h0000744000175000017500000000407311562571364016727 0ustar moellermoeller/* Copyright (c) 2006-2010, The Scripps Research Institute Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Author: Dr. Oleg Trott , The Olson Lab, The Scripps Research Institute */ #ifndef VINA_CACHE_H #define VINA_CACHE_H #include #include "igrid.h" #include "grid.h" #include "model.h" struct cache_mismatch {}; struct rigid_mismatch : public cache_mismatch {}; struct grid_dims_mismatch : public cache_mismatch {}; struct energy_mismatch : public cache_mismatch {}; struct cache : public igrid { cache(const std::string& scoring_function_version_, const grid_dims& gd_, fl slope_, atom_type::t atom_typing_used_); fl eval (const model& m, fl v) const; // needs m.coords // clean up fl eval_deriv( model& m, fl v) const; // needs m.coords, sets m.minus_forces // clean up #if 0 // no longer doing I/O of the cache void read(const path& name); // can throw cache_mismatch void write(const path& name) const; #endif void populate(const model& m, const precalculate& p, const szv& atom_types_needed, bool display_progress = true); private: std::string scoring_function_version; atomv atoms; // for verification grid_dims gd; fl slope; // does not get (de-)serialized atom_type::t atu; std::vector grids; friend class boost::serialization::access; template void save(Archive& ar, const unsigned version) const; template void load(Archive& ar, const unsigned version); BOOST_SERIALIZATION_SPLIT_MEMBER() }; #endif autodock-vina-1.1.2/src/lib/grid_dim.h0000744000175000017500000000373711562571364017450 0ustar moellermoeller/* Copyright (c) 2006-2010, The Scripps Research Institute Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Author: Dr. Oleg Trott , The Olson Lab, The Scripps Research Institute */ #ifndef VINA_GRID_DIM_H #define VINA_GRID_DIM_H #include #include "common.h" struct grid_dim { fl begin; fl end; sz n; // number of intervals == number of sample points - 1 grid_dim() : begin(0), end(0), n(0) {} fl span() const { return end - begin; } bool enabled() const { return (n > 0); } private: friend class boost::serialization::access; template void serialize(Archive& ar, const unsigned version) { ar & begin; ar & end; ar & n; } }; inline bool eq(const grid_dim& a, const grid_dim& b) { return a.n == b.n && eq(a.begin, b.begin) && eq(a.end, b.end); } typedef boost::array grid_dims; inline bool eq(const grid_dims& a, const grid_dims& b) { return eq(a[0], b[0]) && eq(a[1], b[1]) && eq(a[2], b[2]); } inline void print(const grid_dims& gd, std::ostream& out = std::cout) { VINA_FOR_IN(i, gd) std::cout << gd[i].n << " [" << gd[i].begin << " .. " << gd[i].end << "]\n"; } inline vec grid_dims_begin(const grid_dims& gd) { vec tmp; VINA_FOR_IN(i, gd) tmp[i] = gd[i].begin; return tmp; } inline vec grid_dims_end(const grid_dims& gd) { vec tmp; VINA_FOR_IN(i, gd) tmp[i] = gd[i].end; return tmp; } #endif autodock-vina-1.1.2/src/lib/parallel_progress.h0000744000175000017500000000243011562571364021377 0ustar moellermoeller/* Copyright (c) 2006-2010, The Scripps Research Institute Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Author: Dr. Oleg Trott , The Olson Lab, The Scripps Research Institute */ #ifndef VINA_PARALLEL_PROGRESS_H #define VINA_PARALLEL_PROGRESS_H #include #include #include "incrementable.h" struct parallel_progress : public incrementable { parallel_progress() : p(NULL) {} void init(unsigned long n) { p = new boost::progress_display(n); } void operator++() { if(p) { boost::mutex::scoped_lock self_lk(self); ++(*p); } } virtual ~parallel_progress() { delete p; } private: boost::mutex self; boost::progress_display* p; }; #endif autodock-vina-1.1.2/src/lib/atom_base.h0000744000175000017500000000220211562571364017606 0ustar moellermoeller/* Copyright (c) 2006-2010, The Scripps Research Institute Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Author: Dr. Oleg Trott , The Olson Lab, The Scripps Research Institute */ #ifndef VINA_ATOM_BASE_H #define VINA_ATOM_BASE_H #include "atom_type.h" struct atom_base : public atom_type { fl charge; atom_base() : charge(0) {} private: friend class boost::serialization::access; template void serialize(Archive& ar, const unsigned version) { ar & boost::serialization::base_object(*this); ar & charge; } }; #endif autodock-vina-1.1.2/src/lib/parse_error.h0000744000175000017500000000207711562571364020211 0ustar moellermoeller/* Copyright (c) 2006-2010, The Scripps Research Institute Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Author: Dr. Oleg Trott , The Olson Lab, The Scripps Research Institute */ #ifndef VINA_PARSE_ERROR_H #define VINA_PARSE_ERROR_H #include "common.h" struct parse_error { path file; unsigned line; std::string reason; parse_error(const path& file_, unsigned line_, const std::string& reason_ = "") : file(file_), line(line_), reason(reason_) {} private: parse_error() {} }; #endif autodock-vina-1.1.2/src/lib/pdb.h0000744000175000017500000000216411562571364016430 0ustar moellermoeller/* Copyright (c) 2006-2010, The Scripps Research Institute Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Author: Dr. Oleg Trott , The Olson Lab, The Scripps Research Institute */ #ifndef VINA_PDB_H #define VINA_PDB_H #include "common.h" struct pdb_atom { unsigned id; std::string name; std::string residue_name; int residue_id; vec coords; fl b_factor; std::string element; }; struct pdb { std::vector atoms; void check(fl min_distance) const; }; pdb parse_pdb(const path& name); // can throw parse_error #endif autodock-vina-1.1.2/src/lib/model.cpp0000744000175000017500000006707711562571364017334 0ustar moellermoeller/* Copyright (c) 2006-2010, The Scripps Research Institute Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Author: Dr. Oleg Trott , The Olson Lab, The Scripps Research Institute */ #include "model.h" #include "file.h" #include "curl.h" template atom_range get_atom_range(const T& t) { atom_range tmp = t.node; VINA_FOR_IN(i, t.children) { atom_range r = get_atom_range(t.children[i]); if(tmp.begin > r.begin) tmp.begin = r.begin; if(tmp.end < r.end ) tmp.end = r.end; } return tmp; } struct branch_metrics { sz length; sz corner2corner; branch_metrics() : length(0), corner2corner(0) {} }; template branch_metrics get_branch_metrics(const T& t) { branch_metrics tmp; if(!t.children.empty()) { sz corner2corner_max = 0; szv lengths; VINA_FOR_IN(i, t.children) { branch_metrics res = get_branch_metrics(t.children[i]); if(corner2corner_max < res.corner2corner) corner2corner_max = res.corner2corner; lengths.push_back(res.length + 1); // FIXME? weird compiler warning (sz -> unsigned) } std::sort(lengths.begin(), lengths.end()); tmp.length = lengths.back(); tmp.corner2corner = tmp.length; if(lengths.size() >= 2) tmp.corner2corner += lengths[lengths.size() - 1]; if(tmp.corner2corner < corner2corner_max) tmp.corner2corner = corner2corner_max; } return tmp; } sz model::ligand_longest_branch(sz ligand_number) const { return get_branch_metrics(ligands[ligand_number]).length; } sz model::ligand_length(sz ligand_number) const { return get_branch_metrics(ligands[ligand_number]).corner2corner; } void ligand::set_range() { atom_range tmp = get_atom_range(*this); begin = tmp.begin; end = tmp.end; } /////////////////// begin MODEL::APPEND ///////////////////////// // FIXME hairy code - needs to be extensively commented, asserted, reviewed and tested struct appender_info { sz grid_atoms_size; sz m_num_movable_atoms; sz atoms_size; appender_info(const model& m) : grid_atoms_size(m.grid_atoms.size()), m_num_movable_atoms(m.m_num_movable_atoms), atoms_size(m.atoms.size()) {} }; class appender { appender_info a_info; appender_info b_info; sz new_grid_index(sz x) const { return (is_a ? x : (a_info.grid_atoms_size + x)); // a-grid_atoms spliced before b-grid_atoms } public: bool is_a; appender(const model& a, const model& b) : a_info(a), b_info(b), is_a(true) {} sz operator()(sz x) const { // transform coord index if(is_a) { if(x < a_info.m_num_movable_atoms) return x; // a-movable unchanged else return x + b_info.m_num_movable_atoms; // b-movable spliced before a-inflex } else { if(x < b_info.m_num_movable_atoms) return x + a_info.m_num_movable_atoms; // a-movable spliced before b-movable else return x + a_info.atoms_size; // all a's spliced before b-inflex } } atom_index operator()(const atom_index& x) const { // transform atom_index atom_index tmp(x); if(tmp.in_grid) tmp.i = new_grid_index(tmp.i); else tmp.i = operator()(tmp.i); return tmp; } // type-directed old -> new transformations void update(interacting_pair& ip) const { ip.a = operator()(ip.a); ip.b = operator()(ip.b); } void update(vec& v) const { // coordinates & forces - do nothing } void update(ligand& lig) const { lig.transform(*this); // ligand as an atom_range subclass transform_ranges(lig, *this); VINA_FOR_IN(i, lig.pairs) this->update(lig.pairs[i]); VINA_FOR_IN(i, lig.cont) this->update(lig.cont[i]); // parsed_line update, below } void update(residue& r) const { transform_ranges(r, *this); } void update(parsed_line& p) const { if(p.second) p.second = operator()(p.second.get()); } void update(atom& a) const { VINA_FOR_IN(i, a.bonds) { bond& b = a.bonds[i]; b.connected_atom_index = operator()(b.connected_atom_index); // atom_index transformation, above } } // ligands, flex, flex_context, atoms; also used for other_pairs template void append(std::vector& a, const std::vector& b) { // first arg becomes aaaaaaaabbbbbbbbbbbbbbb sz a_sz = a.size(); vector_append(a, b); is_a = true; VINA_FOR(i, a_sz) update(a[i]); is_a = false; VINA_RANGE(i, a_sz, a.size()) update(a[i]); } // internal_coords, coords, minus_forces, atoms template void coords_append(std::vector& a, const std::vector& b) { // first arg becomes aaaaaaaabbbbbbbbbaab std::vector b_copy(b); // more straightforward to make a copy of b and transform that than to do piecewise transformations of the result is_a = true; VINA_FOR_IN(i, a) update(a[i]); is_a = false; VINA_FOR_IN(i, b_copy) update(b_copy[i]); // interleave typedef typename std::vector::const_iterator const cci; cci b1 = b_copy.begin(); cci b2 = b_copy.begin() + b_info.m_num_movable_atoms; cci b3 = b_copy.end(); a.insert(a.begin() + a_info.m_num_movable_atoms , b1 , b2); a.insert(a.end() , b2 , b3); } }; void model::append(const model& m) { VINA_CHECK(atom_typing_used() == m.atom_typing_used()); appender t(*this, m); t.append(other_pairs, m.other_pairs); VINA_FOR_IN(i, atoms) VINA_FOR_IN(j, m.atoms) { if(i >= m_num_movable_atoms && j >= m.m_num_movable_atoms) continue; // no need for inflex-inflex interactions const atom& a = atoms[i]; const atom& b = m.atoms[j]; sz t1 = a.get(atom_typing_used()); sz t2 = b.get(atom_typing_used()); sz n = num_atom_types(atom_typing_used()); if(t1 < n && t2 < n) { t.is_a = true; sz new_i = t(i); t.is_a = false; sz new_j = t(j); sz type_pair_index = triangular_matrix_index_permissive(n, t1, t2); other_pairs.push_back(interacting_pair(type_pair_index, new_i, new_j)); } } VINA_CHECK( minus_forces.size() == coords.size()); VINA_CHECK(m.minus_forces.size() == m.coords.size()); t.coords_append(internal_coords, m.internal_coords); t.coords_append( coords, m .coords); t.coords_append( minus_forces, m .minus_forces); // for now, minus_forces.size() == coords.size() (includes inflex) t.append(ligands, m.ligands); t.append(flex, m.flex); t.append(flex_context, m.flex_context); t .append(grid_atoms, m.grid_atoms); t.coords_append( atoms, m .atoms); m_num_movable_atoms += m.m_num_movable_atoms; } /////////////////// end MODEL::APPEND ///////////////////////// /////////////////// begin MODEL::INITIALIZE ///////////////////////// atom_index model::sz_to_atom_index(sz i) const { if(i < grid_atoms.size()) return atom_index(i , true); else return atom_index(i - grid_atoms.size(), false); } distance_type model::distance_type_between(const distance_type_matrix& mobility, const atom_index& i, const atom_index& j) const { if(i.in_grid && j.in_grid) return DISTANCE_FIXED; if(i.in_grid) return (j.i < m_num_movable_atoms) ? DISTANCE_VARIABLE : DISTANCE_FIXED; if(j.in_grid) return (i.i < m_num_movable_atoms) ? DISTANCE_VARIABLE : DISTANCE_FIXED; assert(!i.in_grid); assert(!j.in_grid); assert(i.i < atoms.size()); assert(j.i < atoms.size()); sz a = i.i; sz b = j.i; if(a == b) return DISTANCE_FIXED; return (a < b) ? mobility(a, b) : mobility(b, a); } const vec& model::atom_coords(const atom_index& i) const { return i.in_grid ? grid_atoms[i.i].coords : coords[i.i]; } fl model::distance_sqr_between(const atom_index& a, const atom_index& b) const { return vec_distance_sqr(atom_coords(a), atom_coords(b)); } struct bond_less { // FIXME rm!? bool operator()(const bond& a, const bond& b) const { return a.connected_atom_index.i < b.connected_atom_index.i; } }; bool model::atom_exists_between(const distance_type_matrix& mobility, const atom_index& a, const atom_index& b, const szv& relevant_atoms) const { // there is an atom closer to both a and b then they are to each other and immobile relative to them fl r2 = distance_sqr_between(a, b); VINA_FOR_IN(relevant_atoms_i, relevant_atoms) { sz i = relevant_atoms[relevant_atoms_i]; atom_index c = sz_to_atom_index(i); if(a == c || b == c) continue; distance_type ac = distance_type_between(mobility, a, c); distance_type bc = distance_type_between(mobility, b, c); if(ac != DISTANCE_VARIABLE && bc != DISTANCE_VARIABLE && distance_sqr_between(a, c) < r2 && distance_sqr_between(b, c) < r2) return true; } return false; } struct beads { fl radius_sqr; std::vector > data; beads(sz reserve_size, fl radius_sqr_) : radius_sqr(radius_sqr_) { data.reserve(reserve_size); } void add(sz index, const vec& coords) { VINA_FOR_IN(i, data) { if(vec_distance_sqr(coords, data[i].first) < radius_sqr) { data[i].second.push_back(index); return; } } // not found std::pair tmp; tmp.first = coords; tmp.second.push_back(index); data.push_back(tmp); } }; void model::assign_bonds(const distance_type_matrix& mobility) { // assign bonds based on relative mobility, distance and covalent length const fl bond_length_allowance_factor = 1.1; sz n = grid_atoms.size() + atoms.size(); // construct beads const fl bead_radius = 15; beads beads_instance(n, sqr(bead_radius)); VINA_FOR(i, n) { atom_index i_atom_index = sz_to_atom_index(i); beads_instance.add(i, atom_coords(i_atom_index)); } // assign bonds VINA_FOR(i, n) { atom_index i_atom_index = sz_to_atom_index(i); const vec& i_atom_coords = atom_coords(i_atom_index); atom& i_atom = get_atom(i_atom_index); const fl max_covalent_r = max_covalent_radius(); // FIXME mv to atom_constants fl i_atom_covalent_radius = max_covalent_r; if(i_atom.ad < AD_TYPE_SIZE) i_atom_covalent_radius = ad_type_property(i_atom.ad).covalent_radius; //find relevant atoms szv relevant_atoms; const fl bead_cutoff_sqr = sqr(bead_radius + bond_length_allowance_factor * (i_atom_covalent_radius + max_covalent_r)); VINA_FOR_IN(b, beads_instance.data) { if(vec_distance_sqr(beads_instance.data[b].first, i_atom_coords) > bead_cutoff_sqr) continue; const szv& bead_elements = beads_instance.data[b].second; VINA_FOR_IN(bead_elements_i, bead_elements) { sz j = bead_elements[bead_elements_i]; atom_index j_atom_index = sz_to_atom_index(j); atom& j_atom = get_atom(j_atom_index); const fl bond_length = i_atom.optimal_covalent_bond_length(j_atom); distance_type dt = distance_type_between(mobility, i_atom_index, j_atom_index); if(dt != DISTANCE_VARIABLE && i != j) { fl r2 = distance_sqr_between(i_atom_index, j_atom_index); //if(r2 < sqr(bond_length_allowance_factor * bond_length)) if(r2 < sqr(bond_length_allowance_factor * (i_atom_covalent_radius + max_covalent_r))) relevant_atoms.push_back(j); } } } // find bonded atoms VINA_FOR_IN(relevant_atoms_i, relevant_atoms) { sz j = relevant_atoms[relevant_atoms_i]; if(j <= i) continue; // already considered atom_index j_atom_index = sz_to_atom_index(j); atom& j_atom = get_atom(j_atom_index); const fl bond_length = i_atom.optimal_covalent_bond_length(j_atom); distance_type dt = distance_type_between(mobility, i_atom_index, j_atom_index); fl r2 = distance_sqr_between(i_atom_index, j_atom_index); if(r2 < sqr(bond_length_allowance_factor * bond_length) && !atom_exists_between(mobility, i_atom_index, j_atom_index, relevant_atoms)) { bool rotatable = (dt == DISTANCE_ROTOR); fl length = std::sqrt(r2); i_atom.bonds.push_back(bond(j_atom_index, length, rotatable)); j_atom.bonds.push_back(bond(i_atom_index, length, rotatable)); } } } } bool model::bonded_to_HD(const atom& a) const { VINA_FOR_IN(i, a.bonds) { const bond& b = a.bonds[i]; if(get_atom(b.connected_atom_index).ad == AD_TYPE_HD) return true; } return false; } bool model::bonded_to_heteroatom(const atom& a) const { VINA_FOR_IN(i, a.bonds) { const bond& b = a.bonds[i]; if(get_atom(b.connected_atom_index).is_heteroatom()) return true; } return false; } void model::assign_types() { VINA_FOR(i, grid_atoms.size() + atoms.size()) { const atom_index ai = sz_to_atom_index(i); atom& a = get_atom(ai); a.assign_el(); sz& x = a.xs; bool acceptor = (a.ad == AD_TYPE_OA || a.ad == AD_TYPE_NA); // X-Score forumaltion apparently ignores SA bool donor_NorO = (a.el == EL_TYPE_Met || bonded_to_HD(a)); switch(a.el) { case EL_TYPE_H : break; case EL_TYPE_C : x = bonded_to_heteroatom(a) ? XS_TYPE_C_P : XS_TYPE_C_H; break; case EL_TYPE_N : x = (acceptor && donor_NorO) ? XS_TYPE_N_DA : (acceptor ? XS_TYPE_N_A : (donor_NorO ? XS_TYPE_N_D : XS_TYPE_N_P)); break; case EL_TYPE_O : x = (acceptor && donor_NorO) ? XS_TYPE_O_DA : (acceptor ? XS_TYPE_O_A : (donor_NorO ? XS_TYPE_O_D : XS_TYPE_O_P)); break; case EL_TYPE_S : x = XS_TYPE_S_P; break; case EL_TYPE_P : x = XS_TYPE_P_P; break; case EL_TYPE_F : x = XS_TYPE_F_H; break; case EL_TYPE_Cl : x = XS_TYPE_Cl_H; break; case EL_TYPE_Br : x = XS_TYPE_Br_H; break; case EL_TYPE_I : x = XS_TYPE_I_H; break; case EL_TYPE_Met : x = XS_TYPE_Met_D; break; case EL_TYPE_SIZE : break; default: VINA_CHECK(false); } } } sz model::find_ligand(sz a) const { VINA_FOR_IN(i, ligands) if(a >= ligands[i].begin && a < ligands[i].end) return i; return ligands.size(); } void model::bonded_to(sz a, sz n, szv& out) const { if(!has(out, a)) { // not found out.push_back(a); if(n > 0) VINA_FOR_IN(i, atoms[a].bonds) { const bond& b = atoms[a].bonds[i]; if(!b.connected_atom_index.in_grid) bonded_to(b.connected_atom_index.i, n-1, out); } } } szv model::bonded_to(sz a, sz n) const { szv tmp; bonded_to(a, n, tmp); return tmp; } void model::initialize_pairs(const distance_type_matrix& mobility) { VINA_FOR_IN(i, atoms) { sz i_lig = find_ligand(i); szv bonded_atoms = bonded_to(i, 3); VINA_RANGE(j, i+1, atoms.size()) { if(i >= m_num_movable_atoms && j >= m_num_movable_atoms) continue; // exclude inflex-inflex if(mobility(i, j) == DISTANCE_VARIABLE && !has(bonded_atoms, j)) { sz t1 = atoms[i].get (atom_typing_used()); sz t2 = atoms[j].get (atom_typing_used()); sz n = num_atom_types(atom_typing_used()); if(t1 < n && t2 < n) { // exclude, say, Hydrogens sz type_pair_index = triangular_matrix_index_permissive(n, t1, t2); interacting_pair ip(type_pair_index, i, j); if(i_lig < ligands.size() && find_ligand(j) == i_lig) ligands[i_lig].pairs.push_back(ip); else other_pairs.push_back(ip); } } } } } void model::initialize(const distance_type_matrix& mobility) { VINA_FOR_IN(i, ligands) ligands[i].set_range(); assign_bonds(mobility); assign_types(); initialize_pairs(mobility); } /////////////////// end MODEL::INITIALIZE ///////////////////////// sz model::num_internal_pairs() const { sz tmp = 0; VINA_FOR_IN(i, ligands) tmp += ligands[i].pairs.size(); return tmp; } szv model::get_movable_atom_types(atom_type::t atom_typing_used_) const { szv tmp; sz n = num_atom_types(atom_typing_used_); VINA_FOR(i, m_num_movable_atoms) { const atom& a = atoms[i]; sz t = a.get(atom_typing_used_); if(t < n && !has(tmp, t)) tmp.push_back(t); } return tmp; } conf_size model::get_size() const { conf_size tmp; tmp.ligands = ligands.count_torsions(); tmp.flex = flex .count_torsions(); return tmp; } conf model::get_initial_conf() const { // torsions = 0, orientations = identity, ligand positions = current conf_size cs = get_size(); conf tmp(cs); tmp.set_to_null(); VINA_FOR_IN(i, ligands) tmp.ligands[i].rigid.position = ligands[i].node.get_origin(); return tmp; } grid_dims model::movable_atoms_box(fl add_to_each_dimension, fl granularity) const { vec corner1(0, 0, 0), corner2(0, 0, 0); VINA_FOR(i, num_movable_atoms()) { const vec& v = movable_coords(i); VINA_FOR_IN(j, v) { if(i == 0 || v[j] < corner1[j]) corner1[j] = v[j]; if(i == 0 || v[j] > corner2[j]) corner2[j] = v[j]; } } corner1 -= add_to_each_dimension / 2; corner2 += add_to_each_dimension / 2; grid_dims gd; { // always doing this now FIXME ? vec center; center = 0.5 * (corner2 + corner1); VINA_FOR_IN(i, gd) { gd[i].n = sz(std::ceil((corner2[i] - corner1[i]) / granularity)); fl real_span = granularity * gd[i].n; gd[i].begin = center[i] - real_span/2; gd[i].end = gd[i].begin + real_span; } } return gd; } void string_write_coord(sz i, fl x, std::string& str) { VINA_CHECK(i > 0); --i; std::ostringstream out; out.setf(std::ios::fixed, std::ios::floatfield); out.setf(std::ios::showpoint); out << std::setw(8) << std::setprecision(3) << x; VINA_CHECK(out.str().size() == 8); VINA_CHECK(str.size() > i + 8); VINA_FOR(j, 8) str[i+j] = out.str()[j]; } std::string coords_to_pdbqt_string(const vec& coords, const std::string& str) { std::string tmp(str); string_write_coord(31, coords[0], tmp); string_write_coord(39, coords[1], tmp); string_write_coord(47, coords[2], tmp); return tmp; } void model::write_context(const context& c, ofile& out) const { verify_bond_lengths(); VINA_FOR_IN(i, c) { const std::string& str = c[i].first; if(c[i].second) { out << coords_to_pdbqt_string(coords[c[i].second.get()], str) << '\n'; } else out << str << '\n'; } } void model::seti(const conf& c) { ligands.set_conf(atoms, internal_coords, c.ligands); } void model::sete(const conf& c) { VINA_FOR_IN(i, ligands) c.ligands[i].rigid.apply(internal_coords, coords, ligands[i].begin, ligands[i].end); flex.set_conf(atoms, coords, c.flex); } void model::set (const conf& c) { ligands.set_conf(atoms, coords, c.ligands); flex .set_conf(atoms, coords, c.flex); } fl model::gyration_radius(sz ligand_number) const { VINA_CHECK(ligand_number < ligands.size()); const ligand& lig = ligands[ligand_number]; fl acc = 0; unsigned counter = 0; VINA_RANGE(i, lig.begin, lig.end) { if(atoms[i].el != EL_TYPE_H) { // only heavy atoms are used acc += vec_distance_sqr(coords[i], lig.node.get_origin()); // FIXME? check! ++counter; } } return (counter > 0) ? std::sqrt(acc/counter) : 0; } fl eval_interacting_pairs(const precalculate& p, fl v, const interacting_pairs& pairs, const vecv& coords) { // clean up const fl cutoff_sqr = p.cutoff_sqr(); fl e = 0; VINA_FOR_IN(i, pairs) { const interacting_pair& ip = pairs[i]; fl r2 = vec_distance_sqr(coords[ip.a], coords[ip.b]); if(r2 < cutoff_sqr) { fl tmp = p.eval_fast(ip.type_pair_index, r2); curl(tmp, v); e += tmp; } } return e; } fl eval_interacting_pairs_deriv(const precalculate& p, fl v, const interacting_pairs& pairs, const vecv& coords, vecv& forces) { // adds to forces // clean up const fl cutoff_sqr = p.cutoff_sqr(); fl e = 0; VINA_FOR_IN(i, pairs) { const interacting_pair& ip = pairs[i]; vec r; r = coords[ip.b] - coords[ip.a]; // a -> b fl r2 = sqr(r); if(r2 < cutoff_sqr) { pr tmp = p.eval_deriv(ip.type_pair_index, r2); vec force; force = tmp.second * r; curl(tmp.first, force, v); e += tmp.first; // FIXME inefficient, if using hard curl forces[ip.a] -= force; // we could omit forces on inflex here forces[ip.b] += force; } } return e; } fl model::evali(const precalculate& p, const vec& v ) const { // clean up fl e = 0; VINA_FOR_IN(i, ligands) e += eval_interacting_pairs(p, v[0], ligands[i].pairs, internal_coords); // probably might was well use coords here return e; } fl model::evale(const precalculate& p, const igrid& ig, const vec& v ) const { // clean up fl e = ig.eval(*this, v[1]); e += eval_interacting_pairs(p, v[2], other_pairs, coords); return e; } fl model::eval (const precalculate& p, const igrid& ig, const vec& v, const conf& c ) { // clean up set(c); fl e = evale(p, ig, v); VINA_FOR_IN(i, ligands) e += eval_interacting_pairs(p, v[0], ligands[i].pairs, coords); // coords instead of internal coords return e; } fl model::eval_deriv (const precalculate& p, const igrid& ig, const vec& v, const conf& c, change& g) { // clean up set(c); fl e = ig.eval_deriv(*this, v[1]); // sets minus_forces, except inflex e += eval_interacting_pairs_deriv(p, v[2], other_pairs, coords, minus_forces); // adds to minus_forces VINA_FOR_IN(i, ligands) e += eval_interacting_pairs_deriv(p, v[0], ligands[i].pairs, coords, minus_forces); // adds to minus_forces // calculate derivatives ligands.derivative(coords, minus_forces, g.ligands); flex .derivative(coords, minus_forces, g.flex); // inflex forces are ignored return e; } fl model::eval_intramolecular(const precalculate& p, const vec& v, const conf& c) { set(c); fl e = 0; // internal for each ligand VINA_FOR_IN(i, ligands) e += eval_interacting_pairs(p, v[0], ligands[i].pairs, coords); // coords instead of internal coords sz nat = num_atom_types(atom_typing_used()); const fl cutoff_sqr = p.cutoff_sqr(); // flex-rigid VINA_FOR(i, num_movable_atoms()) { if(find_ligand(i) < ligands.size()) continue; // we only want flex-rigid interaction const atom& a = atoms[i]; sz t1 = a.get(atom_typing_used()); if(t1 >= nat) continue; VINA_FOR_IN(j, grid_atoms) { const atom& b = grid_atoms[j]; sz t2 = b.get(atom_typing_used()); if(t2 >= nat) continue; fl r2 = vec_distance_sqr(coords[i], b.coords); if(r2 < cutoff_sqr) { sz type_pair_index = triangular_matrix_index_permissive(nat, t1, t2); fl this_e = p.eval_fast(type_pair_index, r2); curl(this_e, v[1]); e += this_e; } } } // flex-flex VINA_FOR_IN(i, other_pairs) { const interacting_pair& pair = other_pairs[i]; if(find_ligand(pair.a) < ligands.size() || find_ligand(pair.b) < ligands.size()) continue; // we only need flex-flex fl r2 = vec_distance_sqr(coords[pair.a], coords[pair.b]); if(r2 < cutoff_sqr) { fl this_e = p.eval_fast(pair.type_pair_index, r2); curl(this_e, v[2]); e += this_e; } } return e; } fl model::eval_adjusted (const scoring_function& sf, const precalculate& p, const igrid& ig, const vec& v, const conf& c, fl intramolecular_energy) { fl e = eval(p, ig, v, c); // sets c return sf.conf_independent(*this, e - intramolecular_energy); } fl model::rmsd_lower_bound_asymmetric(const model& x, const model& y) const { // actually static sz n = x.m_num_movable_atoms; VINA_CHECK(n == y.m_num_movable_atoms); fl sum = 0; unsigned counter = 0; VINA_FOR(i, n) { const atom& a = x.atoms[i]; if(a.el != EL_TYPE_H) { fl r2 = max_fl; VINA_FOR(j, n) { const atom& b = y.atoms[j]; if(a.same_element(b) && !b.is_hydrogen()) { fl this_r2 = vec_distance_sqr(x.coords[i], y.coords[j]); if(this_r2 < r2) r2 = this_r2; } } assert(not_max(r2)); sum += r2; ++counter; } } return (counter == 0) ? 0 : std::sqrt(sum / counter); } fl model::rmsd_lower_bound(const model& m) const { return (std::max)(rmsd_lower_bound_asymmetric(*this, m), rmsd_lower_bound_asymmetric( m, *this)); } fl model::rmsd_upper_bound(const model& m) const { VINA_CHECK(m_num_movable_atoms == m.m_num_movable_atoms); fl sum = 0; unsigned counter = 0; VINA_FOR(i, m_num_movable_atoms) { const atom& a = atoms[i]; const atom& b = m.atoms[i]; assert(a.ad == b.ad); assert(a.xs == b.xs); if(a.el != EL_TYPE_H) { sum += vec_distance_sqr(coords[i], m.coords[i]); ++counter; } } return (counter == 0) ? 0 : std::sqrt(sum / counter); } fl model::rmsd_ligands_upper_bound(const model& m) const { VINA_CHECK(ligands.size() == m.ligands.size()); fl sum = 0; unsigned counter = 0; VINA_FOR_IN(ligand_i, ligands) { const ligand& lig = ligands[ligand_i]; const ligand& m_lig = m.ligands[ligand_i]; VINA_CHECK(lig.begin == m_lig.begin); VINA_CHECK(lig.end == m_lig.end); VINA_RANGE(i, lig.begin, lig.end) { const atom& a = atoms[i]; const atom& b = m.atoms[i]; assert(a.ad == b.ad); assert(a.xs == b.xs); if(a.el != EL_TYPE_H) { sum += vec_distance_sqr(coords[i], m.coords[i]); ++counter; } } } return (counter == 0) ? 0 : std::sqrt(sum / counter); } void model::verify_bond_lengths() const { VINA_FOR(i, grid_atoms.size() + atoms.size()) { const atom_index ai = sz_to_atom_index(i); const atom& a = get_atom(ai); VINA_FOR_IN(j, a.bonds) { const bond& b = a.bonds[j]; fl d = std::sqrt(distance_sqr_between(ai, b.connected_atom_index)); bool ok = eq(d, b.length); if(!ok) { VINA_SHOW(d); VINA_SHOW(b.length); } VINA_CHECK(ok); } } } void model::check_internal_pairs() const { VINA_FOR_IN(i, ligands) { const ligand& lig = ligands[i]; const interacting_pairs& pairs = lig.pairs; VINA_FOR_IN(j, pairs) { const interacting_pair& ip = pairs[j]; VINA_CHECK(ip.a >= lig.begin); VINA_CHECK(ip.b < lig.end); } } } void model::about() const { VINA_SHOW(atom_typing_used()); VINA_SHOW(num_movable_atoms()); VINA_SHOW(num_internal_pairs()); VINA_SHOW(num_other_pairs()); VINA_SHOW(num_ligands()); VINA_SHOW(num_flex()); } void model::print_stuff() const { std::cout << "coords:\n"; VINA_FOR_IN(i, coords) printnl(coords[i]); std::cout << "internal_coords:\n"; VINA_FOR_IN(i, internal_coords) printnl(internal_coords[i]); std::cout << "atoms:\n"; VINA_FOR_IN(i, atoms) { const atom& a = atoms[i]; std::cout << a.el << " " << a.ad << " " << a.xs << " " << a.sy << " " << a.charge << '\n'; std::cout << a.bonds.size() << " "; printnl(a.coords); } std::cout << "grid_atoms:\n"; VINA_FOR_IN(i, grid_atoms) { const atom& a = grid_atoms[i]; std::cout << a.el << " " << a.ad << " " << a.xs << " " << a.sy << " " << a.charge << '\n'; std::cout << a.bonds.size() << " "; printnl(a.coords); } about(); } fl pairwise_clash_penalty(fl r, fl covalent_r) { // r = 0 -> max_penalty // r = covalent_r -> 1 // elsewhere -> hyperbolic function assert(r >= 0); assert(covalent_r > epsilon_fl); const fl x = r / covalent_r; if(x > 2) return 0; return 1-x*x/4; } fl model::clash_penalty_aux(const interacting_pairs& pairs) const { fl e = 0; VINA_FOR_IN(i, pairs) { const interacting_pair& ip = pairs[i]; const fl r = std::sqrt(vec_distance_sqr(coords[ip.a], coords[ip.b])); const fl covalent_r = atoms[ip.a].covalent_radius() + atoms[ip.b].covalent_radius(); e += pairwise_clash_penalty(r, covalent_r); } return e; } fl model::clash_penalty() const { fl e = 0; VINA_FOR_IN(i, ligands) e += clash_penalty_aux(ligands[i].pairs); e += clash_penalty_aux(other_pairs); return e; } autodock-vina-1.1.2/src/lib/common.h0000744000175000017500000002262611562571364017160 0ustar moellermoeller/* Copyright (c) 2006-2010, The Scripps Research Institute Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Author: Dr. Oleg Trott , The Olson Lab, The Scripps Research Institute */ #ifndef VINA_COMMON_H #define VINA_COMMON_H #include #include #include #include // pair #include // too common #include // used in typedef, and commonly used overall #include // commonly used #include // various debugging everywhere #include // print_coords #include // to_string #include // to_string #include // probably included by the above anyway, common anyway #include // can't come before the above two - wart fixed in upcoming Boost versions #include // movable_atom needs it - (derived from atom) #include // typedef'ed #include "macros.h" typedef double fl; template T sqr(T x) { return x*x; } const fl not_a_num = std::sqrt(fl(-1)); // FIXME? check typedef std::size_t sz; typedef std::pair pr; struct vec { fl data[3]; vec() { #ifndef NDEBUG data[0] = data[1] = data[2] = not_a_num; #endif } vec(fl x, fl y, fl z) { data[0] = x; data[1] = y; data[2] = z; } const fl& operator[](sz i) const { assert(i < 3); return data[i]; } fl& operator[](sz i) { assert(i < 3); return data[i]; } fl norm_sqr() const { return sqr(data[0]) + sqr(data[1]) + sqr(data[2]); } fl norm() const { return std::sqrt(norm_sqr()); } fl operator*(const vec& v) const { return data[0] * v[0] + data[1] * v[1] + data[2] * v[2]; } const vec& operator+=(const vec& v) { data[0] += v[0]; data[1] += v[1]; data[2] += v[2]; return *this; } const vec& operator-=(const vec& v) { data[0] -= v[0]; data[1] -= v[1]; data[2] -= v[2]; return *this; } const vec& operator+=(fl s) { data[0] += s; data[1] += s; data[2] += s; return *this; } const vec& operator-=(fl s) { data[0] -= s; data[1] -= s; data[2] -= s; return *this; } vec operator+(const vec& v) const { return vec(data[0] + v[0], data[1] + v[1], data[2] + v[2]); } vec operator-(const vec& v) const { return vec(data[0] - v[0], data[1] - v[1], data[2] - v[2]); } const vec& operator*=(fl s) { data[0] *= s; data[1] *= s; data[2] *= s; return *this; } void assign(fl s) { data[0] = data[1] = data[2] = s; } sz size() const { return 3; } private: friend class boost::serialization::access; template void serialize(Archive& ar, const unsigned version) { ar & data; } }; inline vec operator*(fl s, const vec& v) { return vec(s * v[0], s * v[1], s * v[2]); } inline vec cross_product(const vec& a, const vec& b) { return vec(a[1]*b[2] - a[2]*b[1], a[2]*b[0] - a[0]*b[2], a[0]*b[1] - a[1]*b[0]); } inline vec elementwise_product(const vec& a, const vec& b) { return vec(a[0] * b[0], a[1] * b[1], a[2] * b[2]); } struct mat { fl data[9]; mat() { #ifndef NDEBUG data[0] = data[1] = data[2] = data[3] = data[4] = data[5] = data[6] = data[7] = data[8] = not_a_num; #endif } // column-major const fl& operator()(sz i, sz j) const { assert(i < 3); assert(j < 3); return data[i + 3*j]; } fl& operator()(sz i, sz j) { assert(i < 3); assert(j < 3); return data[i + 3*j]; } mat(fl xx, fl xy, fl xz, fl yx, fl yy, fl yz, fl zx, fl zy, fl zz) { data[0] = xx; data[3] = xy; data[6] = xz; data[1] = yx; data[4] = yy; data[7] = yz; data[2] = zx; data[5] = zy; data[8] = zz; } vec operator*(const vec& v) const { return vec(data[0]*v[0] + data[3]*v[1] + data[6]*v[2], data[1]*v[0] + data[4]*v[1] + data[7]*v[2], data[2]*v[0] + data[5]*v[1] + data[8]*v[2]); } const mat& operator*=(fl s) { VINA_FOR(i, 9) data[i] *= s; return *this; } }; typedef std::vector vecv; typedef std::pair vecp; typedef std::vector flv; typedef std::vector prv; typedef std::vector szv; typedef boost::filesystem::path path; struct internal_error { std::string file; unsigned line; internal_error(const std::string& file_, unsigned line_) : file(file_), line(line_) {} }; #ifdef NDEBUG #define VINA_CHECK(P) do { if(!(P)) throw internal_error(__FILE__, __LINE__); } while(false) #else #define VINA_CHECK(P) assert(P) #endif const fl pi = fl(3.1415926535897931); inline sz fl_to_sz(fl x, sz max_sz) { // return a value in [0, max_sz] if(x <= 0) return 0; if(x >= max_sz) return max_sz; sz tmp = static_cast(x); return (std::min)(tmp, max_sz); // sz -> fl cast loses precision. 'min' is to guard against returning values out of range } const fl fl_tolerance = fl(0.001); inline bool eq(fl a, fl b) { return std::abs(a - b) < fl_tolerance; } inline bool eq(const vec& a, const vec& b) { return eq(a[0], b[0]) && eq(a[1], b[1]) && eq(a[2], b[2]); } template bool eq(const std::vector& a, const std::vector& b) { if(a.size() != b.size()) return false; VINA_FOR_IN(i, a) if(!eq(a[i], b[i])) return false; return true; } const fl max_fl = (std::numeric_limits::max)(); const sz max_sz = (std::numeric_limits::max)(); const unsigned max_unsigned = (std::numeric_limits::max)(); const fl epsilon_fl = std::numeric_limits::epsilon(); const vec zero_vec(0, 0, 0); const vec max_vec(max_fl, max_fl, max_fl); inline bool not_max(fl x) { return (x < 0.1 * max_fl); } inline fl vec_distance_sqr(const vec& a, const vec& b) { return sqr(a[0] - b[0]) + \ sqr(a[1] - b[1]) + \ sqr(a[2] - b[2]); } inline fl sqr(const vec& v) { return sqr(v[0]) + sqr(v[1]) + sqr(v[2]); } template sz vector_append(std::vector& x, const std::vector& y) { // return old size sz old_size = x.size(); x.insert(x.end(), y.begin(), y.end()); return old_size; } template sz find_min(const std::vector& v) { // returns v.size() i.e. 0 for empty vectors; the index of the smallest elt otherwise sz tmp = v.size(); VINA_FOR_IN(i, v) if(i == 0 || v[i] < v[tmp]) tmp = i; return tmp; } inline void normalize_angle(fl& x) { // subtract or add enough 2*pi's to make x be in [-pi, pi] if (x > 3*pi) { // very large fl n = ( x - pi) / (2*pi); // how many 2*pi's do you want to subtract? x -= 2*pi*std::ceil(n); // ceil can be very slow, but this should not be called often normalize_angle(x); } else if(x < -3*pi) { // very small fl n = (-x - pi) / (2*pi); // how many 2*pi's do you want to add? x += 2*pi*std::ceil(n); // ceil can be very slow, but this should not be called often normalize_angle(x); } else if(x > pi) { // in ( pi, 3*pi] x -= 2*pi; } else if(x < -pi) { // in [-3*pi, -pi) x += 2*pi; } assert(x >= -pi && x <= pi); // in [-pi, pi] } inline fl normalized_angle(fl x) { normalize_angle(x); return x; } template std::string to_string(const T& x, std::streamsize width = 0, char fill = ' ') { // default 0 width means no restrictions on width std::ostringstream out; out.fill(fill); if(width > 0) out << std::setw(width); out << x; return out.str(); } template T sum(const std::vector& v) { T acc = 0; VINA_FOR_IN(i, v) acc += v[i]; return acc; } // multiply pK by this to get free energy in kcal/mol: // K = exp(E/RT) -- lower K and lower E == better binder // pK = -log10(K) => K = 10^(-pK) // E = RT ln(K) = RT ln (10^(-pK)) = - RT * ln(10) * pK const fl pK_to_energy_factor = -8.31 /* RT in J/K/mol */ * 0.001 /* kilo */ * 300 /* K */ / 4.184 /* J/cal */ * std::log(10.0); // -0.6 kcal/mol * log(10) = -1.38 inline fl pK_to_energy(fl pK) { return pK_to_energy_factor * pK; } inline void print(fl x, std::ostream& out = std::cout) { out << x; } inline void print(sz x, std::ostream& out = std::cout) { out << x; } inline void print(const vec& v, std::ostream& out = std::cout) { out << "("; VINA_FOR_IN(i, v) { if(i != 0) out << ", "; print(v[i], out); } out << ")"; } template void print(const std::vector& v, std::ostream& out = std::cout) { out << "["; VINA_FOR_IN(i, v) { if(i != 0) out << " "; print(v[i], out); } out << "]"; } template void printnl(const T& x, std::ostream& out = std::cout) { print(x, out); out << '\n'; } inline bool starts_with(const std::string& str, const std::string& start) { return str.size() >= start.size() && str.substr(0, start.size()) == start; } template bool has(const std::vector& v, const T& element) { return std::find(v.begin(), v.end(), element) != v.end(); } #endif autodock-vina-1.1.2/src/lib/coords.cpp0000744000175000017500000000366411562571364017515 0ustar moellermoeller/* Copyright (c) 2006-2010, The Scripps Research Institute Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Author: Dr. Oleg Trott , The Olson Lab, The Scripps Research Institute */ #include "coords.h" fl rmsd_upper_bound(const vecv& a, const vecv& b) { VINA_CHECK(a.size() == b.size()); fl acc = 0; VINA_FOR_IN(i, a) acc += vec_distance_sqr(a[i], b[i]); return (a.size() > 0) ? std::sqrt(acc / a.size()) : 0; } std::pair find_closest(const vecv& a, const output_container& b) { std::pair tmp(b.size(), max_fl); VINA_FOR_IN(i, b) { fl res = rmsd_upper_bound(a, b[i].coords); if(i == 0 || res < tmp.second) tmp = std::pair(i, res); } return tmp; } void add_to_output_container(output_container& out, const output_type& t, fl min_rmsd, sz max_size) { std::pair closest_rmsd = find_closest(t.coords, out); if(closest_rmsd.first < out.size() && closest_rmsd.second < min_rmsd) { // have a very similar one if(t.e < out[closest_rmsd.first].e) { // the new one is better, apparently out[closest_rmsd.first] = t; // FIXME? slow } } else { // nothing similar if(out.size() < max_size) out.push_back(new output_type(t)); // the last one had the worst energy - replacing else if(!out.empty() && t.e < out.back().e) // FIXME? - just changed out.back() = t; // FIXME? slow } out.sort(); } autodock-vina-1.1.2/src/lib/convert_substring.h0000744000175000017500000000377311562571364021452 0ustar moellermoeller/* Copyright (c) 2006-2010, The Scripps Research Institute Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Author: Dr. Oleg Trott , The Olson Lab, The Scripps Research Institute */ #ifndef VINA_CONVERT_SUBSTRING_H #define VINA_CONVERT_SUBSTRING_H #include // for isspace #include #include "common.h" struct bad_conversion {}; template T convert_substring(const std::string& str, sz i, sz j) { // indexes are 1-based, the substring should be non-null if(i < 1 || i > j+1 || j > str.size()) throw bad_conversion(); // omit leading whitespace while(i <= j && std::isspace(str[i-1])) ++i; T tmp; try { tmp = boost::lexical_cast(str.substr(i-1, j-i+1)); } catch(...) { throw bad_conversion(); } return tmp; } inline bool substring_is_blank(const std::string& str, sz i, sz j) { // indexes are 1-based, the substring should be non-null if(i < 1 || i > j+1 || j > str.size()) throw bad_conversion(); VINA_RANGE(k, i-1, j) if(!std::isspace(str[k])) return false; return true; } // when this was written, lexical cast to unsigned didn't work very well with "-123", etc. template<> inline unsigned convert_substring(const std::string& str, sz i, sz j) { // indexes are 1-based, the substring should be non-null int tmp = convert_substring(str, i, j); if(tmp < 0) throw bad_conversion(); return static_cast(tmp); } #endif autodock-vina-1.1.2/src/lib/parallel_mc.h0000744000175000017500000000234111562571364020133 0ustar moellermoeller/* Copyright (c) 2006-2010, The Scripps Research Institute Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Author: Dr. Oleg Trott , The Olson Lab, The Scripps Research Institute */ #ifndef VINA_PARALLEL_MC_H #define VINA_PARALLEL_MC_H #include "monte_carlo.h" struct parallel_mc { monte_carlo mc; sz num_tasks; sz num_threads; bool display_progress; parallel_mc() : num_tasks(8), num_threads(1), display_progress(true) {} void operator()(const model& m, output_container& out, const precalculate& p, const igrid& ig, const precalculate& p_widened, const igrid& ig_widened, const vec& corner1, const vec& corner2, rng& generator) const; }; #endif autodock-vina-1.1.2/src/lib/szv_grid.cpp0000744000175000017500000000546211562571364020051 0ustar moellermoeller/* Copyright (c) 2006-2010, The Scripps Research Institute Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Author: Dr. Oleg Trott , The Olson Lab, The Scripps Research Institute */ #include "szv_grid.h" #include "brick.h" szv_grid::szv_grid(const model& m, const grid_dims& gd, fl cutoff_sqr) : m_data(gd[0].n, gd[1].n, gd[2].n) { vec end; VINA_FOR_IN(i, gd) { m_init[i] = gd[i].begin; end [i] = gd[i].end; } m_range = end - m_init; const sz nat = num_atom_types(m.atom_typing_used()); szv relevant_indexes; VINA_FOR_IN(i, m.grid_atoms) { const atom& a = m.grid_atoms[i]; if(a.get(m.atom_typing_used()) < nat && brick_distance_sqr(m_init, end, a.coords) < cutoff_sqr) relevant_indexes.push_back(i); } VINA_FOR(x, m_data.dim0()) VINA_FOR(y, m_data.dim1()) VINA_FOR(z, m_data.dim2()) { VINA_FOR_IN(ri, relevant_indexes) { const sz i = relevant_indexes[ri]; const atom& a = m.grid_atoms[i]; if(brick_distance_sqr(index_to_coord(x, y, z), index_to_coord(x+1, y+1, z+1), a.coords) < cutoff_sqr) m_data(x, y, z).push_back(i); } } } fl szv_grid::average_num_possibilities() const { sz counter = 0; VINA_FOR(x, m_data.dim0()) VINA_FOR(y, m_data.dim1()) VINA_FOR(z, m_data.dim2()) { counter += m_data(x, y, z).size(); } return fl(counter) / (m_data.dim0() * m_data.dim1() * m_data.dim2()); } const szv& szv_grid::possibilities(const vec& coords) const { boost::array index; VINA_FOR_IN(i, index) { assert(coords[i] + epsilon_fl >= m_init[i]); assert(coords[i] <= m_init[i] + m_range[i] + epsilon_fl); const fl tmp = (coords[i] - m_init[i]) * m_data.dim(i) / m_range[i]; index[i] = fl_to_sz(tmp, m_data.dim(i) - 1); } return m_data(index[0], index[1], index[2]); } vec szv_grid::index_to_coord(sz i, sz j, sz k) const { vec index(i, j, k); vec tmp; VINA_FOR_IN(n, tmp) tmp[n] = m_init[n] + m_range[n] * index[n] / m_data.dim(n); return tmp; } grid_dims szv_grid_dims(const grid_dims& gd) { grid_dims tmp; VINA_FOR_IN(i, tmp) { tmp[i].begin = gd[i].begin; tmp[i].end = gd[i].end; fl n_fl = (gd[i].end - gd[i].begin) / 3; // 3A preferred size int n_int = int(n_fl); tmp[i].n = (n_int < 1) ? 1 : sz(n_int); } return tmp; } autodock-vina-1.1.2/src/lib/tee.h0000744000175000017500000000273711562571364016446 0ustar moellermoeller/* Copyright (c) 2006-2010, The Scripps Research Institute Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Author: Dr. Oleg Trott , The Olson Lab, The Scripps Research Institute */ #ifndef VINA_TEE_H #define VINA_TEE_H #include #include "file.h" struct tee { ofile* of; tee() : of(NULL) {} void init(const path& name) { of = new ofile(name); } virtual ~tee() { delete of; } void flush() { std::cout << std::flush; if(of) (*of) << std::flush; } void endl() { std::cout << std::endl; if(of) (*of) << std::endl; } void setf(std::ios::fmtflags a) { std::cout.setf(a); if(of) of->setf(a); } void setf(std::ios::fmtflags a, std::ios::fmtflags b) { std::cout.setf(a, b); if(of) of->setf(a, b); } }; template tee& operator<<(tee& out, const T& x) { std::cout << x; if(out.of) (*out.of) << x; return out; } #endif autodock-vina-1.1.2/src/lib/cache.cpp0000744000175000017500000001170311562571364017260 0ustar moellermoeller/* Copyright (c) 2006-2010, The Scripps Research Institute Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Author: Dr. Oleg Trott , The Olson Lab, The Scripps Research Institute */ #include // fill, etc #if 0 // use binary cache // for some reason, binary archive gives four huge warnings in VC2008 #include #include typedef boost::archive::binary_iarchive iarchive; typedef boost::archive::binary_oarchive oarchive; #else // use text cache #include #include typedef boost::archive::text_iarchive iarchive; typedef boost::archive::text_oarchive oarchive; #endif #include #include #include #include "cache.h" #include "file.h" #include "szv_grid.h" cache::cache(const std::string& scoring_function_version_, const grid_dims& gd_, fl slope_, atom_type::t atom_typing_used_) : scoring_function_version(scoring_function_version_), gd(gd_), slope(slope_), atu(atom_typing_used_), grids(num_atom_types(atom_typing_used_)) {} fl cache::eval (const model& m, fl v) const { // needs m.coords fl e = 0; sz nat = num_atom_types(atu); VINA_FOR(i, m.num_movable_atoms()) { const atom& a = m.atoms[i]; sz t = a.get(atu); if(t >= nat) continue; const grid& g = grids[t]; assert(g.initialized()); e += g.evaluate(m.coords[i], slope, v); } return e; } fl cache::eval_deriv( model& m, fl v) const { // needs m.coords, sets m.minus_forces fl e = 0; sz nat = num_atom_types(atu); VINA_FOR(i, m.num_movable_atoms()) { const atom& a = m.atoms[i]; sz t = a.get(atu); if(t >= nat) { m.minus_forces[i].assign(0); continue; } const grid& g = grids[t]; assert(g.initialized()); vec deriv; e += g.evaluate(m.coords[i], slope, v, deriv); m.minus_forces[i] = deriv; } return e; } #if 0 // No longer doing I/O of the cache void cache::read(const path& p) { ifile in(p, std::ios::binary); iarchive ar(in); ar >> *this; } void cache::write(const path& p) const { ofile out(p, std::ios::binary); oarchive ar(out); ar << *this; } #endif template void cache::save(Archive& ar, const unsigned version) const { ar & scoring_function_version; ar & gd; ar & atu; ar & grids; } template void cache::load(Archive& ar, const unsigned version) { std::string name_tmp; ar & name_tmp; if(name_tmp != scoring_function_version) throw energy_mismatch(); grid_dims gd_tmp; ar & gd_tmp; if(!eq(gd_tmp, gd)) throw grid_dims_mismatch(); atom_type::t atu_tmp; ar & atu_tmp; if(atu_tmp != atu) throw cache_mismatch(); ar & grids; } void cache::populate(const model& m, const precalculate& p, const szv& atom_types_needed, bool display_progress) { szv needed; VINA_FOR_IN(i, atom_types_needed) { sz t = atom_types_needed[i]; if(!grids[t].initialized()) { needed.push_back(t); grids[t].init(gd); } } if(needed.empty()) return; flv affinities(needed.size()); sz nat = num_atom_types(atu); grid& g = grids[needed.front()]; const fl cutoff_sqr = p.cutoff_sqr(); grid_dims gd_reduced = szv_grid_dims(gd); szv_grid ig(m, gd_reduced, cutoff_sqr); VINA_FOR(x, g.m_data.dim0()) { VINA_FOR(y, g.m_data.dim1()) { VINA_FOR(z, g.m_data.dim2()) { std::fill(affinities.begin(), affinities.end(), 0); vec probe_coords; probe_coords = g.index_to_argument(x, y, z); const szv& possibilities = ig.possibilities(probe_coords); VINA_FOR_IN(possibilities_i, possibilities) { const sz i = possibilities[possibilities_i]; const atom& a = m.grid_atoms[i]; const sz t1 = a.get(atu); if(t1 >= nat) continue; const fl r2 = vec_distance_sqr(a.coords, probe_coords); if(r2 <= cutoff_sqr) { VINA_FOR_IN(j, needed) { const sz t2 = needed[j]; assert(t2 < nat); const sz type_pair_index = triangular_matrix_index_permissive(num_atom_types(atu), t1, t2); affinities[j] += p.eval_fast(type_pair_index, r2); } } } VINA_FOR_IN(j, needed) { sz t = needed[j]; assert(t < nat); grids[t].m_data(x, y, z) = affinities[j]; } } } } } autodock-vina-1.1.2/src/lib/array3d.h0000744000175000017500000000431311562571364017226 0ustar moellermoeller/* Copyright (c) 2006-2010, The Scripps Research Institute Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Author: Dr. Oleg Trott , The Olson Lab, The Scripps Research Institute */ #ifndef VINA_ARRAY3D_H #define VINA_ARRAY3D_H #include // std::bad_alloc #include "common.h" inline sz checked_multiply(sz i, sz j) { if(i == 0 || j == 0) return 0; const sz tmp = i * j; if(tmp < i || tmp < j || tmp / i != j) throw std::bad_alloc(); // can't alloc if the size makes sz wrap around return tmp; } inline sz checked_multiply(sz i, sz j, sz k) { return checked_multiply(checked_multiply(i, j), k); } template class array3d { sz m_i, m_j, m_k; std::vector m_data; friend class boost::serialization::access; template void serialize(Archive& ar, const unsigned version) { ar & m_i; ar & m_j; ar & m_k; ar & m_data; } public: array3d() : m_i(0), m_j(0), m_k(0) {} array3d(sz i, sz j, sz k) : m_i(i), m_j(j), m_k(k), m_data(checked_multiply(i, j, k)) {} sz dim0() const { return m_i; } sz dim1() const { return m_j; } sz dim2() const { return m_k; } sz dim(sz i) const { switch(i) { case 0: return m_i; case 1: return m_j; case 2: return m_k; default: assert(false); return 0; // to get rid of the warning } } void resize(sz i, sz j, sz k) { // data is essentially garbled m_i = i; m_j = j; m_k = k; m_data.resize(checked_multiply(i, j, k)); } T& operator()(sz i, sz j, sz k) { return m_data[i + m_i*(j + m_j*k)]; } const T& operator()(sz i, sz j, sz k) const { return m_data[i + m_i*(j + m_j*k)]; } }; #endif autodock-vina-1.1.2/src/lib/mutate.h0000744000175000017500000000165111562571364017162 0ustar moellermoeller/* Copyright (c) 2006-2010, The Scripps Research Institute Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Author: Dr. Oleg Trott , The Olson Lab, The Scripps Research Institute */ #ifndef VINA_MUTATE_H #define VINA_MUTATE_H #include "model.h" // does not set model void mutate_conf(conf& c, const model& m, fl amplitude, rng& generator); #endif autodock-vina-1.1.2/src/lib/atom_type.h0000744000175000017500000000601311562571364017661 0ustar moellermoeller/* Copyright (c) 2006-2010, The Scripps Research Institute Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Author: Dr. Oleg Trott , The Olson Lab, The Scripps Research Institute */ #ifndef VINA_ATOM_TYPE_H #define VINA_ATOM_TYPE_H #include "atom_constants.h" #include "triangular_matrix_index.h" struct atom_type { enum t {EL, AD, XS, SY}; sz el, ad, xs, sy; atom_type() : el(EL_TYPE_SIZE), ad(AD_TYPE_SIZE), xs(XS_TYPE_SIZE), sy(SY_TYPE_SIZE) {} sz get(t atom_typing_used) const { switch(atom_typing_used) { case EL: return el; case AD: return ad; case XS: return xs; case SY: return sy; default: assert(false); return max_sz; } } bool is_hydrogen() const { return ad_is_hydrogen(ad); } bool is_heteroatom() const { return ad_is_heteroatom(ad) || xs == XS_TYPE_Met_D; } bool acceptable_type() const { return ad < AD_TYPE_SIZE || xs == XS_TYPE_Met_D; } void assign_el() { el = ad_type_to_el_type(ad); if(ad == AD_TYPE_SIZE && xs == XS_TYPE_Met_D) el = EL_TYPE_Met; } bool same_element(const atom_type& a) const { // does not distinguish metals or unassigned types return el == a.el; } fl covalent_radius() const { if(ad < AD_TYPE_SIZE) return ad_type_property(ad).covalent_radius; else if(xs == XS_TYPE_Met_D) return metal_covalent_radius; VINA_CHECK(false); return 0; // never happens - placating the compiler } fl optimal_covalent_bond_length(const atom_type& x) const { return covalent_radius() + x.covalent_radius(); } private: friend class boost::serialization::access; template void serialize(Archive& ar, const unsigned version) { ar & el; ar & ad; ar & xs; ar & sy; } }; inline sz num_atom_types(atom_type::t atom_typing_used) { switch(atom_typing_used) { case atom_type::EL: return EL_TYPE_SIZE; case atom_type::AD: return AD_TYPE_SIZE; case atom_type::XS: return XS_TYPE_SIZE; case atom_type::SY: return SY_TYPE_SIZE; default: assert(false); return max_sz; } } inline sz get_type_pair_index(atom_type::t atom_typing_used, const atom_type& a, const atom_type& b) { // throws error if any arg is unassigned in the given typing scheme sz n = num_atom_types(atom_typing_used); sz i = a.get(atom_typing_used); VINA_CHECK(i < n); sz j = b.get(atom_typing_used); VINA_CHECK(j < n); if(i <= j) return triangular_matrix_index(n, i, j); else return triangular_matrix_index(n, j, i); } #endif autodock-vina-1.1.2/src/lib/manifold.h0000744000175000017500000000560711562571364017461 0ustar moellermoeller/* Copyright (c) 2006-2010, The Scripps Research Institute Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Author: Dr. Oleg Trott , The Olson Lab, The Scripps Research Institute */ #ifndef VINA_MANIFOLD_H #define VINA_MANIFOLD_H // This is not used by Vina proper any more, but "design" sort of needs it #include "ssd.h" struct manifold { ssd ssd_par; sz num_phases; unsigned num_steps; unsigned num_attempts; sz num_final_tunings; //fl manifold_mid_factor; fl manifold_lambda; fl cost_factor; fl max_prob; fl rstart_fraction; fl min_rmsd; vec hunt_cap; scale exclusion; fl relative_pair_cost; // the cost of calculating pairwise energy / interaction of atom with grid bool use_ssd; void print() const { std::cout << "{ssd: "; ssd_par.print(); std::cout << "}\n" << "num_phases=" << num_phases << ",\nnum_steps=" << num_steps << ",\nnum_attempts=" << num_attempts << ",\nnum_final_tunings=" << num_final_tunings << ",\nmanifold_lambda=" << manifold_lambda << ",\ncost_factor=" << cost_factor << ",\nmax_prob=" << max_prob << ",\nrstart_fraction=" << rstart_fraction << ",\nmin_rmsd=" << min_rmsd << ",\nhunt_cap=" << hunt_cap[0] << " " << hunt_cap[1] << " " << hunt_cap[2] << ",\nexclusion=" << exclusion.position << " " << exclusion.orientation << " " << exclusion.torsion << ",\nrelative_pair_cost=" << relative_pair_cost << ",\nuse_ssd=" << use_ssd << std::endl; } manifold() : num_phases(800), num_steps(50), num_attempts(10), num_final_tunings(1), /*manifold_mid_factor(0.1), */ manifold_lambda(0), cost_factor(0.5), max_prob(0.9), rstart_fraction(0.25), min_rmsd(2), //hunt_cap(2, 0.1, 2), hunt_cap(0.01, 0.001, 0.01), exclusion(1, pi/24, pi/12), relative_pair_cost(0.5), use_ssd(false) {} output_type operator()(model& m, const precalculate& p, const igrid& ig, const precalculate& p_widened, const igrid& ig_widened, const vec& corner1, const vec& corner2, rng& generator) const; // out is sorted void operator()(model& m, output_container& out, const precalculate& p, const igrid& ig, const precalculate& p_widened, const igrid& ig_widened, const vec& corner1, const vec& corner2, rng& generator) const; }; #endif autodock-vina-1.1.2/src/lib/manifold.cpp0000744000175000017500000001650311562571364020011 0ustar moellermoeller/* Copyright (c) 2006-2010, The Scripps Research Institute Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Author: Dr. Oleg Trott , The Olson Lab, The Scripps Research Institute */ #include "manifold.h" #include "recent_history.h" #include "coords.h" #include "quasi_newton.h" const vec authentic_v(1000, 1000, 1000); // FIXME? this is here to avoid max_fl/max_fl output_type manifold::operator()(model& m, const precalculate& p, const igrid& ig, const precalculate& p_widened, const igrid& ig_widened, const vec& corner1, const vec& corner2, rng& generator) const { output_container tmp; this->operator()(m, tmp, p, ig, p_widened, ig_widened, corner1, corner2, generator); // call the version that produces the whole container VINA_CHECK(!tmp.empty()); return tmp.front(); } const conf* select_rs(const output_container& mf, sz rstart, rng& generator) { // clean up if(!mf.empty() && mf.size() >= rstart) { sz i = random_sz(0, mf.size()-1, generator); return &(mf[i].c); } return NULL; } bool determine_iu(const conf& c, const output_container& mf, std::vector& internal_too_close, fl exclusion) { // clean up bool tmp = true; VINA_FOR_IN(i, mf) { bool t = c.internal_too_close(mf[i].c, exclusion); internal_too_close[i] = t; if(t) tmp = false; } return tmp; } bool conf_is_legal(const conf& c, const output_container& mf, const std::vector& internal_too_close, const scale& exclusion) { assert(mf.size() == internal_too_close.size()); VINA_FOR_IN(i, mf) if(internal_too_close[i] && c.external_too_close(mf[i].c, exclusion)) return false; return true; } conf generate_external(const conf& internal_conf, const output_container& mf, const std::vector& internal_too_close, bool uniq, const scale& spread, const scale& exclusion, fl rp, const conf* rs, unsigned num_attempts, bool& failed, rng& generator) { // FIXME if one ligand with no side chains, don't use the same (pos, orient) more than once failed = false; VINA_U_FOR(attempt, num_attempts) { conf tmp(internal_conf); tmp.generate_external(spread, rp, rs, generator); // CHECKME if(uniq || conf_is_legal(tmp, mf, internal_too_close, exclusion)) return tmp; if(attempt + 1 >= num_attempts) { failed = true; return tmp; } } VINA_CHECK(false); return internal_conf; // placating the compiler } fl extrapolate_cap(fl from, fl to, fl progress) { if(from < epsilon_fl) return from; return from * std::exp(progress * std::log(to/from)); } vec extrapolate_cap(const vec& from, const vec& to, fl progress) { vec tmp; VINA_FOR_IN(i, tmp) tmp[i] = extrapolate_cap(from[i], to[i], progress); return tmp; } void manifold_phase(sz phase, output_type& out, model& m, const output_container& mf, const precalculate& p, const igrid& ig, fl corner2corner, fl init_manifold_factor, recent_history& e_internal_stats, const manifold& par, rng& generator) { // out.first is starting conf on input out.e = max_fl; // FIXME ? back to above? const fl rp = 1 - std::exp(std::log(1-par.max_prob) * phase/par.num_phases); // max_prob had better be < 1 fl e_internal_cost = par.relative_pair_cost * m.num_internal_pairs(); fl e_external_cost = par.relative_pair_cost * m.num_other_pairs() + m.num_movable_atoms(); const sz rigid_trials = 1 + fl_to_sz(1 + par.cost_factor * e_internal_cost / e_external_cost, 100); unsigned num_steps = (std::max)(unsigned(1), par.num_steps); VINA_U_FOR(step, num_steps) { const fl manifold_factor = init_manifold_factor * std::exp(- par.manifold_lambda * step / par.num_steps); vec hunt_cap; hunt_cap = extrapolate_cap(par.hunt_cap, authentic_v, fl(step) / num_steps); const scale spread(corner2corner * manifold_factor, pi * manifold_factor, pi * manifold_factor); sz rstart = fl_to_sz(par.rstart_fraction * par.num_phases, par.num_phases); const conf* rs = select_rs(mf, rstart, generator); output_type candidate = out; candidate.c.generate_internal(spread.torsion, rp, rs, generator); // CHECKME std::vector internal_too_close(mf.size()); bool uniq = determine_iu(candidate.c, mf, internal_too_close, par.exclusion.torsion); // internal_too_close is output m.seti(candidate.c); VINA_CHECK(rigid_trials > 0); bool candidate_is_set = false; VINA_FOR(i, rigid_trials) { bool failed = false; output_type candidate2(generate_external(candidate.c, mf, internal_too_close, uniq, spread, par.exclusion, rp, rs, par.num_attempts, failed, generator), 0); if(failed && (candidate_is_set || i+1 < rigid_trials)) // candidate is set or a chance to set it remains continue; m.sete(candidate2.c); candidate2.e = m.evale(p, ig, hunt_cap); if(!candidate_is_set || candidate2.e < candidate.e) { candidate_is_set = true; candidate = candidate2; // this works because internal conf is the same in both // FIXME inefficient, all this } } VINA_CHECK(candidate_is_set); if(true) { fl e_internal = (3 * step < 2 * num_steps) ? 0 : m.evali(p, hunt_cap); e_internal_stats.add(e_internal); candidate.e += e_internal; if(step == 0 || candidate.e < out.e) out = candidate; } } } void manifold::operator()(model& m, output_container& out, const precalculate& p, const igrid& ig, const precalculate& p_widened, const igrid& ig_widened, const vec& corner1, const vec& corner2, rng& generator) const { manifold tuning_par; tuning_par.hunt_cap = authentic_v; fl corner2corner = 0.5 * (corner2 - corner1).norm(); conf_size s = m.get_size(); change g(s); sz np = (std::max)(sz(1), num_phases); recent_history e_internal_stats(0, 10, 10); VINA_FOR(phase, np) { output_type tmp(s, 0); tmp.c.randomize(corner1, corner2, generator); manifold_phase(phase, tmp, m, out, p_widened, ig_widened, corner2corner, 1, e_internal_stats, *this, generator); // 1 - initial manifold if(use_ssd) ssd_par(m, p, ig, tmp, g, authentic_v); else { quasi_newton quasi_newton_par; quasi_newton_par.max_steps = ssd_par.evals; quasi_newton_par(m, p, ig, tmp, g, authentic_v); } m.set(tmp.c); tmp.coords = m.get_heavy_atom_movable_coords(); VINA_CHECK(tmp.coords.size() > 0); std::pair closest_rmsd = find_closest(tmp.coords, out); if(closest_rmsd.first < out.size() && closest_rmsd.second < min_rmsd) { // have a very similar one if(tmp.e < out[closest_rmsd.first].e) { // the new one is better, apparently out[closest_rmsd.first] = tmp; // FIXME? slow } } else { // nothing similar out.push_back(new output_type(tmp)); } } // final tunings const output_container null_array; VINA_CHECK(!out.empty()); out.sort(); VINA_CHECK(out.front().e <= out.back().e); // make sure the sorting worked in the correct order } autodock-vina-1.1.2/src/lib/naive_non_cache.h0000744000175000017500000000221711562571364020761 0ustar moellermoeller/* Copyright (c) 2006-2010, The Scripps Research Institute Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Author: Dr. Oleg Trott , The Olson Lab, The Scripps Research Institute */ #ifndef VINA_NAIVE_NON_CACHE_H #define VINA_NAIVE_NON_CACHE_H #include "igrid.h" #include "model.h" struct naive_non_cache : public igrid { naive_non_cache(const precalculate* p_); virtual fl eval (const model& m, fl v) const; // needs m.coords virtual fl eval_deriv( model& m, fl v) const { VINA_CHECK(false); return 0; } // unused private: const precalculate* p; }; #endif autodock-vina-1.1.2/src/split/0000755000175000017500000000000011562571364016073 5ustar moellermoellerautodock-vina-1.1.2/src/split/split.cpp0000644000175000017500000001723311562571364017740 0ustar moellermoeller/* Copyright (c) 2006-2010, The Scripps Research Institute Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Author: Dr. Oleg Trott , The Olson Lab, The Scripps Research Institute */ #include #include #include #include // ligand paths #include #include // getline? #include // for ceila #include #include #include #include // filesystem::basename #include "file.h" #include "parse_error.h" using boost::filesystem::path; path make_path(const std::string& str) { return path(str, boost::filesystem::native); } std::string default_prefix(const std::string& input_name, const std::string& add) { std::string tmp = input_name; if(tmp.size() >= 6 && tmp.substr(tmp.size()-6, 6) == ".pdbqt") tmp.resize(tmp.size() - 6); // FIXME? return tmp + add; } struct usage_error : public std::runtime_error { usage_error(const std::string& message) : std::runtime_error(message) {} }; typedef std::list strl; struct model { strl ligand; strl flex; }; typedef std::list models; models parse_multimodel_pdbqt(const std::string& input) { const path p = make_path(input); ifile in(p); models tmp; unsigned count = 0; std::string str; bool parsing_model = false; bool parsing_ligand = true; while(std::getline(in, str)) { ++count; if(starts_with(str, "MODEL")) { if(parsing_model == true || parsing_ligand == false) throw parse_error(p, count, "Misplaced MODEL tag"); tmp.push_back(model()); parsing_model = true; } else if(starts_with(str, "ENDMDL")) { if(parsing_model == false || parsing_ligand == false) throw parse_error(p, count, "Misplaced ENDMDL tag"); parsing_model = false; } else if(starts_with(str, "BEGIN_RES")) { if(parsing_model == false || parsing_ligand == false) throw parse_error(p, count, "Misplaced BEGIN_RES tag"); parsing_ligand = false; tmp.back().flex.push_back(str); } else if(starts_with(str, "END_RES")) { if(parsing_model == false || parsing_ligand == true) throw parse_error(p, count, "Misplaced END_RES tag"); parsing_ligand = true; tmp.back().flex.push_back(str); } else { if(parsing_model == false) throw parse_error(p, count, "Input occurs outside MODEL"); if(parsing_ligand) { tmp.back().ligand.push_back(str); } else { tmp.back().flex.push_back(str); } } } if(parsing_model == true) throw parse_error(p, count+1, "Missing ENDMDL tag"); return tmp; } void write_pdbqt(const strl& lines, const std::string& name) { if(lines.size() > 0) { ofile out(make_path(name)); for(strl::const_iterator it = lines.begin(); it != lines.end(); ++it) out << *it << '\n'; } } void write_multimodel_pdbqt(const models& m, const std::string& ligand_prefix, const std::string& flex_prefix) { sz how_many = m.size(); std::streamsize w = static_cast(to_string(how_many).size()); sz counter = 0; for(models::const_iterator it = m.begin(); it != m.end(); ++it) { ++counter; const std::string add = to_string(counter, w, '0') + ".pdbqt"; write_pdbqt(it->ligand, ligand_prefix + add); write_pdbqt(it->flex, flex_prefix + add); } } int main(int argc, char* argv[]) { using namespace boost::program_options; const bool advanced = false; const std::string version_string = "AutoDock Vina PDBQT Split 1.1.2 (May 11, 2011)"; const std::string error_message = "\n\n\ Please contact the author, Dr. Oleg Trott , so\n\ that this problem can be resolved. The reproducibility of the\n\ error may be vital, so please remember to include the following in\n\ your problem report:\n\ * the EXACT error message,\n\ * your version of the program,\n\ * the computer system you are running it on,\n\ * command line and configuration file options,\n\ * input (if possible),\n\ \n\ Thank you!\n"; try { std::string input_name, ligand_prefix = "ligand_", flex_prefix = "flex_"; bool help = false, version = false; options_description inputs("Input"); inputs.add_options() ("input", value(&input_name), "input to split (PDBQT)") ; options_description outputs("Output (optional) - defaults are chosen based on the input file name"); outputs.add_options() ("ligand", value(&ligand_prefix), "prefix for ligands") ("flex", value(&flex_prefix), "prefix for side chains") ; options_description info("Information (optional)"); info.add_options() ("help", bool_switch(&help), "print this message") ("version", bool_switch(&version), "print program version") ; options_description desc; desc.add(inputs).add(outputs).add(info); positional_options_description positional; // remains empty variables_map vm; try { store(command_line_parser(argc, argv) .options(desc) .style(command_line_style::default_style ^ command_line_style::allow_guessing) .positional(positional) .run(), vm); notify(vm); } catch(boost::program_options::error& e) { std::cerr << "Command line parse error: " << e.what() << '\n' << "\nCorrect usage:\n" << desc << '\n'; return 1; } if(help) { std::cout << desc << '\n'; return 0; } if(version) { std::cout << version_string << '\n'; return 0; } if(vm.count("input") <= 0) { std::cerr << "Missing input.\n" << "\nCorrect usage:\n" << desc << '\n'; return 1; } if(vm.count("ligand") <= 0) { ligand_prefix = default_prefix(input_name, "_ligand_"); std::cout << "Prefix for ligands will be " << ligand_prefix << '\n'; } if(vm.count("flex") <= 0) { flex_prefix = default_prefix(input_name, "_flex_"); std::cout << "Prefix for flexible side chains will be " << flex_prefix << '\n'; } const models tmp = parse_multimodel_pdbqt(input_name); write_multimodel_pdbqt(tmp, ligand_prefix, flex_prefix); } catch(file_error& e) { std::cerr << "\n\nError: could not open \"" << e.name.native_file_string() << "\" for " << (e.in ? "reading" : "writing") << ".\n"; return 1; } catch(boost::filesystem::filesystem_error& e) { std::cerr << "\n\nFile system error: " << e.what() << '\n'; return 1; } catch(usage_error& e) { std::cerr << "\n\nUsage error: " << e.what() << ".\n"; return 1; } catch(parse_error& e) { std::cerr << "\n\nParse error on line " << e.line << " in file \"" << e.file.native_file_string() << "\": " << e.reason << '\n'; return 1; } catch(std::bad_alloc&) { std::cerr << "\n\nError: insufficient memory!\n"; return 1; } // Errors that shouldn't happen: catch(std::exception& e) { std::cerr << "\n\nAn error occurred: " << e.what() << ". " << error_message; return 1; } catch(internal_error& e) { std::cerr << "\n\nAn internal error occurred in " << e.file << "(" << e.line << "). " << error_message; return 1; } catch(...) { std::cerr << "\n\nAn unknown error occurred. " << error_message; return 1; } } autodock-vina-1.1.2/src/main/0000755000175000017500000000000011562607744015666 5ustar moellermoellerautodock-vina-1.1.2/src/main/main.cpp0000644000175000017500000006470211562571364017325 0ustar moellermoeller/* Copyright (c) 2006-2010, The Scripps Research Institute Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Author: Dr. Oleg Trott , The Olson Lab, The Scripps Research Institute */ #include #include #include #include // ligand paths #include // for ceila #include #include #include #include // filesystem::basename #include // hardware_concurrency // FIXME rm ? #include "parse_pdbqt.h" #include "parallel_mc.h" #include "file.h" #include "cache.h" #include "non_cache.h" #include "naive_non_cache.h" #include "parse_error.h" #include "everything.h" #include "weighted_terms.h" #include "current_weights.h" #include "quasi_newton.h" #include "tee.h" #include "coords.h" // add_to_output_container using boost::filesystem::path; path make_path(const std::string& str) { return path(str, boost::filesystem::native); } void doing(int verbosity, const std::string& str, tee& log) { if(verbosity > 1) { log << str << std::string(" ... "); log.flush(); } } void done(int verbosity, tee& log) { if(verbosity > 1) { log << "done."; log.endl(); } } std::string default_output(const std::string& input_name) { std::string tmp = input_name; if(tmp.size() >= 6 && tmp.substr(tmp.size()-6, 6) == ".pdbqt") tmp.resize(tmp.size() - 6); // FIXME? return tmp + "_out.pdbqt"; } void write_all_output(model& m, const output_container& out, sz how_many, const std::string& output_name, const std::vector& remarks) { if(out.size() < how_many) how_many = out.size(); VINA_CHECK(how_many <= remarks.size()); ofile f(make_path(output_name)); VINA_FOR(i, how_many) { m.set(out[i].c); m.write_model(f, i+1, remarks[i]); // so that model numbers start with 1 } } void do_randomization(model& m, const std::string& out_name, const vec& corner1, const vec& corner2, int seed, int verbosity, tee& log) { conf init_conf = m.get_initial_conf(); rng generator(static_cast(seed)); if(verbosity > 1) { log << "Using random seed: " << seed; log.endl(); } const sz attempts = 10000; conf best_conf = init_conf; fl best_clash_penalty = 0; VINA_FOR(i, attempts) { conf c = init_conf; c.randomize(corner1, corner2, generator); m.set(c); fl penalty = m.clash_penalty(); if(i == 0 || penalty < best_clash_penalty) { best_conf = c; best_clash_penalty = penalty; } } m.set(best_conf); if(verbosity > 1) { log << "Clash penalty: " << best_clash_penalty; // FIXME rm? log.endl(); } m.write_structure(make_path(out_name)); } void refine_structure(model& m, const precalculate& prec, non_cache& nc, output_type& out, const vec& cap, sz max_steps = 1000) { change g(m.get_size()); quasi_newton quasi_newton_par; quasi_newton_par.max_steps = max_steps; const fl slope_orig = nc.slope; VINA_FOR(p, 5) { nc.slope = 100 * std::pow(10.0, 2.0*p); quasi_newton_par(m, prec, nc, out, g, cap); m.set(out.c); // just to be sure if(nc.within(m)) break; } out.coords = m.get_heavy_atom_movable_coords(); if(!nc.within(m)) out.e = max_fl; nc.slope = slope_orig; } std::string vina_remark(fl e, fl lb, fl ub) { std::ostringstream remark; remark.setf(std::ios::fixed, std::ios::floatfield); remark.setf(std::ios::showpoint); remark << "REMARK VINA RESULT: " << std::setw(9) << std::setprecision(1) << e << " " << std::setw(9) << std::setprecision(3) << lb << " " << std::setw(9) << std::setprecision(3) << ub << '\n'; return remark.str(); } output_container remove_redundant(const output_container& in, fl min_rmsd) { output_container tmp; VINA_FOR_IN(i, in) add_to_output_container(tmp, in[i], min_rmsd, in.size()); return tmp; } void do_search(model& m, const boost::optional& ref, const scoring_function& sf, const precalculate& prec, const igrid& ig, const precalculate& prec_widened, const igrid& ig_widened, non_cache& nc, // nc.slope is changed const std::string& out_name, const vec& corner1, const vec& corner2, const parallel_mc& par, fl energy_range, sz num_modes, int seed, int verbosity, bool score_only, bool local_only, tee& log, const terms& t, const flv& weights) { conf_size s = m.get_size(); conf c = m.get_initial_conf(); fl e = max_fl; const vec authentic_v(1000, 1000, 1000); if(score_only) { fl intramolecular_energy = m.eval_intramolecular(prec, authentic_v, c); naive_non_cache nnc(&prec); // for out of grid issues e = m.eval_adjusted(sf, prec, nnc, authentic_v, c, intramolecular_energy); log << "Affinity: " << std::fixed << std::setprecision(5) << e << " (kcal/mol)"; log.endl(); flv term_values = t.evale_robust(m); VINA_CHECK(term_values.size() == 5); log << "Intermolecular contributions to the terms, before weighting:\n"; log << std::setprecision(5); log << " gauss 1 : " << term_values[0] << '\n'; log << " gauss 2 : " << term_values[1] << '\n'; log << " repulsion : " << term_values[2] << '\n'; log << " hydrophobic : " << term_values[3] << '\n'; log << " Hydrogen : " << term_values[4] << '\n'; VINA_CHECK(weights.size() == term_values.size() + 1); fl e2 = 0; VINA_FOR_IN(i, term_values) e2 += term_values[i] * weights[i]; e2 = sf.conf_independent(m, e2); if(e < 100 && std::abs(e2 - e) > 0.05) { log << "WARNING: the individual terms are inconsisent with the\n"; log << "WARNING: affinity. Consider reporting this as a bug:\n"; log << "WARNING: http://vina.scripps.edu/manual.html#bugs\n"; } } else if(local_only) { output_type out(c, e); doing(verbosity, "Performing local search", log); refine_structure(m, prec, nc, out, authentic_v, par.mc.ssd_par.evals); done(verbosity, log); fl intramolecular_energy = m.eval_intramolecular(prec, authentic_v, out.c); e = m.eval_adjusted(sf, prec, nc, authentic_v, out.c, intramolecular_energy); log << "Affinity: " << std::fixed << std::setprecision(5) << e << " (kcal/mol)"; log.endl(); if(!nc.within(m)) log << "WARNING: not all movable atoms are within the search space\n"; doing(verbosity, "Writing output", log); output_container out_cont; out_cont.push_back(new output_type(out)); std::vector remarks(1, vina_remark(e, 0, 0)); write_all_output(m, out_cont, 1, out_name, remarks); // how_many == 1 done(verbosity, log); } else { rng generator(static_cast(seed)); log << "Using random seed: " << seed; log.endl(); output_container out_cont; doing(verbosity, "Performing search", log); par(m, out_cont, prec, ig, prec_widened, ig_widened, corner1, corner2, generator); done(verbosity, log); doing(verbosity, "Refining results", log); VINA_FOR_IN(i, out_cont) refine_structure(m, prec, nc, out_cont[i], authentic_v, par.mc.ssd_par.evals); if(!out_cont.empty()) { out_cont.sort(); const fl best_mode_intramolecular_energy = m.eval_intramolecular(prec, authentic_v, out_cont[0].c); VINA_FOR_IN(i, out_cont) if(not_max(out_cont[i].e)) out_cont[i].e = m.eval_adjusted(sf, prec, nc, authentic_v, out_cont[i].c, best_mode_intramolecular_energy); // the order must not change because of non-decreasing g (see paper), but we'll re-sort in case g is non strictly increasing out_cont.sort(); } const fl out_min_rmsd = 1; out_cont = remove_redundant(out_cont, out_min_rmsd); done(verbosity, log); log.setf(std::ios::fixed, std::ios::floatfield); log.setf(std::ios::showpoint); log << '\n'; log << "mode | affinity | dist from best mode\n"; log << " | (kcal/mol) | rmsd l.b.| rmsd u.b.\n"; log << "-----+------------+----------+----------\n"; model best_mode_model = m; if(!out_cont.empty()) best_mode_model.set(out_cont.front().c); sz how_many = 0; std::vector remarks; VINA_FOR_IN(i, out_cont) { if(how_many >= num_modes || !not_max(out_cont[i].e) || out_cont[i].e > out_cont[0].e + energy_range) break; // check energy_range sanity FIXME ++how_many; log << std::setw(4) << i+1 << " " << std::setw(9) << std::setprecision(1) << out_cont[i].e; // intermolecular_energies[i]; m.set(out_cont[i].c); const model& r = ref ? ref.get() : best_mode_model; const fl lb = m.rmsd_lower_bound(r); const fl ub = m.rmsd_upper_bound(r); log << " " << std::setw(9) << std::setprecision(3) << lb << " " << std::setw(9) << std::setprecision(3) << ub; // FIXME need user-readable error messages in case of failures remarks.push_back(vina_remark(out_cont[i].e, lb, ub)); log.endl(); } doing(verbosity, "Writing output", log); write_all_output(m, out_cont, how_many, out_name, remarks); done(verbosity, log); if(how_many < 1) { log << "WARNING: Could not find any conformations completely within the search space.\n" << "WARNING: Check that it is large enough for all movable atoms, including those in the flexible side chains."; log.endl(); } } } void main_procedure(model& m, const boost::optional& ref, // m is non-const (FIXME?) const std::string& out_name, bool score_only, bool local_only, bool randomize_only, bool no_cache, const grid_dims& gd, int exhaustiveness, const flv& weights, int cpu, int seed, int verbosity, sz num_modes, fl energy_range, tee& log) { doing(verbosity, "Setting up the scoring function", log); everything t; VINA_CHECK(weights.size() == 6); weighted_terms wt(&t, weights); precalculate prec(wt); const fl left = 0.25; const fl right = 0.25; precalculate prec_widened(prec); prec_widened.widen(left, right); done(verbosity, log); vec corner1(gd[0].begin, gd[1].begin, gd[2].begin); vec corner2(gd[0].end, gd[1].end, gd[2].end); parallel_mc par; sz heuristic = m.num_movable_atoms() + 10 * m.get_size().num_degrees_of_freedom(); par.mc.num_steps = unsigned(70 * 3 * (50 + heuristic) / 2); // 2 * 70 -> 8 * 20 // FIXME par.mc.ssd_par.evals = unsigned((25 + m.num_movable_atoms()) / 3); par.mc.min_rmsd = 1.0; par.mc.num_saved_mins = 20; par.mc.hunt_cap = vec(10, 10, 10); par.num_tasks = exhaustiveness; par.num_threads = cpu; par.display_progress = (verbosity > 1); const fl slope = 1e6; // FIXME: too large? used to be 100 if(randomize_only) { do_randomization(m, out_name, corner1, corner2, seed, verbosity, log); } else { non_cache nc (m, gd, &prec, slope); // if gd has 0 n's, this will not constrain anything non_cache nc_widened(m, gd, &prec_widened, slope); // if gd has 0 n's, this will not constrain anything if(no_cache) { do_search(m, ref, wt, prec, nc, prec_widened, nc_widened, nc, out_name, corner1, corner2, par, energy_range, num_modes, seed, verbosity, score_only, local_only, log, t, weights); } else { bool cache_needed = !(score_only || randomize_only || local_only); if(cache_needed) doing(verbosity, "Analyzing the binding site", log); cache c("scoring_function_version001", gd, slope, atom_type::XS); if(cache_needed) c.populate(m, prec, m.get_movable_atom_types(prec.atom_typing_used())); if(cache_needed) done(verbosity, log); do_search(m, ref, wt, prec, c, prec, c, nc, out_name, corner1, corner2, par, energy_range, num_modes, seed, verbosity, score_only, local_only, log, t, weights); } } } struct usage_error : public std::runtime_error { usage_error(const std::string& message) : std::runtime_error(message) {} }; struct options_occurrence { bool some; bool all; options_occurrence() : some(false), all(true) {} // convenience options_occurrence& operator+=(const options_occurrence& x) { some = some || x.some; all = all && x.all; return *this; } }; options_occurrence get_occurrence(boost::program_options::variables_map& vm, boost::program_options::options_description& d) { options_occurrence tmp; VINA_FOR_IN(i, d.options()) if(vm.count((*d.options()[i]).long_name())) tmp.some = true; else tmp.all = false; return tmp; } void check_occurrence(boost::program_options::variables_map& vm, boost::program_options::options_description& d) { VINA_FOR_IN(i, d.options()) { const std::string& str = (*d.options()[i]).long_name(); if(!vm.count(str)) std::cerr << "Required parameter --" << str << " is missing!\n"; } } model parse_bundle(const std::string& rigid_name, const boost::optional& flex_name_opt, const std::vector& ligand_names) { model tmp = (flex_name_opt) ? parse_receptor_pdbqt(make_path(rigid_name), make_path(flex_name_opt.get())) : parse_receptor_pdbqt(make_path(rigid_name)); VINA_FOR_IN(i, ligand_names) tmp.append(parse_ligand_pdbqt(make_path(ligand_names[i]))); return tmp; } model parse_bundle(const std::vector& ligand_names) { VINA_CHECK(!ligand_names.empty()); // FIXME check elsewhere model tmp = parse_ligand_pdbqt(make_path(ligand_names[0])); VINA_RANGE(i, 1, ligand_names.size()) tmp.append(parse_ligand_pdbqt(make_path(ligand_names[i]))); return tmp; } model parse_bundle(const boost::optional& rigid_name_opt, const boost::optional& flex_name_opt, const std::vector& ligand_names) { if(rigid_name_opt) return parse_bundle(rigid_name_opt.get(), flex_name_opt, ligand_names); else return parse_bundle(ligand_names); } int main(int argc, char* argv[]) { using namespace boost::program_options; const std::string version_string = "AutoDock Vina 1.1.2 (May 11, 2011)"; const std::string error_message = "\n\n\ Please contact the author, Dr. Oleg Trott , so\n\ that this problem can be resolved. The reproducibility of the\n\ error may be vital, so please remember to include the following in\n\ your problem report:\n\ * the EXACT error message,\n\ * your version of the program,\n\ * the type of computer system you are running it on,\n\ * all command line options,\n\ * configuration file (if used),\n\ * ligand file as PDBQT,\n\ * receptor file as PDBQT,\n\ * flexible side chains file as PDBQT (if used),\n\ * output file as PDBQT (if any),\n\ * input (if possible),\n\ * random seed the program used (this is printed when the program starts).\n\ \n\ Thank you!\n"; const std::string cite_message = "\ #################################################################\n\ # If you used AutoDock Vina in your work, please cite: #\n\ # #\n\ # O. Trott, A. J. Olson, #\n\ # AutoDock Vina: improving the speed and accuracy of docking #\n\ # with a new scoring function, efficient optimization and #\n\ # multithreading, Journal of Computational Chemistry 31 (2010) #\n\ # 455-461 #\n\ # #\n\ # DOI 10.1002/jcc.21334 #\n\ # #\n\ # Please see http://vina.scripps.edu for more information. #\n\ #################################################################\n"; try { std::string rigid_name, ligand_name, flex_name, config_name, out_name, log_name; fl center_x, center_y, center_z, size_x, size_y, size_z; int cpu = 0, seed, exhaustiveness, verbosity = 2, num_modes = 9; fl energy_range = 2.0; // -0.035579, -0.005156, 0.840245, -0.035069, -0.587439, 0.05846 fl weight_gauss1 = -0.035579; fl weight_gauss2 = -0.005156; fl weight_repulsion = 0.840245; fl weight_hydrophobic = -0.035069; fl weight_hydrogen = -0.587439; fl weight_rot = 0.05846; bool score_only = false, local_only = false, randomize_only = false, help = false, help_advanced = false, version = false; // FIXME positional_options_description positional; // remains empty options_description inputs("Input"); inputs.add_options() ("receptor", value(&rigid_name), "rigid part of the receptor (PDBQT)") ("flex", value(&flex_name), "flexible side chains, if any (PDBQT)") ("ligand", value(&ligand_name), "ligand (PDBQT)") ; //options_description search_area("Search area (required, except with --score_only)"); options_description search_area("Search space (required)"); search_area.add_options() ("center_x", value(¢er_x), "X coordinate of the center") ("center_y", value(¢er_y), "Y coordinate of the center") ("center_z", value(¢er_z), "Z coordinate of the center") ("size_x", value(&size_x), "size in the X dimension (Angstroms)") ("size_y", value(&size_y), "size in the Y dimension (Angstroms)") ("size_z", value(&size_z), "size in the Z dimension (Angstroms)") ; //options_description outputs("Output prefixes (optional - by default, input names are stripped of .pdbqt\nare used as prefixes. _001.pdbqt, _002.pdbqt, etc. are appended to the prefixes to produce the output names"); options_description outputs("Output (optional)"); outputs.add_options() ("out", value(&out_name), "output models (PDBQT), the default is chosen based on the ligand file name") ("log", value(&log_name), "optionally, write log file") ; options_description advanced("Advanced options (see the manual)"); advanced.add_options() ("score_only", bool_switch(&score_only), "score only - search space can be omitted") ("local_only", bool_switch(&local_only), "do local search only") ("randomize_only", bool_switch(&randomize_only), "randomize input, attempting to avoid clashes") ("weight_gauss1", value(&weight_gauss1)->default_value(weight_gauss1), "gauss_1 weight") ("weight_gauss2", value(&weight_gauss2)->default_value(weight_gauss2), "gauss_2 weight") ("weight_repulsion", value(&weight_repulsion)->default_value(weight_repulsion), "repulsion weight") ("weight_hydrophobic", value(&weight_hydrophobic)->default_value(weight_hydrophobic), "hydrophobic weight") ("weight_hydrogen", value(&weight_hydrogen)->default_value(weight_hydrogen), "Hydrogen bond weight") ("weight_rot", value(&weight_rot)->default_value(weight_rot), "N_rot weight") ; options_description misc("Misc (optional)"); misc.add_options() ("cpu", value(&cpu), "the number of CPUs to use (the default is to try to detect the number of CPUs or, failing that, use 1)") ("seed", value(&seed), "explicit random seed") ("exhaustiveness", value(&exhaustiveness)->default_value(8), "exhaustiveness of the global search (roughly proportional to time): 1+") ("num_modes", value(&num_modes)->default_value(9), "maximum number of binding modes to generate") ("energy_range", value(&energy_range)->default_value(3.0), "maximum energy difference between the best binding mode and the worst one displayed (kcal/mol)") ; options_description config("Configuration file (optional)"); config.add_options() ("config", value(&config_name), "the above options can be put here") ; options_description info("Information (optional)"); info.add_options() ("help", bool_switch(&help), "display usage summary") ("help_advanced", bool_switch(&help_advanced), "display usage summary with advanced options") ("version", bool_switch(&version), "display program version") ; options_description desc, desc_config, desc_simple; desc .add(inputs).add(search_area).add(outputs).add(advanced).add(misc).add(config).add(info); desc_config.add(inputs).add(search_area).add(outputs).add(advanced).add(misc); desc_simple.add(inputs).add(search_area).add(outputs).add(misc).add(config).add(info); variables_map vm; try { //store(parse_command_line(argc, argv, desc, command_line_style::default_style ^ command_line_style::allow_guessing), vm); store(command_line_parser(argc, argv) .options(desc) .style(command_line_style::default_style ^ command_line_style::allow_guessing) .positional(positional) .run(), vm); notify(vm); } catch(boost::program_options::error& e) { std::cerr << "Command line parse error: " << e.what() << '\n' << "\nCorrect usage:\n" << desc_simple << '\n'; return 1; } if(vm.count("config")) { try { path name = make_path(config_name); ifile config_stream(name); store(parse_config_file(config_stream, desc_config), vm); notify(vm); } catch(boost::program_options::error& e) { std::cerr << "Configuration file parse error: " << e.what() << '\n' << "\nCorrect usage:\n" << desc_simple << '\n'; return 1; } } if(help) { std::cout << desc_simple << '\n'; return 0; } if(help_advanced) { std::cout << desc << '\n'; return 0; } if(version) { std::cout << version_string << '\n'; return 0; } bool search_box_needed = !score_only; // randomize_only and local_only still need the search space bool output_produced = !score_only; bool receptor_needed = !randomize_only; if(receptor_needed) { if(vm.count("receptor") <= 0) { std::cerr << "Missing receptor.\n" << "\nCorrect usage:\n" << desc_simple << '\n'; return 1; } } if(vm.count("ligand") <= 0) { std::cerr << "Missing ligand.\n" << "\nCorrect usage:\n" << desc_simple << '\n'; return 1; } if(cpu < 1) cpu = 1; if(vm.count("seed") == 0) seed = auto_seed(); if(exhaustiveness < 1) throw usage_error("exhaustiveness must be 1 or greater"); if(num_modes < 1) throw usage_error("num_modes must be 1 or greater"); sz max_modes_sz = static_cast(num_modes); boost::optional rigid_name_opt; if(vm.count("receptor")) rigid_name_opt = rigid_name; boost::optional flex_name_opt; if(vm.count("flex")) flex_name_opt = flex_name; if(vm.count("flex") && !vm.count("receptor")) throw usage_error("Flexible side chains are not allowed without the rest of the receptor"); // that's the only way parsing works, actually tee log; if(vm.count("log") > 0) log.init(log_name); if(search_box_needed) { options_occurrence oo = get_occurrence(vm, search_area); if(!oo.all) { check_occurrence(vm, search_area); std::cerr << "\nCorrect usage:\n" << desc_simple << std::endl; return 1; } if(size_x <= 0 || size_y <= 0 || size_z <= 0) throw usage_error("Search space dimensions should be positive"); } log << cite_message << '\n'; if(search_box_needed && size_x * size_y * size_z > 27e3) { log << "WARNING: The search space volume > 27000 Angstrom^3 (See FAQ)\n"; } if(output_produced) { // FIXME if(!vm.count("out")) { out_name = default_output(ligand_name); log << "Output will be " << out_name << '\n'; } } grid_dims gd; // n's = 0 via default c'tor flv weights; weights.push_back(weight_gauss1); weights.push_back(weight_gauss2); weights.push_back(weight_repulsion); weights.push_back(weight_hydrophobic); weights.push_back(weight_hydrogen); weights.push_back(5 * weight_rot / 0.1 - 1); // linearly maps onto a different range, internally. see everything.cpp if(search_box_needed) { const fl granularity = 0.375; vec span(size_x, size_y, size_z); vec center(center_x, center_y, center_z); VINA_FOR_IN(i, gd) { gd[i].n = sz(std::ceil(span[i] / granularity)); fl real_span = granularity * gd[i].n; gd[i].begin = center[i] - real_span/2; gd[i].end = gd[i].begin + real_span; } } if(vm.count("cpu") == 0) { unsigned num_cpus = boost::thread::hardware_concurrency(); if(verbosity > 1) { if(num_cpus > 0) log << "Detected " << num_cpus << " CPU" << ((num_cpus > 1) ? "s" : "") << '\n'; else log << "Could not detect the number of CPUs, using 1\n"; } if(num_cpus > 0) cpu = num_cpus; else cpu = 1; } if(cpu < 1) cpu = 1; if(verbosity > 1 && exhaustiveness < cpu) log << "WARNING: at low exhaustiveness, it may be impossible to utilize all CPUs\n"; doing(verbosity, "Reading input", log); model m = parse_bundle(rigid_name_opt, flex_name_opt, std::vector(1, ligand_name)); boost::optional ref; done(verbosity, log); main_procedure(m, ref, out_name, score_only, local_only, randomize_only, false, // no_cache == false gd, exhaustiveness, weights, cpu, seed, verbosity, max_modes_sz, energy_range, log); } catch(file_error& e) { std::cerr << "\n\nError: could not open \"" << e.name.native_file_string() << "\" for " << (e.in ? "reading" : "writing") << ".\n"; return 1; } catch(boost::filesystem::filesystem_error& e) { std::cerr << "\n\nFile system error: " << e.what() << '\n'; return 1; } catch(usage_error& e) { std::cerr << "\n\nUsage error: " << e.what() << ".\n"; return 1; } catch(parse_error& e) { std::cerr << "\n\nParse error on line " << e.line << " in file \"" << e.file.native_file_string() << "\": " << e.reason << '\n'; return 1; } catch(std::bad_alloc&) { std::cerr << "\n\nError: insufficient memory!\n"; return 1; } // Errors that shouldn't happen: catch(std::exception& e) { std::cerr << "\n\nAn error occurred: " << e.what() << ". " << error_message; return 1; } catch(internal_error& e) { std::cerr << "\n\nAn internal error occurred in " << e.file << "(" << e.line << "). " << error_message; return 1; } catch(...) { std::cerr << "\n\nAn unknown error occurred. " << error_message; return 1; } } autodock-vina-1.1.2/build/0000755000175000017500000000000011562607744015252 5ustar moellermoellerautodock-vina-1.1.2/build/makefile_common0000644000175000017500000000336111562571401020313 0ustar moellermoellerLIBOBJ = cache.o coords.o current_weights.o everything.o grid.o szv_grid.o manifold.o model.o monte_carlo.o mutate.o my_pid.o naive_non_cache.o non_cache.o parallel_mc.o parse_pdbqt.o pdb.o quasi_newton.o quaternion.o random.o ssd.o terms.o weighted_terms.o MAINOBJ = main.o SPLITOBJ = split.o INCFLAGS = -I $(BOOST_INCLUDE) # -pedantic fails on Mac with Boost 1.41 (syntax problems in their headers) #CC = ${GPP} ${C_PLATFORM} -ansi -pedantic -Wno-long-long ${C_OPTIONS} $(INCFLAGS) CC = ${GPP} ${C_PLATFORM} -ansi -Wno-long-long ${C_OPTIONS} $(INCFLAGS) LDFLAGS = -L$(BASE)/lib -L. LIBS = -l boost_system${BOOST_LIB_VERSION} -l boost_thread${BOOST_LIB_VERSION} -l boost_serialization${BOOST_LIB_VERSION} -l boost_filesystem${BOOST_LIB_VERSION} -l boost_program_options${BOOST_LIB_VERSION}#-l pthread .SUFFIXES: .cpp .o %.o : ../../../src/lib/%.cpp $(CC) $(CFLAGS) -o $@ -c $< %.o : ../../../src/design/%.cpp $(CC) $(CFLAGS) -I ../../../src/lib -o $@ -c $< %.o : ../../../src/main/%.cpp $(CC) $(CFLAGS) -I ../../../src/lib -o $@ -c $< %.o : ../../../src/split/%.cpp $(CC) $(CFLAGS) -I ../../../src/lib -o $@ -c $< all: vina vina_split include dependencies vina: $(MAINOBJ) $(LIBOBJ) $(CC) $(LDFLAGS) -o $@ $^ $(LIBS) vina_split: $(SPLITOBJ) $(CC) $(LDFLAGS) -o $@ $^ $(LIBS) clean: rm -f *.o depend: ln -sf `${GPP} -print-file-name=libstdc++.a` rm -f dependencies_tmp dependencies_tmp.bak touch dependencies_tmp makedepend -f dependencies_tmp -Y -I ../../../src/lib ../../../src/lib/*.cpp ../../../src/tests/*.cpp ../../../src/design/*.cpp ../../../src/main/*.cpp ../../../src/split/*.cpp ../../../src/tune/*.cpp sed -e "s/^\.\.\/\.\.\/\.\.\/src\/[a-z]*\//.\//" dependencies_tmp > dependencies rm -f dependencies_tmp dependencies_tmp.bak autodock-vina-1.1.2/build/linux/0000755000175000017500000000000011562607744016411 5ustar moellermoellerautodock-vina-1.1.2/build/linux/release/0000755000175000017500000000000011562571401020017 5ustar moellermoellerautodock-vina-1.1.2/build/linux/release/dependencies0000644000175000017500000000000011562571401022356 0ustar moellermoellerautodock-vina-1.1.2/build/linux/release/Makefile0000644000175000017500000000030011562571401021450 0ustar moellermoellerBASE=/usr/local BOOST_VERSION=1_41 BOOST_INCLUDE = $(BASE)/include C_PLATFORM=-static -pthread GPP=/usr/local/bin/g++ C_OPTIONS= -O3 -DNDEBUG BOOST_LIB_VERSION= include ../../makefile_common autodock-vina-1.1.2/build/linux/debug/0000755000175000017500000000000011562607744017477 5ustar moellermoellerautodock-vina-1.1.2/build/linux/debug/dependencies0000644000175000017500000000000011562571401022024 0ustar moellermoellerautodock-vina-1.1.2/build/linux/debug/Makefile0000644000175000017500000000026611562571401021131 0ustar moellermoellerBASE=/usr/local BOOST_VERSION=1_41 BOOST_INCLUDE = $(BASE)/include C_PLATFORM=-static -pthread GPP=/usr/local/bin/g++ C_OPTIONS= -g BOOST_LIB_VERSION= include ../../makefile_common autodock-vina-1.1.2/build/mac/0000755000175000017500000000000011562607744016012 5ustar moellermoellerautodock-vina-1.1.2/build/mac/release/0000755000175000017500000000000011562571401017420 5ustar moellermoellerautodock-vina-1.1.2/build/mac/release/dependencies0000644000175000017500000000000011562571401021757 0ustar moellermoellerautodock-vina-1.1.2/build/mac/release/Makefile0000644000175000017500000000040111562571401021053 0ustar moellermoellerBASE=/usr/local BOOST_VERSION=1_41 BOOST_INCLUDE = $(BASE)/include C_PLATFORM=-arch i386 -arch ppc -isysroot /Developer/SDKs/MacOSX10.5.sdk -mmacosx-version-min=10.4 GPP=/usr/bin/g++ C_OPTIONS= -O3 -DNDEBUG BOOST_LIB_VERSION= include ../../makefile_common autodock-vina-1.1.2/build/mac/debug/0000755000175000017500000000000011562607744017100 5ustar moellermoellerautodock-vina-1.1.2/build/mac/debug/dependencies0000644000175000017500000000000011562571401021425 0ustar moellermoellerautodock-vina-1.1.2/build/mac/debug/Makefile0000644000175000017500000000036711562571401020534 0ustar moellermoellerBASE=/usr/local BOOST_VERSION=1_41 BOOST_INCLUDE = $(BASE)/include C_PLATFORM=-arch i386 -arch ppc -isysroot /Developer/SDKs/MacOSX10.5.sdk -mmacosx-version-min=10.4 GPP=/usr/bin/g++ C_OPTIONS= -g BOOST_LIB_VERSION= include ../../makefile_common autodock-vina-1.1.2/LICENSE0000644000175000017500000002613611562571372015165 0ustar moellermoeller Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.