// SPDX-FileCopyrightText: 2026 Filip Leonarski, Paul Scherrer Institute // SPDX-License-Identifier: GPL-3.0-only #include "RugnuxResultBlocks.h" #include #include // write_cif_block_to_stream #include // 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(r.seqid.icode)); p.het_flag.push_back(static_cast(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(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; }