00001 00002 //------------------------------------------------------------------------------ 00003 // This file is part of the OpenStructure project <www.openstructure.org> 00004 // 00005 // Copyright (C) 2008-2011 by the OpenStructure authors 00006 // 00007 // This library is free software; you can redistribute it and/or modify it under 00008 // the terms of the GNU Lesser General Public License as published by the Free 00009 // Software Foundation; either version 3.0 of the License, or (at your option) 00010 // any later version. 00011 // This library is distributed in the hope that it will be useful, but WITHOUT 00012 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 00013 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 00014 // details. 00015 // 00016 // You should have received a copy of the GNU Lesser General Public License 00017 // along with this library; if not, write to the Free Software Foundation, Inc., 00018 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00019 //------------------------------------------------------------------------------ 00020 #ifndef OST_MOL_BASE_BUILDER_HH 00021 #define OST_MOL_BASE_BUILDER_HH 00022 00023 #include "module_config.hh" 00024 00025 #include "atom_handle.hh" 00026 #include "residue_handle.hh" 00027 #include "chain_handle.hh" 00028 #include "entity_handle.hh" 00029 #include "bond_handle.hh" 00030 #include "xcs_editor.hh" 00031 00032 00033 namespace ost { namespace mol { 00034 00035 // a helper class to easily create entities 00036 class DLLEXPORT Builder { 00037 public: 00038 Builder(): ent_(CreateEntity()), edi_(ent_.EditXCS(BUFFERED_EDIT)) { 00039 } 00040 00041 // conversion to entity handle 00042 operator EntityHandle() { return ent_; } 00043 00044 Builder& Chain(const String& name) { 00045 chain_ = edi_.InsertChain(name); 00046 res_ = ResidueHandle(); 00047 atom_ = AtomHandle(); 00048 return *this; 00049 } 00050 00051 Builder& Residue(const String& name) { 00052 res_ = edi_.AppendResidue(chain_, name); 00053 atom_ = AtomHandle(); 00054 return *this; 00055 } 00056 00057 Builder& OneLetterCode(char olc) { 00058 res_.SetOneLetterCode(olc); 00059 return *this; 00060 } 00061 00062 Builder& Atom(const String& name, const geom::Vec3& pos=geom::Vec3()) { 00063 edi_.InsertAtom(res_, name, pos); 00064 return *this; 00065 } 00066 Builder& Gly(bool connect=true) { 00067 this->Residue("GLY"); 00068 this->Atom("N"); 00069 this->Atom("CA"); 00070 this->Atom("C"); 00071 this->Atom("O"); 00072 if (connect) { 00073 edi_.Connect(res_.FindAtom("N"), res_.FindAtom("CA")); 00074 edi_.Connect(res_.FindAtom("CA"), res_.FindAtom("C")); 00075 edi_.Connect(res_.FindAtom("C"), res_.FindAtom("O")); 00076 } 00077 return *this; 00078 } 00079 Builder& ConnectToPrev() { 00080 AtomHandle ah = res_.FindAtom("N"); 00081 AtomHandle pa = res_.GetPrev().FindAtom("C"); 00082 if (pa) { 00083 edi_.Connect(pa, ah); 00084 } 00085 return *this; 00086 } 00087 private: 00088 EntityHandle ent_; 00089 ChainHandle chain_; 00090 ResidueHandle res_; 00091 AtomHandle atom_; 00092 XCSEditor edi_; 00093 00094 00095 }; 00096 00097 }} 00098 #endif 00099