Gemmi C++ API
Loading...
Searching...
No Matches
mmcif.hpp
Go to the documentation of this file.
1// Copyright 2017 Global Phasing Ltd.
2//
3// Read mmCIF (PDBx/mmCIF) file into a Structure from model.hpp.
4
5#ifndef GEMMI_MMCIF_HPP_
6#define GEMMI_MMCIF_HPP_
7
8#include <string>
9#include "cifdoc.hpp" // for Block, etc
10#include "fail.hpp" // for fail
11#include "model.hpp" // for Structure
12
13namespace gemmi {
14
17
20 // mmCIF files for deposition may have more than one block:
21 // coordinates in the first block and restraints in the others.
22 for (size_t i = 1; i < doc.blocks.size(); ++i)
23 if (doc.blocks[i].has_tag("_atom_site.id"))
24 fail("2+ blocks are ok if only the first one has coordinates;\n"
25 "_atom_site in block #" + std::to_string(i+1) + ": " + doc.source);
27 if (save_doc)
28 *save_doc = std::move(doc);
29 return st;
30}
31
32// Reading chemical component as a coordinate file.
33enum class ChemCompModel {
34 Xyz = 1, // _chem_comp_atom.x, etc
35 Example = 2, // _chem_comp_atom.model_Cartn_x
36 Ideal = 4 // _chem_comp_atom.pdbx_model_Cartn_x_ideal
37};
38
39constexpr int operator|(ChemCompModel a, ChemCompModel b) { return (int)a | (int)b; }
40
43
45 Model model;
46 model.chains.emplace_back("");
47 model.chains[0].residues.push_back(make_residue_from_chemcomp_block(block, kind));
48 return model;
49}
50
51// For CCD input - returns a structure with two single-residue models:
52// example (model_Cartn_x) and ideal (pdbx_model_Cartn_x_ideal).
53// For Refmac dictionary (monomer library) files returns structure with
54// a single model.
57 st.input_format = CoorFormat::ChemComp;
58 if (const std::string* name = block.find_value("_chem_comp.id"))
59 st.name = *name;
60 auto ok = [which](ChemCompModel x) { return which & static_cast<int>(x); };
61 if (ok(ChemCompModel::Xyz) && block.has_any_value("_chem_comp_atom.x"))
63 if (ok(ChemCompModel::Example) && block.has_any_value("_chem_comp_atom.model_Cartn_x"))
65 if (ok(ChemCompModel::Ideal) && block.has_any_value("_chem_comp_atom.pdbx_model_Cartn_x_ideal"))
67 st.renumber_models();
68 return st;
69}
70
71// a helper function for use with make_structure_from_chemcomp_block():
72// int n = check_chemcomp_block_number(doc);
73// if (n != -1)
74// Structure st = make_structure_from_chemcomp_block(doc.blocks[n]);
76 // monomer library file without global_
77 if (doc.blocks.size() == 2 && doc.blocks[0].name == "comp_list")
78 return 1;
79 // monomer library file with global_
80 if (doc.blocks.size() == 3 && doc.blocks[0].name.empty() &&
81 doc.blocks[1].name == "comp_list")
82 return 2;
83 // CCD file
84 if (doc.blocks.size() == 1 &&
85 !doc.blocks[0].has_tag("_atom_site.id") &&
86 !doc.blocks[0].has_tag("_cell.length_a") &&
87 doc.blocks[0].has_tag("_chem_comp_atom.atom_id"))
88 return 0;
89 return -1;
90}
91
93 cif::Document* save_doc=nullptr,
94 int which=7) {
96 if (n == -1)
97 fail("Not a chem_comp format.");
99 if (save_doc)
100 *save_doc = std::move(doc);
101 return st;
102}
103
104} // namespace gemmi
105#endif
struct Document that represents the CIF file (but can also be read from a different representation,...
fail(), unreachable() and __declspec/__attribute__ macros
#define GEMMI_DLL
Definition fail.hpp:53
Data structures to store macromolecular structure models.
Structure make_structure_from_chemcomp_block(const cif::Block &block, int which=7)
Definition mmcif.hpp:55
Model make_model_from_chemcomp_block(const cif::Block &block, ChemCompModel kind)
Definition mmcif.hpp:44
Structure make_structure(cif::Document &&doc, cif::Document *save_doc=nullptr)
structure from a coordinate mmCIF document
Definition mmcif.hpp:19
ChemCompModel
Definition mmcif.hpp:33
int check_chemcomp_block_number(const cif::Document &doc)
Definition mmcif.hpp:75
GEMMI_DLL Structure make_structure_from_block(const cif::Block &block)
structure from a coordinate mmCIF block
constexpr int operator|(ChemCompModel a, ChemCompModel b)
Definition mmcif.hpp:39
void fail(const std::string &msg)
Definition fail.hpp:59
GEMMI_DLL Residue make_residue_from_chemcomp_block(const cif::Block &block, ChemCompModel kind)
make_residue_from_chemcomp_block
Structure make_structure_from_chemcomp_doc(const cif::Document &doc, cif::Document *save_doc=nullptr, int which=7)
Definition mmcif.hpp:92
std::vector< Chain > chains
Definition model.hpp:722
const std::string * find_value(const std::string &tag) const
Definition cifdoc.hpp:841
bool has_any_value(const std::string &tag) const
Definition cifdoc.hpp:467