6#ifndef GEMMI_MONLIB_HPP_
7#define GEMMI_MONLIB_HPP_
36 if (group == Group::Null)
38 return res == group || (group == Group::Peptide && ChemComp::is_peptide_group(res))
39 || (group == Group::DnaRna && ChemComp::is_nucleotide_group(res));
44 return group == Group::PPeptide || group == Group::MPeptide ? 1 : 0;
103 std::multimap<std::string, Bond>
bonds;
109 std::map<std::string, ChemLink>
links;
115 auto link = links.find(link_id);
116 return link != links.end() ? &
link->second :
nullptr;
119 auto modif = modifications.find(name);
120 return modif != modifications.end() ? &
modif->second :
nullptr;
125 std::tuple<const ChemLink*, bool, const ChemComp::Aliasing*, const ChemComp::Aliasing*>
127 const Residue& res2,
const std::string&
atom2,
char alt2,
130 bool inverted =
false;
136 for (
const auto&
ml : links) {
144 if (link_side_matches_residue(
link.side1, res1.
name, &aliasing1) &&
145 link_side_matches_residue(
link.side2, res2.
name, &aliasing2) &&
148 int score =
link.calculate_score(res1, &res2, alt1, alt2, aliasing1, aliasing2);
157 if (link_side_matches_residue(
link.side1, res2.
name, &aliasing2) &&
158 link_side_matches_residue(
link.side2, res1.
name, &aliasing1) &&
162 int score =
link.calculate_score(res2, &res1, alt2, alt1, aliasing2, aliasing1);
176 if (block.
has_tag(
"_chem_comp_atom.atom_id")) {
178 if (cc.
group == ChemComp::Group::Null) {
179 auto it = cc_groups.find(cc.
name);
180 if (
it != cc_groups.end())
183 std::string name = cc.
name;
184 monomers.emplace(name, std::move(cc));
193 if (!
side.comp.empty())
196 if (
it != monomers.end()) {
197 if (
side.matches_group(
it->second.group))
200 if (
side.matches_group(a.group)) {
210 return monomer_dir + relative_monomer_path(
code);
221 if (!monomer_dir.empty() && monomer_dir.back() !=
'/' && monomer_dir.back() !=
'\\')
228 const std::vector<std::string>&
resnames,
237 const std::vector<std::string>&
resnames,
238 const std::string&
libin=
"",
249 error +=
"Please create definitions for missing monomers.";
ChemComp - chemical component that represents a monomer from Refmac monomer library,...
struct Document that represents the CIF file (but can also be read from a different representation,...
Elements from the periodic table.
fail(), unreachable() and __declspec/__attribute__ macros
Logger - a tiny utility for passing messages through a callback.
Data structures to store macromolecular structure models.
MonLib read_monomer_lib(const std::string &monomer_dir, const std::vector< std::string > &resnames, const std::string &libin="", bool ignore_missing=false)
ChemComp make_chemcomp_from_block(const cif::Block &block_)
bool atom_match_with_alias(const std::string &atom_id, const std::string &atom, const ChemComp::Aliasing *aliasing)
constexpr float sq(float x)
void cat_to(std::string &)
bool starts_with(const std::string &str, const std::string &prefix)
void fail(const std::string &msg)
bool matches_group(Group res) const
int calculate_score(const Residue &res1, const Residue *res2, char alt, char alt2, const ChemComp::Aliasing *aliasing1, const ChemComp::Aliasing *aliasing2) const
If multiple ChemLinks match a bond, the one with highest scores should be used.
void apply_to(ChemComp &chemcomp, ChemComp::Group alias_group) const
std::vector< AtomMod > atom_mods
std::multimap< std::string, Bond > bonds
std::map< std::string, Atom > atoms
void read(const cif::Document &doc)
Passes messages (including warnings/errors) to a callback function.
std::function< void(const std::string &)> callback
A function that handles messages.
bool read_monomer_lib(const std::string &monomer_dir_, const std::vector< std::string > &resnames, const Logger &logger)
Read mon_lib_list.cif, ener_lib.cif and required monomers.
void read_monomer_doc(const cif::Document &doc)
double find_ideal_distance(const const_CRA &cra1, const const_CRA &cra2) const
const ChemLink * get_link(const std::string &link_id) const
std::map< std::string, ChemMod > modifications
static std::string relative_monomer_path(const std::string &code)
std::map< std::string, ChemLink > links
std::map< std::string, ChemComp::Group > cc_groups
void set_monomer_dir(const std::string &monomer_dir_)
void add_monomer_if_present(const cif::Block &block)
std::tuple< const ChemLink *, bool, const ChemComp::Aliasing *, const ChemComp::Aliasing * > match_link(const Residue &res1, const std::string &atom1, char alt1, const Residue &res2, const std::string &atom2, char alt2, double min_bond_sq=0) const
bool link_side_matches_residue(const ChemLink::Side &side, const std::string &res_name, ChemComp::Aliasing const **aliasing) const
void update_old_atom_names(Structure &st, const Logger &logger) const
std::map< std::string, ChemComp > monomers
const ChemMod * get_mod(const std::string &name) const
void read_monomer_cif(const std::string &path_)
std::string path(const std::string &code) const
Returns path to the monomer cif file (the file may not exist).
bool has_tag(const std::string &tag) const