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 <map>
24 #include <boost/shared_ptr.hpp>
25 #include <ost/string_ref.hh>
27 
28 #include <ost/mol/chem_class.hh>
29 #include <ost/mol/chem_type.hh>
30 
31 namespace ost { namespace conop {
32 
34  Date(int y, int m, int d):
35  year(y), month(m), day(d)
36  { }
37  Date():
38  year(1900), month(1), day(1)
39  { }
40  bool operator<(const Date& date) const
41  {
42  return year<date.year && month<date.month && day<date.day;
43  }
44  bool operator==(const Date& date) const
45  {
46  return year==date.year && month==date.month && day==date.day;
47  }
48 
49  bool operator!=(const Date& date) const
50  {
51  return !this->operator==(date);
52  }
53 
54  static Date FromString(const StringRef& str)
55  {
56  std::vector<StringRef> parts=str.split('-');
57  assert(parts.size()==3);
58  std::pair<bool, int> year=parts[0].to_int();
59  std::pair<bool, int> month=parts[1].to_int();
60  std::pair<bool, int> day=parts[2].to_int();
61  assert(year.first); assert(month.first); assert(day.first);
62  return Date(year.second, month.second, day.second);
63  }
64 
65  String ToString() const;
66 
67  int year;
68  int month;
69  int day;
70 };
71 
74  ordinal(0),
75  name(),
76  alt_name(),
77  element(),
78  is_leaving(false),
79  is_aromatic()
80  {
81  }
82  AtomSpec(int o, const String& n, const String& a, const String& e,
83  bool l, bool r):
84  ordinal(o),
85  name(n),
86  alt_name(a),
87  element(e),
88  is_leaving(l),
89  is_aromatic(r)
90  {}
91  int ordinal;
95  bool is_leaving;
97  bool operator==(const AtomSpec& rhs) const {
98  return ordinal==rhs.ordinal && name==rhs.name && alt_name==rhs.alt_name &&
99  element==rhs.element && is_leaving==rhs.is_leaving &&
100  rhs.is_aromatic==rhs.is_aromatic;
101  }
102  bool operator!=(const AtomSpec& rhs) const {
103  return !this->operator==(rhs);
104  }
105 };
106 
109  atom_one(0),
110  atom_two(0),
111  order(1)
112  {
113  }
114 
115  BondSpec(int a, int b, int o): atom_one(a), atom_two(b), order(o) {}
116  bool operator==(const BondSpec& rhs) const {
117  return atom_one==rhs.atom_one && atom_two==rhs.atom_two;
118  }
119 
120  bool operator!=(const BondSpec& rhs) const {
121  return !this->operator==(rhs);
122  }
123  int atom_one;
124  int atom_two;
125  int order;
126 };
127 
128 typedef std::vector<AtomSpec> AtomSpecList;
129 typedef std::vector<BondSpec> BondSpecList;
130 class Compound;
131 typedef boost::shared_ptr<Compound> CompoundPtr;
132 
133 
136 public:
137  typedef enum {
138  PDB ='P',
139  CHARMM ='C',
140  OPLS ='O',
141  AMBER ='A',
142  } Dialect;
143 
144  Compound(const String& id):
145  olc_('?'),
146  tlc_(id),
147  formula_(),
148  name_(),
149  atom_specs_(),
150  bond_specs_(),
151  chem_class_(),
152  chem_type_(),
153  dialect_(Compound::PDB),
154  creation_date_(),
155  mod_date_()
156  {
157  }
158 
160  const String& GetID() const {
161  return tlc_;
162  }
163  Dialect GetDialect() const { return dialect_; }
164 
166  switch (dialect_) {
167  case CHARMM:
168  return "CHARMM";
169  case PDB:
170  return "PDB";
171  case OPLS:
172  return "OPLS";
173  case AMBER:
174  return "AMBER";
175  default:
176  return "";
177  }
178  }
179  void SetDialect(Dialect dialect) { dialect_=dialect; }
180 
181  void SetOneLetterCode(char olc) {
182  olc_=olc;
183  }
184 
190  char GetOneLetterCode() const {
191  return olc_;
192  }
193 
194  void SetChemClass(mol::ChemClass chem_class) {
195  chem_class_=chem_class;
196  }
197 
199  return chem_class_;
200  }
201 
202  void SetChemType(mol::ChemType chem_type) {
203  chem_type_=chem_type;
204  }
205 
211  return chem_type_;
212  }
213 
214  bool IsPeptideLinking() const {
215  return chem_class_.IsPeptideLinking();
216  }
217 
218  bool IsNucleotideLinking() const {
219  return chem_class_.IsNucleotideLinking();
220  }
221 
222  void AddAtom(const AtomSpec& atom) {
223  atom_specs_.push_back(atom);
224  }
225 
226  void AddBond(const BondSpec& bond) {
227  bond_specs_.push_back(bond);
228  }
229 
230  const AtomSpecList& GetAtomSpecs() const {
231  return atom_specs_;
232  }
233 
234  int GetAtomSpecIndex(const String& name) const;
235 
236  const String& GetName() { return name_; }
237 
238  void SetName(const String& name) { name_=name; }
239 
240  void SetFormula(const String& formula) { formula_=formula; }
241 
242  const String& GetFormula() { return formula_; }
243 
244  const BondSpecList& GetBondSpecs() const {
245  return bond_specs_;
246  }
247  const Date& GetModificationDate() const
248  {
249  return mod_date_;
250  }
251  const Date& GetCreationDate() const
252  {
253  return creation_date_;
254  }
255 
256  void SetModificationDate(const Date& mod_date)
257  {
258  mod_date_=mod_date;
259  }
260 
261  void SetCreationDate(const Date& creation_date)
262  {
263  creation_date_=creation_date;
264  }
265 private:
266  Compound();
267  char olc_;
268  String tlc_;
269  String formula_;
270  String name_;
271  AtomSpecList atom_specs_;
272  BondSpecList bond_specs_;
273  mol::ChemClass chem_class_;
274  mol::ChemType chem_type_;
275  Dialect dialect_;
276  Date creation_date_;
277  Date mod_date_;
278 };
279 
280 typedef std::map<String, CompoundPtr> CompoundMap;
281 
282 }}
283 
284 #endif