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-2020 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>
26 #include <ost/message.hh>
27 #include <ost/log.hh>
29 
30 #include <ost/mol/chem_class.hh>
31 #include <ost/mol/chem_type.hh>
32 
33 namespace ost { namespace conop {
34 
36  Date(int y, int m, int d):
37  year(y), month(m), day(d)
38  { }
39  Date():
40  year(1900), month(1), day(1)
41  { }
42  bool operator<(const Date& date) const
43  {
44  return year<date.year && month<date.month && day<date.day;
45  }
46  bool operator==(const Date& date) const
47  {
48  return year==date.year && month==date.month && day==date.day;
49  }
50 
51  bool operator!=(const Date& date) const
52  {
53  return !this->operator==(date);
54  }
55 
56  static Date FromString(const StringRef& str)
57  {
58  std::vector<StringRef> parts=str.split('-');
59  if (parts.size() != 3) {
60  std::stringstream msg;
61  msg << "Invalid date string: '" << str << "'";
62  throw ost::Error(msg.str());
63  }
64  std::pair<bool, int> year=parts[0].to_int();
65  std::pair<bool, int> month=parts[1].to_int();
66  std::pair<bool, int> day=parts[2].to_int();
67  if (! year.first || ! month.first || ! day.first) {
68  std::stringstream msg;
69  msg << "Invalid date string: '" << str << "'";
70  throw ost::Error(msg.str());
71  }
72  return Date(year.second, month.second, day.second);
73  }
74 
75  String ToString() const;
76 
77  int year;
78  int month;
79  int day;
80 };
81 
84  ordinal(0),
85  name(),
86  alt_name(),
87  element(),
88  is_leaving(false),
89  is_aromatic(),
90  charge(0)
91  {
92  }
93  AtomSpec(int o, const String& n, const String& a, const String& e,
94  bool l, bool r, int c=0):
95  ordinal(o),
96  name(n),
97  alt_name(a),
98  element(e),
99  is_leaving(l),
100  is_aromatic(r),
101  charge(c)
102  {}
103  int ordinal;
109  int charge;
110  bool operator==(const AtomSpec& rhs) const {
111  return ordinal==rhs.ordinal && name==rhs.name && alt_name==rhs.alt_name &&
112  element==rhs.element && is_leaving==rhs.is_leaving &&
113  is_aromatic==rhs.is_aromatic;
114 
115  }
116  bool operator!=(const AtomSpec& rhs) const {
117  return !this->operator==(rhs);
118  }
119 };
120 
123  atom_one(0),
124  atom_two(0),
125  order(1)
126  {
127  }
128 
129  BondSpec(int a, int b, int o): atom_one(a), atom_two(b), order(o) {}
130  bool operator==(const BondSpec& rhs) const {
131  return atom_one==rhs.atom_one && atom_two==rhs.atom_two;
132  }
133 
134  bool operator!=(const BondSpec& rhs) const {
135  return !this->operator==(rhs);
136  }
137  int atom_one;
138  int atom_two;
139  int order;
140 };
141 
142 typedef std::vector<AtomSpec> AtomSpecList;
143 typedef std::vector<BondSpec> BondSpecList;
144 class Compound;
145 typedef boost::shared_ptr<Compound> CompoundPtr;
146 
147 
150 public:
151  typedef enum {
152  PDB ='P',
153  CHARMM ='C',
154  OPLS ='O',
155  AMBER ='A',
156  } Dialect;
157 
158  Compound(const String& id):
159  olc_('?'),
160  tlc_(id),
161  formula_(),
162  name_(),
163  inchi_(),
164  inchi_key_(),
165  smiles_(),
166  replaced_by_(),
167  obsolete_(),
168  atom_specs_(),
169  bond_specs_(),
170  chem_class_(),
171  chem_type_(),
172  dialect_(Compound::PDB),
173  creation_date_(),
174  mod_date_()
175  {
176  }
177 
179  const String& GetID() const {
180  return tlc_;
181  }
182 
184  void SetID(const String& id) {
185  tlc_ = id;
186  }
187 
188  Dialect GetDialect() const { return dialect_; }
189 
191  switch (dialect_) {
192  case CHARMM:
193  return "CHARMM";
194  case PDB:
195  return "PDB";
196  case OPLS:
197  return "OPLS";
198  case AMBER:
199  return "AMBER";
200  default:
201  return "";
202  }
203  }
204  void SetDialect(Dialect dialect) { dialect_=dialect; }
205 
206  void SetOneLetterCode(char olc) {
207  olc_=olc;
208  }
209 
215  char GetOneLetterCode() const {
216  return olc_;
217  }
218 
219  void SetChemClass(mol::ChemClass chem_class) {
220  chem_class_=chem_class;
221  }
222 
224  return chem_class_;
225  }
226 
227  void SetObsolete(bool obsolete) {
228  obsolete_=obsolete;
229  }
230 
231  bool GetObsolete() const {
232  return obsolete_;
233  }
234 
235  void SetReplacedBy(const String& replaced_by) {
236  replaced_by_=replaced_by;
237  }
238 
239  const String& GetReplacedBy() const {
240  return replaced_by_;
241  }
242 
243  void SetChemType(mol::ChemType chem_type) {
244  chem_type_=chem_type;
245  }
246 
252  return chem_type_;
253  }
254 
255  bool IsPeptideLinking() const {
256  return chem_class_.IsPeptideLinking();
257  }
258 
259  bool IsNucleotideLinking() const {
260  return chem_class_.IsNucleotideLinking();
261  }
262 
263  void AddAtom(const AtomSpec& atom) {
264  atom_specs_.push_back(atom);
265  }
266 
267  void AddBond(const BondSpec& bond) {
268  bond_specs_.push_back(bond);
269  }
270 
271  const AtomSpecList& GetAtomSpecs() const {
272  return atom_specs_;
273  }
274 
275  int GetAtomSpecIndex(const String& name) const;
276 
277  const String& GetName() { return name_; }
278 
279  void SetName(const String& name) { name_=name; }
280 
281  void SetFormula(const String& formula) { formula_=formula; }
282 
283  const String& GetFormula() { return formula_; }
284 
285  void SetInchi(const String& inchi) { inchi_=inchi; }
286 
287  const String& GetInchi() { return inchi_; }
288 
289  void SetInchiKey(const String& inchikey) { inchi_key_=inchikey; }
290 
291  const String& GetInchiKey() { return inchi_key_; }
292 
293  void SetSMILES(const String& smiles) { smiles_=smiles; }
294 
295  const String& GetSMILES() { return smiles_; }
296 
297  const BondSpecList& GetBondSpecs() const {
298  return bond_specs_;
299  }
300  const Date& GetModificationDate() const
301  {
302  return mod_date_;
303  }
304  const Date& GetCreationDate() const
305  {
306  return creation_date_;
307  }
308 
309  void SetModificationDate(const Date& mod_date)
310  {
311  mod_date_=mod_date;
312  }
313 
314  void SetCreationDate(const Date& creation_date)
315  {
316  creation_date_=creation_date;
317  }
318 private:
319  Compound();
320  char olc_;
321  String tlc_;
322  String formula_;
323  String name_;
324  String inchi_;
325  String inchi_key_;
326  String smiles_;
327  String replaced_by_;
328  bool obsolete_;
329  AtomSpecList atom_specs_;
330  BondSpecList bond_specs_;
331  mol::ChemClass chem_class_;
332  mol::ChemType chem_type_;
333  Dialect dialect_;
334  Date creation_date_;
335  Date mod_date_;
336 };
337 
338 typedef std::map<String, CompoundPtr> CompoundMap;
339 
340 }}
341 
342 #endif
convenient datatype for referencing character data
Definition: string_ref.hh:39
std::vector< StringRef > split(char p) const
split string into chunks delimited by p
Knows about the atoms and bonds of a chemical compounds.
Definition: compound.hh:149
bool GetObsolete() const
Definition: compound.hh:231
void AddBond(const BondSpec &bond)
Definition: compound.hh:267
mol::ChemType GetChemType() const
PDB ligand classification from component dictionary.
Definition: compound.hh:251
const String & GetInchiKey()
Definition: compound.hh:291
bool IsPeptideLinking() const
Definition: compound.hh:255
const String & GetSMILES()
Definition: compound.hh:295
void AddAtom(const AtomSpec &atom)
Definition: compound.hh:263
void SetFormula(const String &formula)
Definition: compound.hh:281
void SetReplacedBy(const String &replaced_by)
Definition: compound.hh:235
const String & GetName()
Definition: compound.hh:277
const String & GetReplacedBy() const
Definition: compound.hh:239
char GetOneLetterCode() const
one letter code, if available.
Definition: compound.hh:215
void SetID(const String &id)
set three-letter code that is unique for every compound
Definition: compound.hh:184
String GetDialectAsString() const
Definition: compound.hh:190
Dialect GetDialect() const
Definition: compound.hh:188
void SetModificationDate(const Date &mod_date)
Definition: compound.hh:309
void SetOneLetterCode(char olc)
Definition: compound.hh:206
const Date & GetCreationDate() const
Definition: compound.hh:304
const String & GetFormula()
Definition: compound.hh:283
void SetSMILES(const String &smiles)
Definition: compound.hh:293
void SetObsolete(bool obsolete)
Definition: compound.hh:227
void SetChemClass(mol::ChemClass chem_class)
Definition: compound.hh:219
const BondSpecList & GetBondSpecs() const
Definition: compound.hh:297
const String & GetInchi()
Definition: compound.hh:287
void SetInchi(const String &inchi)
Definition: compound.hh:285
const AtomSpecList & GetAtomSpecs() const
Definition: compound.hh:271
bool IsNucleotideLinking() const
Definition: compound.hh:259
int GetAtomSpecIndex(const String &name) const
Compound(const String &id)
Definition: compound.hh:158
void SetDialect(Dialect dialect)
Definition: compound.hh:204
void SetName(const String &name)
Definition: compound.hh:279
mol::ChemClass GetChemClass() const
Definition: compound.hh:223
void SetChemType(mol::ChemType chem_type)
Definition: compound.hh:243
const String & GetID() const
three-letter code that is unique for every compound
Definition: compound.hh:179
void SetCreationDate(const Date &creation_date)
Definition: compound.hh:314
void SetInchiKey(const String &inchikey)
Definition: compound.hh:289
const Date & GetModificationDate() const
Definition: compound.hh:300
#define DLLEXPORT_OST_CONOP
std::string String
Definition: base.hh:54
bool DLLEXPORT_OST_GEOM operator==(const Line2 &l1, const Line2 &l2)
std::vector< BondSpec > BondSpecList
Definition: compound.hh:143
boost::shared_ptr< Compound > CompoundPtr
Definition: compound.hh:144
std::vector< AtomSpec > AtomSpecList
Definition: compound.hh:142
std::map< String, CompoundPtr > CompoundMap
Definition: compound.hh:338
Definition: base.dox:1
bool operator!=(const AtomSpec &rhs) const
Definition: compound.hh:116
bool operator==(const AtomSpec &rhs) const
Definition: compound.hh:110
AtomSpec(int o, const String &n, const String &a, const String &e, bool l, bool r, int c=0)
Definition: compound.hh:93
bool operator!=(const BondSpec &rhs) const
Definition: compound.hh:134
bool operator==(const BondSpec &rhs) const
Definition: compound.hh:130
BondSpec(int a, int b, int o)
Definition: compound.hh:129
Date(int y, int m, int d)
Definition: compound.hh:36
bool operator<(const Date &date) const
Definition: compound.hh:42
bool operator!=(const Date &date) const
Definition: compound.hh:51
static Date FromString(const StringRef &str)
Definition: compound.hh:56
String ToString() const
bool operator==(const Date &date) const
Definition: compound.hh:46