OpenStructure
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
compound.hh
Go to the documentation of this file.
1 //------------------------------------------------------------------------------
2 // This file is part of the OpenStructure project <www.openstructure.org>
3 //
4 // Copyright (C) 2008-2011 by the OpenStructure authors
5 //
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License as published by the Free
8 // Software Foundation; either version 3.0 of the License, or (at your option)
9 // any later version.
10 // This library is distributed in the hope that it will be useful, but WITHOUT
11 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
13 // details.
14 //
15 // You should have received a copy of the GNU Lesser General Public License
16 // along with this library; if not, write to the Free Software Foundation, Inc.,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 //------------------------------------------------------------------------------
19 #ifndef OST_CONOP_COMPOUND_HH
20 #define OST_CONOP_COMPOUND_HH
21 
22 #include <vector>
23 #include <boost/shared_ptr.hpp>
24 #include <ost/string_ref.hh>
26 
27 #include <ost/mol/chem_class.hh>
28 #include <ost/mol/chem_type.hh>
29 
30 namespace ost { namespace conop {
31 
33  Date(int y, int m, int d):
34  year(y), month(m), day(d)
35  { }
36  Date():
37  year(1900), month(1), day(1)
38  { }
39  bool operator<(const Date& date) const
40  {
41  return year<date.year && month<date.month && day<date.day;
42  }
43  bool operator==(const Date& date) const
44  {
45  return year==date.year && month==date.month && day==date.day;
46  }
47 
48  bool operator!=(const Date& date) const
49  {
50  return !this->operator==(date);
51  }
52 
53  static Date FromString(const StringRef& str)
54  {
55  std::vector<StringRef> parts=str.split('-');
56  assert(parts.size()==3);
57  std::pair<bool, int> year=parts[0].to_int();
58  std::pair<bool, int> month=parts[1].to_int();
59  std::pair<bool, int> day=parts[2].to_int();
60  assert(year.first); assert(month.first); assert(day.first);
61  return Date(year.second, month.second, day.second);
62  }
63 
64  String ToString() const;
65 
66  int year;
67  int month;
68  int day;
69 };
70 
73  : ordinal(0), is_leaving(false) {
74  }
75  int ordinal;
79  bool is_leaving;
81  bool operator==(const AtomSpec& rhs) const {
82  return ordinal==rhs.ordinal && name==rhs.name && alt_name==rhs.alt_name &&
83  element==rhs.element && is_leaving==rhs.is_leaving &&
84  rhs.is_aromatic==rhs.is_aromatic;
85  }
86  bool operator!=(const AtomSpec& rhs) const {
87  return !this->operator==(rhs);
88  }
89 };
90 
93  : atom_one(0), atom_two(0), order(1) {
94 
95  }
96 
97  bool operator==(const BondSpec& rhs) const {
98  return atom_one==rhs.atom_one && atom_two==rhs.atom_two;
99  }
100 
101  bool operator!=(const BondSpec& rhs) const {
102  return !this->operator==(rhs);
103  }
104  int atom_one;
105  int atom_two;
106  int order;
107 };
108 
109 typedef std::vector<AtomSpec> AtomSpecList;
110 typedef std::vector<BondSpec> BondSpecList;
111 class Compound;
112 typedef boost::shared_ptr<Compound> CompoundPtr;
113 
114 
117 public:
118  typedef enum {
119  PDB ='P',
120  CHARMM ='C',
121  OPLS ='O',
122  AMBER ='A',
123  } Dialect;
124 
125  Compound(const String& id)
126  : olc_('?'), tlc_(id), chem_class_(), chem_type_(), dialect_(Compound::PDB){
127  }
128 
130  const String& GetID() const {
131  return tlc_;
132  }
133  Dialect GetDialect() const { return dialect_; }
134 
136  switch (dialect_) {
137  case CHARMM:
138  return "CHARMM";
139  case PDB:
140  return "PDB";
141  case OPLS:
142  return "OPLS";
143  case AMBER:
144  return "AMBER";
145  default:
146  return "";
147  }
148  }
149  void SetDialect(Dialect dialect) { dialect_=dialect; }
150 
151  void SetOneLetterCode(char olc) {
152  olc_=olc;
153  }
154 
160  char GetOneLetterCode() const {
161  return olc_;
162  }
163 
164  void SetChemClass(mol::ChemClass chem_class) {
165  chem_class_=chem_class;
166  }
167 
169  return chem_class_;
170  }
171 
172  void SetChemType(mol::ChemType chem_type) {
173  chem_type_=chem_type;
174  }
175 
181  return chem_type_;
182  }
183 
184  bool IsPeptideLinking() const {
185  return chem_class_.IsPeptideLinking();
186  }
187 
188  bool IsNucleotideLinking() const {
189  return chem_class_.IsNucleotideLinking();
190  }
191 
192  void AddAtom(const AtomSpec& atom) {
193  atom_specs_.push_back(atom);
194  }
195 
196  void AddBond(const BondSpec& bond) {
197  bond_specs_.push_back(bond);
198  }
199 
200  const AtomSpecList& GetAtomSpecs() const {
201  return atom_specs_;
202  }
203 
204  int GetAtomSpecIndex(const String& name) const;
205 
206  const String& GetName() { return name_; }
207 
208  void SetName(const String& name) { name_=name; }
209 
210  void SetFormula(const String& formula) { formula_=formula; }
211 
212  const String& GetFormula() { return formula_; }
213 
214  const BondSpecList& GetBondSpecs() const {
215  return bond_specs_;
216  }
217  const Date& GetModificationDate() const
218  {
219  return mod_date_;
220  }
221  const Date& GetCreationDate() const
222  {
223  return creation_date_;
224  }
225 
226  void SetModificationDate(const Date& mod_date)
227  {
228  mod_date_=mod_date;
229  }
230 
231  void SetCreationDate(const Date& creation_date)
232  {
233  creation_date_=creation_date;
234  }
235 private:
236  Compound();
237  char olc_;
238  String tlc_;
239  String formula_;
240  String name_;
241  AtomSpecList atom_specs_;
242  BondSpecList bond_specs_;
243  mol::ChemClass chem_class_;
244  mol::ChemType chem_type_;
245  Dialect dialect_;
246  Date creation_date_;
247  Date mod_date_;
248 };
249 
250 }}
251 
252 #endif