The placed-model END block lost everything but the atoms, so the writer's _model.cif had no sequence references, authors, software or secondary structure, and gemmi relabelled the subchains. The block now also carries label_asym_id, label_entity_id and label_seq_id per atom and the input model's metadata as the mmCIF categories gemmi writes without coordinates (metadata_mmcif), which the writer parses with gemmi and puts back. The writer's _model.cif is now the same text as the one rugnux writes itself and as /rugnux/model.cif serves. Older blocks without the new fields are read as before. Test: a predicted myoglobin model through END -> CBOR -> writer gives byte-identical _model.cif/_model.pdb to WritePlacedModel and to PlacedModelMmcif, with its _struct_ref, _entity_poly_seq, _audit_author, _software and _struct_conf. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015CeEGgpKdfkCTJb3YNMJcu (cherry picked from commit 29d752e6a107e3b8bc71ad6e9af0d81064966537)
58 lines
2.8 KiB
C++
58 lines
2.8 KiB
C++
// SPDX-FileCopyrightText: 2026 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
#include "RugnuxResultBlocks.h"
|
|
|
|
#include <sstream>
|
|
|
|
#include <gemmi/to_cif.hpp> // write_cif_block_to_stream
|
|
#include <gemmi/to_mmcif.hpp> // make_mmcif_block
|
|
|
|
PlacedModelMessage PlacedModelFromStructure(const gemmi::Structure &st, const UnitCell &cell,
|
|
const std::string &data_space_group_name) {
|
|
PlacedModelMessage p;
|
|
p.name = st.name;
|
|
p.unit_cell = cell;
|
|
p.space_group_name = data_space_group_name;
|
|
p.model_space_group_name = st.spacegroup_hm;
|
|
bool has_aniso = false;
|
|
for (const gemmi::Model &m : st.models)
|
|
for (const gemmi::Chain &ch : m.chains)
|
|
for (const gemmi::Residue &r : ch.residues)
|
|
for (const gemmi::Atom &a : r.atoms) {
|
|
p.model_number.push_back(m.num);
|
|
p.chain.push_back(ch.name);
|
|
p.residue_name.push_back(r.name);
|
|
p.seq_num.push_back(*r.seqid.num);
|
|
p.icode.push_back(static_cast<uint8_t>(r.seqid.icode));
|
|
p.het_flag.push_back(static_cast<uint8_t>(r.het_flag));
|
|
p.subchain.push_back(r.subchain);
|
|
p.entity_id.push_back(r.entity_id);
|
|
p.label_seq.push_back(r.label_seq.value);
|
|
p.atom_name.push_back(a.name);
|
|
p.element.push_back(a.element.name());
|
|
p.altloc.push_back(static_cast<uint8_t>(a.altloc));
|
|
p.charge.push_back(a.charge);
|
|
p.x.push_back(a.pos.x);
|
|
p.y.push_back(a.pos.y);
|
|
p.z.push_back(a.pos.z);
|
|
p.b_iso.push_back(a.b_iso);
|
|
p.occupancy.push_back(a.occ);
|
|
p.aniso.insert(p.aniso.end(), {a.aniso.u11, a.aniso.u22, a.aniso.u33,
|
|
a.aniso.u12, a.aniso.u13, a.aniso.u23});
|
|
has_aniso = has_aniso || a.aniso.nonzero();
|
|
}
|
|
if (!has_aniso)
|
|
p.aniso.clear();
|
|
// Everything of the model but its coordinates (and what goes with them: cell, symmetry, scale), as the mmCIF
|
|
// categories gemmi writes, for the writer to put back on _model.cif.
|
|
gemmi::MmcifOutputGroups groups(true);
|
|
groups.atoms = groups.cell = groups.symmetry = groups.scale = groups.atom_type = groups.origx = false;
|
|
// _entry.id would otherwise be made up from the name, which the block carries anyway.
|
|
groups.entry = st.info.count("_entry.id") > 0;
|
|
std::ostringstream os;
|
|
gemmi::cif::write_cif_block_to_stream(os, gemmi::make_mmcif_block(st, groups));
|
|
p.metadata_mmcif = os.str();
|
|
return p;
|
|
}
|