Skip to content

Commit

Permalink
make_structure_from_chemcomp_doc/gz: add option Document* save_doc=nu…
Browse files Browse the repository at this point in the history
…llptr
  • Loading branch information
wojdyr committed Nov 21, 2024
1 parent 76f405e commit b9a5cb9
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 7 deletions.
9 changes: 7 additions & 2 deletions include/gemmi/mmcif.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,16 @@ inline int check_chemcomp_block_number(const cif::Document& doc) {
return -1;
}

inline Structure make_structure_from_chemcomp_doc(const cif::Document& doc, int which=7) {
inline Structure make_structure_from_chemcomp_doc(const cif::Document& doc,
cif::Document* save_doc=nullptr,
int which=7) {
int n = check_chemcomp_block_number(doc);
if (n == -1)
fail("Not a chem_comp format.");
return make_structure_from_chemcomp_block(doc.blocks[n], which);
Structure st = make_structure_from_chemcomp_block(doc.blocks[n], which);
if (save_doc)
*save_doc = std::move(doc);
return st;
}

} // namespace gemmi
Expand Down
2 changes: 1 addition & 1 deletion include/gemmi/mmread.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ Structure read_structure(T&& input, CoorFormat format=CoorFormat::Unknown,
return st;
}
case CoorFormat::ChemComp:
return make_structure_from_chemcomp_doc(cif::read(input));
return make_structure_from_chemcomp_doc(cif::read(input), save_doc);
case CoorFormat::Unknown:
case CoorFormat::Detect:
fail("Unknown format of " +
Expand Down
4 changes: 3 additions & 1 deletion include/gemmi/mmread_gz.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ GEMMI_DLL Structure read_structure_gz(const std::string& path,
GEMMI_DLL Structure read_pdb_gz(const std::string& path,
PdbReadOptions options=PdbReadOptions());

GEMMI_DLL Structure read_structure_from_chemcomp_gz(const std::string& path, int which);
GEMMI_DLL Structure read_structure_from_chemcomp_gz(const std::string& path,
cif::Document* save_doc=nullptr,
int which=7);

GEMMI_DLL CoorFormat coor_format_from_ext_gz(const std::string& path);

Expand Down
2 changes: 1 addition & 1 deletion prog/convert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ int GEMMI_MAIN(int argc, char **argv) {
if (p.options[FormatIn].arg && std::strlen(p.options[FormatIn].arg) > 9)
// cf. ChemCompModel
which = p.options[FormatIn].arg[9] == 'i' ? 4 : 2;
st = gemmi::read_structure_from_chemcomp_gz(input, which);
st = gemmi::read_structure_from_chemcomp_gz(input, nullptr, which);
} else {
st = gemmi::read_structure_gz(input, in_type);
}
Expand Down
5 changes: 3 additions & 2 deletions src/mmread_gz.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ Structure read_pdb_gz(const std::string& path, PdbReadOptions options) {
return read_pdb(MaybeGzipped(path), options);
}

Structure read_structure_from_chemcomp_gz(const std::string& path, int which) {
return make_structure_from_chemcomp_doc(read_cif_gz(path), which);
Structure read_structure_from_chemcomp_gz(const std::string& path,
cif::Document* save_doc, int which) {
return make_structure_from_chemcomp_doc(read_cif_gz(path), save_doc, which);
}

CoorFormat coor_format_from_ext_gz(const std::string& path) {
Expand Down

0 comments on commit b9a5cb9

Please sign in to comment.