OpenStructure
mmcif_writer.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-2024 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_MMCIF_WRITER_HH
20 #define OST_IO_MMCIF_WRITER_HH
21 
22 #include <fstream>
23 
24 #include <ost/mol/entity_handle.hh>
26 
27 #include <ost/io/mol/mmcif_info.hh>
28 #include <ost/io/mol/io_profile.hh>
30 
31 namespace ost { namespace io {
32 
33 // generates as many chain names as you want (potentially multiple characters)
34 struct ChainNameGenerator{
36 
38 
39  void Reset();
40 
42  int n_chain_names;
43  std::vector<int> indices;
44 };
45 
46 struct MMCifWriterEntity {
47 
49 
50  static MMCifWriterEntity FromPolymer(const String& entity_poly_type,
51  const std::vector<String>& mon_ids,
53 
54  int GetAsymIdx(const String& asym_id) const;
55 
56  void AddHet(int rnum, const String& mon_id) {
57  het[rnum].push_back(mon_id);
58  }
59 
60  bool operator==(const MMCifWriterEntity& rhs) const {
61  return (type == rhs.type)
62  && (poly_type == rhs.poly_type)
63  && (branch_type == rhs.branch_type)
64  && (asym_ids == rhs.asym_ids)
65  && (is_poly == rhs.is_poly)
66  && (mon_ids == rhs.mon_ids)
67  && (seq_olcs == rhs.seq_olcs)
68  && (seq_can_olcs == rhs.seq_can_olcs)
69  && (asym_alns == rhs.asym_alns);
70  }
71 
72  bool operator!=(const MMCifWriterEntity& rhs) const {
73  return !(*this == rhs);
74  }
75 
76  // _entity.type
77  String type;
78 
79  // _entity_poly.type
81 
82  // __pdbx_entity_branch.type
84 
85  // Names of chains in AU that are assigned to this entity
86  std::vector<String> asym_ids;
87 
88  // in principle type == "polymer"
89  bool is_poly;
90 
91  // SEQRES... kind of... internally we're not working on one letter codes
92  // etc. but on full compound names. Only one element if is_poly is false.
93  std::vector<String> mon_ids;
94 
95  // The respective strings for pdbx_seq_one_letter_code
96  // Irrelevant if is_poly is false.
97  std::vector<String> seq_olcs;
98 
99  // same for pdbx_seq_one_letter_code_can
100  // Irrelevant if is_poly is false.
101  std::vector<String> seq_can_olcs;
102 
103  // One alignment to mon_ids for each element in asym_ids, i.e. SEQRES-ATOMSEQ
104  // alignment. Contains "-" for residues that are missing in ATOMSEQ.
105  // irrelevant if is_poly is false. The assumption is that aligned residues
106  // exactly match with the respective position in mon_ids.
107  std::map<String, std::vector<String> > asym_alns;
108 
109  // heterogeneities
110  std::map<int, std::vector<String> > het;
111 };
112 
113 class DLLEXPORT_OST_IO MMCifWriter : public StarWriter {
114 public:
115 
116  MMCifWriter(): structure_set_(false) { }
117 
118  virtual ~MMCifWriter() { }
119 
121  bool mmcif_conform=true,
122  const std::vector<MMCifWriterEntity>& entity_info=std::vector<MMCifWriterEntity>());
123 
125  bool mmcif_conform=true,
126  const std::vector<MMCifWriterEntity>& entity_info=std::vector<MMCifWriterEntity>());
127 
128  const std::vector<MMCifWriterEntity>& GetEntities() const { return entity_info_; }
129 
130 private:
131 
132  void Setup();
133 
135 
136  std::vector<MMCifWriterEntity> entity_info_;
137  StarWriterLoopPtr atom_type_;
138  StarWriterLoopPtr atom_site_;
139  StarWriterLoopPtr pdbx_poly_seq_scheme_;
140  StarWriterLoopPtr entity_;
141  StarWriterLoopPtr struct_asym_;
142  StarWriterLoopPtr entity_poly_;
143  StarWriterLoopPtr entity_poly_seq_;
144  StarWriterLoopPtr chem_comp_;
145  StarWriterLoopPtr pdbx_entity_branch_;
146  bool structure_set_;
147 };
148 
149 }} // ns
150 
151 #endif
void SetStructure(const ost::mol::EntityHandle &ent, conop::CompoundLibPtr compound_lib, bool mmcif_conform=true, const std::vector< MMCifWriterEntity > &entity_info=std::vector< MMCifWriterEntity >())
const std::vector< MMCifWriterEntity > & GetEntities() const
void SetStructure(const ost::mol::EntityView &ent, conop::CompoundLibPtr compound_lib, bool mmcif_conform=true, const std::vector< MMCifWriterEntity > &entity_info=std::vector< MMCifWriterEntity >())
Protein or molecule.
definition of EntityView
Definition: entity_view.hh:86
#define DLLEXPORT_OST_IO
std::string String
Definition: base.hh:54
boost::shared_ptr< CompoundLib > CompoundLibPtr
Definition: compound_lib.hh:32
boost::shared_ptr< StarWriterLoop > StarWriterLoopPtr
Definition: star_writer.hh:79
Definition: base.dox:1
std::vector< int > indices
Definition: mmcif_writer.hh:43
std::vector< String > asym_ids
Definition: mmcif_writer.hh:86
void AddHet(int rnum, const String &mon_id)
Definition: mmcif_writer.hh:56
std::vector< String > seq_olcs
Definition: mmcif_writer.hh:97
int GetAsymIdx(const String &asym_id) const
std::map< int, std::vector< String > > het
std::map< String, std::vector< String > > asym_alns
bool operator==(const MMCifWriterEntity &rhs) const
Definition: mmcif_writer.hh:60
static MMCifWriterEntity FromPolymer(const String &entity_poly_type, const std::vector< String > &mon_ids, conop::CompoundLibPtr compound_lib)
bool operator!=(const MMCifWriterEntity &rhs) const
Definition: mmcif_writer.hh:72
std::vector< String > mon_ids
Definition: mmcif_writer.hh:93
std::vector< String > seq_can_olcs