Skip to content

Commit e97d222

Browse files
committed
read _chem_comp_atom.alt_atom_id into ChemComp::Atom::old_id
in prepare_topology(), if old (alt) atom names are used, print more informative warning message
1 parent 880c3e6 commit e97d222

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

include/gemmi/chemcomp.hpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,7 @@ struct ChemComp {
341341

342342
struct Atom {
343343
std::string id;
344+
std::string old_id; // read from _chem_comp_atom.alt_atom_id
344345
Element el;
345346
// _chem_comp_atom.partial_charge can be non-integer,
346347
// _chem_comp_atom.charge is always integer (but sometimes has format
@@ -435,6 +436,14 @@ struct ChemComp {
435436
return find_atom(atom_id) != atoms.end();
436437
}
437438

439+
std::vector<Atom>::iterator find_atom_by_old_name(const std::string& old_id) {
440+
return std::find_if(atoms.begin(), atoms.end(),
441+
[&](const Atom& a) { return a.old_id == old_id; });
442+
}
443+
std::vector<Atom>::const_iterator find_atom_by_old_name(const std::string& old_id) const {
444+
return const_cast<ChemComp*>(this)->find_atom_by_old_name(old_id);
445+
}
446+
438447
int get_atom_index(const std::string& atom_id) const {
439448
auto it = find_atom(atom_id);
440449
if (it == atoms.end())
@@ -580,8 +589,10 @@ inline ChemComp make_chemcomp_from_block(const cif::Block& block_) {
580589
cc.type_or_group = type_col.str(0);
581590
for (auto row : block.find("_chem_comp_atom.",
582591
{"atom_id", "type_symbol", "?type_energy",
583-
"?charge", "?partial_charge"}))
584-
cc.atoms.push_back({row.str(0), Element(row.str(1)),
592+
"?charge", "?partial_charge", "?alt_atom_id"}))
593+
cc.atoms.push_back({row.str(0),
594+
row.has(5) ? row.str(5) : "",
595+
Element(row.str(1)),
585596
(float) cif::as_number(row.one_of(3, 4), 0.0),
586597
row.has(2) ? row.str(2) : "",
587598
Position()});

src/monlib.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ void ChemMod::apply_to(ChemComp& chemcomp, ChemComp::Group alias_group) const {
256256
if (mod.new_id.empty())
257257
fail("New atom id is not given");
258258
if (!chemcomp.has_atom(real(mod.new_id)))
259-
chemcomp.atoms.push_back({mod.new_id, mod.el,
259+
chemcomp.atoms.push_back({mod.new_id, "", mod.el,
260260
std::isnan(mod.charge) ? mod.charge : 0,
261261
mod.chem_type, Position()});
262262
continue;

src/topo.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ std::unique_ptr<ChemComp> make_chemcomp_with_restraints(const Residue& res) {
2626
if (el == El::D)
2727
el = El::H;
2828
const std::string& chem_type = el.uname();
29-
cc->atoms.push_back(ChemComp::Atom{a.name, el, float(a.charge), chem_type, a.pos});
29+
cc->atoms.push_back(ChemComp::Atom{a.name, "", el, float(a.charge), chem_type, a.pos});
3030
}
3131
// prepare pairs of atoms
3232
struct Pair {
@@ -929,8 +929,13 @@ prepare_topology(Structure& st, MonLib& monlib, size_t model_index,
929929
if (!cc.has_atom(atom.name)) {
930930
std::string msg = "definition not found for "
931931
+ atom_str(chain_info.chain_ref, *ri.res, atom);
932-
if (ri.orig_chemcomp && ri.orig_chemcomp->has_atom(atom.name))
932+
if (ri.orig_chemcomp && ri.orig_chemcomp->has_atom(atom.name)) {
933933
msg += " (linkage should remove this atom)";
934+
} else {
935+
auto it = cc.find_atom_by_old_name(atom.name);
936+
if (it != cc.atoms.end())
937+
cat_to(msg, " (replace ", atom.name, " with ", it->id, ')');
938+
}
934939
topo->err(msg);
935940
}
936941
}

0 commit comments

Comments
 (0)