global_functions.h
Go to the documentation of this file.
00001 // Copyright (c) 2009-2010  INRIA Sophia-Antipolis (France).
00002 // All rights reserved.
00003 //
00004 //This file is part of ESBTL.
00005 //
00006 //ESBTL is free software: you can redistribute it and/or modify
00007 //it under the terms of the GNU General Public License as published by
00008 //the Free Software Foundation, either version 3 of the License, or
00009 //(at your option) any later version.
00010 //
00011 //ESBTL is distributed in the hope that it will be useful,
00012 //but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 //GNU General Public License for more details.
00015 //
00016 //You should have received a copy of the GNU General Public License
00017 //along with ESBTL.  If not, see <http://www.gnu.org/licenses/>.
00018 //
00019 //
00020 //Additional permission under GNU GPL version 3 section 7
00021 //
00022 //If you modify this Library, or any covered work, by linking or
00023 //combining it with CGAL (or a modified version of that library), the
00024 //licensors of this Library grant you additional permission to convey
00025 //the resulting work. Corresponding Source for a non-source form of
00026 //such a combination shall include the source code for the parts of CGAL
00027 //used as well as that of the covered work. 
00028 //
00029 //
00030 //
00031 // Author(s)     :  Sébastien Loriot
00032 
00033 
00034 
00035 #ifndef ESBTL_GLOBAL_FUNCTIONS_H
00036 #define ESBTL_GLOBAL_FUNCTIONS_H
00037 
00038 #include <fstream>
00039 
00040 namespace ESBTL {
00041 
00042   
00051 template <class Atom>
00052 bool is_backbone(const Atom& atom){
00053   if (get_is_hetatm(atom))
00054     return false;
00055   std::string atomname=get_atom_name(atom);
00056   return atomname=="N"   ||
00057          atomname=="CA"  ||
00058          atomname=="C"   ||
00059          atomname=="O"   ||
00060          atomname=="OXT";
00061 }
00062 
00071 template <class Atom>
00072 bool is_side_chain_or_CA(const Atom& atom){
00073   if (atom.is_hetatm())
00074     return false;
00075   return !is_backbone(atom) || get_atom_name(atom)=="CA";
00076 }
00077 
00084 template <class Atom>
00085 bool is_hydrogen(const Atom& atom){
00086   return get_element(atom) == std::string("H");
00087 }
00088 
00096 template <class Atom>
00097 bool is_water(const Atom& atom){
00098   std::string resname=get_residue_name(atom);
00099   return resname=="HOH" || resname=="SOL" || resname=="WAT";
00100 }
00101 
00102 
00115 template<class Atom_iterator,class Classifier_with_radius,class Color_of>
00116 void write_to_cgo(const std::string& filename,Atom_iterator first, Atom_iterator last,
00117                   const Classifier_with_radius& classifier,const Color_of& color_of)
00118 {
00119   std::ofstream st(filename.c_str());
00120   st << "from pymol.cgo import *\n";
00121   st << "from pymol import cmd\n";  
00122   st << "obj=[\n";  
00123   
00124   for (Atom_iterator it=first;it!=last;++it){
00125     st << "COLOR," << color_of(*it);
00126     st << ",SPHERE, " <<it->x() << ", " << it->y() << ", " << it->z() << ", ";
00127     st << get_radius(classifier.get_properties(*it)) << ",\n";
00128   }
00129   
00130   st << "]\ncmd.load_cgo(obj,\'cgo01\')\n";
00131 }
00132 
00133 }//namespace ESBTL
00134 
00135 #endif //ESBTL_GLOBAL_FUNCTIONS_H