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