00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef OST_CONOP_COMPOUND_HH
00020 #define OST_CONOP_COMPOUND_HH
00021
00022 #include <vector>
00023 #include <map>
00024 #include <boost/shared_ptr.hpp>
00025 #include <ost/string_ref.hh>
00026 #include <ost/conop/module_config.hh>
00027
00028 #include <ost/mol/chem_class.hh>
00029 #include <ost/mol/chem_type.hh>
00030
00031 namespace ost { namespace conop {
00032
00033 struct DLLEXPORT_OST_CONOP Date {
00034 Date(int y, int m, int d):
00035 year(y), month(m), day(d)
00036 { }
00037 Date():
00038 year(1900), month(1), day(1)
00039 { }
00040 bool operator<(const Date& date) const
00041 {
00042 return year<date.year && month<date.month && day<date.day;
00043 }
00044 bool operator==(const Date& date) const
00045 {
00046 return year==date.year && month==date.month && day==date.day;
00047 }
00048
00049 bool operator!=(const Date& date) const
00050 {
00051 return !this->operator==(date);
00052 }
00053
00054 static Date FromString(const StringRef& str)
00055 {
00056 std::vector<StringRef> parts=str.split('-');
00057 assert(parts.size()==3);
00058 std::pair<bool, int> year=parts[0].to_int();
00059 std::pair<bool, int> month=parts[1].to_int();
00060 std::pair<bool, int> day=parts[2].to_int();
00061 assert(year.first); assert(month.first); assert(day.first);
00062 return Date(year.second, month.second, day.second);
00063 }
00064
00065 String ToString() const;
00066
00067 int year;
00068 int month;
00069 int day;
00070 };
00071
00072 struct DLLEXPORT_OST_CONOP AtomSpec {
00073 AtomSpec():
00074 ordinal(0),
00075 name(),
00076 alt_name(),
00077 element(),
00078 is_leaving(false),
00079 is_aromatic()
00080 {
00081 }
00082 AtomSpec(int o, const String& n, const String& a, const String& e,
00083 bool l, bool r):
00084 ordinal(o),
00085 name(n),
00086 alt_name(a),
00087 element(e),
00088 is_leaving(l),
00089 is_aromatic(r)
00090 {}
00091 int ordinal;
00092 String name;
00093 String alt_name;
00094 String element;
00095 bool is_leaving;
00096 bool is_aromatic;
00097 bool operator==(const AtomSpec& rhs) const {
00098 return ordinal==rhs.ordinal && name==rhs.name && alt_name==rhs.alt_name &&
00099 element==rhs.element && is_leaving==rhs.is_leaving &&
00100 is_aromatic==rhs.is_aromatic;
00101
00102 }
00103 bool operator!=(const AtomSpec& rhs) const {
00104 return !this->operator==(rhs);
00105 }
00106 };
00107
00108 struct DLLEXPORT_OST_CONOP BondSpec {
00109 BondSpec():
00110 atom_one(0),
00111 atom_two(0),
00112 order(1)
00113 {
00114 }
00115
00116 BondSpec(int a, int b, int o): atom_one(a), atom_two(b), order(o) {}
00117 bool operator==(const BondSpec& rhs) const {
00118 return atom_one==rhs.atom_one && atom_two==rhs.atom_two;
00119 }
00120
00121 bool operator!=(const BondSpec& rhs) const {
00122 return !this->operator==(rhs);
00123 }
00124 int atom_one;
00125 int atom_two;
00126 int order;
00127 };
00128
00129 typedef std::vector<AtomSpec> AtomSpecList;
00130 typedef std::vector<BondSpec> BondSpecList;
00131 class Compound;
00132 typedef boost::shared_ptr<Compound> CompoundPtr;
00133
00134
00136 class DLLEXPORT_OST_CONOP Compound {
00137 public:
00138 typedef enum {
00139 PDB ='P',
00140 CHARMM ='C',
00141 OPLS ='O',
00142 AMBER ='A',
00143 } Dialect;
00144
00145 Compound(const String& id):
00146 olc_('?'),
00147 tlc_(id),
00148 formula_(),
00149 name_(),
00150 inchi_(),
00151 inchi_key_(),
00152 atom_specs_(),
00153 bond_specs_(),
00154 chem_class_(),
00155 chem_type_(),
00156 dialect_(Compound::PDB),
00157 creation_date_(),
00158 mod_date_()
00159 {
00160 }
00161
00163 const String& GetID() const {
00164 return tlc_;
00165 }
00166 Dialect GetDialect() const { return dialect_; }
00167
00168 String GetDialectAsString() const {
00169 switch (dialect_) {
00170 case CHARMM:
00171 return "CHARMM";
00172 case PDB:
00173 return "PDB";
00174 case OPLS:
00175 return "OPLS";
00176 case AMBER:
00177 return "AMBER";
00178 default:
00179 return "";
00180 }
00181 }
00182 void SetDialect(Dialect dialect) { dialect_=dialect; }
00183
00184 void SetOneLetterCode(char olc) {
00185 olc_=olc;
00186 }
00187
00193 char GetOneLetterCode() const {
00194 return olc_;
00195 }
00196
00197 void SetChemClass(mol::ChemClass chem_class) {
00198 chem_class_=chem_class;
00199 }
00200
00201 mol::ChemClass GetChemClass() const {
00202 return chem_class_;
00203 }
00204
00205 void SetChemType(mol::ChemType chem_type) {
00206 chem_type_=chem_type;
00207 }
00208
00213 mol::ChemType GetChemType() const {
00214 return chem_type_;
00215 }
00216
00217 bool IsPeptideLinking() const {
00218 return chem_class_.IsPeptideLinking();
00219 }
00220
00221 bool IsNucleotideLinking() const {
00222 return chem_class_.IsNucleotideLinking();
00223 }
00224
00225 void AddAtom(const AtomSpec& atom) {
00226 atom_specs_.push_back(atom);
00227 }
00228
00229 void AddBond(const BondSpec& bond) {
00230 bond_specs_.push_back(bond);
00231 }
00232
00233 const AtomSpecList& GetAtomSpecs() const {
00234 return atom_specs_;
00235 }
00236
00237 int GetAtomSpecIndex(const String& name) const;
00238
00239 const String& GetName() { return name_; }
00240
00241 void SetName(const String& name) { name_=name; }
00242
00243 void SetFormula(const String& formula) { formula_=formula; }
00244
00245 const String& GetFormula() { return formula_; }
00246
00247 void SetInchi(const String& inchi) { inchi_=inchi; }
00248
00249 const String& GetInchi() { return inchi_; }
00250
00251 void SetInchiKey(const String& inchikey) { inchi_key_=inchikey; }
00252
00253 const String& GetInchiKey() { return inchi_key_; }
00254
00255 const BondSpecList& GetBondSpecs() const {
00256 return bond_specs_;
00257 }
00258 const Date& GetModificationDate() const
00259 {
00260 return mod_date_;
00261 }
00262 const Date& GetCreationDate() const
00263 {
00264 return creation_date_;
00265 }
00266
00267 void SetModificationDate(const Date& mod_date)
00268 {
00269 mod_date_=mod_date;
00270 }
00271
00272 void SetCreationDate(const Date& creation_date)
00273 {
00274 creation_date_=creation_date;
00275 }
00276 private:
00277 Compound();
00278 char olc_;
00279 String tlc_;
00280 String formula_;
00281 String name_;
00282 String inchi_;
00283 String inchi_key_;
00284 AtomSpecList atom_specs_;
00285 BondSpecList bond_specs_;
00286 mol::ChemClass chem_class_;
00287 mol::ChemType chem_type_;
00288 Dialect dialect_;
00289 Date creation_date_;
00290 Date mod_date_;
00291 };
00292
00293 typedef std::map<String, CompoundPtr> CompoundMap;
00294
00295 }}
00296
00297 #endif