OpenStructure
Loading...
Searching...
No Matches
omf.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_IO_OMF_HH
20#define OST_IO_OMF_HH
21
22#include <unordered_map>
23#include <unordered_set>
24#include <fstream>
25#include <boost/iostreams/filtering_stream.hpp>
27#include <ost/geom/mat4.hh>
29#include <ost/io/mmcif_info.hh>
30
31namespace ost { namespace io {
32
33const int OMF_VERSION = 3;
34
35class ChainData;
36class OMF;
37typedef boost::shared_ptr<OMF> OMFPtr;
38typedef boost::shared_ptr<ChainData> ChainDataPtr;
39
40struct SidechainAtomRule {
42 int anchor_idx[3];
44 Real angle;
45 // 0: chi1, 1: chi2, 2: chi3, 3: chi4, 4: 0.0
46 int dihedral_idx;
47 // the value of the dihedral above will be added to base_dihedral to get
48 // the final diheral angle. If you want to have the effect of chi3 + M_PI
49 // you define dihedral_idx as 2 and base_dihedral = M_PI.
51};
52
53struct ChiDefinition{
54 int idx_one;
55 int idx_two;
56 int idx_three;
57 int idx_four;
58};
59
60struct ResidueDefinition {
61
63
65
66 bool operator==(const ResidueDefinition& other) const {
67 return (name == other.name &&
68 olc == other.olc &&
69 chem_type == other.chem_type &&
70 chem_class == other.chem_class &&
71 anames == other.anames &&
72 elements == other.elements &&
73 is_hetatm == other.is_hetatm &&
74 bonds == other.bonds &&
75 bond_orders == other.bond_orders);
76 }
77
78 bool operator!=(const ResidueDefinition& other) const {
79 return !(*this == other);
80 }
81
82 void ToStream(std::ostream& stream) const;
83
84 void FromStream(std::istream& stream);
85
86 int GetIdx(const String& aname) const;
87
88 const std::set<int>& GetRotamericAtoms() const;
89
90 const std::vector<ChiDefinition>& GetChiDefinitions() const;
91
92 const std::vector<SidechainAtomRule>& GetSidechainAtomRules() const;
93
94 int GetNChiAngles() const;
95
96 void _InitIdxMapper() const;
97
98 void _AddChiDefinition(int idx_one, int idx_two, int idx_three,
99 int idx_four);
100
101 void _AddAtomRule(int a_idx, int anch_one_idx,
102 int anch_two_idx, int anch_three_idx,
103 Real bond_length, Real angle, int dihedral_idx,
104 Real base_dihedral);
105
106 String name;
107 char olc;
108 char chem_type;
109 char chem_class;
110 std::vector<String> anames;
111 std::vector<String> elements;
112 std::vector<bool> is_hetatm;
113 std::vector<int> bonds;
114 std::vector<int> bond_orders;
115 mutable std::map<String, int> idx_mapper;
116 std::set<int> rotameric_atoms;
117 std::vector<ChiDefinition> chi_definitions;
118 std::vector<SidechainAtomRule> sidechain_atom_rules;
119 std::set<int> critical_sidechain_angles;
120};
121
122struct ChainData {
123
124 ChainData(): ch_name(""), chain_type(ost::mol::CHAINTYPE_UNKNOWN) { }
125
127 const std::vector<ResidueDefinition>& residue_definitions,
128 const std::unordered_map<unsigned long, int>& res_idx_map,
129 const std::vector<std::pair<unsigned long, unsigned long> >&
130 inter_residue_bonds,
131 const std::vector<int>& inter_residue_bond_orders,
132 std::unordered_map<long, int>& atom_idx_mapper);
133
134 void ToStream(std::ostream& stream,
135 const std::vector<ResidueDefinition>& res_def,
136 Real max_error, bool avg_bfactors, bool round_bfactors,
137 bool skip_ss) const;
138
139 void FromStream(std::istream& stream,
140 const std::vector<ResidueDefinition>& res_def,
141 int version, Real max_error, bool avg_bfactors,
142 bool round_bfactors, bool skip_ss);
143
144 // chain features
147
148 // residue features
149 std::vector<int> res_def_indices;
150 std::vector<int> rnums;
151 std::vector<char> insertion_codes;
152 std::vector<char> sec_structures;
153
154 // atom features
155 std::vector<Real> occupancies;
156 std::vector<Real> bfactors;
158
159 // bond features - only for bonds that are inter-residue
160 // e.g. peptide bonds
161 std::vector<int> bonds;
162 std::vector<int> bond_orders;
163};
164
165
166class DefaultPepLib{
167public:
169 static DefaultPepLib instance;
170 return instance;
171 }
172 std::vector<ResidueDefinition> residue_definitions;
173
174private:
176 DefaultPepLib(DefaultPepLib const& copy);
177 DefaultPepLib& operator=(DefaultPepLib const& copy);
178};
179
180class OMF {
181
182public:
183
186
187 bool OptionSet(OMFOption opt) const {
188 return (opt & options_) == opt;
189 }
190
192 Real max_error = 0.0,
193 uint8_t options = 0);
194
195 static OMFPtr FromFile(const String& fn);
196
197 static OMFPtr FromString(const String& s);
198
199 void ToFile(const String& fn) const;
200
202
204
206 return this->GetAU();
207 }
208
210
212 return this->GetAUChain(name);
213 }
214
215 OMFPtr ToAssembly(const std::vector<std::vector<String> >& au_chains,
216 const std::vector<std::vector<geom::Mat4> >& transformations,
217 const std::vector<std::vector<std::vector<String> > >& bu_chains) const;
218
219 void Trace(const String& cname, const String& aname,
220 std::vector<int>& rnums, geom::Vec3List& pos) const;
221
222 int GetVersion() const { return version_; }
223
224 static int GetCurrentOMFVersion() { return OMF_VERSION; }
225
226 Real GetMaxError() const { return 0.001 * max_error_; }
227
228 // data access without requirement of generating a full
229 // OpenStructure entity
230
231 String GetName() const { return name_; }
232
233 std::vector<String> GetChainNames() const;
234
235 const geom::Vec3List& GetPositions(const String& cname) const;
236
237 const std::vector<Real>& GetBFactors(const String& cname) const;
238
239 std::vector<Real> GetAvgBFactors(const String& cname) const;
240
241 const std::vector<Real>& GetOccupancies(const String& cname) const;
242
243 String GetSequence(const String& cname) const;
244
245 const std::vector<int>& GetRNums(const String& cname) const;
246
247 // raw data access - pros only...
248 const std::vector<ResidueDefinition>& GetResidueDefinitions() const {
249 return residue_definitions_;
250 }
251
252 ChainDataPtr GetChainData(const std::string& cname) const {
253 return chain_data_.at(cname);
254 }
255
256private:
257 // only construct with static functions
258 OMF(): options_(0) { }
259
260 void ToStream(std::ostream& stream) const;
261
262 void FromStream(std::istream& stream);
263
264 void FillChain(const ChainDataPtr data, ost::mol::XCSEditor& ed,
265 ost::mol::ChainHandle& chain) const;
266
267 String name_;
268 uint16_t max_error_;
269 std::vector<ResidueDefinition> residue_definitions_;
270 std::map<String, ChainDataPtr> chain_data_;
271
272 // bond features - only for bonds that are inter-chain
273 // given n bonds, bond_chain_names_ and bond_atoms_ have length 2*n and are
274 // organized as follows:
275 // [bond1_at1_x, bond1_at2_x, ..., bondn_at1_x, bondn_at2_x]
276 // bond_orders_ on the other hand has length n
277 std::vector<String> bond_chain_names_;
278 std::vector<int> bond_atoms_;
279 std::vector<int> bond_orders_;
280
281 // bitfield with options
282 uint8_t options_;
283
284 int version_;
285};
286
287}} //ns
288
289#endif
std::vector< ResidueDefinition > residue_definitions
Definition omf.hh:172
static DefaultPepLib & Instance()
Definition omf.hh:168
ost::mol::EntityHandle GetAUChain(const String &name) const
static OMFPtr FromFile(const String &fn)
const std::vector< Real > & GetBFactors(const String &cname) const
OMFPtr ToAssembly(const std::vector< std::vector< String > > &au_chains, const std::vector< std::vector< geom::Mat4 > > &transformations, const std::vector< std::vector< std::vector< String > > > &bu_chains) const
static OMFPtr FromEntity(const ost::mol::EntityHandle &ent, Real max_error=0.0, uint8_t options=0)
bool OptionSet(OMFOption opt) const
Definition omf.hh:187
String GetName() const
Definition omf.hh:231
const std::vector< ResidueDefinition > & GetResidueDefinitions() const
Definition omf.hh:248
ost::mol::EntityHandle GetEntity() const
Definition omf.hh:205
std::vector< String > GetChainNames() const
ost::mol::EntityHandle GetAU() const
ChainDataPtr GetChainData(const std::string &cname) const
Definition omf.hh:252
const geom::Vec3List & GetPositions(const String &cname) const
Real GetMaxError() const
Definition omf.hh:226
const std::vector< Real > & GetOccupancies(const String &cname) const
std::vector< Real > GetAvgBFactors(const String &cname) const
String ToString() const
static int GetCurrentOMFVersion()
Definition omf.hh:224
int GetVersion() const
Definition omf.hh:222
@ ROUND_BFACTORS
Definition omf.hh:184
@ DEFAULT_PEPLIB
Definition omf.hh:184
@ INFER_PEP_BONDS
Definition omf.hh:185
@ AVG_BFACTORS
Definition omf.hh:184
const std::vector< int > & GetRNums(const String &cname) const
void Trace(const String &cname, const String &aname, std::vector< int > &rnums, geom::Vec3List &pos) const
String GetSequence(const String &cname) const
void ToFile(const String &fn) const
ost::mol::EntityHandle GetEntityChain(const String &name) const
Definition omf.hh:211
static OMFPtr FromString(const String &s)
linear chain of residues
Protein or molecule.
external coordinate system editor
Definition xcs_editor.hh:36
float Real
Definition base.hh:44
std::string String
Definition base.hh:54
boost::shared_ptr< ChainData > ChainDataPtr
Definition omf.hh:38
const int OMF_VERSION
Definition omf.hh:33
boost::shared_ptr< OMF > OMFPtr
Definition omf.hh:37
Definition base.dox:1
unsigned short uint16_t
Definition stdint_msc.hh:79
unsigned char uint8_t
Definition stdint_msc.hh:78
std::vector< int > bond_orders
Definition omf.hh:162
ChainData(const ost::mol::ChainHandle &chain, const std::vector< ResidueDefinition > &residue_definitions, const std::unordered_map< unsigned long, int > &res_idx_map, const std::vector< std::pair< unsigned long, unsigned long > > &inter_residue_bonds, const std::vector< int > &inter_residue_bond_orders, std::unordered_map< long, int > &atom_idx_mapper)
std::vector< int > res_def_indices
Definition omf.hh:149
std::vector< int > rnums
Definition omf.hh:150
ost::mol::ChainType chain_type
Definition omf.hh:146
String ch_name
Definition omf.hh:145
void FromStream(std::istream &stream, const std::vector< ResidueDefinition > &res_def, int version, Real max_error, bool avg_bfactors, bool round_bfactors, bool skip_ss)
std::vector< char > insertion_codes
Definition omf.hh:151
std::vector< int > bonds
Definition omf.hh:161
geom::Vec3List positions
Definition omf.hh:157
std::vector< char > sec_structures
Definition omf.hh:152
void ToStream(std::ostream &stream, const std::vector< ResidueDefinition > &res_def, Real max_error, bool avg_bfactors, bool round_bfactors, bool skip_ss) const
std::vector< Real > occupancies
Definition omf.hh:155
std::vector< Real > bfactors
Definition omf.hh:156
std::vector< int > bond_orders
Definition omf.hh:114
std::vector< String > anames
Definition omf.hh:110
bool operator==(const ResidueDefinition &other) const
Definition omf.hh:66
ResidueDefinition(const ost::mol::ResidueHandle &res)
const std::set< int > & GetRotamericAtoms() const
int GetIdx(const String &aname) const
void _AddChiDefinition(int idx_one, int idx_two, int idx_three, int idx_four)
std::vector< SidechainAtomRule > sidechain_atom_rules
Definition omf.hh:118
const std::vector< ChiDefinition > & GetChiDefinitions() const
std::set< int > rotameric_atoms
Definition omf.hh:116
void ToStream(std::ostream &stream) const
std::set< int > critical_sidechain_angles
Definition omf.hh:119
void FromStream(std::istream &stream)
std::vector< int > bonds
Definition omf.hh:113
void _AddAtomRule(int a_idx, int anch_one_idx, int anch_two_idx, int anch_three_idx, Real bond_length, Real angle, int dihedral_idx, Real base_dihedral)
std::vector< ChiDefinition > chi_definitions
Definition omf.hh:117
bool operator!=(const ResidueDefinition &other) const
Definition omf.hh:78
std::vector< bool > is_hetatm
Definition omf.hh:112
std::vector< String > elements
Definition omf.hh:111
std::map< String, int > idx_mapper
Definition omf.hh:115
const std::vector< SidechainAtomRule > & GetSidechainAtomRules() const