Gemmi C++ API
Loading...
Searching...
No Matches
interop.hpp
Go to the documentation of this file.
1// Copyright 2020 Global Phasing Ltd.
2//
3// Interoperability between Model (MX) and SmallStructure (SX).
4
5#ifndef GEMMI_INTEROP_HPP_
6#define GEMMI_INTEROP_HPP_
7
8#include "model.hpp"
9#include "small.hpp"
10
11namespace gemmi {
12
13inline SmallStructure::Site atom_to_site(const Atom& atom, const UnitCell& cell) {
15 site.label = atom.name;
16 site.type_symbol = atom.element.name();
17 site.fract = cell.fractionalize(atom.pos);
18 site.occ = atom.occ;
19 // occupancy may need to be adjusted if the atom is on special position
20 if (atom.occ <= 0.5) {
21 int n_mates = cell.is_special_position(atom.pos);
22 if (n_mates > 0 && atom.occ * (n_mates + 1) <= 1.0)
23 site.occ = atom.occ * (n_mates + 1);
24 }
25 site.u_iso = atom.b_iso / u_to_b();
26 if (atom.aniso.nonzero()) {
27 if (cell.alpha == 90. || cell.beta == 90. || cell.gamma == 90.) {
28 site.aniso = atom.aniso.scaled(1.0);
29 } else {
31 Vec3 v = {1.0 / cell.ar, 1.0 / cell.br, 1.0 / cell.cr};
32 site.aniso = {t.u11 * v.x * v.x,
33 t.u22 * v.y * v.y,
34 t.u33 * v.z * v.z,
35 t.u12 * v.x * v.y,
36 t.u13 * v.x * v.z,
37 t.u23 * v.y * v.z};
38 }
39 }
40 site.element = atom.element;
41 site.charge = atom.charge;
42 return site;
43}
44
46 const Model& model = st.models.at(n);
48 small_st.name = st.name;
49 small_st.cell = st.cell;
50 small_st.spacegroup_hm = st.spacegroup_hm;
51 for (const Chain& chain : model.chains)
52 for (const Residue& residue : chain.residues)
53 for (const Atom& atom : residue.atoms)
54 small_st.sites.push_back(atom_to_site(atom, st.cell));
55 return small_st;
56}
57
58} // namespace gemmi
59#endif
SmallStructure mx_to_sx_structure(const Structure &st, int n=0)
Definition interop.hpp:45
Vec3_< double > Vec3
Definition math.hpp:101
SmallStructure::Site atom_to_site(const Atom &atom, const UnitCell &cell)
Definition interop.hpp:13
constexpr double u_to_b()
Definition math.hpp:29
Represents atom site in macromolecular structure (~100 bytes).
Definition model.hpp:112
SMat33< float > aniso
Definition model.hpp:127
signed char charge
Definition model.hpp:116
float b_iso
Definition model.hpp:126
Element element
Definition model.hpp:117
float occ
Definition model.hpp:124
Position pos
Definition model.hpp:123
std::string name
Definition model.hpp:114
const char * name() const
Definition elem.hpp:309
std::vector< Chain > chains
Definition model.hpp:700
SMat33< Real > scaled(Real s) const
Definition math.hpp:284
bool nonzero() const
Definition math.hpp:273
SMat33< Real > transformed_by(const Mat33 &m) const
Definition math.hpp:319
Unit cell.
Definition unitcell.hpp:139
Transform frac
Definition unitcell.hpp:151
double ar
reciprocal parameters a*, b*, c*, alpha*, beta*, gamma*
Definition unitcell.hpp:154
Fractional fractionalize(const Position &o) const
Definition unitcell.hpp:374
int is_special_position(const Fractional &fpos, double max_dist) const
Counts nearby symmetry mates (0 = none, 3 = 4-fold axis, etc).
Definition unitcell.hpp:503