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  is_aromatic==rhs.is_aromatic;
101 
102  }
103  bool operator!=(const AtomSpec& rhs) const {
104  return !this->operator==(rhs);
105  }
106 };
107 
110  atom_one(0),
111  atom_two(0),
112  order(1)
113  {
114  }
115 
116  BondSpec(int a, int b, int o): atom_one(a), atom_two(b), order(o) {}
117  bool operator==(const BondSpec& rhs) const {
118  return atom_one==rhs.atom_one && atom_two==rhs.atom_two;
119  }
120 
121  bool operator!=(const BondSpec& rhs) const {
122  return !this->operator==(rhs);
123  }
124  int atom_one;
125  int atom_two;
126  int order;
127 };
128 
129 typedef std::vector<AtomSpec> AtomSpecList;
130 typedef std::vector<BondSpec> BondSpecList;
131 class Compound;
132 typedef boost::shared_ptr<Compound> CompoundPtr;
133 
134 
137 public:
138  typedef enum {
139  PDB ='P',
140  CHARMM ='C',
141  OPLS ='O',
142  AMBER ='A',
143  } Dialect;
144 
145  Compound(const String& id):
146  olc_('?'),
147  tlc_(id),
148  formula_(),
149  name_(),
150  inchi_(),
151  inchi_key_(),
152  atom_specs_(),
153  bond_specs_(),
154  chem_class_(),
155  chem_type_(),
156  dialect_(Compound::PDB),
157  creation_date_(),
158  mod_date_()
159  {
160  }
161 
163  const String& GetID() const {
164  return tlc_;
165  }
166  Dialect GetDialect() const { return dialect_; }
167 
169  switch (dialect_) {
170  case CHARMM:
171  return "CHARMM";
172  case PDB:
173  return "PDB";
174  case OPLS:
175  return "OPLS";
176  case AMBER:
177  return "AMBER";
178  default:
179  return "";
180  }
181  }
182  void SetDialect(Dialect dialect) { dialect_=dialect; }
183 
184  void SetOneLetterCode(char olc) {
185  olc_=olc;
186  }
187 
193  char GetOneLetterCode() const {
194  return olc_;
195  }
196 
197  void SetChemClass(mol::ChemClass chem_class) {
198  chem_class_=chem_class;
199  }
200 
202  return chem_class_;
203  }
204 
205  void SetChemType(mol::ChemType chem_type) {
206  chem_type_=chem_type;
207  }
208 
214  return chem_type_;
215  }
216 
217  bool IsPeptideLinking() const {
218  return chem_class_.IsPeptideLinking();
219  }
220 
221  bool IsNucleotideLinking() const {
222  return chem_class_.IsNucleotideLinking();
223  }
224 
225  void AddAtom(const AtomSpec& atom) {
226  atom_specs_.push_back(atom);
227  }
228 
229  void AddBond(const BondSpec& bond) {
230  bond_specs_.push_back(bond);
231  }
232 
233  const AtomSpecList& GetAtomSpecs() const {
234  return atom_specs_;
235  }
236 
237  int GetAtomSpecIndex(const String& name) const;
238 
239  const String& GetName() { return name_; }
240 
241  void SetName(const String& name) { name_=name; }
242 
243  void SetFormula(const String& formula) { formula_=formula; }
244 
245  const String& GetFormula() { return formula_; }
246 
247  void SetInchi(const String& inchi) { inchi_=inchi; }
248 
249  const String& GetInchi() { return inchi_; }
250 
251  void SetInchiKey(const String& inchikey) { inchi_key_=inchikey; }
252 
253  const String& GetInchiKey() { return inchi_key_; }
254 
255  const BondSpecList& GetBondSpecs() const {
256  return bond_specs_;
257  }
258  const Date& GetModificationDate() const
259  {
260  return mod_date_;
261  }
262  const Date& GetCreationDate() const
263  {
264  return creation_date_;
265  }
266 
267  void SetModificationDate(const Date& mod_date)
268  {
269  mod_date_=mod_date;
270  }
271 
272  void SetCreationDate(const Date& creation_date)
273  {
274  creation_date_=creation_date;
275  }
276 private:
277  Compound();
278  char olc_;
279  String tlc_;
280  String formula_;
281  String name_;
282  String inchi_;
283  String inchi_key_;
284  AtomSpecList atom_specs_;
285  BondSpecList bond_specs_;
286  mol::ChemClass chem_class_;
287  mol::ChemType chem_type_;
288  Dialect dialect_;
289  Date creation_date_;
290  Date mod_date_;
291 };
292 
293 typedef std::map<String, CompoundPtr> CompoundMap;
294 
295 }}
296 
297 #endif
void SetFormula(const String &formula)
Definition: compound.hh:243
convenient datatype for referencing character data
Definition: string_ref.hh:39
std::vector< BondSpec > BondSpecList
Definition: compound.hh:130
Date(int y, int m, int d)
Definition: compound.hh:34
std::vector< AtomSpec > AtomSpecList
Definition: compound.hh:129
std::vector< StringRef > split(char p) const
split string into chunks delimited by p
BondSpec(int a, int b, int o)
Definition: compound.hh:116
std::string String
Definition: base.hh:54
const String & GetName()
Definition: compound.hh:239
#define DLLEXPORT_OST_CONOP
void SetName(const String &name)
Definition: compound.hh:241
const BondSpecList & GetBondSpecs() const
Definition: compound.hh:255
bool operator!=(const Date &date) const
Definition: compound.hh:49
bool operator==(const AtomSpec &rhs) const
Definition: compound.hh:97
void SetCreationDate(const Date &creation_date)
Definition: compound.hh:272
const String & GetID() const
three-letter code that is unique for every compound
Definition: compound.hh:163
Compound(const String &id)
Definition: compound.hh:145
std::map< String, CompoundPtr > CompoundMap
Definition: compound.hh:293
bool DLLEXPORT_OST_GEOM operator==(const Line2 &l1, const Line2 &l2)
const String & GetInchi()
Definition: compound.hh:249
static Date FromString(const StringRef &str)
Definition: compound.hh:54
const AtomSpecList & GetAtomSpecs() const
Definition: compound.hh:233
void SetModificationDate(const Date &mod_date)
Definition: compound.hh:267
Knows about the atoms and bonds of a chemical compounds.
Definition: compound.hh:136
const Date & GetCreationDate() const
Definition: compound.hh:262
void SetChemClass(mol::ChemClass chem_class)
Definition: compound.hh:197
void AddAtom(const AtomSpec &atom)
Definition: compound.hh:225
String GetDialectAsString() const
Definition: compound.hh:168
void SetInchiKey(const String &inchikey)
Definition: compound.hh:251
Dialect GetDialect() const
Definition: compound.hh:166
boost::shared_ptr< Compound > CompoundPtr
Definition: compound.hh:131
void SetOneLetterCode(char olc)
Definition: compound.hh:184
bool IsPeptideLinking() const
Definition: compound.hh:217
mol::ChemType GetChemType() const
PDB ligand classification from component dictionary.
Definition: compound.hh:213
char GetOneLetterCode() const
one letter code, if available.
Definition: compound.hh:193
const Date & GetModificationDate() const
Definition: compound.hh:258
void SetDialect(Dialect dialect)
Definition: compound.hh:182
const String & GetInchiKey()
Definition: compound.hh:253
mol::ChemClass GetChemClass() const
Definition: compound.hh:201
bool operator==(const BondSpec &rhs) const
Definition: compound.hh:117
void AddBond(const BondSpec &bond)
Definition: compound.hh:229
AtomSpec(int o, const String &n, const String &a, const String &e, bool l, bool r)
Definition: compound.hh:82
void SetChemType(mol::ChemType chem_type)
Definition: compound.hh:205
bool IsNucleotideLinking() const
Definition: compound.hh:221
bool operator!=(const BondSpec &rhs) const
Definition: compound.hh:121
const String & GetFormula()
Definition: compound.hh:245
bool operator<(const Date &date) const
Definition: compound.hh:40
void SetInchi(const String &inchi)
Definition: compound.hh:247
bool operator==(const Date &date) const
Definition: compound.hh:44
bool operator!=(const AtomSpec &rhs) const
Definition: compound.hh:103