OpenStructure
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 
29 namespace ost { namespace conop {
30 
31 struct Date {
32  Date(int y, int m, int d):
33  year(y), month(m), day(d)
34  { }
35  Date():
36  year(1900), month(1), day(1)
37  { }
38  bool operator<(const Date& date) const
39  {
40  return year<date.year && month<date.month && day<date.day;
41  }
42  bool operator==(const Date& date) const
43  {
44  return year==date.year && month==date.month && day==date.day;
45  }
46 
47  bool operator!=(const Date& date) const
48  {
49  return !this->operator==(date);
50  }
51 
52  static Date FromString(const StringRef& str)
53  {
54  assert(str[4]=='-');
55  assert(str[7]=='-');
56  std::pair<bool, int> year=str.substr(0,4).to_int();
57  std::pair<bool, int> month=str.substr(5,2).to_int();
58  std::pair<bool, int> day=str.substr(8, 2).to_int();
59  assert(year.first); assert(month.first); assert(day.first);
60  return Date(year.second, month.second, day.second);
61  }
62 
63  int year;
64  int month;
65  int day;
66 };
67 
68 struct AtomSpec {
70  : ordinal(0), is_leaving(false) {
71  }
72  int ordinal;
76  bool is_leaving;
78  bool operator==(const AtomSpec& rhs) const {
79  return ordinal==rhs.ordinal && name==rhs.name && alt_name==rhs.alt_name &&
80  element==rhs.element && is_leaving==rhs.is_leaving &&
81  rhs.is_aromatic==rhs.is_aromatic;
82  }
83  bool operator!=(const AtomSpec& rhs) const {
84  return !this->operator==(rhs);
85  }
86 };
87 
88 struct BondSpec {
90  : atom_one(0), atom_two(0), order(1) {
91 
92  }
93 
94  bool operator==(const BondSpec& rhs) const {
95  return atom_one==rhs.atom_one && atom_two==rhs.atom_two;
96  }
97 
98  bool operator!=(const BondSpec& rhs) const {
99  return !this->operator==(rhs);
100  }
101  int atom_one;
102  int atom_two;
103  int order;
104 };
105 
106 typedef std::vector<AtomSpec> AtomSpecList;
107 typedef std::vector<BondSpec> BondSpecList;
108 class Compound;
109 typedef boost::shared_ptr<Compound> CompoundPtr;
110 
111 
114 public:
115  typedef enum {
116  PDB ='P',
117  CHARMM ='C',
118  OPLS ='O',
119  AMBER ='A',
120  } Dialect;
121 
122  Compound(const String& id)
123  : olc_('?'), tlc_(id), chem_class_(), dialect_(Compound::PDB) {
124  }
125 
127  const String& GetID() const {
128  return tlc_;
129  }
130  Dialect GetDialect() const { return dialect_; }
131 
133  switch (dialect_) {
134  case CHARMM:
135  return "CHARMM";
136  case PDB:
137  return "PDB";
138  case OPLS:
139  return "OPLS";
140  case AMBER:
141  return "AMBER";
142  default:
143  return "";
144  }
145  }
146  void SetDialect(Dialect dialect) { dialect_=dialect; }
147 
148  void SetOneLetterCode(char olc) {
149  olc_=olc;
150  }
151 
157  char GetOneLetterCode() const {
158  return olc_;
159  }
160 
161  void SetChemClass(mol::ChemClass chem_class) {
162  chem_class_=chem_class;
163  }
164 
166  return chem_class_;
167  }
168 
169  bool IsPeptideLinking() const {
170  return chem_class_.IsPeptideLinking();
171  }
172  void AddAtom(const AtomSpec& atom) {
173  atom_specs_.push_back(atom);
174  }
175 
176  void AddBond(const BondSpec& bond) {
177  bond_specs_.push_back(bond);
178  }
179 
180  const AtomSpecList& GetAtomSpecs() const {
181  return atom_specs_;
182  }
183 
184  int GetAtomSpecIndex(const String& name) const;
185 
186  const String& GetFormula() { return formula_; }
187 
188  void SetFormula(const String& formula) { formula_=formula; }
189 
190  const BondSpecList& GetBondSpecs() const {
191  return bond_specs_;
192  }
193  const Date& GetModificationDate() const
194  {
195  return mod_date_;
196  }
197  const Date& GetCreationDate() const
198  {
199  return creation_date_;
200  }
201 
202  void SetModificationDate(const Date& mod_date)
203  {
204  mod_date_=mod_date;
205  }
206 
207  void SetCreationDate(const Date& creation_date)
208  {
209  creation_date_=creation_date;
210  }
211 private:
212  Compound();
213  char olc_;
214  String tlc_;
215  String formula_;
216  AtomSpecList atom_specs_;
217  BondSpecList bond_specs_;
218  mol::ChemClass chem_class_;
219  Dialect dialect_;
220  Date creation_date_;
221  Date mod_date_;
222 };
223 
224 }}
225 
226 #endif