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 <boost/shared_ptr.hpp>
00024 #include <ost/string_ref.hh>
00025 #include <ost/conop/module_config.hh>
00026
00027 #include <ost/mol/chem_class.hh>
00028
00029 namespace ost { namespace conop {
00030
00031 struct Date {
00032 Date(int y, int m, int d):
00033 year(y), month(m), day(d)
00034 { }
00035 Date():
00036 year(1900), month(1), day(1)
00037 { }
00038 bool operator<(const Date& date) const
00039 {
00040 return year<date.year && month<date.month && day<date.day;
00041 }
00042 bool operator==(const Date& date) const
00043 {
00044 return year==date.year && month==date.month && day==date.day;
00045 }
00046
00047 bool operator!=(const Date& date) const
00048 {
00049 return !this->operator==(date);
00050 }
00051
00052 static Date FromString(const StringRef& str)
00053 {
00054 assert(str[4]=='-');
00055 assert(str[7]=='-');
00056 std::pair<bool, int> year=str.substr(0,4).to_int();
00057 std::pair<bool, int> month=str.substr(5,2).to_int();
00058 std::pair<bool, int> day=str.substr(8, 2).to_int();
00059 assert(year.first); assert(month.first); assert(day.first);
00060 return Date(year.second, month.second, day.second);
00061 }
00062
00063 int year;
00064 int month;
00065 int day;
00066 };
00067
00068 struct AtomSpec {
00069 AtomSpec()
00070 : ordinal(0), is_leaving(false) {
00071 }
00072 int ordinal;
00073 String name;
00074 String alt_name;
00075 String element;
00076 bool is_leaving;
00077 bool is_aromatic;
00078 bool operator==(const AtomSpec& rhs) const {
00079 return ordinal==rhs.ordinal && name==rhs.name && alt_name==rhs.alt_name &&
00080 element==rhs.element && is_leaving==rhs.is_leaving &&
00081 rhs.is_aromatic==rhs.is_aromatic;
00082 }
00083 bool operator!=(const AtomSpec& rhs) const {
00084 return !this->operator==(rhs);
00085 }
00086 };
00087
00088 struct BondSpec {
00089 BondSpec()
00090 : atom_one(0), atom_two(0), order(1) {
00091
00092 }
00093
00094 bool operator==(const BondSpec& rhs) const {
00095 return atom_one==rhs.atom_one && atom_two==rhs.atom_two;
00096 }
00097
00098 bool operator!=(const BondSpec& rhs) const {
00099 return !this->operator==(rhs);
00100 }
00101 int atom_one;
00102 int atom_two;
00103 int order;
00104 };
00105
00106 typedef std::vector<AtomSpec> AtomSpecList;
00107 typedef std::vector<BondSpec> BondSpecList;
00108 class Compound;
00109 typedef boost::shared_ptr<Compound> CompoundPtr;
00110
00111
00113 class DLLEXPORT_OST_CONOP Compound {
00114 public:
00115 Compound(const String& id)
00116 : olc_('?'), tlc_(id), chem_class_() {
00117 }
00118
00120 const String& GetID() const {
00121 return tlc_;
00122 }
00123
00124 void SetOneLetterCode(char olc) {
00125 olc_=olc;
00126 }
00127
00133 char GetOneLetterCode() const {
00134 return olc_;
00135 }
00136
00137 void SetChemClass(mol::ChemClass chem_class) {
00138 chem_class_=chem_class;
00139 }
00140
00141 mol::ChemClass GetChemClass() const {
00142 return chem_class_;
00143 }
00144
00145 bool IsPeptideLinking() const {
00146 return chem_class_.IsPeptideLinking();
00147 }
00148 void AddAtom(const AtomSpec& atom) {
00149 atom_specs_.push_back(atom);
00150 }
00151
00152 void AddBond(const BondSpec& bond) {
00153 bond_specs_.push_back(bond);
00154 }
00155
00156 const AtomSpecList& GetAtomSpecs() const {
00157 return atom_specs_;
00158 }
00159
00160 int GetAtomSpecIndex(const String& name) const;
00161
00162 const String& GetFormula() { return formula_; }
00163
00164 void SetFormula(const String& formula) { formula_=formula; }
00165
00166 const BondSpecList& GetBondSpecs() const {
00167 return bond_specs_;
00168 }
00169 const Date& GetModificationDate() const
00170 {
00171 return mod_date_;
00172 }
00173 const Date& GetCreationDate() const
00174 {
00175 return creation_date_;
00176 }
00177
00178 void SetModificationDate(const Date& mod_date)
00179 {
00180 mod_date_=mod_date;
00181 }
00182
00183 void SetCreationDate(const Date& creation_date)
00184 {
00185 creation_date_=creation_date;
00186 }
00187 private:
00188 Compound();
00189 char olc_;
00190 String tlc_;
00191 String formula_;
00192 AtomSpecList atom_specs_;
00193 BondSpecList bond_specs_;
00194 mol::ChemClass chem_class_;
00195 Date creation_date_;
00196 Date mod_date_;
00197 };
00198
00199 }}
00200
00201 #endif