diff --git a/examples/torsion_in_ring.cpp b/examples/torsion_in_ring.cpp index 64e19b96..0b9ce782 100644 --- a/examples/torsion_in_ring.cpp +++ b/examples/torsion_in_ring.cpp @@ -1,6 +1,6 @@ // prints torsion restraints that are part of a ring -#include +#include #include //#include // for write_cif_to_stream #include @@ -9,7 +9,7 @@ namespace cif = gemmi::cif; using AtomId = gemmi::Restraints::AtomId; void check_torsions(const char* file_path) { - cif::Document doc = cif::read_file(file_path); + cif::Document doc = gemmi::read_cif_gz(file_path); for (cif::Block& block : doc.blocks) { if (block.name.empty() && block.name == "comp_list") continue; diff --git a/examples/with_bgl.cpp b/examples/with_bgl.cpp index 7f6b0ef1..d44e330e 100644 --- a/examples/with_bgl.cpp +++ b/examples/with_bgl.cpp @@ -10,7 +10,7 @@ #include #include #include -#include // for cif::read_file +#include // for read_cif_gz #include // for ChemComp, make_chemcomp_from_block struct AtomVertex { @@ -41,7 +41,7 @@ Graph make_graph(const gemmi::ChemComp& cc) { } gemmi::ChemComp make_chemcomp(const char* path) { - gemmi::cif::Document doc = gemmi::cif::read_file(path); + gemmi::cif::Document doc = gemmi::read_cif_gz(path); // assuming the component description is in the last block of the file return gemmi::make_chemcomp_from_block(doc.blocks.back()); } @@ -83,7 +83,7 @@ void count_automorphisms_of_SO3() { // // Example output: // -// $ ./with_bgl ccd/M10.cif monomers/m/M10.cif +// $ ./with_bgl ccd/M10.cif monomers/m/M10.cif // isomorphic! // O4 -> O9 // O9 -> O4 @@ -162,7 +162,7 @@ void check_subgraph_isomorphism(const char* cif1, const char* cif2) { // CAE -> C7 // OAI -> O8 // CAD -> C1 -// +// // real 0m0.012s // user 0m0.008s // sys 0m0.004s diff --git a/python/cif.cpp b/python/cif.cpp index a1f6e963..e65cf5cc 100644 --- a/python/cif.cpp +++ b/python/cif.cpp @@ -1,6 +1,7 @@ // Copyright 2017 Global Phasing Ltd. #include +#include "gemmi/cif.hpp" // for parse_input #include "gemmi/cifdoc.hpp" #include "gemmi/to_cif.hpp" #include "gemmi/to_json.hpp" @@ -59,6 +60,16 @@ T& add_to_vector(std::vector& vec, const T& new_item, int pos) { return vec[pos]; } +// cif parsing without checking for missing values and duplicates +void cif_parse_string(Document& doc, const std::string& data) { + tao::pegtl::memory_input<> in(data, "string"); + parse_input(doc, in); +} +void cif_parse_file(Document& doc, const std::string& filename) { + GEMMI_CIF_FILE_INPUT(in, filename); + parse_input(doc, in); +} + } // anonymous namespace // for delitem_slice diff --git a/python/common.h b/python/common.h index 12caed1c..3853f36d 100644 --- a/python/common.h +++ b/python/common.h @@ -58,10 +58,6 @@ void add_write(nb::module_& m, nb::class_& structure); // defined in align.cpp void add_assign_label_seq_id(nb::class_& structure); -// defined in read.cpp -void cif_parse_string(gemmi::cif::Document& doc, const std::string& data); -void cif_parse_file(gemmi::cif::Document& doc, const std::string& filename); - // convert pythonic index to C++ index inline int c_index(int index, size_t size) { if (index < 0) diff --git a/python/read.cpp b/python/read.cpp index 26825cb1..1095d076 100644 --- a/python/read.cpp +++ b/python/read.cpp @@ -7,7 +7,6 @@ #include "gemmi/numb.hpp" #include "gemmi/cifdoc.hpp" -#include "gemmi/cif.hpp" #include "gemmi/mmcif.hpp" // for make_structure_from_block, ... #include "gemmi/pdb.hpp" // for read_pdb_string #include "gemmi/gz.hpp" // for estimate_uncompressed_size @@ -24,7 +23,7 @@ using namespace gemmi; NB_MAKE_OPAQUE(std::vector) void add_cif_read(nb::module_& cif) { - cif.def("read_file", &cif::read_file, nb::arg("filename"), + cif.def("read_file", &read_cif_gz, nb::arg("filename"), "Reads a CIF file copying data into Document."); cif.def("read", &read_cif_or_mmjson_gz, nb::arg("filename"), "Reads normal or gzipped CIF file."); @@ -101,7 +100,7 @@ void add_read_structure(nb::module_& m) { // from smcif.hpp m.def("read_small_structure", [](const std::string& path) { - cif::Block block = cif::read_file(path).sole_block(); + cif::Block block = read_cif_gz(path).sole_block(); return new SmallStructure(make_small_structure_from_block(block)); }, nb::arg("path"), "Reads a small molecule CIF file."); m.def("make_small_structure_from_block", &make_small_structure_from_block, @@ -180,12 +179,3 @@ void add_small(nb::module_& m) { nb::arg("st"), nb::arg("n")=0); } -// used in cif.cpp -void cif_parse_string(cif::Document& doc, const std::string& data) { - tao::pegtl::memory_input<> in(data, "string"); - cif::parse_input(doc, in); -} -void cif_parse_file(cif::Document& doc, const std::string& filename) { - GEMMI_CIF_FILE_INPUT(in, filename); - cif::parse_input(doc, in); -}