Gemmi C++ API
Loading...
Searching...
No Matches
assembly.hpp
Go to the documentation of this file.
1// Copyright 2020 Global Phasing Ltd.
2//
3// Generating biological assemblies by applying operations
4// from struct Assembly to a Model.
5// Includes chain (re)naming utilities.
6
7#ifndef GEMMI_ASSEMBLY_HPP_
8#define GEMMI_ASSEMBLY_HPP_
9
10#include "model.hpp" // for Model
11#include "util.hpp" // for in_vector
12#include "logger.hpp" // for Logger
13
14namespace gemmi {
15
17
20 std::vector<std::string> used_names;
21
23 ChainNameGenerator(const Model& model, HowToNameCopiedChain how_) : how(how_) {
25 for (const Chain& chain : model.chains)
26 used_names.push_back(chain.name);
27 }
28 bool try_add(const std::string& name) {
29 if (in_vector(name, used_names))
30 return false;
31 used_names.push_back(name);
32 return true;
33 }
34 std::string make_short_name(const std::string& preferred) {
35 static const char symbols[] = {
36 'A','B','C','D','E','F','G','H','I','J','K','L','M',
37 'N','O','P','Q','R','S','T','U','V','W','X','Y','Z',
38 'a','b','c','d','e','f','g','h','i','j','k','l','m',
39 'n','o','p','q','r','s','t','u','v','w','x','y','z',
40 '0','1','2','3','4','5','6','7','8','9'
41 };
42 if (try_add(preferred))
43 return preferred;
44 std::string name(1, 'A');
45 for (char symbol : symbols) {
46 name[0] = symbol;
47 if (try_add(name))
48 return name;
49 }
50 name += 'A';
51 for (char symbol1 : symbols) {
52 name[0] = symbol1;
53 for (char symbol2 : symbols) {
54 name[1] = symbol2;
55 if (try_add(name))
56 return name;
57 }
58 }
59 fail("run out of 1- and 2-letter chain names");
60 }
61
62 std::string make_name_with_numeric_postfix(const std::string& base, int n) {
63 std::string name = base;
64 name += std::to_string(n);
65 while (!try_add(name)) {
66 name.resize(base.size());
67 name += std::to_string(++n);
68 }
69 return name;
70 }
71
72 std::string make_new_name(const std::string& old, int n) {
73 switch (how) {
76 case HowToNameCopiedChain::Dup: return old;
77 }
79 }
80};
81
82inline void ensure_unique_chain_name(const Model& model, Chain& chain) {
84 for (const Chain& ch : model.chains)
85 if (&ch != &chain)
86 namegen.try_add(ch.name);
87 chain.name = namegen.make_short_name(chain.name);
88}
89
90GEMMI_DLL Model make_assembly(const Assembly& assembly, const Model& model,
91 HowToNameCopiedChain how, const Logger& logging);
92
94 Assembly assembly("unit_cell");
95 std::vector<Assembly::Operator> operators(cell.images.size() + 1);
96 // operators[0] stays as identity
97 for (size_t i = 1; i != operators.size(); ++i) {
98 const FTransform& op = cell.images[i-1];
99 operators[i].transform = cell.orth.combine(op.combine(cell.frac));
100 }
101 assembly.generators.push_back({{"(all)"}, {}, operators});
102 return assembly;
103}
104
107GEMMI_DLL void transform_to_assembly(Structure& st, const std::string& assembly_name,
108 HowToNameCopiedChain how, const Logger& logging,
109 bool keep_spacegroup=false, double merge_dist=0.2);
110
111
112GEMMI_DLL Model expand_ncs_model(const Model& model, const std::vector<NcsOp>& ncs,
114
118 double max_dist=0.2, bool compare_serial=true);
119
120
122
123GEMMI_DLL void expand_ncs(Structure& st, HowToNameCopiedChain how, double merge_dist=0.2);
124
127
128} // namespace gemmi
129#endif
#define GEMMI_DLL
Definition fail.hpp:53
Logger - a tiny utility for passing messages through a callback.
Data structures to store macromolecular structure models.
GEMMI_DLL Model make_assembly(const Assembly &assembly, const Model &model, HowToNameCopiedChain how, const Logger &logging)
GEMMI_DLL Model expand_ncs_model(const Model &model, const std::vector< NcsOp > &ncs, HowToNameCopiedChain how)
HowToNameCopiedChain
Definition assembly.hpp:16
GEMMI_DLL void merge_atoms_in_expanded_model(Model &model, const UnitCell &cell, double max_dist=0.2, bool compare_serial=true)
Searches and merges overlapping equivalent atoms from different chains.
GEMMI_DLL void shorten_chain_names(Structure &st)
GEMMI_DLL void transform_to_assembly(Structure &st, const std::string &assembly_name, HowToNameCopiedChain how, const Logger &logging, bool keep_spacegroup=false, double merge_dist=0.2)
If called with assembly_name="unit_cell" changes structure to unit cell (P1).
bool in_vector(const T &x, const std::vector< T > &v)
Definition util.hpp:242
GEMMI_DLL void expand_ncs(Structure &st, HowToNameCopiedChain how, double merge_dist=0.2)
GEMMI_DLL void split_chains_by_segments(Model &model, HowToNameCopiedChain how)
HowToNameCopiedChain::Dup adds segment name to chain name.
void fail(const std::string &msg)
Definition fail.hpp:59
void ensure_unique_chain_name(const Model &model, Chain &chain)
Definition assembly.hpp:82
void unreachable()
Definition fail.hpp:80
Assembly pseudo_assembly_for_unit_cell(const UnitCell &cell)
Definition assembly.hpp:93
std::vector< Gen > generators
Definition metadata.hpp:383
std::string make_name_with_numeric_postfix(const std::string &base, int n)
Definition assembly.hpp:62
std::string make_new_name(const std::string &old, int n)
Definition assembly.hpp:72
HowToNameCopiedChain how
Definition assembly.hpp:19
std::string make_short_name(const std::string &preferred)
Definition assembly.hpp:34
ChainNameGenerator(HowToNameCopiedChain how_)
Definition assembly.hpp:22
ChainNameGenerator(const Model &model, HowToNameCopiedChain how_)
Definition assembly.hpp:23
std::vector< std::string > used_names
Definition assembly.hpp:20
bool try_add(const std::string &name)
Definition assembly.hpp:28
std::string name
Definition model.hpp:485
Like Transform, but apply() arg is Fractional (not Vec3 - for type safety).
Definition unitcell.hpp:112
Passes messages (including warnings/errors) to a callback function.
Definition logger.hpp:23
std::vector< Chain > chains
Definition model.hpp:722
Transform combine(const Transform &b) const
Definition math.hpp:404
Unit cell.
Definition unitcell.hpp:165
Transform frac
Definition unitcell.hpp:174
std::vector< FTransform > images
Definition unitcell.hpp:181
Transform orth
Definition unitcell.hpp:173
Utilities. Mostly for working with strings and vectors.