OpenStructure
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
builder.hh
Go to the documentation of this file.
1 
2 //------------------------------------------------------------------------------
3 // This file is part of the OpenStructure project <www.openstructure.org>
4 //
5 // Copyright (C) 2008-2011 by the OpenStructure authors
6 //
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License as published by the Free
9 // Software Foundation; either version 3.0 of the License, or (at your option)
10 // any later version.
11 // This library is distributed in the hope that it will be useful, but WITHOUT
12 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
14 // details.
15 //
16 // You should have received a copy of the GNU Lesser General Public License
17 // along with this library; if not, write to the Free Software Foundation, Inc.,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 //------------------------------------------------------------------------------
20 #ifndef OST_MOL_BASE_BUILDER_HH
21 #define OST_MOL_BASE_BUILDER_HH
22 
23 #include "module_config.hh"
24 
25 #include "atom_handle.hh"
26 #include "residue_handle.hh"
27 #include "chain_handle.hh"
28 #include "entity_handle.hh"
29 #include "bond_handle.hh"
30 #include "xcs_editor.hh"
31 
32 
33 namespace ost { namespace mol {
34 
35 // a helper class to easily create entities
36 class DLLEXPORT Builder {
37 public:
38  Builder(): ent_(CreateEntity()), edi_(ent_.EditXCS(BUFFERED_EDIT)) {
39  }
40 
41  // conversion to entity handle
42  operator EntityHandle() { return ent_; }
43 
44  Builder& Chain(const String& name) {
45  chain_ = edi_.InsertChain(name);
46  res_ = ResidueHandle();
47  atom_ = AtomHandle();
48  return *this;
49  }
50 
51  Builder& Residue(const String& name) {
52  res_ = edi_.AppendResidue(chain_, name);
53  atom_ = AtomHandle();
54  return *this;
55  }
56 
57  Builder& OneLetterCode(char olc) {
58  res_.SetOneLetterCode(olc);
59  return *this;
60  }
61 
62  Builder& Atom(const String& name, const geom::Vec3& pos=geom::Vec3()) {
63  edi_.InsertAtom(res_, name, pos);
64  return *this;
65  }
66  Builder& Gly(bool connect=true) {
67  this->Residue("GLY");
68  this->Atom("N");
69  this->Atom("CA");
70  this->Atom("C");
71  this->Atom("O");
72  if (connect) {
73  edi_.Connect(res_.FindAtom("N"), res_.FindAtom("CA"));
74  edi_.Connect(res_.FindAtom("CA"), res_.FindAtom("C"));
75  edi_.Connect(res_.FindAtom("C"), res_.FindAtom("O"));
76  }
77  return *this;
78  }
80  AtomHandle ah = res_.FindAtom("N");
81  AtomHandle pa = res_.GetPrev().FindAtom("C");
82  if (pa) {
83  edi_.Connect(pa, ah);
84  }
85  return *this;
86  }
87 private:
88  EntityHandle ent_;
89  ChainHandle chain_;
90  ResidueHandle res_;
91  AtomHandle atom_;
92  XCSEditor edi_;
93 
94 
95 };
96 
97 }}
98 #endif
99 
Builder & Gly(bool connect=true)
Definition: builder.hh:66
std::string String
Definition: base.hh:54
Handle to atom datatype.
Definition: atom_handle.hh:37
Protein or molecule.
Builder & Atom(const String &name, const geom::Vec3 &pos=geom::Vec3())
Definition: builder.hh:62
Builder & ConnectToPrev()
Definition: builder.hh:79
Builder & OneLetterCode(char olc)
Definition: builder.hh:57
linear chain of residues
Definition: chain_handle.hh:52
Three dimensional vector class, using Real precision.
Definition: vec3.hh:42
external coordinate system editor
Definition: xcs_editor.hh:36
Builder & Residue(const String &name)
Definition: builder.hh:51
Builder & Chain(const String &name)
Definition: builder.hh:44